@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
|
@@ -1,328 +0,0 @@
|
|
|
1
|
-
import { ControlEvalResult, KnowledgeReadinessReport, KnowledgeRequirement } from '@tangle-network/agent-eval';
|
|
2
|
-
import { e as AgentRuntimeEvent, R as RuntimeStreamEvent, f as AgentTaskStatus } from './types-BwoZWq-i.js';
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* The one router chat client: direct OpenAI-compatible completions through the
|
|
6
|
-
* Tangle router — the cheapest dial, no sandbox. Three layers: `routerChatWithUsage`
|
|
7
|
-
* (chat-only), `routerChatWithTools` (one completion with function tools), and
|
|
8
|
-
* `routerToolLoop` (the off-box agentic loop over tool-calling). Shared by the
|
|
9
|
-
* built-in executors and the bench/lab harnesses.
|
|
10
|
-
*
|
|
11
|
-
* Reports REAL token usage so the backend-integrity guard sees a real backend.
|
|
12
|
-
* Returns `undefined` usage when the provider omitted it — never a fabricated 0
|
|
13
|
-
* (a phantom 0 reads as a free call downstream, which the gate would act on).
|
|
14
|
-
*/
|
|
15
|
-
|
|
16
|
-
interface RouterConfig {
|
|
17
|
-
routerBaseUrl: string;
|
|
18
|
-
routerKey: string;
|
|
19
|
-
model: string;
|
|
20
|
-
/**
|
|
21
|
-
* Optional completion transport. When set, `routerChatWithUsage` / `routerChatWithTools` call it
|
|
22
|
-
* with the OpenAI-shape request body and use the parsed `/chat/completions` JSON it returns,
|
|
23
|
-
* INSTEAD of `fetch(routerBaseUrl + '/chat/completions')`. When absent the fetch path runs
|
|
24
|
-
* unchanged — the live router stays the default. The injection seam an offline benchmark uses to
|
|
25
|
-
* drive the worker with no network: a deterministic in-process responder satisfies it, no server.
|
|
26
|
-
*/
|
|
27
|
-
complete?: (body: Record<string, unknown>) => Promise<unknown>;
|
|
28
|
-
}
|
|
29
|
-
interface RouterChatResult {
|
|
30
|
-
/** The final answer, with any inline `<think>...</think>` block stripped into `reasoning`. */
|
|
31
|
-
content: string;
|
|
32
|
-
/**
|
|
33
|
-
* Thinking-model reasoning, when the provider surfaced it — either as a separate
|
|
34
|
-
* `reasoning`/`reasoning_content` message field (OpenRouter style) or inlined into
|
|
35
|
-
* `content` as a `<think>` block (Groq style). Undefined for non-thinking models.
|
|
36
|
-
* Downstream parsers that match single-token answers must read `content`, which is
|
|
37
|
-
* clean either way; before this split, Groq-style inlining made the same model look
|
|
38
|
-
* broken on one provider and fine on another.
|
|
39
|
-
*/
|
|
40
|
-
reasoning?: string;
|
|
41
|
-
/** REAL usage, or undefined when the provider reported none. */
|
|
42
|
-
usage?: {
|
|
43
|
-
input: number;
|
|
44
|
-
output: number;
|
|
45
|
-
};
|
|
46
|
-
/** Derived from usage via `estimateCost` when the model is priced; else undefined. */
|
|
47
|
-
costUsd?: number;
|
|
48
|
-
}
|
|
49
|
-
/** One OpenAI-compatible chat completion through the Tangle router, returning text + REAL token usage (`undefined` when the provider omits it — never a fabricated 0). */
|
|
50
|
-
declare function routerChatWithUsage(cfg: RouterConfig, messages: Array<{
|
|
51
|
-
role: string;
|
|
52
|
-
content: string;
|
|
53
|
-
}>, opts?: {
|
|
54
|
-
temperature?: number;
|
|
55
|
-
signal?: AbortSignal;
|
|
56
|
-
maxTokens?: number;
|
|
57
|
-
/**
|
|
58
|
-
* Reasoning control for thinking models, forwarded as `reasoning_effort`.
|
|
59
|
-
* 'none' is the load-bearing value: binary/single-token decisions (routing,
|
|
60
|
-
* gating) on a thinking model otherwise burn the whole token budget inside
|
|
61
|
-
* the think block — on slow backends (CPU-local) that turns into a client
|
|
62
|
-
* timeout, not just waste. Providers that ignore the field are handled by
|
|
63
|
-
* the reasoning/content split in `parseChatResult`.
|
|
64
|
-
*/
|
|
65
|
-
reasoningEffort?: 'none' | 'low' | 'medium' | 'high';
|
|
66
|
-
}): Promise<RouterChatResult>;
|
|
67
|
-
/** A tool-call the model emitted (provider-neutral; mirrors the runtime's ToolCallRequest). */
|
|
68
|
-
interface RouterToolCall {
|
|
69
|
-
id: string;
|
|
70
|
-
name: string;
|
|
71
|
-
/** Raw JSON arguments string as emitted by the model. */
|
|
72
|
-
arguments: string;
|
|
73
|
-
}
|
|
74
|
-
interface RouterChatToolsResult {
|
|
75
|
-
content: string | null;
|
|
76
|
-
toolCalls: RouterToolCall[];
|
|
77
|
-
usage?: {
|
|
78
|
-
input: number;
|
|
79
|
-
output: number;
|
|
80
|
-
};
|
|
81
|
-
costUsd?: number;
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* A router completion WITH tool-calling — the operator driver's LLM seam. Passes OpenAI-shape
|
|
85
|
-
* `messages` (system/user/assistant-with-tool_calls/tool roles) + function `tools`, and returns the
|
|
86
|
-
* assistant text plus the tool calls the model wants run. Same fail-loud + real-usage discipline as
|
|
87
|
-
* `routerChatWithUsage`. `tool_choice: 'auto'` lets the model decide; the driver loops on the result.
|
|
88
|
-
*/
|
|
89
|
-
declare function routerChatWithTools(cfg: RouterConfig, messages: ReadonlyArray<Record<string, unknown>>, tools: ReadonlyArray<{
|
|
90
|
-
type: 'function';
|
|
91
|
-
function: {
|
|
92
|
-
name: string;
|
|
93
|
-
description?: string;
|
|
94
|
-
parameters: unknown;
|
|
95
|
-
};
|
|
96
|
-
}>, opts?: {
|
|
97
|
-
temperature?: number;
|
|
98
|
-
signal?: AbortSignal;
|
|
99
|
-
toolChoice?: 'auto' | 'required' | 'none';
|
|
100
|
-
maxTokens?: number;
|
|
101
|
-
}): Promise<RouterChatToolsResult>;
|
|
102
|
-
interface ToolSpec {
|
|
103
|
-
type: 'function';
|
|
104
|
-
function: {
|
|
105
|
-
name: string;
|
|
106
|
-
description?: string;
|
|
107
|
-
parameters: unknown;
|
|
108
|
-
};
|
|
109
|
-
}
|
|
110
|
-
interface RouterToolLoopResult {
|
|
111
|
-
/** The model's final assistant text (the turn where it stopped calling tools, or the budget turn). */
|
|
112
|
-
final: string;
|
|
113
|
-
/** Inference turns spent (≤ maxTurns) — the equal-budget unit vs random@k. */
|
|
114
|
-
turns: number;
|
|
115
|
-
toolCalls: number;
|
|
116
|
-
/** The behavior trace: each tool call + its result, in order. What a trace-analyst
|
|
117
|
-
* steerer reads (behavior, never the verdict) to diagnose + redirect the next shot. */
|
|
118
|
-
toolTrace: Array<{
|
|
119
|
-
name: string;
|
|
120
|
-
args: string;
|
|
121
|
-
result: string;
|
|
122
|
-
}>;
|
|
123
|
-
usage: {
|
|
124
|
-
input: number;
|
|
125
|
-
output: number;
|
|
126
|
-
};
|
|
127
|
-
/** The full conversation after the loop (seed + every assistant/tool turn). Lets a caller
|
|
128
|
-
* CARRY the messages into the next shot (depth continuation) and read the trajectory. */
|
|
129
|
-
messages: Array<Record<string, unknown>>;
|
|
130
|
-
}
|
|
131
|
-
/**
|
|
132
|
-
* The tool-using router backend: a real agentic loop OVER the Tangle router (which
|
|
133
|
-
* supports tool-calling), off-box — no sandbox. Each turn is one router completion
|
|
134
|
-
* with `tools`; if the model emits tool_calls, `execute` runs them on the host and
|
|
135
|
-
* their results are folded back as `tool` messages; the loop repeats until the
|
|
136
|
-
* model answers without a tool call or the turn budget is hit. One turn = one
|
|
137
|
-
* inference call, so `maxTurns` is the equal-compute unit against random@k.
|
|
138
|
-
*
|
|
139
|
-
* This is the depth substrate for agentic gates (the worker ACTS, observes the real
|
|
140
|
-
* result, and continues) that the chat-only `routerChatWithUsage` cannot express.
|
|
141
|
-
*/
|
|
142
|
-
declare function routerToolLoop(cfg: RouterConfig, system: string, user: string, tools: ReadonlyArray<ToolSpec>, execute: (name: string, args: Record<string, unknown>) => Promise<string>, opts?: {
|
|
143
|
-
maxTurns?: number;
|
|
144
|
-
temperature?: number;
|
|
145
|
-
signal?: AbortSignal;
|
|
146
|
-
maxTokens?: number;
|
|
147
|
-
/** Seed the loop with an existing conversation (depth continuation) instead of
|
|
148
|
-
* `[system, user]`. When set, `system`/`user` are ignored. The array is copied. */
|
|
149
|
-
initialMessages?: ReadonlyArray<Record<string, unknown>>;
|
|
150
|
-
}): Promise<RouterToolLoopResult>;
|
|
151
|
-
/**
|
|
152
|
-
* The router as a supervisor BRAIN: the canonical `ToolLoopChat` seam backed by the router's
|
|
153
|
-
* tool-calling. The driver's spawn/observe/steer/await/stop turns become real router tool-calls.
|
|
154
|
-
* The turnkey production brain — tests script a mock `ToolLoopChat`; production passes
|
|
155
|
-
* `routerBrain(cfg)`. No message translation: the loop already speaks the router's OpenAI shape.
|
|
156
|
-
*/
|
|
157
|
-
declare function routerBrain(cfg: RouterConfig, opts?: {
|
|
158
|
-
temperature?: number;
|
|
159
|
-
}): ToolLoopChat;
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* THE canonical agentic tool-loop. One inference turn → run any requested tools → fold the
|
|
163
|
-
* results back as `tool` messages → repeat, until the model answers without a tool call or the
|
|
164
|
-
* turn budget is hit. One turn = one inference call (the equal-compute unit vs random@k).
|
|
165
|
-
*
|
|
166
|
-
* The inference is an INJECTABLE seam (`ToolLoopChat`): a router model, a sandboxed CLI
|
|
167
|
-
* harness, or a scripted mock all satisfy it — so the loop is backend-agnostic. The metered /
|
|
168
|
-
* steerable concerns the call sites add (a driver's conserved-pool + deadline bound; an inline
|
|
169
|
-
* executor's inbox flush + abort) attach via optional `hooks`; the skeleton stays one copy.
|
|
170
|
-
*/
|
|
171
|
-
|
|
172
|
-
type Msg = Record<string, unknown>;
|
|
173
|
-
/** One inference turn over the running conversation + the tool specs → the model's text, any
|
|
174
|
-
* tool calls, and token usage. The seam every brain satisfies. */
|
|
175
|
-
type ToolLoopChat = (messages: ReadonlyArray<Msg>, tools: ReadonlyArray<ToolSpec>) => Promise<{
|
|
176
|
-
content?: string | null;
|
|
177
|
-
toolCalls: RouterToolCall[];
|
|
178
|
-
usage?: {
|
|
179
|
-
input: number;
|
|
180
|
-
output: number;
|
|
181
|
-
};
|
|
182
|
-
/** The turn's inference cost (usd) when the provider priced it — for callers that meter usd
|
|
183
|
-
* into a conserved pool (the supervisor brain). `runBrainLoop` itself ignores it. */
|
|
184
|
-
costUsd?: number;
|
|
185
|
-
}>;
|
|
186
|
-
/** Self-compaction — bound the loop's OWN context window the way a fresh-respawn (dumb-Ralph) loop
|
|
187
|
-
* does, but in place. A stateless chat API re-sends the WHOLE running conversation every turn, so an
|
|
188
|
-
* agent that accumulates dozens of turns of tool results re-bills its entire transcript on every
|
|
189
|
-
* inference — the context-overflow-one-level-up that the conserved budget pool cannot fix. With
|
|
190
|
-
* compaction set, once the conversation exceeds `thresholdTokens` the accumulated middle (every prior
|
|
191
|
-
* assistant turn + tool result) is distilled into ONE compact progress note and the conversation is
|
|
192
|
-
* reset to `[...head, digest]`: the preserved head (system + the original task) survives, the stale
|
|
193
|
-
* turn-by-turn history does not. The model keeps deciding; it stops re-billing the whole transcript.
|
|
194
|
-
* Fires at a CLEAN turn boundary (after a turn's tool results are folded in, before the next
|
|
195
|
-
* inference) so it never orphans an assistant `tool_calls` from its `tool` replies. */
|
|
196
|
-
interface ToolLoopCompaction {
|
|
197
|
-
/** Compact once the estimated token count of the conversation exceeds this. */
|
|
198
|
-
readonly thresholdTokens: number;
|
|
199
|
-
/** Distill the conversation into a compact progress note that REPLACES the middle. Receives the
|
|
200
|
-
* full conversation (so it can summarize everything done so far); returns the digest string. */
|
|
201
|
-
readonly distill: (messages: ReadonlyArray<Msg>) => Promise<string> | string;
|
|
202
|
-
/** Leading messages preserved verbatim (system + the original task). Default 2. */
|
|
203
|
-
readonly preserveHead?: number;
|
|
204
|
-
/** Token estimator over the conversation. Default ≈ chars/4 (incl. tool-call arguments). */
|
|
205
|
-
readonly estimateTokens?: (messages: ReadonlyArray<Msg>) => number;
|
|
206
|
-
/** Notified each time a compaction fires — for observability/metering. */
|
|
207
|
-
readonly onCompact?: (info: {
|
|
208
|
-
turn: number;
|
|
209
|
-
beforeTokens: number;
|
|
210
|
-
afterTokens: number;
|
|
211
|
-
}) => void;
|
|
212
|
-
}
|
|
213
|
-
/** Public supervisor-facing compaction config: same knobs as the primitive, but `distill` is optional
|
|
214
|
-
* because the supervisor has a default digest that combines a brain note with live worker state. */
|
|
215
|
-
type ToolLoopCompactionOptions = Omit<ToolLoopCompaction, 'distill'> & {
|
|
216
|
-
readonly distill?: ToolLoopCompaction['distill'];
|
|
217
|
-
};
|
|
218
|
-
|
|
219
|
-
/**
|
|
220
|
-
*
|
|
221
|
-
* Sanitization for runtime telemetry. The rule: nothing user-controlled leaks
|
|
222
|
-
* unless the caller opts in with a `RuntimeTelemetryOptions` flag. This is the
|
|
223
|
-
* envelope that ends up in `agent_run.metadata.runtimeEvents` on every
|
|
224
|
-
* consumer, so the default must be safe.
|
|
225
|
-
*
|
|
226
|
-
* @stable
|
|
227
|
-
*/
|
|
228
|
-
|
|
229
|
-
/** @stable */
|
|
230
|
-
interface RuntimeTelemetryOptions {
|
|
231
|
-
/**
|
|
232
|
-
* Include raw task inputs. Off by default because task inputs often contain
|
|
233
|
-
* customer facts, credentials, source text, or internal IDs.
|
|
234
|
-
*/
|
|
235
|
-
includeInputs?: boolean;
|
|
236
|
-
/** Include requirement descriptions. Secret requirements are always redacted. */
|
|
237
|
-
includeRequirementDescriptions?: boolean;
|
|
238
|
-
/** Include evidence IDs. Off by default; counts are safer for shared reports. */
|
|
239
|
-
includeEvidenceIds?: boolean;
|
|
240
|
-
/** Include user answers from question preflight. Off by default. */
|
|
241
|
-
includeUserAnswers?: boolean;
|
|
242
|
-
/** Include action payloads and action results for control steps. Off by default. */
|
|
243
|
-
includeControlPayloads?: boolean;
|
|
244
|
-
/** Include task metadata. Off by default because metadata may carry IDs or policy internals. */
|
|
245
|
-
includeMetadata?: boolean;
|
|
246
|
-
/** Include eval detail/evidence strings. Off by default because validators may echo private input. */
|
|
247
|
-
includeEvalDetails?: boolean;
|
|
248
|
-
}
|
|
249
|
-
/** @stable */
|
|
250
|
-
interface SanitizedKnowledgeRequirement {
|
|
251
|
-
id: string;
|
|
252
|
-
description?: string;
|
|
253
|
-
requiredFor: string[];
|
|
254
|
-
category: KnowledgeRequirement['category'];
|
|
255
|
-
acquisitionMode: KnowledgeRequirement['acquisitionMode'];
|
|
256
|
-
importance: KnowledgeRequirement['importance'];
|
|
257
|
-
freshness: KnowledgeRequirement['freshness'];
|
|
258
|
-
sensitivity: KnowledgeRequirement['sensitivity'];
|
|
259
|
-
confidenceNeeded: number;
|
|
260
|
-
currentConfidence: number;
|
|
261
|
-
evidenceCount: number;
|
|
262
|
-
evidenceIds?: string[];
|
|
263
|
-
fallbackPolicy: KnowledgeRequirement['fallbackPolicy'];
|
|
264
|
-
}
|
|
265
|
-
/** @stable */
|
|
266
|
-
interface SanitizedKnowledgeReadinessReport {
|
|
267
|
-
taskId: string;
|
|
268
|
-
readinessScore: number;
|
|
269
|
-
recommendedAction: KnowledgeReadinessReport['recommendedAction'];
|
|
270
|
-
severity: KnowledgeReadinessReport['severity'];
|
|
271
|
-
reason: string;
|
|
272
|
-
blockingMissingRequirements: SanitizedKnowledgeRequirement[];
|
|
273
|
-
nonBlockingGaps: SanitizedKnowledgeRequirement[];
|
|
274
|
-
evidenceCount: number;
|
|
275
|
-
evidenceIds?: string[];
|
|
276
|
-
missingRequirementIds: string[];
|
|
277
|
-
}
|
|
278
|
-
/** Strip PII and large blobs from a `KnowledgeReadinessReport` for safe telemetry emission. @stable */
|
|
279
|
-
declare function sanitizeKnowledgeReadinessReport(report: KnowledgeReadinessReport, options?: RuntimeTelemetryOptions): SanitizedKnowledgeReadinessReport;
|
|
280
|
-
/** Reduce an `AgentRuntimeEvent` to a PII-safe, serializable plain object for telemetry. @stable */
|
|
281
|
-
declare function sanitizeAgentRuntimeEvent<TState, TAction, TActionResult, TEval extends ControlEvalResult>(event: AgentRuntimeEvent<TState, TAction, TActionResult, TEval>, options?: RuntimeTelemetryOptions): Record<string, unknown>;
|
|
282
|
-
/** Reduce a `RuntimeStreamEvent` to a PII-safe, serializable plain object for telemetry. @stable */
|
|
283
|
-
declare function sanitizeRuntimeStreamEvent(event: RuntimeStreamEvent, options?: RuntimeTelemetryOptions): Record<string, unknown>;
|
|
284
|
-
/** @stable */
|
|
285
|
-
interface RuntimeEventCollector<TState = unknown, TAction = unknown, TActionResult = unknown, TEval extends ControlEvalResult = ControlEvalResult> {
|
|
286
|
-
onEvent: (event: AgentRuntimeEvent<TState, TAction, TActionResult, TEval>) => void;
|
|
287
|
-
events: Array<Record<string, unknown>>;
|
|
288
|
-
}
|
|
289
|
-
/** @stable */
|
|
290
|
-
type RuntimeStreamEventSink = (event: RuntimeStreamEvent) => void;
|
|
291
|
-
/** @stable */
|
|
292
|
-
interface RuntimeStreamEventSummary {
|
|
293
|
-
/** Total count of sanitized events collected. */
|
|
294
|
-
eventCount: number;
|
|
295
|
-
/** Count of events per `type`. Useful for log-line summaries. */
|
|
296
|
-
eventCountsByType: Record<string, number>;
|
|
297
|
-
/** First session id observed in a `session_created` / `session_resumed` event, if any. */
|
|
298
|
-
firstSessionId?: string;
|
|
299
|
-
/** Last `final` event's status, if a final event was observed. */
|
|
300
|
-
finalStatus?: AgentTaskStatus;
|
|
301
|
-
/** Last `final` event's reason, if a final event was observed. */
|
|
302
|
-
finalReason?: string;
|
|
303
|
-
/** Concatenated `text_delta.text` across the stream, even when payloads are redacted. */
|
|
304
|
-
finalText: string;
|
|
305
|
-
}
|
|
306
|
-
/** @stable */
|
|
307
|
-
interface RuntimeStreamEventCollector {
|
|
308
|
-
onEvent: RuntimeStreamEventSink;
|
|
309
|
-
events: Array<Record<string, unknown>>;
|
|
310
|
-
/** Snapshot of a small streaming-flavored summary derived from collected events. */
|
|
311
|
-
summary(): RuntimeStreamEventSummary;
|
|
312
|
-
}
|
|
313
|
-
/** Build an in-memory collector that sanitizes and accumulates `AgentRuntimeEvent`s for inspection. @stable */
|
|
314
|
-
declare function createRuntimeEventCollector<TState = unknown, TAction = unknown, TActionResult = unknown, TEval extends ControlEvalResult = ControlEvalResult>(options?: RuntimeTelemetryOptions): RuntimeEventCollector<TState, TAction, TActionResult, TEval>;
|
|
315
|
-
/**
|
|
316
|
-
*
|
|
317
|
-
* Streaming-event counterpart of `createRuntimeEventCollector`. Pass each
|
|
318
|
-
* event yielded by `runAgentTaskStream` through `onEvent` and read the
|
|
319
|
-
* sanitized copies off `events`; the same `RuntimeTelemetryOptions` redaction
|
|
320
|
-
* flags apply. Kept distinct from `createRuntimeEventCollector` because the
|
|
321
|
-
* stream and non-stream event shapes overlap on `type` literals — dispatching
|
|
322
|
-
* on `type` alone would misroute events.
|
|
323
|
-
*
|
|
324
|
-
* @stable
|
|
325
|
-
*/
|
|
326
|
-
declare function createRuntimeStreamEventCollector(options?: RuntimeTelemetryOptions): RuntimeStreamEventCollector;
|
|
327
|
-
|
|
328
|
-
export { type RouterConfig as R, type SanitizedKnowledgeReadinessReport as S, type ToolLoopChat as T, type ToolLoopCompactionOptions as a, type ToolSpec as b, type RuntimeTelemetryOptions as c, type RuntimeEventCollector as d, type RuntimeStreamEventCollector as e, createRuntimeEventCollector as f, createRuntimeStreamEventCollector as g, sanitizeKnowledgeReadinessReport as h, sanitizeRuntimeStreamEvent as i, type RouterChatResult as j, type RouterChatToolsResult as k, type RouterToolCall as l, type RouterToolLoopResult as m, type ToolLoopCompaction as n, routerChatWithTools as o, routerChatWithUsage as p, routerToolLoop as q, routerBrain as r, sanitizeAgentRuntimeEvent as s };
|