Skip to content

The fastest, cheapest, most efficient open-source agent harness. Run more than 500 agents on a $10 VPS.

feat(bench): add meter-proxy harness for capturing proxy metrics

Steven Enamakel7a8a2ca13d73
diff --git a/bench/harnesses/meter-proxy/capture.mjs b/bench/harnesses/meter-proxy/capture.mjs
index 863fc48e07..77ad841632 100644
--- a/bench/harnesses/meter-proxy/capture.mjs
+++ b/bench/harnesses/meter-proxy/capture.mjs
@@ -29,6 +29,14 @@ export const sha = (value) =>
const safe = (s) => String(s).replace(/[^A-Za-z0-9._#@=-]/g, "_");
+/**
+ * Which conversation a call continues: the tool list is the stable identity of an agent loop.
+ * Side requests (a title generator has no tools) and sub-agents (their own tools) get a different
+ * lineage from the main agent, so a call is compared with the previous call of its own lineage
+ * and an interleaved side request cannot make the main agent look as if it rewrote its prompt.
+ */
+export const lineageOf = (body) => (Array.isArray(body.tools) && body.tools.length ? sha(body.tools) : "no-tools");
+
function conversationOf(format, body) {
if (format === FORMATS.CHAT) {
return (body.messages ?? []).filter(
diff --git a/bench/harnesses/meter-proxy/proxy.mjs b/bench/harnesses/meter-proxy/proxy.mjs
index aabe54cc69..5768d0d149 100644
--- a/bench/harnesses/meter-proxy/proxy.mjs
+++ b/bench/harnesses/meter-proxy/proxy.mjs
@@ -27,7 +27,7 @@ import path from "node:path";
import { pathToFileURL } from "node:url";
import { forwardHeaders } from "./headers.mjs";
import zlib from "node:zlib";
-import { buildCapture, capResponse, writeCapture } from "./capture.mjs";
+import { buildCapture, capResponse, lineageOf, writeCapture } from "./capture.mjs";
import { computeCost, fetchPricing } from "./pricing.mjs";
import {
FORMATS,
@@ -167,7 +167,7 @@ export function createProxy(opts) {
if (parsed) {
const sizes = promptSizes(format, parsed);
if (captureRoot) {
- const key = `${tag.run_id}/${tag.harness}/${tag.task}`;
+ const key = `${tag.run_id}/${tag.harness}/${tag.task}/${lineageOf(parsed)}`;
built = buildCapture({
format,
body: parsed,
@@ -186,6 +186,8 @@ export function createProxy(opts) {
model,
reasoning_effort: effort,
provider_pinned: provider,
+ // system prompt + tool list: lets the report tell the main agent from side requests and sub-agents
+ context: built ? `${built.state.systemSha}.${built.state.toolsSha}` : undefined,
overridden: rewritten.overridden,
stream: parsed.stream === true,
messages: Array.isArray(parsed.messages)
diff --git a/bench/harnesses/report.mjs b/bench/harnesses/report.mjs
index 01a60ec0ac..e234870525 100644
--- a/bench/harnesses/report.mjs
+++ b/bench/harnesses/report.mjs
@@ -35,13 +35,16 @@ const mean = (xs) => {
* request (OpenCode's title generator), which would otherwise read as "no tools".
*/
export function mainRequest(calls, taskKey) {
- const size = (r) => (r.system_prompt_tokens ?? 0) + (r.tool_schema_tokens ?? 0);
- let best = null;
- for (const r of calls) {
- if (r.task !== taskKey || r.system_prompt_tokens == null) continue;
- if (best === null || size(r) > size(best)) best = r;
- }
- return best;
+ const { main, contexts } = classify(calls.filter((r) => r.task === taskKey));
+ return contexts.get(main)?.calls.find((r) => r.system_prompt_tokens != null) ?? null;
+}
+
+/** Calls of a harness that are not its main agent: side requests and sub-agents, per task. */
+function sideCalls(calls, taskKeys) {
+ return taskKeys.flatMap((t) => {
+ const { main, contexts } = classify(calls.filter((r) => r.task === t));
+ return [...contexts.values()].filter((c) => c.id !== main).flatMap((c) => c.calls);
+ });
}
export function aggregate(meter, tasks) {
@@ -63,7 +66,9 @@ export function aggregate(meter, tasks) {
const prompt = sum(ok.map((r) => r.prompt_tokens));
const cached = sum(ok.map((r) => r.cached_tokens));
const cost = sum(calls.map((r) => r.cost_usd));
- const unpriced = calls.filter((r) => r.cost_usd == null).length;
+ // A failed request is not billed, so only successful calls with no cost are "unpriced".
+ const unpriced = ok.filter((r) => r.cost_usd == null).length;
+ const side = sideCalls(calls, mine.map((t) => t.task_key));
const passed = mine.filter((t) => t.result?.check?.passed).length;
const resolved = mine.filter((t) => t.grade?.resolved).length;
@@ -122,11 +127,16 @@ export function aggregate(meter, tasks) {
firstCalls.map((r) => (r.system_prompt_tokens ?? 0) + (r.tool_schema_tokens ?? 0)),
50,
),
+ tokens_total: sum(calls.map((r) => (r.prompt_tokens ?? 0) + (r.completion_tokens ?? 0))),
prompt_tokens: prompt,
completion_tokens: sum(ok.map((r) => r.completion_tokens)),
cache_pct: prompt ? (100 * cached) / prompt : null,
cost_usd: cost,
cost_unpriced_calls: unpriced,
+ side_calls: side.length,
+ side_tokens: sum(side.map((r) => (r.prompt_tokens ?? 0) + (r.completion_tokens ?? 0))),
+ side_cost_usd: sum(side.map((r) => r.cost_usd)),
+ side_failed_calls: side.filter((r) => !(r.status >= 200 && r.status < 300)).length,
cost_per_task_usd: mine.length ? cost / mine.length : null,
cost_per_resolved_usd: resolved ? cost / resolved : null,
ttft_ms_p50: percentile(ok.map((r) => r.first_token_ms), 50),
@@ -153,6 +163,7 @@ export function aggregate(meter, tasks) {
return out;
}
+import { classify } from "./contexts.mjs";
import { count, mem, ms, orderHarnesses, pct, secs, usd } from "./format.mjs";
const f = (v, d = 0) => (v === null || v === undefined ? "-" : Number(v).toFixed(d));
@@ -198,6 +209,8 @@ export function toMarkdown(meta, summary) {
["peak RAM, process memory (solved tasks)", (s) => mem(s.solved_peak_anon_mb_max), (s) => s.solved_peak_anon_mb_max, "low"],
["peak RAM incl. page cache (all tasks)", (s) => mem(s.peak_mem_mb_max), (s) => s.peak_mem_mb_max, "low"],
["avg RAM (all tasks)", (s) => mem(s.avg_mem_mb_mean), (s) => s.avg_mem_mb_mean, "low"],
+ ["side / sub-agent calls (failed)", (s) => `${count(s.side_calls)} of ${count(s.llm_calls)} (${count(s.side_failed_calls)})`],
+ ["side / sub-agent share of tokens", (s) => pct(s.tokens_total ? (100 * s.side_tokens) / s.tokens_total : null)],
["LLM calls (errors)", (s) => `${count(s.llm_calls)} (${count(s.llm_call_errors)})`],
["prompt / completion tokens", (s) => `${count(s.prompt_tokens)} / ${count(s.completion_tokens)}`],
];