Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions crates/openfang-runtime/src/agent_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,18 @@ pub async fn run_agent_loop(
// Add the user message to session history.
// When content blocks are provided (e.g. text + image from a channel),
// use multimodal message format so the LLM receives the image for vision.
if let Some(blocks) = user_content_blocks {
// The text message is prepended to the blocks so the LLM sees both the
// user's question AND any attached images in a single turn.
if let Some(mut blocks) = user_content_blocks {
if !user_message.is_empty() {
blocks.insert(
0,
ContentBlock::Text {
text: user_message.to_string(),
provider_metadata: None,
},
);
}
session.messages.push(Message::user_with_blocks(blocks));
} else {
session.messages.push(Message::user(user_message));
Expand Down Expand Up @@ -1448,7 +1459,18 @@ pub async fn run_agent_loop_streaming(
// Add the user message to session history.
// When content blocks are provided (e.g. text + image from a channel),
// use multimodal message format so the LLM receives the image for vision.
if let Some(blocks) = user_content_blocks {
// The text message is prepended to the blocks so the LLM sees both the
// user's question AND any attached images in a single turn.
if let Some(mut blocks) = user_content_blocks {
if !user_message.is_empty() {
blocks.insert(
0,
ContentBlock::Text {
text: user_message.to_string(),
provider_metadata: None,
},
);
}
session.messages.push(Message::user_with_blocks(blocks));
} else {
session.messages.push(Message::user(user_message));
Expand Down