π€― LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.
TypeScript agentagent-collaborationagent-harnessloop-engineeringmcppersonal-assistantproactive-agentskillssuper-agenttask-management
β¨ feat(verify): feed builder-captured evidence to the agent verifier (#16260)
Arvin Xue7549bf3c99b
diff --git a/apps/server/src/services/verify/__tests__/agentVerifier.test.ts b/apps/server/src/services/verify/__tests__/agentVerifier.test.tsindex c889b70e89c..75202cda245 100644--- a/apps/server/src/services/verify/__tests__/agentVerifier.test.ts+++ b/apps/server/src/services/verify/__tests__/agentVerifier.test.ts@@ -117,4 +117,58 @@ describe('createVerifierAgentRunner', () => {expect(existsByIdMock).not.toHaveBeenCalled();expect(execParams().slug).toBe(BUILTIN_AGENT_SLUGS.verifyAgent);});++ it('injects the builder-captured evidence into the verifier prompt (LOBE-10638)', async () => {+ getBuiltinAgentMock.mockResolvedValue({ id: 'builtin-verify' });++ const runner = createVerifierAgentRunner({ ...baseParams })!;+ await runner({+ ...runnerArgs,+ evidence: [+ { description: 'toolbar screenshot', type: 'screenshot' },+ { content: 'aria-label="Send"', description: 'DOM', type: 'dom_snapshot' },+ ],+ });++ const prompt: string = execParams().prompt;+ expect(prompt).toContain('## Captured evidence');+ expect(prompt).toContain('toolbar screenshot');+ expect(prompt).toContain('[artifact captured]'); // screenshot referenced by presence+ expect(prompt).toContain('aria-label="Send"'); // inline dom text quoted+ });++ it('omits the captured-evidence section when no evidence was provided', async () => {+ getBuiltinAgentMock.mockResolvedValue({ id: 'builtin-verify' });++ const runner = createVerifierAgentRunner({ ...baseParams })!;+ await runner(runnerArgs);++ expect(execParams().prompt).not.toContain('## Captured evidence');+ });++ it('attaches file-backed evidence to the verifier run so it can see the artifact', async () => {+ getBuiltinAgentMock.mockResolvedValue({ id: 'builtin-verify' });++ const runner = createVerifierAgentRunner({ ...baseParams })!;+ await runner({+ ...runnerArgs,+ evidence: [+ { description: 'toolbar', fileId: 'file-shot-1', type: 'screenshot' },+ { content: 'inline only', type: 'dom_snapshot' }, // no fileId+ { description: 'demo', fileId: 'file-vid-1', type: 'video' },+ ],+ });++ // Only the file-backed artifacts are forwarded to execAgent (inline-text has none).+ expect(execParams().fileIds).toEqual(['file-shot-1', 'file-vid-1']);+ });++ it('does not pass fileIds when no evidence is file-backed', async () => {+ getBuiltinAgentMock.mockResolvedValue({ id: 'builtin-verify' });++ const runner = createVerifierAgentRunner({ ...baseParams })!;+ await runner({ ...runnerArgs, evidence: [{ content: 'text', type: 'text' }] });++ expect(execParams().fileIds).toBeUndefined();+ });});diff --git a/apps/server/src/services/verify/agentVerifier.ts b/apps/server/src/services/verify/agentVerifier.tsindex f48383e5d90..2e052fc7da7 100644--- a/apps/server/src/services/verify/agentVerifier.ts+++ b/apps/server/src/services/verify/agentVerifier.ts@@ -10,6 +10,7 @@ import { ThreadModel } from '@/database/models/thread';import type { LobeChatDatabase } from '@/database/type';import type { VerifierAgentRunner } from './executor';+import { describeEvidence, type JudgeEvidence } from './prompts';const log = debug('lobe-server:verify-agent-verifier');@@ -17,21 +18,30 @@ const log = debug('lobe-server:verify-agent-verifier');* Build the instruction for a verifier sub-agent investigating one check. The* sub-agent reports its verdict by calling the `submitVerifyResult` tool with the* `checkItemId` injected here β it does not write to the DB directly.+ *+ * `evidence` is what the builder self-captured during the run (LOBE-10638): the+ * verifier judges against the run goal AND this evidence β it's the verifier's+ * primary Data, not a competing verdict.*/export const buildVerifierPrompt = (params: {checkItem: VerifyCheckItem;deliverable: string;+ evidence?: JudgeEvidence[];goal: string;instruction?: string;}): string => {- const { checkItem, deliverable, goal, instruction } = params;+ const { checkItem, deliverable, evidence, goal, instruction } = params;+ const capturedEvidence = describeEvidence(evidence);return [`## Check to verify\ncheckItemId: ${checkItem.id}\nTitle: ${checkItem.title}`,checkItem.description ? `Summary: ${checkItem.description}` : '',instruction ? `\n## Judging instruction\n${instruction}` : '',`\n## Run goal\n${goal}`,deliverable ? `\n## Deliverable / final output\n${deliverable}` : '',- `\n## Your task\nInvestigate whether the deliverable satisfies this check, following the judging instruction. Gather concrete evidence. When done, call \`submitVerifyResult\` exactly once with checkItemId="${checkItem.id}" and your verdict (passed / failed / uncertain) plus evidence and reasoning.`,+ capturedEvidence+ ? `\n## Captured evidence (builder self-evidence β primary Data, weight above prose)${capturedEvidence}`+ : '',+ `\n## Your task\nInvestigate whether the deliverable satisfies this check, judging against the run goal and the judging instruction. Weight the captured evidence above as primary Data; gather more yourself only where it's missing or insufficient. When done, call \`submitVerifyResult\` exactly once with checkItemId="${checkItem.id}" and your verdict (passed / failed / uncertain) plus evidence and reasoning.`,].filter(Boolean).join('\n');@@ -69,7 +79,7 @@ export const createVerifierAgentRunner = (params: {params;if (!topicId) return undefined;- return async ({ checkItem, goal, operationId }) => {+ return async ({ checkItem, evidence, goal, operationId }) => {// The detailed instruction is the criterion's rule body, stored in a document.const instruction = checkItem.documentId? ((await new DocumentModel(db, userId, workspaceId).findById(checkItem.documentId))@@ -121,6 +131,13 @@ export const createVerifierAgentRunner = (params: {return null;}+ // Attach the builder-captured file artifacts (screenshots / videos / large+ // text) so a multimodal verifier can SEE them β the prompt only references+ // them by presence + caption, which is blind for visual checks (LOBE-10638).+ const evidenceFileIds = (evidence ?? [])+ .map((e) => e.fileId)+ .filter((id): id is string => Boolean(id));+// Dynamic import breaks the static cycle: aiAgent β agentRuntime completion// β verify lifecycle β this runner β aiAgent.const { AiAgentService } = await import('@/server/services/aiAgent');@@ -129,11 +146,12 @@ export const createVerifierAgentRunner = (params: {...(extraPluginIds.length ? { additionalPluginIds: extraPluginIds } : {}),appContext: { threadId: thread.id, topicId },autoStart: true,+ ...(evidenceFileIds.length ? { fileIds: evidenceFileIds } : {}),// Only the builtin fallback inherits the parent run's model/provider; a// pinned agent keeps its own (critical for heterogeneous runtimes)....(inheritModel && model ? { model } : {}),parentOperationId: operationId,- prompt: buildVerifierPrompt({ checkItem, deliverable, goal, instruction }),+ prompt: buildVerifierPrompt({ checkItem, deliverable, evidence, goal, instruction }),...(inheritModel && provider ? { provider } : {}),...agentRef,userInterventionConfig: { approvalMode: 'headless' },diff --git a/apps/server/src/services/verify/executor.ts b/apps/server/src/services/verify/executor.tsindex fe47a340935..c6464db3ae6 100644--- a/apps/server/src/services/verify/executor.ts+++ b/apps/server/src/services/verify/executor.ts@@ -41,6 +41,8 @@ const log = debug('lobe-server:verify-executor');export interface VerifierAgentRunner {(args: {checkItem: VerifyCheckItem;+ /** Evidence the builder captured for this item β input to the verifier's judgment. */+ evidence?: JudgeEvidence[];goal: string;operationId: string;}): Promise<{ verifierOperationId: string } | null>;@@ -150,7 +152,9 @@ export class VerifyExecutorService {await Promise.all([this.runProgramItems(verifyRunId, programItems),this.runLlmItems(params, verifyRunId, llmItems, evidenceByItem),- ...agentItems.map((item) => this.runAgentItem(params, verifyRunId, item)),+ ...agentItems.map((item) =>+ this.runAgentItem(params, verifyRunId, item, evidenceByItem.get(item.id) ?? []),+ ),]);await this.statusService.recompute(params.operationId);@@ -162,7 +166,14 @@ export class VerifyExecutorService {const byItem: EvidenceByItem = new Map();for (const row of rows) {const list = byItem.get(row.checkItemId) ?? [];- list.push({ content: row.content, description: row.description, type: row.type });+ // Keep `fileId` so the agent verifier can attach the actual artifact (the+ // LLM judge ignores it and renders text only).+ list.push({+ content: row.content,+ description: row.description,+ fileId: row.fileId,+ type: row.type,+ });byItem.set(row.checkItemId, list);}return byItem;@@ -235,6 +246,7 @@ export class VerifyExecutorService {params: ExecuteVerifyParams,verifyRunId: string,item: VerifyCheckItem,+ evidence: JudgeEvidence[],): Promise<void> {if (!params.runVerifierAgent) {await this.resultModel.updateByCheckItem(verifyRunId, item.id, {@@ -247,6 +259,7 @@ export class VerifyExecutorService {try {const spawned = await params.runVerifierAgent({checkItem: item,+ evidence,goal: params.goal,operationId: params.operationId,});diff --git a/apps/server/src/services/verify/prompts.ts b/apps/server/src/services/verify/prompts.tsindex b76834d70bd..136368dc979 100644--- a/apps/server/src/services/verify/prompts.ts+++ b/apps/server/src/services/verify/prompts.ts@@ -52,6 +52,12 @@ export const buildPlanPrompt = ({export interface JudgeEvidence {content?: string | null;description?: string | null;+ /**+ * Stored artifact id (screenshot / video / large text). The text prompt only+ * references it by presence + caption; the agent verifier attaches the actual+ * file to its run via `execAgent({ fileIds })` so it can SEE the artifact.+ */+ fileId?: string | null;type: VerifyEvidenceType;}@@ -68,7 +74,7 @@ export interface JudgePromptInput {mode: 'single' | 'batch';}-const describeEvidence = (evidence: JudgeEvidence[] | undefined): string => {+export const describeEvidence = (evidence: JudgeEvidence[] | undefined): string => {if (!evidence?.length) return '';const lines = evidence.map((e) => {const caption = e.description ? ` β ${e.description}` : '';