X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/790279faf0fda789d93a75f6f5996e65d5de4a18..12bd9e96f3b3e67290484e3829461e054110db27:/subagent_run.go diff --git a/subagent_run.go b/subagent_run.go index 0780393..faa6207 100644 --- a/subagent_run.go +++ b/subagent_run.go @@ -256,6 +256,18 @@ func (r *SubagentRuns) Resume(ctx context.Context) error { return r.save() } +// Snapshot locks the run state, memory, and subagent logs while snapshot reads +// the agent files. The lock order agrees with Stop, which logs under the run +// lock. +func (r *SubagentRuns) Snapshot(ctx context.Context, snapshot func() error) error { + r.mutex.Lock() + defer r.mutex.Unlock() + + return r.memory.Snapshot(ctx, func() error { + return r.subagents.Snapshot(ctx, snapshot) + }) +} + // Close ends every run and waits for them. No subagent starts after Close. func (r *SubagentRuns) Close() { r.mutex.Lock() @@ -412,8 +424,9 @@ func (r *SubagentRuns) workPath() string { } // run runs the chains of run and reports and logs its end with the length of -// the run, unless Close ended it. A chain follows while messages wait after the final answer of the chain before -// it, and no chain failed. A chain that Stop ends gives the reply "stopped". +// the run, unless Close ended it. A chain follows while messages wait after the +// final answer of the chain before it, and no chain failed. A chain that Stop +// ends gives the reply "stopped". func (r *SubagentRuns) run(ctx context.Context, run *SubagentRun) { defer r.workers.Done() defer run.cancel() @@ -503,11 +516,13 @@ func (r *SubagentRuns) chain(ctx context.Context, run *SubagentRun) (string, err input = append(input, modelUserMessage(r.state()), modelUserMessage(log)) chain := &Chain{ client: r.client, + images: r.agent.Images(), tools: &Toolbox{ log: run.subagent, chat: r.memory, subagents: r.subagents, workdir: run.subagent.WorkDir(), + images: r.agent.Images(), }, request: ModelRequest{ Model: r.agent.config.Model, @@ -538,8 +553,8 @@ func (r *SubagentRuns) take(run *SubagentRun) []Message { // SubagentRun is one run of a subagent: the view that its requests get, its // effort, the end of its context, the messages of Tell that wait for a request, -// whether Stop ended it, and the time it started. The mutex of SubagentRuns protects the messages -// and the stop. +// whether Stop ended it, and the time it started. The mutex of SubagentRuns +// protects the messages and the stop. type SubagentRun struct { subagent *Subagent view []string