Skip to Content
ExamplesAgent Monitoring

Agent Monitoring

Monitor AI agents and autonomous systems with flat numeric events. This pattern is the best starting point for OpenClaw and similar agent workflows.

EventValueWhy
tool.errors.count1 per errorTrack tool reliability across your agent’s toolchain
tool.calls.count1 per callMeasure tool usage volume and spot unexpected spikes
task.duration_msDuration in msCatch tasks that are running slower than expected
tokens.usedToken countMonitor LLM cost per task and catch runaway token spend
heartbeat.missed.count1 per missDetect when an agent worker stops responding

Logging events

await client.log({ agent: "openclaw.main", event: "tool.errors.count", value: 1, meta: { tool_name: "crm.lookup", error: "timeout" } }); await client.log({ agent: "openclaw.main", event: "task.duration_ms", value: 1250, meta: { task_name: "email_triage" } }); await client.log({ agent: "openclaw.main", event: "tokens.used", value: 3400, meta: { task_name: "email_triage", model: "claude-sonnet-4-5-20250929" } });
EventPeriodAggregateConditionThresholdWhy
tool.errors.counthoursumgt10Catch a tool that starts failing repeatedly
task.duration_mshouraveragegt5000Detect slowdowns before they compound
task.duration_msdayp95_estgt10000Track tail latency trends over time
tokens.useddaysumgt100000Budget guard for daily token spend
heartbeat.missed.countdaysumgt0Any missed heartbeat is worth investigating

Using comparisons

Check whether task duration is trending up compared to the same hour yesterday:

const analytics = await client.getEventAnalytics(taskDurationEventID, { view: "window", period: "1h", previous: "previous_1d", }); // analytics.data.mean_pct_change — e.g., 15% slower than yesterday

Or compare this week’s token spend to last week:

const analytics = await client.getEventAnalytics(tokensUsedEventID, { view: "window", period: "7d", previous: "previous_window", }); // analytics.data.value_pct_change — e.g., 30% more tokens this week
Last updated on