From 026f5cf32d2d79c66aa190b2c65f283bc69adcac Mon Sep 17 00:00:00 2001 From: ZhenYi <434836402@qq.com> Date: Tue, 28 Apr 2026 13:03:55 +0800 Subject: [PATCH] feat(context): thread embed_service through ToolContext for FC tool access Add with_embed_service() builder and embed_service() accessor to ToolContext, wired through ChatService so function-calling tools can access Qdrant vector search. --- libs/agent/chat/service.rs | 6 ++++++ libs/agent/tool/context.rs | 11 +++++++++++ 2 files changed, 17 insertions(+) diff --git a/libs/agent/chat/service.rs b/libs/agent/chat/service.rs index 0867bf4..e17a539 100644 --- a/libs/agent/chat/service.rs +++ b/libs/agent/chat/service.rs @@ -270,6 +270,9 @@ impl ChatService { Some(request.sender.uid), ) .with_project(request.project.id); + if let Some(ref es) = self.embed_service { + ctx = ctx.with_embed_service(es.clone()); + } if let Some(ref registry) = self.tool_registry { ctx.registry_mut().merge(registry.clone()); } @@ -596,6 +599,9 @@ impl ChatService { Some(request.sender.uid), ) .with_project(request.project.id); + if let Some(ref es) = self.embed_service { + ctx = ctx.with_embed_service(es.clone()); + } if let Some(ref registry) = self.tool_registry { ctx.registry_mut().merge(registry.clone()); } diff --git a/libs/agent/tool/context.rs b/libs/agent/tool/context.rs index 7b993e3..e14cefa 100644 --- a/libs/agent/tool/context.rs +++ b/libs/agent/tool/context.rs @@ -27,6 +27,7 @@ struct Inner { pub sender_id: Option, pub project_id: Uuid, pub registry: ToolRegistry, + pub embed_service: Option, depth: u32, max_depth: u32, tool_call_count: usize, @@ -50,6 +51,7 @@ impl ToolContext { sender_id, project_id: Uuid::nil(), registry: ToolRegistry::new(), + embed_service: None, depth: 0, max_depth: 5, tool_call_count: 0, @@ -78,6 +80,15 @@ impl ToolContext { self } + pub fn with_embed_service(mut self, embed_service: crate::embed::EmbedService) -> Self { + Arc::make_mut(&mut self.inner).embed_service = Some(embed_service); + self + } + + pub fn embed_service(&self) -> Option<&crate::embed::EmbedService> { + self.inner.embed_service.as_ref() + } + pub fn recursion_exceeded(&self) -> bool { self.inner.depth >= self.inner.max_depth }