pub struct Message {
pub id: MessageId,
pub role: MessageRole,
pub parts: Vec<Part>,
pub task_id: Option<TaskId>,
pub context_id: Option<ContextId>,
pub reference_task_ids: Option<Vec<TaskId>>,
pub extensions: Option<Vec<String>>,
pub metadata: Option<Value>,
}Expand description
A message exchanged between a client and an agent.
Fields§
§id: MessageIdUnique message identifier.
role: MessageRoleRole of the message originator.
parts: Vec<Part>Message content parts.
Spec requirement: Must contain at least one element. The A2A protocol does not define behavior for empty parts lists.
Parsing treats absence as empty (ProtoJSON printers omit empty
repeated fields; the gRPC binding already decodes it that way) — the
server rejects empty parts with a structured invalid-params error
instead of a JSON type error, uniformly across bindings.
task_id: Option<TaskId>Task this message belongs to, if any.
context_id: Option<ContextId>Conversation context this message belongs to, if any.
reference_task_ids: Option<Vec<TaskId>>IDs of tasks referenced by this message.
extensions: Option<Vec<String>>URIs of extensions used in this message.
metadata: Option<Value>Arbitrary metadata.
Implementations§
Source§impl Message
impl Message
Sourcepub fn text(&self) -> Option<&str>
pub fn text(&self) -> Option<&str>
Returns the text of the first text Part, or None if this message
carries no text part.
Reading the caller’s text is the most common operation in agent code.
This is the one-liner form of the parts.iter().find_map(..) match over
PartContent::Text:
use a2a_protocol_types::message::{Message, MessageId, MessageRole, Part};
let msg = Message {
id: MessageId::new("m1"),
role: MessageRole::User,
parts: vec![Part::url("https://example.com/f.pdf"), Part::text("hello")],
task_id: None,
context_id: None,
reference_task_ids: None,
extensions: None,
metadata: None,
};
assert_eq!(msg.text(), Some("hello"));Non-text parts are skipped rather than ending the search, so a message that leads with a file attachment still yields its text.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Message
impl<'de> Deserialize<'de> for Message
Source§fn deserialize<__D>(
__deserializer: __D,
) -> Result<Message, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<Message, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
impl Eq for Message
Source§impl Serialize for Message
impl Serialize for Message
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
impl StructuralPartialEq for Message
Auto Trait Implementations§
impl Freeze for Message
impl RefUnwindSafe for Message
impl Send for Message
impl Sync for Message
impl Unpin for Message
impl UnsafeUnpin for Message
impl UnwindSafe for Message
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,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.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> 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 moreSource§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>
T in a tonic::Request