TAC overview
Twilio Agent Connect (TAC) is an SDK that connects your LLM application to Twilio's communication channels, Conversation Memory, and Conversation Orchestrator. TAC works with any LLM provider or agent framework, including OpenAI, AWS Bedrock, and Microsoft Foundry.
You can use TAC to build applications in Python or TypeScript.
TAC is not an agent runtime. It acts as middleware, enabling your existing LLM application to use Twilio Platform services without managing the underlying infrastructure.
TAC handles the integration complexity between your AI agent and Twilio's platform so you can focus on your agent's intelligence:
- Unified channel access: Connect your agent to Twilio's communication channels through a single interface. TAC handles WebSocket connections for Voice and webhook processing for messaging.
- Built-in memory and context: Retrieve customer profiles, conversation history, and trait data from Conversation Memory with each interaction. Your agent can personalize responses without building its own memory layer.
- Custom tools and knowledge: Define custom tools your agent can call at runtime, and use built-in tools for Enterprise Knowledge search, memory retrieval, and escalation to human agents.
- Escalation to human agents: Transfer conversations from your AI agent to a human agent in Twilio Flex when the situation requires it, with full context preserved.
- LLM-agnostic: TAC works with any LLM provider. Use the dedicated AWS Bedrock or Microsoft Foundry integration packages, the built-in OpenAI adapter, or integrate with any other provider through the
MemoryPromptBuilder.
Without TAC, connecting an AI agent to Twilio channels requires building and maintaining:
- Webhook infrastructure: HTTP server with endpoints for each channel, Twilio signature validation, payload parsing, and channel-based routing logic.
- Conversations API coordination: Parsing conversation lifecycle events (
COMMUNICATION_CREATED,PARTICIPANT_ADDED,CONVERSATION_UPDATED), managing participants, and handling conversation state. - Memory API integration: Profile lookup by phone number, memory retrieval with queries, observation storage, conversation summaries, and graceful degradation when the Memory API is unavailable.
- Voice-specific complexity: WebSocket server for Conversation Relay, TwiML generation, speech-to-text message parsing, and call lifecycle management.
- Session management: Tracking active conversations per channel, mapping conversation IDs to profile IDs, and cleaning up sessions on conversation end.
TAC automates all of this. You register channels, define a message callback, and start the server:
1tac = TAC(config=TACConfig.from_env())2voice_channel = VoiceChannel(tac, config=VoiceChannelConfig(memory_mode="always"))3sms_channel = SMSChannel(tac, config=SMSChannelConfig(memory_mode="always"))45async def handle_message(message, context, memory):6response = await your_llm(message, memory)7return response # TAC routes the response to the correct channel automatically89tac.on_message_ready(handle_message)1011# TACFastAPIServer registers webhook and WebSocket routes for configured channels12server = TACFastAPIServer(tac=tac, voice_channel=voice_channel, messaging_channels=[sms_channel])13server.start()
You focus on your agent's business logic — TAC handles the infrastructure.
TAC uses a modular architecture with the following components:
- TAC Core: Central orchestration layer that coordinates with Conversation Memory and Conversations, handles callback registration, and provides helper methods for memory retrieval and profile fetching.
- Conversation Orchestration: Conversation orchestration and management through Conversation Orchestrator.
- Conversation Memory: Memory retrieval and trait-based user profiles through Conversation Memory.
- Channels: Voice and messaging (SMS, WhatsApp, RCS, Chat) channel abstraction layer. Voice uses Conversation Relay WebSocket connections for real-time streaming. Messaging channels process events from Conversations.
- Tools: Function-based tool system that your agent can call at runtime, including built-in tools for knowledge search, memory management, and escalation.
- ConversationSession: Session context with profile, memory, channel, and conversation state passed to every callback.
TAC tracks active conversations in instance-local memory. This works perfectly for single-instance deployments but has implications for multi-instance deployments behind a load balancer.
The issue: Webhooks may route to a different instance than the one that handled the initial connection or message. This prevents proper conversation cleanup and can cause memory leaks.
Recommended solutions:
- Shared state store (recommended): Implement a shared conversation state layer using Redis, DynamoDB, or a database. This ensures all instances can access conversation state regardless of which instance receives the webhook.
- Hash-based routing: Configure your load balancer to route requests by
conversation_idso all webhooks for a conversation reach the same instance.- nginx: Use
hash $conversation_iddirective
- nginx: Use
For production deployments with multiple instances, implement one of these solutions before going live.
- API credentials: Store
TWILIO_API_KEYandTWILIO_API_SECRETin a secrets manager (AWS Secrets Manager, Azure Key Vault, HashiCorp Vault) rather than environment variables. - Webhook signature validation: Enable Twilio webhook signature validation in production to prevent unauthorized requests.
- TLS/SSL: All webhook endpoints must use HTTPS in production.
TAC provides built-in logging. Enable debug logging during development:
TWILIO_LOG_LEVEL=DEBUG
For production monitoring, track:
- Conversation latency (time between user message and agent response)
- Memory retrieval time
- Channel-specific error rates
- WebSocket connection failures (Voice)
- Python: 3.10 or later
- TypeScript: Node 22.13.0 or later
- TAC for AWS: Connectors for Strands, Bedrock Agents, and Bedrock AgentCore
- TAC for Microsoft: Connectors for Microsoft Agent Framework and Azure AI Foundry Voice Live
- Quickstart: Build and test a TAC application from scratch.
- Add TAC to your agent: Connect your existing agent and configure channels, tools, knowledge, and memory.
- Core concepts: Understand TAC's architecture and component relationships.