优化查询代码,优化工具代码
All checks were successful
构建并部署 AI Agent 服务 / deploy (push) Successful in 5m33s

This commit is contained in:
2026-05-08 22:30:26 +08:00
parent bfb2ddbe76
commit b30f7b00a7
11 changed files with 375 additions and 511 deletions

View File

@@ -0,0 +1,46 @@
"""
Agent Service 配置模块 - 配置构建和解析
"""
from typing import Dict, Any, Tuple, Optional
from langchain_core.messages import HumanMessage
from backend.app.logger import warning
class ServiceConfig:
"""配置构建器"""
def __init__(self, chat_services: dict):
self.chat_services = chat_services
def resolve_model(self, model: Optional[str]) -> str:
"""
解析并验证模型名称,不可用时回退到第一个可用模型
"""
if not model or model not in self.chat_services:
fallback = next(iter(self.chat_services.keys()))
warning(f"模型 '{model}' 不可用,回退到 '{fallback}'")
return fallback
return model
def build_invocation(
self, message: str, thread_id: str, model: str, user_id: str
) -> Tuple[Dict[str, Any], Dict[str, Any]]:
"""
构建图调用所需的 config 和 input_state
Returns:
(config, input_state) 元组
"""
config = {
"configurable": {
"thread_id": thread_id,
},
"metadata": {"user_id": user_id}
}
input_state = {
"messages": [HumanMessage(content=message)],
"user_id": user_id,
}
return config, input_state