Skip to content

fix: propagate error info from sub-agents to manager in ManagedAgent#2189

Open
Ricardo-M-L wants to merge 2 commits intohuggingface:mainfrom
Ricardo-M-L:fix/managed-agent-error-propagation
Open

fix: propagate error info from sub-agents to manager in ManagedAgent#2189
Ricardo-M-L wants to merge 2 commits intohuggingface:mainfrom
Ricardo-M-L:fix/managed-agent-error-propagation

Conversation

@Ricardo-M-L
Copy link
Copy Markdown

Summary

Fixes #2166

  • Problem: When a sub-agent hits tool errors or exhausts max_steps, ManagedAgent.__call__ returns empty/None to the manager. The manager cannot distinguish "completed with empty output" from "task failed", making informed retry decisions impossible.

  • Root cause: __call__ calls self.run() with default return_full_result=False, discarding RunResult.state. Error information stored in memory steps is never surfaced to the manager.

  • Fix:

    • __call__ now always requests RunResult to inspect the sub-agent's run state
    • New _collect_error_context() method inspects memory steps for: max_steps exhaustion, tool errors during execution, and empty results
    • Prepends structured [WARNING] headers to the managed agent response when issues are detected
    • Manager receives actionable context (error type, step info, agent name) to decide whether to retry or take alternative action

Changes

  • src/smolagents/agents.py: Modified __call__ (+12 lines), added _collect_error_context (+63 lines)
  • tests/test_agents.py: 7 new tests covering max_steps exhaustion, tool errors, successful runs, empty results, and unit tests for _collect_error_context

Test plan

  • Syntax validation passes
  • pytest tests/test_agents.py::TestManagedAgentErrorPropagation — all 7 tests
  • Existing tests unaffected (the change is additive — successful sub-agents see no behavioral difference)

🤖 Generated with Claude Code

@Ricardo-M-L
Copy link
Copy Markdown
Author

Gentle bump — this one fixes #2166: ManagedAgent.__call__ calls self.run() with default return_full_result=False, so when a sub-agent hits tool errors or exhausts max_steps, the manager sees an empty/None return and can't distinguish "completed empty" from "task failed". The fix surfaces RunResult.state upward. Happy to rebase or trim if needed. Thanks!

Copy link
Copy Markdown

@VANDRANKI VANDRANKI left a comment

Choose a reason for hiding this comment

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

Thanks for working on this - the problem is real. When ManagedAgent.__call__ silently returns an empty result on failure, the managing agent has no way to distinguish a task completion from a failure, which makes it hard to design reliable retry or escalation logic.

Rebase needed before review can continue

The diff currently shows src/smolagents/agents.py being deleted in its entirety (-1814 lines), with no replacement. This means the PR branch has diverged significantly from main and the actual code change is not visible in the diff. The only new content showing is the test file (+334 lines).

To unblock review:

  1. git fetch upstream && git rebase upstream/main on your branch
  2. Resolve any conflicts in agents.py (the file is still present on main at src/smolagents/agents.py)
  3. Force-push the rebased branch

Once rebased, the diff will show only the targeted changes to ManagedAgent.__call__ and the tests, which makes it reviewable.

The test class TestManagedAgentErrorPropagation that is visible in the diff looks well-structured - once the rebase is done and the implementation is visible I would be happy to continue the review.

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.

ManagedAgent swallows tool errors from sub-agents - manager sees empty/None result

2 participants