What is an Agent?
An Agent controls the input/output event loop. Theprocess method receives events (user speech, call start, etc.) and yields responses.
An Agent can be:
- A class with a
processmethod - A function with the same signature
(env, event) -> AsyncIterable[OutputEvent]
- Events arrive (user speaks, call starts, button pressed)
- SDK calls
agent.process(env, event) - Agent yields output events (speech, tool calls, handoffs)
- SDK handles audio, LLM calls, and state management
LlmAgent
Use the built-inLlmAgent which wraps 100+ LLM providers via LiteLLM:
Prompting
system_prompt to define your agent’s personality and introduction for the greeting:
Supported Models
LlmConfig Options
History Management
LlmAgent exposes a history attribute for structured control over the conversation history the LLM sees.
Adding entries:
Per-Turn Overrides
process() accepts keyword arguments that apply to just that turn without mutating the agent:
LlmConfig fields take effect — unset fields fall through to the agent’s stored config.
To change tools permanently (e.g., enabling end_call after a certain point), modify agent.tools directly instead of using per-turn overrides.
Controlling the Conversational Loop
Use event filters to control when your agent’sprocess method runs, and which events can interrupt it.
Default Behavior
Customizing Filters
Return a tuple fromget_agent to override defaults:
Common Customizations
More responsive (process partial transcriptions):interruptible=False when sending it with AgentSendText.
Handling Incoming Calls
When a call arrives, you can inspect caller information and configure how your agent responds before it starts.- A call arrives from a web client or telephony provider
- Your
pre_call_handlerreceives aCallRequestwith caller details - You return configuration (voice, language) or reject the call
- Your
get_agentfunction creates an agent using the enriched request
Parsing the CallRequest
Contains information about the incoming call:
The
agent field contains an AgentConfig with:
Returning a PreCallResult
Usepre_call_handler to set voice, language, or reject calls before your agent starts:
pre_call_handler reads this and configures TTS/STT accordingly.
Configuration Options
TTS Options:
STT Options:
Rejecting Calls
ReturnNone to reject a call with a 403 status:
Custom Pronunciations
Use a pronunciation dictionary to control how specific words are spoken:Accessing call metadata in your Agent logic
TheCallRequest is available in get_agent:
LlmConfig.from_call_request() handles the priority chain automatically:
CallRequest.agent.system_promptvalue (if set)- Your fallback value (if provided)
- SDK default
CallRequest lets you iterate on system prompts from the Playground instantly, while code handles the technical configuration and fallback defaults.
Letting The User Speak First
Setintroduction to an empty string to wait for the user to speak first: