Skip to contents

Creates a new idle session whose transcript is the source path up to a cut, with the same entry ids. Nothing live is shared (listeners, queue, run, lock, usage); the fork's file is written lazily at its first own message, with parentSession and gptr.forkOf in its header. The fork's workspace is an overlay of the source's kept home: it reads every object of the source at zero cost, and its writes stay in the overlay.

Usage

gptr_fork(s, at = NULL, envir = c("overlay", "shared"))

Arguments

s

A gptr_session: the source.

at

NULL (the last closed boundary; a running source is cut there), an integer k >= 0 (the end of turn k; 0 is an empty conversation) or an entry id.

envir

"overlay": the fork evaluates in new.env(parent = <source home>); "shared": the same home.

Value

A new idle gptr_session.

Examples

fake = gptr_fake_provider(list("A", "B"))
session = peter("first", model = fake)
#> gptr: thinking
#> gptr: done · 1 turn · 1.6k tokens · $0.0000
branch = gptr_fork(session)
branch |> peter("branch")
#> gptr: thinking
#> gptr: done · 2 turns · 1.6k tokens · $0.0000
#> B
#> idle · fake/fake-1 · 2 turns · 1.6k tokens · $0.0000 · sc83c4ca36b
c(session$turns, branch$turns)
#> [1] 1 2