Skip to main content
AgentFlow streams all responses using Server-Sent Events (SSE). This delivers token-by-token output and tool execution updates in real time.

Event Types

TypeDescription
STARTExecution begins (agent or tool)
DELTAIncremental content (streamed tokens)
ENDExecution complete with full response
ERRORAn error occurred
APPROVAL_REQUIREDTool awaiting human approval
APPROVAL_RESOLVEDApproval decision received
QUESTION_ASKEDAgent asks a clarifying question
QUESTION_ANSWEREDUser answers the question

Event Structure

{
  "type": "DELTA",
  "delta": "Here is the next token",
  "metadata": {
    "icon": "robot",
    "display_name": "MainAgent",
    "content_type": "text"
  },
  "timestamp": "2025-01-15T10:30:00Z",
  "call_id": "call_abc123"
}

Consuming the Stream

cURL

curl -N -X POST http://localhost:8000/agent/MainAgent/chat \
  -H "Content-Type: application/json" \
  -d '{"message": "Hello"}'

Python SDK

import agentflow as af

async for event in af.chat_stream("Hello", agent="MainAgent"):
    if event.type == "DELTA":
        print(event.delta, end="", flush=True)

JavaScript

const response = await fetch("/agent/MainAgent/chat", {
  method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({ message: "Hello" }),
});

const reader = response.body.getReader();
const decoder = new TextDecoder();

while (true) {
  const { done, value } = await reader.read();
  if (done) break;
  const event = JSON.parse(decoder.decode(value));
  process.stdout.write(event.delta || "");
}

Verbose Mode

Set verbose=true to receive events from nested tool and sub-agent executions, not just the top-level agent.