setupGracefulShutdown

View as MarkdownOpen in Claude

Static method that registers process signal handlers for SIGTERM and SIGINT so the agent shuts down cleanly. This is especially useful in Kubernetes deployments where the pod receives SIGTERM before termination.

Only registers handlers once, even if called multiple times.

Parameters

opts
object

Optional configuration.

opts.timeout
numberDefaults to 5000

Shutdown timeout in milliseconds before the process exits.

Returns

void

Example

1import { AgentBase } from '@signalwire/sdk';
2
3AgentBase.setupGracefulShutdown({ timeout: 10000 });
4
5const agent = new AgentBase({ name: 'support', route: '/support' });
6agent.setPromptText('You are a helpful assistant.');
7await agent.serve();