A Python framework for building agentic applications with Twilio
Project description
Twilio Agent Connect
A powerful SDK for building intelligent, context-aware AI agents with Twilio's communication technologies.
Seamlessly integrate with Twilio Conversation Memory and Conversation Orchestrator to build LLM-powered agents with persistent memory and conversation context.
[!TIP] Building AI agents on AWS or Microsoft? Connect them to Twilio's voice, messaging, and conversation context with these dedicated packages:
- TAC for AWS — Strands, Bedrock Agents, Bedrock AgentCore
- TAC for Microsoft — Microsoft Agent Framework, Azure AI Foundry (incl. Voice Live), Azure OpenAI
Key Features
- Multi-Channel Support: Built-in handling for Voice (ConversationRelay), SMS, RCS, WhatsApp, and Chat
- Outbound Conversations: Agent-initiated conversations across all supported channels
- ConversationRelay-Only Mode: Get started quickly with TAC's voice plumbing (TwiML, WebSocket, callbacks) before adding Conversation Orchestrator or Conversation Memory
- Memory Management: Automatic integration with Twilio Conversation Memory for persistent user context
- Conversation Lifecycle: Automatic tracking of conversation sessions and state
- Human Handoff: Built-in tool to route conversations to human agents via Twilio Studio Flows (including Flex)
Get Started
To get started, set up your Python environment (Python 3.10 or newer required), and then install TAC SDK package.
uv (Recommended)
We recommend using uv for the best development experience:
uv init
uv add git+https://github.com/twilio/twilio-agent-connect-python.git
# Install with server support (includes FastAPI and uvicorn for TACFastAPIServer)
uv add git+https://github.com/twilio/twilio-agent-connect-python.git --extra server
pip/venv (Alternative)
If you prefer using pip and venv:
python -m venv .venv
source .venv/bin/activate # On Windows: .venv\Scripts\activate
pip install git+https://github.com/twilio/twilio-agent-connect-python.git
# Install with server support
pip install "git+https://github.com/twilio/twilio-agent-connect-python.git[server]"
Quick Examples
Option 1: Use the Setup Wizard
Use the Twilio Setup Wizard to automatically create a Memory Store and Conversation Configuration and generate your .env file:
git clone https://github.com/twilio/twilio-agent-connect-python.git
cd twilio-agent-connect-python
make setup # Open http://localhost:8080
Option 2: Manual Setup
You can also create a Memory Store and Conversation Configuration manually through the Twilio Console. For a full walkthrough — credentials, Console navigation, and webhook configuration — see the TAC Quickstart.
After completing setup, here's a minimal example to get started:
Multi-Channel with OpenAI SDK
Use the OpenAI adapter to automatically inject conversation memory and user context into your OpenAI API calls across Voice, SMS, RCS, WhatsApp, and Chat channels.
First, install the required packages:
uv add openai python-dotenv
Note:
python-dotenvis optional — TAC works with environment variables from any source (.envfiles, Docker, Kubernetes, CI/CD, shell exports, etc.).
Then create your application:
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})
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()
Note: See the getting started guide for complete setup instructions and
.envconfiguration details.
That's it! The server automatically:
- Creates FastAPI app with
/twiml,/ws, and/webhookendpoints - Handles Voice, SMS, RCS, WhatsApp, and Chat conversations
- Routes responses to the appropriate channel
- Injects conversation memory and user profile into OpenAI calls
For configuration details and environment variables, see the getting started guide.
How It Works
TAC simplifies building AI agents by handling the integration between Twilio's communication channels and your LLM:
Message Flow
- Webhook/Connection Received: Twilio sends webhook (SMS) or WebSocket connection (Voice) to your server
- Channel Processing: Channel validates and processes the incoming event
- Memory Retrieval: TAC optionally retrieves user memories and profile from Memory
- Callback Invoked: Your
on_message_readycallback receives user message, context, and optional memory response - Response Handling: Your callback returns a response string that TAC routes to the appropriate channel
For detailed architecture and advanced usage, see CLAUDE.md.
Learn More
Examples & Guides:
- Getting Started Guide - Setup wizard, examples, and comprehensive documentation
- Partner SDK Examples - OpenAI Chat Completions and Responses API examples
- ConversationRelay-Only Mode - Get started with voice using just ConversationRelay
- More examples coming soon
AWS and Microsoft connectors:
- TAC for AWS —
StrandsConnector,BedrockConnector,BedrockAgentCoreConnectorfor AWS Strands, Bedrock Agents, and Bedrock AgentCore - TAC for Microsoft —
AgentFrameworkConnectorandVoiceLiveConnectorfor Microsoft Agent Framework, Azure AI Foundry (including Voice Live), and Azure OpenAI
Documentation:
- CLAUDE.md - Architecture, development guide, and API reference
- Getting Started Guide - Setup instructions, environment variables, and troubleshooting
TAC Development / Contribution
TAC uses uv for package management. Ensure you have it installed:
uv --version
Setup Development Environment
# Install all dependencies (including dev tools)
make sync
# Or manually with uv
uv sync --all-extras --all-groups
Running Tests and Checks
# Format code
make format
# Run linting
make lint
# Run type checking
make type-check
# Run tests
make test
# Run all checks at once
make check
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file twilio_agent_connect-1.0.1.tar.gz.
File metadata
- Download URL: twilio_agent_connect-1.0.1.tar.gz
- Upload date:
- Size: 85.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c17eb7f9c38e21bd55615baad1480708d4db1382e1f404516c73fa7b6bf8d85
|
|
| MD5 |
ba95fcd57200b5284f24bf4999fa0f4b
|
|
| BLAKE2b-256 |
2ff2792ac8115aa396ccbccf7dc109324718262c10df0b8bd730a503b0d2d75b
|
Provenance
The following attestation bundles were made for twilio_agent_connect-1.0.1.tar.gz:
Publisher:
deploy.yml on twilio/twilio-agent-connect-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
twilio_agent_connect-1.0.1.tar.gz -
Subject digest:
9c17eb7f9c38e21bd55615baad1480708d4db1382e1f404516c73fa7b6bf8d85 - Sigstore transparency entry: 1460950091
- Sigstore integration time:
-
Permalink:
twilio/twilio-agent-connect-python@ced2fcbe26a60a5c202ccf8b63f52185f976c548 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/twilio
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
deploy.yml@ced2fcbe26a60a5c202ccf8b63f52185f976c548 -
Trigger Event:
release
-
Statement type:
File details
Details for the file twilio_agent_connect-1.0.1-py3-none-any.whl.
File metadata
- Download URL: twilio_agent_connect-1.0.1-py3-none-any.whl
- Upload date:
- Size: 115.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a115c140f1fde2ab125bec7858cd1e8f009be18f2791248c8947cfe2e6417b44
|
|
| MD5 |
e101ba3a153164051f956dbb1981d769
|
|
| BLAKE2b-256 |
5b8acf17bcb06e1b24e421d5f657d12bd21738e065e6a1dab6d351a184960e69
|
Provenance
The following attestation bundles were made for twilio_agent_connect-1.0.1-py3-none-any.whl:
Publisher:
deploy.yml on twilio/twilio-agent-connect-python
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
twilio_agent_connect-1.0.1-py3-none-any.whl -
Subject digest:
a115c140f1fde2ab125bec7858cd1e8f009be18f2791248c8947cfe2e6417b44 - Sigstore transparency entry: 1460950293
- Sigstore integration time:
-
Permalink:
twilio/twilio-agent-connect-python@ced2fcbe26a60a5c202ccf8b63f52185f976c548 -
Branch / Tag:
refs/tags/v1.0.1 - Owner: https://github.com/twilio
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
deploy.yml@ced2fcbe26a60a5c202ccf8b63f52185f976c548 -
Trigger Event:
release
-
Statement type: