From 0f60b02ede154f73b8f9d55ea594c430bfb16e8e Mon Sep 17 00:00:00 2001 From: oudecheng <13802883547@139.com> Date: Sat, 15 Aug 2026 23:10:39 +0800 Subject: [PATCH] =?UTF-8?q?chore(log):=20=E7=BC=A9=E5=87=8F=20INFO=20?= =?UTF-8?q?=E6=97=A5=E5=BF=97=E9=87=8F=EF=BC=8C=E9=AB=98=E9=A2=91=E8=AF=8A?= =?UTF-8?q?=E6=96=AD=E6=97=A5=E5=BF=97=E9=99=8D=E7=BA=A7/=E5=88=A0?= =?UTF-8?q?=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 1. 删除缓存诊断日志 4 处(openai.rs):排查已完结,字段已补齐,每次 LLM 调用都刷屏。 2. 删除 AgentPromptProvider 模型配置日志(agent_prompt_provider.rs):排查遗留,每次请求刷。 3. AgentFactory 创建日志 info→debug(agent_factory.rs):每轮对话刷,降级保留供偶发排查。 4. Calling tool / Tool calls detected info→debug(agent_loop.rs):每次工具调用都刷,全量参数打印开销大,tracing 在未启用级别时不评估字段。 5. LoadTaskMessages 3 条日志 info→debug(load_task_messages.rs):每次前端 trigger 都刷,一次 3 条。 6. 旧结果诊断日志 info→debug(execution.rs):每条消息首次 agent 迭代都触发。 7. pending subagents 日志 info→debug(processor.rs):子代理运行期高频率重复触发。 8. Updating current_session_id 仅变化时打(ws.rs):old==new 时每条消息都刷,无信息量。 编译通过,测试全绿。 --- src/agent/agent_loop.rs | 4 ++-- src/command/handlers/load_task_messages.rs | 6 +++--- src/gateway/agent_factory.rs | 4 ++-- src/gateway/agent_prompt_provider.rs | 9 --------- src/gateway/execution.rs | 2 +- src/gateway/processor.rs | 2 +- src/gateway/ws.rs | 14 ++++++++------ src/providers/openai.rs | 16 ---------------- 8 files changed, 17 insertions(+), 40 deletions(-) diff --git a/src/agent/agent_loop.rs b/src/agent/agent_loop.rs index 1cbd9f8..1c7ac29 100644 --- a/src/agent/agent_loop.rs +++ b/src/agent/agent_loop.rs @@ -1406,7 +1406,7 @@ impl AgentLoop { } // Execute tool calls - tracing::info!( + tracing::debug!( iteration, count = response.tool_calls.len(), "Tool calls detected, executing tools" @@ -2088,7 +2088,7 @@ impl AgentLoop { serde_json::Value::Object(obj) if obj.is_empty() => "{}".to_string(), other => serde_json::to_string_pretty(other).unwrap_or_else(|_| other.to_string()), }; - tracing::info!(tool = %tool_call.name, args = %args_str, "Calling tool"); + tracing::debug!(tool = %tool_call.name, args = %args_str, "Calling tool"); // Record ToolCallStart event if let Some(ref observer) = self.observer { diff --git a/src/command/handlers/load_task_messages.rs b/src/command/handlers/load_task_messages.rs index cfa7b88..33589ec 100644 --- a/src/command/handlers/load_task_messages.rs +++ b/src/command/handlers/load_task_messages.rs @@ -56,7 +56,7 @@ async fn handle_load_task_messages( task_id: String, ctx: CommandContext, ) -> Result { - tracing::info!( + tracing::debug!( task_id = %task_id, request_id = %ctx.request_id, "LoadTaskMessages: looking up task" @@ -65,7 +65,7 @@ async fn handle_load_task_messages( // 1. Try in-memory repository first let task = match handler.task_repository.load_task_session(&task_id).await { Ok(Some(task)) => { - tracing::info!( + tracing::debug!( task_id = %task.id, session_id = %task.session_id, state = ?task.state, @@ -74,7 +74,7 @@ async fn handle_load_task_messages( Some(task) } Ok(None) => { - tracing::info!( + tracing::debug!( task_id = %task_id, "LoadTaskMessages: task not in memory, searching database" ); diff --git a/src/gateway/agent_factory.rs b/src/gateway/agent_factory.rs index 61c5c94..b363eda 100644 --- a/src/gateway/agent_factory.rs +++ b/src/gateway/agent_factory.rs @@ -233,8 +233,8 @@ impl AgentFactory { _ => expert_provider_config, }; - // 诊断日志:记录 agent 实际使用的配置和实例 ID - tracing::info!( + // 诊断日志(debug):记录 agent 实际使用的配置和实例 ID + tracing::debug!( instance_id = self.instance_id, channel = %request.channel_name, session_id = %session_id, diff --git a/src/gateway/agent_prompt_provider.rs b/src/gateway/agent_prompt_provider.rs index ef1845b..7e60811 100644 --- a/src/gateway/agent_prompt_provider.rs +++ b/src/gateway/agent_prompt_provider.rs @@ -61,15 +61,6 @@ impl SystemPromptProvider for AgentPromptProvider { return None; } - // 诊断日志:记录系统提示词实际使用的模型配置(用于排查"配置不生效"问题) - tracing::info!( - session_id = ?context.session_id, - chat_id = %context.chat_id, - provider = %self.provider_config.name, - model_id = %self.provider_config.model_id, - "AgentPromptProvider: building system prompt with model config" - ); - // 加载 Agent 提示词(AGENT.md + builtin + MEMORY_SUMMARY.md) let agent_prompt = load_agent_prompt().ok().flatten()?; diff --git a/src/gateway/execution.rs b/src/gateway/execution.rs index c8d8155..fc50b0b 100644 --- a/src/gateway/execution.rs +++ b/src/gateway/execution.rs @@ -167,7 +167,7 @@ impl AgentExecutionService { .as_deref() .unwrap_or(request.chat_id), ); - tracing::info!( + tracing::debug!( channel = %request.channel_name, chat_id = %request.chat_id, user_message_id = %request.user_message.id, diff --git a/src/gateway/processor.rs b/src/gateway/processor.rs index 40e91c4..c9b083c 100644 --- a/src/gateway/processor.rs +++ b/src/gateway/processor.rs @@ -594,7 +594,7 @@ impl InboundProcessor { .list_pending_subagents(topic_id, Some("running")) .unwrap_or_default(); if !pending.is_empty() { - tracing::info!( + tracing::debug!( topic_id = %topic_id, pending_count = pending.len(), "Skipping ExecutionCompleted: pending subagents still running" diff --git a/src/gateway/ws.rs b/src/gateway/ws.rs index 49f6996..b428baa 100644 --- a/src/gateway/ws.rs +++ b/src/gateway/ws.rs @@ -557,13 +557,15 @@ async fn handle_inbound( // 处理响应 if response.success { - // 更新当前会话 ID(如果是创建会话) + // 更新当前会话 ID(如果是创建会话);仅在变化时记录日志 if let Some(session_id) = response.metadata.get("session_id") { - tracing::info!( - old_session_id = %current_session_id, - new_session_id = %session_id, - "Updating current_session_id" - ); + if session_id != current_session_id { + tracing::info!( + old_session_id = %current_session_id, + new_session_id = %session_id, + "Updating current_session_id" + ); + } *current_session_id = session_id.clone(); let _ = state .channel_manager diff --git a/src/providers/openai.rs b/src/providers/openai.rs index 0f7c805..d17b7d8 100644 --- a/src/providers/openai.rs +++ b/src/providers/openai.rs @@ -96,7 +96,6 @@ impl StreamingAccumulator { /// 跳过 total_tokens=0 的占位帧,避免覆盖真实值。 fn set_usage(&mut self, usage: OpenAIUsage) { if usage.total_tokens > 0 { - usage.log_cache_diagnostics("stream_final_frame"); self.usage = Some(usage); } } @@ -725,7 +724,6 @@ impl OpenAIProvider { }) .unwrap_or_default(); // 回退场景下也从非流式响应提取 usage - openai_resp.usage.log_cache_diagnostics("non_streaming_fallback"); response.usage = Usage { prompt_tokens: openai_resp.usage.prompt_tokens, completion_tokens: openai_resp.usage.completion_tokens, @@ -1108,19 +1106,6 @@ impl OpenAIUsage { }) .unwrap_or(0) } - - /// 诊断日志:记录 API 是否返回缓存字段及解析后的值(排查"缓存一直不命中"问题)。 - /// field_present=false 说明 API/网关根本没返回缓存字段(中转服务剥离或模型不支持)。 - fn log_cache_diagnostics(&self, source: &str) { - tracing::info!( - source = %source, - prompt_tokens = self.prompt_tokens, - cached_tokens = self.cached_tokens(), - deepseek_cache_field_present = self.prompt_cache_hit_tokens.is_some(), - openai_cache_details_present = self.prompt_tokens_details.is_some(), - "OpenAI usage cache diagnostics" - ); - } } #[async_trait] @@ -1279,7 +1264,6 @@ impl LLMProvider for OpenAIProvider { reasoning_content: openai_resp.choices[0].message.reasoning_content.clone(), tool_calls, usage: { - openai_resp.usage.log_cache_diagnostics("non_streaming"); Usage { prompt_tokens: openai_resp.usage.prompt_tokens, completion_tokens: openai_resp.usage.completion_tokens,