Skip to navigation

Streaming

When streaming_enabled is true on session creation, agent responses arrive incrementally as EVENT_TYPE_POLY_AGENT_MESSAGE_CHUNK events instead of a single EVENT_TYPE_POLY_AGENT_MESSAGE. This lets you display the response as it’s generated.

Chunk format

{
"type": "EVENT_TYPE_POLY_AGENT_MESSAGE_CHUNK",
"payload": {
"message_id": "msg_abc123",
"text": "I'd be happy to ",
"attachments": [],
"response_suggestions": [],
"chunk_index": 1,
"is_complete": false
}
}
FieldTypeDescription
message_idstringSame across all chunks of one message — use this to group them
textstringA fragment of text to append to the message
attachmentsarrayAttachment(s) to append to the attachment list
response_suggestionsarraySuggestion(s) to append to the suggestions list
chunk_indexinteger1-based index. Process chunks in this order.
is_completebooleantrue on the final chunk — the message is now complete

Reassembling chunks

To reconstruct the full message, concatenate text and append attachments / response_suggestions from each chunk in order:

ChunkReceivedAccumulated message
1text: "Hello ", attachments: [A1], suggestions: [S1]text: "Hello ", attachments: [A1], suggestions: [S1]
2text: "there, ", attachments: [], suggestions: []text: "Hello there, ", attachments: [A1], suggestions: [S1]
3text: "how can I help?", is_complete: truetext: "Hello there, how can I help?", attachments: [A1], suggestions: [S1]

The final chunk (is_complete: true) may have empty text. It signals that the message is complete and may carry attachments or response suggestions that were only available after the full response was generated.

Example: handling chunks in JavaScript

const streamingMessages = {};
function handleChunk(payload) {
const { message_id, text, attachments, response_suggestions, chunk_index, is_complete } = payload;
if (!streamingMessages[message_id]) {
streamingMessages[message_id] = { text: "", attachments: [], suggestions: [] };
}
const msg = streamingMessages[message_id];
msg.text += text;
msg.attachments.push(...attachments);
msg.suggestions.push(...response_suggestions);
updateMessageInUI(message_id, msg);
if (is_complete) {
finalizeMessageInUI(message_id, msg);
delete streamingMessages[message_id];
}
}

Streaming flow

rect [rgb(240, 248, 255)] USER_MESSAGE echo (USER_MESSAGE) POLY_AGENT_THINKING POLY_AGENT_MESSAGE_CHUNK (chunk_index: 1, text: "I'd be happy to ") POLY_AGENT_MESSAGE_CHUNK (chunk_index: 2, text: "help you with ") POLY_AGENT_MESSAGE_CHUNK (chunk_index: 3, text: "your booking!", is_complete: true) Streaming chunks (same message_id) Reassembled: "I'd be happy to help you with your booking!" Your App PolyAI