Skip to content

[Feature] Session event query API: unlock the event stream agents already produce #17067

@ukr-coder

Description

@ukr-coder

Sessions Are Event Streams — But We Can't Query Them

Every OpenClaw session produces a rich stream of events: messages, tool calls, compactions, spawns, errors. These are stored in .jsonl files — append-only, ordered, timestamped. This is event sourcing by accident.

But there's no API to query this stream. The only option is to parse raw .jsonl files, which means:

  • No way to ask "what tools did this agent call in the last hour?"
  • No way to aggregate "how many errors across all sessions today?"
  • No way to build dashboards, alerts, or analytics without custom file parsing
  • The richest data source in OpenClaw is effectively invisible

Proposed: Session Event Query API

Tool-Level (for agents)

// Query own session events
session_events({
  types: ["tool_call", "error"],   // filter by event type
  since: "2026-02-15T10:00:00Z",  // time range
  limit: 50                        // pagination
})

// Query across sessions (for orchestrators)
sessions_events({
  sessionKey: "agent:main:*",      // wildcard
  types: ["spawn", "complete"],
  since: "1h"                      // relative time
})

HTTP API (for external systems)

GET /api/sessions/:key/events?types=error,tool_call&since=1h&limit=100
GET /api/events?agentId=main&types=spawn,complete&since=24h

Event Types to Expose

Event Payload Use Case
message role, tokens, model Usage tracking, conversation analysis
tool_call tool name, duration, success/fail Tool reliability monitoring
tool_error tool name, error message Alert on repeated failures
compaction before/after tokens, summaryLength Context management insights
spawn child sessionKey, task, model Orchestration tracking
complete result, duration, tokens Pipeline completion
model_switch from, to, reason Failover monitoring

Why This Enables Everything Else

This is foundational infrastructure. Without queryable events:

Event sourcing is the #1 pattern in distributed systems (Kafka, EventStore, Axon). OpenClaw already HAS the event log — it just needs an API on top.

Minimal First Step

Expose the existing .jsonl content via a read-only session_events tool with type filtering and time range. No new storage, no new indexing — just structured access to what's already there.

Happy to help design the schema and test on Windows.

Metadata

Metadata

Assignees

No one assigned

    Labels

    staleMarked as stale due to inactivity

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions