Infrastructure

View as MarkdownOpen in Claude

These classes mirror the LiveKit infrastructure types used in agent entrypoints. On SignalWire, connection lifecycle and room management are handled automatically by the control plane, so these are lightweight stubs that maintain API compatibility.

JobContext

Mirrors a LiveKit JobContext. Provides access to the room and process objects, and lifecycle methods that the entrypoint calls before starting a session.

1import { JobContext, Agent, AgentSession } from '@signalwire/sdk/livewire';
2
3async function entry(ctx: JobContext) {
4 await ctx.connect(); // No-op on SignalWire
5 const participant = await ctx.waitForParticipant();
6
7 const agent = new Agent({ instructions: 'You are a helpful assistant.' });
8 const session = new AgentSession();
9 await session.start({ agent, room: ctx.room });
10}

Properties

room
any

A room stub object with a name property (defaults to "livewire-room").

proc
JobProcess

A JobProcess instance with a userData object, populated by the prewarm function if one was registered via defineAgent().

Methods

connect

1async connect(): Promise<void>

No-op. SignalWire’s control plane handles connection lifecycle automatically. The agent connects when the platform invokes the SWML endpoint.


waitForParticipant

1async waitForParticipant(): Promise<any>

No-op. SignalWire handles participant management automatically. Returns { identity: 'caller' }.


JobProcess

Mirrors a LiveKit JobProcess. Used for prewarm and setup tasks. The prewarm function registered in defineAgent({ prewarm }) receives a JobProcess instance.

1import { defineAgent, JobProcess } from '@signalwire/sdk/livewire';
2
3const agentDef = defineAgent({
4 prewarm: (proc: JobProcess) => {
5 proc.userData.dbConnection = connectToDb();
6 },
7 entry: async (ctx) => {
8 const db = ctx.proc.userData.dbConnection;
9 // ...
10 },
11});

Properties

userData
Record<string, any>

Arbitrary data object for sharing state between the prewarm function and the entry function. Defaults to an empty object.


Full Example

1import {
2 Agent, AgentSession, JobContext, JobProcess,
3 tool, defineAgent, runApp,
4} from '@signalwire/sdk/livewire';
5
6const getGreeting = tool({
7 description: 'Get the configured greeting message.',
8 execute: (_params, { ctx }) => {
9 return (ctx.userData as Record<string, any>).greeting ?? 'Hello!';
10 },
11});
12
13const agentDef = defineAgent({
14 prewarm: (proc: JobProcess) => {
15 proc.userData.greeting = 'Welcome to Acme Corp!';
16 },
17 entry: async (ctx: JobContext) => {
18 await ctx.connect();
19 await ctx.waitForParticipant();
20
21 const agent = new Agent({
22 instructions: 'You are a helpful assistant.',
23 tools: { getGreeting },
24 });
25
26 const session = new AgentSession();
27 await session.start({ agent, room: ctx.room });
28 session.say(ctx.proc.userData.greeting);
29 },
30});
31
32runApp(agentDef);