Skip to main content

POST /api/agents/companionAgent/stream

Generate a real-time streaming response from the companion agent using Server-Sent Events (SSE).

Request Body

The request body is identical to the generate endpoint.
messages
Array
required
Conversation history array containing user and assistant messages.
runtimeContext.metadata.personality
string
default:"friend"
Personality mode for the response. Options: "guru", "wanderer", "friend", "philosopher"
threadId
string
Unique identifier for the conversation thread. Recommended for conversation continuity.
resourceId
string
User identifier for conversation persistence. Recommended for user-specific conversations.

Streaming Response Format

Responses are sent as Server-Sent Events with the following event types:

Text Content Events

Tool Call Events

Tool Result Events

Completion Events

Error Events

Stream Event Types

JavaScript Stream Handler

Complete Example

cURL Example

Error Handling

Stream errors are sent as SSE events:

Best Practices

Connection Management: Always properly close stream connections to avoid resource leaks.
Error Recovery: Implement exponential backoff for stream reconnection on network errors.
UI Updates: Use the streaming events to provide real-time UI updates for better user experience.