From twilio-developer-kit
Connect third-party AI agents (OpenAI, Bedrock, LangChain, Microsoft Foundry) to Twilio's communication channels using the Twilio Agent Connect SDK. Covers identity resolution, memory and context management via Conversation Memory, conversation orchestration via Conversation Orchestrator, multi-channel handling (Voice, SMS, RCS, WhatsApp, Chat), and AI-to-human escalation. Use this skill when integrating an existing LLM agent with Twilio services.
npx claudepluginhub twilio/ai --plugin twilio-developer-kitThis skill uses the workspace's default tool permissions.
Twilio Agent Connect (TAC) is a Python and TypeScript SDK that integrates third-party LLM agentic applications with Twilio's communication technologies. TAC provides middleware for identity resolution, memory/context management (via Conversation Memory), conversation orchestration (via Conversation Orchestrator), and multi-channel handling (Voice, SMS, RCS, WhatsApp, Chat).
Guides Next.js Cache Components and Partial Prerendering (PPR): 'use cache' directives, cacheLife(), cacheTag(), revalidateTag() for caching, invalidation, static/dynamic optimization. Auto-activates on cacheComponents: true.
Guides building MCP servers enabling LLMs to interact with external services via tools. Covers best practices, TypeScript/Node (MCP SDK), Python (FastMCP).
Share bugs, ideas, or general feedback.
Twilio Agent Connect (TAC) is a Python and TypeScript SDK that integrates third-party LLM agentic applications with Twilio's communication technologies. TAC provides middleware for identity resolution, memory/context management (via Conversation Memory), conversation orchestration (via Conversation Orchestrator), and multi-channel handling (Voice, SMS, RCS, WhatsApp, Chat).
Key Architecture Principle: TAC is not an agent runtime itself—it's middleware that enables existing LLM applications (OpenAI Agents SDK, Bedrock, LangChain, Microsoft Foundry, etc.) to leverage Twilio Conversations services.
TAC integrates with three core Twilio Conversations services:
Conversation Memory (Memory Store) - Persistent user context and memory management
Conversation Orchestrator - Multi-channel conversation lifecycle management
Enterprise Knowledge - Knowledge base integration
TAC provides built-in support for:
All channels support both inbound (customer-initiated) and outbound (agent-initiated) conversations.
TAC supports a simplified "ConversationRelay-only" mode for getting started with voice conversations without requiring Conversation Orchestrator or Conversation Memory setup. This mode provides:
Requirements: Python 3.10+
# Using uv (recommended)
uv add git+https://github.com/twilio/twilio-agent-connect-python.git
# With server support (includes FastAPI and uvicorn for TACFastAPIServer)
uv add git+https://github.com/twilio/twilio-agent-connect-python.git --extra server
# Using pip
pip install git+https://github.com/twilio/twilio-agent-connect-python.git
pip install "git+https://github.com/twilio/twilio-agent-connect-python.git[server]"
Requirements: Node.js 22.13+
# Clone and build (not yet published to npm)
git clone https://github.com/twilio/twilio-agent-connect-typescript.git
cd twilio-agent-connect-typescript
npm install
npm run build
from dotenv import load_dotenv
from openai import AsyncOpenAI
from tac import TAC, TACConfig
from tac.adapters.openai import with_tac_memory
from tac.channels.sms import SMSChannel
from tac.channels.voice import VoiceChannel
from tac.server import TACFastAPIServer
load_dotenv()
tac = TAC(config=TACConfig.from_env())
voice_channel = VoiceChannel(tac)
sms_channel = SMSChannel(tac)
openai_client = AsyncOpenAI()
conversation_history = {}
SYSTEM_INSTRUCTIONS = (
"You are a customer service agent speaking with a user over voice or SMS. "
"Keep responses short and conversational — a sentence or two. "
"Do not use markdown, asterisks, bullets, or emojis; your words will be "
"spoken aloud or sent as plain text."
)
async def handle_message_ready(user_message, context, memory_response):
conv_id = context.conversation_id
if conv_id not in conversation_history:
conversation_history[conv_id] = []
conversation_history[conv_id].append({"role": "user", "content": user_message})
# Inject conversation memory and profile into OpenAI client
client = with_tac_memory(openai_client, memory_response, context)
response = await client.responses.create(
model="gpt-5.4-mini",
instructions=SYSTEM_INSTRUCTIONS,
input=conversation_history[conv_id]
)
llm_response = response.output_text
conversation_history[conv_id].append({"role": "assistant", "content": llm_response})
return llm_response
tac.on_message_ready(handle_message_ready)
TACFastAPIServer(tac=tac, voice_channel=voice_channel, messaging_channels=[sms_channel]).start()
import { config } from 'dotenv';
import OpenAI from 'openai';
import {
TAC,
TACConfig,
VoiceChannel,
SMSChannel,
TACServer,
MemoryPromptBuilder,
} from 'twilio-agent-connect';
config();
const openai = new OpenAI();
const tac = await TAC.create({ config: TACConfig.fromEnv() });
const voiceChannel = new VoiceChannel(tac);
const smsChannel = new SMSChannel(tac);
tac.registerChannel(voiceChannel);
tac.registerChannel(smsChannel);
const conversationHistory: Record<string, OpenAI.Chat.ChatCompletionMessageParam[]> = {};
const SYSTEM_INSTRUCTIONS =
'You are a customer service agent speaking with a user over voice or SMS. ' +
'Keep responses short and conversational — a sentence or two. ' +
'Do not use markdown, asterisks, bullets, or emojis; your words will be ' +
'spoken aloud or sent as plain text.';
tac.onMessageReady(async ({ conversationId, message, memory, session }) => {
const convId = conversationId as string;
if (!conversationHistory[convId]) {
conversationHistory[convId] = [];
}
const memoryContext = MemoryPromptBuilder.build(memory, session);
const systemPrompt = SYSTEM_INSTRUCTIONS + (memoryContext ? `\n\n${memoryContext}` : '');
conversationHistory[convId].push({ role: 'user', content: message });
const response = await openai.chat.completions.create({
model: 'gpt-4o-mini',
messages: [
{ role: 'system', content: systemPrompt },
...conversationHistory[convId],
],
});
const llmResponse = response.choices[0]?.message?.content ?? '';
conversationHistory[convId].push({ role: 'assistant', content: llmResponse });
return llmResponse;
});
const server = new TACServer(tac);
await server.start();
# Twilio Account Credentials
TWILIO_ACCOUNT_SID=ACxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
TWILIO_AUTH_TOKEN=your_auth_token
TWILIO_API_KEY=SKxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
TWILIO_API_SECRET=your_api_key_secret
# Conversation Configuration
TWILIO_CONVERSATION_CONFIGURATION_ID=conv_configuration_xxxx
# Phone Number
TWILIO_PHONE_NUMBER=+1234567890
# Server Configuration (for Voice)
TWILIO_VOICE_PUBLIC_DOMAIN=your-domain.ngrok.io
# Conversation Memory (optional)
TWILIO_MEMORY_STORE_ID=mem_service_xxxx
TWILIO_TRAIT_GROUPS=Contact,Preferences
Package: twilio-agent-connect-aws
Connect AWS agent services to Twilio channels:
# With Strands SDK
pip install twilio-agent-connect-aws[strands,server]
# With Bedrock Agents
pip install twilio-agent-connect-aws[bedrock,server]
# With Bedrock AgentCore
pip install twilio-agent-connect-aws[agentcore,server]
Features:
Repository: https://github.com/twilio/twilio-agent-connect-aws
Package: twilio-agent-connect-microsoft (formerly tac-azure)
Connect Microsoft Foundry agents to Twilio channels:
# With Agent Framework
pip install twilio-agent-connect-microsoft[agent-framework,server]
# With Voice Live
pip install twilio-agent-connect-microsoft[voice-live,server]
Features:
response.cancelRepository: https://github.com/twilio/twilio-agent-connect-microsoft
Automatic integration with Twilio Conversation Memory for persistent user context:
Automatic tracking of conversation sessions and state:
on_message_ready callback receives user message, context, and optional memory responseTAC supports agent-initiated conversations across all channels:
TAC handles the full ConversationRelay WebSocket protocol:
The Voice Live connector provides:
i-twilio-idempotency-token headerTAC provides unified handling across SMS, RCS, WhatsApp, and Chat:
on_message_ready callback for all channelsProcess Conversation Intelligence operator results to create observations and summaries:
from tac.core.config import ConversationIntelligenceConfig
config = TACConfig.from_env()
config.conversation_intelligence_config = ConversationIntelligenceConfig(
configuration_id="your_ci_configuration_id",
observation_operator_sid="LY...",
summary_operator_sid="LY...",
)
@app.post("/ci-webhook")
async def ci_webhook_handler(request: Request):
payload = await request.json()
result = await tac.process_conversation_intelligence_event(payload)
return result.model_dump()
TAC provides built-in tools for common operations:
You can also create custom tools using the @function_tool decorator:
from tac.tools import function_tool
@function_tool()
def send_email(recipient: str, subject: str, body: str) -> bool:
"""
Sends an email to a recipient.
Args:
recipient: Email address
subject: Email subject
body: Email body
Returns:
True on success, False on failure
"""
# Implementation here
return True
TAC provides adapters for automatic memory injection into LLM runtimes:
Python OpenAI Adapter:
from tac.adapters.openai import with_tac_memory
client = with_tac_memory(openai_client, memory_response, context)
# Memory and profile automatically injected into system messages
TypeScript Memory Prompt Builder:
import { MemoryPromptBuilder } from 'twilio-agent-connect';
const memoryContext = MemoryPromptBuilder.build(memory, session);
const systemPrompt = SYSTEM_INSTRUCTIONS + `\n\n${memoryContext}`;
TAC includes a web-based setup wizard to automatically create required Twilio services:
# Python SDK
git clone https://github.com/twilio/twilio-agent-connect-python.git
cd twilio-agent-connect-python
make setup # Opens http://localhost:8080
The wizard creates:
.env file with all required credentialsBuild an AI-powered customer support agent with:
Create an agent that initiates conversations:
Replace traditional IVR with conversational AI:
Build globally accessible agents:
TAC provides lenient error handling:
Memory not retrieving:
TWILIO_MEMORY_STORE_ID is setTWILIO_TAC_LOG_LEVEL=DEBUGVoice not connecting:
TWILIO_VOICE_PUBLIC_DOMAIN is accessibleDuplicate messages:
Channel isolation issues:
configuration_id filtering is enabledMIT License - see repository LICENSE files for details.