Skip to navigation

asRouter

View as MarkdownOpen in Claude

Get a router that embeds this agent’s routes in a host Hono application. The routes are relative to the agent’s root (/, /swaig, /post_prompt, plus any routing callbacks), so mount it under the agent’s route: app.route(agent.route, agent.asRouter()). AgentServer mounts it the same way. getApp() serves the same routes under the agent’s route instead.

The routes also answer with a trailing slash (/swaig/, /post_prompt/), for a host app with strict routing.

Parameters

None.

Returns

HostAppRouter — A Hono sub-app carrying the agent’s routes, relative to its root. HostAppRouter is a type alias for Hono, named for the host-app mounting contract it fulfills.

Example

import { Hono } from 'hono';
import { AgentBase } from '@signalwire/sdk';
const app = new Hono();
const supportAgent = new AgentBase({ name: 'support', route: '/support' });
const salesAgent = new AgentBase({ name: 'sales', route: '/sales' });
app.route('/support', supportAgent.asRouter());
app.route('/sales', salesAgent.asRouter());