Skip to content

fix(agent): honor AgentToolResult.terminate#432

Open
d8rt8v wants to merge 1 commit into
huggingface:mainfrom
d8rt8v:agent/honor-agent-tool-result-terminate
Open

fix(agent): honor AgentToolResult.terminate#432
d8rt8v wants to merge 1 commit into
huggingface:mainfrom
d8rt8v:agent/honor-agent-tool-result-terminate

Conversation

@d8rt8v

@d8rt8v d8rt8v commented Jul 21, 2026

Copy link
Copy Markdown

Summary

Honor AgentToolResult.terminate in the agent loop.

The loop now collects finalized results after the complete tool-call batch has run and skips the automatic follow-up model turn only when every result requests termination. Results modified by after_tool_call are respected, while mixed batches continue normally.

Reproduction

Before this change, a custom terminal tool could return:

return AgentToolResult(
    content=[TextContent(text="result accepted")],
    terminate=True,
)

The tool completed successfully, but the loop set has_more_tools from the presence of tool calls alone and made another provider request. With max_turns=1, the attempted follow-up also turned a successful run into Agent stopped after max_turns=1.

This is the same early-termination behavior fixed in Pi:

Validation

  • uv run pytest
  • uv run ruff check .
  • uv run ruff format --check .
  • uv run mypy

@d8rt8v
d8rt8v marked this pull request as ready for review July 21, 2026 19:59
@d8rt8v
d8rt8v requested a review from alejandro-ao as a code owner July 21, 2026 19:59
Copilot AI review requested due to automatic review settings July 21, 2026 19:59

Copilot AI 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.

Pull request overview

Updates Tau’s provider/tool agent loop to respect AgentToolResult.terminate, aligning early-termination behavior with Pi and preventing unnecessary follow-up model turns (especially under tight max_turns limits).

Changes:

  • Collects finalized tool execution results (ToolExecutionEndEvent.result) across the full tool-call batch.
  • Skips the automatic follow-up model turn only when all tool results explicitly request termination (terminate is True), while mixed batches continue normally.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/tau_agent/loop.py
Comment on lines +160 to +162
has_more_tools = bool(final_tool_results) and not all(
result.terminate is True for result in final_tool_results
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants