[M-AI-05-03] 实现 Feynman Executor 与结构化输出验证 #306
Closed
opened 2026-06-21 15:53:27 +08:00 by wangdl
·
1 comment
Labels
Clear labels
adr
Area: adr
architecture
Area: architecture
area:activity
活动/统计
area:admin
管理后台
area:admin-api
area:ai
AI/RAG
area:ai-runtime
AI Runtime / AI 分析体系相关
area:analytics
area:api
API 接口
area:auth
认证与授权
area:cos
对象存储
area:database
数据库/Migration
area:import
文件导入/解析
area:knowledge
知识库/知识点
area:learning-info
area:learning-session
area:quiz
测验/自测
area:reading-event
area:reading-progress
area:review
复习系统
area:security
安全相关
audit
Area: audit
audit:api-admin-info
audit:api-info
audit:planned
已完成宏观规划,尚未代码审查
audit:reviewed
backend
Area: backend
billing
Area: billing
blocked-by:api-info-aggregation
blocked-by:api-info-core
blocked-by:api-info-ops
blocked-by:api-info-schema
blocked-by:processor
blocked-by:schema
compatibility
Area: compatibility
gate
Area: gate
infrastructure
Area: infrastructure
priority:p0
最高优先级,阻塞发布
priority:p1
高优先级,里程碑必需
priority:p2
中优先级,后续版本
prisma
Area: prisma
release
Area: release
repo:api
API 仓库 Issue
status:blocked
被阻塞
status:done
已完成
status:partial
status:todo
type:aggregation
type:bug
缺陷修复
type:design
设计
type:docs
文档
type:feature
新功能
type:migration
type:refactor
重构
type:test
work:admin-api
work:aggregation
work:api
work:artifact
题目/卡片产物
work:audit
work:circuit-breaker
熔断
work:contract
work:design
架构/协议设计工作
work:docs
work:export
work:extend-existing
work:internal-api
Runtime 内部接口
work:job
Job 调度相关
work:new-module
work:new-table
work:ops
work:query
work:quota
额度/限流
work:schema
Prisma Schema 设计
work:security
work:service
Service 层实现
work:snapshot
Snapshot 构建
work:test
Milestone
No items
No Milestone
M-AI-05 Feynman 与 ReviewCard 可靠链路
Projects
Clear projects
No project
No Assignees
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: wangdl/api-server#306
Reference in New Issue
Block a user
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
类型 / 标签
风险等级
P1(验证缺失会导致非法输出进入数据库;Prompt 语义偏离会导致评估质量下降)
依赖
目标
将现有 Feynman AI 评估逻辑适配到统一 Execution Engine,保持原 Prompt 和业务语义。Executor 只负责调用模型并返回结构化输出,不写数据库。
Executor
新增
FeynmanExecutor,职责:禁止:直接调用 Provider SDK、自行解析模型凭据、读取 Controller DTO、直接读取或修改业务表、创建 FocusItem、创建 ReviewCard、修改 Job 状态、自行实现 BullMQ Retry。
输出 Schema
严格依据 M-AI-05-01。需要区分:模型原始输出、JSON Repair 后输出、Schema 验证后输出、业务验证后输出。
Business Validator
至少根据真实 Schema 验证:score 范围、正确性枚举、反馈非空、missingPoints 数量与长度、misconceptions 合法性、建议数量、禁止空对象冒充成功、禁止异常大文本、禁止模型指令或代码块进入结构化字段。
Reference Validator
如果输出包含引用:引用 ID 必须存在、只能引用 Snapshot 中允许的资料、不得引用其他用户知识库、不得伪造 URL 或内部路径。没有引用字段时,不得为了形式强行生成引用。
兼容对比
使用固定 Fixture 对比 Legacy Workflow 和新 Executor:Prompt Key、系统提示、用户消息、模型参数、输入上下文、输出业务语义、错误分类。不要求自然语言逐字相同。
影响范围
src/modules/ai-job/executor/、src/modules/ai-job/validator/、src/modules/ai-gateway/验收标准
建议执行顺序
第 3 个执行(依赖 02)
开发完成评论
完成内容
FeynmanExecutor:FeynmanEvaluationWorkflow.execute()格式一致)AiGatewayService.generate()调用模型(feature=feynman-evaluation, promptKey=feynman-evaluation, outputSchema=FeynmanEvaluationResultSchema)FeynmanBusinessValidator(11 项验证规则):FeynmanReferenceValidator:_snapshot?参数(未来扩展引用范围验证)AiJobModule:注册 FeynmanExecutor + FeynmanBusinessValidator + FeynmanReferenceValidator验证链
修改文件
src/modules/ai-job/feynman-executor.ts(新增,88 行)src/modules/ai-job/feynman-validator.ts(新增,225 行)src/modules/ai-job/feynman-executor.spec.ts(新增,315 行)src/modules/ai-job/ai-job.module.ts(修改,+7 行:4 imports + 3 providers)代码证据
feynman-executor.ts:43-79— execute() 核心逻辑(消息构造 + AiGateway 调用 + timeout 传递)feynman-validator.ts:105-172— BusinessValidator.validate()(11 项完整验证规则)feynman-validator.ts:207-247— ReferenceValidator.validate()(URL/Email 检测)feynman-validator.ts:179-198— validateStringArray()(数组字段通用验证)feynman-executor.ts:2-4— 仅注入 AiGatewayService(不注入 PrismaService — 零 DB 副作用)测试情况
npx jest --testPathPatterns="feynman-executor"npx jest --testPathPatterns="ai-job"与 Legacy 的兼容性
FeynmanEvaluationWorkflow.execute()(workflow.ts:18-29) 一致【知识点标题】+ title + 【知识点原文】+ content + 【用户的费曼解释】+ explanationprimary)未完成 / 风险
AiJobExecutionEngine中接入(留待 M-AI-05-05 入口路由 + Engine 分派)feynman_evaluation的 jobType 分支(或改为通用 Registry 驱动的 Executor 分派)是否建议进入 Review