pub struct HumanMessage { /* private fields */ }Expand description
A human message in the conversation.
Human messages support both simple text content and multimodal content
with images. Use HumanMessage::new for simple text messages and
HumanMessage::with_content for multimodal messages.
This corresponds to HumanMessage in LangChain Python.
Implementations§
Source§impl HumanMessage
impl HumanMessage
Sourcepub fn new(content: impl Into<String>) -> Self
pub fn new(content: impl Into<String>) -> Self
Create a new human message with simple text content.
Sourcepub fn with_id(id: impl Into<String>, content: impl Into<String>) -> Self
pub fn with_id(id: impl Into<String>, content: impl Into<String>) -> Self
Create a new human message with simple text content and an explicit ID.
Use this when deserializing or reconstructing messages where the ID must be preserved.
Sourcepub fn with_content(parts: Vec<ContentPart>) -> Self
pub fn with_content(parts: Vec<ContentPart>) -> Self
Create a new human message with multipart content.
§Example
use agent_chain_core::messages::{HumanMessage, ContentPart, ImageSource};
let msg = HumanMessage::with_content(vec![
ContentPart::Text { text: "What's in this image?".into() },
ContentPart::Image {
source: ImageSource::Url {
url: "https://example.com/image.jpg".into(),
},
detail: None,
},
]);Sourcepub fn with_id_and_content(
id: impl Into<String>,
parts: Vec<ContentPart>,
) -> Self
pub fn with_id_and_content( id: impl Into<String>, parts: Vec<ContentPart>, ) -> Self
Create a new human message with multipart content and an explicit ID.
Use this when deserializing or reconstructing messages where the ID must be preserved.
Sourcepub fn with_image_url(text: impl Into<String>, url: impl Into<String>) -> Self
pub fn with_image_url(text: impl Into<String>, url: impl Into<String>) -> Self
Create a human message with text and a single image from a URL.
Sourcepub fn with_image_base64(
text: impl Into<String>,
media_type: impl Into<String>,
data: impl Into<String>,
) -> Self
pub fn with_image_base64( text: impl Into<String>, media_type: impl Into<String>, data: impl Into<String>, ) -> Self
Create a human message with text and a single base64-encoded image.
Sourcepub fn content(&self) -> &str
pub fn content(&self) -> &str
Get the message content as text.
For multipart messages, this returns an empty string.
Use message_content() to access the full content.
Sourcepub fn message_content(&self) -> &MessageContent
pub fn message_content(&self) -> &MessageContent
Get the full message content (text or multipart).
Sourcepub fn has_images(&self) -> bool
pub fn has_images(&self) -> bool
Check if this message contains images.
Sourcepub fn additional_kwargs(&self) -> &HashMap<String, Value>
pub fn additional_kwargs(&self) -> &HashMap<String, Value>
Get additional kwargs.
Trait Implementations§
Source§impl Clone for HumanMessage
impl Clone for HumanMessage
Source§fn clone(&self) -> HumanMessage
fn clone(&self) -> HumanMessage
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more