Overview
The response stream consists of a sequence of events. Each event has atype and a data payload. The client should listen for these events to reconstruct the agent’s activity and the final message content.
Event Types
Here are the primary event types you will encounter:Initialization Events
connection_established
Sent immediately when the SSE connection is successfully opened.
agent_processing_started
Indicates that the agent has received the request and started processing.
response_stream_start
Signals the beginning of the content stream.
Execution Events
agent_step_started
Fired when the agent begins a specific step in its plan.
agent_step_progress
Provides updates on the progress of the current step.
agent_response_update
Provides a full update of the agent’s response content. This is often used for synchronization or when the entire response needs to be refreshed.
agent_step_completed
Indicates that a specific step has been successfully completed.
agent_progress
Provides an overall progress update for the agent’s task.
response_chunk
Contains a partial text chunk of the agent’s response. These chunks should be concatenated to form the full text. This stream includes both the agent’s natural language response and injected tags for tool calls.
checkpoint_created
Indicates a checkpoint has been reached in the agent’s execution flow.
input_required
The agent requires user input to proceed. This usually happens at a specific checkpoint.
Tool Execution Events
Events related to the agent using tools. Note that the textual representation of tool calls (inputs/outputs) appears in theresponse_chunk stream, while these events provide structured status updates.
For a detailed tutorial on how to handle these events to build a rich UI, please refer to the Handling Tool Streaming guide.
tool_update
Updates on tool execution status, phases, or metadata.
tool_partial_update
Streaming output from a tool (e.g., a long-running process, generated content, or “thinking” from a sub-agent).
tool_input_required
The tool requires human intervention or confirmation.
Completion Events
agent_processing_complete
Indicates the agent has finished its task.
Parsing Response Content
Theresponse_chunk events carry the raw text generated by the agent. This text often contains structured tags (like <<TOOL_STEP_START>>, <<thinking>>, etc.) that represent the agent’s internal state and actions.
For a detailed reference on how to parse these tags and structure the final message, please refer to the Agent Message Structure guide.
Handling and Reconstructing Content
To correctly display the agent’s response, you have two main options:Option 1: Use the Ubik Agent SDK (Recommended)
The easiest way to handle the event stream is to use the official SDKs, which automatically handle connection management, event parsing, chunk reassembly, and message reconstruction. These SDKs provide a clean, ready-to-render Markdown representation of the agent’s activity.Note: Theubik-agent(JavaScript/TypeScript) andubik-agent-py(Python) SDKs are currently under development.
Option 2: Process Raw Events (Advanced)
If you are building a custom interface or cannot use the SDKs, you can process the raw SSE events directly. This requires implementing the state reconstruction logic yourself. To faithfully reflect the agent’s behavior, it is recommended to use a state reconstruction approach rather than a simple concatenation stream.Reconstruction Logic (Rebuild)
The recommended implementation maintains a chronological list of all events and rebuilds the complete message content on each update. Here is the logic:- Store Sequence: Add each incoming event (
step_started,response_chunk,checkpoint, etc.) to aneventSequencearray. - Sort: Ensure events are sorted by timestamp.
- Generate Content: Iterate through the sequence to build the final string. For details on building message elements, see the Agent Message Structure guide:
- Steps (
agent_step_started): Open a block with<<STEP_START>>. Allresponse_chunkevents associated with this step must be inserted inside. Close with<<STEP_END>>once the step is completed or when changing steps. - Non-step Chunks (
response_chunk): If a chunk is not associated with a step, it is added directly to the main content (often after a newline). - Checkpoints (
checkpoint_created): Insert<<CHECKPOINT_START>>…<<CHECKPOINT_END>>tags at the appropriate chronological position. - Input Required (
input_required): Generate an<<INPUT_REQUIRED_START>>block containing the prompt and expected types. If input has been provided, include it in a<<USER_INPUT_PROVIDED_START>>block. - Tools (
tool_update): These events provide real-time status. While you can inject them into the text with temporary tags (like<<TOOL_EVENT_START>>) for display, it is recommended to use the event data directly to render reactive UI components (spinners, status logs) on top of the text stream. These temporary tags are not preserved in the final history.
- Steps (
chunks) are correctly represented in the final message.
Large Payloads (Chunking)
For very large events that exceed SSE limits, the system may split a single event into multiple chunks. These events have a type ending in_delta_sse (e.g., response_chunk_delta_sse, tool_update_delta_sse, agent_processing_complete_delta_sse).
Note: Any event type can be chunked if its payload is large enough. The client should be prepared to handle _delta_sse variants for all event types.
The payload for these events includes:
chunk_id: Unique ID for the split event.chunk_index: Index of the current chunk (0-based).total_chunks: Total number of chunks to expect.original_event_type: The type of the event being reconstructed.chunk_data: The partial data string.
- Buffer incoming chunks by
chunk_id. - When
receivedChunks === totalChunks, join thechunk_datain order. - Parse the joined string as JSON.
- Process the result as a standard event of type
original_event_type.
Example: JavaScript Event Handler
Here is a simplified example of how you might handle these events in a frontend application:Error Handling
If an error occurs during processing, you may receive anagent_processing_error event.

