From 07208f95ab70dcc06563905cf65fa6087c68423d Mon Sep 17 00:00:00 2001 From: Adil Hafeez Date: Tue, 16 Dec 2025 09:48:14 -0800 Subject: [PATCH] fix agent description and pre-commit --- arch/supervisord.conf | 2 +- .../src/handlers/agent_chat_completions.rs | 1 - .../src/handlers/agent_selector.rs | 38 ++----------------- .../src/handlers/pipeline_processor.rs | 18 ++++----- demos/use_cases/rag_agent/README.md | 4 +- 5 files changed, 15 insertions(+), 48 deletions(-) diff --git a/arch/supervisord.conf b/arch/supervisord.conf index a02092f8..2b715a1e 100644 --- a/arch/supervisord.conf +++ b/arch/supervisord.conf @@ -2,7 +2,7 @@ nodaemon=true [program:brightstaff] -command=sh -c "RUST_LOG=debug /app/brightstaff 2>&1 | tee /var/log/brightstaff.log | while IFS= read -r line; do echo '[brightstaff]' \"$line\"; done" +command=sh -c "RUST_LOG=info /app/brightstaff 2>&1 | tee /var/log/brightstaff.log | while IFS= read -r line; do echo '[brightstaff]' \"$line\"; done" stdout_logfile=/dev/stdout redirect_stderr=true stdout_logfile_maxbytes=0 diff --git a/crates/brightstaff/src/handlers/agent_chat_completions.rs b/crates/brightstaff/src/handlers/agent_chat_completions.rs index b72c4c6c..fb7db45a 100644 --- a/crates/brightstaff/src/handlers/agent_chat_completions.rs +++ b/crates/brightstaff/src/handlers/agent_chat_completions.rs @@ -170,7 +170,6 @@ async fn handle_agent_chat( &chat_completions_request.messages, &listener, trace_parent, - &agent_map, ) .await?; diff --git a/crates/brightstaff/src/handlers/agent_selector.rs b/crates/brightstaff/src/handlers/agent_selector.rs index fc5b79ca..48735628 100644 --- a/crates/brightstaff/src/handlers/agent_selector.rs +++ b/crates/brightstaff/src/handlers/agent_selector.rs @@ -69,7 +69,6 @@ impl AgentSelector { messages: &[Message], listener: &Listener, trace_parent: Option, - agent_map: &HashMap, ) -> Result { let agents = listener .agents @@ -83,7 +82,7 @@ impl AgentSelector { } let usage_preferences = self - .convert_agent_description_to_routing_preferences(agents, agent_map) + .convert_agent_description_to_routing_preferences(agents) .await; debug!( "Agents usage preferences for agent routing str: {}", @@ -142,40 +141,15 @@ impl AgentSelector { async fn convert_agent_description_to_routing_preferences( &self, agents: &[AgentFilterChain], - agent_map: &HashMap, ) -> Vec { let mut preferences = Vec::new(); for agent_chain in agents { - // Get the actual agent from the agent_map - let agent = agent_map.get(&agent_chain.id); - - // Determine the description to use - let description = if let Some(agent) = agent { - // Check if this is an MCP agent (URL starts with mcp://) - if agent.url.starts_with("mcp://") { - debug!( - "Agent {} is an MCP agent, fetching tool description from: {}", - agent.id, agent.url - ); - - //TODO: fetch description from mcp server - - "MCP tool description placeholder from config".to_string() - } else { - // Not an MCP agent, use description from config - agent_chain.description.clone().unwrap_or_default() - } - } else { - // Agent not found in map, use description from config - agent_chain.description.clone().unwrap_or_default() - }; - preferences.push(ModelUsagePreference { model: agent_chain.id.clone(), routing_preferences: vec![RoutingPreference { name: agent_chain.id.clone(), - description, + description: agent_chain.description.clone().unwrap_or_default(), }], }); } @@ -288,14 +262,8 @@ mod tests { create_test_agent("agent2", "Second agent description", false), ]; - let agent_structs = vec![ - create_test_agent_struct("agent1"), - create_test_agent_struct("agent2"), - ]; - let agent_map = selector.create_agent_map(&agent_structs); - let preferences = selector - .convert_agent_description_to_routing_preferences(&agents, &agent_map) + .convert_agent_description_to_routing_preferences(&agents) .await; assert_eq!(preferences.len(), 2); diff --git a/crates/brightstaff/src/handlers/pipeline_processor.rs b/crates/brightstaff/src/handlers/pipeline_processor.rs index 85d41afc..6c763679 100644 --- a/crates/brightstaff/src/handlers/pipeline_processor.rs +++ b/crates/brightstaff/src/handlers/pipeline_processor.rs @@ -103,7 +103,7 @@ impl PipelineProcessor { let start_time = SystemTime::now(); let start_instant = Instant::now(); - + // Extract trace context from OpenTelemetry let current_cx = opentelemetry::Context::current(); let span_ref = current_cx.span(); @@ -118,11 +118,11 @@ impl PipelineProcessor { } else { None }; - + chat_history_updated = self .execute_filter(&chat_history_updated, agent, request_headers) .await?; - + let end_time = SystemTime::now(); let elapsed = start_instant.elapsed(); @@ -132,7 +132,7 @@ impl PipelineProcessor { elapsed.as_secs_f64() * 1000.0, chat_history_updated.len() ); - + // Build span with trace context if let Some(collector) = trace_collector { let mut span_builder = SpanBuilder::new(format!("filter_execution: {}", agent_name)) @@ -142,14 +142,14 @@ impl PipelineProcessor { .with_attribute("filter_name", agent_name.to_string()) .with_attribute("tool_name", tool_name.to_string()) .with_attribute("duration_ms", format!("{:.2}", elapsed.as_secs_f64() * 1000.0)); - + if !trace_id.is_empty() { span_builder = span_builder.with_trace_id(trace_id); } if let Some(parent_id) = parent_span_id { span_builder = span_builder.with_parent_span_id(parent_id); } - + let span = span_builder.build(); collector.record_span("brightstaff", span); } @@ -167,7 +167,7 @@ impl PipelineProcessor { ) -> Result { let mut headers = request_headers.clone(); headers.remove(hyper::header::CONTENT_LENGTH); - + headers.insert( ARCH_UPSTREAM_HOST_HEADER, hyper::header::HeaderValue::from_str(agent_id) @@ -249,7 +249,7 @@ impl PipelineProcessor { agent_id: &str, ) -> Result { let request_body = serde_json::to_string(json_rpc_request)?; - + debug!("Sending MCP request to agent {}: {}", agent_id, request_body); let response = self @@ -420,7 +420,7 @@ impl PipelineProcessor { debug!("Sending initialized notification for agent {}", agent_id); let headers = self.build_mcp_headers(&HeaderMap::new(), agent_id, Some(session_id))?; - + let response = self .client .post(format!("{}/mcp", self.url)) diff --git a/demos/use_cases/rag_agent/README.md b/demos/use_cases/rag_agent/README.md index f46a3b8c..7b8b97b9 100644 --- a/demos/use_cases/rag_agent/README.md +++ b/demos/use_cases/rag_agent/README.md @@ -18,7 +18,7 @@ Each agent runs as an independent MCP server and exposes tools that can be calle - **Description**: Rewrites user queries using LLM for better retrieval - **Port**: 10500 -### Context Builder Agent +### Context Builder Agent - **Tool**: `chat_completions` - **Description**: Augments queries with relevant context from knowledge base - **Port**: 10501 @@ -76,7 +76,7 @@ agent_filters: - id: query_rewriter url: mcp://host.docker.internal:10500 tool: rewrite_query_with_archgw # MCP tool name - + - id: context_builder url: mcp://host.docker.internal:10501 tool: chat_completions