Streaming
Stream agent responses in real-time using callback-based chunk delivery.
Agents support streaming responses, delivering content in real-time chunks as the AI generates them.
Basic Streaming
agent = aiAgent(
name : "StreamAgent",
description: "Streaming assistant"
)
// Accumulate response as it streams
response = ""
agent.stream(
onChunk: ( chunk ) => {
content = chunk.choices?.first()?.delta?.content ?: ""
response &= content
print( content ) // Print each chunk immediately
},
input: "Write a short story about BoxLang"
)
// response now contains the full text
println( "" ) // New line after streamStreaming with Parameters
Streaming in a Pipeline
Agents implement IAiRunnable, so they work in streaming pipelines:
Streaming with Memory
Streaming calls store messages in memory the same as regular calls:
Streaming with Per-Call Identity (v3.0+)
Resume Streaming (v3.0+)
After a suspension, resume and stream the continuation:
Related Pages
Getting Started — Agent construction and return formats
Memory Management — Per-call identity routing in streaming
Middleware — Intercepting stream lifecycle events
Pipeline Streaming — Streaming in full pipelines
Last updated