pub struct EventStream { /* private fields */ }Expand description
Event stream with broadcast capability for real-time subscribers
Implementations§
Source§impl EventStream
impl EventStream
Sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Create event stream with custom channel capacity
Sourcepub fn append(
&self,
scope: EventScope,
event_type: EventType,
component_id: String,
status: ComponentStatus,
workflow_id: WorkflowId,
message: Option<String>,
data: JsonValue,
) -> JoinHandle<Result<Event, String>>
pub fn append( &self, scope: EventScope, event_type: EventType, component_id: String, status: ComponentStatus, workflow_id: WorkflowId, message: Option<String>, data: JsonValue, ) -> JoinHandle<Result<Event, String>>
Append a new event and broadcast to all subscribers
Events are emitted asynchronously in a spawned task to avoid blocking agent execution. Returns a JoinHandle that can be awaited if the caller needs to ensure the event was processed or needs the Event object.
§Examples
use agent_runtime::event::{EventStream, EventScope, EventType, ComponentStatus};
use serde_json::json;
let stream = EventStream::new();
// Fire and forget (most common)
stream.append(
EventScope::Agent,
EventType::Started,
"my_agent".to_string(),
ComponentStatus::Running,
"workflow_1".to_string(),
None,
json!({})
);
// Wait for event if needed
let event = stream.append(
EventScope::Agent,
EventType::Completed,
"my_agent".to_string(),
ComponentStatus::Completed,
"workflow_1".to_string(),
Some("Agent completed successfully".to_string()),
json!({})
).await.unwrap();Sourcepub fn append_with_parent(
&self,
scope: EventScope,
event_type: EventType,
component_id: String,
status: ComponentStatus,
workflow_id: WorkflowId,
parent_workflow_id: Option<WorkflowId>,
message: Option<String>,
data: JsonValue,
) -> JoinHandle<Result<Event, String>>
pub fn append_with_parent( &self, scope: EventScope, event_type: EventType, component_id: String, status: ComponentStatus, workflow_id: WorkflowId, parent_workflow_id: Option<WorkflowId>, message: Option<String>, data: JsonValue, ) -> JoinHandle<Result<Event, String>>
Append event with optional parent workflow ID
Events are emitted asynchronously to avoid blocking execution. Returns a JoinHandle that resolves to the created Event.
Sourcepub fn agent_started(
&self,
agent_name: &str,
workflow_id: WorkflowId,
data: JsonValue,
) -> JoinHandle<Result<Event, String>>
pub fn agent_started( &self, agent_name: &str, workflow_id: WorkflowId, data: JsonValue, ) -> JoinHandle<Result<Event, String>>
Emit Agent::Started event
Sourcepub fn agent_completed(
&self,
agent_name: &str,
workflow_id: WorkflowId,
message: Option<String>,
data: JsonValue,
) -> JoinHandle<Result<Event, String>>
pub fn agent_completed( &self, agent_name: &str, workflow_id: WorkflowId, message: Option<String>, data: JsonValue, ) -> JoinHandle<Result<Event, String>>
Emit Agent::Completed event
Sourcepub fn agent_failed(
&self,
agent_name: &str,
workflow_id: WorkflowId,
error: &str,
data: JsonValue,
) -> JoinHandle<Result<Event, String>>
pub fn agent_failed( &self, agent_name: &str, workflow_id: WorkflowId, error: &str, data: JsonValue, ) -> JoinHandle<Result<Event, String>>
Emit Agent::Failed event
Sourcepub fn llm_started(
&self,
agent_name: &str,
iteration: usize,
workflow_id: WorkflowId,
data: JsonValue,
) -> JoinHandle<Result<Event, String>>
pub fn llm_started( &self, agent_name: &str, iteration: usize, workflow_id: WorkflowId, data: JsonValue, ) -> JoinHandle<Result<Event, String>>
Emit LlmRequest::Started event
Sourcepub fn llm_progress(
&self,
agent_name: &str,
iteration: usize,
workflow_id: WorkflowId,
chunk: String,
) -> JoinHandle<Result<Event, String>>
pub fn llm_progress( &self, agent_name: &str, iteration: usize, workflow_id: WorkflowId, chunk: String, ) -> JoinHandle<Result<Event, String>>
Emit LlmRequest::Progress event (streaming chunk)
Sourcepub fn llm_completed(
&self,
agent_name: &str,
iteration: usize,
workflow_id: WorkflowId,
data: JsonValue,
) -> JoinHandle<Result<Event, String>>
pub fn llm_completed( &self, agent_name: &str, iteration: usize, workflow_id: WorkflowId, data: JsonValue, ) -> JoinHandle<Result<Event, String>>
Emit LlmRequest::Completed event
Sourcepub fn llm_failed(
&self,
agent_name: &str,
iteration: usize,
workflow_id: WorkflowId,
error: &str,
) -> JoinHandle<Result<Event, String>>
pub fn llm_failed( &self, agent_name: &str, iteration: usize, workflow_id: WorkflowId, error: &str, ) -> JoinHandle<Result<Event, String>>
Emit LlmRequest::Failed event
Sourcepub fn tool_started(
&self,
tool_name: &str,
workflow_id: WorkflowId,
data: JsonValue,
) -> JoinHandle<Result<Event, String>>
pub fn tool_started( &self, tool_name: &str, workflow_id: WorkflowId, data: JsonValue, ) -> JoinHandle<Result<Event, String>>
Emit Tool::Started event
Sourcepub fn tool_progress(
&self,
tool_name: &str,
workflow_id: WorkflowId,
message: &str,
percent: Option<u8>,
) -> JoinHandle<Result<Event, String>>
pub fn tool_progress( &self, tool_name: &str, workflow_id: WorkflowId, message: &str, percent: Option<u8>, ) -> JoinHandle<Result<Event, String>>
Emit Tool::Progress event
Sourcepub fn tool_completed(
&self,
tool_name: &str,
workflow_id: WorkflowId,
data: JsonValue,
) -> JoinHandle<Result<Event, String>>
pub fn tool_completed( &self, tool_name: &str, workflow_id: WorkflowId, data: JsonValue, ) -> JoinHandle<Result<Event, String>>
Emit Tool::Completed event
Sourcepub fn tool_failed(
&self,
tool_name: &str,
workflow_id: WorkflowId,
error: &str,
data: JsonValue,
) -> JoinHandle<Result<Event, String>>
pub fn tool_failed( &self, tool_name: &str, workflow_id: WorkflowId, error: &str, data: JsonValue, ) -> JoinHandle<Result<Event, String>>
Emit Tool::Failed event
Sourcepub fn workflow_started(
&self,
workflow_name: &str,
data: JsonValue,
) -> JoinHandle<Result<Event, String>>
pub fn workflow_started( &self, workflow_name: &str, data: JsonValue, ) -> JoinHandle<Result<Event, String>>
Emit Workflow::Started event
Sourcepub fn workflow_completed(
&self,
workflow_name: &str,
data: JsonValue,
) -> JoinHandle<Result<Event, String>>
pub fn workflow_completed( &self, workflow_name: &str, data: JsonValue, ) -> JoinHandle<Result<Event, String>>
Emit Workflow::Completed event
Sourcepub fn workflow_failed(
&self,
workflow_name: &str,
error: &str,
data: JsonValue,
) -> JoinHandle<Result<Event, String>>
pub fn workflow_failed( &self, workflow_name: &str, error: &str, data: JsonValue, ) -> JoinHandle<Result<Event, String>>
Emit Workflow::Failed event
Sourcepub fn step_started(
&self,
workflow_name: &str,
step_index: usize,
data: JsonValue,
) -> JoinHandle<Result<Event, String>>
pub fn step_started( &self, workflow_name: &str, step_index: usize, data: JsonValue, ) -> JoinHandle<Result<Event, String>>
Emit WorkflowStep::Started event
Sourcepub fn step_completed(
&self,
workflow_name: &str,
step_index: usize,
data: JsonValue,
) -> JoinHandle<Result<Event, String>>
pub fn step_completed( &self, workflow_name: &str, step_index: usize, data: JsonValue, ) -> JoinHandle<Result<Event, String>>
Emit WorkflowStep::Completed event
Sourcepub fn step_failed(
&self,
workflow_name: &str,
step_index: usize,
error: &str,
data: JsonValue,
) -> JoinHandle<Result<Event, String>>
pub fn step_failed( &self, workflow_name: &str, step_index: usize, error: &str, data: JsonValue, ) -> JoinHandle<Result<Event, String>>
Emit WorkflowStep::Failed event
Sourcepub fn subscribe(&self) -> Receiver<Event>
pub fn subscribe(&self) -> Receiver<Event>
Subscribe to real-time event stream Returns a receiver that will get all future events
Sourcepub fn from_offset(&self, offset: EventOffset) -> Vec<Event>
pub fn from_offset(&self, offset: EventOffset) -> Vec<Event>
Get events from a specific offset (for replay)
pub fn is_empty(&self) -> bool
Sourcepub fn current_offset(&self) -> EventOffset
pub fn current_offset(&self) -> EventOffset
Get the current offset (next event will have this offset)