From 5e5de7ce9ffa4d03ceca45923b51709a27bb9a2e Mon Sep 17 00:00:00 2001 From: oudecheng <13802883547@139.com> Date: Thu, 28 May 2026 18:52:40 +0800 Subject: [PATCH] =?UTF-8?q?refactor:=20=E7=A7=BB=E9=99=A4=20show=5Ftool=5F?= =?UTF-8?q?results=20=E5=BC=80=E5=85=B3=EF=BC=8C=E5=A7=8B=E7=BB=88?= =?UTF-8?q?=E5=AE=9E=E6=97=B6=E6=8E=A8=E9=80=81=E5=B7=A5=E5=85=B7=E8=B0=83?= =?UTF-8?q?=E7=94=A8=E6=B6=88=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 简化工具消息推送逻辑,去掉条件判断,让所有工具消息(含结果) 直接通过 emit_live_tool_call_message 实时发送给用户。 Co-Authored-By: Claude Opus 4.7 --- src/agent/agent_loop.rs | 10 ++++------ src/gateway/processor.rs | 1 - src/gateway/session.rs | 21 +++++++-------------- 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/src/agent/agent_loop.rs b/src/agent/agent_loop.rs index 7aeae95..619ada1 100644 --- a/src/agent/agent_loop.rs +++ b/src/agent/agent_loop.rs @@ -975,7 +975,8 @@ impl AgentLoop { }, ); messages.push(tool_message.clone()); - emitted_messages.push(tool_message); + emitted_messages.push(tool_message.clone()); + self.emit_live_tool_call_message(tool_message).await; } LoopDetectionResult::Ok => { let tool_message = ChatMessage::tool_with_state( @@ -989,7 +990,8 @@ impl AgentLoop { }, ); messages.push(tool_message.clone()); - emitted_messages.push(tool_message); + emitted_messages.push(tool_message.clone()); + self.emit_live_tool_call_message(tool_message).await; } } } @@ -1111,10 +1113,6 @@ impl AgentLoop { } async fn emit_live_tool_call_message(&self, message: ChatMessage) { - if !message.is_assistant_tool_call_message() { - return; - } - if let Some(handler) = &self.emitted_message_handler { handler.handle(message).await; } diff --git a/src/gateway/processor.rs b/src/gateway/processor.rs index aaf7128..4fd0dbe 100644 --- a/src/gateway/processor.rs +++ b/src/gateway/processor.rs @@ -223,7 +223,6 @@ impl InboundProcessor { inbound.channel.clone(), inbound.chat_id.clone(), inbound.forwarded_metadata.clone(), - self.session_manager.show_tool_results(), )); match self diff --git a/src/gateway/session.rs b/src/gateway/session.rs index 1c3d89f..4d56032 100644 --- a/src/gateway/session.rs +++ b/src/gateway/session.rs @@ -17,6 +17,7 @@ use uuid::Uuid; use super::agent_factory::{AgentBuildRequest, AgentFactory}; use super::cli_session::CliSessionService; +#[cfg(test)] use super::execution::should_display_message_to_user; #[cfg(test)] use super::memory_maintenance::{ @@ -51,7 +52,6 @@ pub struct BusToolCallEmitter { channel_name: String, chat_id: String, metadata: HashMap, - show_tool_results: bool, } impl BusToolCallEmitter { @@ -60,14 +60,12 @@ impl BusToolCallEmitter { channel_name: impl Into, chat_id: impl Into, metadata: HashMap, - show_tool_results: bool, ) -> Self { Self { bus, channel_name: channel_name.into(), chat_id: chat_id.into(), metadata, - show_tool_results, } } } @@ -75,10 +73,6 @@ impl BusToolCallEmitter { #[async_trait] impl EmittedMessageHandler for BusToolCallEmitter { async fn handle(&self, message: ChatMessage) { - if !should_display_message_to_user(self.show_tool_results, &message) { - return; - } - for outbound in OutboundMessage::from_chat_message( &self.channel_name, &self.chat_id, @@ -664,6 +658,7 @@ impl SessionManager { mod tests { use super::*; use crate::bus::MessageBus; + use crate::bus::message::OutboundEventKind; use crate::gateway::tool_registry_factory::ToolRegistryFactory; use crate::storage::MemoryRecord; use crate::tools::NoopSessionMessageSender; @@ -1741,7 +1736,7 @@ mod tests { } #[tokio::test] - async fn test_bus_tool_call_emitter_hides_completed_tool_results_when_disabled() { + async fn test_bus_tool_call_emitter_emits_completed_tool_results() { let bus = MessageBus::new(4); let emitter = BusToolCallEmitter::new( @@ -1749,18 +1744,16 @@ mod tests { "test-channel", "chat-1", HashMap::new(), - false, ); emitter .handle(ChatMessage::tool("call-1", "calculator", "2")) .await; - assert!( - tokio::time::timeout(std::time::Duration::from_millis(50), bus.consume_outbound()) - .await - .is_err() - ); + let msg = tokio::time::timeout(std::time::Duration::from_millis(500), bus.consume_outbound()) + .await + .expect("should have received an outbound message"); + assert_eq!(msg.event_kind, OutboundEventKind::ToolResult); } #[tokio::test]