twilio-agent-connect 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ MIT License
2
+
3
+ Copyright (C) 2026, Twilio Inc. <https://www.twilio.com/help/contact>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
9
+ of the Software, and to permit persons to whom the Software is furnished to do
10
+ so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
22
+
package/README.md ADDED
@@ -0,0 +1,251 @@
1
+ <div align="center">
2
+ <div>
3
+ <img src="logo.svg" alt="TAC Logo" width="120" height="120">
4
+ </div>
5
+
6
+ <h1>
7
+ Twilio Agent Connect
8
+ </h1>
9
+
10
+ <h2>
11
+ A powerful SDK for building intelligent, context-aware AI agents with Twilio's communication technologies.
12
+ </h2>
13
+
14
+ <div align="center">
15
+ <a href="https://github.com/twilio/twilio-agent-connect-typescript"><img alt="Node.js" src="https://img.shields.io/badge/Node.js-22.13+-339933.svg"/></a>
16
+ <a href="LICENSE"><img alt="License" src="https://img.shields.io/badge/license-MIT-green.svg"/></a>
17
+ <a href="https://www.twilio.com/docs/platform/tac/quickstart"><img alt="Getting Started" src="https://img.shields.io/badge/Getting%20Started-Quickstart-F22F46.svg"/></a>
18
+ </div>
19
+
20
+ <p>
21
+ <a href="https://www.twilio.com/docs/platform/tac/overview">Documentation</a>
22
+ ◆ <a href="https://github.com/twilio/twilio-agent-connect-python">Python SDK</a>
23
+ ◆ <a href="https://github.com/twilio/twilio-agent-connect-typescript">TypeScript SDK</a>
24
+ ◆ <a href="getting_started/examples">Examples</a>
25
+ </p>
26
+ </div>
27
+
28
+ Seamlessly integrate with Twilio's Memory Store and Conversation Orchestrator to build LLM-powered agents with persistent memory and conversation context.
29
+
30
+ ---
31
+
32
+ ## Key Features
33
+
34
+ - **Messaging Channel Support**: Built-in webhook handling for SMS, RCS, WhatsApp, and Chat conversations
35
+ - **Voice Channel Support**: WebSocket protocol handling for Twilio Voice with ConversationRelay
36
+ - **Outbound Conversations**: Agent-initiated conversations via SMS, RCS, WhatsApp, Chat, and Voice channels
37
+ - **ConversationRelay-Only Mode**: Get started quickly with TAC's voice plumbing (TwiML, WebSocket, callbacks) before adding Conversation Orchestrator
38
+ - **Memory Management**: Automatic integration with Twilio Memory for persistent user context
39
+ - **Conversation Lifecycle**: Automatic tracking of conversation sessions and state
40
+ - **Type-Safe**: Full TypeScript support with strict type checking
41
+ - **Callback-Based**: Simple `onMessageReady` callback for LLM integration with optional memory retrieval
42
+ - **Production Ready**: Comprehensive test coverage and error handling
43
+
44
+ ## Get Started
45
+
46
+ To get started, set up your Node.js environment (Node.js 22.13.0 or newer required), and then install TAC SDK package.
47
+
48
+ > [!IMPORTANT]
49
+ > TAC packages are not yet published to npm. We recommend building your agent directly in this repository.
50
+
51
+ ### Build in This Repository
52
+
53
+ Clone this repository and work within it:
54
+
55
+ ```bash
56
+ git clone https://github.com/twilio/twilio-agent-connect-typescript.git
57
+ cd twilio-agent-connect-typescript
58
+
59
+ # Install dependencies
60
+ npm install
61
+
62
+ # Build packages
63
+ npm run build
64
+ ```
65
+
66
+ ## Quick Examples
67
+
68
+ **Option 1: Use the Setup Wizard**
69
+
70
+ Use the [Twilio Setup Wizard](https://github.com/twilio/twilio-agent-connect-python/tree/main/getting_started/twilio_setup) from the Python SDK to automatically create a Memory Store and Conversation Configuration and generate your `.env` file:
71
+
72
+ ```bash
73
+ git clone https://github.com/twilio/twilio-agent-connect-python.git
74
+ cd twilio-agent-connect-python
75
+ make setup # Open http://localhost:8080
76
+ ```
77
+
78
+ **Option 2: Manual Setup**
79
+
80
+ You can also create a Memory Store and Conversation Configuration manually through the [Twilio Console](https://1console.twilio.com). For a full walkthrough — credentials, Console navigation, and webhook configuration — see the [TAC Quickstart](https://www.twilio.com/docs/platform/tac/quickstart).
81
+
82
+ ---
83
+
84
+ After completing setup, here's a minimal example to get started:
85
+
86
+ ### Multi-Channel with OpenAI SDK
87
+
88
+ Use the OpenAI SDK to build an AI agent that works across Voice and SMS channels with conversation memory and user context.
89
+
90
+ First, install the required dependencies in the repository:
91
+
92
+ ```bash
93
+ npm install openai dotenv
94
+ ```
95
+
96
+ > **Note**: `dotenv` is optional — TAC works with environment variables from any source (`.env` files, Docker, Kubernetes, CI/CD, shell exports, etc.).
97
+
98
+ Then create your application (e.g., in `getting_started/examples/` or your own directory):
99
+
100
+ ```typescript
101
+ import { config } from 'dotenv';
102
+ import OpenAI from 'openai';
103
+ import {
104
+ TAC,
105
+ TACConfig,
106
+ VoiceChannel,
107
+ SMSChannel,
108
+ TACServer,
109
+ MemoryPromptBuilder,
110
+ } from 'twilio-agent-connect';
111
+
112
+ config();
113
+
114
+ const openai = new OpenAI();
115
+
116
+ // Initialize TAC and channels
117
+ const tac = await TAC.create({ config: TACConfig.fromEnv() });
118
+ const voiceChannel = new VoiceChannel(tac);
119
+ const smsChannel = new SMSChannel(tac);
120
+
121
+ // Register channels
122
+ tac.registerChannel(voiceChannel);
123
+ tac.registerChannel(smsChannel);
124
+
125
+ // Store conversation history
126
+ const conversationHistory: Record<string, OpenAI.Chat.ChatCompletionMessageParam[]> = {};
127
+
128
+ // System instructions for the AI agent
129
+ const SYSTEM_INSTRUCTIONS =
130
+ 'You are a customer service agent speaking with a user over voice or SMS. ' +
131
+ 'Keep responses short and conversational — a sentence or two. ' +
132
+ 'Do not use markdown, asterisks, bullets, or emojis; your words will be ' +
133
+ 'spoken aloud or sent as plain text.';
134
+
135
+ // Handle incoming messages
136
+ tac.onMessageReady(async ({ conversationId, message, memory, session }) => {
137
+ const convId = conversationId as string;
138
+
139
+ if (!conversationHistory[convId]) {
140
+ conversationHistory[convId] = [];
141
+ }
142
+
143
+ // Build system prompt with memory context
144
+ const memoryContext = MemoryPromptBuilder.build(memory, session);
145
+ const systemPrompt = SYSTEM_INSTRUCTIONS + (memoryContext ? `\n\n${memoryContext}` : '');
146
+
147
+ conversationHistory[convId].push({ role: 'user', content: message });
148
+
149
+ const response = await openai.chat.completions.create({
150
+ model: 'gpt-4o-mini',
151
+ messages: [
152
+ { role: 'system', content: systemPrompt },
153
+ ...conversationHistory[convId],
154
+ ],
155
+ });
156
+
157
+ const llmResponse = response.choices[0]?.message?.content ?? '';
158
+ conversationHistory[convId].push({ role: 'assistant', content: llmResponse });
159
+
160
+ return llmResponse;
161
+ });
162
+
163
+ const server = new TACServer(tac);
164
+ await server.start();
165
+ ```
166
+
167
+ > **Note**: See the [getting started guide](getting_started/README.md) for complete setup instructions and `.env` configuration details.
168
+
169
+ **That's it!** The server automatically:
170
+ - Creates Fastify app with `/twiml`, `/ws`, and `/webhook` endpoints
171
+ - Handles Voice and SMS conversations
172
+ - Routes responses to the appropriate channel
173
+ - Provides conversation memory and user profile in the callback
174
+
175
+ For configuration details and environment variables, see the [getting started guide](getting_started/README.md).
176
+
177
+ ## How It Works
178
+
179
+ TAC simplifies building AI agents by handling the integration between Twilio's communication channels and your LLM:
180
+
181
+ ### Message Flow
182
+
183
+ 1. **Webhook/Connection Received**: Twilio sends webhook (SMS) or WebSocket connection (Voice) to your server
184
+ 2. **Channel Processing**: Channel validates and processes the incoming event
185
+ 3. **Memory Retrieval**: TAC optionally retrieves user memories and profile from Memory
186
+ 4. **Callback Invoked**: Your `onMessageReady` callback receives user message, context, and optional memory response
187
+ 5. **Response Handling**: Your callback returns a response string that TAC routes to the appropriate channel
188
+
189
+ For detailed architecture and advanced usage, see [CLAUDE.md](CLAUDE.md).
190
+
191
+ ## Learn More
192
+
193
+ **Examples & Guides:**
194
+ - **[Getting Started Guide](getting_started/)** - Examples and comprehensive documentation
195
+ - **[OpenAI SDK Example](getting_started/examples/openai/)** - Complete multi-channel example with Voice, SMS, and Chat
196
+ - **[WhatsApp Example](getting_started/examples/whatsapp/)** - WhatsApp channel with memory integration
197
+ - **[Chat Example](getting_started/examples/chat/)** - Web chat integration example
198
+ - **[ConversationRelay-Only Mode](getting_started/examples/relay-only/)** - Get started with voice using just ConversationRelay
199
+ - **[Outbound Conversations](getting_started/examples/outbound/)** - Agent-initiated conversations example
200
+ - More examples coming soon
201
+
202
+ **Documentation:**
203
+ - **[CLAUDE.md](CLAUDE.md)** - Architecture, development guide, and API reference
204
+ - **[Getting Started Guide](getting_started/README.md)** - Setup instructions, environment variables, and troubleshooting
205
+
206
+ ---
207
+
208
+ # TAC Development / Contribution
209
+
210
+ TAC uses npm workspaces for package management. Ensure you have Node.js and npm installed:
211
+
212
+ ```bash
213
+ node --version # Should be 22.13.0 or newer
214
+ npm --version # Should be 9 or newer
215
+ ```
216
+
217
+ ### Setup Development Environment
218
+
219
+ ```bash
220
+ # Clone repository
221
+ git clone https://github.com/twilio/twilio-agent-connect-typescript.git
222
+ cd twilio-agent-connect-typescript
223
+
224
+ # Install all dependencies
225
+ npm install
226
+
227
+ # Build all packages
228
+ npm run build
229
+ ```
230
+
231
+ ### Running Tests and Checks
232
+
233
+ ```bash
234
+ # Format code
235
+ npm run format
236
+
237
+ # Run linting
238
+ npm run lint
239
+
240
+ # Run type checking
241
+ npm run typecheck
242
+
243
+ # Run tests
244
+ npm test
245
+
246
+ # Run tests in watch mode (for development)
247
+ npm run test:watch
248
+
249
+ # Run all checks at once
250
+ npm run build && npm run lint && npm run typecheck && npm test
251
+ ```