Agent

View as MarkdownOpen in Claude

The Agent<UserData> class mirrors a LiveKit voice agent. It holds the system prompt (instructions), a map of tools, and optional user data. When bound to an AgentSession, the session translates this into a SignalWire AgentBase under the hood.

1import { Agent, tool } from '@signalwire/sdk/livewire';
2
3const getWeather = tool({
4 description: 'Get the current weather for a city.',
5 parameters: { city: { type: 'string' } },
6 execute: (params) => {
7 return `It is sunny in ${params.city}.`;
8 },
9});
10
11const agent = new Agent({
12 instructions: 'You are a helpful weather assistant.',
13 tools: { getWeather },
14});

Constructor

1new Agent<UserData>(options: {
2 instructions: string;
3 tools?: Record<string, FunctionTool>;
4 userData?: UserData;
5})
instructions
stringRequired

The system prompt text for the agent. Mapped to the SignalWire prompt when the session starts.

tools
Record<string, FunctionTool>Defaults to {}

A map of tool names to FunctionTool definitions. Each tool is registered as a SWAIG function on the underlying SignalWire agent.

userData
UserDataDefaults to undefined

Arbitrary data attached to the agent. Accessible from tool handlers via RunContext.userData.

Properties

instructions
string

The system prompt text for the agent. Can be read or modified directly.

tools
Record<string, FunctionTool>

The map of registered tools.

userData
UserData | undefined

The user data attached to this agent.

Example

1import { Agent, AgentSession, tool, defineAgent, runApp, JobContext } from '@signalwire/sdk/livewire';
2
3const lookupAccount = tool({
4 description: 'Look up a customer account by email.',
5 parameters: { email: { type: 'string' } },
6 execute: (params) => {
7 return `Account found for ${params.email}: Premium tier.`;
8 },
9});
10
11const agentDef = defineAgent({
12 entry: async (ctx: JobContext) => {
13 const agent = new Agent({
14 instructions: 'You are a customer support agent. Help users with their accounts.',
15 tools: { lookupAccount },
16 userData: { department: 'support' },
17 });
18
19 const session = new AgentSession();
20 await session.start({ agent });
21 session.generateReply({ instructions: 'Greet the customer and ask how you can help.' });
22 },
23});
24
25runApp(agentDef);