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.
Force the HTTP server on or off. When
None, the server starts automatically if webhooks are registered.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
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: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.