For the complete documentation index, see llms.txt. This page is also available as Markdown.

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 stream

Streaming 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:

resumeStream( onChunk, decision, threadId, editedData, decidedBy, reason ) — onChunk comes first. Valid decisions are approve, approve_always, approve_session, reject, edit, and cancel.

When a turn requested several tool calls needing approval, they suspend together as one checkpoint; pass an array of per-call decision structs to resolve them individually. Streaming batch approvals are supported on OpenAI and Claude — the two providers with streaming tool-call support today.

Last updated