serve

View as MarkdownOpen in Claude

Start a Hono web server (via @hono/node-server) to serve this agent. The server exposes endpoints for SWML document delivery, SWAIG function execution, post-prompt summary handling, and health checks.

The server automatically includes:

  • SWML document endpoint at the agent’s route
  • SWAIG function dispatch at {route}/swaig
  • Post-prompt handler at {route}/post_prompt
  • /health and /ready health check endpoints
  • Security headers middleware
  • Basic Auth middleware

run() is an alias for serve(). Both methods are equivalent in the TypeScript SDK.

Parameters

opts
object

Optional host and port overrides.

opts.host
string

Host to bind the server to. Falls back to the constructor’s host option.

opts.port
number

Port to listen on. Falls back to the constructor’s port option.

When the SWAIG_CLI_MODE environment variable is set to "true", serve() returns immediately without starting the server. This lets the swaig-test CLI load the agent’s configuration without binding a port.

Returns

Promise<void> — Resolves once the server is running.

Example

1import { AgentBase } from '@signalwire/sdk';
2
3const agent = new AgentBase({ name: 'my-agent', host: '0.0.0.0', port: 3000 });
4agent.setPromptText('You are a helpful assistant.');
5await agent.serve(); // Blocks here, serving at http://0.0.0.0:3000/