Skip to content

Add StopFlowTool - #25265

Draft
luisorofino wants to merge 6 commits into
loa/openmetrics-ai-genfrom
loa/stop-flow-tool
Draft

luisorofino wants to merge 6 commits into
loa/openmetrics-ai-genfrom
loa/stop-flow-tool

Conversation

@luisorofino

@luisorofino luisorofino commented Sep 17, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds a stop_flow tool 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 calls stop_flow with a reason, and the whole run ends immediately with that reason recorded — instead of the agent guessing, improvising, or looping.

Mechanically: the tool just returns a ToolResult with stop_reason set. ReActProcess checks for it after each turn's tool calls and raises FlowStopRequested instead 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_error records a FailedCheckpoint with the agent's reason as the error, emits PhaseFailedMessage, and PhaseOrchestrator turns that into a FatalProcessingError that winds the whole bus down. No orchestrator or checkpoint changes were
needed — 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)

  • Feature or bugfix MUST have appropriate tests (unit, integration, e2e)
  • Add qa/required if this PR needs QA validation, or qa/skip-qa if it does not. Exactly one of the two is required.
  • If you need to backport this PR to another branch, you can add the backport/<branch-name> label to the PR and it will automatically open a backport PR once this one is merged

@luisorofino luisorofino added the qa/skip-qa Automatically skip this PR for the next QA label Sep 17, 2026
@cit-pr-commenter-54b7da

Copy link
Copy Markdown

evalya-impact-summary

evalya impact analysis
Impact analysis: 0 selected, 0 skipped (of 0 test tasks)
Publish tasks:   2 (always emitted)
Diff (241 files):
  .gitignore
  ddev/hatch.toml
  ddev/pyproject.toml
  ddev/src/ddev/ai/__init__.py
  ddev/src/ddev/ai/agent/__init__.py
  ddev/src/ddev/ai/agent/anthropic_agent.py
  ddev/src/ddev/ai/agent/anthropic_provider.py
  ddev/src/ddev/ai/agent/base.py
  ddev/src/ddev/ai/agent/build.py
  ddev/src/ddev/ai/agent/exceptions.py
  ddev/src/ddev/ai/agent/provider.py
  ddev/src/ddev/ai/agent/registry.py
  ddev/src/ddev/ai/agent/scope.py
  ddev/src/ddev/ai/agent/types.py
  ddev/src/ddev/ai/callbacks/__init__.py
  ddev/src/ddev/ai/callbacks/callbacks.py
  ddev/src/ddev/ai/config/__init__.py
  ddev/src/ddev/ai/config/classify.py
  ddev/src/ddev/ai/config/dependency_graph.py
  ddev/src/ddev/ai/config/engine.py
  ... and 221 more

Debug a specific task: evalya plan impact --path <path> --task <task>

Learn more about CI impact filtering

@dd-octo-sts dd-octo-sts Bot added the ddev label Sep 17, 2026
@datadog-datadog-prod-us1-2

datadog-datadog-prod-us1-2 Bot commented Sep 17, 2026

Copy link
Copy Markdown

Tests  Code Coverage

All CI checks and tests passed.

🎉 All green!

🧪 All tests passed
❄️ No new flaky tests detected

🎯 Code Coverage (details)
Patch Coverage: 100.00%
Overall Coverage: 89.84%

This comment will be updated automatically if new data arrives.
🔗 Commit SHA: 9a96d46 | Docs | View more details | Give us feedback!

@luisorofino

Copy link
Copy Markdown
Contributor Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment on lines +179 to +183
raise FlowStopRequested(
f"Agent stopped the flow with reason:\n{stop_reason}",
input_tokens=total_input,
output_tokens=total_output,
)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge 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 👍 / 👎.

@luisorofino luisorofino Sep 18, 2026

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread ddev/src/ddev/ai/phases/agentic_phase.py
Comment thread ddev/src/ddev/ai/react/process.py
Comment thread ddev/tests/ai/phases/test_agentic_phase.py Outdated
@luisorofino
luisorofino marked this pull request as ready for review September 18, 2026 08:48
@luisorofino
luisorofino requested a review from a team as a code owner September 18, 2026 08:48

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 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".

Comment thread ddev/src/ddev/ai/phases/goal.py
Comment thread ddev/src/ddev/ai/react/process.py
@dd-octo-sts

dd-octo-sts Bot commented Sep 18, 2026

Copy link
Copy Markdown
Contributor

Validation Report

All 21 validations passed.

Show details
Validation Description Status
agent-reqs Verify check versions match the Agent requirements file
ci Validate CI configuration and code coverage settings
codeowners Validate every integration has a CODEOWNERS entry
config Validate default configuration files against spec.yaml
dep Verify dependency pins are consistent and Agent-compatible
http Validate integrations use the HTTP wrapper correctly
imports Validate check imports do not use deprecated modules
integration-style Validate check code style conventions
jmx-metrics Validate JMX metrics definition files and config
labeler Validate PR labeler config matches integration directories
legacy-signature Validate no integration uses the legacy Agent check signature
license-headers Validate Python files have proper license headers
licenses Validate third-party license attribution list
metadata Validate metadata.csv metric definitions
models Validate configuration data models match spec.yaml
openmetrics Validate OpenMetrics integrations disable the metric limit
package Validate Python package metadata and naming
qa-label Validate the pull request declares whether it needs QA for the next Agent release
readmes Validate README files have required sections
saved-views Validate saved view JSON file structure and fields
version Validate version consistency between package and changelog

View full run

@luisorofino
luisorofino marked this pull request as draft September 18, 2026 14:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ddev qa/skip-qa Automatically skip this PR for the next QA team/agent-integrations

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant