Aleph
Gateway RPCMethods Reference

events.*

Event subscription and streaming RPC methods

Event methods manage real-time event subscriptions over the WebSocket connection. Subscribe to topics using glob patterns to receive notifications about agent activity, streaming output, configuration changes, and more.

Event Delivery

Events are delivered as JSON-RPC notifications (no id field) on the WebSocket connection:

{
  "jsonrpc": "2.0",
  "method": "event",
  "params": {
    "topic": "stream.chunk",
    "data": {
      "run_id": "run-uuid-123",
      "content": "Here is the response..."
    },
    "timestamp": 1706400000000
  }
}

Events are fire-and-forget: the server sends them without waiting for acknowledgement. If the client disconnects, events during the disconnection are lost.

Methods

events.subscribe

Subscribe to one or more event topics using glob patterns. Subscriptions are additive -- calling subscribe multiple times adds new patterns without removing existing ones.

Request:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "events.subscribe",
  "params": {
    "patterns": ["stream.*", "agent.*"]
  }
}

Response:

{
  "jsonrpc": "2.0",
  "id": 1,
  "result": {
    "subscribed": ["stream.*", "agent.*"],
    "active_patterns": ["stream.*", "agent.*"]
  }
}

Parameters:

ParameterTypeRequiredDescription
patternsstring[]YesArray of glob patterns to subscribe to

events.unsubscribe

Remove one or more event subscriptions. Patterns must match exactly what was subscribed.

Request:

{
  "jsonrpc": "2.0",
  "id": 2,
  "method": "events.unsubscribe",
  "params": {
    "patterns": ["stream.*"]
  }
}

Response:

{
  "jsonrpc": "2.0",
  "id": 2,
  "result": {
    "unsubscribed": ["stream.*"],
    "active_patterns": ["agent.*"]
  }
}

Parameters:

ParameterTypeRequiredDescription
patternsstring[]YesArray of patterns to unsubscribe from

events.list

List all active event subscriptions for the current WebSocket connection.

Request:

{
  "jsonrpc": "2.0",
  "id": 3,
  "method": "events.list"
}

Response:

{
  "jsonrpc": "2.0",
  "id": 3,
  "result": {
    "patterns": ["agent.*"],
    "total": 1
  }
}

This method takes no parameters.

Event Topics

Streaming Events (stream.*)

Emitted during agent response generation.

TopicDescriptionData Fields
stream.startResponse streaming beginsrun_id
stream.chunkText chunk from the agentrun_id, content
stream.tool_startAgent is invoking a toolrun_id, tool_name, args
stream.tool_endTool execution completedrun_id, tool_name, result, duration_ms
stream.thinkingReasoning step (CoT transparency)run_id, step_type, content
stream.endResponse streaming finishedrun_id

Example -- stream.chunk:

{
  "jsonrpc": "2.0",
  "method": "event",
  "params": {
    "topic": "stream.chunk",
    "data": {
      "run_id": "run-uuid-123",
      "content": "Based on my analysis, "
    }
  }
}

Example -- stream.tool_start:

{
  "jsonrpc": "2.0",
  "method": "event",
  "params": {
    "topic": "stream.tool_start",
    "data": {
      "run_id": "run-uuid-123",
      "tool_name": "shell:exec",
      "args": { "command": "git log --oneline -5" }
    }
  }
}

Agent Events (agent.*)

Emitted for agent lifecycle changes.

TopicDescriptionData Fields
agent.startedAgent run has startedrun_id, session_key
agent.completedAgent run finishedrun_id, session_key, tokens_used
agent.errorAgent run encountered an errorrun_id, error
agent.cancelledAgent run was cancelledrun_id

Example -- agent.completed:

{
  "jsonrpc": "2.0",
  "method": "event",
  "params": {
    "topic": "agent.completed",
    "data": {
      "run_id": "run-uuid-123",
      "session_key": "agent:main:main",
      "tokens_used": 1247,
      "duration_ms": 5000
    }
  }
}

Session Events (session.*)

Emitted when session state changes.

TopicDescriptionData Fields
session.createdNew session createdsession_key
session.deletedSession was deletedsession_key
session.compactedSession was compactedsession_key, tokens_before, tokens_after

Config Events (config.*)

Emitted when configuration changes.

TopicDescriptionData Fields
config.changedConfiguration was modifiedchanged_keys, source
config.reloadedConfiguration reloaded from filesource

Cron Events (cron.*)

Emitted during scheduled job execution.

TopicDescriptionData Fields
cron.triggeredJob was triggeredjob_id, run_id, trigger_source
cron.completedJob run finishedjob_id, run_id, duration_ms
cron.failedJob run failedjob_id, run_id, error

Exec Events (exec.*)

Emitted during command execution approval.

TopicDescriptionData Fields
exec.approval_requestedApproval needed for a commandid, command, risk_level
exec.approval_resolvedApproval decision madeid, decision

Glob Pattern Matching

Event subscription patterns use glob-style matching:

PatternMatches
stream.*All streaming events: stream.chunk, stream.start, etc.
agent.*All agent lifecycle events
*All events
stream.chunkExact match only
*.completedAny completed event: agent.completed, cron.completed, etc.

Patterns are matched against the full topic string. The * wildcard matches any sequence of non-dot characters. Use * alone to subscribe to everything.

Typical Client Flow

A typical client subscribes to events before starting agent interactions:

// 1. Subscribe to relevant events
{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "events.subscribe",
  "params": {
    "patterns": ["stream.*", "agent.*", "exec.*"]
  }
}

// 2. Start an agent run
{
  "jsonrpc": "2.0",
  "id": 2,
  "method": "agent.run",
  "params": {
    "message": "Check disk usage and alert if over 80%"
  }
}

// 3. Receive stream events
{ "jsonrpc": "2.0", "method": "event", "params": { "topic": "agent.started", "data": { "run_id": "run-123" } } }
{ "jsonrpc": "2.0", "method": "event", "params": { "topic": "stream.start", "data": { "run_id": "run-123" } } }
{ "jsonrpc": "2.0", "method": "event", "params": { "topic": "stream.tool_start", "data": { "run_id": "run-123", "tool_name": "shell:exec" } } }
{ "jsonrpc": "2.0", "method": "event", "params": { "topic": "stream.tool_end", "data": { "run_id": "run-123", "tool_name": "shell:exec" } } }
{ "jsonrpc": "2.0", "method": "event", "params": { "topic": "stream.chunk", "data": { "run_id": "run-123", "content": "Disk usage is at 45%..." } } }
{ "jsonrpc": "2.0", "method": "event", "params": { "topic": "stream.end", "data": { "run_id": "run-123" } } }
{ "jsonrpc": "2.0", "method": "event", "params": { "topic": "agent.completed", "data": { "run_id": "run-123" } } }

See Also

On this page