Skip to main content

SgrAgentStream

Trait SgrAgentStream 

Source
pub trait SgrAgentStream: SgrAgent {
    // Required method
    fn decide_stream<T>(
        &self,
        messages: &[Self::Msg],
        on_token: T,
    ) -> impl Future<Output = Result<StepDecision<Self::Action>, Self::Error>> + Send
       where T: FnMut(&str) + Send;
}
Expand description

Streaming extension for SGR agents.

Implement this alongside SgrAgent to get streaming tokens during the decision phase. Use with run_loop_stream.

impl SgrAgentStream for MyAgent {
    fn decide_stream<T>(&self, messages: &[Msg], mut on_token: T)
        -> impl Future<Output = Result<StepDecision<Action>, Error>> + Send
    where T: FnMut(&str) + Send
    {
        async move {
            let stream = B.MyFunction.stream(&messages).await?;
            while let Some(partial) = stream.next().await {
                on_token(&partial.raw_text);
            }
            let result = stream.get_final_response().await?;
            Ok(StepDecision { ... })
        }
    }
}

Required Methods§

Source

fn decide_stream<T>( &self, messages: &[Self::Msg], on_token: T, ) -> impl Future<Output = Result<StepDecision<Self::Action>, Self::Error>> + Send
where T: FnMut(&str) + Send,

Call LLM with streaming — emits tokens via on_token callback.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§