Commit 2a43e5a7 by luoqi

feat(ai): agent_invocations 落库完整 system prompt(审计/复盘)

prompt_template 只存 user prompt;新增 system_prompt 列存完整 system(base-system +
注入的 skills 正文),一键审计完整 prompt,免去用 input+promptVersion 重跑 composeSystem。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
parent ff6ea96b
-- AlterTable
ALTER TABLE "agent_invocations" ADD COLUMN "system_prompt" TEXT;
......@@ -1213,8 +1213,10 @@ model AgentInvocation {
/// }
/// 运维侧需要保留期清理:成功调用 N 天后清 inputSnapshot 仅保留元数据;失败的保留更久供 debug
inputSnapshot Json @map("input_snapshot")
/// prompt 模板原文(若有); agentVersion 反查 prompt 仓库通常更可靠,本字段冗余兜底
/// user prompt 原文(截断 8000); agentVersion 反查 prompt 仓库通常更可靠,本字段冗余兜底
promptTemplate String? @map("prompt_template") @db.Text
/// system prompt 原文(base-system + 注入的 skills 正文);一键审计/复盘完整 prompt ,免去重跑 composeSystem
systemPrompt String? @map("system_prompt") @db.Text
/// 结构化输出(JSON); outputText 双轨,不同 agent 形态各取所需。
/// **AI 解析结果(如影像 AI 分析)归这里,v1 不回写 patient_facts**(db-review-confirm §3.7)
output Json?
......
......@@ -93,6 +93,7 @@ export class AiCallRunnerService {
const invocationId = await this.recorder.start({
...this.baseStart(call, ctx, modelId, provider, inputHash, input, false),
promptTemplate: prompt.length > 8000 ? prompt.slice(0, 8000) + '…[truncated]' : prompt,
systemPrompt: system.length > 40000 ? system.slice(0, 40000) + '…[truncated]' : system,
});
// ─── 3. 调 LLM ───
......@@ -189,6 +190,7 @@ export class AiCallRunnerService {
const invocationId = await this.recorder.start({
...this.baseStart(call, ctx, modelId, provider, inputHash, input, false),
promptTemplate: prompt.length > 8000 ? prompt.slice(0, 8000) + '…[truncated]' : prompt,
systemPrompt: system.length > 40000 ? system.slice(0, 40000) + '…[truncated]' : system,
});
yield { type: 'start', invocationId, modelId, promptVersion: call.promptVersion };
......
......@@ -27,7 +27,8 @@ export interface InvocationStartInput {
evalMode?: 'production' | 'golden_set' | 'shadow' | 'manual';
goldenSetCaseId?: string;
inputSnapshot: Prisma.InputJsonValue;
promptTemplate?: string;
promptTemplate?: string; // user prompt(截断 8000)
systemPrompt?: string; // system prompt(base-system + 注入的 skills 正文;审计/复盘用)
linkedPatientId?: string;
linkedPersonaId?: string;
linkedPlanId?: string;
......@@ -72,6 +73,7 @@ export class InvocationRecorderService {
goldenSetCaseId: input.goldenSetCaseId ?? null,
inputSnapshot: input.inputSnapshot,
promptTemplate: input.promptTemplate ?? null,
systemPrompt: input.systemPrompt ?? null,
linkedPatientId: input.linkedPatientId ?? null,
linkedPersonaId: input.linkedPersonaId ?? null,
linkedPlanId: input.linkedPlanId ?? null,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment