pub struct KernelMessage {
pub id: String,
pub from: Pid,
pub target: MessageTarget,
pub payload: MessagePayload,
pub timestamp: DateTime<Utc>,
pub correlation_id: Option<String>,
pub trace_id: Option<String>,
}Expand description
A typed message envelope for kernel IPC.
Fields§
§id: StringUnique message identifier.
from: PidSender PID (0 = kernel).
target: MessageTargetTarget for delivery.
payload: MessagePayloadMessage payload.
timestamp: DateTime<Utc>Creation timestamp.
correlation_id: Option<String>Optional correlation ID for request-response patterns.
When set, this links a response message back to the original request that triggered it. Used by the A2A protocol’s request-response tracking.
trace_id: Option<String>Distributed trace ID for end-to-end request tracing (K2-G4).
External messages entering the kernel receive a new UUID v4 trace_id. Internal messages inherit the parent’s trace_id via correlation linkage.
Implementations§
Source§impl KernelMessage
impl KernelMessage
Sourcepub fn new(from: Pid, target: MessageTarget, payload: MessagePayload) -> Self
pub fn new(from: Pid, target: MessageTarget, payload: MessagePayload) -> Self
Create a new kernel message.
Uses an atomic counter for the message ID instead of UUID v4, eliminating crypto-random generation overhead in hot IPC paths.
Sourcepub fn with_correlation(
from: Pid,
target: MessageTarget,
payload: MessagePayload,
correlation_id: String,
) -> Self
pub fn with_correlation( from: Pid, target: MessageTarget, payload: MessagePayload, correlation_id: String, ) -> Self
Create a new kernel message with a correlation ID.
Sourcepub fn with_trace(
from: Pid,
target: MessageTarget,
payload: MessagePayload,
trace_id: String,
) -> Self
pub fn with_trace( from: Pid, target: MessageTarget, payload: MessagePayload, trace_id: String, ) -> Self
Create a new kernel message with a trace ID (for external entry points).
Sourcepub fn set_trace_id(self, trace_id: impl Into<String>) -> Self
pub fn set_trace_id(self, trace_id: impl Into<String>) -> Self
Set the trace ID on this message (builder pattern).
Sourcepub fn ensure_trace_id(self) -> Self
pub fn ensure_trace_id(self) -> Self
Ensure this message has a trace ID, generating one if missing.
Sourcepub fn text(from: Pid, target: MessageTarget, text: impl Into<String>) -> Self
pub fn text(from: Pid, target: MessageTarget, text: impl Into<String>) -> Self
Create a text message.
Sourcepub fn signal(from: Pid, target: MessageTarget, signal: KernelSignal) -> Self
pub fn signal(from: Pid, target: MessageTarget, signal: KernelSignal) -> Self
Create a signal message.
Sourcepub fn tool_call(
from: Pid,
target: MessageTarget,
name: impl Into<String>,
args: Value,
) -> Self
pub fn tool_call( from: Pid, target: MessageTarget, name: impl Into<String>, args: Value, ) -> Self
Create a tool call message.
Sourcepub fn tool_result(
from: Pid,
target: MessageTarget,
call_id: impl Into<String>,
result: Value,
) -> Self
pub fn tool_result( from: Pid, target: MessageTarget, call_id: impl Into<String>, result: Value, ) -> Self
Create a tool result message (response to a tool call).
Trait Implementations§
Source§impl Clone for KernelMessage
impl Clone for KernelMessage
Source§fn clone(&self) -> KernelMessage
fn clone(&self) -> KernelMessage
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for KernelMessage
impl Debug for KernelMessage
Source§impl<'de> Deserialize<'de> for KernelMessage
impl<'de> Deserialize<'de> for KernelMessage
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for KernelMessage
impl RefUnwindSafe for KernelMessage
impl Send for KernelMessage
impl Sync for KernelMessage
impl Unpin for KernelMessage
impl UnsafeUnpin for KernelMessage
impl UnwindSafe for KernelMessage
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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