Initiate outbound conversations
TAC supports outbound (agent-initiated) conversations across all channels. Your agent can send the first message over SMS, WhatsApp, or RCS, or place an outbound voice call — then handle customer replies through the same on_message_ready callback used for inbound conversations.
- TAC SDK installed and configured with your Twilio credentials (see Add TAC to your agent)
- A running TAC server with channels configured (the server must be running to receive replies)
- For Voice:
TWILIO_VOICE_PUBLIC_DOMAINset to your public domain (for example, your ngrok domain) - For WhatsApp:
TWILIO_WHATSAPP_NUMBERset to your WhatsApp-enabled number (format:whatsapp:+1234567890) - For RCS:
TWILIO_RCS_SENDER_IDset to your RCS Sender ID
Send an SMS to a customer and handle their replies.
1from tac import TAC, TACConfig2from tac.channels.sms import SMSChannel, SMSChannelConfig3from tac.models.outbound import InitiateMessagingConversationOptions4from tac.server import TACFastAPIServer56tac = TAC(config=TACConfig.from_env())7sms_channel = SMSChannel(tac, config=SMSChannelConfig(memory_mode="always"))89async def handle_message_ready(message, context, memory):10# Called when the customer replies11llm_response = await your_llm.generate(message)12return llm_response1314tac.on_message_ready(handle_message_ready)1516# Initiate outbound SMS after server starts17result = await sms_channel.initiate_outbound_conversation(18InitiateMessagingConversationOptions(19to="+16505551234",20message="Hi! This is Acme Corp. Your order has shipped.",21)22)23print(f"Conversation started: {result.conversation_id}")2425# Start the TACFastAPIServer to receive replies26server = TACFastAPIServer(tac=tac, messaging_channels=[sms_channel])27server.start()
The initiate_outbound_conversation method creates a conversation through Conversation Orchestrator, adds both participants (customer and AI agent), and sends the initial message. When the customer replies, TAC routes their response to your on_message_ready callback.
Place an outbound voice call. The call connects to your TAC server's WebSocket endpoint, where Conversation Relay handles speech-to-text and text-to-speech.
1import os2from tac import TAC, TACConfig3from tac.channels.voice import VoiceChannel, VoiceChannelConfig4from tac.models.outbound import InitiateVoiceConversationOptions5from tac.server import TACFastAPIServer6from tac.server.config import TACServerConfig78tac = TAC(config=TACConfig.from_env())9voice_channel = VoiceChannel(tac, config=VoiceChannelConfig(memory_mode="always"))1011async def handle_message_ready(message, context, memory):12llm_response = await your_llm.generate(message)13return llm_response1415tac.on_message_ready(handle_message_ready)1617# Get public domain for WebSocket URL18server_config = TACServerConfig.from_env()19public_domain = server_config.public_domain2021# Initiate outbound voice call22result = await voice_channel.initiate_outbound_conversation(23InitiateVoiceConversationOptions(24to="+16505551234",25websocket_url=f"wss://{public_domain}/ws",26welcome_greeting="Hi! This is an AI assistant calling from Acme Corp.",27action_url=f"https://{public_domain}/conversation-relay-callback",28)29)30print(f"Call placed: {result.call_sid}")3132# Start the TACFastAPIServer to handle the call33server = TACFastAPIServer(tac=tac, voice_channel=voice_channel)34server.start()
The welcome_greeting (Python) or welcomeGreeting (TypeScript) is optional — if provided, Conversation Relay speaks it to the customer as soon as they pick up, before waiting for your agent to respond.
WhatsApp and RCS outbound follow the same pattern as SMS. Use the corresponding channel class and configure the required environment variable.
1from tac.channels.whatsapp import WhatsAppChannel, WhatsAppChannelConfig2from tac.channels.rcs import RCSChannel, RCSChannelConfig3from tac.models.outbound import InitiateMessagingConversationOptions45# WhatsApp — requires TWILIO_WHATSAPP_NUMBER env var6whatsapp_channel = WhatsAppChannel(tac, config=WhatsAppChannelConfig(memory_mode="always"))78result = await whatsapp_channel.initiate_outbound_conversation(9InitiateMessagingConversationOptions(10to="whatsapp:+16505551234",11message="Hi! Your appointment is confirmed for tomorrow at 2pm.",12)13)1415# RCS — requires TWILIO_RCS_SENDER_ID env var16rcs_channel = RCSChannel(tac, config=RCSChannelConfig(memory_mode="always"))1718result = await rcs_channel.initiate_outbound_conversation(19InitiateMessagingConversationOptions(20to="+16505551234",21message="Hi! Your appointment is confirmed for tomorrow at 2pm.",22)23)
Outbound conversations use the same on_message_ready callback as inbound conversations. When a customer replies to your outbound message or speaks during an outbound call, TAC delivers the message to your callback. You can distinguish inbound from outbound using the conversation session metadata if needed.
- Channels: Learn more about channel configuration and supported channels.
- Add TAC to your agent: Configure tools, knowledge, and memory alongside channels.