@tangle-network/agent-runtime 0.49.0 → 0.50.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/dist/agent.d.ts +1 -1
- package/dist/agent.js +1 -1
- package/dist/analyst-loop.d.ts +1 -1
- package/dist/{chunk-U2VEWKKK.js → chunk-BKAIVNFA.js} +3 -3
- package/dist/{chunk-PXUTIMGJ.js → chunk-CM2IK7VS.js} +148 -25
- package/dist/chunk-CM2IK7VS.js.map +1 -0
- package/dist/{chunk-XTEZ3YJ4.js → chunk-ML4IXGTV.js} +2 -2
- package/dist/{chunk-IQS4HI3F.js → chunk-NDM5VXZW.js} +8 -6
- package/dist/{chunk-IQS4HI3F.js.map → chunk-NDM5VXZW.js.map} +1 -1
- package/dist/chunk-OM3YNZIW.js +978 -0
- package/dist/chunk-OM3YNZIW.js.map +1 -0
- package/dist/{chunk-VIEDXELL.js → chunk-RHW75JW5.js} +94 -348
- package/dist/chunk-RHW75JW5.js.map +1 -0
- package/dist/{coder-CVZNGbyg.d.ts → coder-_YCf3BAK.d.ts} +2 -2
- package/dist/{driver-DYU2sgHr.d.ts → driver-DLI1io57.d.ts} +1 -1
- package/dist/index.d.ts +7 -7
- package/dist/index.js +13 -11
- package/dist/index.js.map +1 -1
- package/dist/{kb-gate-CsXpNRk7.d.ts → kb-gate-CHAyt4aI.d.ts} +436 -10
- package/dist/{loop-runner-bin-Cgn0A-NW.d.ts → loop-runner-bin-DFUNgpeK.d.ts} +4 -4
- package/dist/loop-runner-bin.d.ts +5 -5
- package/dist/loop-runner-bin.js +3 -3
- package/dist/loops.d.ts +5 -5
- package/dist/loops.js +7 -1
- package/dist/mcp/bin.js +28 -14
- package/dist/mcp/bin.js.map +1 -1
- package/dist/mcp/index.d.ts +17 -56
- package/dist/mcp/index.js +17 -5
- package/dist/mcp/index.js.map +1 -1
- package/dist/openai-tools-D4HLDWgw.d.ts +45 -0
- package/dist/profiles.d.ts +2 -2
- package/dist/{run-loop-DvD4aGiE.d.ts → run-loop-BIineL1T.d.ts} +1 -1
- package/dist/runtime.d.ts +119 -17
- package/dist/runtime.js +7 -1
- package/dist/{types-BpDfCPUp.d.ts → types-5MGt5KTY.d.ts} +1 -1
- package/dist/{types-nBMuollC.d.ts → types-BEQsBhOE.d.ts} +1 -1
- package/dist/workflow.d.ts +2 -2
- package/dist/workflow.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-GHX7XOJ2.js +0 -433
- package/dist/chunk-GHX7XOJ2.js.map +0 -1
- package/dist/chunk-PXUTIMGJ.js.map +0 -1
- package/dist/chunk-VIEDXELL.js.map +0 -1
- package/dist/otel-export-EzfsVUhh.d.ts +0 -191
- /package/dist/{chunk-U2VEWKKK.js.map → chunk-BKAIVNFA.js.map} +0 -0
- /package/dist/{chunk-XTEZ3YJ4.js.map → chunk-ML4IXGTV.js.map} +0 -0
package/dist/agent.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import * as _tangle_network_agent_eval from '@tangle-network/agent-eval';
|
|
2
2
|
import { TraceAnalystKindSpec, AnalystFinding } from '@tangle-network/agent-eval';
|
|
3
|
-
import { R as RuntimeStreamEvent, S as SandboxClient, O as OutputAdapter, A as AgentRunSpec } from './types-
|
|
3
|
+
import { R as RuntimeStreamEvent, S as SandboxClient, O as OutputAdapter, A as AgentRunSpec } from './types-BEQsBhOE.js';
|
|
4
4
|
import { A as AgentSurfaces } from './improvement-adapter-BC4HhuAR.js';
|
|
5
5
|
export { C as CreateSurfaceImprovementAdapterOpts, D as DraftPatchInput, a as DraftPatchOutput, R as ResolvedSurface, S as SurfaceImprovementEdit, b as SurfaceValidationIssue, c as createSurfaceImprovementAdapter, r as renderSurfaceIssues, d as resolveSubjectPath, v as validateSurfaces } from './improvement-adapter-BC4HhuAR.js';
|
|
6
6
|
import { K as KnowledgeAdapter, a as RunAnalystLoopResult } from './types-p8dWBIXL.js';
|
package/dist/agent.js
CHANGED
package/dist/analyst-loop.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { TraceAnalystByteBudgets, TraceAnalysisStore } from '@tangle-network/agent-eval';
|
|
2
|
-
import { I as Iteration } from './types-
|
|
2
|
+
import { I as Iteration } from './types-BEQsBhOE.js';
|
|
3
3
|
import { R as RunAnalystLoopOpts, a as RunAnalystLoopResult } from './types-p8dWBIXL.js';
|
|
4
4
|
export { A as AnalystLoopEvent, b as AnalystRegistryLike, c as AnalystRegistryStreamingLike, d as AutoApplyPolicy, F as FindingsStoreLike, I as ImprovementAdapter, e as ImprovementEditBatch, f as ImprovementReport, K as KnowledgeAdapter, g as KnowledgeProposalBatch, h as KnowledgeReport } from './types-p8dWBIXL.js';
|
|
5
5
|
import '@tangle-network/sandbox';
|
|
@@ -3,14 +3,14 @@ import {
|
|
|
3
3
|
} from "./chunk-FNMGYYSS.js";
|
|
4
4
|
import {
|
|
5
5
|
createDefaultCoderDelegate
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-OM3YNZIW.js";
|
|
7
7
|
import {
|
|
8
8
|
runAnalystLoop
|
|
9
9
|
} from "./chunk-HNUXAZIJ.js";
|
|
10
10
|
import {
|
|
11
11
|
createDriver,
|
|
12
12
|
runLoop
|
|
13
|
-
} from "./chunk-
|
|
13
|
+
} from "./chunk-CM2IK7VS.js";
|
|
14
14
|
import {
|
|
15
15
|
ConfigError
|
|
16
16
|
} from "./chunk-GSUO5QS6.js";
|
|
@@ -200,4 +200,4 @@ export {
|
|
|
200
200
|
runLoopRunnerCli,
|
|
201
201
|
parseLoopRunnerArgv
|
|
202
202
|
};
|
|
203
|
-
//# sourceMappingURL=chunk-
|
|
203
|
+
//# sourceMappingURL=chunk-BKAIVNFA.js.map
|
|
@@ -3109,7 +3109,138 @@ function isNoEntError2(err) {
|
|
|
3109
3109
|
|
|
3110
3110
|
// src/runtime/supervise/runtime.ts
|
|
3111
3111
|
import { spawn } from "child_process";
|
|
3112
|
+
import { estimateCost as estimateCost2, isModelPriced as isModelPriced2 } from "@tangle-network/agent-eval";
|
|
3113
|
+
|
|
3114
|
+
// src/runtime/router-client.ts
|
|
3112
3115
|
import { estimateCost, isModelPriced } from "@tangle-network/agent-eval";
|
|
3116
|
+
async function routerChatWithUsage(cfg, messages, opts) {
|
|
3117
|
+
const url = `${cfg.routerBaseUrl.replace(/\/$/, "")}/chat/completions`;
|
|
3118
|
+
const headers = { "content-type": "application/json", authorization: `Bearer ${cfg.routerKey}` };
|
|
3119
|
+
let temperature = opts?.temperature ?? 0.2;
|
|
3120
|
+
let lastErr = "";
|
|
3121
|
+
for (let attempt = 0; attempt < 5; attempt += 1) {
|
|
3122
|
+
const res = await fetch(url, {
|
|
3123
|
+
method: "POST",
|
|
3124
|
+
headers,
|
|
3125
|
+
// max_tokens default is generous: THINKING models (kimi-k2.6) spend the budget on
|
|
3126
|
+
// reasoning_content first — a small router default yields EMPTY content.
|
|
3127
|
+
body: JSON.stringify({
|
|
3128
|
+
model: cfg.model,
|
|
3129
|
+
messages,
|
|
3130
|
+
temperature,
|
|
3131
|
+
max_tokens: opts?.maxTokens ?? 8192
|
|
3132
|
+
}),
|
|
3133
|
+
...opts?.signal ? { signal: opts.signal } : {}
|
|
3134
|
+
});
|
|
3135
|
+
if (res.ok) return parseChatResult(await res.json(), cfg.model);
|
|
3136
|
+
const status = res.status;
|
|
3137
|
+
const text = (await res.text()).slice(0, 200);
|
|
3138
|
+
lastErr = `router ${status}: ${text}`;
|
|
3139
|
+
if (status === 400 && /temperature/i.test(text) && temperature !== 1) {
|
|
3140
|
+
temperature = 1;
|
|
3141
|
+
continue;
|
|
3142
|
+
}
|
|
3143
|
+
if (![408, 425, 429, 500, 502, 503, 504, 520, 522, 524].includes(status))
|
|
3144
|
+
throw new Error(lastErr);
|
|
3145
|
+
if (attempt < 4) await new Promise((r) => setTimeout(r, 800 * 2 ** attempt));
|
|
3146
|
+
}
|
|
3147
|
+
throw new Error(`${lastErr} (exhausted retries)`);
|
|
3148
|
+
}
|
|
3149
|
+
function parseChatResult(json, model) {
|
|
3150
|
+
const data = json;
|
|
3151
|
+
const u = data.usage;
|
|
3152
|
+
const usage = u && typeof u.prompt_tokens === "number" && typeof u.completion_tokens === "number" ? { input: u.prompt_tokens, output: u.completion_tokens } : void 0;
|
|
3153
|
+
const costUsd = usage && isModelPriced(model) ? estimateCost(usage.input, usage.output, model) : void 0;
|
|
3154
|
+
return {
|
|
3155
|
+
content: data.choices?.[0]?.message?.content ?? "",
|
|
3156
|
+
...usage ? { usage } : {},
|
|
3157
|
+
...costUsd !== void 0 ? { costUsd } : {}
|
|
3158
|
+
};
|
|
3159
|
+
}
|
|
3160
|
+
async function routerChatWithTools(cfg, messages, tools, opts) {
|
|
3161
|
+
const res = await fetch(`${cfg.routerBaseUrl.replace(/\/$/, "")}/chat/completions`, {
|
|
3162
|
+
method: "POST",
|
|
3163
|
+
headers: { "content-type": "application/json", authorization: `Bearer ${cfg.routerKey}` },
|
|
3164
|
+
body: JSON.stringify({
|
|
3165
|
+
model: cfg.model,
|
|
3166
|
+
messages,
|
|
3167
|
+
tools,
|
|
3168
|
+
tool_choice: opts?.toolChoice ?? "auto",
|
|
3169
|
+
temperature: opts?.temperature ?? 0.3
|
|
3170
|
+
}),
|
|
3171
|
+
...opts?.signal ? { signal: opts.signal } : {}
|
|
3172
|
+
});
|
|
3173
|
+
if (!res.ok) throw new Error(`router ${res.status}: ${(await res.text()).slice(0, 200)}`);
|
|
3174
|
+
const data = await res.json();
|
|
3175
|
+
const msg = data.choices?.[0]?.message;
|
|
3176
|
+
const toolCalls = (msg?.tool_calls ?? []).map((tc, i) => ({
|
|
3177
|
+
id: tc.id ?? `call_${i}`,
|
|
3178
|
+
name: tc.function?.name ?? "",
|
|
3179
|
+
arguments: tc.function?.arguments ?? "{}"
|
|
3180
|
+
}));
|
|
3181
|
+
const u = data.usage;
|
|
3182
|
+
const usage = u && typeof u.prompt_tokens === "number" && typeof u.completion_tokens === "number" ? { input: u.prompt_tokens, output: u.completion_tokens } : void 0;
|
|
3183
|
+
const costUsd = usage && isModelPriced(cfg.model) ? estimateCost(usage.input, usage.output, cfg.model) : void 0;
|
|
3184
|
+
return {
|
|
3185
|
+
content: msg?.content ?? null,
|
|
3186
|
+
toolCalls,
|
|
3187
|
+
...usage ? { usage } : {},
|
|
3188
|
+
...costUsd !== void 0 ? { costUsd } : {}
|
|
3189
|
+
};
|
|
3190
|
+
}
|
|
3191
|
+
async function routerToolLoop(cfg, system, user, tools, execute, opts) {
|
|
3192
|
+
const maxTurns = opts?.maxTurns ?? 4;
|
|
3193
|
+
const messages = [
|
|
3194
|
+
{ role: "system", content: system },
|
|
3195
|
+
{ role: "user", content: user }
|
|
3196
|
+
];
|
|
3197
|
+
let toolCalls = 0;
|
|
3198
|
+
let lastText = "";
|
|
3199
|
+
const usage = { input: 0, output: 0 };
|
|
3200
|
+
const toolTrace = [];
|
|
3201
|
+
for (let turn = 1; turn <= maxTurns; turn += 1) {
|
|
3202
|
+
const r = await routerChatWithTools(cfg, messages, tools, {
|
|
3203
|
+
...opts?.temperature !== void 0 ? { temperature: opts.temperature } : {},
|
|
3204
|
+
...opts?.signal ? { signal: opts.signal } : {}
|
|
3205
|
+
});
|
|
3206
|
+
if (r.usage) {
|
|
3207
|
+
usage.input += r.usage.input;
|
|
3208
|
+
usage.output += r.usage.output;
|
|
3209
|
+
}
|
|
3210
|
+
if (r.content) lastText = r.content;
|
|
3211
|
+
if (r.toolCalls.length === 0)
|
|
3212
|
+
return { final: lastText, turns: turn, toolCalls, toolTrace, usage };
|
|
3213
|
+
messages.push({
|
|
3214
|
+
role: "assistant",
|
|
3215
|
+
content: r.content ?? "",
|
|
3216
|
+
tool_calls: r.toolCalls.map((tc) => ({
|
|
3217
|
+
id: tc.id,
|
|
3218
|
+
type: "function",
|
|
3219
|
+
function: { name: tc.name, arguments: tc.arguments }
|
|
3220
|
+
}))
|
|
3221
|
+
});
|
|
3222
|
+
for (const tc of r.toolCalls) {
|
|
3223
|
+
toolCalls += 1;
|
|
3224
|
+
let args = {};
|
|
3225
|
+
try {
|
|
3226
|
+
args = JSON.parse(tc.arguments);
|
|
3227
|
+
} catch {
|
|
3228
|
+
messages.push({
|
|
3229
|
+
role: "tool",
|
|
3230
|
+
tool_call_id: tc.id,
|
|
3231
|
+
content: `error: arguments were not valid JSON: ${tc.arguments.slice(0, 200)}`
|
|
3232
|
+
});
|
|
3233
|
+
continue;
|
|
3234
|
+
}
|
|
3235
|
+
const out = await execute(tc.name, args);
|
|
3236
|
+
messages.push({ role: "tool", tool_call_id: tc.id, content: out });
|
|
3237
|
+
toolTrace.push({ name: tc.name, args: tc.arguments, result: out });
|
|
3238
|
+
}
|
|
3239
|
+
}
|
|
3240
|
+
return { final: lastText, turns: maxTurns, toolCalls, toolTrace, usage };
|
|
3241
|
+
}
|
|
3242
|
+
|
|
3243
|
+
// src/runtime/supervise/runtime.ts
|
|
3113
3244
|
var routerSeamKey = "router";
|
|
3114
3245
|
var sandboxSeamKey = "sandbox";
|
|
3115
3246
|
var cliSeamKey = "cli";
|
|
@@ -3155,30 +3286,19 @@ var routerInlineExecutor = (spec, ctx) => {
|
|
|
3155
3286
|
const messages = taskToMessages(task, spec);
|
|
3156
3287
|
const started = Date.now();
|
|
3157
3288
|
const linked = linkSignals(signal, controller.signal);
|
|
3158
|
-
const
|
|
3159
|
-
|
|
3160
|
-
|
|
3161
|
-
|
|
3162
|
-
|
|
3163
|
-
});
|
|
3164
|
-
if (!res.ok) {
|
|
3165
|
-
throw new ValidationError(
|
|
3166
|
-
`routerInlineExecutor: router ${res.status}: ${(await res.text()).slice(0, 200)}`
|
|
3167
|
-
);
|
|
3168
|
-
}
|
|
3169
|
-
const data = await res.json();
|
|
3170
|
-
const u = data.usage;
|
|
3171
|
-
const usage = u && typeof u.prompt_tokens === "number" && typeof u.completion_tokens === "number" ? { input: u.prompt_tokens, output: u.completion_tokens } : void 0;
|
|
3172
|
-
const usd = usage && isModelPriced(model) ? estimateCost(usage.input, usage.output, model) : 0;
|
|
3173
|
-
const content = data.choices?.[0]?.message?.content ?? "";
|
|
3289
|
+
const r = await routerChatWithUsage(
|
|
3290
|
+
{ routerBaseUrl: seam.routerBaseUrl, routerKey: seam.routerKey, model },
|
|
3291
|
+
messages,
|
|
3292
|
+
linked ? { signal: linked } : {}
|
|
3293
|
+
);
|
|
3174
3294
|
const spent = {
|
|
3175
3295
|
iterations: 1,
|
|
3176
|
-
tokens: usage ? { input: usage.input, output: usage.output } : zeroTokenUsage(),
|
|
3177
|
-
usd,
|
|
3296
|
+
tokens: r.usage ? { input: r.usage.input, output: r.usage.output } : zeroTokenUsage(),
|
|
3297
|
+
usd: r.costUsd ?? 0,
|
|
3178
3298
|
ms: Date.now() - started
|
|
3179
3299
|
};
|
|
3180
|
-
const out = { content };
|
|
3181
|
-
artifact = { outRef: contentRef("router", { model, content }), out, spent };
|
|
3300
|
+
const out = { content: r.content };
|
|
3301
|
+
artifact = { outRef: contentRef("router", { model, content: r.content }), out, spent };
|
|
3182
3302
|
return artifact;
|
|
3183
3303
|
},
|
|
3184
3304
|
teardown(_grace) {
|
|
@@ -3285,7 +3405,7 @@ var routerToolsInlineExecutor = (spec, ctx) => {
|
|
|
3285
3405
|
messages.push({ role: "tool", tool_call_id: id, content: result });
|
|
3286
3406
|
}
|
|
3287
3407
|
}
|
|
3288
|
-
const usd =
|
|
3408
|
+
const usd = isModelPriced2(model) ? estimateCost2(tokens.input, tokens.output, model) : 0;
|
|
3289
3409
|
const spent = { iterations: turns, tokens, usd, ms: Date.now() - started };
|
|
3290
3410
|
const out = { content: lastText };
|
|
3291
3411
|
artifact = { outRef: contentRef("router-tools", { model, content: lastText }), out, spent };
|
|
@@ -4530,7 +4650,7 @@ function promotionGate(opts) {
|
|
|
4530
4650
|
import { pairedBootstrap, paretoFrontier } from "@tangle-network/agent-eval";
|
|
4531
4651
|
|
|
4532
4652
|
// src/runtime/strategy.ts
|
|
4533
|
-
import { createChatClient, estimateCost as
|
|
4653
|
+
import { createChatClient, estimateCost as estimateCost3, isModelPriced as isModelPriced3 } from "@tangle-network/agent-eval";
|
|
4534
4654
|
var taskNudge = "Use the available tools to bring the artifact to the required final state. Address EVERY distinct change the request implies. After each tool result, check what remains and continue. Re-read the values you set to confirm they took. Reply DONE only once every required change is made and verified.";
|
|
4535
4655
|
async function runShot(surface, _task, handle, tools, messages, opts, modelOverride) {
|
|
4536
4656
|
const innerTurns = opts.innerTurns ?? 4;
|
|
@@ -4722,7 +4842,7 @@ ${taskNudge}` }
|
|
|
4722
4842
|
spent: {
|
|
4723
4843
|
iterations: shot.completions,
|
|
4724
4844
|
tokens: shot.tokens,
|
|
4725
|
-
usd:
|
|
4845
|
+
usd: isModelPriced3(opts.model) ? estimateCost3(shot.tokens.input, shot.tokens.output, opts.model) : 0,
|
|
4726
4846
|
ms: 0
|
|
4727
4847
|
}
|
|
4728
4848
|
};
|
|
@@ -4752,7 +4872,7 @@ function analystExecutor(opts) {
|
|
|
4752
4872
|
spent: {
|
|
4753
4873
|
iterations: 1,
|
|
4754
4874
|
tokens,
|
|
4755
|
-
usd:
|
|
4875
|
+
usd: isModelPriced3(analystModel) ? estimateCost3(tokens.input, tokens.output, analystModel) : 0,
|
|
4756
4876
|
ms: 0
|
|
4757
4877
|
}
|
|
4758
4878
|
};
|
|
@@ -6358,6 +6478,9 @@ export {
|
|
|
6358
6478
|
InMemoryCorpus,
|
|
6359
6479
|
FileCorpus,
|
|
6360
6480
|
renderCorpusToInstructions,
|
|
6481
|
+
routerChatWithUsage,
|
|
6482
|
+
routerChatWithTools,
|
|
6483
|
+
routerToolLoop,
|
|
6361
6484
|
createExecutor,
|
|
6362
6485
|
createExecutorRegistry,
|
|
6363
6486
|
spendFromUsageEvents,
|
|
@@ -6396,4 +6519,4 @@ export {
|
|
|
6396
6519
|
gitWorkspace,
|
|
6397
6520
|
jjWorkspace
|
|
6398
6521
|
};
|
|
6399
|
-
//# sourceMappingURL=chunk-
|
|
6522
|
+
//# sourceMappingURL=chunk-CM2IK7VS.js.map
|