rydantic dependency for model derive resolution. Custom providers work with rydantic-ai = { version = "0.6.0", default-features = false }. Streams start on the current Tokio runtime.
Partial object previews
Partial<T> is a typed stream handle. Its snapshots contain JSON values with the fields available so far; the terminal result contains the fully validated T.
{"name":"Ada"} while age is still missing. Required fields stay missing and final validators have not run. complete_json describes the syntax of the current buffer; the producer can still append bytes. Use the Complete event as the accepted model result.
Unfinished strings and object keys wait for more input. Partial snapshots recover available containers, literals and numbers through the existing partial JSON parser; truncated string contents are not exposed. Snapshots reparse accumulated buffers and can incur quadratic total work across many small chunks. Partial::finish().await drains progress and returns only RunResult<T>.
Stream validated list elements
Agent<Dependencies, T>::stream_iterable() requests a JSON object containing {"items": [T, ...]}. This object envelope supports native JSON Schema endpoints, including providers that require an object at the root. Its schema is generated from T, including nested and recursive definitions.
StreamItem<T> contains a zero-based index and a fully parsed, normalized and validated value: T. Sync and async validators run before emission. No Clone implementation is required. Numbers wait for a right delimiter so a fragment 1 followed by 2, becomes one item 12. Nested values, Unicode, escaped strings and exact numeric lexemes are preserved.
For an accepted list and complete metadata, collect a fresh stream:
collect() clears invalidated attempts automatically. Call it before manually consuming item events; previously consumed items cannot be recovered. Async item checks run once per emitted element per attempt. Finalization checks the complete JSON envelope, duplicate/unknown fields and item count without rerunning those checks. A syntactically invalid tail can invalidate earlier valid items.
Validation correction and attempt boundaries
Every progress event carries the one-based model-call number. Output validation failures produceResetReason::Validation(errors) before bounded correction. The errors include field/index paths, and the Agent sends them back to the model. Tool turns produce ResetReason::ToolContinuation before execution. The next model call starts a new attempt with an empty preview or list.
Backpressure, cancellation and limits
stream.cancel() requests cancellation explicitly. The parent context remains available for other work; cancelling the parent also cancels the stream.
Provider integration
The Responses, Chat Completions and Anthropic Messages providers normalize native text deltas automatically. Custom providers emitresponse.output_text.delta events through their supplied RunContext. Streaming calls set ModelRequest::stream = true and retain the caller’s original native-event sink.
Deltas must belong to a single text part per model call and exactly match the text in the completed response. Refusals, incomplete transport termination, text mismatches and resource-limit failures stop the stream. Providers that return only a completed response still work; progress events become available after that response arrives.
Run the offline example with cargo run -p rydantic-ai --example structured. The same APIs work with the HTTP feature disabled.