mirror of
https://github.com/katanemo/plano.git
synced 2026-05-08 07:12:42 +02:00
use standard tracing and logging in brightstaff (#721)
This commit is contained in:
parent
4d9ed74b68
commit
46de89590b
55 changed files with 1494 additions and 2432 deletions
|
|
@ -96,14 +96,14 @@ impl RouterService {
|
|||
.generate_request(messages, &usage_preferences);
|
||||
|
||||
debug!(
|
||||
"sending request to arch-router model: {}, endpoint: {}",
|
||||
self.router_model.get_model_name(),
|
||||
self.router_url
|
||||
model = %self.router_model.get_model_name(),
|
||||
endpoint = %self.router_url,
|
||||
"sending request to arch-router"
|
||||
);
|
||||
|
||||
debug!(
|
||||
"arch request body: {}",
|
||||
&serde_json::to_string(&router_request).unwrap(),
|
||||
body = %serde_json::to_string(&router_request).unwrap(),
|
||||
"arch router request"
|
||||
);
|
||||
|
||||
let mut llm_route_request_headers = header::HeaderMap::new();
|
||||
|
|
@ -148,9 +148,9 @@ impl RouterService {
|
|||
Ok(response) => response,
|
||||
Err(err) => {
|
||||
warn!(
|
||||
"Failed to parse JSON: {}. Body: {}",
|
||||
err,
|
||||
&serde_json::to_string(&body).unwrap()
|
||||
error = %err,
|
||||
body = %serde_json::to_string(&body).unwrap(),
|
||||
"failed to parse json response"
|
||||
);
|
||||
return Err(RoutingError::JsonError(
|
||||
err,
|
||||
|
|
@ -160,7 +160,7 @@ impl RouterService {
|
|||
};
|
||||
|
||||
if chat_completion_response.choices.is_empty() {
|
||||
warn!("No choices in router response: {}", body);
|
||||
warn!(body = %body, "no choices in router response");
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
|
|
@ -169,10 +169,10 @@ impl RouterService {
|
|||
.router_model
|
||||
.parse_response(content, &usage_preferences)?;
|
||||
info!(
|
||||
"arch-router determined route: {}, selected_model: {:?}, response time: {}ms",
|
||||
content.replace("\n", "\\n"),
|
||||
parsed_response,
|
||||
router_response_time.as_millis()
|
||||
content = %content.replace("\n", "\\n"),
|
||||
selected_model = ?parsed_response,
|
||||
response_time_ms = router_response_time.as_millis(),
|
||||
"arch-router determined route"
|
||||
);
|
||||
|
||||
if let Some(ref parsed_response) = parsed_response {
|
||||
|
|
|
|||
|
|
@ -197,12 +197,12 @@ impl OrchestratorModel for OrchestratorModelV1 {
|
|||
token_count += message_token_count;
|
||||
if token_count > self.max_token_length {
|
||||
debug!(
|
||||
"OrchestratorModelV1: token count {} exceeds max token length {}, truncating conversation, selected message count {}, total message count: {}",
|
||||
token_count,
|
||||
self.max_token_length
|
||||
, selected_messsage_count,
|
||||
messages_vec.len()
|
||||
);
|
||||
token_count = token_count,
|
||||
max_tokens = self.max_token_length,
|
||||
selected = selected_messsage_count,
|
||||
total = messages_vec.len(),
|
||||
"token count exceeds max, truncating conversation"
|
||||
);
|
||||
if message.role == Role::User {
|
||||
// If message that exceeds max token length is from user, we need to keep it
|
||||
selected_messages_list_reversed.push(message);
|
||||
|
|
@ -214,9 +214,7 @@ impl OrchestratorModel for OrchestratorModelV1 {
|
|||
}
|
||||
|
||||
if selected_messages_list_reversed.is_empty() {
|
||||
debug!(
|
||||
"OrchestratorModelV1: no messages selected, using the last message in the conversation"
|
||||
);
|
||||
debug!("no messages selected, using last message");
|
||||
if let Some(last_message) = messages_vec.last() {
|
||||
selected_messages_list_reversed.push(last_message);
|
||||
}
|
||||
|
|
@ -228,12 +226,12 @@ impl OrchestratorModel for OrchestratorModelV1 {
|
|||
// - last() is the first message in the original conversation
|
||||
if let Some(first_message) = selected_messages_list_reversed.first() {
|
||||
if first_message.role != Role::User {
|
||||
warn!("OrchestratorModelV1: last message in the conversation is not from user, this may lead to incorrect orchestration");
|
||||
warn!("last message is not from user, may lead to incorrect orchestration");
|
||||
}
|
||||
}
|
||||
if let Some(last_message) = selected_messages_list_reversed.last() {
|
||||
if last_message.role != Role::User {
|
||||
warn!("OrchestratorModelV1: first message in the selected conversation is not from user, this may lead to incorrect orchestration");
|
||||
warn!("first message is not from user, may lead to incorrect orchestration");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -323,8 +321,9 @@ impl OrchestratorModel for OrchestratorModelV1 {
|
|||
result.push((selected_route, model_name));
|
||||
} else {
|
||||
warn!(
|
||||
"No matching model found for route: {}, usage preferences: {:?}",
|
||||
selected_route, usage_preferences
|
||||
route = %selected_route,
|
||||
preferences = ?usage_preferences,
|
||||
"no matching model found for route"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
@ -339,8 +338,9 @@ impl OrchestratorModel for OrchestratorModelV1 {
|
|||
result.push((selected_route, model));
|
||||
} else {
|
||||
warn!(
|
||||
"No model found for route: {}, orchestrator model preferences: {:?}",
|
||||
selected_route, self.agent_orchestration_to_model_map
|
||||
route = %selected_route,
|
||||
preferences = ?self.agent_orchestration_to_model_map,
|
||||
"no model found for route"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,13 +2,12 @@ use std::{collections::HashMap, sync::Arc};
|
|||
|
||||
use common::{
|
||||
configuration::{AgentUsagePreference, OrchestrationPreference},
|
||||
consts::{
|
||||
ARCH_PROVIDER_HINT_HEADER, PLANO_ORCHESTRATOR_MODEL_NAME, REQUEST_ID_HEADER,
|
||||
TRACE_PARENT_HEADER,
|
||||
},
|
||||
consts::{ARCH_PROVIDER_HINT_HEADER, PLANO_ORCHESTRATOR_MODEL_NAME, REQUEST_ID_HEADER},
|
||||
};
|
||||
use hermesllm::apis::openai::{ChatCompletionsResponse, Message};
|
||||
use hyper::header;
|
||||
use opentelemetry::global;
|
||||
use opentelemetry_http::HeaderInjector;
|
||||
use thiserror::Error;
|
||||
use tracing::{debug, info, warn};
|
||||
|
||||
|
|
@ -57,7 +56,6 @@ impl OrchestratorService {
|
|||
pub async fn determine_orchestration(
|
||||
&self,
|
||||
messages: &[Message],
|
||||
trace_parent: Option<String>,
|
||||
usage_preferences: Option<Vec<AgentUsagePreference>>,
|
||||
request_id: Option<String>,
|
||||
) -> Result<Option<Vec<(String, String)>>> {
|
||||
|
|
@ -75,14 +73,14 @@ impl OrchestratorService {
|
|||
.generate_request(messages, &usage_preferences);
|
||||
|
||||
debug!(
|
||||
"sending request to arch-orchestrator model: {}, endpoint: {}",
|
||||
self.orchestrator_model.get_model_name(),
|
||||
self.orchestrator_url
|
||||
model = %self.orchestrator_model.get_model_name(),
|
||||
endpoint = %self.orchestrator_url,
|
||||
"sending request to arch-orchestrator"
|
||||
);
|
||||
|
||||
debug!(
|
||||
"arch orchestrator request body: {}",
|
||||
&serde_json::to_string(&orchestrator_request).unwrap(),
|
||||
body = %serde_json::to_string(&orchestrator_request).unwrap(),
|
||||
"arch orchestrator request"
|
||||
);
|
||||
|
||||
let mut orchestration_request_headers = header::HeaderMap::new();
|
||||
|
|
@ -96,12 +94,12 @@ impl OrchestratorService {
|
|||
header::HeaderValue::from_str(PLANO_ORCHESTRATOR_MODEL_NAME).unwrap(),
|
||||
);
|
||||
|
||||
if let Some(trace_parent) = trace_parent {
|
||||
orchestration_request_headers.insert(
|
||||
header::HeaderName::from_static(TRACE_PARENT_HEADER),
|
||||
header::HeaderValue::from_str(&trace_parent).unwrap(),
|
||||
);
|
||||
}
|
||||
// Inject OpenTelemetry trace context from current span
|
||||
global::get_text_map_propagator(|propagator| {
|
||||
let cx =
|
||||
tracing_opentelemetry::OpenTelemetrySpanExt::context(&tracing::Span::current());
|
||||
propagator.inject_context(&cx, &mut HeaderInjector(&mut orchestration_request_headers));
|
||||
});
|
||||
|
||||
if let Some(request_id) = request_id {
|
||||
orchestration_request_headers.insert(
|
||||
|
|
@ -131,9 +129,9 @@ impl OrchestratorService {
|
|||
Ok(response) => response,
|
||||
Err(err) => {
|
||||
warn!(
|
||||
"Failed to parse JSON: {}. Body: {}",
|
||||
err,
|
||||
&serde_json::to_string(&body).unwrap()
|
||||
error = %err,
|
||||
body = %serde_json::to_string(&body).unwrap(),
|
||||
"failed to parse json response"
|
||||
);
|
||||
return Err(OrchestrationError::JsonError(
|
||||
err,
|
||||
|
|
@ -143,7 +141,7 @@ impl OrchestratorService {
|
|||
};
|
||||
|
||||
if chat_completion_response.choices.is_empty() {
|
||||
warn!("No choices in orchestrator response: {}", body);
|
||||
warn!(body = %body, "no choices in orchestrator response");
|
||||
return Ok(None);
|
||||
}
|
||||
|
||||
|
|
@ -152,10 +150,10 @@ impl OrchestratorService {
|
|||
.orchestrator_model
|
||||
.parse_response(content, &usage_preferences)?;
|
||||
info!(
|
||||
"arch-orchestrator determined routes: {}, selected_routes: {:?}, response time: {}ms",
|
||||
content.replace("\n", "\\n"),
|
||||
parsed_response,
|
||||
orchestrator_response_time.as_millis()
|
||||
content = %content.replace("\n", "\\n"),
|
||||
selected_routes = ?parsed_response,
|
||||
response_time_ms = orchestrator_response_time.as_millis(),
|
||||
"arch-orchestrator determined routes"
|
||||
);
|
||||
|
||||
if let Some(ref parsed_response) = parsed_response {
|
||||
|
|
|
|||
|
|
@ -94,12 +94,12 @@ impl RouterModel for RouterModelV1 {
|
|||
token_count += message_token_count;
|
||||
if token_count > self.max_token_length {
|
||||
debug!(
|
||||
"RouterModelV1: token count {} exceeds max token length {}, truncating conversation, selected message count {}, total message count: {}",
|
||||
token_count,
|
||||
self.max_token_length
|
||||
, selected_messsage_count,
|
||||
messages_vec.len()
|
||||
);
|
||||
token_count = token_count,
|
||||
max_tokens = self.max_token_length,
|
||||
selected = selected_messsage_count,
|
||||
total = messages_vec.len(),
|
||||
"token count exceeds max, truncating conversation"
|
||||
);
|
||||
if message.role == Role::User {
|
||||
// If message that exceeds max token length is from user, we need to keep it
|
||||
selected_messages_list_reversed.push(message);
|
||||
|
|
@ -111,9 +111,7 @@ impl RouterModel for RouterModelV1 {
|
|||
}
|
||||
|
||||
if selected_messages_list_reversed.is_empty() {
|
||||
debug!(
|
||||
"RouterModelV1: no messages selected, using the last message in the conversation"
|
||||
);
|
||||
debug!("no messages selected, using last message");
|
||||
if let Some(last_message) = messages_vec.last() {
|
||||
selected_messages_list_reversed.push(last_message);
|
||||
}
|
||||
|
|
@ -122,12 +120,12 @@ impl RouterModel for RouterModelV1 {
|
|||
// ensure that first and last selected message is from user
|
||||
if let Some(first_message) = selected_messages_list_reversed.first() {
|
||||
if first_message.role != Role::User {
|
||||
warn!("RouterModelV1: last message in the conversation is not from user, this may lead to incorrect routing");
|
||||
warn!("last message is not from user, may lead to incorrect routing");
|
||||
}
|
||||
}
|
||||
if let Some(last_message) = selected_messages_list_reversed.last() {
|
||||
if last_message.role != Role::User {
|
||||
warn!("RouterModelV1: first message in the conversation is not from user, this may lead to incorrect routing");
|
||||
warn!("first message is not from user, may lead to incorrect routing");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -206,8 +204,9 @@ impl RouterModel for RouterModelV1 {
|
|||
return Ok(Some((selected_route, model_name)));
|
||||
} else {
|
||||
warn!(
|
||||
"No matching model found for route: {}, usage preferences: {:?}",
|
||||
selected_route, usage_preferences
|
||||
route = %selected_route,
|
||||
preferences = ?usage_preferences,
|
||||
"no matching model found for route"
|
||||
);
|
||||
return Ok(None);
|
||||
}
|
||||
|
|
@ -219,8 +218,9 @@ impl RouterModel for RouterModelV1 {
|
|||
}
|
||||
|
||||
warn!(
|
||||
"No model found for route: {}, router model preferences: {:?}",
|
||||
selected_route, self.llm_route_to_model_map
|
||||
route = %selected_route,
|
||||
preferences = ?self.llm_route_to_model_map,
|
||||
"no model found for route"
|
||||
);
|
||||
|
||||
Ok(None)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue