refactor: 移除 show_tool_results 开关,始终实时推送工具调用消息

简化工具消息推送逻辑,去掉条件判断,让所有工具消息(含结果)
直接通过 emit_live_tool_call_message 实时发送给用户。

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
oudecheng 2026-05-28 18:52:40 +08:00
parent 7755164df5
commit 5e5de7ce9f
3 changed files with 11 additions and 21 deletions

View File

@ -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;
}

View File

@ -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

View File

@ -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<String, String>,
show_tool_results: bool,
}
impl BusToolCallEmitter {
@ -60,14 +60,12 @@ impl BusToolCallEmitter {
channel_name: impl Into<String>,
chat_id: impl Into<String>,
metadata: HashMap<String, String>,
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]