Skip to content
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

Multi agents with manager #32687

Merged
merged 13 commits into from
Sep 4, 2024
Merged

Multi agents with manager #32687

merged 13 commits into from
Sep 4, 2024

Conversation

aymeric-roucher
Copy link
Contributor

What does this PR do?

Add native support for multi-agents in a tree-like hierarchic structure, by allowing an agent to manage other agents and call them as if they were tools.

cc @LysandreJik and @plaggy

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@plaggy
Copy link
Contributor

plaggy commented Aug 16, 2024

@aymeric-roucher did you consider wrapping managed agents as tools, the way you did with Gaia? Would passing a separate list of managed agents be beneficial in some way?

@aymeric-roucher
Copy link
Contributor Author

@plaggy passing the list of agents as tools works as done on GAIA, but it leads to confusion between managed agents and tools, which leads to errors.
For instance if you use a search agent and name it search_agent, when building tool descriptions, search_agent being amongst tools means that your manager agent will understand it should be called the same way as tools. So instead of giving it detailed and complex requests as it would do for an agent (something like "Give me the 3rd player listed on the Denver Nuggets homepage from the 15th of October"), it will give it minimal requests as for a normal google search : "3rd player Denver Nuggets", and thus get suboptimal results. This bad behaviour persists even if you prompt it correctly in the description like" this is not a tool but an agent, give it detailed explanations"

This is why passing managed agents as a different argument than tools is mandatory IMO.

error_msg = f"Error: unknown tool {tool_name}, should be instead one of {list(self.toolbox.tools.keys())}."
available_tools = self.toolbox.tools
if self.managed_agents is not None:
available_tools = {**available_tools, **self.managed_agents}
Copy link
Contributor

Choose a reason for hiding this comment

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

looks like this part can be moved to self.toolbox() since it's a dedicated function for that

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'd prefer to leave managed agents as a separate thing from Tools, since they're supposed to be handled differently here.

@@ -337,6 +352,7 @@ def __init__(
verbose: int = 0,
memory_verbose: bool = False,
grammar: Dict[str, str] = None,
managed_agents: List = None,
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this supposed to be a list of ManagedAgent objects? It'd help to have some hints on how/where ManagedAgent is designed to be used

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes it's supposed to be! Since ManagedAgent is not defined yet, I have a chicken-and-egg definition problem, that's why I did not put a type hint. But if you have an idea on how to do this hint i'll include it!

@plaggy
Copy link
Contributor

plaggy commented Aug 20, 2024

@plaggy passing the list of agents as tools works as done on GAIA, but it leads to confusion between managed agents and tools, which leads to errors. For instance if you use a search agent and name it search_agent, when building tool descriptions, search_agent being amongst tools means that your manager agent will understand it should be called the same way as tools. So instead of giving it detailed and complex requests as it would do for an agent (something like "Give me the 3rd player listed on the Denver Nuggets homepage from the 15th of October"), it will give it minimal requests as for a normal google search : "3rd player Denver Nuggets", and thus get suboptimal results. This bad behaviour persists even if you prompt it correctly in the description like" this is not a tool but an agent, give it detailed explanations"

This is why passing managed agents as a different argument than tools is mandatory IMO.

@aymeric-roucher is the idea to provide agents-as-tools a verbose description of the task in a prompt so they'd perform better?
The implementation makes sense to me! Left a couple of comments

@LysandreJik
Copy link
Member

@aymeric-roucher let me know when you'd like me to review this PR!

@aymeric-roucher aymeric-roucher force-pushed the multi-agents-with-manager branch from e0bc2fe to 8ed5ebd Compare August 30, 2024 15:12
@aymeric-roucher
Copy link
Contributor Author

@LysandreJik this is ready for review! 🤗
File agents.py is becoming quite big with the addition of planning and ManagedAgent : at some point we might have to export both these components to other files.

Copy link
Member

@LysandreJik LysandreJik left a comment

Choose a reason for hiding this comment

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

Nice work! Yes, no problem for me to either split the module in several or to have a specific folder to host different modules/objects

@aymeric-roucher aymeric-roucher merged commit 2cb543d into main Sep 4, 2024
24 checks passed
@aymeric-roucher aymeric-roucher deleted the multi-agents-with-manager branch September 4, 2024 15:30
itazap pushed a commit to NielsRogge/transformers that referenced this pull request Sep 20, 2024
* Add Multi agents with a hierarchical system
BernardZach pushed a commit to BernardZach/transformers that referenced this pull request Dec 5, 2024
* Add Multi agents with a hierarchical system
BernardZach pushed a commit to innovationcore/transformers that referenced this pull request Dec 6, 2024
* Add Multi agents with a hierarchical system
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants