重构:增强 JSON 解析稳定性,优化 Prompt,改进状态结构
All checks were successful
构建并部署 AI Agent 服务 / deploy (push) Successful in 5m36s
All checks were successful
构建并部署 AI Agent 服务 / deploy (push) Successful in 5m36s
主要改进: 1. 新增 json_parser.py - 统一的 JSON 解析工具 - 支持多种格式(纯 JSON、markdown、文本中的 JSON) - 多层 fallback 策略 - 安全的字段提取函数 2. 优化 intent.py 和 hybrid_router.py - 使用新的 json_parser - 优化 Prompt,更清晰的格式要求 - 更好的错误处理 3. 改进 state.py - 新增结构化状态字段 - ReactReasoningState、HybridRouterState、FastPathState - 向后兼容旧的 debug_info 4. 更新各节点模块 - 同时更新旧字段保持兼容 - reasoning.py - 更新 state.react_reasoning - hybrid_router.py - 更新 state.hybrid_router - fast_paths.py - 更新 state.fast_path
This commit is contained in:
@@ -41,6 +41,30 @@ class ErrorRecord:
|
||||
context: Dict[str, Any] = field(default_factory=dict) # 错误上下文
|
||||
|
||||
|
||||
@dataclass
|
||||
class ReactReasoningState:
|
||||
"""React 推理状态 - 替代 debug_info 中的相关字段"""
|
||||
last_reasoning: Optional[Dict[str, Any]] = None
|
||||
reasoning_result: Optional[Any] = None # 实际类型是 ReasoningResult
|
||||
|
||||
|
||||
@dataclass
|
||||
class HybridRouterState:
|
||||
"""混合路由状态 - 替代 debug_info 中的相关字段"""
|
||||
decision: Optional[Any] = None # 实际类型是 HybridRouterResult
|
||||
start_time: Optional[str] = None
|
||||
|
||||
|
||||
@dataclass
|
||||
class FastPathState:
|
||||
"""快速路径状态 - 替代 debug_info 中的相关字段"""
|
||||
chitchat_success: bool = False
|
||||
rag_success: bool = False
|
||||
tool_success: bool = False
|
||||
failed: bool = False
|
||||
fail_reason: str = ""
|
||||
|
||||
|
||||
@dataclass
|
||||
class MainGraphState:
|
||||
"""
|
||||
@@ -103,4 +127,11 @@ class MainGraphState:
|
||||
# ========== 元数据 ==========
|
||||
start_time: Optional[str] = None
|
||||
end_time: Optional[str] = None
|
||||
|
||||
# ========== 结构化状态(替代黑盒 debug_info)==========
|
||||
react_reasoning: ReactReasoningState = field(default_factory=ReactReasoningState)
|
||||
hybrid_router: HybridRouterState = field(default_factory=HybridRouterState)
|
||||
fast_path: FastPathState = field(default_factory=FastPathState)
|
||||
|
||||
# ========== 向后兼容 ==========
|
||||
debug_info: Dict[str, Any] = field(default_factory=dict)
|
||||
|
||||
Reference in New Issue
Block a user