Event Reference
This page enumerates the three discriminated-union event streams in
@inbrowser/agent. Each is a typed AsyncIterable consumed at a different
layer.
| Stream | Discriminant | Source | Consumer |
|---|---|---|---|
SessionEvent | kind | AgentSession.submit(prompt, signal) | The host. |
StrategyEvent | kind | AgentStrategy.run(input, signal) | The session (translates into SessionEvent). |
ModelEvent | kind | ModelClient.chat(req, signal) | The strategy. |
The flow is layered: chat yields ModelEvents to the strategy, the strategy
yields StrategyEvents to the session, and the session yields SessionEvents
to the host. ModelEvent is the shared contract from
@inbrowser/model/contract (re-exported from @inbrowser/agent); the other two
streams are agent-internal types layered on top of it.
SessionEvent
Yielded by AgentSession.submit. The session-owned turnId correlates events
within one turn.
kind | Fields | Meaning |
|---|---|---|
turn_started | turnId: string | A turn has begun. Emitted first. |
text | turnId: string, chunk: string | A chunk of assistant output text. |
thinking | turnId: string, chunk: string | A chunk of hidden reasoning text. |
tool_started | turnId: string, callId: string, name: string, args: unknown, signature?: string | The model requested a tool call. |
tool_finished | turnId: string, callId: string, result: ToolResult | A tool call completed. |
workspace_changed | workspace: Workspace | A tool result patched the workspace. Emitted after the tool_finished that caused it. |
runtime_changed | runtime: RuntimeState | A tool result patched the runtime state. |
turn_completed | turnId: string, metrics: TurnMetrics, details: TurnDetails | The turn finished. Carries recorded metrics and turn details. |
error | turnId?: string, message: string | The run failed. Terminates the stream. |
completed | (none) | The run completed normally. Emitted last. |
strategy_event | name: string, data?: unknown | A strategy-emitted milestone. Generic envelope (planner phases, branch expansions, reflexion critiques). |
Notes:
- A run ends with either
completed(normal) orerror(failure). After anerror, no further events are yielded. strategy_eventcarries thenameanddataof a strategy’scustomevent. The ReAct strategy with reflexion enabled emits one namedreflexion_critique.
StrategyEvent
Yielded by AgentStrategy.run. The session maps each variant onto a
SessionEvent.
kind | Fields | Maps to SessionEvent |
|---|---|---|
text | chunk: string | text |
thinking | chunk: string | thinking |
tool_call | id: string, name: string, args: unknown, signature?: string | tool_started |
tool_result | id: string, result: ToolResult | tool_finished (plus workspace_changed / runtime_changed when the result carries patches) |
turn_complete | usage: ModelUsage, details: TurnDetails | turn_completed (after the session records metrics from usage) |
error | message: string | error (terminates the run) |
custom | name: string, data?: unknown | strategy_event |
Notes:
- The session derives
turnIdandcallIdmappings:tool_call.idbecomestool_started.callId, andtool_result.idbecomestool_finished.callId. turn_complete.usageis the raw provider usage; the session passes it to theMetricsCollectorand stamps the resultingTurnMetricsontoturn_completed.customis the extension point: new strategies surface milestones without expanding the union. The ReAct strategy’s reflexion pass emitscustomevents namedreflexion_critiquewith a{ verdict, text, feedback? }payload, whereverdictis'ok','retry', or'exhausted'.
ModelEvent
Yielded by ModelClient.chat. The provider-level stream the strategy consumes.
This is the shared contract from @inbrowser/model/contract, re-exported from
@inbrowser/agent.
kind | Fields | Meaning |
|---|---|---|
text | text: string | A chunk of assistant output text. |
thinking | text: string | A chunk of hidden reasoning text. |
tool_call | id: string, name: string, args: unknown, signature?: string | The model requested a tool call. |
usage | usage: ModelUsage | Final per-turn accounting. Emitted once, just before the iterable returns. |
error | message: string | The provider call failed. Terminal. |
ModelUsage:
| Field | Type | Description |
|---|---|---|
promptTokens | number | Input tokens. |
outputTokens | number | Output tokens. |
cachedTokens | number (optional) | Cache-hit input tokens. |
reasoningTokens | number (optional) | Reasoning tokens. |
costUsd | number (optional) | Provider-supplied cost; bypasses pricing tables when present. |
Notes:
- The turn ends when the async iterable returns; there is no
turn_completeevent. On a normal end ausageevent is emitted before the return — it carries the final accounting. Anerrorevent is itself terminal: after it the iterable returns with nousageevent. Consumers can rely on exactly one of {ausageevent, anerrorevent} per turn. signaturecarries a provider-specific token (for example a Gemini thoughtSignature) through round-trips. It is absent on providers that do not emit one.- The strategy translates this stream into
StrategyEvents:text/thinkingfragments are re-emitted (aschunk), and theusageevent becomes the strategy’sturn_complete, where the session synthesizesTurnDetails({ requestedModel }) from the clientidbefore recording metrics.
Mutation events (distinct stream)
The three streams above are the in-process runtime event streams. They are
distinct from MutationEvent, the on-disk audit record a mutating tool emits
to a project’s event log via wrapMutating. MutationEvent is documented with
the event-log surface in library.md; its three lifecycle
phases (plan, commit, rollback) are filterable by the
agent events command.