fix(ai): Agent chat handler 精确选择 FC-capable provider + 环境变量适配

- chat_handler: 使用 get_provider("claude") 精确获取,避免 resolve fallback 到 Ollama
- ProviderRegistry: 新增 get_provider() 方法(无 health check,无 fallback)
- orchestrator: 从 ANTHROPIC_DEFAULT_SONNET_MODEL 读取模型名,兼容智谱代理
- erp-server: Claude provider 注册优先读 ANTHROPIC_AUTH_TOKEN + ANTHROPIC_BASE_URL

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
This commit is contained in:
iven
2026-05-18 03:58:38 +08:00
parent e47fe547c8
commit 882b27ab7a
4 changed files with 30 additions and 15 deletions

View File

@@ -128,14 +128,16 @@ where
tool_call_id: None,
});
// 解析 Provider
let resolved = ai_state
// 解析 Provider — Agent 需要 Function Calling精确获取 Claude/OpenAI
let provider_arc = ai_state
.provider_registry
.resolve("auto")
.await
.map_err(|e| {
tracing::error!(error = %e, "AI provider resolve failed");
erp_core::error::AppError::Internal("AI 服务暂时不可用,请稍后再试".into())
.get_provider("claude")
.or_else(|| ai_state.provider_registry.get_provider("openai"))
.ok_or_else(|| {
tracing::error!("No FC-capable provider found (need claude or openai)");
erp_core::error::AppError::Internal(
"AI Agent 暂时不可用,需要 Claude 或 OpenAI 提供商".into(),
)
})?;
// 构建 ToolRegistry — Phase 0 只有 query_patient_vitals
@@ -159,7 +161,6 @@ where
);
// 执行 Agent ReAct 循环
let provider_arc = resolved.into_arc();
let orchestrator = AgentOrchestrator::new(provider_arc, std::sync::Arc::new(registry));
let result = orchestrator
.run(SYSTEM_PROMPT, &mut messages, &tool_ctx)