-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathexperiment-agent-grouping.ts
More file actions
168 lines (147 loc) · 4.91 KB
/
Copy pathexperiment-agent-grouping.ts
File metadata and controls
168 lines (147 loc) · 4.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
import type { Task, Trial } from "@/lib/types";
const DEFAULT_EXPERIMENT_MODEL_KEY = "default";
const GEMINI_35_DISPLAY_AGENT = "gemini-cli";
const GEMINI_35_DISPLAY_MODEL = "gemini/gemini-3.5-flash";
const GEMINI_35_AGENT_ALIASES = new Set([
"gemini-cli",
"gemini-cli-api-key-no-search",
]);
const GEMINI_35_MODEL_ALIASES = new Set([
"gemini/gemini-3.5-flash",
"google/gemini-3.5-flash",
]);
export const PROBE_AGENT_KEY = "probe";
export type ExperimentAgentSummary = {
key: string;
label: string;
agent: string;
model: string | null;
queueKey: string | null;
isModelScoped: boolean;
};
// The "nop" baseline (no-op) makes no changes; the "oracle" baseline runs the
// known-good gold solution. Each may appear bare or with a suffix/prefix
// (`nop-foo`, `agent-oracle`), so match the family rather than the exact name.
export function isNopAgentName(name: string): boolean {
const lower = name.toLowerCase();
return (
lower === "nop" || lower.startsWith("nop-") || lower.startsWith("agent-nop")
);
}
export function isOracleAgentName(name: string): boolean {
const lower = name.toLowerCase();
return (
lower === "oracle" ||
lower.startsWith("oracle-") ||
lower.startsWith("agent-oracle")
);
}
// Baseline agents (nop / oracle) are deterministic validation runs, so they
// are excluded from score aggregation and row-filter evaluation.
export function isBaselineAgentName(name: string): boolean {
return isNopAgentName(name) || isOracleAgentName(name);
}
function getModelKey(model: string | null | undefined): string {
const trimmed = model?.trim();
return trimmed && trimmed.length > 0 ? trimmed : DEFAULT_EXPERIMENT_MODEL_KEY;
}
function getDisplayAgentModel(
trial: Pick<Trial, "agent" | "model">
): Pick<Trial, "agent" | "model"> {
const agent = trial.agent.trim().toLowerCase();
const model = trial.model?.trim().toLowerCase() ?? null;
// These historical labels represent the same Gemini CLI + Flash 3.5
// execution cohort. Canonicalize only the experiment display key; the
// underlying trial metadata and provenance remain unchanged.
if (
GEMINI_35_AGENT_ALIASES.has(agent) &&
model !== null &&
GEMINI_35_MODEL_ALIASES.has(model)
) {
return {
agent: GEMINI_35_DISPLAY_AGENT,
model: GEMINI_35_DISPLAY_MODEL,
};
}
return trial;
}
function getModelScopedAgents(tasks: Task[]): Set<string> {
const modelsByAgent = new Map<string, Set<string>>();
for (const task of tasks) {
for (const trial of task.trials ?? []) {
if (trial.is_probe) continue;
const display = getDisplayAgentModel(trial);
const existing = modelsByAgent.get(display.agent) ?? new Set<string>();
existing.add(getModelKey(display.model));
modelsByAgent.set(display.agent, existing);
}
}
return new Set(
Array.from(modelsByAgent.entries())
.filter(([, models]) => models.size > 1)
.map(([agent]) => agent)
);
}
// Recover the model-scoped agent set from already-built summaries, for
// consumers that hold summaries but not the tasks they were derived from.
export function getModelScopedAgentsFromSummaries(
summaries: readonly ExperimentAgentSummary[]
): Set<string> {
return new Set(
summaries
.filter((summary) => summary.isModelScoped)
.map((summary) => summary.agent)
);
}
export function getExperimentAgentKey(
trial: Pick<Trial, "agent" | "model" | "is_probe">,
modelScopedAgents: ReadonlySet<string>
): string {
if (trial.is_probe) {
return PROBE_AGENT_KEY;
}
const display = getDisplayAgentModel(trial);
if (!modelScopedAgents.has(display.agent)) {
return display.agent;
}
return `${display.agent}/${getModelKey(display.model)}`;
}
export function buildExperimentAgentSummaries(tasks: Task[]): {
agentSummaries: ExperimentAgentSummary[];
modelScopedAgents: Set<string>;
} {
const modelScopedAgents = getModelScopedAgents(tasks);
const summaries = new Map<string, ExperimentAgentSummary>();
for (const task of tasks) {
for (const trial of task.trials ?? []) {
const key = getExperimentAgentKey(trial, modelScopedAgents);
if (summaries.has(key)) continue;
if (trial.is_probe) {
summaries.set(key, {
key: PROBE_AGENT_KEY,
label: "probe",
agent: PROBE_AGENT_KEY,
model: null,
queueKey: null,
isModelScoped: false,
});
continue;
}
const display = getDisplayAgentModel(trial);
summaries.set(key, {
key,
label: key,
agent: display.agent,
model: display.model,
queueKey: trial.provider ?? null,
isModelScoped: modelScopedAgents.has(display.agent),
});
}
}
const ordered = Array.from(summaries.values());
const probeIndex = ordered.findIndex((s) => s.key === PROBE_AGENT_KEY);
if (probeIndex >= 0) {
ordered.push(ordered.splice(probeIndex, 1)[0]);
}
return { agentSummaries: ordered, modelScopedAgents };
}