type: function) lets the agent call code you control - your database, an internal API, or any business logic.
You declare the function with a name, a description, and a JSON Schema for its parameters.
The model decides when to call it and fills in the arguments; you run the function and return the result so the run can continue.
Unlike built-in tools, the Agent API never executes your code.
When the model calls a custom function, the run pauses and hands the call back to you.
Define a custom tool
Declare the tool in thetools array. Set strict: true to enforce the parameter schema.
Read the function call
The run pauses and returns the call in the responseoutput array as a function_call item with the name and the arguments the model filled in:
Return the result
Pull that item off the response, run the function on your side, then continue the run by sending the result back. The follow-up request replays the conversation so far - the original question, thefunction_call the model emitted, and a function_call_output carrying your result under the same call_id:
call_id is the correlation key: the function_call the model emits and the function_call_output you return must carry the same value.
Set strict: true on the tool to enforce the parameter schema.
You continue the run by replaying the prior items in the input array - pass the function_call and its function_call_output together so the model sees its own request and your result.Next steps
Give it tools
The end-to-end how-to for wiring built-in, MCP, and custom tools into a run.
Tools overview
Every built-in tool, plus MCP servers and custom functions.