pub struct AgentEventStream { /* private fields */ }Expand description
High-level typed event stream for a single agent run.
AgentEventStream owns a StreamBroadcaster and exposes named emit_*
helpers so that agent loop code does not need to construct AgentEvent
variants directly.
use llm_agent_runtime::streaming::{AgentEventStream, StreamBroadcaster};
let stream = AgentEventStream::new(64)?;
let mut rx = stream.broadcaster().subscribe();
stream.emit_thought("I should search the web.")?;
stream.emit_action("search", r#"{"q":"Rust"}"#)?;
stream.emit_observation("Rust is a systems language.")?;
stream.emit_result("The answer is: Rust.")?;Implementations§
Source§impl AgentEventStream
impl AgentEventStream
Sourcepub fn new(capacity: usize) -> Result<Self, AgentRuntimeError>
pub fn new(capacity: usize) -> Result<Self, AgentRuntimeError>
Create a new stream with a broadcast channel of the given capacity.
§Errors
Returns Err if capacity is zero.
Sourcepub fn broadcaster(&self) -> &StreamBroadcaster
pub fn broadcaster(&self) -> &StreamBroadcaster
Borrow the underlying StreamBroadcaster (e.g. to create additional
subscribers).
Sourcepub fn emit_thought(
&self,
thought: impl Into<String>,
) -> Result<usize, AgentRuntimeError>
pub fn emit_thought( &self, thought: impl Into<String>, ) -> Result<usize, AgentRuntimeError>
Emit a Thought event.
Sourcepub fn emit_action(
&self,
tool: impl Into<String>,
input: impl Into<String>,
) -> Result<usize, AgentRuntimeError>
pub fn emit_action( &self, tool: impl Into<String>, input: impl Into<String>, ) -> Result<usize, AgentRuntimeError>
Emit an Action event.
Sourcepub fn emit_observation(
&self,
observation: impl Into<String>,
) -> Result<usize, AgentRuntimeError>
pub fn emit_observation( &self, observation: impl Into<String>, ) -> Result<usize, AgentRuntimeError>
Emit an Observation event.
Sourcepub fn emit_result(
&self,
result: impl Into<String>,
) -> Result<usize, AgentRuntimeError>
pub fn emit_result( &self, result: impl Into<String>, ) -> Result<usize, AgentRuntimeError>
Emit a Result event.
Sourcepub fn emit_error(
&self,
error: impl Into<String>,
) -> Result<usize, AgentRuntimeError>
pub fn emit_error( &self, error: impl Into<String>, ) -> Result<usize, AgentRuntimeError>
Emit an Error event.
Sourcepub fn receiver_count(&self) -> usize
pub fn receiver_count(&self) -> usize
Return the number of active subscribers.
Trait Implementations§
Source§impl Clone for AgentEventStream
impl Clone for AgentEventStream
Source§fn clone(&self) -> AgentEventStream
fn clone(&self) -> AgentEventStream
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for AgentEventStream
impl !RefUnwindSafe for AgentEventStream
impl Send for AgentEventStream
impl Sync for AgentEventStream
impl Unpin for AgentEventStream
impl UnsafeUnpin for AgentEventStream
impl !UnwindSafe for AgentEventStream
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more