@tangle-network/agent-bench 0.14.4 → 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.
- package/CHANGELOG.md +38 -0
- package/README.md +2 -3
- package/dist/adapters.d.ts +2 -5
- package/dist/adapters.js +3 -4
- package/dist/benchmarks/_harness.d.ts +17 -20
- package/dist/benchmarks/_harness.js +4 -4
- package/dist/benchmarks/_harness.js.map +1 -1
- package/dist/benchmarks/aec-bench.d.ts +1 -4
- package/dist/benchmarks/aec-bench.js +1 -2
- package/dist/benchmarks/agentbench.d.ts +2 -5
- package/dist/benchmarks/agentbench.js +1 -2
- package/dist/benchmarks/appworld.d.ts +8 -10
- package/dist/benchmarks/appworld.js +23 -23
- package/dist/benchmarks/appworld.js.map +1 -1
- package/dist/benchmarks/bfcl.d.ts +2 -5
- package/dist/benchmarks/bfcl.js +1 -2
- package/dist/benchmarks/cad-design.d.ts +2 -5
- package/dist/benchmarks/cad-design.js +2 -3
- package/dist/benchmarks/cad-design.js.map +1 -1
- package/dist/benchmarks/cadbench.d.ts +1 -4
- package/dist/benchmarks/cadbench.js +1 -2
- package/dist/benchmarks/cadgenbench.d.ts +1 -4
- package/dist/benchmarks/cadgenbench.js +1 -2
- package/dist/benchmarks/commit0.d.ts +2 -5
- package/dist/benchmarks/commit0.js +1 -2
- package/dist/benchmarks/crag.d.ts +1 -4
- package/dist/benchmarks/crag.js +3 -3
- package/dist/benchmarks/crag.js.map +1 -1
- package/dist/benchmarks/dabstep.d.ts +2 -5
- package/dist/benchmarks/dabstep.js +2 -3
- package/dist/benchmarks/dabstep.js.map +1 -1
- package/dist/benchmarks/enterpriseops-gym.d.ts +2 -5
- package/dist/benchmarks/enterpriseops-gym.js +1 -2
- package/dist/benchmarks/finresearchbench.d.ts +2 -5
- package/dist/benchmarks/finresearchbench.js +2 -3
- package/dist/benchmarks/finsearchcomp.d.ts +2 -5
- package/dist/benchmarks/finsearchcomp.js +4 -4
- package/dist/benchmarks/finsearchcomp.js.map +1 -1
- package/dist/benchmarks/frames.d.ts +3 -19
- package/dist/benchmarks/frames.js +13 -39
- package/dist/benchmarks/frames.js.map +1 -1
- package/dist/benchmarks/hotpotqa.d.ts +4 -14
- package/dist/benchmarks/hotpotqa.js +12 -32
- package/dist/benchmarks/hotpotqa.js.map +1 -1
- package/dist/benchmarks/humaneval.d.ts +9 -12
- package/dist/benchmarks/humaneval.js +2 -3
- package/dist/benchmarks/humaneval.js.map +1 -1
- package/dist/benchmarks/mcad-bench.d.ts +13 -16
- package/dist/benchmarks/mcad-bench.js +2 -3
- package/dist/benchmarks/mcad-bench.js.map +1 -1
- package/dist/benchmarks/mcad-cq-bench.d.ts +17 -20
- package/dist/benchmarks/mcad-cq-bench.js +2 -3
- package/dist/benchmarks/mcad-cq-bench.js.map +1 -1
- package/dist/benchmarks/mcad-cq-golds.d.ts +2 -5
- package/dist/benchmarks/mcad-cq-golds.js +1 -2
- package/dist/benchmarks/mcad-golds.d.ts +1 -4
- package/dist/benchmarks/mcad-golds.js +0 -1
- package/dist/benchmarks/mcad-tasks.d.ts +5 -8
- package/dist/benchmarks/mcad-tasks.js +7 -8
- package/dist/benchmarks/mcad-tasks.js.map +1 -1
- package/dist/benchmarks/mind2web.d.ts +3 -5
- package/dist/benchmarks/mind2web.js +2 -3
- package/dist/benchmarks/mind2web.js.map +1 -1
- package/dist/benchmarks/nomiracl.d.ts +1 -4
- package/dist/benchmarks/nomiracl.js +1 -2
- package/dist/benchmarks/open-rag-bench.d.ts +1 -4
- package/dist/benchmarks/open-rag-bench.js +3 -3
- package/dist/benchmarks/open-rag-bench.js.map +1 -1
- package/dist/benchmarks/programbench.d.ts +2 -5
- package/dist/benchmarks/programbench.js +1 -2
- package/dist/benchmarks/rag-shared.d.ts +30 -22
- package/dist/benchmarks/rag-shared.js +8 -2
- package/dist/benchmarks/rag-shared.js.map +1 -1
- package/dist/benchmarks/ragbench.d.ts +1 -4
- package/dist/benchmarks/ragbench.js +3 -3
- package/dist/benchmarks/ragbench.js.map +1 -1
- package/dist/benchmarks/simpleqa.d.ts +2 -18
- package/dist/benchmarks/simpleqa.js +5 -31
- package/dist/benchmarks/simpleqa.js.map +1 -1
- package/dist/benchmarks/swe-bench.d.ts +7 -10
- package/dist/benchmarks/swe-bench.js +4 -4
- package/dist/benchmarks/swe-bench.js.map +1 -1
- package/dist/benchmarks/t2-ragbench.d.ts +1 -4
- package/dist/benchmarks/t2-ragbench.js +3 -3
- package/dist/benchmarks/t2-ragbench.js.map +1 -1
- package/dist/benchmarks/tau-bench-shared.d.ts +5 -8
- package/dist/benchmarks/tau-bench-shared.js +4 -4
- package/dist/benchmarks/tau-bench-shared.js.map +1 -1
- package/dist/benchmarks/tau2-bench.d.ts +2 -5
- package/dist/benchmarks/tau2-bench.js +1 -2
- package/dist/benchmarks/tau3-banking.d.ts +1 -4
- package/dist/benchmarks/tau3-banking.js +1 -2
- package/dist/benchmarks/terminal-bench.d.ts +1 -4
- package/dist/benchmarks/terminal-bench.js +4 -4
- package/dist/benchmarks/terminal-bench.js.map +1 -1
- package/dist/benchmarks/toollm.d.ts +2 -5
- package/dist/benchmarks/toollm.js +1 -2
- package/dist/benchmarks/trata-hedge.d.ts +1 -4
- package/dist/benchmarks/trata-hedge.js +2 -3
- package/dist/benchmarks/types.d.ts +6 -9
- package/dist/benchmarks/webarena-verified.d.ts +2 -5
- package/dist/benchmarks/webarena-verified.js +1 -2
- package/dist/{cadbench-BRF-59Mt.js → cadbench-DhAndllg.js} +4 -6
- package/dist/cadbench-DhAndllg.js.map +1 -0
- package/dist/{cadgenbench-DXtGkuW3.js → cadgenbench-Tvk16YKT.js} +15 -5
- package/dist/cadgenbench-Tvk16YKT.js.map +1 -0
- package/dist/index.d.ts +8 -18
- package/dist/index.js +16 -24
- package/dist/index.js.map +1 -1
- package/dist/{router-turn-uTYO6KQ1.js → router-turn-DNbQ_GjQ.js} +2 -3
- package/dist/router-turn-DNbQ_GjQ.js.map +1 -0
- package/fixtures/pier-agent/no-model-task/pre_artifacts.sh +0 -0
- package/fixtures/pier-agent/no-model-task/tests/test.sh +0 -0
- package/package.json +10 -10
- package/pier_agents/tangle_candidate.py +15 -23
- package/scripts/run-package-tests.mjs +8 -15
- package/src/atom-mcp-e2e.mts +2 -2
- package/src/benchmarks/frames.ts +10 -44
- package/src/benchmarks/hotpotqa.ts +9 -29
- package/src/benchmarks/rag-shared.ts +12 -0
- package/src/benchmarks/simpleqa.ts +2 -36
- package/src/commit0-prereqs.sh +0 -0
- package/src/corpus-replay.mts +8 -8
- package/src/corpus-report.mts +21 -21
- package/src/corpus.test.mts +5 -5
- package/src/corpus.ts +16 -16
- package/src/directives.ts +0 -38
- package/src/examples/lean-verify.ts +1 -1
- package/src/gate.ts +7 -7
- package/src/generate-eval/certify.ts +2 -2
- package/src/index.ts +1 -0
- package/src/refine-loop.ts +5 -5
- package/src/resolve-client.ts +1 -1
- package/src/router-turn.ts +3 -11
- package/src/run-pool.ts +1 -1
- package/src/runtime-hook-recorder.ts +2 -2
- package/src/search-bench/tasks.ts +1 -1
- package/src/selector.test.mts +13 -13
- package/src/selector.ts +19 -19
- package/src/swe-bench-env.ts +4 -12
- package/src/swe-jail.ts +5 -156
- package/src/swe-structural-judge-policy.ts +3 -3
- package/src/swe-structural-policy.ts +3 -3
- package/src/swe-structural-provenance.ts +4 -4
- package/src/terminal-compare.ts +10 -10
- package/src/worker-blender.ts +2 -106
- package/src/worker-build123d.ts +2 -81
- package/tb_agents/opencode_router_agent.py +1 -1
- package/dist/cadbench-BRF-59Mt.js.map +0 -1
- package/dist/cadgenbench-DXtGkuW3.js.map +0 -1
- package/dist/router-turn-uTYO6KQ1.js.map +0 -1
- package/scripts/cadbench_prepare.py +0 -22
- package/scripts/cadgenbench_hard_parts.py +0 -48
- package/scripts/clbench_codebase_judge.py +0 -73
- package/scripts/render-gate-chart.mjs +0 -176
- package/scripts/trata-hedge/README.md +0 -57
- package/scripts/trata-hedge/run.sh +0 -64
- package/src/cloud-loop.mts +0 -156
- package/src/coordination-mcp-container-reach.mts +0 -182
- package/src/fleet.mts +0 -143
- package/src/hev-structural.mts +0 -697
- package/src/humaneval-gate.mts +0 -220
- package/src/mbpp-structural.mts +0 -676
- package/src/mcp-mount-probe.mts +0 -141
- package/src/profiles.ts +0 -128
- package/src/research-gate.mts +0 -132
- package/src/research-shot.ts +0 -144
- package/src/router-executor.ts +0 -51
- package/src/sandbox-run.ts +0 -108
- package/src/search-bench/bridge.ts +0 -182
- package/src/search-bench/export.mts +0 -0
- package/src/search-bench/parametric-check.mts +0 -78
- package/src/search-bench/profiles.ts +0 -113
- package/src/search-bench/run.mts +0 -286
- package/src/search-bench/tasks-fresh.ts +0 -688
- package/src/smoke-structural-rollout.mts +0 -415
- package/src/stats.mts +0 -90
- package/src/swe-code-improve.mts +0 -306
- package/src/swe-improve.mts +0 -284
- package/src/swe-structural.mts +0 -707
- package/src/tb-container-executor.mts +0 -266
- package/src/tb-container-executor.test.mts +0 -134
- package/src/tb-supervisor-sidecar.mts +0 -208
- package/src/trata-gepa.mts +0 -381
- package/src/trata-hedge-solve.mts +0 -81
- package/tb_agents/opencode_refine_agent.py +0 -117
- package/tb_agents/opencode_supervisor_agent.py +0 -239
package/src/mcp-mount-probe.mts
DELETED
|
@@ -1,141 +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. 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', '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, stop. ' +
|
|
103
|
-
'Call spawn_worker with arguments {"profile":{},"task":"hello"}. ' +
|
|
104
|
-
'Then reply with exactly what spawn_worker returned.',
|
|
105
|
-
},
|
|
106
|
-
],
|
|
107
|
-
mcp.url,
|
|
108
|
-
)
|
|
109
|
-
// The harness ended its turn after spawning; move the settled worker into the ledger.
|
|
110
|
-
await mcp.drainResolved()
|
|
111
|
-
const settled = mcp.settled()
|
|
112
|
-
mounted = settled.length > 0
|
|
113
|
-
console.error(`[probe] opencode replied: ${content.slice(0, 400)}`)
|
|
114
|
-
console.error(`[probe] Scope spawned+settled = ${settled.length}: ${JSON.stringify(settled)}`)
|
|
115
|
-
return mounted ? { mounted: true } : undefined
|
|
116
|
-
} finally {
|
|
117
|
-
await mcp.close()
|
|
118
|
-
}
|
|
119
|
-
},
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
const result = await createSupervisor<unknown, unknown>().run(root, 'probe', {
|
|
123
|
-
budget: { maxIterations: 100, maxTokens: 400_000 },
|
|
124
|
-
runId: 'mcp-probe',
|
|
125
|
-
journal: new InMemorySpawnJournal(),
|
|
126
|
-
blobs,
|
|
127
|
-
executors: createExecutorRegistry(),
|
|
128
|
-
maxDepth: 4,
|
|
129
|
-
now: () => Date.now(),
|
|
130
|
-
})
|
|
131
|
-
console.log(
|
|
132
|
-
mounted
|
|
133
|
-
? '✅ MCP MOUNT WORKS — the in-box opencode harness called spawn_worker → real Scope.spawn'
|
|
134
|
-
: `❌ opencode did NOT call spawn_worker (result=${result.kind}) — protocol/mount needs work`,
|
|
135
|
-
)
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
main().catch((e) => {
|
|
139
|
-
console.error(e instanceof Error ? (e.stack ?? e.message) : String(e))
|
|
140
|
-
process.exit(1)
|
|
141
|
-
})
|
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
|
-
}
|
package/src/research-gate.mts
DELETED
|
@@ -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
|
-
})
|
package/src/research-shot.ts
DELETED
|
@@ -1,144 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* One research rollout as a reusable primitive: 2-step RAG — (1) provider-pinned web
|
|
3
|
-
* search via the router's proven `/v1/search?provider=<id>` + `web_fetch` of the top-K
|
|
4
|
-
* result pages, (2) answer with that evidence through Runtime's profile-bound turn (no tools on the
|
|
5
|
-
* answer call → `content` always present, so a search arm differs from the parametric
|
|
6
|
-
* control ONLY by the evidence). Pure router HTTP (bearer `TANGLE_API_KEY`).
|
|
7
|
-
*
|
|
8
|
-
* Shared by the off-sandbox RAG leaderboard (`research-gate.mts`) and the router-backed
|
|
9
|
-
* loop executor (`router-executor.ts`), so both score the identical retrieve→answer body
|
|
10
|
-
* — the only difference is who drives the rounds (a flat best-of-k pool vs the real
|
|
11
|
-
* `runAgentRounds` kernel with analyst steering).
|
|
12
|
-
*/
|
|
13
|
-
import { runBenchRouterTurn } from './router-turn'
|
|
14
|
-
|
|
15
|
-
export interface ShotCfg {
|
|
16
|
-
model: string
|
|
17
|
-
/** search provider id: 'default'/'off'/'none' = no search (parametric control); else a router provider. */
|
|
18
|
-
search: string
|
|
19
|
-
maxResults: number
|
|
20
|
-
/** how many top search URLs to web_fetch full page content for (0 = snippets only). */
|
|
21
|
-
fetchTopK: number
|
|
22
|
-
temperature: number
|
|
23
|
-
routerBaseUrl: string
|
|
24
|
-
routerKey: string
|
|
25
|
-
timeoutMs: number
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
export interface Shot {
|
|
29
|
-
taskId: string
|
|
30
|
-
attempt: number
|
|
31
|
-
answer: string
|
|
32
|
-
ok: boolean
|
|
33
|
-
detail?: string
|
|
34
|
-
wallMs: number
|
|
35
|
-
/** count of search hits retrieved (0 ⇒ no search happened / it failed). */
|
|
36
|
-
searches: number
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/** Fetch a URL's extracted page text via the router web_fetch MCP tool. Returns '' on any failure. */
|
|
40
|
-
export async function fetchPage(url: string, cfg: ShotCfg): Promise<string> {
|
|
41
|
-
try {
|
|
42
|
-
const res = await fetch(`${cfg.routerBaseUrl}/search/mcp?provider=${encodeURIComponent(cfg.search)}`, {
|
|
43
|
-
method: 'POST',
|
|
44
|
-
headers: { 'content-type': 'application/json', authorization: `Bearer ${cfg.routerKey}` },
|
|
45
|
-
body: JSON.stringify({ jsonrpc: '2.0', id: 1, method: 'tools/call', params: { name: 'web_fetch', arguments: { url } } }),
|
|
46
|
-
...(cfg.timeoutMs ? { signal: AbortSignal.timeout(Math.min(cfg.timeoutMs, 60_000)) } : {}),
|
|
47
|
-
})
|
|
48
|
-
if (!res.ok) return ''
|
|
49
|
-
const body = (await res.json()) as { result?: { content?: Array<{ text?: string }> } }
|
|
50
|
-
const text = body.result?.content?.[0]?.text ?? ''
|
|
51
|
-
// The tool returns a JSON string {url,title,content}; pull `content` if parseable, else the raw text.
|
|
52
|
-
try {
|
|
53
|
-
const parsed = JSON.parse(text) as { content?: string }
|
|
54
|
-
return (parsed.content ?? text).slice(0, 2500)
|
|
55
|
-
} catch {
|
|
56
|
-
return text.slice(0, 2500)
|
|
57
|
-
}
|
|
58
|
-
} catch {
|
|
59
|
-
return ''
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* One research rollout, 2-step RAG against `prompt` (the task question, possibly with a
|
|
65
|
-
* steer appended): (1) provider-pinned web search + web_fetch of the top-K pages, (2)
|
|
66
|
-
* answer with that evidence. The search query is the clean question (first non-empty
|
|
67
|
-
* line) — appended worker-contract / steer boilerplate pollutes the query and returns 0
|
|
68
|
-
* hits — while the ANSWER sees the full `prompt` so a steer round can act on it. The
|
|
69
|
-
* COMMIT prompt stops the model deferring ("may I search?"), which otherwise scores 0.
|
|
70
|
-
* Fault-isolated: a flaky call → a NO-ANSWER `Shot`, never a throw.
|
|
71
|
-
*/
|
|
72
|
-
export async function runResearchShot(prompt: string, taskId: string, attempt: number, cfg: ShotCfg): Promise<Shot> {
|
|
73
|
-
const startedAt = Date.now()
|
|
74
|
-
const useSearch = cfg.search !== 'default' && cfg.search !== 'off' && cfg.search !== 'none'
|
|
75
|
-
let searches = 0
|
|
76
|
-
try {
|
|
77
|
-
// 1) Provider-pinned web search (proven /v1/search). The control arm skips this.
|
|
78
|
-
let context = ''
|
|
79
|
-
if (useSearch) {
|
|
80
|
-
const query = (prompt.split('\n').find((l) => l.trim().length > 0) ?? prompt).slice(0, 300)
|
|
81
|
-
const sres = await fetch(`${cfg.routerBaseUrl}/search?provider=${encodeURIComponent(cfg.search)}`, {
|
|
82
|
-
method: 'POST',
|
|
83
|
-
headers: { 'content-type': 'application/json', authorization: `Bearer ${cfg.routerKey}` },
|
|
84
|
-
body: JSON.stringify({ query, count: cfg.maxResults }),
|
|
85
|
-
...(cfg.timeoutMs ? { signal: AbortSignal.timeout(cfg.timeoutMs) } : {}),
|
|
86
|
-
})
|
|
87
|
-
if (!sres.ok) {
|
|
88
|
-
// Surface, never silently degrade to parametric — a failed search must be visible.
|
|
89
|
-
console.warn(` [search FAIL ${taskId}#${attempt}] HTTP ${sres.status}: ${(await sres.text()).slice(0, 140)}`)
|
|
90
|
-
} else {
|
|
91
|
-
const sb = (await sres.json()) as { data?: Array<{ title?: string; url?: string; snippet?: string }> }
|
|
92
|
-
const hits = sb.data ?? []
|
|
93
|
-
searches = hits.length
|
|
94
|
-
// Fetch the full page text of the top-K results (snippets rarely carry exact figures).
|
|
95
|
-
const fetched = await Promise.all(hits.slice(0, cfg.fetchTopK).map((h) => (h.url ? fetchPage(h.url, cfg) : Promise.resolve(''))))
|
|
96
|
-
context = hits
|
|
97
|
-
.map((h, i) => `[${i + 1}] ${h.title ?? ''}\n${h.snippet ?? ''}\n${h.url ?? ''}${fetched[i] ? `\nPAGE CONTENT:\n${fetched[i]}` : ''}`)
|
|
98
|
-
.join('\n\n')
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
// 2) Answer — no tools (content always present), COMMIT (no deferral), via the shared router primitive.
|
|
103
|
-
const commit =
|
|
104
|
-
'You have no further tools and cannot ask questions or request more research. ' +
|
|
105
|
-
'Output a SINGLE, FINAL answer to the question, leading with the value in the exact units and precision requested ' +
|
|
106
|
-
'(e.g. "Answer: -47.9 billion USD"). ' +
|
|
107
|
-
(useSearch
|
|
108
|
-
? 'Use the WEB SEARCH RESULTS below (snippets + fetched page content) as your primary evidence; cite the source. '
|
|
109
|
-
: 'Answer from your own knowledge. ') +
|
|
110
|
-
'If you are not fully certain, still COMMIT to your single best estimate — never refuse, defer, or reply with a question.'
|
|
111
|
-
const userContent = useSearch && context ? `${prompt}\n\n=== WEB SEARCH RESULTS (provider: ${cfg.search}) ===\n${context}` : prompt
|
|
112
|
-
const turn = await runBenchRouterTurn(
|
|
113
|
-
{
|
|
114
|
-
routerBaseUrl: cfg.routerBaseUrl,
|
|
115
|
-
routerKey: cfg.routerKey,
|
|
116
|
-
profile: {
|
|
117
|
-
name: 'research-shot-answerer',
|
|
118
|
-
harness: 'cli-base',
|
|
119
|
-
model: {
|
|
120
|
-
provider: 'tangle-router',
|
|
121
|
-
default: cfg.model,
|
|
122
|
-
metadata: { temperature: cfg.temperature },
|
|
123
|
-
},
|
|
124
|
-
prompt: { systemPrompt: commit },
|
|
125
|
-
},
|
|
126
|
-
...(cfg.timeoutMs ? { timeoutMs: cfg.timeoutMs } : {}),
|
|
127
|
-
},
|
|
128
|
-
userContent,
|
|
129
|
-
)
|
|
130
|
-
const answer = turn.finalText.trim()
|
|
131
|
-
const ok = answer.length > 0
|
|
132
|
-
return { taskId, attempt, answer, ok, searches, wallMs: Date.now() - startedAt, ...(ok ? {} : { detail: `empty answer (searches=${searches})` }) }
|
|
133
|
-
} catch (err) {
|
|
134
|
-
return {
|
|
135
|
-
taskId,
|
|
136
|
-
attempt,
|
|
137
|
-
answer: '',
|
|
138
|
-
ok: false,
|
|
139
|
-
searches,
|
|
140
|
-
wallMs: Date.now() - startedAt,
|
|
141
|
-
detail: `rollout error: ${(err instanceof Error ? err.message : String(err)).slice(0, 200)}`,
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
}
|
package/src/router-executor.ts
DELETED
|
@@ -1,51 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Router-backed research executor — the "router" cost-dial backend (experiment.ts:
|
|
3
|
-
* "backend = the injected SandboxClient (router / bridge / sandbox)"). Each run is
|
|
4
|
-
* ONE research shot (router web-search + answer, off-sandbox); its answer is the
|
|
5
|
-
* terminal `finalText` the kernel's `answerOutput` parses.
|
|
6
|
-
*
|
|
7
|
-
* Why off-sandbox: research is retrieval, not in-box code execution — it never
|
|
8
|
-
* needed a box, and a real sandbox box reaches only the router (egress allowlist,
|
|
9
|
-
* ops-board #976), so it cannot web-search natively anyway. Driving the loop with
|
|
10
|
-
* this executor instead of a box gives the REAL `runAgentRounds` kernel full `rounds` +
|
|
11
|
-
* analyst steering (the depth regime), search working, no sandbox dependency.
|
|
12
|
-
*
|
|
13
|
-
* This is a BYO `Executor` over `runResearchShot`; `inlineSandboxClient` supplies
|
|
14
|
-
* the one shared box-shell so this file owns only the research-shot specifics
|
|
15
|
-
* (no hand-rolled create/streamPrompt/delete). A fresh executor per round ⇒ no
|
|
16
|
-
* fork/live session; statefulness is the across-round steer, not a box.
|
|
17
|
-
*/
|
|
18
|
-
import {
|
|
19
|
-
type ExecutorFactory,
|
|
20
|
-
type ExecutorResult,
|
|
21
|
-
inlineSandboxClient,
|
|
22
|
-
type SandboxClient,
|
|
23
|
-
} from '@tangle-network/agent-runtime/kernel'
|
|
24
|
-
import { runResearchShot, type ShotCfg } from './research-shot'
|
|
25
|
-
|
|
26
|
-
export function routerSandboxClient(cfg: ShotCfg): SandboxClient {
|
|
27
|
-
let seq = 0
|
|
28
|
-
const factory: ExecutorFactory<unknown> = () => {
|
|
29
|
-
const id = `router-research-${seq++}`
|
|
30
|
-
let artifact: ExecutorResult<unknown> | undefined
|
|
31
|
-
return {
|
|
32
|
-
runtime: 'router',
|
|
33
|
-
async execute(task): Promise<ExecutorResult<unknown>> {
|
|
34
|
-
const started = Date.now()
|
|
35
|
-
const shot = await runResearchShot(String(task), id, 0, cfg)
|
|
36
|
-
artifact = {
|
|
37
|
-
outRef: `router-research:${id}`,
|
|
38
|
-
out: { content: shot.answer },
|
|
39
|
-
spent: { iterations: 1, tokens: { input: 0, output: 0 }, usd: 0, ms: Date.now() - started },
|
|
40
|
-
}
|
|
41
|
-
return artifact
|
|
42
|
-
},
|
|
43
|
-
teardown: () => Promise.resolve({ destroyed: true }),
|
|
44
|
-
resultArtifact() {
|
|
45
|
-
if (!artifact) throw new Error('routerSandboxClient: resultArtifact() read before execute()')
|
|
46
|
-
return artifact
|
|
47
|
-
},
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
return inlineSandboxClient(factory)
|
|
51
|
-
}
|