@tangle-network/agent-runtime 0.76.0 → 0.77.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.js +2 -2
- package/dist/{chunk-SA5GCF2X.js → chunk-CEW5BMGN.js} +177 -24
- package/dist/chunk-CEW5BMGN.js.map +1 -0
- package/dist/{chunk-QKNBYHMK.js → chunk-KKHMDE5I.js} +3 -3
- package/dist/{chunk-MRWXCFV5.js → chunk-LFL7K5FM.js} +2 -2
- package/dist/{chunk-ZKMOIEOB.js → chunk-RQYPH2QE.js} +28 -24
- package/dist/chunk-RQYPH2QE.js.map +1 -0
- package/dist/{coordination-c_7Olmtq.d.ts → coordination-CZe4lTxy.d.ts} +1 -1
- package/dist/index.js +4 -4
- package/dist/intelligence.d.ts +1 -1
- package/dist/loop-runner-bin.js +3 -3
- package/dist/loops.d.ts +183 -6
- package/dist/loops.js +8 -2
- package/dist/mcp/bin.js +1 -1
- package/dist/mcp/index.d.ts +3 -3
- package/dist/mcp/index.js +3 -3
- package/dist/{router-client-C7kp_ECN.d.ts → router-client-CMAWGv1h.d.ts} +8 -0
- package/package.json +5 -4
- package/dist/chunk-SA5GCF2X.js.map +0 -1
- package/dist/chunk-ZKMOIEOB.js.map +0 -1
- /package/dist/{chunk-QKNBYHMK.js.map → chunk-KKHMDE5I.js.map} +0 -0
- /package/dist/{chunk-MRWXCFV5.js.map → chunk-LFL7K5FM.js.map} +0 -0
package/dist/agent.js
CHANGED
|
@@ -19,7 +19,7 @@ import {
|
|
|
19
19
|
stringifySafe,
|
|
20
20
|
withDriverExecutor,
|
|
21
21
|
zeroTokenUsage
|
|
22
|
-
} from "./chunk-
|
|
22
|
+
} from "./chunk-RQYPH2QE.js";
|
|
23
23
|
import {
|
|
24
24
|
AnalystError,
|
|
25
25
|
PlannerError,
|
|
@@ -459,13 +459,85 @@ async function harvestCorpus(opts) {
|
|
|
459
459
|
return report;
|
|
460
460
|
}
|
|
461
461
|
|
|
462
|
-
// src/runtime/
|
|
462
|
+
// src/runtime/in-process-sandbox-client.ts
|
|
463
|
+
import { mkdtempSync, rmSync } from "fs";
|
|
464
|
+
import { mkdir, readFile, writeFile } from "fs/promises";
|
|
465
|
+
import { tmpdir } from "os";
|
|
466
|
+
import { dirname, join } from "path";
|
|
463
467
|
function isAsyncIterable(v) {
|
|
464
468
|
return typeof v === "object" && v !== null && Symbol.asyncIterator in v;
|
|
465
469
|
}
|
|
470
|
+
function inProcessSandboxClient(options) {
|
|
471
|
+
const { onPrompt, workdir: workdirPrefix, id: idOption } = options;
|
|
472
|
+
let seq = 0;
|
|
473
|
+
return {
|
|
474
|
+
async create(_options) {
|
|
475
|
+
const current = seq++;
|
|
476
|
+
const id = typeof idOption === "function" ? idOption(current) : idOption ?? `in-process-${current}`;
|
|
477
|
+
const boxWorkdir = workdirPrefix !== void 0 ? mkdtempSync(join(tmpdir(), `${workdirPrefix}-`)) : void 0;
|
|
478
|
+
let round = 0;
|
|
479
|
+
const fsMembers = boxWorkdir !== void 0 ? {
|
|
480
|
+
fs: {
|
|
481
|
+
async read(path) {
|
|
482
|
+
return readFile(join(boxWorkdir, path), "utf8");
|
|
483
|
+
},
|
|
484
|
+
async write(path, content) {
|
|
485
|
+
const abs = join(boxWorkdir, path);
|
|
486
|
+
await mkdir(dirname(abs), { recursive: true });
|
|
487
|
+
await writeFile(abs, content, "utf8");
|
|
488
|
+
}
|
|
489
|
+
},
|
|
490
|
+
async exec(command) {
|
|
491
|
+
const { exec: execCb } = await import("child_process");
|
|
492
|
+
const { promisify } = await import("util");
|
|
493
|
+
const execAsync = promisify(execCb);
|
|
494
|
+
try {
|
|
495
|
+
const { stdout, stderr } = await execAsync(command, {
|
|
496
|
+
cwd: boxWorkdir,
|
|
497
|
+
timeout: 3e4
|
|
498
|
+
});
|
|
499
|
+
return { exitCode: 0, stdout, stderr };
|
|
500
|
+
} catch (err) {
|
|
501
|
+
const e = err;
|
|
502
|
+
return {
|
|
503
|
+
exitCode: e.code ?? 1,
|
|
504
|
+
stdout: e.stdout ?? "",
|
|
505
|
+
stderr: e.stderr ?? e.message ?? ""
|
|
506
|
+
};
|
|
507
|
+
}
|
|
508
|
+
}
|
|
509
|
+
} : {};
|
|
510
|
+
const box = {
|
|
511
|
+
id,
|
|
512
|
+
async *streamPrompt(message, opts) {
|
|
513
|
+
const prompt = typeof message === "string" ? message : JSON.stringify(message);
|
|
514
|
+
const signal = opts?.signal ?? new AbortController().signal;
|
|
515
|
+
const ctx = { round, workdir: boxWorkdir, signal };
|
|
516
|
+
round += 1;
|
|
517
|
+
const produced = await onPrompt(prompt, ctx);
|
|
518
|
+
if (isAsyncIterable(produced)) {
|
|
519
|
+
for await (const ev of produced) yield ev;
|
|
520
|
+
} else {
|
|
521
|
+
for (const ev of produced) yield ev;
|
|
522
|
+
}
|
|
523
|
+
},
|
|
524
|
+
...fsMembers,
|
|
525
|
+
async delete() {
|
|
526
|
+
if (boxWorkdir !== void 0) rmSync(boxWorkdir, { recursive: true, force: true });
|
|
527
|
+
}
|
|
528
|
+
};
|
|
529
|
+
return box;
|
|
530
|
+
}
|
|
531
|
+
};
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
// src/runtime/inline-sandbox-client.ts
|
|
535
|
+
function isAsyncIterable2(v) {
|
|
536
|
+
return typeof v === "object" && v !== null && Symbol.asyncIterator in v;
|
|
537
|
+
}
|
|
466
538
|
async function settle(exec, task, signal) {
|
|
467
539
|
const r = exec.execute(task, signal);
|
|
468
|
-
if (
|
|
540
|
+
if (isAsyncIterable2(r)) {
|
|
469
541
|
for await (const _ of r) {
|
|
470
542
|
}
|
|
471
543
|
return exec.resultArtifact();
|
|
@@ -1810,7 +1882,8 @@ async function runShot(surface, _task, handle, tools, messages, opts, modelOverr
|
|
|
1810
1882
|
{
|
|
1811
1883
|
routerBaseUrl: opts.routerBaseUrl,
|
|
1812
1884
|
routerKey: opts.routerKey,
|
|
1813
|
-
model: modelOverride ?? opts.model
|
|
1885
|
+
model: modelOverride ?? opts.model,
|
|
1886
|
+
...opts.complete ? { complete: opts.complete } : {}
|
|
1814
1887
|
},
|
|
1815
1888
|
"",
|
|
1816
1889
|
"",
|
|
@@ -1838,15 +1911,50 @@ function compactTrajectory(messages) {
|
|
|
1838
1911
|
return calls ? `CALL ${calls}` : `SAY ${String(m.content).slice(0, 200)}`;
|
|
1839
1912
|
}).join("\n").slice(0, 7e3);
|
|
1840
1913
|
}
|
|
1914
|
+
function analystChat(opts, defaultModel) {
|
|
1915
|
+
if (!opts.complete) {
|
|
1916
|
+
return createChatClient({
|
|
1917
|
+
transport: "router",
|
|
1918
|
+
apiKey: opts.routerKey,
|
|
1919
|
+
baseUrl: opts.routerBaseUrl,
|
|
1920
|
+
defaultModel
|
|
1921
|
+
});
|
|
1922
|
+
}
|
|
1923
|
+
const complete = opts.complete;
|
|
1924
|
+
return createChatClient({
|
|
1925
|
+
transport: "mock",
|
|
1926
|
+
defaultModel,
|
|
1927
|
+
handler: async (req) => {
|
|
1928
|
+
const raw = await complete({
|
|
1929
|
+
model: req.model ?? defaultModel,
|
|
1930
|
+
messages: req.messages,
|
|
1931
|
+
...req.temperature !== void 0 ? { temperature: req.temperature } : {},
|
|
1932
|
+
...req.maxTokens !== void 0 ? { max_tokens: req.maxTokens } : {}
|
|
1933
|
+
});
|
|
1934
|
+
const content = raw.choices?.[0]?.message?.content ?? "";
|
|
1935
|
+
const promptTokens = raw.usage?.prompt_tokens ?? 0;
|
|
1936
|
+
const completionTokens = raw.usage?.completion_tokens ?? 0;
|
|
1937
|
+
return {
|
|
1938
|
+
content,
|
|
1939
|
+
usage: {
|
|
1940
|
+
promptTokens,
|
|
1941
|
+
completionTokens,
|
|
1942
|
+
totalTokens: promptTokens + completionTokens
|
|
1943
|
+
},
|
|
1944
|
+
costUsd: null,
|
|
1945
|
+
model: req.model ?? defaultModel,
|
|
1946
|
+
durationMs: 0,
|
|
1947
|
+
finishReason: raw.choices?.[0]?.finish_reason ?? null,
|
|
1948
|
+
contentEmpty: content.trim().length === 0,
|
|
1949
|
+
raw
|
|
1950
|
+
};
|
|
1951
|
+
}
|
|
1952
|
+
});
|
|
1953
|
+
}
|
|
1841
1954
|
async function consultAnalyst(task, messages, instruction, opts) {
|
|
1842
1955
|
const trajectory = compactTrajectory(messages);
|
|
1843
1956
|
const analystModel = opts.analystModel ?? opts.model;
|
|
1844
|
-
const chat =
|
|
1845
|
-
transport: "router",
|
|
1846
|
-
apiKey: opts.routerKey,
|
|
1847
|
-
baseUrl: opts.routerBaseUrl,
|
|
1848
|
-
defaultModel: analystModel
|
|
1849
|
-
});
|
|
1957
|
+
const chat = analystChat(opts, analystModel);
|
|
1850
1958
|
const res = await chat.chat({
|
|
1851
1959
|
model: analystModel,
|
|
1852
1960
|
temperature: 0.2,
|
|
@@ -1874,12 +1982,7 @@ ${trajectory}`
|
|
|
1874
1982
|
async function analyze(task, messages, opts) {
|
|
1875
1983
|
const trajectory = compactTrajectory(messages);
|
|
1876
1984
|
const analystModel = opts.analystModel ?? opts.model;
|
|
1877
|
-
const inner =
|
|
1878
|
-
transport: "router",
|
|
1879
|
-
apiKey: opts.routerKey,
|
|
1880
|
-
baseUrl: opts.routerBaseUrl,
|
|
1881
|
-
defaultModel: analystModel
|
|
1882
|
-
});
|
|
1985
|
+
const inner = analystChat(opts, analystModel);
|
|
1883
1986
|
const tokens = { input: 0, output: 0 };
|
|
1884
1987
|
const chat = {
|
|
1885
1988
|
...inner,
|
|
@@ -2759,9 +2862,56 @@ function errorMessage(error) {
|
|
|
2759
2862
|
return error instanceof Error ? error.message : String(error);
|
|
2760
2863
|
}
|
|
2761
2864
|
|
|
2865
|
+
// src/runtime/steering-drivers.ts
|
|
2866
|
+
function decideUntilValidOrCapped(history, maxIterations) {
|
|
2867
|
+
if (history.some((it) => it.verdict?.valid)) return "pick-winner";
|
|
2868
|
+
return history.length < maxIterations ? "refine" : "fail";
|
|
2869
|
+
}
|
|
2870
|
+
function naiveDriver(options) {
|
|
2871
|
+
const { continuation, applyContinuation, maxIterations, name = "naive" } = options;
|
|
2872
|
+
return {
|
|
2873
|
+
name,
|
|
2874
|
+
plan(task, history) {
|
|
2875
|
+
if (history.length === 0) return Promise.resolve([task]);
|
|
2876
|
+
const last = history[history.length - 1];
|
|
2877
|
+
if (last?.verdict?.valid) return Promise.resolve([]);
|
|
2878
|
+
if (history.length >= maxIterations) return Promise.resolve([]);
|
|
2879
|
+
return Promise.resolve([applyContinuation(task, continuation)]);
|
|
2880
|
+
},
|
|
2881
|
+
decide(history) {
|
|
2882
|
+
return decideUntilValidOrCapped(history, maxIterations);
|
|
2883
|
+
},
|
|
2884
|
+
// Pure refine topology (one task per round) — render the steer move.
|
|
2885
|
+
describePlan() {
|
|
2886
|
+
return { kind: "refine", rationale: "naive fixed continuation (no grade signal)" };
|
|
2887
|
+
}
|
|
2888
|
+
};
|
|
2889
|
+
}
|
|
2890
|
+
function dumbDriver(options) {
|
|
2891
|
+
const { onPass, onFail, applyContinuation, maxIterations, name = "dumb" } = options;
|
|
2892
|
+
return {
|
|
2893
|
+
name,
|
|
2894
|
+
plan(task, history) {
|
|
2895
|
+
if (history.length === 0) return Promise.resolve([task]);
|
|
2896
|
+
const last = history[history.length - 1];
|
|
2897
|
+
const passed = last?.verdict?.valid === true;
|
|
2898
|
+
if (passed) return Promise.resolve([]);
|
|
2899
|
+
if (history.length >= maxIterations) return Promise.resolve([]);
|
|
2900
|
+
const continuation = passed ? onPass : onFail;
|
|
2901
|
+
return Promise.resolve([applyContinuation(task, continuation)]);
|
|
2902
|
+
},
|
|
2903
|
+
decide(history) {
|
|
2904
|
+
return decideUntilValidOrCapped(history, maxIterations);
|
|
2905
|
+
},
|
|
2906
|
+
describePlan() {
|
|
2907
|
+
return { kind: "refine", rationale: "dumb pass/fail-only continuation (no grader findings)" };
|
|
2908
|
+
}
|
|
2909
|
+
};
|
|
2910
|
+
}
|
|
2911
|
+
|
|
2762
2912
|
// src/runtime/strategy-author.ts
|
|
2763
2913
|
import { mkdirSync, writeFileSync } from "fs";
|
|
2764
|
-
import { join } from "path";
|
|
2914
|
+
import { join as join2 } from "path";
|
|
2765
2915
|
var strategyAuthorContract = `
|
|
2766
2916
|
You author an OPTIMIZATION STRATEGY for an agentic loop system. A strategy decides how to
|
|
2767
2917
|
spend a compute budget to beat a task's deployable check. You compose exactly two steps:
|
|
@@ -2880,7 +3030,7 @@ async function authorStrategy(opts) {
|
|
|
2880
3030
|
}
|
|
2881
3031
|
assertStrategyContract(code);
|
|
2882
3032
|
mkdirSync(opts.outDir, { recursive: true });
|
|
2883
|
-
const file =
|
|
3033
|
+
const file = join2(opts.outDir, `authored-${Date.now()}.mts`);
|
|
2884
3034
|
writeFileSync(file, code);
|
|
2885
3035
|
const mod = await import(`file://${file}`);
|
|
2886
3036
|
if (!mod.default || typeof mod.default.driver !== "function" || !mod.default.name) {
|
|
@@ -3938,10 +4088,10 @@ function jjWorkspace(opts) {
|
|
|
3938
4088
|
};
|
|
3939
4089
|
}
|
|
3940
4090
|
async function runInWorkspace(ws, body, opts = {}) {
|
|
3941
|
-
const { mkdtempSync, rmSync } = await import("fs");
|
|
3942
|
-
const { tmpdir } = await import("os");
|
|
3943
|
-
const { join:
|
|
3944
|
-
const dir =
|
|
4091
|
+
const { mkdtempSync: mkdtempSync2, rmSync: rmSync2 } = await import("fs");
|
|
4092
|
+
const { tmpdir: tmpdir2 } = await import("os");
|
|
4093
|
+
const { join: join3 } = await import("path");
|
|
4094
|
+
const dir = mkdtempSync2(join3(tmpdir2(), opts.tmpPrefix ?? "ws-run-"));
|
|
3945
4095
|
try {
|
|
3946
4096
|
await ws.materialize(dir);
|
|
3947
4097
|
const r = await body(dir);
|
|
@@ -3952,7 +4102,7 @@ async function runInWorkspace(ws, body, opts = {}) {
|
|
|
3952
4102
|
}
|
|
3953
4103
|
return { valid: r.valid, value: r.value };
|
|
3954
4104
|
} finally {
|
|
3955
|
-
|
|
4105
|
+
rmSync2(dir, { recursive: true, force: true });
|
|
3956
4106
|
}
|
|
3957
4107
|
}
|
|
3958
4108
|
function tail(s) {
|
|
@@ -3972,6 +4122,7 @@ export {
|
|
|
3972
4122
|
observe,
|
|
3973
4123
|
renderReport,
|
|
3974
4124
|
harvestCorpus,
|
|
4125
|
+
inProcessSandboxClient,
|
|
3975
4126
|
inlineSandboxClient,
|
|
3976
4127
|
reportLoopUsage,
|
|
3977
4128
|
loopDispatch,
|
|
@@ -4011,6 +4162,8 @@ export {
|
|
|
4011
4162
|
printBenchmarkReport,
|
|
4012
4163
|
SandboxRunAbortError,
|
|
4013
4164
|
openSandboxRun,
|
|
4165
|
+
naiveDriver,
|
|
4166
|
+
dumbDriver,
|
|
4014
4167
|
strategyAuthorContract,
|
|
4015
4168
|
assertStrategyContract,
|
|
4016
4169
|
authorStrategy,
|
|
@@ -4036,4 +4189,4 @@ export {
|
|
|
4036
4189
|
computeFindingId,
|
|
4037
4190
|
makeFinding2 as makeFinding
|
|
4038
4191
|
};
|
|
4039
|
-
//# sourceMappingURL=chunk-
|
|
4192
|
+
//# sourceMappingURL=chunk-CEW5BMGN.js.map
|