Skip to content

Commit c00383e

Browse files
authored
docs(examples): intelligence-coding-bench — instrument the webcode benchmark with the full Intelligence SDK (#418)
Imports the EXACT webcode-matrix grid + tasks and wraps every harness×model cell in all three Tangle Intelligence layers: 1. withTangleIntelligence — the billing boundary + effort tiers ('off' = provable passthrough floor) 2. createWaterfallCollector — the per-tool cost waterfall (sum of spans IS the billed cost) 3. createOtelExporter + loopEventToOtelSpan — stream spans to an OTLP/HTTP collector - new examples/intelligence-coding-bench/{intelligence-coding-bench.ts,README.md} - webcode-matrix exports its grid + tasks + WebCodeTask so the example reuses the same benchmark - bidirectional README links (main showcase row + webcode-matrix back-link)
1 parent 8089ea1 commit c00383e

5 files changed

Lines changed: 203 additions & 4 deletions

File tree

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,11 @@ Runnable, grouped by what they show — copy the one nearest your task:
7979
| Drive a team of agents to a goal | [`supervise`](./examples/supervise) · [`recursive-supervisor`](./examples/recursive-supervisor) |
8080
| Benchmark strategies on your own domain | [`coding-benchmark`](./examples/coding-benchmark) |
8181
| Benchmark **harnesses × models** over a real task suite | [`webcode-matrix`](./examples/webcode-matrix) |
82+
| Trace + bill + effort-gate a coding benchmark (the Intelligence SDK) | [`intelligence-coding-bench`](./examples/intelligence-coding-bench) |
8283
| Self-improve an agent, gated on a held-out set | [`improve`](./examples/improve) · [`self-improving-coder`](./examples/self-improving-coder) |
8384
| Study coordination vs raw compute | [`ablation-suite`](./examples/ablation-suite) |
8485

85-
All 27 live in [`examples/`](./examples).
86+
All 28 live in [`examples/`](./examples).
8687

8788
## Where to go next
8889

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# intelligence-coding-bench
2+
3+
The [WebCode harness×model coding benchmark](../webcode-matrix) — every cell wrapped in the **full Tangle Intelligence SDK**. Same grid, same hidden-test-graded tasks; this file adds nothing but the instrumentation, so per harness×model you see: **did it pass, what it cost, where the cost went, and the exported trace.**
4+
5+
## The three layers (all on one cell)
6+
7+
| Layer | Primitive | What it gives you |
8+
|---|---|---|
9+
| **1 · Boundary** | `withTangleIntelligence(cell, { project, effort })` | The bill + the control. `effort ∈ off · eco · standard · thorough · max`; **`'off'` is the provable passthrough floor** — intelligence spend clamped to 0, the cell still runs. |
10+
| **2 · Waterfall** | `createWaterfallCollector()` on the run | The cost truth, per tool/phase. The **sum of its spans IS the billed run cost** — no separate tally to drift. |
11+
| **3 · OTLP** | `createOtelExporter()` + `loopEventToOtelSpan` | The production trace pipe. Streams every span to your OTLP/HTTP collector; a no-op until `OTEL_EXPORTER_OTLP_ENDPOINT` is set. |
12+
13+
The intelligence attaches at **two seams**: the boundary wraps the whole cell (`withTangleIntelligence` works over any async function), and the internal trace rides `openSandboxRun`'s `hooks` (the one run-verb here that emits per-tool spans). The same pattern instruments a `runProfileMatrix` dispatch wholesale.
14+
15+
## Run
16+
17+
```bash
18+
TANGLE_API_KEY=… SANDBOX_API_KEY=… EXA_API_KEY=… [EFFORT=standard] [OTEL_EXPORTER_OTLP_ENDPOINT=…] \
19+
tsx examples/intelligence-coding-bench/intelligence-coding-bench.ts
20+
```
21+
22+
Prove the floor: run once with `EFFORT=standard`, once with `EFFORT=off` — same passes, zero intelligence spend on the second.
23+
24+
## Relationship to webcode-matrix
25+
26+
[`../webcode-matrix`](../webcode-matrix) is the **benchmark** — the harness×model × WebCode-task grid, graded by hidden tests, scored with paired stats. This example **imports that exact grid and task set** and answers a different question: not "which harness wins" but "what does each run cost, and what did it do" — the observability + billing view of the same benchmark.
Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,168 @@
1+
/**
2+
* intelligence-coding-bench — the WebCode harness×model coding benchmark (see ../webcode-matrix),
3+
* instrumented with the FULL Tangle Intelligence SDK. It reuses the EXACT benchmark next door — the same
4+
* harness×model grid and the same post-Aug-2025 WebCode tasks graded by hidden tests — and adds nothing
5+
* but the intelligence wiring. Per harness×model you get: did it pass, what it cost, the per-tool
6+
* waterfall, and the spans streamed to your trace collector.
7+
*
8+
* Three intelligence layers, all on one cell:
9+
* 1. BOUNDARY (the bill + the control) — `withTangleIntelligence(cell, { project, effort })`.
10+
* `effort ∈ off | eco | standard | thorough | max`; `'off'` is the PROVABLE passthrough floor —
11+
* intelligence spend clamped to 0, the cell still runs. This is the one knob that gates spend.
12+
* 2. WATERFALL (the cost truth) — `createWaterfallCollector()` on the run. The sum of its spans IS the
13+
* billed run cost, per tool/phase — no separate tally to drift.
14+
* 3. OTLP (the production trace pipe) — `createOtelExporter()` + `loopEventToOtelSpan`. Streams every
15+
* span to your OTLP/HTTP collector (set `OTEL_EXPORTER_OTLP_ENDPOINT`); a no-op when unset.
16+
*
17+
* The intelligence attaches at TWO seams: the BOUNDARY wraps the whole cell (`withTangleIntelligence`
18+
* works over any async fn), and the INTERNAL trace rides `openSandboxRun`'s `hooks` (the only run verb
19+
* here that emits per-tool spans). Same pattern instruments `runProfileMatrix`'s dispatch wholesale.
20+
*
21+
* Run:
22+
* TANGLE_API_KEY=… SANDBOX_API_KEY=… EXA_API_KEY=… [EFFORT=standard] [OTEL_EXPORTER_OTLP_ENDPOINT=…] \
23+
* tsx examples/intelligence-coding-bench/intelligence-coding-bench.ts
24+
*/
25+
26+
import type { AgentProfile } from '@tangle-network/agent-interface'
27+
import {
28+
composeRuntimeHooks,
29+
createOtelExporter,
30+
loopEventToOtelSpan,
31+
type RuntimeHooks,
32+
} from '@tangle-network/agent-runtime'
33+
import { type EffortTier, withTangleIntelligence } from '@tangle-network/agent-runtime/intelligence'
34+
import {
35+
type AgentRunSpec,
36+
createWaterfallCollector,
37+
openSandboxRun,
38+
type SandboxClient,
39+
} from '@tangle-network/agent-runtime/loops'
40+
import type { BackendType } from '@tangle-network/sandbox'
41+
import {
42+
type WebCodeTask,
43+
profiles as webcodeGrid,
44+
tasks as webcodeTasks,
45+
} from '../webcode-matrix/webcode-matrix'
46+
47+
const routerBaseUrl = process.env.ROUTER_BASE_URL ?? 'https://router.tangle.tools/v1'
48+
const effort = (process.env.EFFORT ?? 'standard') as EffortTier
49+
const project = process.env.TANGLE_PROJECT ?? 'webcode-bench'
50+
51+
interface CellInput {
52+
profile: AgentProfile
53+
task: WebCodeTask
54+
}
55+
interface CellResult {
56+
passed: boolean
57+
usd: number
58+
ms: number
59+
waterfall: string
60+
}
61+
62+
/** One instrumented cell: run a harness×model on a WebCode task in its own sandbox with the INTERNAL trace
63+
* collected (cost waterfall) AND streamed (OTLP), then score on the hidden tests. Wrapping this in
64+
* `withTangleIntelligence` (below) adds the BOUNDARY layer. */
65+
function instrumentedCell(client: SandboxClient): (input: CellInput) => Promise<CellResult> {
66+
return async ({ profile, task }) => {
67+
const harness = String(profile.metadata?.harness ?? 'opencode')
68+
const model = String(profile.metadata?.model ?? '')
69+
70+
// LAYER 2 + 3 — the INTERNAL trace: the per-tool waterfall (cost) AND OTLP spans, both as run hooks.
71+
const waterfall = createWaterfallCollector()
72+
const otel = createOtelExporter() // undefined unless OTEL_EXPORTER_OTLP_ENDPOINT (or config) is set
73+
const otelHook: RuntimeHooks = otel
74+
? {
75+
onEvent: (e) => {
76+
otel.exportSpan(
77+
loopEventToOtelSpan(
78+
{
79+
kind: e.target,
80+
runId: e.runId,
81+
timestamp: e.timestamp,
82+
payload: (e.payload ?? {}) as object,
83+
},
84+
e.runId,
85+
),
86+
)
87+
},
88+
}
89+
: {}
90+
91+
const agentRun: AgentRunSpec<string> = {
92+
profile,
93+
name: profile.name ?? harness,
94+
taskToPrompt: (t) => t,
95+
sandboxOverrides: {
96+
// Only the WebCode search creds — never router/model credentials into the box.
97+
env: {
98+
TANGLE_SEARCH_DEFAULT_PROVIDER: 'exa',
99+
...(process.env.EXA_API_KEY ? { EXA_API_KEY: process.env.EXA_API_KEY } : {}),
100+
},
101+
backend: {
102+
type: harness as BackendType,
103+
model: { provider: 'openai-compat', model, baseUrl: routerBaseUrl },
104+
},
105+
},
106+
}
107+
108+
const run = await openSandboxRun<{ passed: boolean }>(
109+
client,
110+
{
111+
agentRun,
112+
scenarioId: task.id,
113+
signal: new AbortController().signal,
114+
hooks: composeRuntimeHooks(waterfall.hooks, otelHook),
115+
},
116+
{ kind: 'events', fromEvents: () => ({ passed: false }) },
117+
)
118+
await run.start(task.prompt)
119+
const res = await run.box.exec?.(task.testCmd)
120+
await otel?.flush()
121+
122+
const report = waterfall.report()
123+
return {
124+
passed: (res?.exitCode ?? 1) === 0,
125+
usd: report.totalUsd,
126+
ms: report.totalMs,
127+
waterfall: waterfall.render({ maxRows: 8 }),
128+
}
129+
}
130+
}
131+
132+
/** Run the WebCode grid × tasks with the full intelligence stack on every cell. */
133+
export async function runIntelligenceCodingBench(client: SandboxClient): Promise<void> {
134+
// LAYER 1 — the BOUNDARY: every cell runs under `withTangleIntelligence` — traced + billed, effort-gated.
135+
// `effort: 'off'` clamps intelligence spend to 0 (the provable passthrough floor) while still running.
136+
const smartCell = withTangleIntelligence(instrumentedCell(client), { project, effort })
137+
138+
console.log(`intelligence-coding-bench · effort=${effort} · project=${project}`)
139+
console.log(`${'harness·model'.padEnd(30)}${'task'.padEnd(14)}result cost wall\n`)
140+
let shownWaterfall = false
141+
for (const profile of webcodeGrid) {
142+
for (const task of webcodeTasks) {
143+
const r = await smartCell({ profile, task })
144+
console.log(
145+
`${(profile.name ?? '').padEnd(30)}${task.id.padEnd(14)}${r.passed ? 'PASS' : 'fail'} $${r.usd.toFixed(4)} ${(r.ms / 1000).toFixed(1)}s`,
146+
)
147+
// Show the per-tool cost waterfall (layer 2) once — the same spans the $ column sums.
148+
if (!shownWaterfall) {
149+
console.log(`\n — per-tool cost waterfall (layer 2), one cell —\n${r.waterfall}\n`)
150+
shownWaterfall = true
151+
}
152+
}
153+
}
154+
}
155+
156+
// Run it live — mirrors ../webcode-matrix's client wiring.
157+
if (import.meta.url === `file://${process.argv[1]}`) {
158+
const { SandboxClient } = (await import('@tangle-network/sandbox')) as {
159+
SandboxClient: new (o: { apiKey: string; baseUrl: string }) => SandboxClient
160+
}
161+
const apiKey = process.env.SANDBOX_API_KEY
162+
if (!apiKey) throw new Error('SANDBOX_API_KEY required')
163+
const client = new SandboxClient({
164+
apiKey,
165+
baseUrl: process.env.SANDBOX_BASE_URL ?? 'https://sandbox.tangle.tools',
166+
})
167+
await runIntelligenceCodingBench(client)
168+
}

examples/webcode-matrix/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,7 @@ Prints the per-(harness×model) pass rate over the tasks. Edit `grid` to change
1919
## Why it's interesting
2020

2121
WebCode isolates one thing: can an agent retrieve and apply knowledge it was never trained on? The matrix answers *which harness+model does it best* — the harness controls how the agent searches and iterates, the model controls how well it reasons over what it finds, and the hidden tests keep everyone honest.
22+
23+
## Instrument it with the Intelligence SDK
24+
25+
Want the cost, the per-tool waterfall, and the exported trace for each cell — and an effort knob that gates spend? [`intelligence-coding-bench`](../intelligence-coding-bench) imports this exact grid + task set and wraps every cell in the full Tangle Intelligence stack (`withTangleIntelligence` + `createWaterfallCollector` + `createOtelExporter`).

examples/webcode-matrix/webcode-matrix.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ const grid = [
3636
{ harness: 'gemini', model: 'google/gemini-2.5-pro-2025-06-17' },
3737
] as const
3838

39-
const profiles: AgentProfile[] = grid.map(({ harness, model }) => ({
39+
export const profiles: AgentProfile[] = grid.map(({ harness, model }) => ({
4040
name: `${harness}·${model.split('/')[1]}`,
4141
// AgentProfile has no `harness` field — the harness is a SANDBOX backend, carried on metadata so the
4242
// dispatch can read it back. The model rides the standard `model.default`.
@@ -48,13 +48,13 @@ const profiles: AgentProfile[] = grid.map(({ harness, model }) => ({
4848

4949
// ── Axis 2 — the WebCode TASKS. Each is a prompt + the repo + the hidden test command (the grader).
5050
// Three representative tasks shown; the full 33-task dataset loads the same shape.
51-
interface WebCodeTask extends Scenario {
51+
export interface WebCodeTask extends Scenario {
5252
prompt: string
5353
lang: string
5454
repo: string
5555
testCmd: string
5656
}
57-
const tasks: WebCodeTask[] = [
57+
export const tasks: WebCodeTask[] = [
5858
{
5959
id: 'go-fiber-v3',
6060
kind: 'webcode',

0 commit comments

Comments
 (0)