Skip to content

A programming framework for agentic AI

Update readme with agent-as-tool (#6949)

Eric Zhudb10c9dd2c06
diff --git a/README.md b/README.md
index b57aeb31e..5cb2b948a 100644
--- a/README.md
+++ b/README.md
@@ -43,7 +43,7 @@ from autogen_agentchat.agents import AssistantAgent
from autogen_ext.models.openai import OpenAIChatCompletionClient
async def main() -> None:
- model_client = OpenAIChatCompletionClient(model="gpt-4o")
+ model_client = OpenAIChatCompletionClient(model="gpt-4.1")
agent = AssistantAgent("assistant", model_client=model_client)
print(await agent.run(task="Say 'Hello World!'"))
await model_client.close()
@@ -90,6 +90,58 @@ asyncio.run(main())
> **Warning**: Only connect to trusted MCP servers as they may execute commands
> in your local environment or expose sensitive information.
+### Multi-Agent Orchestration
+
+You can use `AgentTool` to create a basic multi-agent orchestration setup.
+
+```python
+import asyncio
+
+from autogen_agentchat.agents import AssistantAgent
+from autogen_agentchat.tools import AgentTool
+from autogen_agentchat.ui import Console
+from autogen_ext.models.openai import OpenAIChatCompletionClient
+
+
+async def main() -> None:
+ model_client = OpenAIChatCompletionClient(model="gpt-4.1")
+
+ math_agent = AssistantAgent(
+ "math_expert",
+ model_client=model_client,
+ system_message="You are a math expert.",
+ description="A math expert assistant.",
+ model_client_stream=True,
+ )
+ math_agent_tool = AgentTool(math_agent, return_value_as_last_message=True)
+
+ chemistry_agent = AssistantAgent(
+ "chemistry_expert",
+ model_client=model_client,
+ system_message="You are a chemistry expert.",
+ description="A chemistry expert assistant.",
+ model_client_stream=True,
+ )
+ chemistry_agent_tool = AgentTool(chemistry_agent, return_value_as_last_message=True)
+
+ agent = AssistantAgent(
+ "assistant",
+ system_message="You are a general assistant. Use expert tools when needed.",
+ model_client=model_client,
+ model_client_stream=True,
+ tools=[math_agent_tool, chemistry_agent_tool],
+ max_tool_iterations=10,
+ )
+ await Console(agent.run_stream(task="What is the integral of x^2?"))
+ await Console(agent.run_stream(task="What is the molecular weight of water?"))
+
+
+asyncio.run(main())
+```
+
+For more advanced multi-agent orchestrations and workflows, read
+[AgentChat documentation](https://microsoft.github.io/autogen/stable/user-guide/agentchat-user-guide/index.html).
+
### AutoGen Studio
Use AutoGen Studio to prototype and run multi-agent workflows without writing code.