wave-pulseStreaming

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(
    callback: ( 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:

Last updated