Skip to contents

A backend runs child sessions on the shared reactor. Its start(spec, ctx) returns a handle with a gptr_session in session and a zero-argument cancel function that stops the child and its processes. Asynchronous work supplies run, the child's live run on that reactor; without run the team scheduler treats the child as settled. Backend callbacks must not block the reactor for more than 50 ms.

Usage

gptr_backend(name, start, poll = NULL, cancel, capabilities = list())

Arguments

name

Backend name, usable as backend = <name>.

start

function(spec, ctx), receiving the prepared child specification and parent context, and returning the handle described above. gptr_check() calls it with a minimal probe (name, prompt, model and tools) and a scratch context, so it should tolerate a specification without the other prepared fields.

poll

function(handle) or NULL, retained in the spec. The built-in team scheduler observes handle$run on the reactor and does not call this callback.

cancel

function(handle) that stops the child and every process it started. gptr_check() calls it on its probe handle and requires that no child process remains. The team scheduler cancels through the handle's zero-argument cancel function instead, so a backend normally sets cancel = function(handle) handle$cancel().

capabilities

Named list: for a custom backend, parallel = "cpu" selects the worker concurrency pool (other values select inline); live_objects (logical) and ask ("queue", "forward" or "none") describe the backend rather than enforcing scheduler behavior.

Value

A spec of class c("gptr_backend", "gptr_spec").

Examples

# This constructs a spec; a working start() must return the handle described above.
gptr_backend("echo", start = function(spec, ctx) NULL, cancel = function(handle) handle$cancel())
#> <gptr_backend echo>
#>   start: <fn>
#>   cancel: <fn>
#>   capabilities: <list of 0>
#>   api_version: 1.0