diff --git a/api/src/routes/rest/routes/chats/post_chat.rs b/api/src/routes/rest/routes/chats/post_chat.rs index 07bbbb7f9..206bd1d93 100644 --- a/api/src/routes/rest/routes/chats/post_chat.rs +++ b/api/src/routes/rest/routes/chats/post_chat.rs @@ -102,20 +102,19 @@ async fn process_chat(request: ChatCreateNewChat, user: User) -> Result { + while let Ok(message) = rx.recv().await { + match message { + Ok(msg) => { match msg { AgentMessage::Assistant { content: Some(content), tool_calls: None, .. } => { - // Store the final message content + // Store the final message and break immediately final_message = Some(content); + break; } _ => messages.push(msg), } } - Ok(Err(e)) => return Err(e.into()), - Err(broadcast::error::RecvError::Closed) => break, - Err(e) => return Err(anyhow!(e)), + Err(e) => return Err(e.into()), } }