Skip to navigation

runServerless

View as MarkdownOpen in Claude

Handle a single serverless invocation by routing the platform’s event through the agent’s HTTP app, and return the platform’s response. This is the explicit serverless path: run() calls it when it detects a serverless platform, and you call it yourself from a handler file to opt in deliberately.

The routing is done by a ServerlessAdapter for the given platform. On CGI with no event, the request is read from the CGI environment and standard input, and the response is written to standard output.

Parameters

event
ServerlessEventRequired

The platform’s invocation event, such as a Lambda event or a Cloud Functions request.

context
unknown

The platform’s invocation context. Accepted for the handler signature; the base agent doesn’t use it.

platform
'lambda' | 'gcf' | 'azure' | 'cgi' | 'auto'Defaults to auto

Serverless platform. auto detects it from the environment.

Returns

Promise<ServerlessResponse> — The normalized response for the platform.

Example

import { AgentBase, type ServerlessEvent } from '@signalwire/sdk';
const agent = new AgentBase({ name: 'dispatch', route: '/dispatch' });
agent.setPromptText('You are Ada, the dispatcher for Bayview Taxi.');
export const handler = (event: ServerlessEvent, context: unknown) =>
agent.runServerless(event, context, 'lambda');