Skip to content

Support managed agents in ToolCallingAgent #1456

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jun 19, 2025

Conversation

albertvillanova
Copy link
Member

Support managed agents in ToolCallingAgent.

Fix #1455.
Fix #1353.
Supersede and close #1418.

@albertvillanova albertvillanova requested a review from Copilot June 19, 2025 08:34
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR adds support for managed agents in ToolCallingAgent, ensuring they are treated like tools when calling the model and surfaced in prompts.

  • Register managed agents as callable tools with input/output metadata
  • Update prompt templates to display each agent’s inputs and output type
  • Include managed agents in tools_to_call_from for both streaming and non-streaming calls

Reviewed Changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
tests/test_agents.py Added a test to verify that managed agents are passed to model.generate alongside tools
src/smolagents/prompts/toolcalling_agent.yaml Extended system prompt to list agent inputs and output types
src/smolagents/prompts/structured_code_agent.yaml Updated example agent signatures to include typed task argument and docstring
src/smolagents/prompts/code_agent.yaml Mirrored signature/docs update in code agent prompt
src/smolagents/agents.py In _setup_managed_agents, set inputs/output_type; merged managed agents into tools_to_call_from
Comments suppressed due to low confidence (2)

tests/test_agents.py:1089

  • Consider adding a complementary test for the non-streaming path (when stream=False) to verify that managed agents are also included in model.generate calls in that scenario.
    def test_toolcalling_agent_passes_both_tools_and_managed_agents(self, test_tool):

src/smolagents/prompts/toolcalling_agent.yaml:106

  • [nitpick] The indentation of these lines is deeper than the preceding list item. Align them with the bullet (-) for consistent prompt formatting.
      Takes inputs: {{agent.inputs}}

@@ -150,8 +150,12 @@ system_prompt: |-
Here is a list of the team members that you can call:
```python
{%- for agent in managed_agents.values() %}
def {{ agent.name }}("Your query goes here.") -> str:
"""{{ agent.description }}"""
def {{ agent.name }}(task: str) -> str:
Copy link
Collaborator

Choose a reason for hiding this comment

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

You can add additional_args here to hint the manager that it can pass other args:

Suggested change
def {{ agent.name }}(task: str) -> str:
def {{ agent.name }}(task: str, additional_args: dict[str, Any]) -> str:

Copy link
Member Author

@albertvillanova albertvillanova Jun 19, 2025

Choose a reason for hiding this comment

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

I guess this is a follow-up to:

I also guess this should be added to the ToolCallingAgent prompt as well...

Copy link
Member Author

Choose a reason for hiding this comment

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

I think I will treat that in a subsequent PR.


Args:
task: Long detailed description of the task.
"""
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
"""
additional_args: a dictionary of other variables to make available to your managed agent, e.g. images, or dataframes.
"""

Copy link
Member Author

Choose a reason for hiding this comment

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

I just noted that the images param is treated differently from the additional_args param in the run method.

Is this expected? I mean, if we can to pass images to the managed agent, should we use images or additional_args?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think I will treat that in a subsequent PR.

@albertvillanova albertvillanova merged commit 1da0527 into huggingface:main Jun 19, 2025
3 checks passed
@albertvillanova albertvillanova deleted the fix-1455 branch June 19, 2025 17:59
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.

[BUG] ToolCallingAgent ignores managed agents [BUG] Managed Agents aren't registered as tools
2 participants