Skip to content

Content

Content represents the payload of a single message in a conversation. It’s a powerful primitive that supports multi-modal messages, including text, images, documents, tool calls, and tool responses.

The most common type of content is simple text.

use radkit::models::Content;
// Create from a string slice
let content = Content::from_text("Hello!");
// Or from a String
let content = Content::from_text(String::from("Hello, world!"));

For more complex messages, you can combine different types of ContentPart. This is how you would send an image to a vision-capable model.

use radkit::models::{Content, ContentPart};
let content = Content::from_parts(vec![
ContentPart::Text("Check out this image:".to_string()),
ContentPart::from_data(
"image/png",
"base64_encoded_image_data_here",
Some("photo.png".to_string())
).unwrap(),
]);

Once you have a Content object, you can easily inspect and extract information from it.

You can get the first text part, all text parts, or a single joined string.

use radkit::models::Content;
let content = Content::from_text("First part. Second part.");
// Get the first text part
if content.has_text() {
println!("First text: {}", content.first_text().unwrap());
}
// Iterate over all text parts
for text in content.texts() {
println!("Part: {}", text);
}
// Get a single string with all text parts joined together
if let Some(combined) = content.joined_texts() {
println!("Combined: {}", combined);
}

You can also check for the presence of other content types, like tool calls or images.

use radkit::models::Content;
let content = Content::from_text("Example"); // Assume this might have other parts
if content.has_tool_calls() {
println!("Content has {} tool calls", content.tool_calls().len());
}
if content.has_images() {
println!("Content has images");
}

The Content API provides a safe and convenient way to handle the potentially complex, multi-modal data that flows through an agent system.