Documentation Index
Fetch the complete documentation index at: https://docs.xpander.ai/llms.txt
Use this file to discover all available pages before exploring further.
Task.areport_metrics records the task’s token usage, tool calls, and execution outcome to the platform’s metrics store. The @on_task runtime calls this automatically at the end of every handler if task.tokens is set, so you only need to invoke it directly when you’re driving a task outside the runtime.
task.tokens must be set before calling areport_metrics. The method raises ValueError if tokens is missing.Parameters
| Parameter | Type | Required | Description |
|---|---|---|---|
configuration | Configuration | No | Override SDK config. Falls back to task.configuration, then env-derived defaults. |
Returns
None.
What gets reported
The metrics report includes:execution_id: task id.source: task source.memory_thread_id: same as task id (memory and execution share an id).task: input text (task.input.text).status: currenttask.status.internal_status: currenttask.internal_status.ai_model: fixed to"xpander".api_calls_made: tool names fromtask.used_tools(or[]for orchestration tasks withreturn_metrics=True).result: final result string.llm_tokens: token counts wrapped inExecutionTokens(worker=task.tokens).
Examples
Inside a custom event loop
If you’re driving an agent without@on_task, report metrics manually before returning to the caller:
Sync version
Errors
RaisesModuleException on persistence failures, or ValueError if task.tokens is None.
