@tangle-network/agent-bench 0.14.2 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (218) hide show
  1. package/CHANGELOG.md +48 -0
  2. package/README.md +2 -3
  3. package/dist/adapters.d.ts +2 -5
  4. package/dist/adapters.js +3 -4
  5. package/dist/benchmarks/_harness.d.ts +17 -20
  6. package/dist/benchmarks/_harness.js +4 -4
  7. package/dist/benchmarks/_harness.js.map +1 -1
  8. package/dist/benchmarks/aec-bench.d.ts +1 -4
  9. package/dist/benchmarks/aec-bench.js +1 -2
  10. package/dist/benchmarks/agentbench.d.ts +2 -5
  11. package/dist/benchmarks/agentbench.js +1 -2
  12. package/dist/benchmarks/appworld.d.ts +8 -10
  13. package/dist/benchmarks/appworld.js +23 -23
  14. package/dist/benchmarks/appworld.js.map +1 -1
  15. package/dist/benchmarks/bfcl.d.ts +2 -5
  16. package/dist/benchmarks/bfcl.js +1 -2
  17. package/dist/benchmarks/cad-design.d.ts +2 -5
  18. package/dist/benchmarks/cad-design.js +2 -3
  19. package/dist/benchmarks/cad-design.js.map +1 -1
  20. package/dist/benchmarks/cadbench.d.ts +1 -4
  21. package/dist/benchmarks/cadbench.js +1 -2
  22. package/dist/benchmarks/cadgenbench.d.ts +1 -4
  23. package/dist/benchmarks/cadgenbench.js +1 -2
  24. package/dist/benchmarks/commit0.d.ts +2 -5
  25. package/dist/benchmarks/commit0.js +1 -2
  26. package/dist/benchmarks/crag.d.ts +1 -4
  27. package/dist/benchmarks/crag.js +3 -3
  28. package/dist/benchmarks/crag.js.map +1 -1
  29. package/dist/benchmarks/dabstep.d.ts +2 -5
  30. package/dist/benchmarks/dabstep.js +2 -3
  31. package/dist/benchmarks/dabstep.js.map +1 -1
  32. package/dist/benchmarks/enterpriseops-gym.d.ts +2 -5
  33. package/dist/benchmarks/enterpriseops-gym.js +1 -2
  34. package/dist/benchmarks/finresearchbench.d.ts +2 -5
  35. package/dist/benchmarks/finresearchbench.js +2 -3
  36. package/dist/benchmarks/finsearchcomp.d.ts +2 -5
  37. package/dist/benchmarks/finsearchcomp.js +4 -4
  38. package/dist/benchmarks/finsearchcomp.js.map +1 -1
  39. package/dist/benchmarks/frames.d.ts +3 -19
  40. package/dist/benchmarks/frames.js +13 -39
  41. package/dist/benchmarks/frames.js.map +1 -1
  42. package/dist/benchmarks/hotpotqa.d.ts +4 -14
  43. package/dist/benchmarks/hotpotqa.js +12 -32
  44. package/dist/benchmarks/hotpotqa.js.map +1 -1
  45. package/dist/benchmarks/humaneval.d.ts +9 -12
  46. package/dist/benchmarks/humaneval.js +2 -3
  47. package/dist/benchmarks/humaneval.js.map +1 -1
  48. package/dist/benchmarks/mcad-bench.d.ts +13 -16
  49. package/dist/benchmarks/mcad-bench.js +2 -3
  50. package/dist/benchmarks/mcad-bench.js.map +1 -1
  51. package/dist/benchmarks/mcad-cq-bench.d.ts +17 -20
  52. package/dist/benchmarks/mcad-cq-bench.js +2 -3
  53. package/dist/benchmarks/mcad-cq-bench.js.map +1 -1
  54. package/dist/benchmarks/mcad-cq-golds.d.ts +2 -5
  55. package/dist/benchmarks/mcad-cq-golds.js +1 -2
  56. package/dist/benchmarks/mcad-golds.d.ts +1 -4
  57. package/dist/benchmarks/mcad-golds.js +0 -1
  58. package/dist/benchmarks/mcad-tasks.d.ts +5 -8
  59. package/dist/benchmarks/mcad-tasks.js +7 -8
  60. package/dist/benchmarks/mcad-tasks.js.map +1 -1
  61. package/dist/benchmarks/mind2web.d.ts +3 -5
  62. package/dist/benchmarks/mind2web.js +2 -3
  63. package/dist/benchmarks/mind2web.js.map +1 -1
  64. package/dist/benchmarks/nomiracl.d.ts +1 -4
  65. package/dist/benchmarks/nomiracl.js +1 -2
  66. package/dist/benchmarks/open-rag-bench.d.ts +1 -4
  67. package/dist/benchmarks/open-rag-bench.js +3 -3
  68. package/dist/benchmarks/open-rag-bench.js.map +1 -1
  69. package/dist/benchmarks/programbench.d.ts +2 -5
  70. package/dist/benchmarks/programbench.js +1 -2
  71. package/dist/benchmarks/rag-shared.d.ts +30 -22
  72. package/dist/benchmarks/rag-shared.js +8 -2
  73. package/dist/benchmarks/rag-shared.js.map +1 -1
  74. package/dist/benchmarks/ragbench.d.ts +1 -4
  75. package/dist/benchmarks/ragbench.js +3 -3
  76. package/dist/benchmarks/ragbench.js.map +1 -1
  77. package/dist/benchmarks/simpleqa.d.ts +2 -18
  78. package/dist/benchmarks/simpleqa.js +5 -31
  79. package/dist/benchmarks/simpleqa.js.map +1 -1
  80. package/dist/benchmarks/swe-bench.d.ts +7 -10
  81. package/dist/benchmarks/swe-bench.js +4 -4
  82. package/dist/benchmarks/swe-bench.js.map +1 -1
  83. package/dist/benchmarks/t2-ragbench.d.ts +1 -4
  84. package/dist/benchmarks/t2-ragbench.js +3 -3
  85. package/dist/benchmarks/t2-ragbench.js.map +1 -1
  86. package/dist/benchmarks/tau-bench-shared.d.ts +5 -8
  87. package/dist/benchmarks/tau-bench-shared.js +4 -4
  88. package/dist/benchmarks/tau-bench-shared.js.map +1 -1
  89. package/dist/benchmarks/tau2-bench.d.ts +2 -5
  90. package/dist/benchmarks/tau2-bench.js +1 -2
  91. package/dist/benchmarks/tau3-banking.d.ts +1 -4
  92. package/dist/benchmarks/tau3-banking.js +1 -2
  93. package/dist/benchmarks/terminal-bench.d.ts +1 -4
  94. package/dist/benchmarks/terminal-bench.js +4 -4
  95. package/dist/benchmarks/terminal-bench.js.map +1 -1
  96. package/dist/benchmarks/toollm.d.ts +2 -5
  97. package/dist/benchmarks/toollm.js +1 -2
  98. package/dist/benchmarks/trata-hedge.d.ts +1 -4
  99. package/dist/benchmarks/trata-hedge.js +2 -3
  100. package/dist/benchmarks/types.d.ts +6 -9
  101. package/dist/benchmarks/webarena-verified.d.ts +2 -5
  102. package/dist/benchmarks/webarena-verified.js +1 -2
  103. package/dist/{cadbench-BRF-59Mt.js → cadbench-DhAndllg.js} +4 -6
  104. package/dist/cadbench-DhAndllg.js.map +1 -0
  105. package/dist/{cadgenbench-DXtGkuW3.js → cadgenbench-Tvk16YKT.js} +15 -5
  106. package/dist/cadgenbench-Tvk16YKT.js.map +1 -0
  107. package/dist/index.d.ts +8 -18
  108. package/dist/index.js +16 -24
  109. package/dist/index.js.map +1 -1
  110. package/dist/{router-turn-uTYO6KQ1.js → router-turn-DNbQ_GjQ.js} +2 -3
  111. package/dist/router-turn-DNbQ_GjQ.js.map +1 -0
  112. package/fixtures/pier-agent/no-model-task/pre_artifacts.sh +0 -0
  113. package/fixtures/pier-agent/no-model-task/tests/test.sh +0 -0
  114. package/package.json +10 -10
  115. package/pier_agents/tangle_candidate.py +15 -23
  116. package/scripts/run-package-tests.mjs +8 -15
  117. package/scripts/verify-packed-consumer.mjs +0 -1
  118. package/src/atom-mcp-e2e.mts +16 -4
  119. package/src/benchmarks/frames.ts +10 -44
  120. package/src/benchmarks/hotpotqa.ts +9 -29
  121. package/src/benchmarks/rag-shared.ts +12 -0
  122. package/src/benchmarks/simpleqa.ts +2 -36
  123. package/src/commit0-prereqs.sh +0 -0
  124. package/src/corpus-replay.mts +8 -8
  125. package/src/corpus-report.mts +21 -21
  126. package/src/corpus.test.mts +5 -5
  127. package/src/corpus.ts +16 -16
  128. package/src/directives.ts +0 -38
  129. package/src/examples/lean-verify.ts +1 -1
  130. package/src/gate.ts +8 -8
  131. package/src/generate-eval/certify.ts +2 -2
  132. package/src/index.ts +1 -0
  133. package/src/refine-loop.ts +5 -5
  134. package/src/resolve-client.ts +1 -1
  135. package/src/router-turn.ts +3 -11
  136. package/src/run-benchmarks.test.mts +0 -4
  137. package/src/run-pool.ts +1 -1
  138. package/src/runtime-hook-recorder.ts +2 -2
  139. package/src/search-bench/tasks.ts +1 -1
  140. package/src/selector.test.mts +13 -13
  141. package/src/selector.ts +19 -19
  142. package/src/swe-bench-env.ts +4 -12
  143. package/src/swe-jail.ts +5 -156
  144. package/src/swe-structural-judge-policy.ts +3 -3
  145. package/src/swe-structural-policy.ts +3 -3
  146. package/src/swe-structural-provenance.ts +4 -4
  147. package/src/terminal-compare.ts +10 -10
  148. package/src/worker-blender.ts +2 -106
  149. package/src/worker-build123d.ts +2 -81
  150. package/tb_agents/opencode_router_agent.py +1 -1
  151. package/dist/cadbench-BRF-59Mt.js.map +0 -1
  152. package/dist/cadgenbench-DXtGkuW3.js.map +0 -1
  153. package/dist/router-turn-uTYO6KQ1.js.map +0 -1
  154. package/scripts/cadbench_prepare.py +0 -22
  155. package/scripts/cadgenbench_hard_parts.py +0 -48
  156. package/scripts/clbench_codebase_judge.py +0 -73
  157. package/scripts/render-gate-chart.mjs +0 -176
  158. package/scripts/trata-hedge/README.md +0 -57
  159. package/scripts/trata-hedge/run.sh +0 -64
  160. package/src/browser/adapters/bad-design-audit.ts +0 -153
  161. package/src/browser/adapters/bad-design-audit.verify.ts +0 -85
  162. package/src/browser/adapters/bad.ts +0 -165
  163. package/src/browser/agent-adapter.ts +0 -145
  164. package/src/browser/process-adapter.ts +0 -146
  165. package/src/browser/run-to-spans.ts +0 -105
  166. package/src/browser/run-to-spans.verify.ts +0 -89
  167. package/src/browser/ui-reviewer.ts +0 -200
  168. package/src/browser/ui-reviewer.verify.ts +0 -94
  169. package/src/browser/verify.ts +0 -96
  170. package/src/clbench-codebase-gate.mts +0 -314
  171. package/src/clbench-context-gate.mts +0 -341
  172. package/src/cloud-loop.mts +0 -156
  173. package/src/commit0-env-run.mts +0 -62
  174. package/src/commit0-env.ts +0 -172
  175. package/src/commit0-gate.mts +0 -558
  176. package/src/coordination-mcp-container-reach.mts +0 -182
  177. package/src/egress-probe.mts +0 -26
  178. package/src/fleet.mts +0 -143
  179. package/src/hev-structural.mts +0 -697
  180. package/src/humaneval-gate.mts +0 -220
  181. package/src/humaneval-repair-gate.mts +0 -182
  182. package/src/mbpp-structural.mts +0 -676
  183. package/src/mcp-mount-probe.mts +0 -139
  184. package/src/profile-coordinates.ts +0 -134
  185. package/src/profiles.ts +0 -128
  186. package/src/research-gate.mts +0 -132
  187. package/src/research-shot.ts +0 -144
  188. package/src/router-executor.ts +0 -51
  189. package/src/run-benchmarks-report.ts +0 -66
  190. package/src/sandbox-run.ts +0 -108
  191. package/src/search-bench/bridge.ts +0 -182
  192. package/src/search-bench/export.mts +0 -0
  193. package/src/search-bench/parametric-check.mts +0 -78
  194. package/src/search-bench/profiles.ts +0 -113
  195. package/src/search-bench/run.mts +0 -286
  196. package/src/search-bench/tasks-fresh.ts +0 -688
  197. package/src/skill-sandbox-smoke.mts +0 -101
  198. package/src/smoke-structural-rollout.mts +0 -415
  199. package/src/stats.mts +0 -90
  200. package/src/supervisor-arena.mts +0 -825
  201. package/src/swe-code-improve.mts +0 -306
  202. package/src/swe-emit-patch.mts +0 -125
  203. package/src/swe-improve.mts +0 -284
  204. package/src/swe-local-proof.mts +0 -265
  205. package/src/swe-repro-calibrate.mts +0 -451
  206. package/src/swe-stream.mts +0 -1561
  207. package/src/swe-structural.mts +0 -707
  208. package/src/tb-container-executor.mts +0 -266
  209. package/src/tb-container-executor.test.mts +0 -134
  210. package/src/tb-supervisor-sidecar.mts +0 -208
  211. package/src/trajectory-assemble.mjs +0 -130
  212. package/src/trata-gepa.mts +0 -381
  213. package/src/trata-hedge-solve.mts +0 -81
  214. package/src/worker-browser.ts +0 -115
  215. package/src/worker-cad.ts +0 -470
  216. package/src/workspace-loop.mts +0 -133
  217. package/tb_agents/opencode_refine_agent.py +0 -117
  218. package/tb_agents/opencode_supervisor_agent.py +0 -239
@@ -1,139 +0,0 @@
1
- /**
2
- * The critical de-risk for the real e2e: does an in-box opencode harness (via the cli-bridge)
3
- * actually MOUNT my coordination MCP and CALL spawn_worker — landing on a real Scope.spawn?
4
- *
5
- * Serves the coordination MCP over a live Scope, then asks the bridge's opencode (with that MCP in
6
- * its config) to call spawn_worker + await_event. If the Scope spawned+settled, the in-box driving
7
- * path is real. No mock.
8
- *
9
- * ROUTER_BASE=http://127.0.0.1:3355/v1 TANGLE_API_KEY=<bridge-bearer> \
10
- * WORKER_MODEL=opencode/zai-coding-plan/glm-5-turbo npx tsx bench/src/mcp-mount-probe.mts
11
- */
12
-
13
- import {
14
- type Agent,
15
- type AgentProfile,
16
- type AgentSpec,
17
- collectAgentTurn,
18
- createExecutor,
19
- createExecutorRegistry,
20
- createSupervisor,
21
- type Executor,
22
- type ExecutorResult,
23
- InMemoryResultBlobStore,
24
- InMemorySpawnJournal,
25
- type Scope,
26
- streamAgentTurn,
27
- type UsageEvent,
28
- } from '../../src/runtime/index'
29
- import { serveCoordinationMcp } from '../../src/runtime/supervise/coordination-mcp'
30
-
31
- const BRIDGE = process.env.ROUTER_BASE ?? 'http://127.0.0.1:3355/v1'
32
- const BEARER = process.env.TANGLE_API_KEY ?? ''
33
- const MODEL = process.env.WORKER_MODEL ?? 'opencode/zai-coding-plan/glm-5-turbo'
34
-
35
- function deliveringLeaf(name: string, out: unknown): Agent<unknown, unknown> {
36
- const ex: Executor<unknown> = {
37
- runtime: 'router',
38
- execute() {
39
- return (async function* () {
40
- yield { kind: 'iteration' } as UsageEvent
41
- yield { kind: 'tokens', input: 5, output: 5 } as UsageEvent
42
- })()
43
- },
44
- teardown: () => Promise.resolve({ destroyed: true }),
45
- resultArtifact: (): ExecutorResult<unknown> => ({
46
- outRef: `w:${name}`,
47
- out,
48
- verdict: { valid: true, score: 1 },
49
- spent: { iterations: 1, tokens: { input: 5, output: 5 }, usd: 0, ms: 0 },
50
- }),
51
- }
52
- const spec: AgentSpec = { profile: { name } as AgentProfile, harness: null, executor: ex }
53
- return { name, act: async () => out, executorSpec: spec } as Agent<unknown, unknown> & {
54
- executorSpec: AgentSpec
55
- }
56
- }
57
-
58
- async function bridgeChat(messages: Array<{ role: string; content: string }>, mcpUrl: string): Promise<string> {
59
- if (!BEARER) throw new Error('TANGLE_API_KEY is required')
60
- const profile: AgentProfile = {
61
- name: 'mcp-mount-probe-supervisor',
62
- model: { default: MODEL },
63
- mcp: { coordination: { transport: 'http', url: mcpUrl } },
64
- }
65
- const factory = createExecutor({
66
- backend: 'bridge',
67
- bridgeUrl: BRIDGE.replace(/\/v1\/?$/u, ''),
68
- bridgeBearer: BEARER,
69
- })
70
- const turn = await collectAgentTurn(
71
- streamAgentTurn(
72
- { kind: 'executor', factory, profile },
73
- { prompt: messages.map((message) => message.content).join('\n\n') },
74
- ),
75
- )
76
- if (turn.status !== 'completed') {
77
- throw new Error(turn.error?.message ?? `bridge turn ended with ${turn.status}`)
78
- }
79
- return turn.finalText
80
- }
81
-
82
- async function main(): Promise<void> {
83
- const blobs = new InMemoryResultBlobStore()
84
- let mounted = false
85
- const root: Agent<unknown, unknown> = {
86
- name: 'mcp-mount-probe',
87
- async act(_t, scope: Scope<unknown>) {
88
- const mcp = await serveCoordinationMcp({
89
- scope,
90
- blobs,
91
- makeWorkerAgent: () => deliveringLeaf('w', { ok: true }),
92
- perWorker: { maxIterations: 4, maxTokens: 2000 },
93
- toolNames: ['spawn_worker', 'await_event', 'stop'],
94
- })
95
- console.error(`[probe] coordination MCP live at ${mcp.url}`)
96
- try {
97
- const content = await bridgeChat(
98
- [
99
- {
100
- role: 'user',
101
- content:
102
- 'You have an MCP server named "coordination" with tools: spawn_worker, await_event, stop. ' +
103
- 'Call spawn_worker with arguments {"profile":{},"task":"hello"}. Then call await_event. ' +
104
- 'Then reply with exactly what await_event returned.',
105
- },
106
- ],
107
- mcp.url,
108
- )
109
- const settled = mcp.settled()
110
- mounted = settled.length > 0
111
- console.error(`[probe] opencode replied: ${content.slice(0, 400)}`)
112
- console.error(`[probe] Scope spawned+settled = ${settled.length}: ${JSON.stringify(settled)}`)
113
- return mounted ? { mounted: true } : undefined
114
- } finally {
115
- await mcp.close()
116
- }
117
- },
118
- }
119
-
120
- const result = await createSupervisor<unknown, unknown>().run(root, 'probe', {
121
- budget: { maxIterations: 100, maxTokens: 400_000 },
122
- runId: 'mcp-probe',
123
- journal: new InMemorySpawnJournal(),
124
- blobs,
125
- executors: createExecutorRegistry(),
126
- maxDepth: 4,
127
- now: () => Date.now(),
128
- })
129
- console.log(
130
- mounted
131
- ? '✅ MCP MOUNT WORKS — the in-box opencode harness called spawn_worker → real Scope.spawn'
132
- : `❌ opencode did NOT call spawn_worker (result=${result.kind}) — protocol/mount needs work`,
133
- )
134
- }
135
-
136
- main().catch((e) => {
137
- console.error(e instanceof Error ? (e.stack ?? e.message) : String(e))
138
- process.exit(1)
139
- })
@@ -1,134 +0,0 @@
1
- /**
2
- * The AgentProfile genome as independently-optimizable coordinates. Every field the harness lets
3
- * you define — prompt, skills, subagents, hooks, tools, mcp — is a coordinate: a way to inject a
4
- * set of named candidates into a profile while holding every OTHER field fixed. This is the one
5
- * abstraction behind "improve any part of the agent, freeze the rest, combine freely":
6
- *
7
- * compose(baseProfile, selected) = { ...baseProfile, <thisField>: inject(selected) }
8
- *
9
- * Freeze a coordinate ⇒ never select it (it stays as-is in the base profile). Optimize one ⇒
10
- * vary its selection. Combine ⇒ compose several coordinates' composers in sequence. Because a
11
- * subagent is ITSELF an AgentProfile, the same coordinates apply recursively to any node in the
12
- * supervisor flow (root driver, worker, sub-worker) — you point a coordinate at that node's
13
- * base profile.
14
- */
15
- import { readFileSync, readdirSync } from 'node:fs'
16
- import { join } from 'node:path'
17
- import type { AgentProfile } from '@tangle-network/agent-interface'
18
- import { defineInlineResource } from '@tangle-network/agent-interface'
19
-
20
- export interface ProfileCoordinate {
21
- /** Coordinate id (the COORDINATE= knob value). */
22
- readonly name: string
23
- /** Candidate names the optimizer screens (one per independently-testable unit). */
24
- candidates(): readonly string[]
25
- /** Inject the selected candidates into THIS field of the profile, holding all others fixed.
26
- * Empty selection ⇒ the base profile unchanged (the frozen/baseline arm). */
27
- compose(base: AgentProfile, selected: readonly string[]): AgentProfile
28
- }
29
-
30
- const here = (p: string) => join(import.meta.dirname, p)
31
-
32
- // ── skills: SKILL.md packages materialized to disk (resources.skills) ───────────────
33
- function skillsCoordinate(dir = here(process.env.SKILLS_DIR ?? 'coding-skills')): ProfileCoordinate {
34
- const files = () => readdirSync(dir).filter((f) => f.endsWith('.md')).sort()
35
- return {
36
- name: 'skills',
37
- candidates: () => files().map((f) => f.replace(/\.md$/, '')),
38
- compose: (base, selected) => {
39
- if (!selected.length) return base
40
- const refs = selected.map((n) => defineInlineResource(n, readFileSync(join(dir, `${n}.md`), 'utf8')))
41
- return { ...base, resources: { ...base.resources, skills: [...(base.resources?.skills ?? []), ...refs] } }
42
- },
43
- }
44
- }
45
-
46
- // ── hooks: shell commands the harness fires on lifecycle events (enforced, not advisory) ──
47
- const hookDefs: Record<string, { event: string; command: string; matcher?: string }> = {
48
- 'lint-before-edit': { event: 'PreToolUse', matcher: 'Edit|Write', command: 'ruff check . 2>/dev/null || true' },
49
- 'tests-after-edit': { event: 'PostToolUse', matcher: 'Edit|Write', command: 'python -m pytest -q 2>/dev/null | tail -5 || true' },
50
- 'no-print-debugging': { event: 'PreToolUse', matcher: 'Edit|Write', command: 'true' },
51
- }
52
- function hooksCoordinate(): ProfileCoordinate {
53
- return {
54
- name: 'hooks',
55
- candidates: () => Object.keys(hookDefs),
56
- compose: (base, selected) => {
57
- if (!selected.length) return base
58
- const hooks: Record<string, { command: string; matcher?: string }[]> = { ...(base.hooks ?? {}) }
59
- for (const n of selected) {
60
- const d = hookDefs[n]
61
- if (!d) throw new Error(`unknown hook ${n}`)
62
- hooks[d.event] = [...(hooks[d.event] ?? []), { command: d.command, ...(d.matcher ? { matcher: d.matcher } : {}) }]
63
- }
64
- return { ...base, hooks: hooks as AgentProfile['hooks'] }
65
- },
66
- }
67
- }
68
-
69
- // ── tools: enable/disable named harness tools ───────────────────────────────────────
70
- const toolCandidates = ['webfetch', 'websearch', 'bash', 'edit', 'read', 'grep']
71
- function toolsCoordinate(): ProfileCoordinate {
72
- return {
73
- name: 'tools',
74
- candidates: () => toolCandidates,
75
- compose: (base, selected) => {
76
- if (!selected.length) return base
77
- const tools: Record<string, boolean> = { ...(base.tools ?? {}) }
78
- for (const n of selected) tools[n] = true
79
- return { ...base, tools }
80
- },
81
- }
82
- }
83
-
84
- // ── prompt: extra instruction lines appended to the active system prompt ─────────────
85
- const instructionDefs: Record<string, string> = {
86
- 'be-surgical': 'Make the smallest change that satisfies the task; do not touch unrelated code.',
87
- 'check-examples': 'Before finalizing, re-read the examples in the docstring and confirm your output matches them exactly.',
88
- 'edge-cases': 'Enumerate boundary inputs (empty, zero, negative, max) and make sure your solution handles each.',
89
- }
90
- function promptCoordinate(): ProfileCoordinate {
91
- return {
92
- name: 'prompt',
93
- candidates: () => Object.keys(instructionDefs),
94
- compose: (base, selected) => {
95
- if (!selected.length) return base
96
- const instructions = [...(base.prompt?.instructions ?? []), ...selected.map((n) => instructionDefs[n]!)]
97
- return { ...base, prompt: { ...base.prompt, instructions } }
98
- },
99
- }
100
- }
101
-
102
- // ── subagents: helper agents the root can delegate to (each is itself a mini-profile) ──
103
- const subagentDefs: Record<string, { description: string; prompt: string; tools?: Record<string, boolean> }> = {
104
- reviewer: { description: 'Reviews a proposed change for bugs before it is finalized.', prompt: 'You are a strict code reviewer. Find bugs, edge cases, and contract violations in the proposed change. Be concise.' },
105
- tester: { description: 'Writes and runs a focused test for the change.', prompt: 'You write the minimal test that would catch a regression in this change, run it, and report pass/fail.' },
106
- }
107
- function subagentsCoordinate(): ProfileCoordinate {
108
- return {
109
- name: 'subagents',
110
- candidates: () => Object.keys(subagentDefs),
111
- compose: (base, selected) => {
112
- if (!selected.length) return base
113
- const subagents = { ...(base.subagents ?? {}) }
114
- for (const n of selected) subagents[n] = subagentDefs[n]!
115
- return { ...base, subagents: subagents as AgentProfile['subagents'] }
116
- },
117
- }
118
- }
119
-
120
- const REGISTRY: Record<string, () => ProfileCoordinate> = {
121
- skills: () => skillsCoordinate(),
122
- hooks: hooksCoordinate,
123
- tools: toolsCoordinate,
124
- prompt: promptCoordinate,
125
- subagents: subagentsCoordinate,
126
- }
127
-
128
- export function getCoordinate(name: string): ProfileCoordinate {
129
- const make = REGISTRY[name]
130
- if (!make) throw new Error(`unknown coordinate ${name} (have: ${Object.keys(REGISTRY).join(', ')})`)
131
- return make()
132
- }
133
-
134
- export const coordinateNames = (): string[] => Object.keys(REGISTRY)
package/src/profiles.ts DELETED
@@ -1,128 +0,0 @@
1
- /**
2
- * The profile directory — roles are DATA, not code. One primitive (a profiled agent run as
3
- * `Agent.act` in an executor, orchestrated by the Supervisor); worker / analyst / driver are the
4
- * SAME agent, differing only by the profile below. This is the full unification: there is no
5
- * "operator type" or "analyst type" — there are profiles + the operator toolbox they use to manage
6
- * each other (in-process via the Scope, in a sandbox via the same verbs exposed as MCP tools).
7
- *
8
- * Complete agent-eval methods optimize these profiles over explicit train,
9
- * selection, and final-test partitions.
10
- * The trace-analyst's findings are the optimizer's input — the loop improves the profile that the
11
- * findings say is weak.
12
- */
13
-
14
- /** The operator toolbox — the verbs a DRIVER profile uses to lead the workers it drives. In-process
15
- * these are `Scope` methods; in a sandbox they are the SAME verbs exposed as MCP tools (Scope-as-MCP).
16
- * `analyze`/`define_analyst`/`run_analyst` make the trace-analyst a first-class, definable sub-agent —
17
- * the driver triggers analysts as a tool (or spawns one), never via raw bash. */
18
- export const OPERATOR_TOOLS = [
19
- 'list_analysts', // the trace analysts already available
20
- 'define_analyst', // author + register a NEW trace analyst (a profile) on the fly
21
- 'run_analyst', // run an analyst over a worker's trace → findings (selector≠judge: trace, not score)
22
- 'observe_worker', // a worker's in-flight trace, or its last finished episode/shot
23
- 'spawn_worker', // start a worker (or a sub-analyst) — drive many; parallelize when independent
24
- 'steer_worker', // send a live worker a message down: instruction, course-correction, or continuation (interrupt? for forceful)
25
- 'stop', // declare the task complete (verified) or abandon a line
26
- ] as const
27
-
28
- export type OperatorTool = (typeof OPERATOR_TOOLS)[number]
29
-
30
- /** One role in the directory. The unified run-config: who the agent is (`systemPrompt`/`skills`), what
31
- * it can do (`tools` + `mcp`), and which lane it serves (`role`). The same shape the sandbox executor
32
- * runs and the optimizer mutates. */
33
- export interface RoleProfile {
34
- readonly id: string
35
- readonly role: 'worker' | 'analyst' | 'driver'
36
- /** Default model snapshot; the optimizer may pin/sweep it. */
37
- readonly model: string
38
- readonly systemPrompt: string
39
- /** Reusable capabilities the skillopt driver evolves; the driver may PROPOSE new ones from findings. */
40
- readonly skills: string[]
41
- /** Tool names available in-box. Workers get the artifact's tools; drivers also get the operator toolbox. */
42
- readonly tools: string[]
43
- /** MCP servers wired in-box (the operator toolbox is one, when the driver runs in a sandbox). */
44
- readonly mcp?: string[]
45
- }
46
-
47
- /** WORKER: does the task over the artifact. Its tools are the artifact's (the surface supplies them);
48
- * its dynamic-workflow / fanout capability comes from the harness it runs (pi/codex/claude-code) +
49
- * its skills — which is exactly why those live on the profile. */
50
- export const workerProfile: RoleProfile = {
51
- id: 'worker/default',
52
- role: 'worker',
53
- model: 'deepseek-v4-flash',
54
- systemPrompt:
55
- 'You are a worker. Use the available tools to bring the artifact to the required final state. ' +
56
- 'Address every distinct change the request implies; after each tool result, check what remains ' +
57
- 'and continue; verify each value you set actually took. Use your harness’s parallelism / dynamic ' +
58
- 'workflow / sub-agents when the sub-tasks are genuinely independent. Reply DONE only once every ' +
59
- 'required change is made and verified.',
60
- skills: [],
61
- tools: ['<artifact tools>'],
62
- }
63
-
64
- /** ANALYST: reads a trace, emits findings. Firewall — judges from observed tool RESULTS, never a score
65
- * (selector≠judge). A driver can `define_analyst` to spawn specialized variants of this. */
66
- export const analystProfile: RoleProfile = {
67
- id: 'analyst/trace',
68
- role: 'analyst',
69
- model: 'deepseek-v4-flash',
70
- systemPrompt:
71
- 'You audit a worker’s trajectory. From ONLY the task and the worker’s tool-call trace (calls + ' +
72
- 'their RESULTS), list every required change that does NOT yet appear done or verified. Judge from ' +
73
- 'observed results, never from intent, and never from a grader/score. Be specific. If everything ' +
74
- 'required appears done and verified, reply exactly COMPLETE.',
75
- skills: [],
76
- tools: ['read_trace'],
77
- }
78
-
79
- /** DRIVER: the lead steerer. A sandbox agent that reviews the workers it drives, investigates their
80
- * traces (using/defining analysts, fanning out when useful), takes the lead or dispatches, and
81
- * parallelizes intelligently. This is the profile you sketched — formalized. Topology is ITS choice. */
82
- export const driverProfile: RoleProfile = {
83
- id: 'driver/operator',
84
- role: 'driver',
85
- model: 'deepseek-v4-flash',
86
- systemPrompt: [
87
- 'You are the OPERATOR. You lead one or more worker agents to fully complete a task over a shared',
88
- 'artifact. You may delegate, investigate, and — when it is faster or more reliable — do the work',
89
- 'yourself. You judge from traces, never from a grader/score (selector ≠ judge).',
90
- '',
91
- 'TOOLS:',
92
- '- list_analysts / run_analyst(id, worker): the trace analysts available — run one over a worker’s',
93
- ' trajectory to get findings.',
94
- '- define_analyst(profile): if no existing analyst fits, AUTHOR a new one and run it. Specialized',
95
- ' analysts are cheap; make them when a worker’s failure mode needs a focused lens.',
96
- '- observe_worker(worker): the worker’s IN-FLIGHT trace if it is still running, else its last',
97
- ' finished episode/shot.',
98
- '- spawn_worker(profile, task) / steer_worker(worker, instruction, interrupt?) / stop.',
99
- '- the artifact’s own tools (read/edit/run) — use them to inspect the workspace and to contribute',
100
- ' decisive work yourself.',
101
- '',
102
- 'EACH CYCLE:',
103
- '1. Review the workers you are driving — analyze their in-flight traces, or their last finished',
104
- ' shot. Investigate deeply: run analysts, define a new analyst if needed, and fan out / spawn',
105
- ' sub-analysts in PARALLEL to inspect traces faster when that genuinely helps.',
106
- '2. Identify everything you can — incomplete work, errors, wrong approaches, policy violations,',
107
- ' stalls, repeated mistakes. Be concrete about what remains.',
108
- '3. If a finding is a reusable capability, PROPOSE it as a skill (so the optimizer can fold it into',
109
- ' the profile directory) rather than re-deriving it every run.',
110
- '4. Decide and act. If you are confident on the issue and dispatching would be slower or less',
111
- ' reliable, TAKE THE LEAD: do the decisive turn yourself (directly, via sub-agents, or a dynamic',
112
- ' workflow). Otherwise STEER the worker with a specific, verifiable instruction.',
113
- '5. Parallelize as much as you intelligently can — NOT frivolously. Fan out only when the sub-tasks',
114
- ' are genuinely independent; go deep on a single line when the work is sequential.',
115
- '',
116
- 'STOP only when every required change is made AND confirmed in the workers’ tool results.',
117
- ].join('\n'),
118
- skills: ['trace-review', 'fanout-when-independent', 'take-the-lead-when-confident'],
119
- tools: [...OPERATOR_TOOLS, '<artifact tools>'],
120
- mcp: ['coordination'], // Scope-as-MCP: the coordination verbs, in a sandbox
121
- }
122
-
123
- /** The directory — the population the RSI loop optimizes (gepa over prompts, skillopt over skills). */
124
- export const profileDirectory: Record<string, RoleProfile> = {
125
- [workerProfile.id]: workerProfile,
126
- [analystProfile.id]: analystProfile,
127
- [driverProfile.id]: driverProfile,
128
- }
@@ -1,132 +0,0 @@
1
- /**
2
- * Research leaderboard — model × web-search-provider × multi-shot, on the research
3
- * benches (finsearchcomp / frames / hotpotqa / simpleqa). This is the OFF-SANDBOX
4
- * RAG baseline: per shot, (1) provider-pinned web search via the router's proven
5
- * `/v1/search?provider=<id>` + `web_fetch` of the top-K result pages, (2) answer with
6
- * the evidence in context (no tools → `content` always present, so every arm differs
7
- * ONLY by the search provider — a clean controlled A/B). `SEARCH=default` skips search
8
- * (parametric control). Pure router HTTP (bearer `TANGLE_API_KEY`) — never touches the
9
- * sandbox, so it never contends with sandbox-bound gates.
10
- *
11
- * The retrieve→answer body is the shared `runResearchShot` (research-shot.ts). Reuses
12
- * `runPool` (bounded concurrency), `appendRunRecord` (the durable corpus), and the bench's own
13
- * `adapter.judge`; nothing is reinvented. The AGENTIC HARNESS regime (opencode/pi multi-turn in
14
- * a box) runs through the gate (`runGate`) with a sandbox-backed executor; this
15
- * file is the flat, non-agentic search-RAG baseline.
16
- *
17
- * Each shot's answer is graded by the bench judge; writes one corpus RunRecord/task
18
- * tagged `search:<provider>` + `model` so the leaderboard slices by arm. Fault-isolated
19
- * (a flaky call → a NO-ANSWER attempt, never a throw).
20
- *
21
- * dotenvx run -f ~/company/devops/secrets/.env.keys -f ~/company/devops/secrets/agent-state.env -- \
22
- * env BENCH=simpleqa SIMPLEQA_FIXTURES=1 MODEL=gpt-4o-mini SEARCH=you N=10 K=1 \
23
- * CONCURRENCY=3 JUDGE_MODEL=gpt-4o-mini CORPUS=/tmp/research-you.jsonl tsx src/research-gate.mts
24
- * tsx src/corpus-report.mts <armA.jsonl> <armB.jsonl> # paired-bootstrap across arms
25
- */
26
-
27
- import { ADAPTERS } from './adapters'
28
- import { type AttemptRecord, appendRunRecord, type RunRecord } from './corpus'
29
- import { runResearchShot, type ShotCfg } from './research-shot'
30
- import { runPool } from './run-pool'
31
-
32
- function must(name: string): string {
33
- const v = process.env[name]
34
- if (!v) throw new Error(`env ${name} is required`)
35
- return v
36
- }
37
-
38
- async function main(): Promise<void> {
39
- const benchName = process.env.BENCH ?? 'finsearchcomp'
40
- const makeAdapter = ADAPTERS[benchName]
41
- if (!makeAdapter) throw new Error(`unknown BENCH=${benchName} (have: ${Object.keys(ADAPTERS).join(', ')})`)
42
-
43
- const n = Number(process.env.N ?? 6)
44
- const k = Number(process.env.K ?? 3)
45
- const model = process.env.MODEL ?? process.env.WORKER_MODEL ?? 'deepseek-v4-flash'
46
- const search = process.env.SEARCH ?? 'default'
47
- const cfg: ShotCfg = {
48
- model,
49
- search,
50
- maxResults: Number(process.env.SEARCH_MAX_RESULTS ?? 5),
51
- fetchTopK: Number(process.env.FETCH_TOP_K ?? 3),
52
- temperature: Number(process.env.TEMPERATURE ?? 0.7),
53
- routerBaseUrl: process.env.ROUTER_BASE ?? 'https://router.tangle.tools/v1',
54
- routerKey: must('TANGLE_API_KEY'), // worker (router) + bench judge both need it
55
- timeoutMs: process.env.SHOT_TIMEOUT_MS ? Number(process.env.SHOT_TIMEOUT_MS) : 600_000,
56
- }
57
- const concurrency = Number(process.env.CONCURRENCY ?? 3)
58
- const corpusPath = process.env.CORPUS ?? `/tmp/research-${benchName}-${model.replace(/[^a-z0-9]/gi, '_')}-${search}.jsonl`
59
- if (!Number.isInteger(n) || n < 1) throw new Error(`N must be a positive integer, got ${process.env.N}`)
60
- if (!Number.isInteger(k) || k < 1) throw new Error(`K must be a positive integer, got ${process.env.K}`)
61
-
62
- const adapter = makeAdapter()
63
- console.log(`=== research gate (router-RAG) · bench=${benchName} · model=${model} · search=${search} · N=${n} K=${k} conc=${concurrency} ===`)
64
- await adapter.preflight()
65
- const tasks = await adapter.loadTasks({ limit: n })
66
- console.log(`loaded ${tasks.length} task(s)`)
67
-
68
- // Phase 1 — rollouts, concurrent (the shared runPool), off-sandbox. Fault-isolated.
69
- const units = tasks.flatMap((task) => Array.from({ length: k }, (_, attempt) => ({ task, attempt })))
70
- console.log(`\n▶ phase 1: ${units.length} rollouts (conc=${concurrency}) · search=${search}`)
71
- const shots = await runPool(units, concurrency, async (u) => {
72
- const s = await runResearchShot(u.task.prompt, u.task.id, u.attempt, cfg)
73
- console.log(` rollout ${u.task.id}#${u.attempt}: ${s.ok ? `answer ${s.answer.length}B · ${s.searches} search(es)` : `NO ANSWER (${s.detail})`} (${(s.wallMs / 1000) | 0}s)`)
74
- return s
75
- })
76
- const shotOf = (id: string, i: number) => shots.find((o) => o.value?.taskId === id && o.value?.attempt === i)?.value
77
-
78
- // Phase 2 — judge via the bench's OWN judge; write one RunRecord/task (the shared corpus).
79
- console.log(`\n▶ phase 2: judging via ${adapter.name} judge → ${corpusPath}`)
80
- let scoredTasks = 0
81
- for (const task of tasks) {
82
- const attempts: AttemptRecord[] = []
83
- for (let i = 0; i < k; i += 1) {
84
- const s = shotOf(task.id, i)
85
- let sc: { score: number; resolved: boolean } | undefined
86
- if (s?.ok) {
87
- try {
88
- const v = await adapter.judge(task, s.answer)
89
- sc = { score: v.score, resolved: v.resolved }
90
- console.log(` judge ${task.id}#${i}: score=${(v.score * 100).toFixed(1)}% resolved=${v.resolved}`)
91
- } catch (err) {
92
- console.log(` judge ${task.id}#${i}: ERROR ${(err instanceof Error ? err.message : String(err)).slice(0, 160)}`)
93
- }
94
- } else {
95
- console.log(` judge ${task.id}#${i}: skipped (no answer)`)
96
- }
97
- attempts.push({
98
- round: i,
99
- prompt: `research:${search}`,
100
- output: s?.answer ?? '',
101
- ...(sc ? { valid: sc.resolved, score: sc.score } : {}),
102
- wallMs: s?.wallMs ?? 0,
103
- eventCount: s?.searches ?? 0,
104
- eventTypes: { 'web_search.requests': s?.searches ?? 0 },
105
- traceTail: (s?.answer ?? '').slice(-600),
106
- })
107
- }
108
- if (attempts.some((a) => a.score !== undefined)) scoredTasks += 1
109
- const record: RunRecord = {
110
- ts: new Date().toISOString(),
111
- benchmark: adapter.name,
112
- instanceId: task.id,
113
- condition: `search:${search}`,
114
- model,
115
- blindResolved: attempts[0]?.valid === true,
116
- resolved: attempts.some((a) => a.valid === true),
117
- attempts,
118
- infraError: false,
119
- }
120
- await appendRunRecord(corpusPath, record)
121
- }
122
-
123
- console.log(
124
- `\n=== wrote ${tasks.length} task(s) (${scoredTasks} with ≥1 scored attempt) → ${corpusPath} ===\n` +
125
- ` arm = model:${model} × search:${search} · compare arms: tsx src/corpus-report.mts <armA.jsonl> <armB.jsonl>`,
126
- )
127
- }
128
-
129
- main().catch((err) => {
130
- console.error(`research-gate: ${err instanceof Error ? err.message : String(err)}`)
131
- process.exit(1)
132
- })