function_tool
__name__, the prose above its
Args: block, and its type hints — so a well-written docstring is what
the model sees.
Agent subclass are registered automatically; tools defined
elsewhere go in Agent(tools=[...]).
By default an interruption cancels the tool: if the caller talks over the
agent while it runs, the tool sees asyncio.CancelledError at its next
await and its result is discarded. Declare cancel_on_interrupt=False
for work that must not be cut off halfway, such as a payment: the tool runs
to completion, and what the caller said meanwhile is answered afterwards.
Override the exposed name. Everything else the model is told comes off the function itself.
Whether the caller talking over the agent cancels the tool while it runs. Defaults to True.
MCPServerStdio
A local MCP server, run as a subprocess and spoken to over stdio.Fields
Environment for the child.
None inherits this process’s, which is usually what you want: the server needs the same API keys you already have.Seconds to wait for the connection and for each tool call. The vendor’s default is 5, which is tight for a server that starts an interpreter; its own examples pass 30.
Always
stdio. Set for you — it is what tells the SDK which transport to connect with.MCPServerHTTP
A remote MCP server, reached over HTTP.Fields
Sent with every request — an API key usually lives here. Read in this process, so the credential stays with you.
Seconds a quiet stream may stay open. Long by default: an MCP server that has nothing to say is not broken.