pub struct A2ARouter { /* private fields */ }Expand description
Agent-to-agent message router.
Manages per-agent inboxes (bounded mpsc channels), validates
IPC scope through the capability checker, and routes messages
to their targets (direct PID, topic, broadcast, service).
Implementations§
Source§impl A2ARouter
impl A2ARouter
Sourcepub fn new(
process_table: Arc<ProcessTable>,
capability_checker: Arc<CapabilityChecker>,
topic_router: Arc<TopicRouter>,
) -> Self
pub fn new( process_table: Arc<ProcessTable>, capability_checker: Arc<CapabilityChecker>, topic_router: Arc<TopicRouter>, ) -> Self
Create a new A2A router.
Sourcepub fn with_service_registry(self, registry: Arc<ServiceRegistry>) -> Self
pub fn with_service_registry(self, registry: Arc<ServiceRegistry>) -> Self
Attach a service registry for service-based routing (D1, D19).
Sourcepub fn with_gate(self, gate: Arc<dyn GateBackend>) -> Self
pub fn with_gate(self, gate: Arc<dyn GateBackend>) -> Self
Attach a routing-time gate for dual-layer governance (C4).
When set, every message routed through send() is checked against
the gate before inbox delivery. A Deny decision blocks the
message; Defer still delivers (the handler-time gate decides).
Sourcepub fn set_gate(&self, gate: Arc<dyn GateBackend>)
pub fn set_gate(&self, gate: Arc<dyn GateBackend>)
Set the routing-time gate after construction (for boot wiring).
This allows the governance gate to be attached after the router
is already wrapped in an Arc, since the OnceLock provides
interior mutability for the first (and only) write.
Sourcepub fn service_registry(&self) -> Option<&Arc<ServiceRegistry>>
pub fn service_registry(&self) -> Option<&Arc<ServiceRegistry>>
Get the service registry (if configured).
Sourcepub fn create_inbox(&self, pid: Pid) -> Receiver<KernelMessage>
pub fn create_inbox(&self, pid: Pid) -> Receiver<KernelMessage>
Create an inbox for a process.
Returns the receiver half that the agent should poll for incoming messages. The sender half is stored internally for routing.
If an inbox already exists for this PID, the old one is replaced (existing messages are lost).
Sourcepub fn remove_inbox(&self, pid: Pid)
pub fn remove_inbox(&self, pid: Pid)
Remove an inbox (used during process cleanup).
Sourcepub async fn send(&self, msg: KernelMessage) -> KernelResult<()>
pub async fn send(&self, msg: KernelMessage) -> KernelResult<()>
Send a message, routing it to the appropriate target.
Validates that the sender exists and is running, checks IPC scope via the capability checker, then delivers the message to the target.
§Routing
Process(pid): delivers directly to the target’s inboxTopic(name): publishes to all topic subscribersBroadcast: delivers to all inboxes except the senderService(name): logs a warning (service routing is a future extension)Kernel: logs a warning (kernel messages are internal)
§Errors
Returns KernelError::ProcessNotFound if the sender PID
is not in the process table, or KernelError::CapabilityDenied
if the sender’s IPC scope does not permit the target.
Sourcepub async fn send_checked(
&self,
msg: KernelMessage,
chain: Option<&ChainManager>,
) -> KernelResult<()>
pub async fn send_checked( &self, msg: KernelMessage, chain: Option<&ChainManager>, ) -> KernelResult<()>
Send a message with chain-event logging.
This mirrors KernelIpc::send_checked but for the A2ARouter:
every routed message is logged as an ipc.send chain event with
sender, target, payload type, and message ID — forming a
tamper-evident IPC audit trail in the exochain.
When the exochain feature is disabled this is equivalent to
a plain send().
Sourcepub fn topic_router(&self) -> &Arc<TopicRouter>
pub fn topic_router(&self) -> &Arc<TopicRouter>
Get the topic router.
Sourcepub fn inbox_count(&self) -> usize
pub fn inbox_count(&self) -> usize
Get the number of active inboxes.
Sourcepub async fn request(
&self,
msg: KernelMessage,
timeout: Duration,
) -> KernelResult<KernelMessage>
pub async fn request( &self, msg: KernelMessage, timeout: Duration, ) -> KernelResult<KernelMessage>
Send a request and wait for a correlated response with timeout.
The request message is sent normally, but its id is registered
as a pending request. When a response arrives with a matching
correlation_id, it is delivered to the returned future instead
of the sender’s inbox.
§Errors
Returns KernelError::Timeout if no response arrives within the
specified duration, or KernelError::Ipc if the response channel
is closed before a response arrives.
Sourcepub fn try_complete_request(&self, msg: KernelMessage) -> bool
pub fn try_complete_request(&self, msg: KernelMessage) -> bool
Try to complete a pending request with a correlated response.
If the message has a correlation_id that matches a pending
request, the response is delivered to the waiting future and
true is returned. Otherwise returns false.
Sourcepub fn pending_request_count(&self) -> usize
pub fn pending_request_count(&self) -> usize
Get the number of pending requests.
Auto Trait Implementations§
impl !Freeze for A2ARouter
impl !RefUnwindSafe for A2ARouter
impl Send for A2ARouter
impl Sync for A2ARouter
impl Unpin for A2ARouter
impl UnsafeUnpin for A2ARouter
impl !UnwindSafe for A2ARouter
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
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more