From 9336250f1c07fa24ad4cf586f42e1e3a645de4ed Mon Sep 17 00:00:00 2001 From: ZhenYi <434836402@qq.com> Date: Sat, 18 Apr 2026 19:41:59 +0800 Subject: [PATCH] fix(agent): skip reasoning_effort when think=false to avoid API errors --- libs/agent/chat/service.rs | 14 +++++++++++++- libs/agent/tool/context.rs | 5 +++++ libs/agent/tool/mod.rs | 2 +- libs/agent/tool/registry.rs | 14 ++++++++++++++ libs/service/lib.rs | 5 ++++- libs/service/project/invitation.rs | 8 ++++---- 6 files changed, 41 insertions(+), 7 deletions(-) diff --git a/libs/agent/chat/service.rs b/libs/agent/chat/service.rs index 56db151..7fcc8b7 100644 --- a/libs/agent/chat/service.rs +++ b/libs/agent/chat/service.rs @@ -19,7 +19,7 @@ use crate::compact::{CompactConfig, CompactService}; use crate::embed::EmbedService; use crate::error::{AgentError, Result}; use crate::perception::{PerceptionService, SkillEntry, ToolCallEvent}; -use crate::tool::{ToolCall, ToolContext, ToolExecutor}; +use crate::tool::{ToolCall, ToolContext, ToolExecutor, registry::ToolRegistry}; /// Service for handling AI chat requests in rooms. pub struct ChatService { @@ -27,6 +27,7 @@ pub struct ChatService { compact_service: Option, embed_service: Option, perception_service: PerceptionService, + tool_registry: Option, } impl ChatService { @@ -36,6 +37,7 @@ impl ChatService { compact_service: None, embed_service: None, perception_service: PerceptionService::default(), + tool_registry: None, } } @@ -54,6 +56,11 @@ impl ChatService { self } + pub fn with_tool_registry(mut self, registry: ToolRegistry) -> Self { + self.tool_registry = Some(registry); + self + } + #[allow(deprecated)] pub async fn process(&self, request: AiRequest) -> Result { let tools: Vec = request.tools.clone().unwrap_or_default(); @@ -390,6 +397,11 @@ impl ChatService { ) .with_project(request.project.id); + // Add pre-configured tool registry if available + if let Some(ref registry) = self.tool_registry { + ctx.registry_mut().merge(registry.clone()); + } + let executor = ToolExecutor::new(); let results = executor diff --git a/libs/agent/tool/context.rs b/libs/agent/tool/context.rs index 42697b2..220299f 100644 --- a/libs/agent/tool/context.rs +++ b/libs/agent/tool/context.rs @@ -130,4 +130,9 @@ impl ToolContext { pub fn registry(&self) -> &ToolRegistry { &self.inner.registry } + + /// Mutable access to registry for adding tools. + pub fn registry_mut(&mut self) -> &mut ToolRegistry { + &mut Arc::make_mut(&mut self.inner).registry + } } diff --git a/libs/agent/tool/mod.rs b/libs/agent/tool/mod.rs index b0bacdf..5e534d2 100644 --- a/libs/agent/tool/mod.rs +++ b/libs/agent/tool/mod.rs @@ -24,4 +24,4 @@ pub use call::{ToolCall, ToolCallResult, ToolError, ToolResult}; pub use context::ToolContext; pub use definition::{ToolDefinition, ToolParam, ToolSchema}; pub use executor::ToolExecutor; -pub use registry::ToolRegistry; +pub use registry::{ToolHandler, ToolRegistry}; diff --git a/libs/agent/tool/registry.rs b/libs/agent/tool/registry.rs index 9c0efd2..ffcf0fe 100644 --- a/libs/agent/tool/registry.rs +++ b/libs/agent/tool/registry.rs @@ -92,4 +92,18 @@ impl ToolRegistry { pub fn is_empty(&self) -> bool { self.handlers.is_empty() } + + /// Merges another registry's tools into this one. + /// Panics if a tool with the same name already exists. + pub fn merge(&mut self, other: ToolRegistry) { + for (name, handler) in other.handlers { + if self.handlers.contains_key(&name) { + panic!("tool already registered: {}", name); + } + self.handlers.insert(name, handler); + } + for (name, def) in other.definitions { + self.definitions.insert(name, def); + } + } } diff --git a/libs/service/lib.rs b/libs/service/lib.rs index 0d9f79b..6a4a832 100644 --- a/libs/service/lib.rs +++ b/libs/service/lib.rs @@ -1,6 +1,7 @@ use std::sync::Arc; use ::agent::chat::ChatService; +use ::agent::tool::ToolRegistry; use ::agent::task::service::TaskService; use async_openai::config::OpenAIConfig; use avatar::AppAvatar; @@ -145,7 +146,9 @@ impl AppService { .with_api_key(&api_key) .with_api_base(&base_url); let client = async_openai::Client::with_config(cfg); - Some(Arc::new(ChatService::new(client))) + let mut registry = ToolRegistry::new(); + git_tools::register_all(&mut registry); + Some(Arc::new(ChatService::new(client).with_tool_registry(registry))) } (Err(e), _) => { slog::warn!(logs, "AI chat disabled — {}", e); diff --git a/libs/service/project/invitation.rs b/libs/service/project/invitation.rs index 596800e..090ee99 100644 --- a/libs/service/project/invitation.rs +++ b/libs/service/project/invitation.rs @@ -1,7 +1,6 @@ use crate::AppService; use crate::error::AppError; use chrono::{DateTime, Utc}; -use futures::future::join_all; use models::projects::{ project, MemberRole, project_audit_log, project_member_invitations, project_members, }; @@ -165,13 +164,14 @@ impl AppService { .count(&self.db) .await?; - let invitations = join_all( + let invitations = futures::future::join_all( invitations .into_iter() .map(|inv| InvitationResponse::from_model(inv, self.db.writer())), ) - .await; - .collect(); + .await + .into_iter() + .collect(); Ok(InvitationListResponse { invitations,