Decorators are how your Python module becomes a deployed agent worker. The platform dispatches incoming task events to yourDocumentation Index
Fetch the complete documentation index at: https://docs.xpander.ai/llms.txt
Use this file to discover all available pages before exploring further.
@on_task handler over SSE, calls @on_boot once at startup, runs @on_tool_* hooks around every tool invocation, and routes auth events through @on_auth_event.
| Decorator | Purpose |
|---|---|
@on_task | Handle incoming tasks. The primary entry point for any SDK-based agent. |
@on_boot | Run once at startup, before the SSE listener subscribes. |
@on_shutdown | Run once during graceful shutdown. |
@on_auth_event | Receive MCP/OAuth authentication events as they happen. |
@on_tool_before | Run before any tool invocation. |
@on_tool_after | Run after a successful tool invocation. |
@on_tool_error | Run when a tool invocation raises. |
@register_tool: it lives next to the tools API, since it constructs Tool objects rather than wiring runtime hooks.
Minimal worker
python worker.py: and the worker subscribes to the platform’s SSE stream, picks up tasks dispatched to its agent, runs them, and saves results. Tasks are auto-marked Completed (or Error on raise) and metrics are reported automatically when task.tokens is set.
Required environment
@on_task validates required env vars eagerly at import. Missing any of these raises ModuleException:
| Variable | Required for |
|---|---|
XPANDER_API_KEY | Authentication. |
XPANDER_ORGANIZATION_ID | Routing. |
XPANDER_AGENT_ID | Worker registration. |

