From 9cc01639c5a025a95ba99cafc0817d3bab993a2d Mon Sep 17 00:00:00 2001 From: dal Date: Thu, 8 May 2025 15:44:34 -0600 Subject: [PATCH] strict mode and ignore metadata func --- .../categories/file_tools/create_dashboards.rs | 4 ++-- .../categories/file_tools/create_metrics.rs | 4 ++-- .../categories/file_tools/modify_dashboards.rs | 4 ++-- .../categories/file_tools/modify_metrics.rs | 2 +- .../planning_tools/create_plan_investigative.rs | 2 +- .../create_plan_straightforward.rs | 2 +- api/libs/litellm/src/types.rs | 17 ++++++++++++++++- 7 files changed, 25 insertions(+), 10 deletions(-) diff --git a/api/libs/agents/src/tools/categories/file_tools/create_dashboards.rs b/api/libs/agents/src/tools/categories/file_tools/create_dashboards.rs index 421862866..fb9a9c8f8 100644 --- a/api/libs/agents/src/tools/categories/file_tools/create_dashboards.rs +++ b/api/libs/agents/src/tools/categories/file_tools/create_dashboards.rs @@ -367,7 +367,7 @@ impl ToolExecutor for CreateDashboardFilesTool { async fn get_schema(&self) -> Value { serde_json::json!({ "name": self.get_name(), - "strict": false, + "strict": true, "parameters": { "type": "object", "required": ["files"], @@ -377,7 +377,7 @@ impl ToolExecutor for CreateDashboardFilesTool { "items": { "type": "object", "required": ["name", "yml_content"], - "strict": false, + "strict": true, "properties": { "name": { "type": "string", diff --git a/api/libs/agents/src/tools/categories/file_tools/create_metrics.rs b/api/libs/agents/src/tools/categories/file_tools/create_metrics.rs index e2ea27e4d..07981806a 100644 --- a/api/libs/agents/src/tools/categories/file_tools/create_metrics.rs +++ b/api/libs/agents/src/tools/categories/file_tools/create_metrics.rs @@ -308,7 +308,7 @@ impl ToolExecutor for CreateMetricFilesTool { serde_json::json!({ "name": self.get_name(), "description": get_create_metrics_description().await, - "strict": false, + "strict": true, "parameters": { "type": "object", "required": ["files"], @@ -318,7 +318,7 @@ impl ToolExecutor for CreateMetricFilesTool { "items": { "type": "object", "required": ["name", "yml_content"], - "strict": false, + "strict": true, "properties": { "name": { "type": "string", diff --git a/api/libs/agents/src/tools/categories/file_tools/modify_dashboards.rs b/api/libs/agents/src/tools/categories/file_tools/modify_dashboards.rs index 1eab3bfc0..3487524a4 100644 --- a/api/libs/agents/src/tools/categories/file_tools/modify_dashboards.rs +++ b/api/libs/agents/src/tools/categories/file_tools/modify_dashboards.rs @@ -382,7 +382,7 @@ impl ToolExecutor for ModifyDashboardFilesTool { serde_json::json!({ "name": self.get_name(), "description": get_modify_dashboards_description().await, - "strict": false, + "strict": true, "parameters": { "type": "object", "required": ["files"], @@ -393,7 +393,7 @@ impl ToolExecutor for ModifyDashboardFilesTool { "items": { "type": "object", "required": ["id", "yml_content"], - "strict": false, + "strict": true, "properties": { "id": { "type": "string", diff --git a/api/libs/agents/src/tools/categories/file_tools/modify_metrics.rs b/api/libs/agents/src/tools/categories/file_tools/modify_metrics.rs index 5b9b38ca0..a426dea11 100644 --- a/api/libs/agents/src/tools/categories/file_tools/modify_metrics.rs +++ b/api/libs/agents/src/tools/categories/file_tools/modify_metrics.rs @@ -486,7 +486,7 @@ impl ToolExecutor for ModifyMetricFilesTool { serde_json::json!({ "name": self.get_name(), "description": get_modify_metrics_description().await, - "strict": false, + "strict": true, "parameters": { "type": "object", "required": ["files"], diff --git a/api/libs/agents/src/tools/categories/planning_tools/create_plan_investigative.rs b/api/libs/agents/src/tools/categories/planning_tools/create_plan_investigative.rs index ef1b72723..c2d232320 100644 --- a/api/libs/agents/src/tools/categories/planning_tools/create_plan_investigative.rs +++ b/api/libs/agents/src/tools/categories/planning_tools/create_plan_investigative.rs @@ -87,7 +87,7 @@ impl ToolExecutor for CreatePlanInvestigative { serde_json::json!({ "name": self.get_name(), "description": get_create_plan_investigative_description().await, - "strict": false, + "strict": true, "parameters": { "type": "object", "required": [ diff --git a/api/libs/agents/src/tools/categories/planning_tools/create_plan_straightforward.rs b/api/libs/agents/src/tools/categories/planning_tools/create_plan_straightforward.rs index f04cf073b..120d7734e 100644 --- a/api/libs/agents/src/tools/categories/planning_tools/create_plan_straightforward.rs +++ b/api/libs/agents/src/tools/categories/planning_tools/create_plan_straightforward.rs @@ -84,7 +84,7 @@ impl ToolExecutor for CreatePlanStraightforward { serde_json::json!({ "name": self.get_name(), "description": get_create_plan_straightforward_description().await, - "strict": false, + "strict": true, "parameters": { "type": "object", "required": [ diff --git a/api/libs/litellm/src/types.rs b/api/libs/litellm/src/types.rs index 1f93fa965..dae88a674 100644 --- a/api/libs/litellm/src/types.rs +++ b/api/libs/litellm/src/types.rs @@ -1,6 +1,7 @@ use serde::{Deserialize, Serialize}; use serde_json::Value; use std::collections::HashMap; +use std::env; #[derive(Debug, Serialize, Deserialize, Clone)] pub struct ChatCompletionRequest { @@ -50,7 +51,7 @@ pub struct ChatCompletionRequest { pub parallel_tool_calls: Option, #[serde(skip_serializing_if = "Option::is_none")] pub user: Option, - #[serde(skip_serializing_if = "Option::is_none")] + #[serde(skip_serializing_if = "should_skip_metadata")] pub metadata: Option, } @@ -1065,3 +1066,17 @@ mod tests { assert_eq!(deserialized_resp.usage.total_tokens, 99); } } + +fn should_skip_metadata(metadata: &Option) -> bool { + let env_var_condition_met = match env::var("LLM_BASE_URL") { + Ok(val) => val == "https://api.openai.com/v1", + Err(_) => false, // If env var is not set or any error, condition is not met + }; + + if env_var_condition_met { + return true; // If env var condition is met, always skip + } + + // If env var condition is not met, then skip only if metadata is None + metadata.is_none() +}