@tangle-network/agent-runtime 0.94.13 → 0.96.1

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 (110) hide show
  1. package/README.md +64 -15
  2. package/dist/activation-B0ZD7nfX.d.ts +63 -0
  3. package/dist/agent.d.ts +6 -193
  4. package/dist/agent.js +10 -234
  5. package/dist/agent.js.map +1 -1
  6. package/dist/analyst-loop.d.ts +7 -10
  7. package/dist/analyst-loop.js +1 -2
  8. package/dist/candidate-execution/index.d.ts +43 -16
  9. package/dist/candidate-execution/index.js +17 -8
  10. package/dist/{chunk-VYA2YEKA.js → chunk-2KGAN2HM.js} +83 -14
  11. package/dist/chunk-2KGAN2HM.js.map +1 -0
  12. package/dist/chunk-3XKSBI2U.js +474 -0
  13. package/dist/chunk-3XKSBI2U.js.map +1 -0
  14. package/dist/{chunk-TVJQAYQM.js → chunk-6XKPVJAZ.js} +107 -716
  15. package/dist/chunk-6XKPVJAZ.js.map +1 -0
  16. package/dist/chunk-BLQIYRVR.js +699 -0
  17. package/dist/chunk-BLQIYRVR.js.map +1 -0
  18. package/dist/{chunk-QDSOD7RC.js → chunk-FD2MBMOH.js} +13 -101
  19. package/dist/chunk-FD2MBMOH.js.map +1 -0
  20. package/dist/{chunk-U33YZ7B2.js → chunk-FXF2OL34.js} +8 -8
  21. package/dist/{chunk-EP6RVHMX.js → chunk-HZDEXTSL.js} +848 -2
  22. package/dist/chunk-HZDEXTSL.js.map +1 -0
  23. package/dist/{chunk-WIPGQ4GT.js → chunk-IMSNJSXH.js} +1 -1
  24. package/dist/{chunk-WIPGQ4GT.js.map → chunk-IMSNJSXH.js.map} +1 -1
  25. package/dist/{chunk-VSWBYWFK.js → chunk-M6MD6JBS.js} +20 -27
  26. package/dist/chunk-M6MD6JBS.js.map +1 -0
  27. package/dist/chunk-PSOCBNM3.js +2069 -0
  28. package/dist/chunk-PSOCBNM3.js.map +1 -0
  29. package/dist/{chunk-AEG3NGJ2.js → chunk-Q2JSAVQ3.js} +34 -2
  30. package/dist/chunk-Q2JSAVQ3.js.map +1 -0
  31. package/dist/{chunk-XP5KDM3R.js → chunk-SGQ4YIQW.js} +4 -4
  32. package/dist/{chunk-C3UKLQ54.js → chunk-UQ6PNNXM.js} +18 -10
  33. package/dist/chunk-UQ6PNNXM.js.map +1 -0
  34. package/dist/{chunk-33OG2NN3.js → chunk-WYC2XJF2.js} +2 -2
  35. package/dist/{chunk-ZEYAT33L.js → chunk-Y3SRWZMP.js} +2 -2
  36. package/dist/{chunk-CNH7DF7Z.js → chunk-YOLKCWRV.js} +1116 -591
  37. package/dist/chunk-YOLKCWRV.js.map +1 -0
  38. package/dist/{completion-gate-D1gX1-hg.d.ts → completion-gate-C80jiRfN.d.ts} +1 -1
  39. package/dist/conversation.d.ts +12 -1
  40. package/dist/conversation.js +2 -3
  41. package/dist/{coordination-Dr_axlAf.d.ts → coordination-BFE3Den7.d.ts} +10 -11
  42. package/dist/environment-provider.d.ts +2 -2
  43. package/dist/environment-provider.js +1 -2
  44. package/dist/{agentic-generator-DDMM45kZ.d.ts → improve-g75IE2Cx.d.ts} +152 -4
  45. package/dist/{improvement-adapter-BieWeK5J.d.ts → improvement-adapter-HAZz-7vK.d.ts} +8 -31
  46. package/dist/index.d.ts +55 -28
  47. package/dist/index.js +206 -82
  48. package/dist/index.js.map +1 -1
  49. package/dist/intelligence.d.ts +185 -120
  50. package/dist/intelligence.js +509 -345
  51. package/dist/intelligence.js.map +1 -1
  52. package/dist/knowledge.d.ts +40 -12
  53. package/dist/knowledge.js +13 -7
  54. package/dist/{loop-runner-bin-BRQSQdHa.d.ts → loop-runner-bin-Cn1N2rRo.d.ts} +3 -3
  55. package/dist/loop-runner-bin.d.ts +6 -6
  56. package/dist/loop-runner-bin.js +8 -10
  57. package/dist/loops.d.ts +13 -13
  58. package/dist/loops.js +6 -8
  59. package/dist/mcp/bin.js +5 -7
  60. package/dist/mcp/bin.js.map +1 -1
  61. package/dist/mcp/index.d.ts +6 -6
  62. package/dist/mcp/index.js +12 -14
  63. package/dist/mcp/index.js.map +1 -1
  64. package/dist/platform.js +0 -2
  65. package/dist/platform.js.map +1 -1
  66. package/dist/primeintellect/index.js +1 -2
  67. package/dist/primeintellect/index.js.map +1 -1
  68. package/dist/profile-DbfaMTdk.d.ts +233 -0
  69. package/dist/profiles.d.ts +1 -1
  70. package/dist/profiles.js +0 -1
  71. package/dist/profiles.js.map +1 -1
  72. package/dist/{supervise-DmYOug5f.d.ts → supervise-BLPI50-w.d.ts} +3 -3
  73. package/dist/{types-ByAYqlVb.d.ts → types-B3vAW0Oq.d.ts} +1 -1
  74. package/dist/{prepare-CtdtsFNG.d.ts → types-CWqfCO8s.d.ts} +67 -298
  75. package/dist/{types-BC3bZpH0.d.ts → types-CmYCMbFT.d.ts} +12 -54
  76. package/dist/{types-1d5QGK3t.d.ts → types-CmnA2iL3.d.ts} +3 -3
  77. package/dist/{worktree-fanout-CPprU-qI.d.ts → worktree-fanout-DCA3G4bO.d.ts} +3 -3
  78. package/package.json +14 -16
  79. package/skills/build-with-agent-runtime/SKILL.md +122 -213
  80. package/dist/chunk-6O73TRHW.js +0 -142
  81. package/dist/chunk-6O73TRHW.js.map +0 -1
  82. package/dist/chunk-AEG3NGJ2.js.map +0 -1
  83. package/dist/chunk-C3UKLQ54.js.map +0 -1
  84. package/dist/chunk-CNH7DF7Z.js.map +0 -1
  85. package/dist/chunk-D3H7F6L2.js +0 -626
  86. package/dist/chunk-D3H7F6L2.js.map +0 -1
  87. package/dist/chunk-DGUM43GV.js +0 -11
  88. package/dist/chunk-DGUM43GV.js.map +0 -1
  89. package/dist/chunk-EP6RVHMX.js.map +0 -1
  90. package/dist/chunk-HGRW27YY.js +0 -214
  91. package/dist/chunk-HGRW27YY.js.map +0 -1
  92. package/dist/chunk-ISTDY47H.js +0 -849
  93. package/dist/chunk-ISTDY47H.js.map +0 -1
  94. package/dist/chunk-PCURO3DL.js +0 -661
  95. package/dist/chunk-PCURO3DL.js.map +0 -1
  96. package/dist/chunk-QDSOD7RC.js.map +0 -1
  97. package/dist/chunk-TVJQAYQM.js.map +0 -1
  98. package/dist/chunk-VSWBYWFK.js.map +0 -1
  99. package/dist/chunk-VYA2YEKA.js.map +0 -1
  100. package/dist/generator-YkAQrOoD.d.ts +0 -382
  101. package/dist/improve-BN3HyXIO.d.ts +0 -172
  102. package/dist/lifecycle.d.ts +0 -870
  103. package/dist/lifecycle.js +0 -981
  104. package/dist/lifecycle.js.map +0 -1
  105. package/dist/mcp-serve-verifier-DQQDbuyz.d.ts +0 -34
  106. package/skills/agent-runtime-adoption/SKILL.md +0 -246
  107. /package/dist/{chunk-U33YZ7B2.js.map → chunk-FXF2OL34.js.map} +0 -0
  108. /package/dist/{chunk-XP5KDM3R.js.map → chunk-SGQ4YIQW.js.map} +0 -0
  109. /package/dist/{chunk-33OG2NN3.js.map → chunk-WYC2XJF2.js.map} +0 -0
  110. /package/dist/{chunk-ZEYAT33L.js.map → chunk-Y3SRWZMP.js.map} +0 -0
@@ -1,7 +1,7 @@
1
1
  import { DefaultVerdict } from '@tangle-network/agent-eval';
2
2
  import { AgentProfile } from '@tangle-network/agent-interface';
3
3
  import { BackendType } from '@tangle-network/sandbox';
4
- import { L as LoopTokenUsage, R as RuntimeHooks } from './types-ByAYqlVb.js';
4
+ import { L as LoopTokenUsage, R as RuntimeHooks } from './types-B3vAW0Oq.js';
5
5
 
6
6
  /**
7
7
  *
@@ -385,8 +385,8 @@ type SpawnEvent = {
385
385
  };
386
386
  /**
387
387
  * The spawn-tree event source (mirrors `ConversationJournal`'s begin/append/load shape).
388
- * `loadTree` replays the full ordered event list for resume/replay; `appendEvent` is
389
- * called only AFTER the event is observed-committed (never speculative).
388
+ * `loadTree` returns events for inspection and completed-settlement replay, not live process
389
+ * recovery; `appendEvent` runs only AFTER the event is observed-committed (never speculative).
390
390
  */
391
391
  interface SpawnJournal {
392
392
  loadTree(root: NodeId): Promise<SpawnEvent[] | undefined>;
@@ -1,9 +1,9 @@
1
1
  import { AgentProfile } from '@tangle-network/agent-interface';
2
2
  import { AnalystFinding, DefaultVerdict } from '@tangle-network/agent-eval';
3
- import { d as AgentSpec, e as ExecutorRegistry, B as Budget, A as Agent, f as SpawnJournal, a as ResultBlobStore, g as RootHandle, b as SupervisedResult, N as NodeId, h as Settled, i as Spend, S as Scope, c as Executor } from './types-1d5QGK3t.js';
4
- import { R as RuntimeHooks, I as Iteration } from './types-ByAYqlVb.js';
3
+ import { d as AgentSpec, e as ExecutorRegistry, B as Budget, A as Agent, f as SpawnJournal, a as ResultBlobStore, g as RootHandle, b as SupervisedResult, N as NodeId, h as Settled, i as Spend, S as Scope, c as Executor } from './types-CmnA2iL3.js';
4
+ import { R as RuntimeHooks, I as Iteration } from './types-B3vAW0Oq.js';
5
5
  import { BackendType } from '@tangle-network/sandbox';
6
- import { W as WorktreeHarnessResult, G as GitRunner, a as WorktreeCheckRunner, D as DeliverableSpec } from './completion-gate-D1gX1-hg.js';
6
+ import { W as WorktreeHarnessResult, G as GitRunner, a as WorktreeCheckRunner, D as DeliverableSpec } from './completion-gate-C80jiRfN.js';
7
7
  import { L as LocalHarness, r as runLocalHarness } from './local-harness-ZqCx51u7.js';
8
8
 
9
9
  /**
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tangle-network/agent-runtime",
3
- "version": "0.94.13",
3
+ "version": "0.96.1",
4
4
  "description": "Shared task-lifecycle skeleton for agents: a recursive loop kernel for chat turns, one-shot tasks, and multi-attempt loops, with trace capture and eval-gated self-improvement. Domain behavior lives in adapters; scoring and ship-gates in @tangle-network/agent-eval.",
5
5
  "homepage": "https://github.com/tangle-network/agent-runtime#readme",
6
6
  "repository": {
@@ -49,11 +49,6 @@
49
49
  "import": "./dist/analyst-loop.js",
50
50
  "default": "./dist/analyst-loop.js"
51
51
  },
52
- "./lifecycle": {
53
- "types": "./dist/lifecycle.d.ts",
54
- "import": "./dist/lifecycle.js",
55
- "default": "./dist/lifecycle.js"
56
- },
57
52
  "./knowledge": {
58
53
  "types": "./dist/knowledge.d.ts",
59
54
  "import": "./dist/knowledge.js",
@@ -100,25 +95,27 @@
100
95
  "scripts": {
101
96
  "build": "tsup",
102
97
  "dev": "tsup --watch",
103
- "prepare": "(git rev-parse --git-dir > /dev/null 2>&1 && git config core.hooksPath .githooks) || true; tsup",
98
+ "prepublishOnly": "pnpm run build",
104
99
  "test": "vitest run",
105
100
  "test:watch": "vitest",
106
101
  "lint": "biome check src tests examples",
107
102
  "lint:fix": "biome check --write src tests examples",
108
103
  "typecheck": "tsc --noEmit && pnpm run typecheck:examples",
109
104
  "typecheck:examples": "tsc --noEmit -p tsconfig.examples.json",
105
+ "verify:bench": "pnpm --filter @tangle-network/agent-bench run typecheck:public && pnpm --filter @tangle-network/agent-bench test && pnpm --filter @tangle-network/agent-bench run verify:package:local-runtime",
106
+ "verify:bench:published": "pnpm --filter @tangle-network/agent-bench run typecheck:public && pnpm --filter @tangle-network/agent-bench test && pnpm --filter @tangle-network/agent-bench run verify:package",
110
107
  "verify:package": "node scripts/verify-package-exports.mjs",
111
108
  "verify:primeintellect": "pnpm build && node scripts/verify-primeintellect-v1.mjs",
112
109
  "verify:primeintellect:live": "pnpm build && node scripts/verify-primeintellect-live.mjs",
113
- "docs:api": "typedoc && node scripts/gen-primitive-catalog.mjs",
110
+ "docs:api": "pnpm run build && typedoc && node scripts/gen-primitive-catalog.mjs",
114
111
  "docs:freshness": "node scripts/check-docs-freshness.mjs",
115
112
  "docs:check": "pnpm run docs:api && git diff --exit-code -- docs/api && pnpm run docs:freshness"
116
113
  },
117
114
  "devDependencies": {
118
115
  "@biomejs/biome": "^2.4.15",
119
- "@tangle-network/agent-eval": "0.120.1",
120
- "@tangle-network/agent-interface": "0.26.1",
121
- "@tangle-network/sandbox": "^0.9.7",
116
+ "@tangle-network/agent-eval": "0.122.7",
117
+ "@tangle-network/agent-interface": "0.31.0",
118
+ "@tangle-network/sandbox": "^0.11.1",
122
119
  "@types/node": "^25.9.3",
123
120
  "@types/tar-stream": "3.1.4",
124
121
  "playwright": "^1.61.0",
@@ -134,6 +131,7 @@
134
131
  "minimumReleaseAgeExclude": [
135
132
  "@tangle-network/agent-eval",
136
133
  "@tangle-network/agent-interface",
134
+ "@tangle-network/agent-knowledge",
137
135
  "@tangle-network/agent-profile-materialize",
138
136
  "@tangle-network/sandbox"
139
137
  ],
@@ -147,9 +145,9 @@
147
145
  "license": "MIT",
148
146
  "packageManager": "pnpm@10.28.0",
149
147
  "peerDependencies": {
150
- "@tangle-network/agent-eval": ">=0.120.1 <0.121.0",
151
- "@tangle-network/agent-interface": ">=0.26.1 <0.27.0",
152
- "@tangle-network/sandbox": ">=0.8.0 <1.0.0",
148
+ "@tangle-network/agent-eval": ">=0.122.7 <0.123.0",
149
+ "@tangle-network/agent-interface": ">=0.31.0 <0.32.0",
150
+ "@tangle-network/sandbox": ">=0.11.1 <1.0.0",
153
151
  "playwright": "^1.40.0"
154
152
  },
155
153
  "peerDependenciesMeta": {
@@ -161,8 +159,8 @@
161
159
  }
162
160
  },
163
161
  "dependencies": {
164
- "@tangle-network/agent-knowledge": "^1.12.1",
165
- "@tangle-network/agent-profile-materialize": "0.3.2",
162
+ "@tangle-network/agent-knowledge": "^3.2.1",
163
+ "@tangle-network/agent-profile-materialize": "0.5.1",
166
164
  "tar-stream": "3.2.0"
167
165
  }
168
166
  }
@@ -1,217 +1,126 @@
1
1
  ---
2
2
  name: build-with-agent-runtime
3
- description: Use before hand-rolling a tool loop, driver, corpus, or optimizer wrapper. Create an agent genome, run it on a benchmark, optimize+gate it, observe/ship it with @tangle-network/agent-runtime. The genome→run→optimize→observe spine.
3
+ description: Use before adding an agent loop, benchmark, optimizer, trace wrapper, or candidate activation path. Find and compose the existing Runtime, Eval, Knowledge, and Interface primitives.
4
4
  ---
5
5
 
6
- # build-with-agent-runtime
7
-
8
- The one create→run→optimize→observe seam for `@tangle-network/agent-runtime`. A
9
- **genome** (an `AgentProfile`/`AgentSurfaces` systemPrompt + skills + tools +
10
- mcp + knowledge + memory + rag as ONE combined surface) runs as a
11
- **driver⟷worker** shape over a **benchmark**, gets **optimized by a gated loop**
12
- that evolves the genome and certifies wins on a **frozen holdout**, and is
13
- **observed** through the one lifecycle stream. The selector is never the judge;
14
- observation attaches to the loop, never to the portable genome.
15
-
16
- If you are about to write a `runConversation`, a "skill optimizer", a
17
- "profile-seam", a depth-vs-breadth A/B harness, a bootstrap loop, or a
18
- `new Sandbox(...)` + stream + read dance — **stop.** It exists, and a parallel
19
- silently breaks a load-bearing invariant (equal-k, selector≠judge,
20
- capture-integrity, or eval/prod parity).
21
-
22
- ## Load order point at source, never freeze snippets
23
-
24
- This skill carries **no API snippets**. The barrel MOVES (`./loops` is the
25
- runtime barrel), the agent-eval pin drifts, and signatures get
26
- corrected in place. Freezing a snippet here guarantees rot. Instead, read, in
27
- order, and re-verify against source:
28
-
29
- 1. **`docs/canonical-api.md`** the source of truth: the §2 decision table
30
- ("I want to X → use Y → NOT Z"), §3 per-subsystem signatures (each cited
31
- `file:line`), §4 the end-to-end recipe, §5 the recursive atom, §6 the
32
- two-substrate map. Every signature there was read from source.
33
- 2. **`grep` the export barrel** — `grep -nE 'export (function|const|type)' src/runtime/index.ts`
34
- (and `src/agent/index.ts`, `src/improvement/index.ts`, `src/mcp/index.ts`,
35
- `src/intelligence/index.ts`) for the live names + subpaths. `./loops` is the
36
- runtime barrel (`package.json` maps it to `src/runtime/index.ts`).
37
- 3. **`bench/HARNESS.md`** the experiment-harness map: commands, the
38
- `rollout corpus selector → CI → gate` flow, and the `ADAPTERS` registry
39
- (a harness-local export, `bench/src/adapters.ts`, not a package export).
40
-
41
- **Code wins.** If a name, subpath, or signature here or in `docs/canonical-api.md`
42
- disagrees with source, the **source is right** fix the map in the *same turn*
43
- (the anti-rediscovery law). Verify with Read/Edit, don't re-read to confirm.
44
-
45
- ## Decision table by altitude (each row ONE source, not a snippet)
46
-
47
- Read the cited `docs/canonical-api.md` row before writing; it carries the live
48
- signature + the exact "do NOT build".
49
-
50
- **The §1.5 law, inline:** an agent IS its full authored `AgentProfile`
51
- (prompt+skills+tools+mcp+subagents+hooks); you change behavior by AUTHORING the
52
- profile and letting the substrate materialize it into harness shapes —
53
- self-verification, iteration, and audit are profile levers (hooks/skills/
54
- subagents), never glue code.
55
-
56
- `AgentProfile` is owned by `@tangle-network/agent-interface` (the `/loops`
57
- barrel re-exports the sandbox alias as a one-stop import), which also owns
58
- `HarnessType` + `ReasoningEffort` and a capability layer
59
- (`harnessSupportsModel` / `reasoningEffortsFor`) — so harness/model/reasoning
60
- compatibility is a queryable contract, not an assumption.
61
-
62
- Harness is a RUN-layer coordinate, not part of the portable genome: it rides on
63
- agent-runtime's `AgentSpec { profile, harness }`. To sweep it as an eval axis,
64
- don't hand-declare a harness list expand one base profile across
65
- `CODING_HARNESSES` with `expandProfileAxes` (agent-eval), run with
66
- `runProfileMatrix`, and pivot results by the stamped `AgentProfileCell`
67
- (`groupRunsByAgentProfileCell`); `harnessSupportsModel` filters per harness,
68
- and a vendor-locked harness that supports none of the requested models SNAPS
69
- to its native default (`HARNESS_NATIVE_MODEL`) — never silently dropped.
70
-
71
- | Altitude I want to… | Use | Source |
72
- |---|---|---|
73
- | **Define a genome** (who the agent is + what it can do, ONE surface) | `AgentProfile` (runnable) / `AgentSurfaces` (the editable-coordinate map) — `/loops`, `/agent` | canonical-api §3.2 |
74
- | **Define the personified-run record** (model+prompt+tools+role+seams) | `definePersona(input)` — `/loops` | canonical-api §3.1 |
75
- | **Run a genome driver⟷worker, end-to-end** | `runPersonified({ persona, shape, task, budget })` — `/loops` | canonical-api §3.1 |
76
- | **Loop a worker over one evolving artifact, K rounds, stop-when-good** | `loopUntil(seed, spec)` as the `shape` — `/loops` | canonical-api §3.1 |
77
- | **Best-of-N / parallel-research at equal compute** | `fanout(items, opts)` — `/loops` | canonical-api §3.1 |
78
- | **Produce-then-gate / multi-judge quorum / fixed chain** | `verify` / `panel` / `pipeline` — `/loops` | canonical-api §3.1 |
79
- | **Run depth-vs-breadth (or a custom strategy) over a stateful tool domain** | `runAgentic({ surface, task, mode\|strategy, budget })` — `/loops` | canonical-api §3.3 |
80
- | **Author a new topology/strategy compactly** | `defineStrategy(name, body)` w/ `ctx.shot()`+`ctx.critique()` — `/loops` | canonical-api §3.3 |
81
- | **Add a stateful tool-using domain** | implement `AgenticSurface` (5 hooks) — `/loops` | canonical-api §3.3 |
82
- | **Drive a team of agents over a graded `AgenticSurface` task** (workers settle on its check, driver self-improves from the failing tests) | `superviseSurface(profile, task, { surface, worker })` — `/loops` | canonical-api §2 |
83
- | **Benchmark: compare strategies + significance + Pareto on a domain** | `runBenchmark({ environment, tasks, worker, strategies })` — `/loops` | canonical-api §3.3 |
84
- | **Author a PRODUCT eval leaderboard** (cases + prompt + grader → ranked board, standard flags, fresh run-dir, export, `toBenchmarkAdapter()`) | `defineLeaderboard({ name, cases, prompt, score, axis?, backends?, flags?, setup?/teardown?, onCellEvents?, resolveModel?, export?, dispatch?, judges?, matrix? })` — `/loops` — NOT a hand-assembled flag-parsing + `runProfileMatrix` frame; `runProfileMatrix` is the escape floor, the level-2 `dispatch` override is how in-process products plug in | `src/runtime/define-leaderboard.ts` (verify vs source) |
85
- | **Resolve a harness-in-box backend** (box / local cli-bridge / router leaf, one `SandboxClient` shape) | `resolveSandboxClient({ backend: 'sandbox' \| 'bridge' \| 'router' })` — `/loops` — NOT a per-product backend factory or a hand-faked box (`inlineSandboxClient` / the bridge executor already exist) | `src/runtime/resolve-sandbox-client.ts` |
86
- | **Resolve an in-process chat backend** (the one `--backend` branch for `runChatThroughRuntime` / `runAgentTaskStream`) | `resolveAgentBackend({ kind: 'router' \| 'tcloud' \| 'cli-bridge' \| 'sandbox' })` — root `.` | `src/resolve-agent-backend.ts` |
87
- | **Run ONE agent turn as one normalized event stream** (box, executor, or chat backend; guaranteed terminal result+usage) | `streamAgentTurn(backend, prompt, { signal, timeoutMs })` + `collectAgentTurn(stream)` — `/loops` | canonical-api §2 |
88
- | **Benchmark report: multi-profile × multi-axis leaderboard** (ranked board + score matrix + SVG/HTML charts, any `RunRecord[]`) | `leaderboard(records)` + `renderLeaderboardMarkdown` / `renderLeaderboardSvg` / `renderLeaderboardHtml` — `/loops` | canonical-api §2 |
89
- | **Meter one `openSandboxRun` cell's token/cost usage** | `sumSandboxUsage(events)` — `/loops` | canonical-api §2 |
90
- | **Sweep harness × model as an eval axis** (turn one base profile into the full harness × model set) | `expandProfileAxes({ base, harnesses, models })` over `CODING_HARNESSES` → `runProfileMatrix(...)`, pivot with `groupRunsByAgentProfileCell` — `agent-eval` root — NOT a hand-declared `HARNESSES` list | agent-eval root (verify vs source) |
91
- | **Benchmark: add/run an external benchmark from the harness** | `ADAPTERS`/`resolveAdapter(key)` + a bench gate (`*-gate.mts`) over `openSandboxRun` + `sandboxAgentRun` (`bench/src/sandbox-run.ts`) | canonical-api §3.3 |
92
- | **Spawn N coding agents on isolated git worktrees, keep the one whose patch passes checks** | `worktreeFanout` + `createWorktreeCliExecutor` + `gateOnDeliverable(DeliverableSpec)` over a raw `WorktreePatchArtifact`, winner via `selectValidWinner` — `/loops` — NOT a hand-rolled spawn-loop / "coder" role | canonical-api §3.1 / §5 |
93
- | **Sandbox coding rollout** (fresh box/round, or persistent+resume) | `runLoop(options)` / `openSandboxRun(client, opts, deliverable)` — `/loops` | canonical-api §3.1 |
94
- | **Optimize a CODE surface** in a gated loop | `improvementDriver({ worktree, generator })` — root `.` | canonical-api §3.4 |
95
- | **Freeze a measured profile/diff + code surface for execution** | `buildAgentCandidateBundle(...)` then `verifyAgentCandidateBundle(...)` — `/candidate-execution` | canonical-api §2 |
96
- | **Optimize any agent/code surface** (one call) — START HERE | `improve(profile, findings, { surface, gate })` — root `.`; prompt, skill-document, and curated-memory surfaces have built-in proposers, config/whole-profile surfaces accept a proposer, and code gets isolated incumbent/candidate worktrees. Workflow and rollout-policy files use code plus agent-eval's `parameterSweepProposer` for JSON sweeps; drop to `selfImprove({ agent, scenarios, judge, baselineSurface })` only for lower-level control | canonical-api §3.4 |
97
- | **Gate: ship/hold a candidate** (campaign ctx) | `defaultProductionGate` / `heldOutGate` / `composeGate` — `agent-eval/contract`; `neutralizationGate` (footprint-matched PLACEBO gate — proves a held-out lift is CONTENT, not added prompt/mount footprint) — `agent-eval/campaign` | canonical-api §3.4 |
98
- | **Gate: ship/hold from a `BenchmarkReport`** (per-task cells) | `promotionGate({ report, incumbent, candidate })` `/loops` | canonical-api §3.4 |
99
- | **Run the full multi-generation flywheel + certify** | `runStrategyEvolution(config)` `/loops` | canonical-api §3.4 |
100
- | **Observe a run** (cost/time waterfall, OTLP) | `createWaterfallCollector()` — `/loops`; `createOtelExporter` attached via `composeRuntimeHooks(...)` — root `.` | canonical-api §2 |
101
- | **State any A/B claim** | `pairedLift` (bench) over `pairedBootstrap`/`heldoutSignificance` (substrate) | canonical-api §3.5 |
102
- | **Observe + deliver on a live agent with billing-boundary** | `withIntelligence(agent, { project, target, effort })` — `/intelligence` | canonical-api §2 |
103
- | **Pull the certified profile from the Intelligence plane** (pull-by-default delivery: fold the gate-certified prompt onto the base surface) | `pullCertified` / `withIntelligence` / `composeCertifiedPrompt` — `/intelligence` | `src/intelligence/delivery.ts` |
104
-
105
- ## Do-NOT-reinvent the traps this skill exists to stop
106
-
107
- Each of these gets hand-rolled every session; the canonical primitive already
108
- holds the load-bearing invariant the parallel breaks:
109
-
110
- - `runConversation` / persona-runner / `while(!done)` steering loop **≈**
111
- `loopUntil` + `runPersonified` (threads executor seams; equal-k; selector≠judge
112
- firewall; journal/replay — a parallel runner silently fails to wire the seams).
113
- - "skill optimizer" / "topology mutator" that opens branches + applies patches
114
- **≈** `improvementDriver` (code surface) or `selfImprove`/`gepaProposer` (prompt
115
- surface) both gated on a frozen holdout.
116
- - "profile-seam" / agent-config wrapper carrying model+prompt+tools+role **≈**
117
- `AgentProfile` (it IS that bundle) + `definePersona` (the run record);
118
- `sandboxAgentRun({ profile })` is the box seam — never pass a router key into
119
- the box.
120
- - "drive N coding agents in worktrees + pick the passing patch" / a "coder" role
121
- **≈** `worktreeFanout` + `gateOnDeliverable` (each on its own worktree-CLI leaf,
122
- settled ⟺ delivered, winner via `selectValidWinner` — a hand-rolled spawn-loop
123
- skips the deliverable gate and the valid-only selection).
124
- - `new Sandbox()` + acquire + stream + `box.fs.read` + delete **≈**
125
- `openSandboxRun` (persistent + resume) or `runLoop` (fresh box/round).
126
- - `Promise.all` over N calls + manual argmax/merge **≈** `fanout` (bypassing the
127
- budget pool breaks equal-compute claims).
128
- - a per-step cost/token tally over events **≈** `createWaterfallCollector` (the
129
- sum of spans IS the billed run cost; a parallel tally drifts).
130
- - your own bootstrap loop / PRNG per gate **≈** `pairedLift` / `promotionGate`
131
- (seeded, identical run-to-run; never report a point lift without `low/high/pairs`).
132
- - a per-product `HARNESSES` / `HarnessBackend` list + a metadata-harness reader
133
- **≈** `CODING_HARNESSES` + `expandProfileAxes` (the one canonical harness list;
134
- vendor-locked harnesses SNAP to their native model via `HARNESS_NATIVE_MODEL`,
135
- never dropped) and the
136
- `AgentProfileCell` stamped by `runProfileMatrix`, pivoted via
137
- `groupRunsByAgentProfileCell` — never bake the harness into the model id so the
138
- same model can run under multiple harnesses.
139
- - a per-product leaderboard CLI (flag parsing + run-dir management + axis
140
- expansion + a `runProfileMatrix` call + export/markdown) **≈**
141
- `defineLeaderboard` (0.84+; it owns that whole frame — FRESH default run-dir,
142
- standard `--backend`/`--harnesses`/`--models`/`--cases`/`--shots`/`--reps`
143
- flags, `toBenchmarkAdapter()`; the product writes ~150-250 domain lines).
144
- - a backend factory / `if (backend === 'router') ... else ...` branch or a
145
- hand-faked box around a non-box executor **≈** `resolveSandboxClient`
146
- (harness-in-box: `'sandbox' | 'bridge' | 'router'`) or `resolveAgentBackend`
147
- (in-process: `'router' | 'tcloud' | 'cli-bridge' | 'sandbox'`) — grep the
148
- substrate first; `inlineSandboxClient` and the bridge executor exist.
149
- - a per-provider stream→event mapper for a single agent turn **≈**
150
- `streamAgentTurn` + `collectAgentTurn` (0.85+; one `RuntimeStreamEvent`
151
- contract over box / executor / chat, guaranteed terminal result+usage).
152
-
153
- ## End-to-end recipe
154
-
155
- `docs/canonical-api.md` §4 is the real composition — copy it from there, don't
156
- re-derive: **define a genome → run driver⟷worker via the reactive substrate over
157
- a multi-turn `AgenticSurface` → measure with `runBenchmark` → optimize a prompt
158
- surface with `selfImprove` → certify on a frozen holdout with the gate.** For the
159
- multi-generation flywheel, replace the measure/certify steps with one
160
- `runStrategyEvolution(...)` and read `report.verdict` (NOT `report.trajectory`)
161
- as the evidence. For a sandbox coding rollout judged by an external deterministic
162
- checker, use the bench-gate path: `resolveAdapter(...)` to pick the benchmark,
163
- then `openSandboxRun(client, { agentRun: sandboxAgentRun({ profile }), ... },
164
- deliverable)` per task, A/B-ing a blind arm against an `llmAnalyst`-steered arm
165
- at equal compute (both helpers live in `bench/src/sandbox-run.ts`; the blind arm
166
- is the mandatory equal-compute control). See `bench/src/commit0-gate.mts` /
167
- `gate.ts` for the live shape.
168
-
169
- ## Two substrates — pick one, don't invent a third
170
-
171
- Both implement the same recursive-decision atom over the one `Executor` port and
172
- share `defaultSelectWinner`. **Reactive** (`Supervisor`/`Scope` + personify
173
- combinators: `runPersonified`/`runAgentic`/`runBenchmark`) — prefer for NEW
174
- recursive work; equal-k by construction. **Round-synchronous** (`runLoop` driven
175
- by a caller-supplied `Driver`, plus the bench gates over `openSandboxRun`) —
176
- sandbox coding rollouts against external benchmarks. The full when-which map is
177
- `docs/canonical-api.md` §6.
178
-
179
- ## Observe / ship with the Intelligence SDK
180
-
181
- One hook wraps any agent with send + receive + billing boundary:
182
- `withIntelligence(agent, { project, target, effort })`, `effort ∈
183
- off|eco|standard|thorough|max` (`'off'` is the provable passthrough floor —
184
- intelligence spend clamped to 0). It SENDs a typed `RunRecord` and RECEIVEs the
185
- certified profile, building on `createOtelExporter` + `buildLoopOtelSpans` —
186
- don't hand-roll a trace-wrapper, a second receive path, or effort/tier config.
187
- Verify the live subpath against `src/intelligence/with-intelligence.ts`.
188
-
189
- Two operational facts every consumer must know:
190
-
191
- - **Send is a silent no-op without a tenant apiKey.** The export leg only ships
192
- when an `apiKey` (or `TANGLE_API_KEY`) is present — the ingest requires the
193
- tenant Bearer. One `baseUrl` (`TANGLE_INTELLIGENCE_URL`, default
194
- `https://intelligence.tangle.tools`) drives both the OTLP send (`/v1/otlp`)
195
- and the receive pull. The client's `doctor().exportConfigured` is the check
196
- that a send will actually land.
197
- - **Delivery pulls the certified profile from the plane.** `pullCertified` /
198
- `withIntelligence` hit
199
- `GET {baseUrl}/v1/profiles/:target/composed` with `Bearer TANGLE_API_KEY`;
200
- the pull deserializes the typed `agentProfileDiffs` (surfaced as PROPOSALS,
201
- never auto-applied) alongside the certified prompt. `withIntelligence` folds
202
- the certified prompt onto the base surface, refreshes at most every 5 minutes,
203
- and is fail-closed — a failed pull runs the agent on its base surface.
204
-
205
- ## Final check
206
-
207
- - Picked a primitive from the decision table, not a hand-rolled parallel?
208
- - Genome is ONE `AgentProfile`/`AgentSurfaces` surface, not split skill/tool/prompt knobs?
209
- - Equal compute preserved (budget pool, or `arms[0]` control) — no `Promise.all` zoo?
210
- - Selector ≠ judge: no judge score feeding a driver/another judge; holdout score write-only?
211
- - Any win certified on a FROZEN holdout via a gate, never on the training composite?
212
- - Map fixed in the same turn if source disagreed with `docs/canonical-api.md`?
213
-
214
- See `_common.md` for shared conventions (frontmatter, fail-loud, no AI attribution).
215
-
216
- Next: build the genome/loop/optimizer against `docs/canonical-api.md` §3–§4; if a
217
- strategy beats incumbent on the holdout gate, `/ship` it.
6
+ # Build with agent-runtime
7
+
8
+ Use this skill before writing product-local agent infrastructure.
9
+ The goal is one portable agent definition, one execution path, one measurement system, and one reviewed activation path.
10
+
11
+ ## Read first
12
+
13
+ 1. Read `docs/canonical-api.md` for the current decision table.
14
+ 2. Check exports in `src/index.ts`, `src/runtime/index.ts`, `src/improvement/index.ts`, `src/intelligence/index.ts`, and `src/knowledge/index.ts`.
15
+ 3. Read the nearest runnable example.
16
+ 4. Treat source as authoritative when docs disagree, then correct the stale doc in the same change.
17
+
18
+ ## Ownership
19
+
20
+ | Concern | Owner |
21
+ |---|---|
22
+ | Portable prompt, skills, tools, MCP, hooks, subagents, model hints | `AgentProfile` from `@tangle-network/agent-interface` |
23
+ | Agent execution, supervision, budgets, streaming, candidate execution | `@tangle-network/agent-runtime` |
24
+ | Tasks, graders, search, paired statistics, cost and latency comparison | `@tangle-network/agent-eval` |
25
+ | Sources, retrieval, citations, freshness, memory adapters, knowledge promotion | `@tangle-network/agent-knowledge` |
26
+ | Product records, permissions, funding, UI, and atomic storage writes | The consuming product |
27
+
28
+ Do not move shared measurement into Runtime or product code.
29
+ Do not move product storage transactions into a provider-neutral package.
30
+
31
+ ## Choose the entry point
32
+
33
+ | Need | Use |
34
+ |---|---|
35
+ | One product chat turn | `handleChatTurn(...)` |
36
+ | One normalized streamed agent turn | `streamAgentTurn(...)` and `collectAgentTurn(...)` |
37
+ | One task or multi-turn loop | `runAgentTask(...)`, `runAgentTaskStream(...)`, or `runLoop(...)` |
38
+ | Supervisor and workers | `supervise(...)` or `superviseSurface(...)` |
39
+ | Parallel work with a shared budget | `fanout(...)` |
40
+ | Fixed composition | `pipeline(...)`, `panel(...)`, or `verify(...)` |
41
+ | Product benchmark | `defineLeaderboard(...)` |
42
+ | Profile matrix | `expandProfileAxes(...)` and `runProfileMatrix(...)` from agent-eval |
43
+ | Search one agent surface | `improve(...)` |
44
+ | Analyze traces through a measured proposal | `proposeAgentImprovement(...)` |
45
+ | Review and authorize an exact proposal | `reviewAgentImprovementProposal(...)` and `createAgentImprovementActivation(...)` |
46
+ | Apply or restore an approved candidate | `executeAgentImprovementActivation(...)` with a product transaction |
47
+ | Build a knowledge candidate | `runKnowledgeImprovementJob(...)` |
48
+ | Apply a knowledge candidate | `createKnowledgeImprovementActivationExecutor(...)` through the same activation path |
49
+ | Observe and pull approved changes on a live agent | `withIntelligence(...)` |
50
+
51
+ ## Improvement flow
52
+
53
+ `improve(profile, findings, options)` searches one surface and returns a detached winner.
54
+ It never changes a profile, document, repository, memory store, or knowledge base.
55
+
56
+ Supported profile surfaces are prompt, one named inline skill, tools, MCP, hooks, subagents, whole profile, and curated memory in `profile.resources.instructions`.
57
+ Code uses isolated worktrees and returns a sealed patch candidate.
58
+ Knowledge uses `runKnowledgeImprovementJob(...)` and returns paired snapshots.
59
+
60
+ Use `proposeAgentImprovement(...)` for a production proposal.
61
+ It performs these steps in order:
62
+
63
+ 1. Analyze completed traces.
64
+ 2. Search for a candidate on development tasks.
65
+ 3. Freeze the baseline and winner into one exact experiment.
66
+ 4. Reject the experiment if its candidate differs from the search winner.
67
+ 5. Run baseline and candidate on the same held-back tasks.
68
+ 6. Produce findings, confidence intervals, quality, cost, latency, and a decision.
69
+
70
+ After a person or tenant policy approves the proposal, call `createAgentImprovementActivation(...)` with target identities, funding owner, authority, intent, and expiry.
71
+ Runtime derives the expected current digests from the measured experiment.
72
+ Call `executeAgentImprovementActivation(...)` with one product-owned transaction that compares current state, writes every target atomically, and stores the result under the activation digest.
73
+ Pass a read-only reconciliation function so retries can distinguish committed, uncommitted, and uncertain outcomes.
74
+
75
+ Never apply a change from analyst confidence alone.
76
+ Never measure one candidate and apply another.
77
+ Never let search code write live state.
78
+ Never treat a lost response as a failed write without reconciling it.
79
+
80
+ ## Surface rules
81
+
82
+ - Prompt changes `profile.prompt` only.
83
+ - Skill optimization selects one inline skill by `skills.resourceName`; profile resources must fail closed.
84
+ - Curated memory changes `profile.resources.instructions`; retrieval stores and memory databases belong in the knowledge flow.
85
+ - Tools, MCP, hooks, subagents, and whole-profile changes require an explicit proposer because Runtime cannot invent domain capabilities safely.
86
+ - Code candidates must come from the Runtime worktree path so patch identity and cleanup stay intact.
87
+ - Workflow and policy files are code surfaces; parameter sweeps come from agent-eval.
88
+ - Knowledge candidates remain detached until the shared activation path applies or restores their frozen snapshots.
89
+
90
+ ## Product integration
91
+
92
+ The product supplies only the pieces that vary by deployment:
93
+
94
+ - How traces and current profiles are loaded.
95
+ - How exact candidate execution is placed on compute.
96
+ - How proposal, review, activation, and result records are persisted.
97
+ - How a target is changed atomically.
98
+ - Who may approve, reject, request changes, fund, apply, or restore.
99
+ - How those records and actions appear in the UI or API.
100
+
101
+ The product must not recreate candidate hashing, paired comparison, confidence intervals, review binding, expiry, retry identity, or result validation.
102
+
103
+ ## Do not duplicate
104
+
105
+ - Do not write a provider-specific profile wrapper; extend `AgentProfile` and its materializer.
106
+ - Do not write a second optimizer loop; compose Eval proposers through `improve(...)`.
107
+ - Do not write a second candidate catalog; persist the immutable proposal records.
108
+ - Do not let an analyst or adapter commit, push, open a pull request, or edit a live store.
109
+ - Do not hand-roll SSE parsing, usage totals, profile matrices, bootstrap statistics, sandbox acquisition, or worktree cleanup.
110
+ - Do not add a product-local approval format for knowledge, code, or profile changes.
111
+
112
+ ## Finish
113
+
114
+ - The same agent definition runs in product and measurement paths.
115
+ - The held-back tasks were not visible during search.
116
+ - Candidate identity is checked before execution and again before activation.
117
+ - Quality, cost, latency, sample count, and uncertainty are retained.
118
+ - Rejection and request-changes are first-class outcomes.
119
+ - Activation is authorized, expiring, idempotent, and reconcilable.
120
+ - No customer write, message, trigger, or billing occurs in read-only proof mode.
121
+ - Public examples, package exports, generated API docs, type checks, tests, build, and package verification pass.
122
+
123
+ ## Then consider
124
+
125
+ - Use `critical-audit` when the change introduces or alters a public contract.
126
+ - Use `verify` before publishing or adopting the package in a product.