Skip to main content

rig_agent/
streaming.rs

1//! High-level streaming prompting traits for the classic agent runtime.
2
3use crate::{
4    agent::StreamingPromptRequest,
5    completion::{CompletionModel, GetTokenUsage, Message},
6};
7use rig_core::wasm_compat::{WasmCompatSend, WasmCompatSync};
8
9pub use rig_core::streaming::*;
10
11/// High-level one-shot streaming prompt interface.
12pub trait StreamingPrompt<M, R>
13where
14    M: CompletionModel + 'static,
15    M::StreamingResponse: WasmCompatSend,
16    R: Clone + Unpin + GetTokenUsage,
17{
18    /// Create a classic streaming request for `prompt`.
19    fn stream_prompt(
20        &self,
21        prompt: impl Into<Message> + WasmCompatSend,
22    ) -> StreamingPromptRequest<M>;
23}
24
25/// High-level streaming chat interface with caller-provided history.
26pub trait StreamingChat<M, R>: WasmCompatSend + WasmCompatSync
27where
28    M: CompletionModel + 'static,
29    M::StreamingResponse: WasmCompatSend,
30    R: Clone + Unpin + GetTokenUsage,
31{
32    /// Create a classic streaming request with canonical chat history.
33    fn stream_chat<I, T>(
34        &self,
35        prompt: impl Into<Message> + WasmCompatSend,
36        chat_history: I,
37    ) -> StreamingPromptRequest<M>
38    where
39        I: IntoIterator<Item = T> + WasmCompatSend,
40        T: Into<Message>;
41}