MCPcopy Create free account
hub / github.com/braintrustdata/bash-agent-evals / Factuality

Function Factuality

evals/shared.ts:81–112  ·  view source on GitHub ↗
(args: {
  input: string;
  output: string;
  expected?: string;
})

Source from the content-addressed store, hash-verified

79
80// Wrapper that retries the Factuality scorer on failure
81export const Factuality = async (args: {
82 input: string;
83 output: string;
84 expected?: string;
85}): Promise<{ name: string; score: number | null; metadata?: Record<string, unknown> }> => {
86 let lastError: Error | null = null;
87
88 for (let attempt = 1; attempt <= MAX_SCORER_RETRIES; attempt++) {
89 try {
90 const result = await FactualityBaseScorer({ ...args, maxTokens: 10_000 });
91 // If score is null, treat as failure and retry
92 if (result.score === null) {
93 lastError = new Error('Scorer returned null score');
94 continue;
95 }
96 return result;
97 } catch (error) {
98 lastError = error instanceof Error ? error : new Error(String(error));
99 // Continue to next attempt
100 }
101 }
102
103 // All retries exhausted - return error result
104 return {
105 name: 'Factuality',
106 score: null,
107 metadata: {
108 error: lastError?.message || 'Unknown error after retries',
109 retries: MAX_SCORER_RETRIES,
110 },
111 };
112};
113
114import { runAgentInWorker } from '../src/agents/run-in-worker.js';
115import { defaultErrorScoreHandler, type Span } from 'braintrust';

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected