pub struct AgentMessageBus { /* private fields */ }Expand description
A shared message bus for inter-agent communication within a swarm.
The message bus is shared across all workers in a swarm via Arc<RwLock<>>.
Workers can send messages to specific roles or broadcast to all.
Messages are retained for the lifetime of the swarm and can be queried.
Implementations§
Source§impl AgentMessageBus
impl AgentMessageBus
Sourcepub fn send(
&mut self,
sender: &str,
recipient: &str,
msg_type: MessageType,
content: &str,
metadata: HashMap<String, String>,
) -> String
pub fn send( &mut self, sender: &str, recipient: &str, msg_type: MessageType, content: &str, metadata: HashMap<String, String>, ) -> String
Send a message to a specific recipient (or “*” for broadcast).
Sourcepub fn messages_for(&self, role: &str) -> Vec<&AgentMessage>
pub fn messages_for(&self, role: &str) -> Vec<&AgentMessage>
Get all messages addressed to a specific role (or “*” for broadcast).
Sourcepub fn messages_from(&self, sender: &str) -> Vec<&AgentMessage>
pub fn messages_from(&self, sender: &str) -> Vec<&AgentMessage>
Get all messages from a specific sender.
Sourcepub fn messages_of_type(&self, msg_type: &MessageType) -> Vec<&AgentMessage>
pub fn messages_of_type(&self, msg_type: &MessageType) -> Vec<&AgentMessage>
Get all messages of a specific type.
Sourcepub fn all_messages(&self) -> &[AgentMessage]
pub fn all_messages(&self) -> &[AgentMessage]
Get all messages in the bus.
Sourcepub fn format_for_prompt(&self, role: &str, max_messages: usize) -> String
pub fn format_for_prompt(&self, role: &str, max_messages: usize) -> String
Format recent messages for inclusion in an LLM prompt.
Returns a string with the last N messages formatted for the agent’s context.
Trait Implementations§
Source§impl Clone for AgentMessageBus
impl Clone for AgentMessageBus
Source§fn clone(&self) -> AgentMessageBus
fn clone(&self) -> AgentMessageBus
Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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 AgentMessageBus
impl RefUnwindSafe for AgentMessageBus
impl Send for AgentMessageBus
impl Sync for AgentMessageBus
impl Unpin for AgentMessageBus
impl UnsafeUnpin for AgentMessageBus
impl UnwindSafe for AgentMessageBus
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
Wrap the input message
T in a tonic::Request