From 25007e8316a35649d9eb962a44bf9733308420b2 Mon Sep 17 00:00:00 2001 From: Sam Catlow Date: Mon, 16 Nov 2026 04:39:49 +1100 Subject: [PATCH] feat(runs): an agent that describes an action without calling it gets one more turn to call it (archie #1999) --- internal/platform/prompts/follow_through.md | 8 +++ internal/platform/prompts/prompts.go | 7 +++ modules/runs/investigate.go | 65 ++++++++++++++++++++- 3 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 internal/platform/prompts/follow_through.md diff --git a/internal/platform/prompts/follow_through.md b/internal/platform/prompts/follow_through.md new file mode 100644 index 000000000..f218aabd4 --- /dev/null +++ b/internal/platform/prompts/follow_through.md @@ -0,0 +1,8 @@ +Your last reply described calling an action without calling it, so nothing was +proposed and nobody can approve it. The user message holds the event, your +findings and the actions you described but didn't call. + +Calling an action commits nothing: judgement checks it first, and an action +it holds is put to a person. Call each action you recommended now, with the +target you named. If you've decided against one, say why instead of calling +it. Then reply with your findings again, updated with what judgement answered. diff --git a/internal/platform/prompts/prompts.go b/internal/platform/prompts/prompts.go index 2d95da19b..89f7ce2a1 100644 --- a/internal/platform/prompts/prompts.go +++ b/internal/platform/prompts/prompts.go @@ -7,5 +7,12 @@ import _ "embed" //go:embed investigate.md var investigate string +//go:embed follow_through.md +var followThrough string + // Investigate is the system prompt of the investigate workflow's agent. func Investigate() string { return investigate } + +// FollowThrough is added to the investigate prompt when the agent described an +// action it didn't call. +func FollowThrough() string { return followThrough } diff --git a/modules/runs/investigate.go b/modules/runs/investigate.go index f48fa0a82..4d1449550 100644 --- a/modules/runs/investigate.go +++ b/modules/runs/investigate.go @@ -7,6 +7,7 @@ import ( "errors" "fmt" "regexp" + "slices" "strings" "time" @@ -112,6 +113,12 @@ func Investigate(settings Settings, box Toolbox, judge Judge, ask Approver, noti if err != nil { return nil, err } + if res, err = followThrough(rc, judge, decls, input, res, AgentRequest{ + Provider: provider, Model: model.Model, ModelInfo: info, + Tools: toolSet(box, judge, rc.RunID(), decls), + }); err != nil { + return nil, err + } outcomes, err := settleProposals(rc, judge, ask, deadline) if err != nil { return nil, err @@ -132,6 +139,62 @@ func Investigate(settings Settings, box Toolbox, judge Judge, ask Approver, noti } } +// followThroughBudget bounds the turn that has the agent call what it only +// described. +var followThroughBudget = agentloop.Budget{MaxSteps: 8, MaxTokens: 60_000, WallClock: 5 * time.Minute} + +// followThrough gives the agent one more turn when its findings name an action +// it never called: a small model often writes the call out instead of making +// it, and an action that was only described can't be judged or approved. +func followThrough(rc *Context, judge Judge, decls []connectors.Declaration, input jsontext.Value, res AgentResult, req AgentRequest) (AgentResult, error) { + if !res.Completed { + return res, nil + } + made, err := rc.Step("decisions-made", func(ctx context.Context, _ string) ([]string, error) { + decisions, err := judge.ForRun(ctx, rc.RunID()) + names := make([]string, 0, len(decisions)) + for _, d := range decisions { + names = append(names, toolName(d.Action.Connector, d.Action.Name)) + } + return names, err + }) + if err != nil { + return res, err + } + missed := uncalled(res.Answer, decls, made) + if len(missed) == 0 { + return res, nil + } + prompt, err := json.Marshal(map[string]any{"event": input, "findings": res.Answer, "described_but_not_called": missed}) + if err != nil { + return res, err + } + req.Name, req.System, req.Prompt, req.Budget = "follow-through", prompts.Investigate()+"\n\n"+prompts.FollowThrough(), string(prompt), followThroughBudget + again, err := rc.Agent(req) + if err != nil || !again.Completed { + // The first findings stand when the extra turn doesn't finish. + return res, err + } + return again, nil +} + +// uncalled lists the actions an answer names that no decision in the run +// records. +func uncalled(answer string, decls []connectors.Declaration, made []string) []string { + var out []string + for _, d := range decls { + name := toolName(d.Connector, d.Name) + if d.Kind == connectors.KindAction && strings.Contains(answer, name) && !slices.Contains(made, name) { + out = append(out, name) + } + } + return out +} + +func toolName(connector, name string) string { + return unsafeToolChars.ReplaceAllString(connector+"_"+name, "_") +} + // approvalOutcome is what became of one action the agent proposed. type approvalOutcome struct { Action string `json:"action"` @@ -339,7 +402,7 @@ var unsafeToolChars = regexp.MustCompile(`[^a-zA-Z0-9_-]`) func toolSet(box Toolbox, judge Judge, runID uuid.UUID, decls []connectors.Declaration) core.ToolSet { set := core.ToolSet{} for _, d := range decls { - name := unsafeToolChars.ReplaceAllString(d.Connector+"_"+d.Name, "_") + name := toolName(d.Connector, d.Name) set[name] = &core.Tool{ Name: name, Description: d.Description,