X-Git-Url: http://git.giacomolli.uk/onechat/blobdiff_plain/47f69638bc96100f2e446f63c7c3689023156e64..eeb821ff17ad79c87ca9b64cd9be26f8612f4a03:/subagent_run.go?ds=inline diff --git a/subagent_run.go b/subagent_run.go index 20b15f2..4a88800 100644 --- a/subagent_run.go +++ b/subagent_run.go @@ -19,6 +19,13 @@ const ( subagentNoteEffort = " at effort " ) +// The statuses of the end of a run, in the work event of its report. +const ( + subagentFinished = "finished" + subagentStopped = "stopped" + subagentFailed = "failed" +) + // errSubagentClosed tells that the runs of the subagents ended with the loop. var errSubagentClosed = errors.New("the daemon stops, so no subagent starts") @@ -43,7 +50,7 @@ type SubagentRuns struct { layout *ViewLayout client ChainClient state func() string - report func(text string, stopped bool) + report func(name, text, status string) note func(text string) error notify func(Event) @@ -302,6 +309,7 @@ func (r *SubagentRuns) run(ctx context.Context, run *SubagentRun) { var replies []string stopped := false + status := subagentFinished for more := true; more; { reply, err := r.chain(ctx, run) @@ -312,6 +320,7 @@ func (r *SubagentRuns) run(ctx context.Context, run *SubagentRun) { reply = "stopped" case err != nil: reply = "failed: " + err.Error() + status = subagentFailed } more = err == nil && ctx.Err() == nil && len(run.pending) > 0 @@ -328,7 +337,11 @@ func (r *SubagentRuns) run(ctx context.Context, run *SubagentRun) { return } - r.report(subagentReport(run.subagent.name, replies), stopped) + if stopped { + status = subagentStopped + } + + r.report(run.subagent.name, subagentReport(run.subagent.name, replies), status) } // chain runs one request chain of run and returns its final answer.