agent-connect
Skill2 starsChanged 8 months agoMITView on GitHub
Twilio development skill: agent-connect
- Reads credentials
- Installs packages
In this repository66 other files it gives its agents.
- adversarial-reviewSkill
- agent-teams-guideSkill
- agent-testingSkill
- android-sdkSkill
- brainstormSkill
- branded-callingSkill
- callbacksSkill
- compliance-regulatorySkill
- conferenceSkill
- context-engineeringSkill
- context-hubSkill
- conversational-intelligenceSkill
- conversation-relay-referenceSkill
- conversation-relaySkill
- conversationrelaySkill
- conversations-v2Skill
- customer-memorySkill
- deepgramSkill
- deep-validationSkill
- elastic-sip-trunkingSkill
- env-doctorSkill
- event-streamsSkill
- getting-startedSkill
- hooks-referenceSkill
- iamSkill
- ios-sdkSkill
- ivr-crawlerSkill
- ivr-migratorSkill
- lookupSkill
- media-streamsSkill
- memory-systemsSkill
- messaging-services-referenceSkill
- messaging-servicesSkill
- messagingSkill
- multi-agent-patternsSkill
- operational-gotchasSkill
- paymentsSkill
- paySkill
- phone-numbersSkill
- proxySkill
- real-time-transcriptionSkill
- recordingsSkill
- segmentSkill
- sendgrid-emailSkill
- sip-byocSkill
- sipSkill
- sync-referenceSkill
- syncSkill
- taskrouter-referenceSkill
- taskrouterSkill
- tdd-workflowSkill
- tool-boundariesSkill
- twilio-cliSkill
- twilio-invariantsSkill
- verify-referenceSkill
- verifySkill
- video-patternsSkill
- videoSkill
- voice-insightsSkill
- voice-referenceSkill
- The first 60 shown.
The file
We split this skill into the rules it gives an agent
7 rules. About 0 are common, 3 are distinctive, and 4 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈3
Distinctive · estimate
This author's own choices. Worth a look.
4
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 28
Create and manage conversations automatically via Conversations Orchestrator
- Distinctive: line 29
Write to Customer Memory via MemoryClient (observations, traits — added post-initial-docs)
- Very specific: line 179
ngrok free plan URL changes on restart: Must update phone number webhook config each restart.
- Very specific: line 186
SMS retrieves memory automatically per inbound message: No opt-out — if TWILIO_TAC_MEMORY_STORE_ID is set, every SMS triggers a Recall.
- Very specific: line 192
TwiML
<Redirect>causes double conversation creation: When a TwiML router returns <Redirect> to /twiml, Twilio makes two POST requests. - Very specific: line 198
createHandoffTool() requires destination configuration: Must pre-configure which queue/number/agent pool receives escalated calls.
- Distinctive: line 199
Handoff context carries Memory profile: When handing off to a human agent, the profile ID and Recall context are available to the receiving …
≈ “Common” is an estimate: at least 1 in 5 of the 213,895 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
name: agent-connect description: Twilio Agent Connect (TAC) SDK development guide. Use when building LLM-powered voice/SMS agents with automatic Customer Memory retrieval and Conversations Orchestrator integration. Do NOT use for direct Conversations layer API calls (use /customer-memory, /conversations-v2, /conversational-intelligence instead). allowed-tools: mcp__twilio__*, Read, Grep, Glob, Bash
Twilio Agent Connect (TAC)
SDK middleware that orchestrates voice (ConversationRelay) and SMS (Conversations API) channels with automatic Customer Memory retrieval and Intelligence analysis. You bring the LLM; TAC handles channel I/O, session management, memory retrieval, and conversation tracking.
Generally available — TypeScript (Node 20+) and Python (3.9+). Not PCI/HIPAA compliant.
Evidence: Assertion audit sourced from TAC documentation (2026-03-25) + live integration testing. See references/assertion-audit.md for provenance. Note: assertions are DOC-VERIFIED, not SID-backed. Live testing recommended for production decisions.
Scope
CAN
- Orchestrate voice calls via ConversationRelay WebSocket — STT/TTS handled by Twilio
- Orchestrate SMS via Conversations API webhooks — message routing automated
- Retrieve Customer Memory (observations, summaries, communications) per message/utterance
- Provide unified callback: same
handleMessageReady(userMessage, context, memoryResponse?)across channels - Create and manage conversations automatically via Conversations Orchestrator
- Write to Customer Memory via MemoryClient (observations, traits — added post-initial-docs)
- Handoff to human agents via
createHandoffTool()andonHandoffcallback - Support any LLM provider (OpenAI, Anthropic, Bedrock, LangChain)
- Active voice ingestion via
TWILIO_TAC_ENABLE_VOICE_ACTIVE_HYDRATION=true
CANNOT
- No custom STT/TTS — Uses ConversationRelay defaults; cannot specify Deepgram, ElevenLabs, etc. For custom providers, use ConversationRelay directly.
- No raw audio access — WebSocket is abstracted; only transcribed text exposed. Use Media Streams if you need audio.
- No ConversationRelay protocol events —
setup,interrupt,dtmfevents are not passed through to your callback. Only transcribed speech arrives. - No WhatsApp/Email/Chat channels — Only voice and SMS. For other channels, use the Conversations layer API directly (see Twilio Conversations documentation and the
/conversations-v2skill). - No MCP tools — TAC SDK is not wrapped in the MCP server. Interact via the SDK directly in your application code.
- No mid-conversation provider switch — Cannot change LLM or TTS mid-call through TAC.
- Voice memory auto-retrieval is broken —
TWILIO_TAC_ENABLE_VOICE_ACTIVE_HYDRATIONis documented but has a known bug where context returnsundefined. Use manual Recall via Customer Memory API at call setup instead.
Quick Decision
| Need | Use | Why |
| LLM agent with voice + SMS + auto memory | Agent Connect | Purpose-built SDK, unified callback |
| LLM voice agent with custom STT/TTS | ConversationRelay directly | TAC doesn't expose provider config |
| LLM agent with WhatsApp/Email/Chat | Conversations API directly | TAC only supports voice + SMS |
| Simple IVR without LLM | TwiML <Gather> | No LLM needed |
| Memory retrieval without TAC orchestration | Customer Memory API | Direct REST calls, full control |
| Agent assist during human calls | Intelligence v3 webhooks | TAC is for AI-first agents, not human assist |
Decision Frameworks
TAC SDK vs Direct API
| Criterion | TAC SDK | Direct Conversations API |
| Setup effort | Low — npm install + env vars | High — implement WebSocket handler, webhook routing, Memory calls manually |
| Channel support | Voice + SMS only | All 6 channels (SMS, Voice, WhatsApp, RCS, Chat, Email) |
| Memory control | Automatic retrieval, configurable limits | Full control — choose when/what to Recall |
| Provider config | No control (TAC defaults) | Full control — choose STT/TTS/model |
| Context budget | TAC defaults (obs:10, sum:5, session:3) | You set limits per Recall call |
| Handoff | Built-in createHandoffTool() | Implement yourself (add HUMAN_AGENT participant) |
| Intelligence | Automatic via Conversations config | Same — linked at config level |
| Best for | Quick prototypes, standard voice/SMS agents | Production systems needing full control |
Context Budget Management
TAC passes full memory context to your LLM with no built-in truncation. Default limits:
| Parameter | TAC Default | Recall API Default | Recommendation |
| observation_limit | 10 | 20 | Keep TAC default for voice (latency) |
| summary_limit | 5 | 5 | Sufficient for most agents |
| session_limit | 3 | N/A (TAC-only) | Increase for long customer histories |
| query | None (fast path) | None | Add semantic query for focused retrieval |
Estimated token impact (per turn):
| Scenario | Observations | Summaries | Est. Tokens | % of 128K |
| First-time caller | 0 | 0 | ~100 | <0.1% |
| Returning customer | 10 | 2 | ~2,000-3,000 | ~2% |
| Long-term customer (full limits) | 10 | 5 | ~3,000-5,000 | ~3% |
Architecture
┌─────────────────────────────────────────────────────────────┐
│ Your Application │
│ ┌─────────────┐ ┌──────────────────────────────────────┐ │
│ │ Your LLM │ │ handleMessageReady() callback │ │
│ │ (OpenAI, │◄─┤ - userMessage: string │ │
│ │ Anthropic, │ │ - context: ConversationSession │ │
│ │ Bedrock) │ │ - memoryResponse?: MemoryResponse │ │
│ └──────┬──────┘ └──────────────────┬───────────────────┘ │
│ │ response │ │
│ ▼ │ │
│ voiceChannel.sendResponse() smsChannel.sendResponse() │
└─────────┼─────────────────────────────────────────┼─────────┘
│ │
▼ ▼
┌───────────────┐ ┌──────────────┐ ┌───────────────────┐
│ Twilio Voice │ │ Twilio │ │ Twilio Customer │
│ Conversation │ │ Conversations│ │ Memory Service │
│ Relay (WSS) │ │ API (HTTP) │ │ (HTTP) │
└───────────────┘ └──────────────┘ └───────────────────┘Setup
Prerequisites
- Node 20+ (TypeScript) or Python 3.9+
- Twilio Account SID + Auth Token (or API Key + Secret)
- Phone number with voice webhook → your server
/twiml - Conversations Configuration with phone number assigned for SMS → webhook
/webhook - ngrok or public URL for webhook delivery
- (Optional) Customer Memory Store ID for memory features
TypeScript Quickstart
npm install twilio-agent-connectimport { AgentConnect, VoiceChannel, SMSChannel } from 'twilio-agent-connect';
const agent = new AgentConnect({
accountSid: process.env.TWILIO_ACCOUNT_SID,
authToken: process.env.TWILIO_AUTH_TOKEN,
memoryStoreId: process.env.TWILIO_TAC_MEMORY_STORE_ID, // Optional
});
const voiceChannel = new VoiceChannel(agent);
const smsChannel = new SMSChannel(agent);
async function handleMessageReady(
userMessage: string,
context: ConversationSession,
memoryResponse?: MemoryRetrievalResponse,
): Promise<void> {
// Your LLM logic here
const response = await myLLM.chat(userMessage, {
systemPrompt: buildPrompt(memoryResponse),
});
if (context.channel === 'voice') {
voiceChannel.sendResponse(context.conversationId, response);
} else {
smsChannel.sendResponse(context.conversationId, response);
}
}
// Voice: /twiml endpoint returns <Connect><ConversationRelay> TwiML
// SMS: /webhook endpoint receives Conversations API webhooksEnvironment Variables
| Variable | Required | Description |
TWILIO_ACCOUNT_SID | Yes | Account SID |
TWILIO_AUTH_TOKEN | Yes | Auth Token (or use API Key) |
TWILIO_TAC_MEMORY_STORE_ID | No | Memory Store ID for auto-retrieval |
TWILIO_TAC_ENABLE_VOICE_ACTIVE_HYDRATION | No | true to enable voice memory (buggy — see gotcha #6) |
ENVIRONMENT | No | Must be prod or omitted. dev breaks DNS resolution. |
Gotchas
Environment & Setup
- ENVIRONMENT must be
prodor omitted: TAC SDK reads this env var and constructs hostnames likeconversations.dev-us1.twilio.comwhich don't resolve. Always useprod. [conversations-invariants.md] - Swapping /webhook and /twiml paths produces silent failures: Voice expects ConversationRelay TwiML at
/twiml; SMS expects webhook POST at/webhook. Swapping them results in no errors but no functionality. - ngrok free plan URL changes on restart: Must update phone number webhook config each restart. Use
ngrok http 8000 --url=your-static-domainfor stable URLs (requires paid plan). - Verify ngrok tunnel before debugging: A dead tunnel returns HTML 404 that mimics server 404. Verify:
curl -s -o /dev/null -w "%{http_code}" -X POST https://DOMAIN/healthmust return 200. [conversations-invariants.md]
Memory & Context
- Memory retrieval is all-or-nothing per the default config: TAC retrieves observations + summaries + communications in one call. Configure limits via env vars or SDK options.
- Voice memory auto-retrieval is broken:
TWILIO_TAC_ENABLE_VOICE_ACTIVE_HYDRATION=truedocumented but returnsundefinedfor memory context. Workaround: Call Customer Memory Recall API manually during WebSocketsetupevent. - SMS retrieves memory automatically per inbound message: No opt-out — if
TWILIO_TAC_MEMORY_STORE_IDis set, every SMS triggers a Recall. Budget accordingly. - TAC defaults: obs=10, sum=5, session=3: Lower than direct Recall API defaults (obs=20, sum=5, comms=0). For richer context, use direct API instead.
- No query parameter in TAC memory retrieval: TAC uses fast-path Recall (~37ms, no semantic search). For semantic Recall, bypass TAC and call the API directly.
Voice Channel
- TwiML
<Redirect>causes double conversation creation: When a TwiML router returns<Redirect>to/twiml, Twilio makes two POST requests. Both hit TAC and each creates a conversation (409 Conflict on second). Serve ConversationRelay TwiML directly from the router instead. [conversations-invariants.md] - ConversationRelay gotchas apply to TAC voice: TAC uses CR under the hood — interruption handling, DTMF detection, and TTS behavior all follow CR rules. See ConversationRelay skill for details.
- No intermediate STT confidence scores: TAC only exposes final transcribed text, not partial results or confidence levels.
Handoff
- createHandoffTool() requires destination configuration: Must pre-configure which queue/number/agent pool receives escalated calls.
- Handoff context carries Memory profile: When handing off to a human agent, the profile ID and Recall context are available to the receiving agent via the Conversations API.
Integration Patterns
Manual Memory Retrieval (Voice — Workaround for Gotcha #6)
// Since TAC voice auto-retrieval is broken, manually fetch at call setup
import { recallMemory, resolveCustomer } from './conversations-client';
voiceChannel.onSetup(async (callSid, from) => {
const profileId = await lookupProfile(config, 'phone', from);
if (profileId) {
const memory = await recallMemory(config, profileId);
// Store in session state for use in handleMessageReady
sessions.set(callSid, { memory });
}
});Direct Conversations API for Extra Channels
For WhatsApp, Email, Chat — TAC doesn't support these, but you can build the same pattern using the Conversations layer directly. See the Twilio Conversations documentation and the /conversations-v2 skill for the full API surface needed (profile lookup, Recall, and communication injection across all 6 channel types).
LLM Provider Selection
TAC is LLM-agnostic — you bring your own model via the handleMessageReady() callback. The demos in this project support configurable LLM endpoints.
Decision Tree
| Scenario | Provider | Config |
| Default / fastest setup | Anthropic | No env changes needed |
| Customer requires Azure deployment (BAA) | Azure OpenAI | LLM_PROVIDER=openai-compatible, LLM_BASE_URL=https://...azure.com/... |
| Air-gapped / on-prem | vLLM or Ollama | LLM_PROVIDER=openai-compatible, LLM_BASE_URL=http://internal:8000/v1 |
| Local development (zero cost) | Ollama | LLM_PROVIDER=openai-compatible, LLM_BASE_URL=http://localhost:11434/v1 |
Environment Variables
Set LLM_PROVIDER=openai-compatible plus LLM_BASE_URL, LLM_API_KEY, and LLM_MODEL to target any OpenAI-compatible endpoint. See the ConversationRelay skill for the full env var reference and example configurations.
Implementation
A shared LLM client pattern can provide streaming and non-streaming functions for both Anthropic and OpenAI-compatible endpoints, then be imported by both voice (ConversationRelay WebSocket handler) and SMS (Conversations webhook handler) for unified message processing across channels.
Related Resources
/conversationrelayskill — Voice AI WebSocket protocol details/customer-memoryskill — Memory API deep dive/conversations-v2skill — Conversation Orchestrator integration/conversational-intelligenceskill — Real-time analysis on top of conversations- Twilio Agent Connect docs
twilio-agent-connectnpm package
Reference Files
| Topic | File | When to read |
| Architecture & callbacks | references/architecture-and-callbacks.md | Understanding TAC internals, ConversationSession fields, channel lifecycles |
| Assertion audit | references/assertion-audit.md | Verifying claim provenance (DOC-VERIFIED, not live-tested) |
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

