Agents

TypeScript API reference for AgentBase, SWMLService, SWAIG functions, skills, contexts, LiveWire, search, and more
View as MarkdownOpen in Claude

The Agents namespace provides the core framework for building AI-powered voice agents with SignalWire. It includes the central AgentBase class, SWML document generation, tool/function definitions, skills, multi-agent hosting, CLI tools for local testing and deployment, and configuration management for security and environment settings.

The Agents SDK generates SWML documents under the hood. Each agent produces a SWML document with the ai verb that the SignalWire platform executes.

Example

A complete agent that answers calls, uses an AI prompt, and exposes a custom tool:

1import { AgentBase, FunctionResult } from '@signalwire/sdk';
2
3const agent = new AgentBase({ name: 'support-agent', route: '/support' });
4agent.setPromptText(
5 'You are a friendly support agent for Acme Corp. ' +
6 'Help customers check their order status. ' +
7 'Be concise and professional.'
8);
9agent.setParams({ temperature: 0.5, end_of_speech_timeout: 800 });
10
11agent.defineTool({
12 name: 'check_order',
13 description: 'Check an order status by ID',
14 parameters: {
15 order_id: { type: 'string', description: 'The order ID to check' },
16 },
17 handler: (args, rawData) => {
18 const orderId = (args.order_id as string) || 'unknown';
19 return new FunctionResult(`Order ${orderId} shipped on March 28 and arrives tomorrow.`);
20 },
21});
22
23agent.addSkill('datetime');
24
25agent.run();

Classes