X-Git-Url: https://git.giacomolli.uk/onechat/blobdiff_plain/37d5f21b23da5fbd6b44fed41f653927669571ed..5b778ad04422dd456b7d673fb653f0353c47b0fe:/subagent_run.go diff --git a/subagent_run.go b/subagent_run.go index 16cf2bd..7d3687c 100644 --- a/subagent_run.go +++ b/subagent_run.go @@ -5,6 +5,7 @@ import ( "encoding/json" "errors" "fmt" + "log" "maps" "os" "path/filepath" @@ -43,9 +44,10 @@ var errSubagentClosed = errors.New("the daemon stops, so no subagent starts") // of the subagent. A message of Tell that comes during a chain joins its next // request after the tool results. One that comes after the final answer starts // one more chain, which reads the log again. The report of the run goes to -// report: the final answer of each chain, or the error of a failed call. Stop -// ends one run, and its report says that it stopped. At the stop of the daemon -// the runs end with no report. +// report: the final answer of each chain, or the error of a failed call. The +// logger gets one line at the end of a run: done, failed with the cause, or +// stopped. Stop ends one run, and its report says that it stopped. At the stop +// of the daemon the runs end with no report. // // work.json in the directory of the agent holds the names of the running // subagents. Each start and each end of a run writes it whole, but Close does @@ -66,6 +68,7 @@ type SubagentRuns struct { report func(name, text, status string) note func(text string) error fail func(err error) + logger *log.Logger notify func(Event) mutex sync.Mutex @@ -237,6 +240,7 @@ func (r *SubagentRuns) Resume(ctx context.Context) error { for _, name := range names { _, err = r.Tell(ctx, name, text) if err != nil { + r.logger.Printf("subagent %s cannot go on after the restart, and its report tells the agent: %v", name, err) r.report(name, subagentReport(name, []string{"failed: " + err.Error()}), subagentFailed) } } @@ -406,6 +410,7 @@ func (r *SubagentRuns) run(ctx context.Context, run *SubagentRun) { defer run.cancel() var replies []string + var failure error stopped := false status := subagentFinished for more := true; more; { @@ -419,6 +424,7 @@ func (r *SubagentRuns) run(ctx context.Context, run *SubagentRun) { case err != nil: reply = "failed: " + err.Error() status = subagentFailed + failure = err } more = err == nil && ctx.Err() == nil && len(run.pending) > 0 @@ -447,6 +453,15 @@ func (r *SubagentRuns) run(ctx context.Context, run *SubagentRun) { status = subagentStopped } + switch status { + case subagentStopped: + r.logger.Printf("subagent %s is stopped by the user", run.subagent.name) + case subagentFailed: + r.logger.Printf("subagent %s failed, and its report tells the agent: %v", run.subagent.name, failure) + default: + r.logger.Printf("subagent %s is done, and its report goes to the agent", run.subagent.name) + } + r.report(run.subagent.name, subagentReport(run.subagent.name, replies), status) }