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.

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

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

async connect(): Promise<void>

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


waitForParticipant

async 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.

import { defineAgent, JobProcess } from '@signalwire/sdk/livewire';
const agentDef = defineAgent({
prewarm: (proc: JobProcess) => {
proc.userData.dbConnection = connectToDb();
},
entry: async (ctx) => {
const db = ctx.proc.userData.dbConnection;
// ...
},
});

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

import {
Agent, AgentSession, JobContext, JobProcess,
tool, defineAgent, runApp,
} from '@signalwire/sdk/livewire';
const getGreeting = tool({
description: 'Get the configured greeting message.',
execute: (_params, { ctx }) => {
return (ctx.userData as Record<string, any>).greeting ?? 'Hello!';
},
});
const agentDef = defineAgent({
prewarm: (proc: JobProcess) => {
proc.userData.greeting = 'Welcome to Acme Corp!';
},
entry: async (ctx: JobContext) => {
await ctx.connect();
await ctx.waitForParticipant();
const agent = new Agent({
instructions: 'You are a helpful assistant.',
tools: { getGreeting },
});
const session = new AgentSession();
await session.start({ agent, room: ctx.room });
session.say(ctx.proc.userData.greeting);
},
});
runApp(agentDef);