feat: 添加配置应用诊断日志,便于排查 AgentFactory 实例与工具列表

This commit is contained in:
oudecheng 2026-07-03 16:33:01 +08:00
parent 7640a6e5b7
commit 5ceafb1fd7
4 changed files with 52 additions and 0 deletions

View File

@ -15,6 +15,8 @@ pub(crate) struct AgentFactory {
skills: Arc<SkillRuntime>,
reinject_every: usize,
prompt_repository: Arc<dyn PromptInjectionRepository>,
/// 实例创建时间戳(用于区分新旧 AgentFactory 实例)
instance_id: u64,
}
pub(crate) struct AgentBuildRequest<'a> {
@ -37,17 +39,36 @@ impl AgentFactory {
reinject_every: usize,
prompt_repository: Arc<dyn PromptInjectionRepository>,
) -> Self {
// 使用 Arc 指针地址作为实例标识符,用于区分新旧 AgentFactory 实例
let instance_id = Arc::as_ptr(&tools) as u64;
tracing::info!(
instance_id = instance_id,
tool_count = tools.tool_names().len(),
"AgentFactory::new created"
);
Self {
tools,
skills,
reinject_every,
prompt_repository,
instance_id,
}
}
pub(crate) fn create(&self, request: AgentBuildRequest<'_>) -> Result<AgentLoop, AgentError> {
let session_id = persistent_session_id(request.channel_name, request.session_chat_id);
// 诊断日志:记录 agent 实际使用的配置和实例 ID
tracing::info!(
instance_id = self.instance_id,
channel = %request.channel_name,
session_id = %session_id,
provider = %request.provider_config.name,
model_id = %request.provider_config.model_id,
tool_count = self.tools.tool_names().len(),
"AgentFactory: creating agent with config"
);
// 创建组合的系统提示词提供者
let system_prompt_provider = Arc::new(CompositeSystemPromptProvider::new(vec![
Box::new(AgentPromptProvider::new(

View File

@ -55,6 +55,15 @@ 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()?;

View File

@ -104,6 +104,12 @@ impl GatewayState {
Some(bus.clone()),
)?;
// 诊断日志:记录新 GatewayState 的创建(用于排查重启后是否使用了新状态)
tracing::info!(
mcp_manager_present = mcp_manager.is_some(),
"GatewayState::from_config: new GatewayState created"
);
let cancel_manager = CancelManager::new();
Ok(Self {

View File

@ -224,6 +224,15 @@ pub(crate) fn build_session_manager_with_sender(
// Build base tools
let tools = factory.build();
// 诊断日志:记录 MCP 初始化状态和基础工具数量
tracing::info!(
mcp_enabled = mcp_initializer.is_enabled(),
mcp_tools_collected = mcp_tools_for_subagents.len(),
base_tool_count = tools.tool_names().len(),
base_tools = ?tools.tool_names(),
"build_session_manager: base tools built (before MCP registration)"
);
// Register MCP tools to main agent (async)
// Note: MCP tools for subagents are already collected above
if mcp_initializer.is_enabled() {
@ -240,6 +249,13 @@ pub(crate) fn build_session_manager_with_sender(
let tools = Arc::new(tools);
// 诊断日志:记录最终工具数量(含 MCP 工具,如果启用)
tracing::info!(
final_tool_count = tools.tool_names().len(),
final_tools = ?tools.tool_names(),
"build_session_manager: final tools registered to main agent"
);
let prompt_repository: Arc<dyn PromptInjectionRepository> = store.clone();
let agent_factory = AgentFactory::new(
tools.clone(),