Tools let your agent perform actions and retrieve information. The SDK supports three tool paradigms that differ in how they affect conversation flow.Documentation Index
Fetch the complete documentation index at: https://docs.cartesia.ai/llms.txt
Use this file to discover all available pages before exploring further.
Defining Tools
Any properly annotated function can be a tool. The SDK uses the function’s docstring as the description and type annotations for parameters:The first parameter of every tool must be
ctx (the tool context). This provides access to conversation state and is required for forward compatibility. Your tool parameters follow after ctx.Tool Types
Plain functions passed to
tools are automatically wrapped as loopback tools. Use decorators (@loopback_tool, @passthrough_tool, @handoff_tool) for explicit control.Loopback Tools (@loopback_tool)
The default behavior. The tool’s result is sent back to the LLM, which can then continue generating a response.
Passthrough Tools (@passthrough_tool)
Output events go directly to the user, bypassing the LLM. Use for deterministic actions.
EndCall, TransferCall, SendDtmf), deterministic responses.
Handoff Tools (@handoff_tool)
Transfers control to another handler. All future events are routed to the handoff target instead of the original agent.
event parameter receives different values depending on timing:
- First call:
eventisAgentHandedOff— use this to send a transition message - Subsequent calls:
eventis the actualInputEvent(UserTurnEnded, etc.)
Built-in Tools
| Tool | Description | When to Use |
|---|---|---|
end_call | Ends the call | User says “goodbye” or the agent’s objective has been met |
transfer_call | Transfers to another number (E.164 format) | Escalating to human agents, routing to departments |
web_search | Searches the web for real-time info | Current events, live prices, recent news the LLM doesn’t know |
end_call
Ends the current call and disconnects. The actual hangup occurs after the agent’s final speech completes, so the user hears the full goodbye message before disconnection.
end_call uses a conservative policy that only ends the call when:
- The user’s objective is fully complete
- The user explicitly says goodbye
- The agent has said a natural goodbye
Custom Description
We recommend providing a custom description tailored to your use case. The description fully replaces the default—it is not appended—so include complete instructions with explicit do/don’t guidance.| Parameter | Type | Description |
|---|---|---|
description | Optional[str] | Fully replaces the default description. Include complete instructions for when the LLM should end the call. |
agent_as_handoff
Creates a handoff tool from another Agent—the easiest way to implement multi-agent workflows.
| Parameter | Type | Description |
|---|---|---|
agent | Agent | The agent to hand off to |
handoff_message | Optional[str] | Message spoken before the handoff |
update_call | Optional[UpdateCallConfig] | Optional config to update call settings (voice, pronunciation, language) before handoff |
name | Optional[str] | Tool name for the LLM |
description | Optional[str] | When the LLM should use this tool |
agent_as_handoff automatically sends the handoff message, updates the call settings if specified, triggers the new agent’s introduction, and routes all future events to it.
Long-Running Tools
By default, tool calls are terminated when the agent is interrupted (though any reasoning and tool call response values already produced are preserved for use in the next generation). For tools that are expected to take a long time to complete, setis_background=True. The tool will continue running in the background until completion regardless of interruptions, then loop back to the LLM to produce a response.
Background tools are useful when:
- The operation may take longer than typical user patience (e.g., complex searches, report generation)
- You want the user to be able to speak while the operation completes
- The result should be delivered even if the user interrupts with another question