Add more tools
A real travel assistant needs to speak multiple currencies. We could hardcode a conversion table, but this is a chance to bolt in an external MCP server as a tool. AutoGen does not care that the tool happens to be async and talks to another process.
async def convert_currency(
amount: float,
from_currency: str,
to_currency: str,
) -> str:
"""
Converts currency using an external MCP server.
Use when the user asks for prices in a different currency.
"""
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
server_params = StdioServerParameters(
command=sys.executable,
args=[os.path.join(os.path.dirname(__file__), "mcp_server.py")],
env=dict(os.environ),
)
async with stdio_client(server_params) as (read, write):
async with ClientSession(read, write) as session:
await session.initialize()
result = await session.call_tool(
"convert_currency",
arguments={
"amount": amount,
"from_currency": from_currency,
"to_currency": to_currency,
},
)
if result.content:
return result.content[0].text
return "No output from currency converter."The MCP server runs as a subprocess over stdio. AutoGen treats this async function exactly like any other tool. The model sees a clean signature; all the plumbing hides behind the function body.
AVAILABLE_TOOLS = [
lookup_booking,
search_hotels,
check_flight_status,
search_policies,
book_hotel,
book_taxi,
cancel_booking,
convert_currency,
]A single list of tools keeps the team config honest. Each specialist picks a slice of this list. New tools go in once and then get assigned to whichever specialist owns that capability.
AI prompt: Try it: test the supervisor with a mixed request
Loading practice…
Quiz: Quiz
Loading practice…