Skip to navigation

Start the HTTP server like serve(), or handle a single serverless invocation. run() handles the invocation instead of serving when opts.event is given, or when the environment shows a serverless platform: any of AWS_LAMBDA_FUNCTION_NAME, _HANDLER, FUNCTION_TARGET, FUNCTIONS_WORKER_RUNTIME, or GATEWAY_INTERFACE is set. Otherwise it calls serve(opts).

Returns immediately when SWAIG_CLI_MODE=true is set, so the CLI testing tool can load the agent without opening a port.

Parameters

opts
object

Optional server overrides and serverless invocation data.

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.

opts.event
ServerlessEvent

The platform’s invocation event. When set, run() handles this invocation instead of starting a server.

opts.context
unknown

The platform’s invocation context, passed through with the event.

opts.platform
'lambda' | 'gcf' | 'azure' | 'cgi' | 'auto'

Serverless platform. Detected from the environment when omitted.

Returns

Promise<void | ServerlessResponse> — Resolves once the server is running, or with the response for a serverless invocation.

Example

import { AgentBase } from '@signalwire/sdk';
const agent = new AgentBase({ name: 'my-agent', route: '/agent' });
agent.setPromptText('You are a helpful assistant.');
await agent.run();