Basic Tool Definition
Define tools with the OpenAI-compatibletools array:
Execute the Tool
When the model chooses a tool, inspectmessage.tool_calls, parse the arguments, execute your application function, then send the result back as a tool message.
Python
Choose a Model
Function calling support is model-specific. Use the Text Models page or the Models API to find models withsupportsFunctionCalling.
Going Further
The example above stops after one round trip. Real agents keep going, because the model usually needs several tools before it can answer. Building a Tool-Using Agent with Function Calling works through the whole loop against a database the model has never seen, including parallel tool calls, returning errors the model recovers from, and the difference between a model that declines and a guard that refuses.Design Tips
- Keep tool names and descriptions short and literal.
- Use JSON Schema to make valid arguments easy for the model to produce.
- Prefer narrow tools with clear inputs over one broad tool with many optional behaviors.
- Return concise tool results so the final answer has enough context without wasting tokens.