fix response collector and update system prompts for travel booking agents

This commit is contained in:
Adil Hafeez 2025-12-22 14:26:07 -08:00
parent 39db3006f2
commit fc3045cb03
No known key found for this signature in database
GPG key ID: 9B18EF7691369645
7 changed files with 262 additions and 94 deletions

View file

@ -343,21 +343,22 @@ async fn handle_agent_chat(
debug!("Collecting response from intermediate agent: {}", agent_name);
let response_text = response_handler.collect_full_response(llm_response).await?;
// Create a new message with the agent's response as assistant message
// and add it to the conversation history
current_messages.push(OpenAIMessage {
role: hermesllm::apis::openai::Role::Assistant,
content: hermesllm::apis::openai::MessageContent::Text(response_text.clone()),
name: Some(agent_name.clone()),
tool_calls: None,
tool_call_id: None,
});
info!(
"Agent {} completed, passing {} character response to next agent",
agent_name,
response_text.len()
);
// Create a new message with the agent's response as assistant message
// and add it to the conversation history
current_messages.push(OpenAIMessage {
role: hermesllm::apis::openai::Role::Assistant,
content: hermesllm::apis::openai::MessageContent::Text(response_text),
name: Some(agent_name.clone()),
tool_calls: None,
tool_call_id: None,
});
}
// This should never be reached since we return in the last agent iteration

View file

@ -1,4 +1,7 @@
use bytes::Bytes;
use hermesllm::SseEvent;
use hermesllm::apis::OpenAIApi;
use hermesllm::clients::{SupportedAPIsFromClient, SupportedUpstreamAPIs};
use http_body_util::combinators::BoxBody;
use http_body_util::{BodyExt, Full, StreamBody};
use hyper::body::Frame;
@ -6,7 +9,7 @@ use hyper::{Response, StatusCode};
use tokio::sync::mpsc;
use tokio_stream::wrappers::ReceiverStream;
use tokio_stream::StreamExt;
use tracing::warn;
use tracing::{info, warn};
/// Errors that can occur during response handling
#[derive(Debug, thiserror::Error)]
@ -132,6 +135,11 @@ impl ResponseHandler {
.await
.map_err(|e| ResponseError::StreamError(format!("Failed to read response: {}", e)))?;
let client_api =
SupportedAPIsFromClient::OpenAIChatCompletions(OpenAIApi::ChatCompletions);
let upstream_api = SupportedUpstreamAPIs::OpenAIChatCompletions(OpenAIApi::ChatCompletions);
// Try to parse as SSE streaming response
if let Ok(sse_iter) = SseStreamIter::try_from(response_bytes.as_ref()) {
let mut accumulated_text = String::new();
@ -142,10 +150,19 @@ impl ResponseHandler {
continue;
}
let transformed_event = SseEvent::try_from((sse_event, &client_api, &upstream_api)).unwrap();
// Try to get provider response and extract content delta
if let Ok(provider_response) = sse_event.provider_response() {
if let Some(content) = provider_response.content_delta() {
accumulated_text.push_str(&content);
match transformed_event.provider_response() {
Ok(provider_response) => {
if let Some(content) = provider_response.content_delta() {
accumulated_text.push_str(&content);
} else {
info!("No content delta in provider response");
}
}
Err(e) => {
warn!("Failed to parse provider response: {:?}", e);
}
}
}