Documentation
¶
Overview ¶
Package jobs lets a tool go asynchronous.
Without it every tool is synchronous: a long crawl, build, render, or export blocks the whole run until it finishes, and a run that has to wait cannot also think. With it a tool calls agentcore.LaunchBackground, returns a job receipt immediately, and the model keeps working; the built-in job_list / job_status / job_wait / job_cancel tools observe and stop the work, and jobs that finished since the last turn are announced at the top of the next one.
Every run gets its own board, so a job can be neither observed nor cancelled by another run, and every job is cancelled when its run ends. The board's records are checkpointed: a resumed run can still read the results of jobs that finished, and learns which ones the end of the previous run interrupted.
A running job is not a black box: its work publishes output as it goes (agentcore.PublishJobOutput), and job_status / job_list show the newest part of it. Two opt-ins extend the board: Plugin.AllowSend adds job_send, which steers a running background sub-agent, and Plugin.Survive lets a job the model marks with job_keep outlive the run that started it (see Survival).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WithConversation ¶ added in v0.2.2
WithConversation names the conversation a run belongs to, for Survive. The host sets it on the context it passes to RunNative; it is the identity under which kept jobs are held and found again. A durable session id is used when the context carries none.
Types ¶
type Ended ¶ added in v0.2.2
type Ended struct {
Conversation string
JobID string
Tool string
Label string
// State is "succeeded", "failed" or "cancelled".
State string
// Notice is the completion notice (the text the next run's first step would
// have carried), ready to be sent as a user message of a new run.
Notice string
}
Ended tells the host that a kept job ended while no run of its conversation was attached.
type Hold ¶ added in v0.2.2
type Hold struct {
// contains filtered or unexported fields
}
Hold is the host-owned home of kept jobs between runs, keyed by conversation. It owns no storage and starts nothing: it only keeps the goroutines of jobs the model chose to keep reachable. Create one per process with NewHold.
func NewHold ¶ added in v0.2.2
NewHold creates a Hold. onEnd, when set, is called once for each kept job that ends while no run of its conversation is attached, and for a kept job that had ended unannounced when its run closed. It runs on the job's goroutine: return quickly and start the run elsewhere. It is never called for a job a run is attached to; that run announces the job itself.
type Plugin ¶
type Plugin struct {
// MaxConcurrent bounds running jobs per run. Zero uses 15; -1 disables the ceiling.
MaxConcurrent int
// AllowSend adds job_send, which delivers a message to a running
// background sub-agent at its next step. Off by default: it changes the
// tool list the model sees.
AllowSend bool
// Survive, when set, adds job_keep and lets kept jobs outlive their run.
// Nil keeps every job bound to its run, exactly as without the option.
Survive *Survival
}
Plugin installs background jobs.
type Survival ¶ added in v0.2.2
type Survival struct {
// Hold is the host-owned home of kept jobs between runs. Required.
Hold *Hold
// MaxAge bounds a kept job's lifetime, counted from its start; at that age it
// is cancelled and reported cancelled. Zero uses one hour.
MaxAge time.Duration
// MaxJobs bounds how many kept jobs one conversation may have running. Zero
// uses four.
MaxJobs int
// Exclude names more tools whose jobs job_keep refuses, besides
// spawn_subagent.
Exclude []string
}
Survival is the opt-in that lets a background job outlive the run that started it. Set it as Plugin.Survive.
The model chooses: only a job it marks with job_keep survives; every other job is cancelled when the run ends, exactly as without this option. A kept job keeps running after the run's final answer. It is listed, readable and cancellable (job_list, job_status, job_wait, job_cancel) from the next run of the SAME conversation and from no other. Its result is announced exactly once: in that next run's first step, or, when it ends while no run of the conversation is attached, through Hold's callback.
What the host must do:
- Create one Hold for the process (NewHold) and give every run the same one.
- Tell the library which conversation a run belongs to: WithConversation on the context passed to RunNative, or a durable session id (RunInfo.SessionID). A run with neither cannot keep jobs.
- Implement the Hold's callback to start a new run of that conversation carrying Ended.Notice as a user message.
- Persist the native checkpoint as it already does. A kept job lives in the process: when the process restarts the Hold is empty, and the restored checkpoint reports the job as interrupted.
A job started under one run keeps that run's context values, so its policy, credentials and session stay those of the run that started it; the next run only observes and cancels it.
Model-backed work cannot be kept. spawn_subagent folds its child's token usage into the Agent that spawned it, and that Agent's run has ended by the time a surviving child would finish: the usage would be lost or charged to the wrong run. job_keep refuses it with that reason. Shell commands and host tools can be kept; Exclude refuses more tools that call a model.