3.5 KiB
3.5 KiB
Architecture
系统分层
API Layer
-> ChatController / DiagnosisTraceController
Agent Orchestration
-> ChatService / AiOpsService
Tools
-> lookupKnowledgeTool / queryLogs / queryMetrics / queryPrometheusAlerts
Persistence
-> diagnosis_session / agent_step / tool_invocation
Trace
-> GET /api/diagnosis/{sessionId}/trace
Chat 链路
flowchart TD
User[User Question] --> ChatAPI[POST /api/chat]
ChatAPI --> Strategy[ChatService.executeChatWithStrategy]
Strategy --> Complexity{QuestionComplexity}
Complexity -->|simple| Single[ReactAgent]
Complexity -->|complex| Planner[Planner Agent]
Planner --> Executor[Executor Agent]
Executor --> Tools[Evidence Tools]
Tools --> Executor
Executor --> Verifier[Verifier Agent]
Verifier --> Answer[Final Answer]
Answer --> Session[diagnosis_session]
Planner --> Steps[agent_step]
Executor --> Steps
Verifier --> Steps
Tools --> Invocations[tool_invocation]
Session --> Trace[GET /api/diagnosis/{sessionId}/trace]
Steps --> Trace
Invocations --> Trace
关键代码:
ChatController.chat(...)ChatService.executeChatWithStrategy(...)ChatService.executeChatComplex(...)AgentLoggingHookToolInvocationRecorderDiagnosisTraceService.getTrace(...)
AIOps 链路
flowchart TD
Alert[Alert Payload or Empty Request] --> AiOpsAPI[POST /api/ai_ops]
AiOpsAPI --> SessionEvent[SSE session event]
AiOpsAPI --> AiOpsService[AiOpsService.executeAiOpsAnalysis]
AiOpsService --> PromptMode{Payload?}
PromptMode -->|yes| Targeted[PAYLOAD_TARGETED]
PromptMode -->|no| Discovery[AUTO_DISCOVERY]
Targeted --> Supervisor[ai_ops_supervisor]
Discovery --> Supervisor
Supervisor --> Planner[planner_agent]
Supervisor --> Executor[executor_agent]
Planner --> Tools[Prometheus / Logs / Knowledge]
Executor --> Tools
Tools --> Report[Alert Report]
Report --> Persist[diagnosis_session.answer]
Planner --> Steps[agent_step]
Executor --> Steps
Tools --> Invocations[tool_invocation]
Persist --> Trace[GET /api/diagnosis/{sessionId}/trace]
Steps --> Trace
Invocations --> Trace
关键代码:
ChatController.aiOps(...)AIOpsRequestAiOpsService.resolveSessionId(...)AiOpsService.buildTaskPrompt(...)AiOpsService.hasAlertPayload(...)AiOpsService.persistFinalReport(...)
Trace 数据模型
diagnosis_session
记录一次诊断会话的主信息:
session_idquerystatusagent_flowtotal_duration_mstotal_token_countstep_counttool_call_countanswerself_evaluationfeedback
agent_step
记录 Agent 模型调用过程:
session_idstep_indexagent_namemodel_inputmodel_outputthoughthas_tool_callduration_mstoken_count
tool_invocation
记录真实工具调用:
session_idtool_nameinput_paramsoutput_previewoutput_lengthretrieval_layerrelevance_levelduration_mssuccesserror_message
为什么 trace 是核心
Agent 系统的风险不只是“答案错”,还包括“答案看起来对但无法解释”。这个项目把执行链路拆成 session、step、tool 三层,让面试官可以看到:
- 模型为什么这么答
- 调了哪些工具
- 工具返回了什么证据
- Verifier 如何判断答案可信度
- 用户反馈如何回写到同一个 session
这就是项目区别于普通 Chatbot 的地方。