Chapter 10: Streaming
Streaming is essential for AI applications. ChronoAI models streaming as a frame status: chunks are fed first, then committed as a final value.
Two Phases: feed() vs commit()
const writer = agent.stream('ai-response');
writer.feed('Hello');
writer.feed('Hello, world');
writer.commit('Hello, world!');
feed() updates the timeline with an in-progress frame. commit() finalizes the frame and triggers normal propagation.
status: 'streaming'
During streaming, frames can be marked as streaming. Observers can use this to render partial output differently.
agent.observeTimeline('ai-response', frame => {
if (frame.status === 'streaming') {
renderPartial(frame.value);
} else {
renderFinal(frame.value);
}
});
Listening to Streaming Updates
Use timeline observers for UI updates.
const unsubscribe = agent.observeTimeline('ai-response', frame => {
document.querySelector('#output')!.textContent = frame.value;
});
Remember to unsubscribe when the UI component is destroyed.
When to Use Streaming
Streaming is useful for:
- LLM responses
- tool execution logs
- background progress
- realtime rendering
- long-running transforms
It should be used when partial output has value to the user.
Toolkit Support
@chronoai/toolkit/llm supports streaming model calls out of the box. The executor feeds chunks into the target timeline and commits the final response.
LlmCall.plan({
messages,
target: 'ai-response',
});
Summary
feed()writes partial streaming state.commit()finalizes the frame.- Observers can render partial and final states.
- Commands are the natural place to perform streaming side effects.
Next
Continue with Chapter 11: Roleplay and Status Panel.