AgentsAgentBase

mount

View as MarkdownOpen in Claude

Mount an extra router or ASGI app alongside this agent’s own routes. Use it instead of get_app() followed by include_router() or mount() by hand, which fails silently in three ways:

  • Anything mounted after serve() starts is lost, because serve() builds a fresh app when none exists. This method materializes the app first so a later serve() reuses it.
  • The agent registers a catch-all route, and FastAPI matches routes in registration order, so any route added afterwards is shadowed and never runs. This method moves the catch-all back to the end.
  • The app that get_app() builds answers the agent’s bare route (no trailing slash) with 204 instead of SWML. This method re-registers that route, so the URL the platform fetches keeps working.

Parameters

app_or_router
AnyRequired

A FastAPI APIRouter, included at prefix, or any other ASGI app such as StaticFiles, mounted at prefix.

prefix
strDefaults to ""

Path prefix, without a trailing slash. Keyword-only.

name
str | NoneDefaults to None

Mount name. Used only for ASGI apps. Keyword-only.

Returns

AgentBase — Returns self for method chaining.

Example

from fastapi.staticfiles import StaticFiles
from signalwire import AgentBase
from signalwire.ai_chat import ChatGateway
agent = AgentBase(name="dispatch", route="/dispatch")
gateway = ChatGateway(
config_url="https://bayview-taxi.example.com/dispatch",
key="pk_your_publishable_key",
)
agent.mount(gateway.router(), prefix="/chat")
agent.mount(StaticFiles(directory="web", html=True), prefix="/demo")
agent.serve()

See ChatGateway for what the mounted router serves.