Add StopFlowTool - #25265
Add StopFlowTool#25265luisorofino wants to merge 6 commits into
Conversation
evalya-impact-summaryevalya impact analysis |
|
✅ All CI checks and tests passed. 🎉 All green!🧪 All tests passed 🎯 Code Coverage (details) 🔗 Commit SHA: 9a96d46 | Docs | View more details | Give us feedback! |
|
@codex review |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: bd5c0befcd
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
| raise FlowStopRequested( | ||
| f"Agent stopped the flow with reason:\n{stop_reason}", | ||
| input_tokens=total_input, | ||
| output_tokens=total_output, | ||
| ) |
There was a problem hiding this comment.
Let subagent stop requests escape the spawn wrappers
When a spawned child is granted stop_flow, this exception does not reach the phase: BaseSpawnTool._run_child catches every Exception and converts it into a ChildOutcome error, and the parallel spawn path also aggregates exceptions as ordinary child failures. The parent therefore continues even though the tool explicitly promises to stop the whole run, including from a subagent. Exempt FlowStopRequested from those wrappers and propagate it to the phase.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
I did this on purpose. If a subagent wants to stop the pipeline, it executes the tool and the main agent decides whether the subagent's reason is fair enough to stop the whole flow. That way we don't give the subagent too much power. If the subagent's reason is strong, then the parent should stop.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2094346a60
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
a3325ea to
9a96d46
Compare
Validation ReportAll 21 validations passed. Show details
|
What does this PR do?
Adds a
stop_flowtool for Togo agents. When a task is impossible as specified (e.g. the PRD requires connecting to an endpoint that doesn't exist), an agent callsstop_flowwith areason, and the whole run ends immediately with that reason recorded — instead of the agent guessing, improvising, or looping.Mechanically: the tool just returns a
ToolResultwithstop_reasonset.ReActProcesschecks for it after each turn's tool calls and raisesFlowStopRequestedinstead of feeding results back to the agent. From there it's the existing, unmodified failure path: the exception propagates out of the phase,Phase.on_errorrecords aFailedCheckpointwith the agent's reason as the error, emitsPhaseFailedMessage, andPhaseOrchestratorturns that into aFatalProcessingErrorthat winds the whole bus down. No orchestrator or checkpoint changes wereneeded — reusing the same cascade an unexpected phase failure already takes means a human can fix the PRD and rerun (the phase isn't checkpointed as successful, so it reruns), and the failure reason is exactly what the agent explained rather than a stack trace.
Motivation
Some Togo flows (future API-based flow) give agents instructions that can't always be satisfied (e.g. a generated PRD referencing something that doesn't exist). Previously an agent had no way to signal that cleanly — it would either fail with an opaque error or continue and produce a broken result. This gives it an explicit, self-explaining way to stop.
Review checklist (to be filled by reviewers)
qa/requiredif this PR needs QA validation, orqa/skip-qaif it does not. Exactly one of the two is required.backport/<branch-name>label to the PR and it will automatically open a backport PR once this one is merged