JSON Event Stream Mode
Choosing an integration mode
JSON mode is one of three ways to drive Atomic from your own software. Pick the smallest one that does the job.
If you need the event contract rather than a walkthrough, go to the RPC protocol or the SDK API reference. Programmatic use compares all three modes side by side.
Event Types
Events are defined inAgentSessionEvent:
queue_update emits the full pending steering and follow-up queues whenever they change. session_info_changed, model_changed, and thinking_level_changed report interactive session metadata changes. compaction_start and compaction_end cover manual and automatic verbatim line compaction: the model emits deleted ranges and Atomic mechanically reconstructs retained text.
agent_end closes one low-level agent run; retries, compaction recovery, or queued work may still continue. agent_settled means no automatic work remains for the session-level run. Its aborted field is true when the run was cancelled.
For automatic compaction, compaction_end.willRetry === true means the interrupted turn will retry; AgentSession.prompt() waits for that continuation. This includes overflow and retry-worthy threshold recovery, such as output-token truncation or OpenAI Responses output-budget underflow. Generic invalid_request_body failures still use willRetry: false when threshold compaction is warranted.
If same-model compact-and-retry recovery is exhausted, unresolvedOverflow: true and errorMessage let integrations choose another model rather than treating the prompt as successful.
Check result and errorMessage independently. Both can be present when the boundary was saved but the follow-up request exceeded the provider’s hard input limit.
Compaction planning and branch summaries reuse the configured retry policy for transient provider failures. Their summarization_retry_* events expose scheduling, each restarted request (including whether it belongs to branch summarization or a compaction reason), and retry-loop completion to JSON, RPC, SDK, and interactive consumers.
Base events come from AgentEvent in @earendil-works/pi-agent-core (installed as an Atomic dependency):
durationMs timing. On tool_execution_end, it records how long the tool’s execute() took using a monotonic clock; it is absent when the tool did not run.
On the wire, each message_update record carries:
- The streaming delta in
assistantMessageEvent, with its cumulativepartialfield stripped. - The latest cumulative provider-reported
usage. This may remain zero until completion if the provider reports usage only at the end. endTurn, only when the provider reported it. This is the provider’s explicit end-of-turn signal, pi-ai’sAssistantMessage.endTurn, for example OpenAI Codexend_turn.
Message Types
Base messages come from@bastani/pi-ai (installed as an Atomic dependency):
UserMessageAssistantMessageToolResultMessage
packages/coding-agent/src/core/messages.ts:
BashExecutionMessageCustomMessageBranchSummaryMessage