pub struct EventBus { /* private fields */ }Expand description
A cloneable broadcast bus for agent events.
All components publish to the same bus; external observers subscribe independently. Cloning is cheap — all clones share the same underlying channel.
§Example
use agentix::EventBus;
let bus = EventBus::new(512);
// Attach a custom observer
bus.tap(|msg| async move {
println!("{msg:?}");
});
// Raw subscriber (e.g. for a WebSocket handler)
let mut rx = bus.subscribe();Implementations§
Source§impl EventBus
impl EventBus
pub fn new(capacity: usize) -> Self
Sourcepub fn send(&self, msg: Msg)
pub fn send(&self, msg: Msg)
Broadcast a message to all current subscribers. Silently drops the message if there are no subscribers.
Sourcepub fn subscribe_assembled(&self) -> impl Stream<Item = Msg> + 'static
pub fn subscribe_assembled(&self) -> impl Stream<Item = Msg> + 'static
Subscribe to future messages, folding streaming fragments into complete events.
Concretely:
- Multiple
Msg::Tokenchunks are buffered and emitted as a singleToken(full_text)just before theMsg::Donethat ends the turn. - Multiple
Msg::Reasoningchunks are folded the same way. - All other variants (
ToolCall,ToolResult,Done,User, …) pass through unchanged.
This gives downstream nodes the same view a non-streaming provider would produce — same variant names, just assembled content.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for EventBus
impl !RefUnwindSafe for EventBus
impl Send for EventBus
impl Sync for EventBus
impl Unpin for EventBus
impl UnsafeUnpin for EventBus
impl !UnwindSafe for EventBus
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