When to use
Use this when you are deciding the shape of a Twilio AI agent before writing implementation code: which building block to stand on, how the LLM connects to tools and knowledge, which channels attach, and how humans take over. This is a design skill — it makes the architecture decisions and then routes you to sibling skills for the wiring.
Not for: the ConversationRelay WebSocket protocol itself (see twilio-voice-conversation-relay); connecting a live agent handoff leg (see twilio-agent-connect); or session/state orchestration across turns and channels (see twilio-conversation-orchestrator).
Method
- Decision point — build block:
- You own the LLM and want maximum control over prompting, tools, and latency → ConversationRelay + your server. Most flexible; you operate the model.
- You want Twilio to host the assistant, knowledge, and tool orchestration with less code → Twilio AI Assistants (LLM-backed, with Tools + Knowledge, attachable to channels). Note: an evolving product; confirm current GA status and limits before committing.
- You need something neither covers (custom media pipeline, on-prem model) → custom on
<Connect><Stream> Media Streams, owning STT/TTS.
- Map channels: voice (ConversationRelay or Assistants voice attachment), SMS/MMS, WhatsApp, and web chat. Decide which are in scope and whether one agent brain serves all.
- Design the LLM layer: system prompt, tool schema, and retrieval. With Assistants, register Tools (webhooks the assistant may call) and Knowledge (documents/URLs for grounding). With ConversationRelay, you implement tools and RAG in your own server.
- Define guardrails: input/output filtering, refusal policy, PII redaction, max turn length, and cost/latency budgets. Voice needs tighter latency than chat.
- Design handoff to human: detection trigger (intent, sentiment, explicit request), then transfer the voice leg or escalate the messaging thread — route to twilio-agent-connect for the live leg.
- Design state: what persists per session and across channels — route to twilio-conversation-orchestrator.
- Observability: log every turn (prompt, tool calls, tokens, latency), capture recordings for QA (twilio-call-recordings), and wire status callbacks. Add feedback capture (Assistants exposes a feedback endpoint).
- Decision point — go-live: pilot on one channel, measure containment/handoff rate and cost per session, then expand.
Example
Sketch of an AI Assistant with a tool and knowledge, then attached to voice via ConversationRelay (conceptual REST):
# Create the assistant
curl -X POST https://assistants.twilio.com/v1/Assistants \
-u "$SID:$TOKEN" \
-d "Name=support-agent" \
-d "Personality=You are a concise, friendly support agent."
# Register a tool (a webhook the assistant may invoke)
curl -X POST https://assistants.twilio.com/v1/Assistants/$AID/Tools \
-u "$SID:$TOKEN" \
-d "Name=lookup_order" \
-d "Type=Webhook" \
-d "Url=https://example.com/tools/lookup_order"
# Attach knowledge for grounding
curl -X POST https://assistants.twilio.com/v1/Assistants/$AID/Knowledge \
-u "$SID:$TOKEN" \
-d "Name=faq" -d "Type=Web" -d "Url=https://example.com/faq"
Voice entry point that routes the call into your agent brain:
<Response>
<Connect>
<ConversationRelay url="wss://example.com/relay" ttsProvider="ElevenLabs" interruptible="true" />
</Connect>
</Response>
Pitfalls
- Choosing Assistants for its convenience, then hitting a hard limit that forces a rewrite onto ConversationRelay — validate tool/knowledge/latency limits against your requirements first.
- Treating voice like chat: voice demands sub-second first-token latency and barge-in; a chat-tuned prompt that streams slowly feels broken on a call.
- No handoff path: an agent with no escalation traps frustrated callers. Design the human exit before launch.
- Unbounded tool calls balloon latency and cost per turn; cap tool-call depth and set a budget.
- Assistants products are evolving; pin to documented, current endpoints and re-verify before production.
- Skipping observability means you cannot measure containment rate or debug bad turns after the fact.
Output format
The deliverable of this skill is an architecture decision, not runtime output: a chosen build block, a channel map, an LLM/tool/knowledge wiring plan, guardrail and handoff policies, and an observability plan — each pointing at the sibling skill that implements it.
Reference
- Build blocks:
- ConversationRelay — TwiML
<Connect><ConversationRelay>; you bring the LLM, Twilio does STT/TTS over a WebSocket. Lowest-level of the managed options, most control. See twilio-voice-conversation-relay.
- Twilio AI Assistants — REST under
https://assistants.twilio.com/v1/Assistants with sub-resources: /Assistants/{Sid}/Tools, /Assistants/{Sid}/Knowledge, plus feedback. LLM-backed assistants with hosted tools and knowledge, attachable to voice (via ConversationRelay), messaging, and web. Successor line to Autopilot; treat as evolving and verify GA/limits.
- Custom Media Streams —
<Connect><Stream> delivering base64 mulaw 8 kHz frames; you own the full STT/LLM/TTS pipeline.
- Channels: Programmable Voice, Programmable Messaging (SMS/MMS), WhatsApp Business, and web chat all attach to the same agent brain if you centralize state.
- Auth: HTTP Basic with Account SID + Auth Token (or API Key/Secret) on all REST calls.
- Cost model: standard per-minute voice / per-message rates, plus STT/TTS provider usage, plus your LLM tokens. Budget per session, not per request.
- Route implementation: voice protocol → twilio-voice-conversation-relay; live human handoff leg → twilio-agent-connect; cross-turn/cross-channel session state → twilio-conversation-orchestrator; QA recording → twilio-call-recordings.
1---2name: twilio-ai-agent-architect3description: Design a Twilio AI voice and messaging agent end to end — choosing ConversationRelay vs AI Assistants vs custom, wiring LLM plus tools and knowledge, channels, guardrails, handoff, and observability.4---56## When to use78Use this when you are deciding the shape of a Twilio AI agent before writing implementation code: which building block to stand on, how the LLM connects to tools and knowledge, which channels attach, and how humans take over. This is a design skill — it makes the architecture decisions and then routes you to sibling skills for the wiring.910**Not for:** the ConversationRelay WebSocket protocol itself (see twilio-voice-conversation-relay); connecting a live agent handoff leg (see twilio-agent-connect); or session/state orchestration across turns and channels (see twilio-conversation-orchestrator).1112## Method13141. Decision point — build block:15 - You own the LLM and want maximum control over prompting, tools, and latency → ConversationRelay + your server. Most flexible; you operate the model.16 - You want Twilio to host the assistant, knowledge, and tool orchestration with less code → Twilio AI Assistants (LLM-backed, with Tools + Knowledge, attachable to channels). Note: an evolving product; confirm current GA status and limits before committing.17 - You need something neither covers (custom media pipeline, on-prem model) → custom on `<Connect><Stream>` Media Streams, owning STT/TTS.182. Map channels: voice (ConversationRelay or Assistants voice attachment), SMS/MMS, WhatsApp, and web chat. Decide which are in scope and whether one agent brain serves all.193. Design the LLM layer: system prompt, tool schema, and retrieval. With Assistants, register Tools (webhooks the assistant may call) and Knowledge (documents/URLs for grounding). With ConversationRelay, you implement tools and RAG in your own server.204. Define guardrails: input/output filtering, refusal policy, PII redaction, max turn length, and cost/latency budgets. Voice needs tighter latency than chat.215. Design handoff to human: detection trigger (intent, sentiment, explicit request), then transfer the voice leg or escalate the messaging thread — route to twilio-agent-connect for the live leg.226. Design state: what persists per session and across channels — route to twilio-conversation-orchestrator.237. Observability: log every turn (prompt, tool calls, tokens, latency), capture recordings for QA (twilio-call-recordings), and wire status callbacks. Add feedback capture (Assistants exposes a feedback endpoint).248. Decision point — go-live: pilot on one channel, measure containment/handoff rate and cost per session, then expand.2526## Example2728Sketch of an AI Assistant with a tool and knowledge, then attached to voice via ConversationRelay (conceptual REST):2930```bash31# Create the assistant32curl -X POST https://assistants.twilio.com/v1/Assistants \33 -u "$SID:$TOKEN" \34 -d "Name=support-agent" \35 -d "Personality=You are a concise, friendly support agent."3637# Register a tool (a webhook the assistant may invoke)38curl -X POST https://assistants.twilio.com/v1/Assistants/$AID/Tools \39 -u "$SID:$TOKEN" \40 -d "Name=lookup_order" \41 -d "Type=Webhook" \42 -d "Url=https://example.com/tools/lookup_order"4344# Attach knowledge for grounding45curl -X POST https://assistants.twilio.com/v1/Assistants/$AID/Knowledge \46 -u "$SID:$TOKEN" \47 -d "Name=faq" -d "Type=Web" -d "Url=https://example.com/faq"48```4950Voice entry point that routes the call into your agent brain:5152```xml53<Response>54 <Connect>55 <ConversationRelay url="wss://example.com/relay" ttsProvider="ElevenLabs" interruptible="true" />56 </Connect>57</Response>58```5960## Pitfalls6162- Choosing Assistants for its convenience, then hitting a hard limit that forces a rewrite onto ConversationRelay — validate tool/knowledge/latency limits against your requirements first.63- Treating voice like chat: voice demands sub-second first-token latency and barge-in; a chat-tuned prompt that streams slowly feels broken on a call.64- No handoff path: an agent with no escalation traps frustrated callers. Design the human exit before launch.65- Unbounded tool calls balloon latency and cost per turn; cap tool-call depth and set a budget.66- Assistants products are evolving; pin to documented, current endpoints and re-verify before production.67- Skipping observability means you cannot measure containment rate or debug bad turns after the fact.6869## Output format7071The deliverable of this skill is an architecture decision, not runtime output: a chosen build block, a channel map, an LLM/tool/knowledge wiring plan, guardrail and handoff policies, and an observability plan — each pointing at the sibling skill that implements it.7273## Reference7475- Build blocks:76 - ConversationRelay — TwiML `<Connect><ConversationRelay>`; you bring the LLM, Twilio does STT/TTS over a WebSocket. Lowest-level of the managed options, most control. See twilio-voice-conversation-relay.77 - Twilio AI Assistants — REST under `https://assistants.twilio.com/v1/Assistants` with sub-resources: `/Assistants/{Sid}/Tools`, `/Assistants/{Sid}/Knowledge`, plus feedback. LLM-backed assistants with hosted tools and knowledge, attachable to voice (via ConversationRelay), messaging, and web. Successor line to Autopilot; treat as evolving and verify GA/limits.78 - Custom Media Streams — `<Connect><Stream>` delivering base64 mulaw 8 kHz frames; you own the full STT/LLM/TTS pipeline.79- Channels: Programmable Voice, Programmable Messaging (SMS/MMS), WhatsApp Business, and web chat all attach to the same agent brain if you centralize state.80- Auth: HTTP Basic with Account SID + Auth Token (or API Key/Secret) on all REST calls.81- Cost model: standard per-minute voice / per-message rates, plus STT/TTS provider usage, plus your LLM tokens. Budget per session, not per request.82- Route implementation: voice protocol → twilio-voice-conversation-relay; live human handoff leg → twilio-agent-connect; cross-turn/cross-channel session state → twilio-conversation-orchestrator; QA recording → twilio-call-recordings.