refactor: 移除 show_tool_results 开关,始终实时推送工具调用消息
简化工具消息推送逻辑,去掉条件判断,让所有工具消息(含结果) 直接通过 emit_live_tool_call_message 实时发送给用户。 Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
parent
7755164df5
commit
5e5de7ce9f
@ -975,7 +975,8 @@ impl AgentLoop {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
messages.push(tool_message.clone());
|
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 => {
|
LoopDetectionResult::Ok => {
|
||||||
let tool_message = ChatMessage::tool_with_state(
|
let tool_message = ChatMessage::tool_with_state(
|
||||||
@ -989,7 +990,8 @@ impl AgentLoop {
|
|||||||
},
|
},
|
||||||
);
|
);
|
||||||
messages.push(tool_message.clone());
|
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) {
|
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 {
|
if let Some(handler) = &self.emitted_message_handler {
|
||||||
handler.handle(message).await;
|
handler.handle(message).await;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -223,7 +223,6 @@ impl InboundProcessor {
|
|||||||
inbound.channel.clone(),
|
inbound.channel.clone(),
|
||||||
inbound.chat_id.clone(),
|
inbound.chat_id.clone(),
|
||||||
inbound.forwarded_metadata.clone(),
|
inbound.forwarded_metadata.clone(),
|
||||||
self.session_manager.show_tool_results(),
|
|
||||||
));
|
));
|
||||||
|
|
||||||
match self
|
match self
|
||||||
|
|||||||
@ -17,6 +17,7 @@ use uuid::Uuid;
|
|||||||
|
|
||||||
use super::agent_factory::{AgentBuildRequest, AgentFactory};
|
use super::agent_factory::{AgentBuildRequest, AgentFactory};
|
||||||
use super::cli_session::CliSessionService;
|
use super::cli_session::CliSessionService;
|
||||||
|
#[cfg(test)]
|
||||||
use super::execution::should_display_message_to_user;
|
use super::execution::should_display_message_to_user;
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
use super::memory_maintenance::{
|
use super::memory_maintenance::{
|
||||||
@ -51,7 +52,6 @@ pub struct BusToolCallEmitter {
|
|||||||
channel_name: String,
|
channel_name: String,
|
||||||
chat_id: String,
|
chat_id: String,
|
||||||
metadata: HashMap<String, String>,
|
metadata: HashMap<String, String>,
|
||||||
show_tool_results: bool,
|
|
||||||
}
|
}
|
||||||
|
|
||||||
impl BusToolCallEmitter {
|
impl BusToolCallEmitter {
|
||||||
@ -60,14 +60,12 @@ impl BusToolCallEmitter {
|
|||||||
channel_name: impl Into<String>,
|
channel_name: impl Into<String>,
|
||||||
chat_id: impl Into<String>,
|
chat_id: impl Into<String>,
|
||||||
metadata: HashMap<String, String>,
|
metadata: HashMap<String, String>,
|
||||||
show_tool_results: bool,
|
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
bus,
|
bus,
|
||||||
channel_name: channel_name.into(),
|
channel_name: channel_name.into(),
|
||||||
chat_id: chat_id.into(),
|
chat_id: chat_id.into(),
|
||||||
metadata,
|
metadata,
|
||||||
show_tool_results,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -75,10 +73,6 @@ impl BusToolCallEmitter {
|
|||||||
#[async_trait]
|
#[async_trait]
|
||||||
impl EmittedMessageHandler for BusToolCallEmitter {
|
impl EmittedMessageHandler for BusToolCallEmitter {
|
||||||
async fn handle(&self, message: ChatMessage) {
|
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(
|
for outbound in OutboundMessage::from_chat_message(
|
||||||
&self.channel_name,
|
&self.channel_name,
|
||||||
&self.chat_id,
|
&self.chat_id,
|
||||||
@ -664,6 +658,7 @@ impl SessionManager {
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::bus::MessageBus;
|
use crate::bus::MessageBus;
|
||||||
|
use crate::bus::message::OutboundEventKind;
|
||||||
use crate::gateway::tool_registry_factory::ToolRegistryFactory;
|
use crate::gateway::tool_registry_factory::ToolRegistryFactory;
|
||||||
use crate::storage::MemoryRecord;
|
use crate::storage::MemoryRecord;
|
||||||
use crate::tools::NoopSessionMessageSender;
|
use crate::tools::NoopSessionMessageSender;
|
||||||
@ -1741,7 +1736,7 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[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 bus = MessageBus::new(4);
|
||||||
let emitter =
|
let emitter =
|
||||||
BusToolCallEmitter::new(
|
BusToolCallEmitter::new(
|
||||||
@ -1749,18 +1744,16 @@ mod tests {
|
|||||||
"test-channel",
|
"test-channel",
|
||||||
"chat-1",
|
"chat-1",
|
||||||
HashMap::new(),
|
HashMap::new(),
|
||||||
false,
|
|
||||||
);
|
);
|
||||||
|
|
||||||
emitter
|
emitter
|
||||||
.handle(ChatMessage::tool("call-1", "calculator", "2"))
|
.handle(ChatMessage::tool("call-1", "calculator", "2"))
|
||||||
.await;
|
.await;
|
||||||
|
|
||||||
assert!(
|
let msg = tokio::time::timeout(std::time::Duration::from_millis(500), bus.consume_outbound())
|
||||||
tokio::time::timeout(std::time::Duration::from_millis(50), bus.consume_outbound())
|
.await
|
||||||
.await
|
.expect("should have received an outbound message");
|
||||||
.is_err()
|
assert_eq!(msg.event_kind, OutboundEventKind::ToolResult);
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::test]
|
#[tokio::test]
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user