Skip to content

Agent Streaming Protocol

A protocol for AI agent sessions with durable message streaming and resumable connections.

What is Agent Streaming Protocol?

The Agent Streaming Protocol enables AI agent interactions over HTTP with full resumability. Unlike traditional WebSocket-based chat, sessions survive disconnections - clients can reconnect and replay any missed messages from the exact point they left off.

Built on top of Unbroken Protocol, it combines:

  • Claude Agent SDK for AI model interaction
  • Unbroken Protocol for message persistence
  • SSE for real-time streaming

Key Features

FeatureDescription
ResumableReconnect and continue from any point
PersistentFull conversation history preserved
Tool UseStream tool calls and results
Web NativeWorks in browsers via SSE

Architecture

┌─────────────────────────────────────────────────────────────┐
│ Client │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Message │ │ Tool │ │ Offset │ │
│ │ Input │ │ Executor │ │ Storage │ │
│ └──────┬──────┘ └──────┬──────┘ └──────┬──────┘ │
└─────────┼──────────────────┼──────────────────┼─────────────┘
│ POST │ POST │
▼ ▼ │
┌─────────────────────────────────────────────────────────────┐
│ Agent Server │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Claude │◀───│ Session │───▶│ Durable │ │
│ │ API │ │ Manager │ │ Stream │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
└─────────────────────────────────────────────────────────────┘

Quick Example

Terminal window
# Create a session
curl -X PUT http://localhost:9999/agent/my-chat \
-H "Content-Type: application/json" \
-d '{"model": "claude-sonnet-4-5-20250929"}'
# Stream messages (SSE)
curl "http://localhost:9999/agent/my-chat?offset=-1&live=sse"
# Send a prompt
curl -X POST http://localhost:9999/agent/my-chat/prompt \
-H "Content-Type: application/json" \
-d '{"content": [{"type": "text", "text": "Hello!"}]}'

Protocol at a Glance

Endpoints

MethodPathDescription
PUT/agent/{id}Create session
GET/agent/{id}?offset=X&live=sseStream messages
POST/agent/{id}/promptSend user message
POST/agent/{id}/tool-resultSubmit tool result
POST/agent/{id}/cancelCancel current turn
DELETE/agent/{id}End session
HEAD/agent/{id}Check session exists

Headers

HeaderDirectionDescription
Stream-Next-OffsetResponseOffset for resumption
Stream-Up-To-DateResponseAt end of messages

SSE Event Types

EventDescription
userUser message sent to agent
assistantAgent response text
tool_useAgent requests tool execution
tool_resultTool result submitted
turn_completeTurn finished with stop reason
errorError occurred
controlStream metadata/offset

Use Cases

  • AI Assistants: Persistent chat with tool use
  • Code Agents: Autonomous coding with file/terminal tools
  • Workflows: Long-running AI tasks with checkpoints
  • Multi-client: Share agent sessions across devices

Specification

For the complete protocol specification, see PROTOCOL.md.

Default Port

The agent server uses port 9999/tcp by default (same as Unbroken Protocol).

Requirements

  • Server: Bun runtime, ANTHROPIC_API_KEY environment variable
  • Client: Any HTTP client (browser, curl, custom)