Signals

View as MarkdownOpen in Claude

LiveWire provides error and signal classes that tool handlers can throw or return to control agent behavior.

StopResponse

Extends Error. When thrown inside a tool handler, signals that the tool should not trigger another LLM reply. Use this when the tool’s side effect is the final action and no further conversation is needed.

1import { tool, StopResponse } from '@signalwire/sdk/livewire';
2
3const endCall = tool({
4 description: 'End the current call.',
5 parameters: { reason: { type: 'string' } },
6 execute: (params) => {
7 // Perform cleanup...
8 throw new StopResponse(`Call ended: ${params.reason}`);
9 },
10});

Constructor

1new StopResponse(message?: string)
message
stringDefaults to "StopResponse"

Optional error message. Defaults to "StopResponse".


ToolError

Extends Error. Signals a tool execution failure. Throw this when a tool encounters a problem that should be reported back to the LLM so it can communicate the issue to the user or retry.

1import { tool, ToolError } from '@signalwire/sdk/livewire';
2
3const transferFunds = tool<{ amount: number; toAccount: string }>({
4 description: 'Transfer funds to another account.',
5 parameters: {
6 amount: { type: 'number' },
7 toAccount: { type: 'string' },
8 },
9 execute: (params) => {
10 if (params.amount <= 0) {
11 throw new ToolError('Amount must be positive.');
12 }
13 return `Transferred $${params.amount} to ${params.toAccount}.`;
14 },
15});

Constructor

1new ToolError(message: string)
message
stringRequired

Error message describing what went wrong. This is sent back to the LLM.


AgentHandoff

A signal class for handing off a conversation to a different agent in multi-agent scenarios. Created via the handoff() helper function.

1import { Agent, handoff, tool } from '@signalwire/sdk/livewire';
2
3const billingAgent = new Agent({
4 instructions: 'You handle billing questions.',
5});
6
7const transferToBilling = handoff({
8 agent: billingAgent,
9 returns: 'Transferred to billing department.',
10});

Properties

agent
Agent

The target Agent for the handoff.

returns
string | undefined

Optional return message for the handoff.

handoff()

1function handoff(options: { agent: Agent; returns?: string }): AgentHandoff

Factory function that creates an AgentHandoff instance.

agent
AgentRequired

The target agent to hand off to.

returns
string | undefined

Optional return value for the handoff.


ChatContext

A minimal empty class mirroring the LiveKit ChatContext. Exists for API compatibility. On SignalWire, conversation history is managed by the platform.

1import { llm } from '@signalwire/sdk/livewire';
2
3const chat = new llm.ChatContext();

ChatContext has no methods or properties in the LiveWire implementation. It is an empty stub provided solely so that existing livekit-agents code that references ChatContext compiles without errors.