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-architect3version: 1.0.04description: 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.5author: matrixx00706tags: [twilio, ai, architecture, assistants, agent]7capabilities: []8metadata:9 source: https://skillmd.com/skills/matrixx0070/twilio-ai-agent-architect10---1112## When to use1314Use 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.1516**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).1718## Method19201. Decision point — build block:21 - You own the LLM and want maximum control over prompting, tools, and latency → ConversationRelay + your server. Most flexible; you operate the model.22 - 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.23 - You need something neither covers (custom media pipeline, on-prem model) → custom on `<Connect><Stream>` Media Streams, owning STT/TTS.242. 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.253. 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.264. Define guardrails: input/output filtering, refusal policy, PII redaction, max turn length, and cost/latency budgets. Voice needs tighter latency than chat.275. 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.286. Design state: what persists per session and across channels — route to twilio-conversation-orchestrator.297. 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).308. Decision point — go-live: pilot on one channel, measure containment/handoff rate and cost per session, then expand.3132## Example3334Sketch of an AI Assistant with a tool and knowledge, then attached to voice via ConversationRelay (conceptual REST):3536```bash37# Create the assistant38curl -X POST https://assistants.twilio.com/v1/Assistants \39 -u "$SID:$TOKEN" \40 -d "Name=support-agent" \41 -d "Personality=You are a concise, friendly support agent."4243# Register a tool (a webhook the assistant may invoke)44curl -X POST https://assistants.twilio.com/v1/Assistants/$AID/Tools \45 -u "$SID:$TOKEN" \46 -d "Name=lookup_order" \47 -d "Type=Webhook" \48 -d "Url=https://example.com/tools/lookup_order"4950# Attach knowledge for grounding51curl -X POST https://assistants.twilio.com/v1/Assistants/$AID/Knowledge \52 -u "$SID:$TOKEN" \53 -d "Name=faq" -d "Type=Web" -d "Url=https://example.com/faq"54```5556Voice entry point that routes the call into your agent brain:5758```xml59<Response>60 <Connect>61 <ConversationRelay url="wss://example.com/relay" ttsProvider="ElevenLabs" interruptible="true" />62 </Connect>63</Response>64```6566## Pitfalls6768- 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.69- 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.70- No handoff path: an agent with no escalation traps frustrated callers. Design the human exit before launch.71- Unbounded tool calls balloon latency and cost per turn; cap tool-call depth and set a budget.72- Assistants products are evolving; pin to documented, current endpoints and re-verify before production.73- Skipping observability means you cannot measure containment rate or debug bad turns after the fact.7475## Output format7677The 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.7879## Reference8081- Build blocks:82 - 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.83 - 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.84 - Custom Media Streams — `<Connect><Stream>` delivering base64 mulaw 8 kHz frames; you own the full STT/LLM/TTS pipeline.85- Channels: Programmable Voice, Programmable Messaging (SMS/MMS), WhatsApp Business, and web chat all attach to the same agent brain if you centralize state.86- Auth: HTTP Basic with Account SID + Auth Token (or API Key/Secret) on all REST calls.87- Cost model: standard per-minute voice / per-message rates, plus STT/TTS provider usage, plus your LLM tokens. Budget per session, not per request.88- 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.