agent.serve() starts a runtime that runs messaging interfaces, an HTTP server, and scheduled tasks concurrently. One line to start everything.
Quick Start
serve() / aserve()
agent.serve() is a blocking sync call. Use agent.aserve() in async contexts.
BaseInterface
Interface instances (Telegram, Discord) to run concurrently.
str
default:"None"
Display name for logs. Defaults to the agent’s name.
str
default:"0.0.0.0"
HTTP server bind address.
int
default:"8000"
HTTP server port.
bool
default:"None"
Force the HTTP server on or off. When
None, the server starts automatically if webhooks are registered.bool
default:"false"
Enable hot-reload dev mode. Watches
.py files and auto-restarts on changes. Requires watchfiles.Webhooks
Register HTTP webhook handlers with theWebhook trigger:
Webhook Parameters
str
required
URL path for the webhook (e.g.,
"/github").str
default:"POST"
HTTP method to listen on.
Any
default:"None"
Per-webhook auth override.
None inherits from agent.auth. False disables auth for this endpoint.Handler Return Values
The return value from a webhook handler controls what happens next:TriggerEvent
Every trigger handler receives aTriggerEvent:
Cron Jobs
Schedule tasks with standard cron expressions:str
required
Standard cron expression (e.g.,
"0 9 * * *").str
default:"UTC"
Timezone for the schedule.
Requires
croniter: pip install croniter or pip install 'definable[cron]'Event Triggers
Fire triggers programmatically from anywhere in your code:emit() does not block or return a result.
Lifecycle Hooks
Run logic before every agent run or after every response:- Hooks are always non-fatal — errors are logged but never raised
- Both sync and async functions are supported
- Both
@agent.before_requestand@agent.before_request()syntax work before_requestreceives aRunContext,after_responsereceives aRunOutput
HTTP Server
The built-in server is powered by FastAPI and provides these endpoints:
When
agent.auth is set, all endpoints except /health require authentication. See Authentication for details.
Requires
fastapi and uvicorn: pip install fastapi uvicorn or pip install 'definable[serve]'Dev Mode
Enable hot-reload for development:- Watches
.pyfile changes and auto-restarts the process - Swagger docs available at
/docs - Requires
watchfiles:pip install watchfiles
With Interfaces
Combine messaging interfaces, webhooks, cron, auth, and hooks in a singleserve() call:
How It Works
AgentRuntime orchestrates up to three concurrent tasks:
- HTTP server — FastAPI app serving
/run,/health, and webhook routes - Interface supervisor — runs messaging interfaces (Telegram, Discord, etc.) with exponential backoff auto-restart (1s → 60s)
- Cron scheduler — tracks next-fire times and dispatches cron handlers
SIGINT/SIGTERM cancels all tasks and waits for clean exit.