pub struct MailboxHub { /* private fields */ }Expand description
Central hub for inter-agent message passing.
Manages per-agent mailboxes and a global sequence number. The sequence
number increments every time a result is posted, allowing wait_for_result
to efficiently block until new data arrives.
All methods use internal Mutex — the hub is designed to be shared
via Arc<MailboxHub>.
Implementations§
Source§impl MailboxHub
impl MailboxHub
Sourcepub fn register(&self, agent_path: &AgentPath) -> Option<ChildMailbox>
pub fn register(&self, agent_path: &AgentPath) -> Option<ChildMailbox>
Register a new agent mailbox.
Returns the child-side handle to be given to the spawned agent task.
Returns None if the agent_path is already registered.
Sourcepub fn unregister(&self, agent_path: &AgentPath) -> bool
pub fn unregister(&self, agent_path: &AgentPath) -> bool
Unregister an agent mailbox.
Posts a Closed result first (to wake any waiters), then removes the entry.
Returns true if the agent was registered.
Sourcepub fn send_message(&self, agent_path: &AgentPath, message: String) -> bool
pub fn send_message(&self, agent_path: &AgentPath, message: String) -> bool
Send a message to a sub-agent (no execution trigger).
The message is appended to the agent’s pending message buffer.
Returns true if the message was queued, false if the agent is not registered.
Sourcepub fn send_task(
&self,
agent_path: &AgentPath,
task: String,
interrupt: bool,
) -> bool
pub fn send_task( &self, agent_path: &AgentPath, task: String, interrupt: bool, ) -> bool
Send a task to a sub-agent (triggers execution).
Drains pending messages and packages them with the task.
Returns true if the task was sent, false if the agent is not registered
or the channel is full.
Sourcepub fn has_pending(&self, agent_path: &AgentPath) -> bool
pub fn has_pending(&self, agent_path: &AgentPath) -> bool
Check if an agent has pending (unread) messages.
Sourcepub fn post_result(&self, result: MailboxResult)
pub fn post_result(&self, result: MailboxResult)
Post a result from a child agent.
Increments the global sequence number, waking all wait_for_result callers.
Sourcepub fn subscribe_seq(&self) -> Receiver<u64>
pub fn subscribe_seq(&self) -> Receiver<u64>
Get a clone of the global sequence number receiver.
Used by wait_agent to watch for changes before polling.
Sourcepub fn try_recv_result(&self, agent_path: &AgentPath) -> Option<MailboxResult>
pub fn try_recv_result(&self, agent_path: &AgentPath) -> Option<MailboxResult>
Try to receive a result for a specific agent (non-blocking).
Returns the oldest unread result for the agent, or None.
Sourcepub fn try_recv_any(&self) -> Option<MailboxResult>
pub fn try_recv_any(&self) -> Option<MailboxResult>
Try to receive any result (non-blocking).
Returns the first available result from any agent mailbox.
Sourcepub fn has_results(&self, agent_path: &AgentPath) -> bool
pub fn has_results(&self, agent_path: &AgentPath) -> bool
Check if an agent has unread results.
Sourcepub fn total_pending_results(&self) -> usize
pub fn total_pending_results(&self) -> usize
Return the total number of unread results across all agents.
Sourcepub fn agent_paths(&self) -> Vec<AgentPath>
pub fn agent_paths(&self) -> Vec<AgentPath>
Return all registered agent paths.