@tangle-network/agent-runtime 0.105.0 → 0.106.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/README.md +2 -2
- package/dist/activation-CRjVfOiy.js +203 -0
- package/dist/activation-CRjVfOiy.js.map +1 -0
- package/dist/activation-DyWB0K6E.d.ts +98 -0
- package/dist/agent.d.ts +216 -234
- package/dist/agent.js +615 -547
- package/dist/agent.js.map +1 -1
- package/dist/analyst-loop-DGdtVENg.js +517 -0
- package/dist/analyst-loop-DGdtVENg.js.map +1 -0
- package/dist/analyst-loop.d.ts +10 -43
- package/dist/analyst-loop.js +2 -11
- package/dist/backends-Dy8NujB4.js +713 -0
- package/dist/backends-Dy8NujB4.js.map +1 -0
- package/dist/candidate-execution/index.d.ts +4 -192
- package/dist/candidate-execution/index.js +5 -66
- package/dist/candidate-execution-DqMbv1rU.js +488 -0
- package/dist/candidate-execution-DqMbv1rU.js.map +1 -0
- package/dist/coder-yhVWbdWc.js +40 -0
- package/dist/coder-yhVWbdWc.js.map +1 -0
- package/dist/conversation-XucG_K3l.js +1265 -0
- package/dist/conversation-XucG_K3l.js.map +1 -0
- package/dist/conversation.d.ts +2 -804
- package/dist/conversation.js +2 -55
- package/dist/environment-provider-CfLUmKmf.js +1168 -0
- package/dist/environment-provider-CfLUmKmf.js.map +1 -0
- package/dist/environment-provider-IUGU3epE.d.ts +964 -0
- package/dist/environment-provider.d.ts +2 -78
- package/dist/environment-provider.js +2 -18
- package/dist/errors-DEAvWQPy.js +111 -0
- package/dist/errors-DEAvWQPy.js.map +1 -0
- package/dist/improvement-adapter-Cr5TBSji.d.ts +166 -0
- package/dist/improvement-cycle-C095kS_g.js +2624 -0
- package/dist/improvement-cycle-C095kS_g.js.map +1 -0
- package/dist/index-BGdxAwfO.d.ts +838 -0
- package/dist/index-C-FYUuFG.d.ts +193 -0
- package/dist/index-CbNM40xG.d.ts +140 -0
- package/dist/index-DruSKs3Z.d.ts +7224 -0
- package/dist/index-Efjb3nrQ.d.ts +671 -0
- package/dist/index.d.ts +14 -1058
- package/dist/index.js +2106 -2082
- package/dist/index.js.map +1 -1
- package/dist/intelligence.d.ts +768 -889
- package/dist/intelligence.js +1466 -1367
- package/dist/intelligence.js.map +1 -1
- package/dist/{kb-gate-CwHO0vz6.d.ts → kb-gate-C8z2juK8.d.ts} +33 -31
- package/dist/kb-gate-DpaSwXVx.js +80 -0
- package/dist/kb-gate-DpaSwXVx.js.map +1 -0
- package/dist/knowledge-Ku-mPP4f.js +433 -0
- package/dist/knowledge-Ku-mPP4f.js.map +1 -0
- package/dist/knowledge.d.ts +2 -150
- package/dist/knowledge.js +2 -40
- package/dist/local-harness-Dh8PJ0ot.d.ts +455 -0
- package/dist/loop-runner-bin-BXsFEUcf.d.ts +162 -0
- package/dist/loop-runner-bin-BwjQ1NfH.js +268 -0
- package/dist/loop-runner-bin-BwjQ1NfH.js.map +1 -0
- package/dist/loop-runner-bin.d.ts +2 -15
- package/dist/loop-runner-bin.js +2 -24
- package/dist/loops.d.ts +5 -4164
- package/dist/loops.js +8 -419
- package/dist/mcp/bin.d.ts +1 -1
- package/dist/mcp/bin.js +116 -146
- package/dist/mcp/bin.js.map +1 -1
- package/dist/mcp/index.d.ts +295 -436
- package/dist/mcp/index.js +1242 -1177
- package/dist/mcp/index.js.map +1 -1
- package/dist/mcp/memory-bin.d.ts +1 -1
- package/dist/mcp/memory-bin.js +37 -16
- package/dist/mcp/memory-bin.js.map +1 -1
- package/dist/memory-server-DL6cE2Ag.js +234 -0
- package/dist/memory-server-DL6cE2Ag.js.map +1 -0
- package/dist/model-resolution-Btd9iIKV.js +98 -0
- package/dist/model-resolution-Btd9iIKV.js.map +1 -0
- package/dist/openai-tools-B68JaOCx.d.ts +24 -0
- package/dist/openai-tools-CKLy1C7M.js +44 -0
- package/dist/openai-tools-CKLy1C7M.js.map +1 -0
- package/dist/otel-export-D34IQW1C.js +843 -0
- package/dist/otel-export-D34IQW1C.js.map +1 -0
- package/dist/platform.d.ts +188 -185
- package/dist/platform.js +185 -218
- package/dist/platform.js.map +1 -1
- package/dist/prepare-B53sPV7M.js +4292 -0
- package/dist/prepare-B53sPV7M.js.map +1 -0
- package/dist/primeintellect/index.d.ts +149 -145
- package/dist/primeintellect/index.js +626 -1003
- package/dist/primeintellect/index.js.map +1 -1
- package/dist/profiles.d.ts +296 -490
- package/dist/profiles.js +722 -749
- package/dist/profiles.js.map +1 -1
- package/dist/protected-model-port-BLPH5VVv.js +722 -0
- package/dist/protected-model-port-BLPH5VVv.js.map +1 -0
- package/dist/protected-model-port-BP6Z4eau.d.ts +283 -0
- package/dist/protected-redaction--F3v1oo8.js +200 -0
- package/dist/protected-redaction--F3v1oo8.js.map +1 -0
- package/dist/redact-D-u-rrcn.js +82 -0
- package/dist/redact-D-u-rrcn.js.map +1 -0
- package/dist/redact-kbIOjfjM.d.ts +452 -0
- package/dist/researcher-CoVqNhfI.js +433 -0
- package/dist/researcher-CoVqNhfI.js.map +1 -0
- package/dist/runtime-BG0BziaP.js +5408 -0
- package/dist/runtime-BG0BziaP.js.map +1 -0
- package/dist/sandbox-events-DeI5xX8P.js +316 -0
- package/dist/sandbox-events-DeI5xX8P.js.map +1 -0
- package/dist/spawn-journal-CwPvKUTa.js +456 -0
- package/dist/spawn-journal-CwPvKUTa.js.map +1 -0
- package/dist/structural-rollout-IXUEplky.js +1445 -0
- package/dist/structural-rollout-IXUEplky.js.map +1 -0
- package/dist/substrate-B0TYNrXn.js +27 -0
- package/dist/substrate-B0TYNrXn.js.map +1 -0
- package/dist/{substrate-Dyiqmd3o.d.ts → substrate-BcnuSHXm.d.ts} +57 -54
- package/dist/supervise-BiRutHS9.js +7321 -0
- package/dist/supervise-BiRutHS9.js.map +1 -0
- package/dist/supervisor-DTKhF-RV.js +3826 -0
- package/dist/supervisor-DTKhF-RV.js.map +1 -0
- package/dist/testing.d.ts +4 -3
- package/dist/testing.js +2478 -2637
- package/dist/testing.js.map +1 -1
- package/dist/tool-server-RcWgLIsL.js +141 -0
- package/dist/tool-server-RcWgLIsL.js.map +1 -0
- package/dist/trace-propagation-CJJC7SVB.js +57 -0
- package/dist/trace-propagation-CJJC7SVB.js.map +1 -0
- package/dist/types-BaIpb0XT.d.ts +492 -0
- package/dist/types-BevOjfTY.d.ts +765 -0
- package/dist/types-C9j4qg6l.d.ts +500 -0
- package/dist/types-Cja5OTGh.d.ts +190 -0
- package/dist/util-MVgdwuIS.js +145 -0
- package/dist/util-MVgdwuIS.js.map +1 -0
- package/dist/workspace-archive-BosQiotA.js +575 -0
- package/dist/workspace-archive-BosQiotA.js.map +1 -0
- package/package.json +43 -56
- package/skills/build-with-agent-runtime/SKILL.md +1 -0
- package/dist/activation-Cm-9MMX1.d.ts +0 -69
- package/dist/analyst-loop.js.map +0 -1
- package/dist/backends-BO4Jqoe2.d.ts +0 -134
- package/dist/candidate-execution/index.js.map +0 -1
- package/dist/chunk-2KGAN2HM.js +0 -1256
- package/dist/chunk-2KGAN2HM.js.map +0 -1
- package/dist/chunk-2VZYRB55.js +0 -834
- package/dist/chunk-2VZYRB55.js.map +0 -1
- package/dist/chunk-3MDZX7YU.js +0 -125
- package/dist/chunk-3MDZX7YU.js.map +0 -1
- package/dist/chunk-5IBQAPVB.js +0 -29
- package/dist/chunk-5IBQAPVB.js.map +0 -1
- package/dist/chunk-5QOB7H74.js +0 -387
- package/dist/chunk-5QOB7H74.js.map +0 -1
- package/dist/chunk-C5RTIBNZ.js +0 -48
- package/dist/chunk-C5RTIBNZ.js.map +0 -1
- package/dist/chunk-CTRA64LY.js +0 -680
- package/dist/chunk-CTRA64LY.js.map +0 -1
- package/dist/chunk-DPEUKJRO.js +0 -27
- package/dist/chunk-DPEUKJRO.js.map +0 -1
- package/dist/chunk-FD2MBMOH.js +0 -494
- package/dist/chunk-FD2MBMOH.js.map +0 -1
- package/dist/chunk-H5QPIZNX.js +0 -907
- package/dist/chunk-H5QPIZNX.js.map +0 -1
- package/dist/chunk-HLKC4UYB.js +0 -3514
- package/dist/chunk-HLKC4UYB.js.map +0 -1
- package/dist/chunk-HNP72PNU.js +0 -192
- package/dist/chunk-HNP72PNU.js.map +0 -1
- package/dist/chunk-ISPWRSEC.js +0 -408
- package/dist/chunk-ISPWRSEC.js.map +0 -1
- package/dist/chunk-KRBFHMV6.js +0 -1228
- package/dist/chunk-KRBFHMV6.js.map +0 -1
- package/dist/chunk-M22PL4GH.js +0 -171
- package/dist/chunk-M22PL4GH.js.map +0 -1
- package/dist/chunk-NURIQBJQ.js +0 -72
- package/dist/chunk-NURIQBJQ.js.map +0 -1
- package/dist/chunk-OPVWXJ2H.js +0 -75
- package/dist/chunk-OPVWXJ2H.js.map +0 -1
- package/dist/chunk-PZZKQVQV.js +0 -52
- package/dist/chunk-PZZKQVQV.js.map +0 -1
- package/dist/chunk-Q2JSAVQ3.js +0 -671
- package/dist/chunk-Q2JSAVQ3.js.map +0 -1
- package/dist/chunk-RDOAVVHY.js +0 -699
- package/dist/chunk-RDOAVVHY.js.map +0 -1
- package/dist/chunk-SGKPNBXE.js +0 -60
- package/dist/chunk-SGKPNBXE.js.map +0 -1
- package/dist/chunk-SMQXZGLZ.js +0 -351
- package/dist/chunk-SMQXZGLZ.js.map +0 -1
- package/dist/chunk-UHEZW5BU.js +0 -2918
- package/dist/chunk-UHEZW5BU.js.map +0 -1
- package/dist/chunk-UPWGXKXB.js +0 -254
- package/dist/chunk-UPWGXKXB.js.map +0 -1
- package/dist/chunk-VISA6CI3.js +0 -200
- package/dist/chunk-VISA6CI3.js.map +0 -1
- package/dist/chunk-WMTCUOQL.js +0 -474
- package/dist/chunk-WMTCUOQL.js.map +0 -1
- package/dist/chunk-WRTOVNN4.js +0 -4728
- package/dist/chunk-WRTOVNN4.js.map +0 -1
- package/dist/chunk-WSTRQZYQ.js +0 -5576
- package/dist/chunk-WSTRQZYQ.js.map +0 -1
- package/dist/chunk-XBG2W2VW.js +0 -6434
- package/dist/chunk-XBG2W2VW.js.map +0 -1
- package/dist/chunk-YEJR7IXO.js +0 -68
- package/dist/chunk-YEJR7IXO.js.map +0 -1
- package/dist/chunk-YJZA2BIK.js +0 -1338
- package/dist/chunk-YJZA2BIK.js.map +0 -1
- package/dist/completion-gate-BMy5LGoP.d.ts +0 -256
- package/dist/conversation.js.map +0 -1
- package/dist/coordination-BZZSVYpZ.d.ts +0 -2570
- package/dist/environment-provider.js.map +0 -1
- package/dist/improvement-adapter-HAZz-7vK.d.ts +0 -203
- package/dist/knowledge.js.map +0 -1
- package/dist/local-harness-BDNcl6jI.d.ts +0 -175
- package/dist/loop-runner-bin-68aoM9-7.d.ts +0 -199
- package/dist/loop-runner-bin.js.map +0 -1
- package/dist/loops.js.map +0 -1
- package/dist/openai-tools-fnj6SRVg.d.ts +0 -46
- package/dist/protected-model-port-B4t-OQjL.d.ts +0 -271
- package/dist/redact-BuFjxBUJ.d.ts +0 -481
- package/dist/sanitize-DEbPNtyI.d.ts +0 -328
- package/dist/structural-rollout-DEh6CEsa.d.ts +0 -446
- package/dist/supervise-4_48wwvy.d.ts +0 -379
- package/dist/types-BCoemcXU.d.ts +0 -802
- package/dist/types-BwoZWq-i.d.ts +0 -510
- package/dist/types-Cbp72qyu.d.ts +0 -491
- package/dist/types-CmYCMbFT.d.ts +0 -203
- package/dist/types-CvNwMzQt.d.ts +0 -957
- package/dist/worktree-fanout-DxhAWr5Z.d.ts +0 -999
package/dist/types-BCoemcXU.d.ts
DELETED
|
@@ -1,802 +0,0 @@
|
|
|
1
|
-
import { DefaultVerdict } from '@tangle-network/agent-eval';
|
|
2
|
-
import { CreateSandboxOptions, SandboxInstance, SandboxEvent, AgentProfile } from '@tangle-network/sandbox';
|
|
3
|
-
import { g as AgentTaskSpec, R as RuntimeStreamEvent } from './types-BwoZWq-i.js';
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
*
|
|
7
|
-
* Runtime hook contracts. Hooks are execution-scoped observers, not part of an
|
|
8
|
-
* `AgentProfile`: profiles stay portable agent recipes; hooks attach to the
|
|
9
|
-
* loop or product harness that is running the profile.
|
|
10
|
-
*
|
|
11
|
-
* @experimental
|
|
12
|
-
*/
|
|
13
|
-
type RuntimeHookPhase = 'before' | 'after' | 'error' | 'event';
|
|
14
|
-
type RuntimeHookTarget = 'agent.run' | 'agent.turn' | 'agent.tool_call' | 'agent.spawn' | 'agent.child' | 'agent.plan' | 'agent.decision' | (string & {});
|
|
15
|
-
type RuntimeDecisionKind = 'continue' | 'verify' | 'ask' | 'retry' | 'stop' | 'memory-write' | 'memory-read' | 'tool-select' | 'skill-select' | 'workflow-select' | 'surface-promote' | (string & {});
|
|
16
|
-
interface RuntimeHookEvent<Payload = unknown> {
|
|
17
|
-
id: string;
|
|
18
|
-
runId: string;
|
|
19
|
-
scenarioId?: string;
|
|
20
|
-
target: RuntimeHookTarget;
|
|
21
|
-
phase: RuntimeHookPhase;
|
|
22
|
-
timestamp: number;
|
|
23
|
-
stepIndex?: number;
|
|
24
|
-
parentId?: string;
|
|
25
|
-
payload?: Payload;
|
|
26
|
-
metadata?: Record<string, unknown>;
|
|
27
|
-
}
|
|
28
|
-
interface RuntimeHookContext {
|
|
29
|
-
signal?: AbortSignal;
|
|
30
|
-
}
|
|
31
|
-
interface RuntimeDecisionEvidenceRef {
|
|
32
|
-
source: string;
|
|
33
|
-
id: string;
|
|
34
|
-
detail?: string;
|
|
35
|
-
metadata?: Record<string, unknown>;
|
|
36
|
-
}
|
|
37
|
-
interface RuntimeDecisionPoint {
|
|
38
|
-
id: string;
|
|
39
|
-
runId: string;
|
|
40
|
-
scenarioId?: string;
|
|
41
|
-
stepIndex: number;
|
|
42
|
-
kind: RuntimeDecisionKind;
|
|
43
|
-
candidateActions: string[];
|
|
44
|
-
context?: string;
|
|
45
|
-
evidence: RuntimeDecisionEvidenceRef[];
|
|
46
|
-
metadata?: Record<string, unknown>;
|
|
47
|
-
}
|
|
48
|
-
interface RuntimeHookErrorContext {
|
|
49
|
-
hook: 'onEvent' | 'onDecisionPoint';
|
|
50
|
-
eventId?: string;
|
|
51
|
-
target?: RuntimeHookTarget;
|
|
52
|
-
phase?: RuntimeHookPhase;
|
|
53
|
-
decisionId?: string;
|
|
54
|
-
decisionKind?: RuntimeDecisionKind;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* The observation seam attached to a running loop (never to the portable genome).
|
|
58
|
-
* Implement the optional hooks to receive lifecycle events, semantic decision points,
|
|
59
|
-
* and hook errors. Author with {@link defineRuntimeHooks} for inference, and attach N
|
|
60
|
-
* observers at once with {@link composeRuntimeHooks} — there is ONE event stream, not a
|
|
61
|
-
* callback-prop zoo.
|
|
62
|
-
*/
|
|
63
|
-
interface RuntimeHooks {
|
|
64
|
-
/**
|
|
65
|
-
* General before/after/event hook. Use this for telemetry, memory capture,
|
|
66
|
-
* policy wrapping, child lifecycle observers, or product-specific extension
|
|
67
|
-
* points.
|
|
68
|
-
*/
|
|
69
|
-
onEvent?: (event: RuntimeHookEvent, context: RuntimeHookContext) => void | Promise<void>;
|
|
70
|
-
/**
|
|
71
|
-
* Semantic decision hook. Belief-state evaluation consumes this, but runtime
|
|
72
|
-
* code should keep emitting ordinary lifecycle events as the base layer.
|
|
73
|
-
*/
|
|
74
|
-
onDecisionPoint?: (point: RuntimeDecisionPoint, context: RuntimeHookContext) => void | Promise<void>;
|
|
75
|
-
onHookError?: (error: Error, context: RuntimeHookErrorContext) => void | Promise<void>;
|
|
76
|
-
}
|
|
77
|
-
/** Identity helper that types a {@link RuntimeHooks} literal so the fields are inferred. */
|
|
78
|
-
declare function defineRuntimeHooks(hooks: RuntimeHooks): RuntimeHooks;
|
|
79
|
-
/**
|
|
80
|
-
* Merge several {@link RuntimeHooks} into one. Falsy entries are dropped (so you can
|
|
81
|
-
* pass `flag && hooks`), and every observer's `onEvent`/`onDecisionPoint` fires for each
|
|
82
|
-
* event. Use this to attach N observers to a loop instead of a second event bus.
|
|
83
|
-
*/
|
|
84
|
-
declare function composeRuntimeHooks(...entries: Array<RuntimeHooks | undefined | null | false>): RuntimeHooks;
|
|
85
|
-
/** Fire `hooks.onEvent`, swallowing sync throws and surfacing async failures to `onError`. */
|
|
86
|
-
declare function notifyRuntimeHookEvent(hooks: RuntimeHooks | undefined, event: RuntimeHookEvent, context?: RuntimeHookContext): void;
|
|
87
|
-
/** Fire `hooks.onDecisionPoint`, swallowing sync throws and surfacing async failures to `onError`. */
|
|
88
|
-
declare function notifyRuntimeDecisionPoint(hooks: RuntimeHooks | undefined, point: RuntimeDecisionPoint, context?: RuntimeHookContext): void;
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
*
|
|
92
|
-
* Production-run lifecycle: record what the agent did on behalf of a customer,
|
|
93
|
-
* what it cost, and how it ended.
|
|
94
|
-
*
|
|
95
|
-
* Three concerns live in this module:
|
|
96
|
-
*
|
|
97
|
-
* 1. **Lifecycle state machine** — `running` -> `completed | failed | cancelled`,
|
|
98
|
-
* enforced by `RuntimeRunStateError`. Completion is idempotent for the same
|
|
99
|
-
* status (a second `complete()` call is a no-op so retries / cleanup paths
|
|
100
|
-
* don't double-fire side effects). A different terminal status is a state
|
|
101
|
-
* error.
|
|
102
|
-
*
|
|
103
|
-
* 2. **Cost ledger** — every `llm_call` event the handle observes contributes
|
|
104
|
-
* `tokensIn`, `tokensOut`, `costUsd`, and bumps `llmCalls`. Wall time is
|
|
105
|
-
* measured from `startRuntimeRun()` to `complete()`. Surface via
|
|
106
|
-
* `handle.cost()` for cost-per-task dashboards.
|
|
107
|
-
*
|
|
108
|
-
* 3. **Persistence adapter** — `RuntimeRunPersistenceAdapter` is the seam
|
|
109
|
-
* consumers plug in to write a `RuntimeRunRow` to their D1 / postgres /
|
|
110
|
-
* KV store. The adapter receives a sanitized row shape; no telemetry
|
|
111
|
-
* payload bytes flow through it unless the consumer opts in via
|
|
112
|
-
* `RuntimeRunOptions.telemetryEvents`.
|
|
113
|
-
*
|
|
114
|
-
* @stable
|
|
115
|
-
*/
|
|
116
|
-
|
|
117
|
-
/** @stable */
|
|
118
|
-
type RuntimeRunStatus = 'running' | 'completed' | 'failed' | 'cancelled';
|
|
119
|
-
/** @stable */
|
|
120
|
-
interface RuntimeRunCost {
|
|
121
|
-
/** Cumulative input tokens across every observed `llm_call` event. */
|
|
122
|
-
tokensIn: number;
|
|
123
|
-
/** Cumulative output tokens across every observed `llm_call` event. */
|
|
124
|
-
tokensOut: number;
|
|
125
|
-
/** Sum of `costUsd` from every observed `llm_call` event. */
|
|
126
|
-
costUsd: number;
|
|
127
|
-
/** Wall time from `startRuntimeRun()` to `complete()` (or `now()` if not yet completed). */
|
|
128
|
-
wallMs: number;
|
|
129
|
-
/** Count of `llm_call` events observed during the run. */
|
|
130
|
-
llmCalls: number;
|
|
131
|
-
}
|
|
132
|
-
/** @stable */
|
|
133
|
-
interface RuntimeRunCompleteInput {
|
|
134
|
-
status: Exclude<RuntimeRunStatus, 'running'>;
|
|
135
|
-
resultSummary?: string;
|
|
136
|
-
/** Optional explicit cost override; if omitted, the accumulated ledger is used. */
|
|
137
|
-
cost?: Partial<RuntimeRunCost>;
|
|
138
|
-
/** Stable error message when `status === 'failed'`. */
|
|
139
|
-
error?: string;
|
|
140
|
-
/** Additional adapter-specific fields merged into the persisted row. */
|
|
141
|
-
metadata?: Record<string, unknown>;
|
|
142
|
-
}
|
|
143
|
-
/** @stable */
|
|
144
|
-
interface RuntimeRunRow {
|
|
145
|
-
/** Stable runtime-side identifier. Adapters may translate to their own primary key. */
|
|
146
|
-
id: string;
|
|
147
|
-
workspaceId: string;
|
|
148
|
-
sessionId?: string;
|
|
149
|
-
agentId?: string;
|
|
150
|
-
domain?: string;
|
|
151
|
-
taskId: string;
|
|
152
|
-
scenarioId?: string;
|
|
153
|
-
status: RuntimeRunStatus;
|
|
154
|
-
resultSummary?: string;
|
|
155
|
-
error?: string;
|
|
156
|
-
cost: RuntimeRunCost;
|
|
157
|
-
startedAt: string;
|
|
158
|
-
completedAt?: string;
|
|
159
|
-
metadata?: Record<string, unknown>;
|
|
160
|
-
}
|
|
161
|
-
/** @stable */
|
|
162
|
-
interface RuntimeRunPersistenceAdapter {
|
|
163
|
-
/**
|
|
164
|
-
* Called once when `handle.persist()` runs. Implementations write `row` to
|
|
165
|
-
* their durable store (D1, postgres, KV) and return whatever the consumer
|
|
166
|
-
* wants the caller to see (often the storage-side row id). Errors thrown
|
|
167
|
-
* here propagate out of `persist()` so the caller can decide whether to
|
|
168
|
-
* retry or log-and-continue.
|
|
169
|
-
*/
|
|
170
|
-
upsert(row: RuntimeRunRow): Promise<void> | void;
|
|
171
|
-
}
|
|
172
|
-
/** @stable */
|
|
173
|
-
interface RuntimeRunOptions {
|
|
174
|
-
workspaceId: string;
|
|
175
|
-
sessionId?: string;
|
|
176
|
-
agentId?: string;
|
|
177
|
-
taskSpec: AgentTaskSpec;
|
|
178
|
-
scenarioId?: string;
|
|
179
|
-
/** Optional persistence adapter; if omitted, `persist()` is a no-op. */
|
|
180
|
-
adapter?: RuntimeRunPersistenceAdapter;
|
|
181
|
-
/** Override the row id; default = `${taskSpec.id}:${random suffix}`. */
|
|
182
|
-
id?: string;
|
|
183
|
-
/** Override the clock; default = `Date.now()`. Useful for deterministic tests. */
|
|
184
|
-
now?: () => number;
|
|
185
|
-
}
|
|
186
|
-
/** @stable */
|
|
187
|
-
interface RuntimeRunHandle {
|
|
188
|
-
/** Stable id assigned at start. */
|
|
189
|
-
readonly id: string;
|
|
190
|
-
readonly workspaceId: string;
|
|
191
|
-
readonly sessionId: string | undefined;
|
|
192
|
-
readonly taskSpec: AgentTaskSpec;
|
|
193
|
-
readonly status: RuntimeRunStatus;
|
|
194
|
-
/**
|
|
195
|
-
* Observe a single `RuntimeStreamEvent`. The handle ignores non-cost events
|
|
196
|
-
* (text deltas, tool calls) silently so consumers can pipe the whole stream
|
|
197
|
-
* through `handle.observe`. `llm_call` events update the ledger.
|
|
198
|
-
*/
|
|
199
|
-
observe(event: RuntimeStreamEvent): void;
|
|
200
|
-
/** Snapshot of the current cost ledger. Safe to call at any time. */
|
|
201
|
-
cost(): RuntimeRunCost;
|
|
202
|
-
/**
|
|
203
|
-
* Transition to a terminal state. Idempotent for the same status; throws
|
|
204
|
-
* `RuntimeRunStateError` for a different terminal status (state machines
|
|
205
|
-
* don't time-travel).
|
|
206
|
-
*/
|
|
207
|
-
complete(input: RuntimeRunCompleteInput): void;
|
|
208
|
-
/** Build the current row without writing it. Useful for tests + dry runs. */
|
|
209
|
-
toRow(metadata?: Record<string, unknown>): RuntimeRunRow;
|
|
210
|
-
/**
|
|
211
|
-
* Persist the current row via the configured adapter. Must be called after
|
|
212
|
-
* `complete()`. Idempotent for the same terminal state (the adapter sees
|
|
213
|
-
* the same row on retry).
|
|
214
|
-
*/
|
|
215
|
-
persist(metadata?: Record<string, unknown>): Promise<void>;
|
|
216
|
-
}
|
|
217
|
-
/**
|
|
218
|
-
*
|
|
219
|
-
* Construct a runtime-run handle. The returned handle is mutable across its
|
|
220
|
-
* lifetime; consumers should not share it across requests.
|
|
221
|
-
*
|
|
222
|
-
* @stable
|
|
223
|
-
*/
|
|
224
|
-
declare function startRuntimeRun(options: RuntimeRunOptions): RuntimeRunHandle;
|
|
225
|
-
|
|
226
|
-
/**
|
|
227
|
-
*
|
|
228
|
-
* Driven-loop substrate — type surface.
|
|
229
|
-
*
|
|
230
|
-
* The loop kernel orchestrates around the sandbox SDK; it does not invent
|
|
231
|
-
* its own notion of "what an agent is". Each iteration is a sandbox-SDK
|
|
232
|
-
* `streamPrompt` call against an `AgentProfile`. The kernel owns iteration
|
|
233
|
-
* accounting, concurrency, abort propagation, cost aggregation, and trace
|
|
234
|
-
* emission; the driver owns topology (plan + decide); the validator owns
|
|
235
|
-
* output scoring; the output adapter owns event-stream → typed-output decode.
|
|
236
|
-
*
|
|
237
|
-
* @experimental
|
|
238
|
-
*/
|
|
239
|
-
|
|
240
|
-
/** @experimental */
|
|
241
|
-
interface ValidationCtx {
|
|
242
|
-
/** Iteration index this output came from (0-based). */
|
|
243
|
-
iteration: number;
|
|
244
|
-
/**
|
|
245
|
-
* Live sandbox for this iteration. Validators that need execution-grounded
|
|
246
|
-
* evidence can inspect files or run commands here instead of forcing callers
|
|
247
|
-
* to bypass the loop kernel with raw Sandbox SDK orchestration.
|
|
248
|
-
*/
|
|
249
|
-
box?: SandboxInstance;
|
|
250
|
-
/** Cooperative cancellation channel. */
|
|
251
|
-
signal: AbortSignal;
|
|
252
|
-
/**
|
|
253
|
-
* Optional trace emitter. When set, validator implementations that make
|
|
254
|
-
* LLM calls (e.g. an LLM-judge reviewer) emit spans into it.
|
|
255
|
-
* The kernel passes `ctx.traceEmitter` from `ExecCtx` when available.
|
|
256
|
-
*/
|
|
257
|
-
traceEmitter?: LoopTraceEmitter;
|
|
258
|
-
}
|
|
259
|
-
/** @experimental */
|
|
260
|
-
interface Validator<Output, Verdict = DefaultVerdict> {
|
|
261
|
-
validate(output: Output, ctx: ValidationCtx): Promise<Verdict>;
|
|
262
|
-
}
|
|
263
|
-
/**
|
|
264
|
-
* Sandbox-SDK-shaped agent specification.
|
|
265
|
-
*
|
|
266
|
-
* The kernel uses `profile` to instantiate a sandbox per iteration, formats
|
|
267
|
-
* `task` into a prompt via `taskToPrompt`, and merges `sandboxOverrides` into
|
|
268
|
-
* the `CreateSandboxOptions` it passes to `client.create`. Heterogeneous
|
|
269
|
-
* fanout supplies multiple `AgentRunSpec`s and the kernel round-robins
|
|
270
|
-
* through them when the driver plans N tasks.
|
|
271
|
-
*
|
|
272
|
-
* @experimental
|
|
273
|
-
*/
|
|
274
|
-
interface AgentRunSpec<Task> {
|
|
275
|
-
/** Sandbox SDK profile — what kind of agent runs the task. */
|
|
276
|
-
profile: AgentProfile;
|
|
277
|
-
/** Task → prompt formatter. Pure and deterministic. */
|
|
278
|
-
taskToPrompt: (task: Task) => string;
|
|
279
|
-
/**
|
|
280
|
-
* Optional pre-prompt sandbox provisioner. Runs after the sandbox is acquired
|
|
281
|
-
* and before the first prompt is streamed into that box. Use this for
|
|
282
|
-
* domain-agnostic setup such as repo snapshots, benchmark fixtures, policy
|
|
283
|
-
* files, or seed datasets. The hook is part of the runtime surface so loop
|
|
284
|
-
* consumers do not hand-roll Sandbox SDK orchestration just to prepare a
|
|
285
|
-
* workspace before the agent sees it.
|
|
286
|
-
*
|
|
287
|
-
* `ctx.recordMount` records what was placed into the box so the run carries a
|
|
288
|
-
* provenance manifest (`LoopResult.provenance.mounts`). It is optional and
|
|
289
|
-
* provenance-only — the kernel never reads box contents and attaches no
|
|
290
|
-
* meaning to the entries; not calling it simply leaves the manifest empty.
|
|
291
|
-
*/
|
|
292
|
-
prepareBox?: (box: SandboxInstance, ctx: {
|
|
293
|
-
signal: AbortSignal;
|
|
294
|
-
recordMount: MountRecorder;
|
|
295
|
-
}) => Promise<void> | void;
|
|
296
|
-
/**
|
|
297
|
-
* Per-spec stable name. Surfaced in trace events and the default winner
|
|
298
|
-
* selector tiebreak. Falls back to `profile.name ?? 'agent'`.
|
|
299
|
-
*/
|
|
300
|
-
name?: string;
|
|
301
|
-
/**
|
|
302
|
-
* Optional sandbox-SDK `CreateSandboxOptions` overrides merged on top of
|
|
303
|
-
* the kernel's defaults. `backend.profile` is set to `profile` by the
|
|
304
|
-
* kernel and cannot be overridden here — use `profile` itself for that.
|
|
305
|
-
*/
|
|
306
|
-
sandboxOverrides?: Partial<Omit<CreateSandboxOptions, 'backend'>> & {
|
|
307
|
-
backend?: Omit<NonNullable<CreateSandboxOptions['backend']>, 'profile'>;
|
|
308
|
-
};
|
|
309
|
-
}
|
|
310
|
-
/**
|
|
311
|
-
* Stream of `SandboxEvent`s → typed `Output`.
|
|
312
|
-
*
|
|
313
|
-
* Adapters are pure functions over the already-collected event array; they
|
|
314
|
-
* do not receive the live AsyncIterable so they can be replayed against
|
|
315
|
-
* persisted streams during tests / replays.
|
|
316
|
-
*
|
|
317
|
-
* @experimental
|
|
318
|
-
*/
|
|
319
|
-
interface OutputAdapter<Output> {
|
|
320
|
-
parse(events: SandboxEvent[]): Output;
|
|
321
|
-
}
|
|
322
|
-
/** LLM token usage. Structurally maps into agent-eval's paid-call receipt so a
|
|
323
|
-
* campaign dispatch settles real usage instead of appearing as a stub. */
|
|
324
|
-
interface LoopTokenUsage {
|
|
325
|
-
input: number;
|
|
326
|
-
output: number;
|
|
327
|
-
}
|
|
328
|
-
/**
|
|
329
|
-
* One mounted resource recorded during box preparation — a pure provenance
|
|
330
|
-
* record of what the caller placed into a box before the agent saw it. The
|
|
331
|
-
* kernel never reads box contents itself (it does not know what was mounted);
|
|
332
|
-
* the caller, which owns the bytes inside `prepareBox`, supplies each entry via
|
|
333
|
-
* `recordMount`. Carries no domain semantics — just where the resource landed,
|
|
334
|
-
* its content fingerprint, its size, and where it came from — so a run is
|
|
335
|
-
* auditable after the fact ("what exactly was this agent given?").
|
|
336
|
-
*
|
|
337
|
-
* @experimental
|
|
338
|
-
*/
|
|
339
|
-
interface MountManifestEntry {
|
|
340
|
-
/** Destination path inside the box where the resource was placed. */
|
|
341
|
-
path: string;
|
|
342
|
-
/** Hex SHA-256 of the mounted bytes. The caller computes it from the bytes
|
|
343
|
-
* it wrote — the kernel does not hash box contents. */
|
|
344
|
-
sha256: string;
|
|
345
|
-
/** Size of the mounted resource in bytes. */
|
|
346
|
-
bytes: number;
|
|
347
|
-
/** Free-form origin of the resource (e.g. a repo ref, a corpus id, a local
|
|
348
|
-
* path, a URL). Provenance only — the kernel attaches no meaning to it. */
|
|
349
|
-
source: string;
|
|
350
|
-
}
|
|
351
|
-
/**
|
|
352
|
-
* A record of one candidate-selection decision: which iteration the selector
|
|
353
|
-
* picked (or rejected) and why. Pure audit trail of the SELECTOR role — it
|
|
354
|
-
* carries the selector's identity, the candidate's score, and an optional
|
|
355
|
-
* human-readable reason, with no domain semantics. The kernel emits one receipt
|
|
356
|
-
* per scored candidate at finalize so a run answers "why did THIS one win?".
|
|
357
|
-
*
|
|
358
|
-
* @experimental
|
|
359
|
-
*/
|
|
360
|
-
interface SelectionReceipt {
|
|
361
|
-
/** Iteration index this receipt is about. */
|
|
362
|
-
candidateIndex: number;
|
|
363
|
-
/** True for the iteration the selector chose as winner; false otherwise. */
|
|
364
|
-
selected: boolean;
|
|
365
|
-
/** The candidate's verdict score, when it has one. */
|
|
366
|
-
score?: number;
|
|
367
|
-
/** Why this candidate was (or was not) selected, when the selector states it. */
|
|
368
|
-
reason?: string;
|
|
369
|
-
/** Identity of the selector that produced this receipt — `'caller'` (an
|
|
370
|
-
* explicit `selectWinner`), `'driver'` (a driver-authored winner), or
|
|
371
|
-
* `'default'` (the kernel's best-valid-score argmax). */
|
|
372
|
-
selector: 'caller' | 'driver' | 'default';
|
|
373
|
-
}
|
|
374
|
-
/**
|
|
375
|
-
* Domain-free run provenance: a manifest of what was mounted into the run's
|
|
376
|
-
* boxes and the receipts for how the winner was selected. Surfaced on
|
|
377
|
-
* `LoopResult` purely for run auditability — nothing in the kernel branches on
|
|
378
|
-
* it. Empty arrays when the caller recorded no mounts and there was no
|
|
379
|
-
* candidate to select.
|
|
380
|
-
*
|
|
381
|
-
* @experimental
|
|
382
|
-
*/
|
|
383
|
-
interface RunProvenance {
|
|
384
|
-
/** Every resource recorded via `prepareBox`'s `recordMount`, in record order. */
|
|
385
|
-
mounts: MountManifestEntry[];
|
|
386
|
-
/** One receipt per scored candidate at finalize, in iteration order. */
|
|
387
|
-
selectionReceipts: SelectionReceipt[];
|
|
388
|
-
}
|
|
389
|
-
/**
|
|
390
|
-
* Records a mounted resource into the run's provenance manifest. Passed to
|
|
391
|
-
* `prepareBox` so the caller — which owns the bytes it writes into the box —
|
|
392
|
-
* declares what it mounted without the kernel having to inspect box contents.
|
|
393
|
-
*
|
|
394
|
-
* @experimental
|
|
395
|
-
*/
|
|
396
|
-
type MountRecorder = (entry: MountManifestEntry) => void;
|
|
397
|
-
/** @experimental */
|
|
398
|
-
interface Iteration<Task, Output> {
|
|
399
|
-
/** 0-based iteration index assigned by the kernel. */
|
|
400
|
-
index: number;
|
|
401
|
-
task: Task;
|
|
402
|
-
/** Stable name of the `AgentRunSpec` that produced this iteration. */
|
|
403
|
-
agentRunName: string;
|
|
404
|
-
output?: Output;
|
|
405
|
-
verdict?: DefaultVerdict;
|
|
406
|
-
error?: Error;
|
|
407
|
-
/** Raw sandbox event stream collected for this iteration. */
|
|
408
|
-
events: SandboxEvent[];
|
|
409
|
-
startedAt: number;
|
|
410
|
-
endedAt: number;
|
|
411
|
-
costUsd: number;
|
|
412
|
-
/** Summed LLM token usage across every `llm_call` event in this iteration. */
|
|
413
|
-
tokenUsage: LoopTokenUsage;
|
|
414
|
-
}
|
|
415
|
-
/** @experimental */
|
|
416
|
-
interface Driver<Task, Output, Decision> {
|
|
417
|
-
/**
|
|
418
|
-
* Stable identifier surfaced in trace events. Default `'driver'`.
|
|
419
|
-
*/
|
|
420
|
-
readonly name?: string;
|
|
421
|
-
/**
|
|
422
|
-
* Tasks to issue this iteration. `[task]` → refine; N copies → fanout;
|
|
423
|
-
* `[]` → no more work this round (kernel proceeds to `decide`).
|
|
424
|
-
*/
|
|
425
|
-
plan(task: Task, history: ReadonlyArray<Iteration<Task, Output>>): Promise<Task[]>;
|
|
426
|
-
/**
|
|
427
|
-
* Inspect history and return the next state. The kernel terminates the
|
|
428
|
-
* loop when `decide` returns a value listed in `isTerminalDecision`
|
|
429
|
-
* (`'stop' | 'pick-winner' | 'fail' | 'done'`), when `maxIterations`
|
|
430
|
-
* is hit, or when the abort signal fires.
|
|
431
|
-
*/
|
|
432
|
-
decide(history: ReadonlyArray<Iteration<Task, Output>>): Decision | Promise<Decision>;
|
|
433
|
-
/**
|
|
434
|
-
* Optional: describe the move `plan()` just produced, for trace emission.
|
|
435
|
-
* The kernel calls this immediately after `plan()` and emits the result in
|
|
436
|
-
* the `loop.plan` event so a topology viewer can render the agent's chosen
|
|
437
|
-
* move + rationale (not just the inferred fan-width). Drivers whose topology
|
|
438
|
-
* is a pure function of count (refine/fanout-vote) omit it — the kernel
|
|
439
|
-
* infers `moveKind` from the planned-task count. A driver that authors its
|
|
440
|
-
* own topology returns its chosen move's kind + rationale here.
|
|
441
|
-
*/
|
|
442
|
-
describePlan?(): LoopPlanDescription | undefined;
|
|
443
|
-
/**
|
|
444
|
-
* Optional: the driver AUTHORS the winner instead of the kernel's argmax. The
|
|
445
|
-
* kernel consults this at finalize ONLY when the caller did not pass an explicit
|
|
446
|
-
* `selectWinner` to runAgentRounds. Return the driver-declared winner (e.g. from a
|
|
447
|
-
* `select` topology move) or `undefined` to fall through to the default
|
|
448
|
-
* (best-valid-score, earliest index). This is the SELECTOR role made
|
|
449
|
-
* agent-authorable — the planner runs the selection, not the kernel.
|
|
450
|
-
* @experimental
|
|
451
|
-
*/
|
|
452
|
-
selectWinner?(history: ReadonlyArray<Iteration<Task, Output>>): LoopWinner<Task, Output> | undefined;
|
|
453
|
-
}
|
|
454
|
-
/** @experimental Driver-supplied description of the just-planned move. */
|
|
455
|
-
interface LoopPlanDescription {
|
|
456
|
-
/** Topology move this round — e.g. `'refine' | 'fanout' | 'verify' | 'stop'`. */
|
|
457
|
-
kind: string;
|
|
458
|
-
/** Why the driver chose this move (the agent's rationale), when available. */
|
|
459
|
-
rationale?: string;
|
|
460
|
-
/**
|
|
461
|
-
* Iteration index this round branches FROM, when the driver declares it.
|
|
462
|
-
* Overrides the kernel's inferred branch point — lets a planner that
|
|
463
|
-
* branches off a specific (non-winner) iteration emit faithful edge lineage.
|
|
464
|
-
* Omit to keep the inferred (best-valid / latest) branch point.
|
|
465
|
-
*/
|
|
466
|
-
parentIndex?: number;
|
|
467
|
-
}
|
|
468
|
-
/** @experimental */
|
|
469
|
-
interface LoopWinner<Task, Output> {
|
|
470
|
-
task: Task;
|
|
471
|
-
output: Output;
|
|
472
|
-
verdict?: DefaultVerdict;
|
|
473
|
-
iterationIndex: number;
|
|
474
|
-
agentRunName: string;
|
|
475
|
-
}
|
|
476
|
-
/** @experimental */
|
|
477
|
-
interface LoopResult<Task, Output, Decision> {
|
|
478
|
-
decision: Decision;
|
|
479
|
-
iterations: Iteration<Task, Output>[];
|
|
480
|
-
winner?: LoopWinner<Task, Output>;
|
|
481
|
-
durationMs: number;
|
|
482
|
-
/** Sum of every iteration's `costUsd`. */
|
|
483
|
-
costUsd: number;
|
|
484
|
-
/** Sum of every iteration's token usage. `loopDispatch` commits it through
|
|
485
|
-
* the campaign's paid-call receipt. */
|
|
486
|
-
tokenUsage: LoopTokenUsage;
|
|
487
|
-
/** Domain-free run provenance for auditability: the mount manifest recorded
|
|
488
|
-
* during `prepareBox` and the selection receipts for how the winner was
|
|
489
|
-
* chosen. Always present; empty arrays when nothing was recorded. */
|
|
490
|
-
provenance: RunProvenance;
|
|
491
|
-
}
|
|
492
|
-
/**
|
|
493
|
-
* Minimal sandbox client surface the kernel calls. Satisfied structurally by
|
|
494
|
-
* `new Sandbox({ apiKey, baseUrl })` — declared as a structural type so
|
|
495
|
-
* tests can pass a stub without instantiating the SDK.
|
|
496
|
-
*
|
|
497
|
-
* `describePlacement` is optional. When present, the kernel calls it after
|
|
498
|
-
* each `create()` so the `loop.iteration.dispatch` trace event carries fleet
|
|
499
|
-
* coordinates (fleetId + machineId) instead of just the sibling sandboxId.
|
|
500
|
-
* Fleet-aware adapters set this; the raw `Sandbox` SDK class does not, and
|
|
501
|
-
* the kernel falls back to `{ placement: 'sibling', sandboxId: box.id }`.
|
|
502
|
-
*
|
|
503
|
-
* @experimental
|
|
504
|
-
*/
|
|
505
|
-
interface SandboxClient {
|
|
506
|
-
create(options?: CreateSandboxOptions): Promise<SandboxInstance>;
|
|
507
|
-
describePlacement?(box: SandboxInstance): LoopSandboxPlacement;
|
|
508
|
-
/**
|
|
509
|
-
* Optional CRIU capability probe. When present and it resolves
|
|
510
|
-
* `{ available: true }`, the loop's `lineage.fork` seam may checkpoint+fork a
|
|
511
|
-
* parent box so a fanout's branches inherit a shared context prefix; absent or
|
|
512
|
-
* `false`, the fanout degrades to independent fresh boxes. The kernel reads
|
|
513
|
-
* this ONLY through the capability probe — it never branches on backend kind.
|
|
514
|
-
* The raw `Sandbox` SDK class satisfies it; the loop's test fakes omit it
|
|
515
|
-
* (⇒ `canFork = false`).
|
|
516
|
-
* @experimental
|
|
517
|
-
*/
|
|
518
|
-
criuStatus?(): Promise<{
|
|
519
|
-
available: boolean;
|
|
520
|
-
criuVersion?: string;
|
|
521
|
-
reason?: string;
|
|
522
|
-
}>;
|
|
523
|
-
}
|
|
524
|
-
/**
|
|
525
|
-
* Opt-in box-lineage controls for `runAgentRounds`. Default OFF — with both flags
|
|
526
|
-
* unset the kernel's per-iteration behavior is byte-identical to acquiring a
|
|
527
|
-
* fresh box, streaming once, and tearing it down. The independence of N fresh
|
|
528
|
-
* boxes (e.g. `random@k`) is a compute-control invariant; these flags must
|
|
529
|
-
* never apply to it. Enable them ONLY on a steered loop (refine / planner-driven
|
|
530
|
-
* fanout) where reusing the parent's context is intended.
|
|
531
|
-
*
|
|
532
|
-
* Live-box footprint: the lineage keeps every box it starts or forks alive
|
|
533
|
-
* across rounds so a later round can descend from it, and tears them down at
|
|
534
|
-
* loop end. When the driver's branch point is kernel-inferred (no
|
|
535
|
-
* `describePlan` — refine, fanout-vote), the kernel prunes boxes no future
|
|
536
|
-
* round can reach after each round, so the live set tracks the active frontier.
|
|
537
|
-
* When the driver authors its own branch point (`describePlan().parentIndex`),
|
|
538
|
-
* it may descend from any prior
|
|
539
|
-
* iteration, so no box is pruned and the live-box count rises to the total
|
|
540
|
-
* iterations across all rounds. Size `forkFanout` runs accordingly (CRIU forks
|
|
541
|
-
* are copy-on-write, but each is still a live box until loop end).
|
|
542
|
-
*
|
|
543
|
-
* @experimental
|
|
544
|
-
*/
|
|
545
|
-
interface LoopLineageOptions {
|
|
546
|
-
/**
|
|
547
|
-
* When true, a refine round (1 planned task) descending from a prior round
|
|
548
|
-
* CONTINUES the parent iteration's session on the SAME box
|
|
549
|
-
* (`streamPrompt({ sessionId })`) instead of acquiring a fresh box and
|
|
550
|
-
* re-injecting prior context as prompt text. Round 0 (no parent) always
|
|
551
|
-
* starts fresh. Usable on any single-task path, not just the refine driver.
|
|
552
|
-
*
|
|
553
|
-
* Requires a platform that honors a client-supplied `sessionId`. The lineage
|
|
554
|
-
* mints the id and `continue` asserts the session is still live
|
|
555
|
-
* (`box.session(id).status()`), failing loud if the platform dropped it — so a
|
|
556
|
-
* non-honoring platform errors instead of silently running contextless turns.
|
|
557
|
-
* Verify continuity against the live platform before enabling: the assertion
|
|
558
|
-
* proves the session EXISTS server-side, not that prior turns replay into it.
|
|
559
|
-
*/
|
|
560
|
-
sessionContinuity?: boolean;
|
|
561
|
-
/**
|
|
562
|
-
* When true AND the platform reports CRIU fork support, a fanout round (N
|
|
563
|
-
* planned tasks) descending from a prior round FORKS the parent iteration's
|
|
564
|
-
* checkpoint so all N branches inherit a shared context prefix. Without fork
|
|
565
|
-
* support it degrades to N independent fresh boxes (same result, no prefix).
|
|
566
|
-
* Round 0 always starts fresh. NEVER set this for a `random@k` control arm —
|
|
567
|
-
* forking would couple the independent samples.
|
|
568
|
-
*
|
|
569
|
-
* A real fork inherits the parent's IMAGE/PROFILE: per-branch `AgentRunSpec`
|
|
570
|
-
* profiles are honored only on the degraded fresh-box path, so a
|
|
571
|
-
* heterogeneous-profile fanout silently homogenizes to the parent's profile
|
|
572
|
-
* when fork is available. Use this for same-profile branching; for
|
|
573
|
-
* different-per-branch profiles use the unforked fanout path.
|
|
574
|
-
*/
|
|
575
|
-
forkFanout?: boolean;
|
|
576
|
-
/**
|
|
577
|
-
* Per-turn sandbox streaming mode. Default `'sse'` (live `streamPrompt` —
|
|
578
|
-
* low-latency, full per-token trace; best for interactive chat). `'poll'`
|
|
579
|
-
* fire-and-detaches via `dispatchPrompt` and awaits the terminal result by
|
|
580
|
-
* status-polling, so a long, quiet in-box turn (clone + build + test) never
|
|
581
|
-
* holds a live stream a proxy idle-timeout can drop mid-execution. Lower trace
|
|
582
|
-
* fidelity (one terminal event), so it is opt-in — intended for BATCH eval
|
|
583
|
-
* runs, which don't need live streaming and were losing long turns to the
|
|
584
|
-
* idle-drop. Applies to the default fresh-box path too, not only when
|
|
585
|
-
* `sessionContinuity`/`forkFanout` are on.
|
|
586
|
-
*/
|
|
587
|
-
streaming?: 'sse' | 'poll';
|
|
588
|
-
}
|
|
589
|
-
/** @experimental */
|
|
590
|
-
interface LoopSandboxPlacement {
|
|
591
|
-
kind: 'sibling' | 'fleet';
|
|
592
|
-
sandboxId?: string;
|
|
593
|
-
fleetId?: string;
|
|
594
|
-
machineId?: string;
|
|
595
|
-
}
|
|
596
|
-
/** @experimental */
|
|
597
|
-
interface LoopTraceEmitter {
|
|
598
|
-
emit(event: LoopTraceEvent): void | Promise<void>;
|
|
599
|
-
}
|
|
600
|
-
/** @experimental */
|
|
601
|
-
type LoopTraceEvent = {
|
|
602
|
-
kind: 'loop.started';
|
|
603
|
-
runId: string;
|
|
604
|
-
timestamp: number;
|
|
605
|
-
payload: LoopStartedPayload;
|
|
606
|
-
} | {
|
|
607
|
-
kind: 'loop.plan';
|
|
608
|
-
runId: string;
|
|
609
|
-
timestamp: number;
|
|
610
|
-
payload: LoopPlanPayload;
|
|
611
|
-
} | {
|
|
612
|
-
kind: 'loop.iteration.started';
|
|
613
|
-
runId: string;
|
|
614
|
-
timestamp: number;
|
|
615
|
-
payload: LoopIterationStartedPayload;
|
|
616
|
-
} | {
|
|
617
|
-
kind: 'loop.iteration.dispatch';
|
|
618
|
-
runId: string;
|
|
619
|
-
timestamp: number;
|
|
620
|
-
payload: LoopIterationDispatchPayload;
|
|
621
|
-
} | {
|
|
622
|
-
kind: 'loop.iteration.ended';
|
|
623
|
-
runId: string;
|
|
624
|
-
timestamp: number;
|
|
625
|
-
payload: LoopIterationEndedPayload;
|
|
626
|
-
} | {
|
|
627
|
-
kind: 'loop.decision';
|
|
628
|
-
runId: string;
|
|
629
|
-
timestamp: number;
|
|
630
|
-
payload: LoopDecisionPayload;
|
|
631
|
-
} | {
|
|
632
|
-
kind: 'loop.ended';
|
|
633
|
-
runId: string;
|
|
634
|
-
timestamp: number;
|
|
635
|
-
payload: LoopEndedPayload;
|
|
636
|
-
} | {
|
|
637
|
-
kind: 'loop.teardown.failed';
|
|
638
|
-
runId: string;
|
|
639
|
-
timestamp: number;
|
|
640
|
-
payload: LoopTeardownFailedPayload;
|
|
641
|
-
};
|
|
642
|
-
/** @experimental */
|
|
643
|
-
interface LoopStartedPayload {
|
|
644
|
-
driver: string;
|
|
645
|
-
agentRunNames: string[];
|
|
646
|
-
maxIterations: number;
|
|
647
|
-
maxConcurrency: number;
|
|
648
|
-
}
|
|
649
|
-
/**
|
|
650
|
-
* Emitted once per `plan()` round, immediately after the driver plans. Carries
|
|
651
|
-
* the topology move so a viewer renders WHAT the agent decided + WHY, not just
|
|
652
|
-
* the inferred fan-width. `moveKind` is the driver's `describePlan().kind` when
|
|
653
|
-
* provided, else inferred from `plannedCount` (0→stop, 1→refine, N→fanout).
|
|
654
|
-
*
|
|
655
|
-
* @experimental
|
|
656
|
-
*/
|
|
657
|
-
interface LoopPlanPayload {
|
|
658
|
-
/** 0-based plan round (one per `plan()` call). */
|
|
659
|
-
roundIndex: number;
|
|
660
|
-
/** Tasks the driver issued this round. */
|
|
661
|
-
plannedCount: number;
|
|
662
|
-
/** Topology move — `'refine' | 'fanout' | 'verify' | 'stop'` etc. */
|
|
663
|
-
moveKind: string;
|
|
664
|
-
/** Driver rationale for the move, when available. */
|
|
665
|
-
rationale?: string;
|
|
666
|
-
/**
|
|
667
|
-
* Iteration index this round branched FROM (the edge source). `undefined`
|
|
668
|
-
* for round 0 (root). Kernel-inferred branch point — the best-valid (else
|
|
669
|
-
* latest) iteration so far — unless a driver later declares it explicitly.
|
|
670
|
-
*/
|
|
671
|
-
parentIndex?: number;
|
|
672
|
-
/** Iteration indices this round dispatched (the edge targets). */
|
|
673
|
-
childIndices: number[];
|
|
674
|
-
}
|
|
675
|
-
/** @experimental */
|
|
676
|
-
interface LoopIterationStartedPayload {
|
|
677
|
-
iterationIndex: number;
|
|
678
|
-
agentRunName: string;
|
|
679
|
-
taskHash: string;
|
|
680
|
-
/** Plan round (== `LoopPlanPayload.roundIndex`) this iteration belongs to. */
|
|
681
|
-
groupId?: number;
|
|
682
|
-
/** Iteration this one was planned from; `undefined` ⇒ root. */
|
|
683
|
-
parentIndex?: number;
|
|
684
|
-
}
|
|
685
|
-
/**
|
|
686
|
-
* Where the iteration's worker was placed. `sibling` = a fresh sandbox the
|
|
687
|
-
* kernel created via `sandboxClient.create`. `fleet` = an existing machine in
|
|
688
|
-
* a shared-workspace fleet — workers see the caller's filesystem and any diff
|
|
689
|
-
* they write lands on it directly.
|
|
690
|
-
*
|
|
691
|
-
* @experimental
|
|
692
|
-
*/
|
|
693
|
-
interface LoopIterationDispatchPayload {
|
|
694
|
-
iterationIndex: number;
|
|
695
|
-
agentRunName: string;
|
|
696
|
-
placement: 'sibling' | 'fleet';
|
|
697
|
-
/** Set on every placement. Lets analyst loops correlate per-iteration logs. */
|
|
698
|
-
sandboxId?: string;
|
|
699
|
-
/** Set only when `placement === 'fleet'`. */
|
|
700
|
-
fleetId?: string;
|
|
701
|
-
/** Set only when `placement === 'fleet'`. */
|
|
702
|
-
machineId?: string;
|
|
703
|
-
/** Plan round this iteration belongs to. */
|
|
704
|
-
groupId?: number;
|
|
705
|
-
/** Iteration this one was planned from; `undefined` ⇒ root. */
|
|
706
|
-
parentIndex?: number;
|
|
707
|
-
}
|
|
708
|
-
/** @experimental */
|
|
709
|
-
interface LoopIterationEndedPayload {
|
|
710
|
-
iterationIndex: number;
|
|
711
|
-
agentRunName: string;
|
|
712
|
-
outputHash?: string;
|
|
713
|
-
verdict?: DefaultVerdict;
|
|
714
|
-
error?: string;
|
|
715
|
-
costUsd: number;
|
|
716
|
-
durationMs: number;
|
|
717
|
-
/** Summed LLM token usage for this iteration — maps to gen_ai.usage.* on the
|
|
718
|
-
* branch span. Omitted when no `llm_call` events carried token counts. */
|
|
719
|
-
tokenUsage?: LoopTokenUsage;
|
|
720
|
-
/** Plan round this iteration belongs to. */
|
|
721
|
-
groupId?: number;
|
|
722
|
-
/** Iteration this one was planned from; `undefined` ⇒ root. */
|
|
723
|
-
parentIndex?: number;
|
|
724
|
-
/** Truncated string preview of the parsed output — for a viewer's drawer.
|
|
725
|
-
* Bounded to ~280 chars; never the full payload. */
|
|
726
|
-
outputPreview?: string;
|
|
727
|
-
}
|
|
728
|
-
/** @experimental */
|
|
729
|
-
interface LoopDecisionPayload {
|
|
730
|
-
decision: string;
|
|
731
|
-
historyLength: number;
|
|
732
|
-
}
|
|
733
|
-
/** @experimental */
|
|
734
|
-
interface LoopEndedPayload {
|
|
735
|
-
winnerIterationIndex?: number;
|
|
736
|
-
totalCostUsd: number;
|
|
737
|
-
durationMs: number;
|
|
738
|
-
iterations: number;
|
|
739
|
-
}
|
|
740
|
-
/** Emitted when a box's `delete()` throws or times out during teardown — the
|
|
741
|
-
* loop swallows the failure (platform reaps on expiry) but surfaces it here so
|
|
742
|
-
* a real leak (e.g. mid-loop auth expiry) is observable. @experimental */
|
|
743
|
-
interface LoopTeardownFailedPayload {
|
|
744
|
-
sandboxId?: string;
|
|
745
|
-
/** `'timeout'` or the delete error message. */
|
|
746
|
-
reason: string;
|
|
747
|
-
}
|
|
748
|
-
/**
|
|
749
|
-
* Execution context for `runAgentRounds`: the sandbox client the kernel creates boxes through, plus optional runtime hooks.
|
|
750
|
-
*
|
|
751
|
-
* @experimental
|
|
752
|
-
*/
|
|
753
|
-
interface ExecCtx {
|
|
754
|
-
/** Sandbox SDK client — the kernel calls `.create()` per iteration. */
|
|
755
|
-
sandboxClient: SandboxClient;
|
|
756
|
-
/** Optional runtime hooks. Execution-scoped; never part of `AgentProfile`. */
|
|
757
|
-
hooks?: RuntimeHooks;
|
|
758
|
-
/** Optional trace emitter. When set, the kernel emits `loop.*` events. */
|
|
759
|
-
traceEmitter?: LoopTraceEmitter;
|
|
760
|
-
/**
|
|
761
|
-
* Optional per-event tee. When set, the kernel forwards EVERY raw event from
|
|
762
|
-
* each iteration's `streamPrompt` stream as it arrives, so a host can stream
|
|
763
|
-
* the agent's live output (tokens, tool calls) token-by-token. The observer
|
|
764
|
-
* receives a defensive copy of each event — mutating it cannot affect the
|
|
765
|
-
* run's own cost accounting or output parsing. Called synchronously in the hot
|
|
766
|
-
* stream loop and never awaited, so a slow or never-settling observer cannot
|
|
767
|
-
* stall the stream; keep it cheap. An async observer is fire-and-forget: its
|
|
768
|
-
* promise is not awaited, so events carry no ordering or backpressure
|
|
769
|
-
* guarantees (the next event may be observed before a prior async observer
|
|
770
|
-
* settles) — use it for side-effect telemetry, not sequential processing.
|
|
771
|
-
* Both a synchronous throw and a rejected returned promise are caught +
|
|
772
|
-
* ignored so the observer can never break the run — but prefer not to depend
|
|
773
|
-
* on that.
|
|
774
|
-
*
|
|
775
|
-
* @experimental
|
|
776
|
-
*/
|
|
777
|
-
onSandboxEvent?: (event: SandboxEvent, meta: {
|
|
778
|
-
iterationIndex: number;
|
|
779
|
-
agentRunName: string;
|
|
780
|
-
}) => void | PromiseLike<void>;
|
|
781
|
-
/**
|
|
782
|
-
* Optional production-run handle. When set, every synthesized `llm_call`
|
|
783
|
-
* the kernel infers from a sandbox event stream is forwarded via
|
|
784
|
-
* `runHandle.observe` so per-run cost aggregates pick up loop spend.
|
|
785
|
-
*/
|
|
786
|
-
runHandle?: RuntimeRunHandle;
|
|
787
|
-
/** Cooperative cancellation signal. */
|
|
788
|
-
signal?: AbortSignal;
|
|
789
|
-
/**
|
|
790
|
-
* Trace id for OTEL correlation. When set alongside `traceEmitter`, the
|
|
791
|
-
* exporter uses this as the parent trace for all emitted spans. Typically
|
|
792
|
-
* inherited from TRACE_ID env var in MCP subprocess mode.
|
|
793
|
-
*/
|
|
794
|
-
traceId?: string;
|
|
795
|
-
/**
|
|
796
|
-
* Parent span id for OTEL correlation. Loop events become children of
|
|
797
|
-
* this span. Typically inherited from PARENT_SPAN_ID env var.
|
|
798
|
-
*/
|
|
799
|
-
parentSpanId?: string;
|
|
800
|
-
}
|
|
801
|
-
|
|
802
|
-
export { type AgentRunSpec as A, type LoopIterationEndedPayload as B, type LoopIterationStartedPayload as C, type Driver as D, type ExecCtx as E, type LoopPlanDescription as F, type LoopPlanPayload as G, type LoopStartedPayload as H, type Iteration as I, type LoopTeardownFailedPayload as J, type MountManifestEntry as K, type LoopTokenUsage as L, type MountRecorder as M, type RunProvenance as N, type OutputAdapter as O, type ValidationCtx as P, type RuntimeHooks as R, type SelectionReceipt as S, type Validator as V, type SandboxClient as a, type LoopSandboxPlacement as b, type LoopTraceEvent as c, type RuntimeDecisionEvidenceRef as d, type RuntimeDecisionKind as e, type RuntimeDecisionPoint as f, type RuntimeHookContext as g, type RuntimeHookErrorContext as h, type RuntimeHookEvent as i, type RuntimeHookPhase as j, type RuntimeHookTarget as k, type RuntimeRunHandle as l, type RuntimeRunPersistenceAdapter as m, type RuntimeRunRow as n, composeRuntimeHooks as o, defineRuntimeHooks as p, notifyRuntimeDecisionPoint as q, notifyRuntimeHookEvent as r, startRuntimeRun as s, type LoopTraceEmitter as t, type LoopWinner as u, type LoopLineageOptions as v, type LoopResult as w, type LoopDecisionPayload as x, type LoopEndedPayload as y, type LoopIterationDispatchPayload as z };
|