AgentsAgentBase

as_router

View as MarkdownOpen in Claude

Get a FastAPI APIRouter containing all of this agent’s registered routes. This is the lowest-level integration point for embedding an agent’s endpoints into an existing FastAPI application.

Use this when you need fine-grained control over how the agent’s routes are mounted, or when composing multiple agents into a custom application layout. For multi-agent hosting, consider AgentServer instead.

Parameters

None.

Returns

APIRouter — A FastAPI router with all agent endpoints (SWML delivery, SWAIG function handling, post-prompt, debug events, etc.).

Example

1from fastapi import FastAPI
2from signalwire import AgentBase
3
4app = FastAPI()
5
6support_agent = AgentBase(name="support", route="/support")
7sales_agent = AgentBase(name="sales", route="/sales")
8
9app.include_router(support_agent.as_router(), prefix="/support")
10app.include_router(sales_agent.as_router(), prefix="/sales")