NylorunDocsBeta
Get startedBuildRunDeployReferenceMore
Agents SDK

createActionHandler

Serve agents' tools, hooks, and flow functions as an Action endpoint.

import { createActionHandler } from "@nylorun/agents";

Guides: Action endpoints, App server.

createActionHandler

createActionHandler(options: ActionHandlerOptions): ActionHandler

Returns one HTTP handler for the agents' Actions. The Runtime POSTs each tool call, hook, and flow fn, verify, or tool step to it. Each request's delivery token (Nylorun-Signature) is verified before any code runs: it must be signed by the Tenant's key, for this Tenant, URL, Action, generation, and exact body. Sandbox tools run in the Runtime instead.

const actions = createActionHandler({ agents, url, onError: console.error });
createServer(actions.node).listen(3001);
await actions.register({ url });

ActionHandlerOptions

NameTypeRequiredDescription
agentsreadonly (AgentSource | BuiltWorkflow)[]YesAgents and flow agents served. Agents they embed are served too.
clientAgentsClient | Promise<AgentsClient>NoApplication client for register, and for reading public keys when runtime is unset. Default: createClient().
runtime{ url: string; tenant: string; fetch? }NoWhere to read the Tenant's public keys without a key. Set it for a process that only serves Actions.
jwks{ keys: readonly JsonWebKey[] }NoThe Tenant's public keys, instead of reading them from the Runtime.
urlstringNoThe registered URL every delivery token must name. Default: the URL passed to register in this process.
implementationVersionstringNoRegistered with each endpoint. Default: NYLORUN_IMPLEMENTATION_VERSION, then dev.
onError(error: unknown) => voidNoReceives errors answered with a status instead of thrown.
waitUntil(work: Promise<unknown>) => voidNoKeeps a background tool's work alive after its 202 on platforms that end work with the response. A Node server needs nothing.

ActionHandler

MemberTypeDescription
fetch(request: Request) => Promise<Response>Web-standard handler: Hono, Next.js route handlers, Workers, Bun, Deno.
nodeNode request listenerThe same handler for node:http and Express.
register(options: RegisterOptions) => Promise<EndpointPingResponse[]>Saves definitions, registers url for every served agent, and pings each through the Runtime.

register needs an application key and a Runtime with the action-endpoints feature; it refuses an older Runtime before sending anything.

RegisterOptions

NameTypeRequiredDescription
urlstringYesThe URL the Runtime calls, e.g. http://localhost:3001/nylorun/actions.
saveDefinitionsbooleanNoSave the definitions first. Default true.
timeoutMsnumberNoHow long one inline delivery may take. Default 60 000; at most 840 000.
maxConcurrentnumberNoIn-flight deliveries per agent. Default 16.
signalAbortSignalNoAborts registration.

Responses

StatusWhen
200The outcome, tagged with Nylorun-Outcome: 1, or a ping answer.
400The body is not an Action delivery.
202A background: true tool; the handler heartbeats and posts the result itself.
401The delivery token is missing, invalid, or for another delivery.
404The agent or tool is not served here.
405Any method other than POST.
409A flow Action for another version of the flow. The Runtime retries.
503Signed with a key the handler has not seen yet, just after a rotation. The Runtime retries.

Delegation limits

Agents used as tools cannot declare approval. ctx.ask, ctx.approve, ctx.sleep, and ctx.waitFor inside a delegated agent fail with delegation.interaction-unsupported.

On this page