Implementation:Microsoft Autogen AgentTool TeamTool
| Knowledge Sources | |
|---|---|
| Domains | Agent Composition, Hierarchical Systems, Tool Use, Multi-Agent Systems |
| Last Updated | 2026-02-11 00:00 GMT |
Overview
Concrete tools for wrapping agents and multi-agent teams as callable tools provided by Microsoft AutoGen, enabling hierarchical agent composition through the standard tool-calling interface.
Description
AgentTool wraps a single BaseChatAgent as a tool. When called by a parent agent's LLM, the tool runs the wrapped agent with the tool input as the task message and returns the agent's result. The tool's name and description are derived from the wrapped agent's name and description.
TeamTool wraps an entire BaseGroupChat (a multi-agent team) as a tool. Unlike AgentTool, it requires explicit name and description parameters because teams may not have meaningful intrinsic names. When called, the tool runs the full team conversation with the tool input as the initial task and returns the team's result.
Both classes extend TaskRunnerTool, which provides the common logic for running a task runner (agent or team) and collecting results. The return_value_as_last_message parameter controls whether the tool returns only the last message from the agent/team (concise mode) or the concatenation of all messages (full mode). Concise mode is useful when the parent agent has limited context window, while full mode provides maximum information.
Both tools are serializable via the component configuration system, allowing them to be saved and loaded as part of agent configurations.
Usage
Use AgentTool when you want a parent agent to delegate tasks to a single specialist agent. Use TeamTool when you want a parent agent to delegate tasks to an entire multi-agent team. Pass the resulting tool instances to the parent agent's tools parameter.
Code Reference
Source Location
- Repository: Microsoft AutoGen
- File (AgentTool):
python/packages/autogen-agentchat/src/autogen_agentchat/tools/_agent.py(lines 79-83) - File (TeamTool):
python/packages/autogen-agentchat/src/autogen_agentchat/tools/_team.py(lines 112-116)
Signature
# AgentTool
class AgentTool:
def __init__(
self,
agent: BaseChatAgent,
return_value_as_last_message: bool = False,
) -> None:
...
# TeamTool
class TeamTool:
def __init__(
self,
team: BaseGroupChat,
name: str,
description: str,
return_value_as_last_message: bool = False,
) -> None:
...
Import
from autogen_agentchat.tools import AgentTool, TeamTool
I/O Contract
Inputs (AgentTool)
| Name | Type | Required | Description |
|---|---|---|---|
| agent | BaseChatAgent | Yes | The agent to wrap as a tool. The tool's name and description are derived from the agent's name and description properties.
|
| return_value_as_last_message | bool | No | If True, the tool returns only the last message from the agent's response. If False (default), it returns the concatenation of all messages in the task result. |
Inputs (TeamTool)
| Name | Type | Required | Description |
|---|---|---|---|
| team | BaseGroupChat | Yes | The multi-agent team to wrap as a tool. The team will be run with the tool input as the initial task. |
| name | str | Yes | The name of the tool as presented to the parent agent's LLM. Required because teams may not have meaningful intrinsic names. |
| description | str | Yes | A natural-language description of what the team does. The parent agent's LLM uses this to decide when to delegate to the team. |
| return_value_as_last_message | bool | No | If True, the tool returns only the last message from the team's result. If False (default), it returns the concatenation of all messages. |
Outputs
| Name | Type | Description |
|---|---|---|
| instance | AgentTool or TeamTool | A tool instance that implements BaseTool. When invoked, it runs the wrapped agent or team and returns the result as a string.
|
Usage Examples
AgentTool Basic Example
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.tools import AgentTool
from autogen_ext.models.openai import OpenAIChatCompletionClient
model_client = OpenAIChatCompletionClient(model="gpt-4o")
# Create a specialist agent
poet_agent = AssistantAgent(
name="poet",
model_client=model_client,
system_message="You are a poet. Write poems on the given topic.",
description="A poet that writes poems on any topic.",
)
# Wrap as a tool for a parent agent
poet_tool = AgentTool(agent=poet_agent)
# Create a parent agent that can delegate to the poet
parent_agent = AssistantAgent(
name="coordinator",
model_client=model_client,
tools=[poet_tool],
)
TeamTool Example
from autogen_agentchat.agents import AssistantAgent
from autogen_agentchat.teams import RoundRobinGroupChat
from autogen_agentchat.tools import TeamTool
from autogen_ext.models.openai import OpenAIChatCompletionClient
model_client = OpenAIChatCompletionClient(model="gpt-4o")
# Create a research team
researcher = AssistantAgent(
name="researcher",
model_client=model_client,
system_message="Research the given topic thoroughly.",
)
writer = AssistantAgent(
name="writer",
model_client=model_client,
system_message="Write a summary based on the research.",
)
research_team = RoundRobinGroupChat(
participants=[researcher, writer],
max_turns=4,
)
# Wrap the team as a tool
research_tool = TeamTool(
team=research_team,
name="research_team",
description="A research team that investigates a topic and writes a summary.",
return_value_as_last_message=True,
)
# Parent agent can now delegate research tasks
supervisor = AssistantAgent(
name="supervisor",
model_client=model_client,
tools=[research_tool],
)