returning appropriately

This commit is contained in:
dal 2025-02-24 08:07:42 -07:00
parent c9099d92f7
commit 5c3f3acd6a
No known key found for this signature in database
GPG Key ID: 16F4B0E1E9F61122
1 changed files with 6 additions and 7 deletions

View File

@ -102,20 +102,19 @@ async fn process_chat(request: ChatCreateNewChat, user: User) -> Result<ThreadWi
let mut final_message = None;
// Process messages from the agent
loop {
match rx.recv().await {
Ok(Ok(msg)) => {
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()),
}
}