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

from fastapi import FastAPI
from signalwire import AgentBase
app = FastAPI()
support_agent = AgentBase(name="support", route="/support")
sales_agent = AgentBase(name="sales", route="/sales")
app.include_router(support_agent.as_router(), prefix="/support")
app.include_router(sales_agent.as_router(), prefix="/sales")