Skip to main content
Tools let your agent perform actions and retrieve information. The SDK supports three tool paradigms that differ in how they affect conversation flow.

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.
Use for: Information retrieval, calculations, API queries.

Passthrough Tools (@passthrough_tool)

Output events go directly to the user, bypassing the LLM. Use for deterministic actions.
Use for: Call control (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.
Use for: Custom multi-step flows, specialized handlers with their own logic. When using a handoff tool, the event parameter receives different values depending on timing:
  • First call: event is AgentHandedOff — use this to send a transition message
  • Subsequent calls: event is the actual InputEvent (UserTurnEnded, etc.)
Once a handoff occurs, the original agent no longer receives events. The handoff tool function handles all future conversation turns.
To hand off to another LlmAgent, use the agent_as_handoff helper instead of writing a raw @handoff_tool. It handles the delegation automatically.

Built-in Tools

Examples:
See Knowledge Base for uploading documents and the full parameter list.

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.
By default, 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.

agent_as_handoff

Creates a handoff tool from another Agent—the easiest way to implement multi-agent workflows.
When called, 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.
See Advanced Patterns for a complete multi-agent example with loopback, passthrough, and handoff tools.

HTTP Server Tools

Use http_server_tool to call an HTTP API from JSON schemas, without writing a tool function.
Use for: Connecting an agent to an existing REST API, such as creating tickets, looking up orders, or triggering webhooks.

Parameters

Schema format

Both request_body_schema and query_params_schema take "type": "object" and a "properties" dict. Each property supports: List the properties the LLM must fill in a top-level required array. Properties not listed are optional. Path parameters are always required. Set constant_value at any nesting depth in request_body_schema:

Path and query parameters

Path parameters come from {param} in the URL as required strings. Use path_params_schema for custom descriptions or types:
For GET requests, set the query string with query_params_schema:

Response format

The tool returns structured JSON to the LLM. A 2xx status sets ok to true with the response under body; any other status, connection error, or timeout sets ok to false with the detail under error. Responses over 4096 characters are truncated.
Inputs are validated when you construct the tool. Malformed schemas, missing ${ENV_VAR} values, type mismatches, and parameter name collisions raise ValueError.

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, set is_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.
The built-in knowledge_base tool accepts is_background too, so the agent can keep talking while a retrieval is in flight:
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