Skip to content

Commit 84530a0

Browse files
fix: default parameters
1 parent 03abcc4 commit 84530a0

2 files changed

Lines changed: 45 additions & 46 deletions

File tree

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ The Braintrust eval suite (found in `tests/eval/`) evaluates how well an LLM, wh
121121
#### Notable Environment Variables
122122

123123
- `BRAINTRUST_API_KEY`: Required for all eval runs.
124-
- `EVAL_CONNECTION_STRING`: Overrides the MongoDB connection string (defaults to `mongodb://localhost:27017/?directConnection=true`).
124+
- `BT_EVAL_PARAMS_JSON`: JSON string of parameters to override the default parameters for the eval.
125125
- `EVAL_BASE_EXPERIMENT_NAME`: Lets you compare the current run against a specific baseline experiment. In CI, this is set automatically from the latest `main-<number>` run.
126126

127127
### Running in CI

tests/eval/mongodb.eval.ts

Lines changed: 44 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -15,72 +15,61 @@ import { GetReferenceAnswerTool } from "./lib/tool/getReferenceAnswer.js";
1515
const PROJECT_NAME = "mongodb-mcp-server-evals";
1616
const DATASET_NAME = "Search";
1717
const AGENT_STEP_LIMIT = 10;
18-
const DEFAULT_MODEL = "gpt-5";
19-
const DEFAULT_JUDGE_MODEL = "us.anthropic.claude-sonnet-4-6";
20-
const DEFAULT_CONNECTION_STRING = "mongodb://localhost:27017/?directConnection=true";
2118

22-
const DEFAULT_SYSTEM_CONTEXT =
23-
'You are a MongoDB assistant operating autonomously in a single turn; the user cannot answer follow-up questions. Use the available MongoDB MCP tools to fulfill the request end-to-end. Never ask for clarification; make a reasonable decision and finish the task. If the request refers to "the collection" without naming it, discover collections with the list tools and act on the appropriate one (if there is exactly one user collection, use it). Prefer tools over guessing, and briefly confirm what you did when done.';
19+
const staticDefaultParameters = {
20+
connectionString: "mongodb://localhost:27017/?directConnection=true",
21+
model: "gpt-5",
22+
judgeModel: "us.anthropic.claude-sonnet-4-6",
23+
systemContext: `You are a MongoDB assistant operating autonomously in a single turn;
24+
the user cannot answer follow-up questions.
25+
Use the available MongoDB MCP tools to fulfill the request end-to-end.
26+
Never ask for clarification; make a reasonable decision and finish the task.
27+
If the request refers to "the collection" without naming it,
28+
discover collections with the list tools and act on the appropriate one
29+
(if there is exactly one user collection, use it).
30+
Prefer tools over guessing, and briefly confirm what you did when done.`,
31+
validateReferenceAnswer: false,
32+
};
33+
34+
const defaultParameters = {
35+
...staticDefaultParameters,
36+
...(process.env.BT_EVAL_PARAMS_JSON
37+
? (JSON.parse(process.env.BT_EVAL_PARAMS_JSON) as typeof staticDefaultParameters)
38+
: {}),
39+
};
2440

2541
const parameters = {
26-
connectionString: z.string().default(DEFAULT_CONNECTION_STRING).describe("MongoDB connection string."),
42+
connectionString: z.string().default(defaultParameters.connectionString).describe("MongoDB connection string."),
2743
model: {
2844
type: "model" as const,
29-
default: DEFAULT_MODEL,
45+
default: defaultParameters.model,
3046
description: "Model used by the agent under test.",
3147
},
3248
judgeModel: {
3349
type: "model" as const,
34-
default: DEFAULT_JUDGE_MODEL,
50+
default: defaultParameters.judgeModel,
3551
description: "Model used by the judge.",
3652
},
3753
systemContext: z
3854
.string()
39-
.default(DEFAULT_SYSTEM_CONTEXT)
55+
.default(defaultParameters.systemContext)
4056
.describe("System prompt prepended for the agent under test."),
57+
validateReferenceAnswer: z
58+
.boolean()
59+
.default(defaultParameters.validateReferenceAnswer)
60+
.describe(
61+
"Uses `input.reference_answer` as the prompt instead of `input.prompt`; helpful for validating judge criteria against the reference answer."
62+
),
4163
} as unknown as EvalParameters;
4264

4365
type ResolvedParameters = {
4466
connectionString: string;
4567
model: string;
4668
judgeModel: string;
4769
systemContext: string;
70+
validateReferenceAnswer: boolean;
4871
};
4972

50-
function parseEnvParams(): Record<string, unknown> {
51-
const raw = process.env.BT_EVAL_PARAMS_JSON;
52-
if (!raw) return {};
53-
try {
54-
return JSON.parse(raw) as Record<string, unknown>;
55-
} catch (error) {
56-
console.warn("Failed to parse BT_EVAL_PARAMS_JSON:", error);
57-
return {};
58-
}
59-
}
60-
61-
function stringParam(value: unknown, fallback: string): string {
62-
return typeof value === "string" && value.trim() ? value.trim() : fallback;
63-
}
64-
65-
/**
66-
* Ensures parameter resolution works across all eval modes:
67-
* - Braintrust CLI ('bt'): supports 'BT_EVAL_PARAMS_JSON'
68-
* - Braintrust script ('braintrust') and tsx: do not support 'BT_EVAL_PARAMS_JSON'
69-
* Always resolve parameters so eval runs correctly regardless of entry point.
70-
*/
71-
function resolveParameters(hooksParameters: Record<string, unknown>): ResolvedParameters {
72-
const envParams = parseEnvParams();
73-
const connectionString = stringParam(
74-
hooksParameters.connectionString ?? envParams.connectionString ?? process.env.EVAL_CONNECTION_STRING,
75-
DEFAULT_CONNECTION_STRING
76-
);
77-
const model = stringParam(hooksParameters.model ?? envParams.model, DEFAULT_MODEL);
78-
const judgeModel = stringParam(hooksParameters.judgeModel ?? envParams.judgeModel, DEFAULT_JUDGE_MODEL);
79-
const systemContext = stringParam(hooksParameters.systemContext ?? envParams.systemContext, DEFAULT_SYSTEM_CONTEXT);
80-
81-
return { connectionString, model, judgeModel, systemContext };
82-
}
83-
8473
/**
8574
* Generates a unique but shorter name for the transient database.
8675
*
@@ -121,7 +110,7 @@ void Eval<RunEvalInput, RunEvalOutput, RunEvalExpected, void, boolean, EvalParam
121110
}),
122111
task: async (input, hooks) => {
123112
const aiProvider = await shared.getAiProvider();
124-
const resolved = resolveParameters(hooks.parameters as Record<string, unknown>);
113+
const resolved = hooks.parameters as ResolvedParameters;
125114
shared.registerConnectionString(resolved.connectionString);
126115

127116
const model = aiProvider.chat(resolved.model);
@@ -139,11 +128,21 @@ void Eval<RunEvalInput, RunEvalOutput, RunEvalExpected, void, boolean, EvalParam
139128

140129
const tools = await mcpClient.tools();
141130

131+
let prompt: string;
132+
if (resolved.validateReferenceAnswer) {
133+
if (!hooks.expected?.reference_answer) {
134+
throw new Error("No reference answer provided in the eval case");
135+
}
136+
prompt = `Run the reference answer: ${hooks.expected.reference_answer}`;
137+
} else {
138+
prompt = input.prompt;
139+
}
140+
142141
const { response, messages } = await runTask({
143142
model,
144143
systemContext: resolved.systemContext,
145144
tools,
146-
prompt: input.prompt,
145+
prompt,
147146
tempDbName: dbName,
148147
stepLimit: AGENT_STEP_LIMIT,
149148
});

0 commit comments

Comments
 (0)