@tangle-network/agent-bench 0.8.15 → 0.8.16

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.
@@ -1,128 +0,0 @@
1
- /**
2
- * OFFLINE seams for the codemode-skill improvement harness — copied from
3
- * `examples/graphs/shared.ts` (the same two seams the kernel's own graph tests use), with the
4
- * imports rewritten to the worktree's own src so the bench runs against the in-repo kernel
5
- * without a dist build:
6
- *
7
- * • `scriptedBrain` — a `ToolLoopChat` that plays a fixed sequence of driver turns.
8
- * • `leafSeam` — a `MakeWorkerAgent` whose leaf executors settle instantly.
9
- *
10
- * Only the leaf `act` and the driver brain are scripted; the graph machinery around them
11
- * (node pinning, directive delivery, edge ledger, journal twin) is the real shipped path.
12
- */
13
-
14
- import type { AgentProfile } from '@tangle-network/agent-interface'
15
- import {
16
- type Agent,
17
- type AgentSpec,
18
- createPushTraceSource,
19
- type Executor,
20
- type ExecutorResult,
21
- type MakeWorkerAgent,
22
- type TraceSource,
23
- } from '../../../src/runtime/index.ts'
24
- import type { ToolLoopChat } from '../../../src/testing/index.ts'
25
-
26
- // ── The scripted driver brain ──────────────────────────────────────────────────
27
-
28
- /** A scripted driver turn in the easy-to-write form (parsed tool args). */
29
- export interface ScriptedTurn {
30
- content?: string
31
- toolCalls?: Array<{ id?: string; name: string; arguments: Record<string, unknown> }>
32
- }
33
-
34
- /** Build a scripted `ToolLoopChat` brain from a fixed turn sequence. */
35
- export function scriptedBrain(turns: ScriptedTurn[]): ToolLoopChat {
36
- let i = 0
37
- return async () => {
38
- const turn = turns[Math.min(i, turns.length - 1)] ?? {}
39
- i += 1
40
- return {
41
- ...(turn.content !== undefined ? { content: turn.content } : {}),
42
- toolCalls: (turn.toolCalls ?? []).map((tc, j) => ({
43
- id: tc.id ?? `call-${i}-${j}`,
44
- name: tc.name,
45
- arguments: JSON.stringify(tc.arguments),
46
- })),
47
- }
48
- }
49
- }
50
-
51
- // ── The leaf seam ──────────────────────────────────────────────────────────────
52
-
53
- /** What one settle of a node should produce (per spawn ordinal; the last entry repeats). */
54
- export interface LeafShot {
55
- out: unknown
56
- valid: boolean
57
- score?: number
58
- }
59
-
60
- export interface LeafOptions {
61
- /** Block settlement until a deliver() arrives — so a steer can reach a LIVE worker. */
62
- awaitSteer?: boolean
63
- /** Expose a live tool-trace source so settle-time analysts have evidence to read. */
64
- withTrace?: boolean
65
- /** Per-spawn scripts for this node (last entry repeats). Omit for a generic valid settle. */
66
- shots?: ReadonlyArray<LeafShot>
67
- }
68
-
69
- /** A leaf-agent factory keyed by node name; every spawned profile is captured into `received`. */
70
- export function leafSeam(
71
- received: AgentProfile[],
72
- optsByNode: Record<string, LeafOptions> = {},
73
- ): MakeWorkerAgent {
74
- const attempts = new Map<string, number>()
75
- return (profile) => {
76
- received.push(profile)
77
- const name = profile.name ?? 'leaf'
78
- const opts = optsByNode[name] ?? {}
79
- const attempt = (attempts.get(name) ?? 0) + 1
80
- attempts.set(name, attempt)
81
- const shot = opts.shots?.[Math.min(attempt - 1, opts.shots.length - 1)]
82
- let release: (() => void) | undefined
83
- const gate = opts.awaitSteer
84
- ? new Promise<void>((resolve) => {
85
- release = resolve
86
- })
87
- : undefined
88
- const trace = opts.withTrace
89
- ? createPushTraceSource({ runId: `leaf-${name}-${attempt}` })
90
- : undefined
91
- let artifact: ExecutorResult<unknown> | undefined
92
- const ex: Executor<unknown> = {
93
- runtime: 'router',
94
- ...(opts.awaitSteer
95
- ? {
96
- deliver: () => {
97
- release?.()
98
- return true
99
- },
100
- }
101
- : {}),
102
- ...(trace ? { traceSource: (): TraceSource => trace.source } : {}),
103
- async execute() {
104
- if (trace) {
105
- trace.record({ toolName: 'write_file', args: { path: `${name}.ts` }, status: 'ok' })
106
- }
107
- if (gate) await gate
108
- const valid = shot ? shot.valid : true
109
- artifact = {
110
- outRef: `w:${name}:${attempt}`,
111
- out: shot ? shot.out : { built: name, attempt },
112
- verdict: { valid, score: shot?.score ?? (valid ? 1 : 0) },
113
- spent: { iterations: 1, tokens: { input: 5, output: 5 }, usd: 0, ms: 0 },
114
- }
115
- return artifact
116
- },
117
- teardown: () => Promise.resolve({ destroyed: true }),
118
- resultArtifact: () => {
119
- if (!artifact) throw new Error(`leaf ${name}: no terminal artifact`)
120
- return artifact
121
- },
122
- }
123
- const spec: AgentSpec = { profile, harness: null, executor: ex }
124
- return { name, act: async () => undefined, executorSpec: spec } as Agent<unknown, unknown> & {
125
- executorSpec: AgentSpec
126
- }
127
- }
128
- }