Follow these steps to create your AI voice outbound agent using the latest technologies.
Install the required Python libraries for the Retell AI integration.
pip install retell-ai aiohttp
Authenticate with your Retell AI API key.
import retell client = retell.Client(api_key="your_api_key")
Define your agent's persona and conversation flow.
agent_config = { "initial_message": "Hello, this is Alex from Customer Support.", "voice": "male-1", "persona": "friendly and professional" }
Configure the agent to use CSM-1B model.
agent_config["llm"] = { "model": "csm-1b", "provider": "sesame" }
Initiate the call with recipient's phone number.
response = client.calls.create( phone_number="+15551234567", agent_config=agent_config )
Handle call events and responses.
@client.on("call.connected") async def handle_connected(call): print(f"Call connected: {call.id}") @client.on("agent.response") async def handle_response(response): print(f"Agent said: {response.text}")
Here's the full implementation you can use as a starting point.
import asyncio
import retell
# Initialize client with your API key
client = retell.Client(api_key="your_api_key_here")
# Configure your agent
agent_config = {
"initial_message": "Hello, this is Alex calling from Customer Support.",
"voice": "male-1",
"persona": "friendly and professional",
"llm": {
"model": "csm-1b",
"provider": "sesame"
}
}
# Event handlers
@client.on("call.connected")
async def handle_connected(call):
print(f"Call {call.id} connected to {call.phone_number}")
@client.on("agent.response")
async def handle_response(response):
print(f"Agent response: {response.text}")
@client.on("call.ended")
async def handle_ended(call):
print(f"Call {call.id} ended")
async def make_call():
try:
# Start the call
response = await client.calls.create(
phone_number="+15551234567", # Replace with actual number
agent_config=agent_config
)
print(f"Call initiated: {response.id}")
except Exception as e:
print(f"Error making call: {e}")
# Run the call
asyncio.run(make_call())
Ensure your API key is correct and has proper permissions. Rotate keys if needed.
Use E.164 format (+[country code][number]) for phone numbers.
Check Retell AI documentation for latest supported models if CSM-1B isn't available.
Sign up on Retell AI to get started with the Sesame CSM-1B model today.
Visit Retell AI