Skip to Content
API ReferenceSSE Events

SSE Events

AEGIS uses Server-Sent Events (SSE) to stream real-time updates from agent executions, workspace assessments, and conversation interactions.

Connection Setup

SSE endpoints return a stream of text/event-stream content. Connect using the standard EventSource API or any SSE client.

const token = 'your-jwt-token'; const eventSource = new EventSource( 'http://localhost:8000/conversations/{conversation_id}/stream', { headers: { 'Authorization': `Bearer ${token}` } } ); eventSource.onmessage = (event) => { const data = JSON.parse(event.data); console.log(data.event_type, data); }; eventSource.onerror = (error) => { console.error('SSE connection error:', error); eventSource.close(); };
# Using curl curl -N -H "Authorization: Bearer $TOKEN" \ http://localhost:8000/conversations/{conversation_id}/stream

SSE Endpoints

EndpointPurpose
GET /conversations/{id}/streamStream conversation events (agent responses, tool calls)
GET /workspaces/{checklist_id}/streamStream workspace assessment events

Event Format

Each SSE event is a JSON object with an event_type field:

data: {"event_type": "agent_status", "status": "thinking", "node": "initial_llm_call"} data: {"event_type": "checklist_item_update", "item_index": 2, "status": "complete"}

Conversation Events

Events emitted during agent conversation streaming:

Event TypeDescriptionKey Fields
agent_statusAgent processing state changestatus (thinking, calling_tool, synthesizing), node
tokenStreaming text tokencontent (partial text)
tool_callAgent invoked a tooltool_name, arguments
tool_resultTool execution completedtool_name, result
errorProcessing errormessage, code
doneStream completefinal_response

Example: Conversation Stream

data: {"event_type": "agent_status", "status": "thinking", "node": "system_prompt_node"} data: {"event_type": "agent_status", "status": "thinking", "node": "memory_node"} data: {"event_type": "agent_status", "status": "thinking", "node": "initial_llm_call"} data: {"event_type": "token", "content": "Based on "} data: {"event_type": "token", "content": "the spacing "} data: {"event_type": "token", "content": "analysis..."} data: {"event_type": "tool_call", "tool_name": "spacing_calculation", "arguments": {"well_api": "42-123-45678"}} data: {"event_type": "tool_result", "tool_name": "spacing_calculation", "result": {"min_distance_ft": 340}} data: {"event_type": "agent_status", "status": "synthesizing", "node": "synthesis_llm_call"} data: {"event_type": "token", "content": "The proposed well is 340 feet..."} data: {"event_type": "done", "final_response": "...complete response text..."}

Workspace Events

Events emitted during entity compliance workspace assessments:

Event TypeDescriptionKey Fields
checklist_item_updateChecklist item status changeditem_index, status, label
artifact_generatedDocument/artifact produceditem_index, artifact_type, artifact_id
data_table_updateData table populated/updateditem_index, rows, columns
form_field_updateForm field value setitem_index, field_name, value
validation_resultCompliance check completedrule, passed, message
spatial_updateMap/spatial data updatedcoordinates, features
agent_statusAgent processing statusstatus, phase
assessment_completeFull assessment finishedsummary, risk_level

Example: Workspace Assessment Stream

data: {"event_type": "agent_status", "status": "assessing", "phase": "data_collection"} data: {"event_type": "checklist_item_update", "item_index": 0, "status": "in_progress", "label": "Well Data Review"} data: {"event_type": "data_table_update", "item_index": 0, "rows": [...], "columns": ["API", "Operator", "Distance"]} data: {"event_type": "checklist_item_update", "item_index": 0, "status": "complete"} data: {"event_type": "checklist_item_update", "item_index": 1, "status": "in_progress", "label": "Spacing Analysis"} data: {"event_type": "validation_result", "rule": "Rule 37 Spacing", "passed": false, "message": "340ft < 467ft minimum"} data: {"event_type": "artifact_generated", "item_index": 1, "artifact_type": "spacing_report", "artifact_id": "art-123"} data: {"event_type": "checklist_item_update", "item_index": 1, "status": "complete"} data: {"event_type": "assessment_complete", "summary": "2 of 5 checks passed", "risk_level": "high"}

Reconnection

The browser’s built-in EventSource automatically reconnects on connection drops. If using a custom SSE client, implement reconnection with exponential backoff.

If the connection drops:

  1. Wait 1 second, then reconnect
  2. Double the wait on each subsequent failure (max 30 seconds)
  3. The server does not replay missed events — reconnection starts from the current state

Error Events

If an error occurs during streaming, the server emits an error event before closing:

data: {"event_type": "error", "message": "Budget exceeded: 150000 token limit reached", "code": "BUDGET_EXCEEDED"}

Common error codes:

CodeDescription
BUDGET_EXCEEDEDAgent token or cost budget exhausted
TOOL_FAILUREA tool call failed during execution
APPROVAL_TIMEOUTHITL approval request timed out
INTERNAL_ERRORUnexpected server-side error
Last updated on