Source:
02_agent_with_tools.py · 02-agent-with-tools.tsDefine a tool
Attach tools to an agent
Inspect tool calls
Every tool invocation is captured inresult.meta:
Tips
- Return JSON-serializable data. Dicts, lists, and primitives work best, since the SDK serializes them for the model.
- Keep the docstring or description short. That text is what the model reads when it decides whether to call the tool.
- Errors are fine. If the function raises, the SDK reports the error to the model so it can recover or report back.
- Tool calls run in parallel by default. If the model issues several tool calls in one turn, the SDK runs them concurrently. Disable this with
parallel_tool_execution=False(Python) orparallelToolExecution: false(TS) on theAgent.