Skip to main content

Token-by-token streaming flow with backpressure policy

Primitives used: persona · flow · step · tool · axonendpoint

// `Stream<T>` makes a flow emit tokens incrementally. Any flow whose
// signature carries `Stream<T>` MUST be reachable from a tool that
// declares a `stream:<policy>` effect — the language refuses to ship
// a stream without explicit backpressure.

persona ChatHost {
domain: ["chat"]
tone: friendly
confidence_threshold: 0.6
cite_sources: false
}

tool ChatBackend {
// LLM-routed: the tool IS the model. No `provider:` (v2.69.0).
effects: <network, stream:drop_oldest>
timeout: 60s
}

type Utterance { text: String }
type Token { piece: String }
type ChatRequest { req: Utterance }

flow Chat(req: Utterance) -> Stream<Token> {
step Generate {
given: req
apply: ChatBackend
ask: "Reply to the user, one token at a time."
output: Stream<Token>
}
return Generate.output
}

axonendpoint ChatAPI {
method: post
path: "/v1/chat"
body: ChatRequest
execute: Chat
output: Stream<Token>
backend: auto
transport: sse(axon)
retries: 0
timeout: 60s
public: true // authorization-coverage opt-out (every_boundary_is_guarded)
}