agency-lang 0.7.1 → 0.7.2
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/lib/agents/agency-agent/agent.agency +48 -2
- package/dist/lib/agents/agency-agent/agent.js +120 -20
- package/dist/lib/agents/agency-agent/shared.agency +22 -0
- package/dist/lib/agents/agency-agent/shared.js +158 -1
- package/dist/lib/agents/agency-agent/tests/oneShotRounds.agency +20 -0
- package/dist/lib/agents/agency-agent/tests/oneShotRounds.js +555 -0
- package/dist/lib/agents/agency-agent/tests/oneShotRounds.test.json +9 -0
- package/dist/lib/cli/doctor.d.ts +8 -0
- package/dist/lib/cli/doctor.js +21 -13
- package/dist/lib/cli/doctor.test.js +34 -0
- package/dist/lib/cli/help.js +1 -5
- package/dist/lib/cli/runBundledAgent.d.ts +17 -1
- package/dist/lib/cli/runBundledAgent.js +73 -2
- package/dist/lib/cli/runBundledAgent.test.d.ts +1 -0
- package/dist/lib/cli/runBundledAgent.test.js +96 -0
- package/dist/lib/config.d.ts +42 -33
- package/dist/lib/config.js +108 -6
- package/dist/lib/config.test.js +121 -2
- package/dist/lib/parseCache.js +8 -13
- package/dist/lib/parseCache.test.js +5 -8
- package/dist/lib/parser.js +5 -12
- package/dist/lib/preprocessors/typescriptPreprocessor.d.ts +0 -28
- package/dist/lib/preprocessors/typescriptPreprocessor.js +0 -245
- package/dist/lib/runtime/configOverrides.d.ts +17 -16
- package/dist/lib/runtime/configOverrides.js +27 -16
- package/dist/lib/runtime/configOverrides.test.js +116 -2
- package/dist/lib/runtime/prompt.js +7 -3
- package/dist/lib/runtime/state/context.js +9 -2
- package/dist/lib/stdlib/llm.d.ts +1 -0
- package/dist/lib/stdlib/version.d.ts +1 -1
- package/dist/lib/stdlib/version.js +1 -1
- package/dist/scripts/agency.d.ts +2 -0
- package/dist/scripts/agency.js +55 -12
- package/dist/scripts/agency.test.js +73 -1
- package/package.json +1 -1
- package/stdlib/llm.agency +2 -1
- package/stdlib/llm.js +2 -2
- package/dist/lib/preprocessors/typescriptPreprocessor.config.test.js +0 -327
- /package/dist/lib/{preprocessors/typescriptPreprocessor.config.test.d.ts → cli/doctor.test.d.ts} +0 -0
|
@@ -0,0 +1,555 @@
|
|
|
1
|
+
import { print, printJSON, input, sleep, read, write, writeBinary, readBinary, range, callback, map, filter, exclude, find, findIndex, reduce, flatMap, every, some, count, sortBy, unique, groupBy } from "agency-lang/stdlib/index.js";
|
|
2
|
+
import { resolveMaxToolCallRounds } from "../shared.js";
|
|
3
|
+
import { fileURLToPath } from "url";
|
|
4
|
+
import __process from "process";
|
|
5
|
+
import { readFileSync } from "fs";
|
|
6
|
+
import { nanoid } from "agency-lang";
|
|
7
|
+
import path from "path";
|
|
8
|
+
import {
|
|
9
|
+
RuntimeContext,
|
|
10
|
+
Runner,
|
|
11
|
+
setupNode,
|
|
12
|
+
runNode,
|
|
13
|
+
callHook,
|
|
14
|
+
checkpoint as __checkpoint_impl,
|
|
15
|
+
getCheckpoint as __getCheckpoint_impl,
|
|
16
|
+
restore as __restore_impl,
|
|
17
|
+
_run as __runtime_run_impl,
|
|
18
|
+
interrupt,
|
|
19
|
+
isInterrupt,
|
|
20
|
+
hasInterrupts,
|
|
21
|
+
isDebugger,
|
|
22
|
+
respondToInterrupts as _respondToInterrupts,
|
|
23
|
+
rewindFrom as _rewindFrom,
|
|
24
|
+
runExportedFunction as _runExportedFunction,
|
|
25
|
+
RestoreSignal,
|
|
26
|
+
AgencyAbort,
|
|
27
|
+
__registerGlobalsInit,
|
|
28
|
+
failure,
|
|
29
|
+
__eq,
|
|
30
|
+
AgencyFunction as __AgencyFunction,
|
|
31
|
+
__call,
|
|
32
|
+
__threads,
|
|
33
|
+
getRuntimeContext,
|
|
34
|
+
agencyStore,
|
|
35
|
+
functionRefReviver as __functionRefReviver,
|
|
36
|
+
DeterministicClient as __DeterministicClient,
|
|
37
|
+
installFetchMock as __installFetchMock,
|
|
38
|
+
createLogger as __createLogger
|
|
39
|
+
} from "agency-lang/runtime";
|
|
40
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
41
|
+
const __dirname = path.dirname(__filename);
|
|
42
|
+
const __cwd = __process.cwd();
|
|
43
|
+
const getDirname = () => __dirname;
|
|
44
|
+
const __globalCtx = new RuntimeContext({
|
|
45
|
+
statelogConfig: {
|
|
46
|
+
host: "https://statelog.adit.io",
|
|
47
|
+
apiKey: __process.env["STATELOG_API_KEY"] || "",
|
|
48
|
+
projectId: "agency-lang",
|
|
49
|
+
debugMode: false,
|
|
50
|
+
observability: true,
|
|
51
|
+
logFile: "log.jsonl"
|
|
52
|
+
},
|
|
53
|
+
smoltalkDefaults: {
|
|
54
|
+
apiKey: {
|
|
55
|
+
openAi: __process.env["OPENAI_API_KEY"] || "",
|
|
56
|
+
google: __process.env["GEMINI_API_KEY"] || "",
|
|
57
|
+
anthropic: __process.env["ANTHROPIC_API_KEY"] || "",
|
|
58
|
+
openRouter: __process.env["OPENROUTER_API_KEY"] || "",
|
|
59
|
+
deepInfra: __process.env["DEEPINFRA_API_KEY"] || "",
|
|
60
|
+
liteLlm: __process.env["LITELLM_API_KEY"] || "",
|
|
61
|
+
openAiCompat: __process.env["OPENAI_COMPAT_API_KEY"] || ""
|
|
62
|
+
},
|
|
63
|
+
baseUrl: {
|
|
64
|
+
liteLlm: __process.env["LITELLM_BASE_URL"] || "",
|
|
65
|
+
openAiCompat: __process.env["OPENAI_COMPAT_BASE_URL"] || ""
|
|
66
|
+
},
|
|
67
|
+
model: "gpt-4o-mini",
|
|
68
|
+
logLevel: "warn",
|
|
69
|
+
statelog: {
|
|
70
|
+
host: "https://statelog.adit.io",
|
|
71
|
+
projectId: "smoltalk",
|
|
72
|
+
apiKey: __process.env["STATELOG_SMOLTALK_API_KEY"] || "",
|
|
73
|
+
traceId: nanoid()
|
|
74
|
+
}
|
|
75
|
+
},
|
|
76
|
+
dirname: __dirname,
|
|
77
|
+
logLevel: "info",
|
|
78
|
+
traceConfig: {
|
|
79
|
+
program: "dist/lib/agents/agency-agent/tests/oneShotRounds.agency"
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
const graph = __globalCtx.graph;
|
|
83
|
+
function approve(value) {
|
|
84
|
+
return { type: "approve", value };
|
|
85
|
+
}
|
|
86
|
+
function reject(value) {
|
|
87
|
+
return { type: "reject", value };
|
|
88
|
+
}
|
|
89
|
+
function propagate() {
|
|
90
|
+
return { type: "propagate" };
|
|
91
|
+
}
|
|
92
|
+
const respondToInterrupts = (interrupts, responses, opts) => _respondToInterrupts({ ctx: __globalCtx, interrupts, responses, overrides: opts?.overrides, metadata: opts?.metadata, registerTopLevelCallbacks: __registerTopLevelCallbacks, moduleDir: __dirname });
|
|
93
|
+
const rewindFrom = (checkpoint2, overrides, opts) => _rewindFrom({ ctx: __globalCtx, checkpoint: checkpoint2, overrides, metadata: opts?.metadata, registerTopLevelCallbacks: __registerTopLevelCallbacks, moduleDir: __dirname });
|
|
94
|
+
const __invokeFunction = (fn, namedArgs) => _runExportedFunction({ ctx: __globalCtx, fn, namedArgs, initializeGlobals: __initializeGlobals, registerTopLevelCallbacks: __registerTopLevelCallbacks, moduleDir: __dirname });
|
|
95
|
+
const __setDebugger = (dbg) => {
|
|
96
|
+
__globalCtx.debuggerState = dbg;
|
|
97
|
+
};
|
|
98
|
+
const __setTraceFile = (filePath) => {
|
|
99
|
+
__globalCtx.traceConfig.traceFile = filePath;
|
|
100
|
+
};
|
|
101
|
+
const __setLLMClient = (client) => {
|
|
102
|
+
__globalCtx.setLLMClient(client);
|
|
103
|
+
};
|
|
104
|
+
const __getCheckpoints = () => __globalCtx.checkpoints;
|
|
105
|
+
if (__process.env.AGENCY_LLM_MOCKS) {
|
|
106
|
+
__globalCtx.setLLMClient(
|
|
107
|
+
new __DeterministicClient(JSON.parse(__process.env.AGENCY_LLM_MOCKS))
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
if (__process.env.AGENCY_FETCH_MOCKS_FILE) {
|
|
111
|
+
__installFetchMock(JSON.parse(readFileSync(__process.env.AGENCY_FETCH_MOCKS_FILE, "utf-8")));
|
|
112
|
+
}
|
|
113
|
+
const __toolRegistry = __functionRefReviver.registry ??= {};
|
|
114
|
+
function __registerTool(value, _aliasName) {
|
|
115
|
+
if (__AgencyFunction.isAgencyFunction(value)) {
|
|
116
|
+
__toolRegistry[`${value.module}:${value.name}`] = value;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const checkpoint = __AgencyFunction.create({ name: "checkpoint", module: "__runtime", fn: __checkpoint_impl, params: [], toolDefinition: null }, __toolRegistry);
|
|
120
|
+
const getCheckpoint = __AgencyFunction.create({ name: "getCheckpoint", module: "__runtime", fn: __getCheckpoint_impl, params: [{ name: "checkpointId", hasDefault: false, defaultValue: void 0, variadic: false }], toolDefinition: null }, __toolRegistry);
|
|
121
|
+
const restore = __AgencyFunction.create({ name: "restore", module: "__runtime", fn: __restore_impl, params: [{ name: "checkpointIdOrCheckpoint", hasDefault: false, defaultValue: void 0, variadic: false }, { name: "options", hasDefault: false, defaultValue: void 0, variadic: false }], toolDefinition: null }, __toolRegistry);
|
|
122
|
+
const _run = __AgencyFunction.create({ name: "_run", module: "__runtime", fn: __runtime_run_impl, params: [{ name: "compiled", hasDefault: false, defaultValue: void 0, variadic: false }, { name: "node", hasDefault: false, defaultValue: void 0, variadic: false }, { name: "args", hasDefault: false, defaultValue: void 0, variadic: false }, { name: "wallClock", hasDefault: false, defaultValue: void 0, variadic: false }, { name: "memory", hasDefault: false, defaultValue: void 0, variadic: false }, { name: "ipcPayload", hasDefault: false, defaultValue: void 0, variadic: false }, { name: "stdout", hasDefault: false, defaultValue: void 0, variadic: false }, { name: "configOverrides", hasDefault: false, defaultValue: void 0, variadic: false }, { name: "cwd", hasDefault: false, defaultValue: void 0, variadic: false }, { name: "maxDepth", hasDefault: false, defaultValue: void 0, variadic: false }], toolDefinition: null }, __toolRegistry);
|
|
123
|
+
function setLLMClient(client) {
|
|
124
|
+
__globalCtx.setLLMClient(client);
|
|
125
|
+
}
|
|
126
|
+
function registerTools(tools) {
|
|
127
|
+
for (const tool of tools) {
|
|
128
|
+
if (__AgencyFunction.isAgencyFunction(tool)) {
|
|
129
|
+
__toolRegistry[`${tool.module}:${tool.name}`] = tool;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
__registerTool(print);
|
|
134
|
+
__registerTool(printJSON);
|
|
135
|
+
__registerTool(input);
|
|
136
|
+
__registerTool(sleep);
|
|
137
|
+
__registerTool(read);
|
|
138
|
+
__registerTool(write);
|
|
139
|
+
__registerTool(writeBinary);
|
|
140
|
+
__registerTool(readBinary);
|
|
141
|
+
__registerTool(range);
|
|
142
|
+
__registerTool(callback);
|
|
143
|
+
__registerTool(map);
|
|
144
|
+
__registerTool(filter);
|
|
145
|
+
__registerTool(exclude);
|
|
146
|
+
__registerTool(find);
|
|
147
|
+
__registerTool(findIndex);
|
|
148
|
+
__registerTool(reduce);
|
|
149
|
+
__registerTool(flatMap);
|
|
150
|
+
__registerTool(every);
|
|
151
|
+
__registerTool(some);
|
|
152
|
+
__registerTool(count);
|
|
153
|
+
__registerTool(sortBy);
|
|
154
|
+
__registerTool(unique);
|
|
155
|
+
__registerTool(groupBy);
|
|
156
|
+
__registerTool(resolveMaxToolCallRounds);
|
|
157
|
+
async function __initializeGlobals(__ctx) {
|
|
158
|
+
if (__ctx.globals.isInitialized("dist/lib/agents/agency-agent/tests/oneShotRounds.agency")) {
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
__ctx.globals.markInitialized("dist/lib/agents/agency-agent/tests/oneShotRounds.agency");
|
|
162
|
+
}
|
|
163
|
+
__registerGlobalsInit("dist/lib/agents/agency-agent/tests/oneShotRounds.agency", __initializeGlobals);
|
|
164
|
+
async function __registerTopLevelCallbacks(__ctx) {
|
|
165
|
+
__ctx.topLevelCallbacks = [];
|
|
166
|
+
}
|
|
167
|
+
__functionRefReviver.registry = __toolRegistry;
|
|
168
|
+
graph.node("explicitWinsOverOneShot", async (__state) => {
|
|
169
|
+
const __setupData = setupNode({
|
|
170
|
+
state: __state
|
|
171
|
+
});
|
|
172
|
+
const __stack = __setupData.stack;
|
|
173
|
+
const __step = __setupData.step;
|
|
174
|
+
const __self = __setupData.self;
|
|
175
|
+
const __ctx = getRuntimeContext().ctx;
|
|
176
|
+
let __forked;
|
|
177
|
+
let __functionCompleted = false;
|
|
178
|
+
const runner = new Runner(__ctx, __stack, { nodeContext: true, state: __stack, moduleId: "dist/lib/agents/agency-agent/tests/oneShotRounds.agency", scopeName: "explicitWinsOverOneShot", threads: __setupData.threads });
|
|
179
|
+
try {
|
|
180
|
+
await agencyStore.run({
|
|
181
|
+
...getRuntimeContext(),
|
|
182
|
+
ctx: __ctx,
|
|
183
|
+
stack: __ctx.stateStack,
|
|
184
|
+
threads: __setupData.threads
|
|
185
|
+
}, async () => {
|
|
186
|
+
await runner.hook(0, async () => {
|
|
187
|
+
await callHook({
|
|
188
|
+
name: "onNodeStart",
|
|
189
|
+
data: {
|
|
190
|
+
nodeName: "explicitWinsOverOneShot"
|
|
191
|
+
}
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
await runner.step(1, async (runner2) => {
|
|
195
|
+
__self.__retryable = false;
|
|
196
|
+
runner2.halt({
|
|
197
|
+
messages: __threads(),
|
|
198
|
+
data: __eq(await __call(resolveMaxToolCallRounds, {
|
|
199
|
+
type: "positional",
|
|
200
|
+
args: [7, true]
|
|
201
|
+
}), 7)
|
|
202
|
+
});
|
|
203
|
+
return;
|
|
204
|
+
});
|
|
205
|
+
});
|
|
206
|
+
if (runner.halted) return runner.haltResult;
|
|
207
|
+
await runner.hook(2, async () => {
|
|
208
|
+
await callHook({
|
|
209
|
+
name: "onNodeEnd",
|
|
210
|
+
data: {
|
|
211
|
+
nodeName: "explicitWinsOverOneShot",
|
|
212
|
+
data: void 0
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
});
|
|
216
|
+
return {
|
|
217
|
+
messages: __threads(),
|
|
218
|
+
data: void 0
|
|
219
|
+
};
|
|
220
|
+
} catch (__error) {
|
|
221
|
+
if (__error instanceof RestoreSignal) {
|
|
222
|
+
throw __error;
|
|
223
|
+
}
|
|
224
|
+
if (__error instanceof AgencyAbort) {
|
|
225
|
+
throw __error;
|
|
226
|
+
}
|
|
227
|
+
{
|
|
228
|
+
const __errMsg = __error instanceof Error ? __error.message : String(__error);
|
|
229
|
+
const __errStack = __error instanceof Error && __error.stack ? __error.stack : "";
|
|
230
|
+
const __log = __createLogger(__ctx.logLevel);
|
|
231
|
+
__log.error(`Node explicitWinsOverOneShot crashed: ${__errMsg}`);
|
|
232
|
+
if (__errStack) __log.error(__errStack);
|
|
233
|
+
__ctx.statelogClient?.error?.({
|
|
234
|
+
errorType: "runtimeError",
|
|
235
|
+
message: __errMsg,
|
|
236
|
+
functionName: "explicitWinsOverOneShot"
|
|
237
|
+
});
|
|
238
|
+
}
|
|
239
|
+
return {
|
|
240
|
+
messages: __threads(),
|
|
241
|
+
data: failure(__error instanceof Error ? __error.message : String(__error), { functionName: "explicitWinsOverOneShot" })
|
|
242
|
+
};
|
|
243
|
+
}
|
|
244
|
+
});
|
|
245
|
+
graph.node("oneShotDefaults50", async (__state) => {
|
|
246
|
+
const __setupData = setupNode({
|
|
247
|
+
state: __state
|
|
248
|
+
});
|
|
249
|
+
const __stack = __setupData.stack;
|
|
250
|
+
const __step = __setupData.step;
|
|
251
|
+
const __self = __setupData.self;
|
|
252
|
+
const __ctx = getRuntimeContext().ctx;
|
|
253
|
+
let __forked;
|
|
254
|
+
let __functionCompleted = false;
|
|
255
|
+
const runner = new Runner(__ctx, __stack, { nodeContext: true, state: __stack, moduleId: "dist/lib/agents/agency-agent/tests/oneShotRounds.agency", scopeName: "oneShotDefaults50", threads: __setupData.threads });
|
|
256
|
+
try {
|
|
257
|
+
await agencyStore.run({
|
|
258
|
+
...getRuntimeContext(),
|
|
259
|
+
ctx: __ctx,
|
|
260
|
+
stack: __ctx.stateStack,
|
|
261
|
+
threads: __setupData.threads
|
|
262
|
+
}, async () => {
|
|
263
|
+
await runner.hook(0, async () => {
|
|
264
|
+
await callHook({
|
|
265
|
+
name: "onNodeStart",
|
|
266
|
+
data: {
|
|
267
|
+
nodeName: "oneShotDefaults50"
|
|
268
|
+
}
|
|
269
|
+
});
|
|
270
|
+
});
|
|
271
|
+
await runner.step(1, async (runner2) => {
|
|
272
|
+
__self.__retryable = false;
|
|
273
|
+
runner2.halt({
|
|
274
|
+
messages: __threads(),
|
|
275
|
+
data: __eq(await __call(resolveMaxToolCallRounds, {
|
|
276
|
+
type: "positional",
|
|
277
|
+
args: [null, true]
|
|
278
|
+
}), 50)
|
|
279
|
+
});
|
|
280
|
+
return;
|
|
281
|
+
});
|
|
282
|
+
});
|
|
283
|
+
if (runner.halted) return runner.haltResult;
|
|
284
|
+
await runner.hook(2, async () => {
|
|
285
|
+
await callHook({
|
|
286
|
+
name: "onNodeEnd",
|
|
287
|
+
data: {
|
|
288
|
+
nodeName: "oneShotDefaults50",
|
|
289
|
+
data: void 0
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
return {
|
|
294
|
+
messages: __threads(),
|
|
295
|
+
data: void 0
|
|
296
|
+
};
|
|
297
|
+
} catch (__error) {
|
|
298
|
+
if (__error instanceof RestoreSignal) {
|
|
299
|
+
throw __error;
|
|
300
|
+
}
|
|
301
|
+
if (__error instanceof AgencyAbort) {
|
|
302
|
+
throw __error;
|
|
303
|
+
}
|
|
304
|
+
{
|
|
305
|
+
const __errMsg = __error instanceof Error ? __error.message : String(__error);
|
|
306
|
+
const __errStack = __error instanceof Error && __error.stack ? __error.stack : "";
|
|
307
|
+
const __log = __createLogger(__ctx.logLevel);
|
|
308
|
+
__log.error(`Node oneShotDefaults50 crashed: ${__errMsg}`);
|
|
309
|
+
if (__errStack) __log.error(__errStack);
|
|
310
|
+
__ctx.statelogClient?.error?.({
|
|
311
|
+
errorType: "runtimeError",
|
|
312
|
+
message: __errMsg,
|
|
313
|
+
functionName: "oneShotDefaults50"
|
|
314
|
+
});
|
|
315
|
+
}
|
|
316
|
+
return {
|
|
317
|
+
messages: __threads(),
|
|
318
|
+
data: failure(__error instanceof Error ? __error.message : String(__error), { functionName: "oneShotDefaults50" })
|
|
319
|
+
};
|
|
320
|
+
}
|
|
321
|
+
});
|
|
322
|
+
graph.node("explicitWinsOverInteractive", async (__state) => {
|
|
323
|
+
const __setupData = setupNode({
|
|
324
|
+
state: __state
|
|
325
|
+
});
|
|
326
|
+
const __stack = __setupData.stack;
|
|
327
|
+
const __step = __setupData.step;
|
|
328
|
+
const __self = __setupData.self;
|
|
329
|
+
const __ctx = getRuntimeContext().ctx;
|
|
330
|
+
let __forked;
|
|
331
|
+
let __functionCompleted = false;
|
|
332
|
+
const runner = new Runner(__ctx, __stack, { nodeContext: true, state: __stack, moduleId: "dist/lib/agents/agency-agent/tests/oneShotRounds.agency", scopeName: "explicitWinsOverInteractive", threads: __setupData.threads });
|
|
333
|
+
try {
|
|
334
|
+
await agencyStore.run({
|
|
335
|
+
...getRuntimeContext(),
|
|
336
|
+
ctx: __ctx,
|
|
337
|
+
stack: __ctx.stateStack,
|
|
338
|
+
threads: __setupData.threads
|
|
339
|
+
}, async () => {
|
|
340
|
+
await runner.hook(0, async () => {
|
|
341
|
+
await callHook({
|
|
342
|
+
name: "onNodeStart",
|
|
343
|
+
data: {
|
|
344
|
+
nodeName: "explicitWinsOverInteractive"
|
|
345
|
+
}
|
|
346
|
+
});
|
|
347
|
+
});
|
|
348
|
+
await runner.step(1, async (runner2) => {
|
|
349
|
+
__self.__retryable = false;
|
|
350
|
+
runner2.halt({
|
|
351
|
+
messages: __threads(),
|
|
352
|
+
data: __eq(await __call(resolveMaxToolCallRounds, {
|
|
353
|
+
type: "positional",
|
|
354
|
+
args: [3, false]
|
|
355
|
+
}), 3)
|
|
356
|
+
});
|
|
357
|
+
return;
|
|
358
|
+
});
|
|
359
|
+
});
|
|
360
|
+
if (runner.halted) return runner.haltResult;
|
|
361
|
+
await runner.hook(2, async () => {
|
|
362
|
+
await callHook({
|
|
363
|
+
name: "onNodeEnd",
|
|
364
|
+
data: {
|
|
365
|
+
nodeName: "explicitWinsOverInteractive",
|
|
366
|
+
data: void 0
|
|
367
|
+
}
|
|
368
|
+
});
|
|
369
|
+
});
|
|
370
|
+
return {
|
|
371
|
+
messages: __threads(),
|
|
372
|
+
data: void 0
|
|
373
|
+
};
|
|
374
|
+
} catch (__error) {
|
|
375
|
+
if (__error instanceof RestoreSignal) {
|
|
376
|
+
throw __error;
|
|
377
|
+
}
|
|
378
|
+
if (__error instanceof AgencyAbort) {
|
|
379
|
+
throw __error;
|
|
380
|
+
}
|
|
381
|
+
{
|
|
382
|
+
const __errMsg = __error instanceof Error ? __error.message : String(__error);
|
|
383
|
+
const __errStack = __error instanceof Error && __error.stack ? __error.stack : "";
|
|
384
|
+
const __log = __createLogger(__ctx.logLevel);
|
|
385
|
+
__log.error(`Node explicitWinsOverInteractive crashed: ${__errMsg}`);
|
|
386
|
+
if (__errStack) __log.error(__errStack);
|
|
387
|
+
__ctx.statelogClient?.error?.({
|
|
388
|
+
errorType: "runtimeError",
|
|
389
|
+
message: __errMsg,
|
|
390
|
+
functionName: "explicitWinsOverInteractive"
|
|
391
|
+
});
|
|
392
|
+
}
|
|
393
|
+
return {
|
|
394
|
+
messages: __threads(),
|
|
395
|
+
data: failure(__error instanceof Error ? __error.message : String(__error), { functionName: "explicitWinsOverInteractive" })
|
|
396
|
+
};
|
|
397
|
+
}
|
|
398
|
+
});
|
|
399
|
+
graph.node("interactiveKeepsBaked", async (__state) => {
|
|
400
|
+
const __setupData = setupNode({
|
|
401
|
+
state: __state
|
|
402
|
+
});
|
|
403
|
+
const __stack = __setupData.stack;
|
|
404
|
+
const __step = __setupData.step;
|
|
405
|
+
const __self = __setupData.self;
|
|
406
|
+
const __ctx = getRuntimeContext().ctx;
|
|
407
|
+
let __forked;
|
|
408
|
+
let __functionCompleted = false;
|
|
409
|
+
const runner = new Runner(__ctx, __stack, { nodeContext: true, state: __stack, moduleId: "dist/lib/agents/agency-agent/tests/oneShotRounds.agency", scopeName: "interactiveKeepsBaked", threads: __setupData.threads });
|
|
410
|
+
try {
|
|
411
|
+
await agencyStore.run({
|
|
412
|
+
...getRuntimeContext(),
|
|
413
|
+
ctx: __ctx,
|
|
414
|
+
stack: __ctx.stateStack,
|
|
415
|
+
threads: __setupData.threads
|
|
416
|
+
}, async () => {
|
|
417
|
+
await runner.hook(0, async () => {
|
|
418
|
+
await callHook({
|
|
419
|
+
name: "onNodeStart",
|
|
420
|
+
data: {
|
|
421
|
+
nodeName: "interactiveKeepsBaked"
|
|
422
|
+
}
|
|
423
|
+
});
|
|
424
|
+
});
|
|
425
|
+
await runner.step(1, async (runner2) => {
|
|
426
|
+
__self.__retryable = false;
|
|
427
|
+
runner2.halt({
|
|
428
|
+
messages: __threads(),
|
|
429
|
+
data: __eq(await __call(resolveMaxToolCallRounds, {
|
|
430
|
+
type: "positional",
|
|
431
|
+
args: [null, false]
|
|
432
|
+
}), null)
|
|
433
|
+
});
|
|
434
|
+
return;
|
|
435
|
+
});
|
|
436
|
+
});
|
|
437
|
+
if (runner.halted) return runner.haltResult;
|
|
438
|
+
await runner.hook(2, async () => {
|
|
439
|
+
await callHook({
|
|
440
|
+
name: "onNodeEnd",
|
|
441
|
+
data: {
|
|
442
|
+
nodeName: "interactiveKeepsBaked",
|
|
443
|
+
data: void 0
|
|
444
|
+
}
|
|
445
|
+
});
|
|
446
|
+
});
|
|
447
|
+
return {
|
|
448
|
+
messages: __threads(),
|
|
449
|
+
data: void 0
|
|
450
|
+
};
|
|
451
|
+
} catch (__error) {
|
|
452
|
+
if (__error instanceof RestoreSignal) {
|
|
453
|
+
throw __error;
|
|
454
|
+
}
|
|
455
|
+
if (__error instanceof AgencyAbort) {
|
|
456
|
+
throw __error;
|
|
457
|
+
}
|
|
458
|
+
{
|
|
459
|
+
const __errMsg = __error instanceof Error ? __error.message : String(__error);
|
|
460
|
+
const __errStack = __error instanceof Error && __error.stack ? __error.stack : "";
|
|
461
|
+
const __log = __createLogger(__ctx.logLevel);
|
|
462
|
+
__log.error(`Node interactiveKeepsBaked crashed: ${__errMsg}`);
|
|
463
|
+
if (__errStack) __log.error(__errStack);
|
|
464
|
+
__ctx.statelogClient?.error?.({
|
|
465
|
+
errorType: "runtimeError",
|
|
466
|
+
message: __errMsg,
|
|
467
|
+
functionName: "interactiveKeepsBaked"
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
return {
|
|
471
|
+
messages: __threads(),
|
|
472
|
+
data: failure(__error instanceof Error ? __error.message : String(__error), { functionName: "interactiveKeepsBaked" })
|
|
473
|
+
};
|
|
474
|
+
}
|
|
475
|
+
});
|
|
476
|
+
async function explicitWinsOverOneShot({ messages, callbacks } = {}) {
|
|
477
|
+
return runNode({
|
|
478
|
+
ctx: __globalCtx,
|
|
479
|
+
nodeName: "explicitWinsOverOneShot",
|
|
480
|
+
data: {},
|
|
481
|
+
messages,
|
|
482
|
+
callbacks,
|
|
483
|
+
initializeGlobals: __initializeGlobals,
|
|
484
|
+
registerTopLevelCallbacks: __registerTopLevelCallbacks,
|
|
485
|
+
moduleDir: __dirname
|
|
486
|
+
});
|
|
487
|
+
}
|
|
488
|
+
const __explicitWinsOverOneShotNodeParams = [];
|
|
489
|
+
async function oneShotDefaults50({ messages, callbacks } = {}) {
|
|
490
|
+
return runNode({
|
|
491
|
+
ctx: __globalCtx,
|
|
492
|
+
nodeName: "oneShotDefaults50",
|
|
493
|
+
data: {},
|
|
494
|
+
messages,
|
|
495
|
+
callbacks,
|
|
496
|
+
initializeGlobals: __initializeGlobals,
|
|
497
|
+
registerTopLevelCallbacks: __registerTopLevelCallbacks,
|
|
498
|
+
moduleDir: __dirname
|
|
499
|
+
});
|
|
500
|
+
}
|
|
501
|
+
const __oneShotDefaults50NodeParams = [];
|
|
502
|
+
async function explicitWinsOverInteractive({ messages, callbacks } = {}) {
|
|
503
|
+
return runNode({
|
|
504
|
+
ctx: __globalCtx,
|
|
505
|
+
nodeName: "explicitWinsOverInteractive",
|
|
506
|
+
data: {},
|
|
507
|
+
messages,
|
|
508
|
+
callbacks,
|
|
509
|
+
initializeGlobals: __initializeGlobals,
|
|
510
|
+
registerTopLevelCallbacks: __registerTopLevelCallbacks,
|
|
511
|
+
moduleDir: __dirname
|
|
512
|
+
});
|
|
513
|
+
}
|
|
514
|
+
const __explicitWinsOverInteractiveNodeParams = [];
|
|
515
|
+
async function interactiveKeepsBaked({ messages, callbacks } = {}) {
|
|
516
|
+
return runNode({
|
|
517
|
+
ctx: __globalCtx,
|
|
518
|
+
nodeName: "interactiveKeepsBaked",
|
|
519
|
+
data: {},
|
|
520
|
+
messages,
|
|
521
|
+
callbacks,
|
|
522
|
+
initializeGlobals: __initializeGlobals,
|
|
523
|
+
registerTopLevelCallbacks: __registerTopLevelCallbacks,
|
|
524
|
+
moduleDir: __dirname
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
const __interactiveKeepsBakedNodeParams = [];
|
|
528
|
+
var stdin_default = graph;
|
|
529
|
+
const __sourceMap = { "dist/lib/agents/agency-agent/tests/oneShotRounds.agency:explicitWinsOverOneShot": { "1": { "line": 6, "col": 2 } }, "dist/lib/agents/agency-agent/tests/oneShotRounds.agency:oneShotDefaults50": { "1": { "line": 10, "col": 2 } }, "dist/lib/agents/agency-agent/tests/oneShotRounds.agency:explicitWinsOverInteractive": { "1": { "line": 14, "col": 2 } }, "dist/lib/agents/agency-agent/tests/oneShotRounds.agency:interactiveKeepsBaked": { "1": { "line": 18, "col": 2 } } };
|
|
530
|
+
export {
|
|
531
|
+
__explicitWinsOverInteractiveNodeParams,
|
|
532
|
+
__explicitWinsOverOneShotNodeParams,
|
|
533
|
+
__getCheckpoints,
|
|
534
|
+
__interactiveKeepsBakedNodeParams,
|
|
535
|
+
__invokeFunction,
|
|
536
|
+
__oneShotDefaults50NodeParams,
|
|
537
|
+
__setDebugger,
|
|
538
|
+
__setLLMClient,
|
|
539
|
+
__setTraceFile,
|
|
540
|
+
__sourceMap,
|
|
541
|
+
__toolRegistry,
|
|
542
|
+
approve,
|
|
543
|
+
stdin_default as default,
|
|
544
|
+
explicitWinsOverInteractive,
|
|
545
|
+
explicitWinsOverOneShot,
|
|
546
|
+
hasInterrupts,
|
|
547
|
+
interactiveKeepsBaked,
|
|
548
|
+
interrupt,
|
|
549
|
+
isDebugger,
|
|
550
|
+
isInterrupt,
|
|
551
|
+
oneShotDefaults50,
|
|
552
|
+
reject,
|
|
553
|
+
respondToInterrupts,
|
|
554
|
+
rewindFrom
|
|
555
|
+
};
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
{
|
|
2
|
+
"sourceFile": "oneShotRounds.agency",
|
|
3
|
+
"tests": [
|
|
4
|
+
{ "nodeName": "explicitWinsOverOneShot", "input": "", "expectedOutput": "true", "evaluationCriteria": [{ "type": "exact" }] },
|
|
5
|
+
{ "nodeName": "oneShotDefaults50", "input": "", "expectedOutput": "true", "evaluationCriteria": [{ "type": "exact" }] },
|
|
6
|
+
{ "nodeName": "explicitWinsOverInteractive", "input": "", "expectedOutput": "true", "evaluationCriteria": [{ "type": "exact" }] },
|
|
7
|
+
{ "nodeName": "interactiveKeepsBaked", "input": "", "expectedOutput": "true", "evaluationCriteria": [{ "type": "exact" }] }
|
|
8
|
+
]
|
|
9
|
+
}
|
package/dist/lib/cli/doctor.d.ts
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import { AgencyConfig } from "../config.js";
|
|
2
2
|
export declare function buildDoctorPrompt(file: string, symptom?: string): string;
|
|
3
|
+
export declare function buildDoctorArgs(opts: {
|
|
4
|
+
file: string;
|
|
5
|
+
symptom?: string;
|
|
6
|
+
trace?: string | true;
|
|
7
|
+
logFile?: string;
|
|
8
|
+
}): string[];
|
|
3
9
|
export declare function doctor(config: AgencyConfig, file: string, opts?: {
|
|
4
10
|
symptom?: string;
|
|
11
|
+
trace?: string | true;
|
|
12
|
+
logFile?: string;
|
|
5
13
|
}): void;
|
package/dist/lib/cli/doctor.js
CHANGED
|
@@ -26,18 +26,26 @@ export function buildDoctorPrompt(file, symptom) {
|
|
|
26
26
|
"re-run `typecheck` to confirm the file is clean.",
|
|
27
27
|
].join("\n");
|
|
28
28
|
}
|
|
29
|
-
//
|
|
30
|
-
//
|
|
31
|
-
//
|
|
29
|
+
// Build the argv forwarded to the bundled agent. Kept pure and exported so
|
|
30
|
+
// the flag assembly can be unit-tested without launching the agent. Debug
|
|
31
|
+
// flags go BEFORE the `--` terminator (tokens after `--` are positionals to
|
|
32
|
+
// the agent's std::args parser); the prompt is the sole positional after it.
|
|
33
|
+
export function buildDoctorArgs(opts) {
|
|
34
|
+
const prompt = buildDoctorPrompt(opts.file, opts.symptom);
|
|
35
|
+
const debug = [];
|
|
36
|
+
if (opts.trace !== undefined) {
|
|
37
|
+
debug.push("--trace");
|
|
38
|
+
if (typeof opts.trace === "string")
|
|
39
|
+
debug.push(opts.trace);
|
|
40
|
+
}
|
|
41
|
+
if (opts.logFile)
|
|
42
|
+
debug.push("--log-file", opts.logFile);
|
|
43
|
+
return ["--interactive", "--agent", "code", ...debug, "--", prompt];
|
|
44
|
+
}
|
|
45
|
+
// `agency doctor <file> [--symptom <text>] [--trace [file]] [--log-file <path>]`
|
|
46
|
+
// — launch the agency agent in interactive mode, seeded with a diagnosis prompt
|
|
47
|
+
// routed to the code subagent. A thin wrapper over the generic
|
|
48
|
+
// --interactive/--agent flags.
|
|
32
49
|
export function doctor(config, file, opts = {}) {
|
|
33
|
-
|
|
34
|
-
// `--` ends flag parsing so the prompt (which may start with `-`) is
|
|
35
|
-
// treated as a positional by the agent's std::args parser.
|
|
36
|
-
runBundledAgent(config, "agency-agent", [
|
|
37
|
-
"--interactive",
|
|
38
|
-
"--agent",
|
|
39
|
-
"code",
|
|
40
|
-
"--",
|
|
41
|
-
prompt,
|
|
42
|
-
]);
|
|
50
|
+
runBundledAgent(config, "agency-agent", buildDoctorArgs({ file, ...opts }));
|
|
43
51
|
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { buildDoctorArgs } from "./doctor.js";
|
|
3
|
+
describe("buildDoctorArgs", () => {
|
|
4
|
+
it("appends --trace / --log-file before the -- terminator", () => {
|
|
5
|
+
const args = buildDoctorArgs({
|
|
6
|
+
file: "x.agency",
|
|
7
|
+
symptom: "boom",
|
|
8
|
+
trace: "t.trace",
|
|
9
|
+
logFile: "l.jsonl",
|
|
10
|
+
});
|
|
11
|
+
const dashDash = args.indexOf("--");
|
|
12
|
+
expect(dashDash).toBeGreaterThan(-1);
|
|
13
|
+
expect(args.indexOf("--trace")).toBeGreaterThan(-1);
|
|
14
|
+
expect(args.indexOf("--trace")).toBeLessThan(dashDash);
|
|
15
|
+
expect(args.indexOf("--log-file")).toBeLessThan(dashDash);
|
|
16
|
+
expect(args.slice(args.indexOf("--trace"), args.indexOf("--trace") + 2)).toEqual([
|
|
17
|
+
"--trace",
|
|
18
|
+
"t.trace",
|
|
19
|
+
]);
|
|
20
|
+
});
|
|
21
|
+
it("bare --trace appends just the flag before --", () => {
|
|
22
|
+
const args = buildDoctorArgs({ file: "x.agency", trace: true });
|
|
23
|
+
expect(args.filter((a) => a === "--trace")).toHaveLength(1);
|
|
24
|
+
expect(args.indexOf("--trace")).toBeLessThan(args.indexOf("--"));
|
|
25
|
+
// No stray value token after a bare --trace.
|
|
26
|
+
expect(args[args.indexOf("--trace") + 1]).toBe("--");
|
|
27
|
+
});
|
|
28
|
+
it("omits the debug flags entirely when not requested", () => {
|
|
29
|
+
const args = buildDoctorArgs({ file: "x.agency", symptom: "boom" });
|
|
30
|
+
expect(args).not.toContain("--trace");
|
|
31
|
+
expect(args).not.toContain("--log-file");
|
|
32
|
+
expect(args[args.length - 2]).toBe("--");
|
|
33
|
+
});
|
|
34
|
+
});
|
package/dist/lib/cli/help.js
CHANGED
|
@@ -27,11 +27,7 @@ Flags:
|
|
|
27
27
|
Config File (agency.json):
|
|
28
28
|
{
|
|
29
29
|
"verbose": false, Enable verbose logging by default
|
|
30
|
-
"outDir": "./dist"
|
|
31
|
-
"excludeNodeTypes": ["comment"], Node types to exclude from code generation
|
|
32
|
-
"excludeBuiltinFunctions": ["write"], Builtin functions to exclude
|
|
33
|
-
"allowedFetchDomains": ["api.example.com"], Whitelist for fetch domains
|
|
34
|
-
"disallowedFetchDomains": ["blocked.com"] Blacklist for fetch domains
|
|
30
|
+
"outDir": "./dist" Default output directory for compiled files
|
|
35
31
|
}
|
|
36
32
|
|
|
37
33
|
Examples:
|
|
@@ -1,2 +1,18 @@
|
|
|
1
1
|
import { AgencyConfig } from "../config.js";
|
|
2
|
-
|
|
2
|
+
import { spawn as realSpawn } from "child_process";
|
|
3
|
+
/**
|
|
4
|
+
* Extract the debug flags (`--trace`, `--log-file`) from a bundled agent's
|
|
5
|
+
* forwarded argv, as a config override. This is the ONE place these flags are
|
|
6
|
+
* handled — every bundled agent gets them for free by going through
|
|
7
|
+
* `runBundledAgent`; no agent writes flag code.
|
|
8
|
+
*
|
|
9
|
+
* Tokenization is `node:util.parseArgs` (which `std::args` is itself built on)
|
|
10
|
+
* after the same bare-flag normalization std::args applies, so `--flag=value`,
|
|
11
|
+
* the `--` terminator, last-wins-on-repeat, AND a following-flag-is-not-a-value
|
|
12
|
+
* all match the agent's own parser. An empty/bare `--trace` maps to a per-run
|
|
13
|
+
* trace file in cwd; the flag→config meaning lives in `applyCliFlags`.
|
|
14
|
+
*/
|
|
15
|
+
export declare function agentConfigOverride(args: string[]): Partial<AgencyConfig>;
|
|
16
|
+
export declare function runBundledAgent(config: AgencyConfig, agentName: string, args?: string[], deps?: {
|
|
17
|
+
spawn?: typeof realSpawn;
|
|
18
|
+
}): void;
|