agency-lang 0.7.1 → 0.7.3
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 +55 -3
- package/dist/lib/agents/agency-agent/agent.js +137 -21
- 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/subagents/code.agency +55 -26
- package/dist/lib/agents/agency-agent/subagents/code.js +189 -29
- 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/commands.d.ts +9 -24
- package/dist/lib/cli/commands.js +26 -266
- 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/precompile.d.ts +3 -18
- package/dist/lib/cli/precompile.js +18 -66
- package/dist/lib/cli/precompile.test.js +16 -39
- 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/compiler/buildSession.d.ts +113 -0
- package/dist/lib/compiler/buildSession.js +360 -0
- package/dist/lib/compiler/buildSession.test.d.ts +1 -0
- package/dist/lib/compiler/buildSession.test.js +195 -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
|
@@ -184,12 +184,14 @@ __registerTool(getModelSettings);
|
|
|
184
184
|
__registerTool(loadSettings);
|
|
185
185
|
__registerTool(slotKind);
|
|
186
186
|
let __staticInitPromise = null;
|
|
187
|
+
let ONE_SHOT_MAX_TOOL_CALL_ROUNDS = __UNINIT_STATIC;
|
|
187
188
|
let AGENCY_AGENT_DIR = __UNINIT_STATIC;
|
|
188
189
|
async function __initializeStatic(__ctx) {
|
|
189
190
|
if (__staticInitPromise) {
|
|
190
191
|
return __staticInitPromise;
|
|
191
192
|
}
|
|
192
193
|
__staticInitPromise = (async () => {
|
|
194
|
+
ONE_SHOT_MAX_TOOL_CALL_ROUNDS = __deepFreeze(50);
|
|
193
195
|
AGENCY_AGENT_DIR = __deepFreeze(await __call(computeAgentDir, {
|
|
194
196
|
type: "positional",
|
|
195
197
|
args: []
|
|
@@ -199,6 +201,7 @@ async function __initializeStatic(__ctx) {
|
|
|
199
201
|
}
|
|
200
202
|
function __getStaticVars() {
|
|
201
203
|
return {
|
|
204
|
+
ONE_SHOT_MAX_TOOL_CALL_ROUNDS,
|
|
202
205
|
AGENCY_AGENT_DIR
|
|
203
206
|
};
|
|
204
207
|
}
|
|
@@ -220,6 +223,158 @@ async function __registerTopLevelCallbacks(__ctx) {
|
|
|
220
223
|
__ctx.topLevelCallbacks = [];
|
|
221
224
|
}
|
|
222
225
|
__functionRefReviver.registry = __toolRegistry;
|
|
226
|
+
async function __resolveMaxToolCallRounds_impl(explicit, oneShot) {
|
|
227
|
+
const __setupData = setupFunction();
|
|
228
|
+
const __stack = __setupData.stack;
|
|
229
|
+
const __step = __setupData.step;
|
|
230
|
+
const __self = __setupData.self;
|
|
231
|
+
const __ctx = getRuntimeContext().ctx;
|
|
232
|
+
let __forked;
|
|
233
|
+
let __functionCompleted = false;
|
|
234
|
+
if (!__globals().isInitialized("dist/lib/agents/agency-agent/shared.agency")) {
|
|
235
|
+
await __initializeGlobals(__ctx);
|
|
236
|
+
}
|
|
237
|
+
let __funcStartTime = performance.now();
|
|
238
|
+
__stack.args["explicit"] = explicit;
|
|
239
|
+
__stack.args["oneShot"] = oneShot;
|
|
240
|
+
__self.__retryable = __self.__retryable ?? true;
|
|
241
|
+
const runner = new Runner(__ctx, __stack, { state: __stack, moduleId: "dist/lib/agents/agency-agent/shared.agency", scopeName: "resolveMaxToolCallRounds", threads: __setupData.threads });
|
|
242
|
+
let __resultCheckpointId = -1;
|
|
243
|
+
if (__ctx._pendingArgOverrides) {
|
|
244
|
+
const __overrides = __ctx._pendingArgOverrides;
|
|
245
|
+
__ctx._pendingArgOverrides = void 0;
|
|
246
|
+
if ("explicit" in __overrides) {
|
|
247
|
+
explicit = __overrides["explicit"];
|
|
248
|
+
__stack.args["explicit"] = explicit;
|
|
249
|
+
}
|
|
250
|
+
if ("oneShot" in __overrides) {
|
|
251
|
+
oneShot = __overrides["oneShot"];
|
|
252
|
+
__stack.args["oneShot"] = oneShot;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
try {
|
|
256
|
+
await agencyStore.run({
|
|
257
|
+
...getRuntimeContext(),
|
|
258
|
+
ctx: __ctx,
|
|
259
|
+
stack: __setupData.stateStack,
|
|
260
|
+
threads: __setupData.threads
|
|
261
|
+
}, async () => {
|
|
262
|
+
await runner.hook(0, async () => {
|
|
263
|
+
await callHook({
|
|
264
|
+
name: "onFunctionStart",
|
|
265
|
+
data: {
|
|
266
|
+
functionName: "resolveMaxToolCallRounds",
|
|
267
|
+
args: {
|
|
268
|
+
explicit,
|
|
269
|
+
oneShot
|
|
270
|
+
},
|
|
271
|
+
moduleId: "dist/lib/agents/agency-agent/shared.agency"
|
|
272
|
+
}
|
|
273
|
+
});
|
|
274
|
+
});
|
|
275
|
+
await runner.ifElse(1, [
|
|
276
|
+
{
|
|
277
|
+
condition: async () => !__eq(__stack.args.explicit, null),
|
|
278
|
+
body: async (runner2) => {
|
|
279
|
+
await runner2.step(0, async (runner3) => {
|
|
280
|
+
__functionCompleted = true;
|
|
281
|
+
runner3.halt(__stack.args.explicit);
|
|
282
|
+
return;
|
|
283
|
+
});
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
]);
|
|
287
|
+
await runner.ifElse(2, [
|
|
288
|
+
{
|
|
289
|
+
condition: async () => __stack.args.oneShot,
|
|
290
|
+
body: async (runner2) => {
|
|
291
|
+
await runner2.step(0, async (runner3) => {
|
|
292
|
+
__functionCompleted = true;
|
|
293
|
+
runner3.halt(__readStatic(ONE_SHOT_MAX_TOOL_CALL_ROUNDS, "ONE_SHOT_MAX_TOOL_CALL_ROUNDS", "dist/lib/agents/agency-agent/shared.agency"));
|
|
294
|
+
return;
|
|
295
|
+
});
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
]);
|
|
299
|
+
await runner.step(3, async (runner2) => {
|
|
300
|
+
__functionCompleted = true;
|
|
301
|
+
runner2.halt(null);
|
|
302
|
+
return;
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
if (runner.halted) {
|
|
306
|
+
if (isFailure(runner.haltResult)) {
|
|
307
|
+
runner.haltResult.retryable = runner.haltResult.retryable && __self.__retryable;
|
|
308
|
+
}
|
|
309
|
+
return runner.haltResult;
|
|
310
|
+
}
|
|
311
|
+
} catch (__error) {
|
|
312
|
+
if (__error instanceof RestoreSignal) {
|
|
313
|
+
throw __error;
|
|
314
|
+
}
|
|
315
|
+
if (__error instanceof AgencyAbort) {
|
|
316
|
+
throw __error;
|
|
317
|
+
}
|
|
318
|
+
{
|
|
319
|
+
const __errMsg = __error instanceof Error ? __error.message : String(__error);
|
|
320
|
+
const __errStack = __error instanceof Error && __error.stack ? __error.stack : "";
|
|
321
|
+
const __log = __createLogger(__ctx.logLevel);
|
|
322
|
+
__log.error("Function resolveMaxToolCallRounds threw an exception (converted to Failure): " + __errMsg);
|
|
323
|
+
if (__errStack) __log.error(__errStack);
|
|
324
|
+
__ctx.statelogClient?.error?.({
|
|
325
|
+
errorType: "runtimeError",
|
|
326
|
+
message: __errMsg,
|
|
327
|
+
functionName: "resolveMaxToolCallRounds",
|
|
328
|
+
retryable: __self.__retryable
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
return failure(
|
|
332
|
+
__error instanceof Error ? __error.message : String(__error),
|
|
333
|
+
{
|
|
334
|
+
checkpoint: getRuntimeContext().ctx.getResultCheckpoint(),
|
|
335
|
+
retryable: __self.__retryable,
|
|
336
|
+
functionName: "resolveMaxToolCallRounds",
|
|
337
|
+
args: __stack.args
|
|
338
|
+
}
|
|
339
|
+
);
|
|
340
|
+
} finally {
|
|
341
|
+
__stateStack()?.pop();
|
|
342
|
+
if (__functionCompleted) {
|
|
343
|
+
await callHook({
|
|
344
|
+
name: "onFunctionEnd",
|
|
345
|
+
data: {
|
|
346
|
+
functionName: "resolveMaxToolCallRounds",
|
|
347
|
+
timeTaken: performance.now() - __funcStartTime
|
|
348
|
+
}
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
const resolveMaxToolCallRounds = __AgencyFunction.create({
|
|
354
|
+
name: "resolveMaxToolCallRounds",
|
|
355
|
+
module: "dist/lib/agents/agency-agent/shared.agency",
|
|
356
|
+
fn: __resolveMaxToolCallRounds_impl,
|
|
357
|
+
params: [{
|
|
358
|
+
name: "explicit",
|
|
359
|
+
hasDefault: false,
|
|
360
|
+
defaultValue: void 0,
|
|
361
|
+
variadic: false,
|
|
362
|
+
isFunctionTyped: false
|
|
363
|
+
}, {
|
|
364
|
+
name: "oneShot",
|
|
365
|
+
hasDefault: false,
|
|
366
|
+
defaultValue: void 0,
|
|
367
|
+
variadic: false,
|
|
368
|
+
isFunctionTyped: false
|
|
369
|
+
}],
|
|
370
|
+
toolDefinition: {
|
|
371
|
+
name: "resolveMaxToolCallRounds",
|
|
372
|
+
description: "No description provided.",
|
|
373
|
+
schema: z.object({ "explicit": z.union([z.number(), z.null()]), "oneShot": z.boolean() })
|
|
374
|
+
},
|
|
375
|
+
safe: false,
|
|
376
|
+
exported: true
|
|
377
|
+
}, __toolRegistry);
|
|
223
378
|
async function __computeAgentDir_impl() {
|
|
224
379
|
const __setupData = setupFunction();
|
|
225
380
|
const __stack = __setupData.stack;
|
|
@@ -1993,9 +2148,10 @@ const configureLocalModel = __AgencyFunction.create({
|
|
|
1993
2148
|
exported: true
|
|
1994
2149
|
}, __toolRegistry);
|
|
1995
2150
|
var stdin_default = graph;
|
|
1996
|
-
const __sourceMap = { "dist/lib/agents/agency-agent/shared.agency:computeAgentDir": { "1": { "line":
|
|
2151
|
+
const __sourceMap = { "dist/lib/agents/agency-agent/shared.agency:resolveMaxToolCallRounds": { "1": { "line": 35, "col": 2 }, "2": { "line": 38, "col": 2 }, "3": { "line": 41, "col": 2 }, "1.0": { "line": 36, "col": 4 }, "2.0": { "line": 39, "col": 4 } }, "dist/lib/agents/agency-agent/shared.agency:computeAgentDir": { "1": { "line": 56, "col": 2 }, "2": { "line": 57, "col": 2 }, "3": { "line": 60, "col": 2 }, "2.0": { "line": 58, "col": 4 } }, "dist/lib/agents/agency-agent/shared.agency:enableAgentMemory": { "1": { "line": 81, "col": 2 } }, "dist/lib/agents/agency-agent/shared.agency:getSlowModel": { "1": { "line": 94, "col": 2 } }, "dist/lib/agents/agency-agent/shared.agency:getSlowProvider": { "1": { "line": 98, "col": 2 } }, "dist/lib/agents/agency-agent/shared.agency:setSlowModel": { "1": { "line": 106, "col": 2 }, "2": { "line": 107, "col": 2 } }, "dist/lib/agents/agency-agent/shared.agency:promoteProvider": { "1": { "line": 115, "col": 2 }, "2": { "line": 118, "col": 2 }, "1.0": { "line": 116, "col": 4 } }, "dist/lib/agents/agency-agent/shared.agency:promoteAll": { "1": { "line": 124, "col": 2 }, "2": { "line": 125, "col": 2 }, "3": { "line": 136, "col": 2 }, "2.0": { "line": 126, "col": 4 }, "2.1": { "line": 127, "col": 4 }, "2.2": { "line": 130, "col": 4 } }, "dist/lib/agents/agency-agent/shared.agency:applyResolved": { "1": { "line": 144, "col": 2 }, "2": { "line": 145, "col": 2 }, "2.0": { "line": 146, "col": 4 }, "2.1": { "line": 147, "col": 4 }, "2.2": { "line": 150, "col": 4 }, "2.3.0": { "line": 152, "col": 6 }, "2.3.1": { "line": 159, "col": 6 }, "2.3": { "line": 151, "col": 4 } }, "dist/lib/agents/agency-agent/shared.agency:getResolvedSlots": { "1": { "line": 165, "col": 2 } }, "dist/lib/agents/agency-agent/shared.agency:currentProvider": { "1": { "line": 169, "col": 2 }, "2": { "line": 170, "col": 2 }, "3": { "line": 173, "col": 2 }, "2.0": { "line": 171, "col": 4 } }, "dist/lib/agents/agency-agent/shared.agency:configureModels": { "1": { "line": 192, "col": 2 }, "2": { "line": 197, "col": 2 }, "3": { "line": 198, "col": 2 }, "4": { "line": 202, "col": 2 }, "5": { "line": 203, "col": 2 }, "7": { "line": 212, "col": 2 }, "8": { "line": 216, "col": 2 }, "9": { "line": 217, "col": 2 }, "10": { "line": 220, "col": 2 }, "12": { "line": 226, "col": 2 }, "13": { "line": 227, "col": 2 }, "14": { "line": 236, "col": 2 }, "15": { "line": 237, "col": 2 }, "16": { "line": 242, "col": 2 }, "3.0": { "line": 199, "col": 4 }, "5.0": { "line": 204, "col": 4 }, "5.1": { "line": 205, "col": 4 }, "5.2": { "line": 206, "col": 4 }, "9.0": { "line": 218, "col": 4 }, "10.0": { "line": 221, "col": 4 }, "15.0": { "line": 238, "col": 4 }, "15.1": { "line": 239, "col": 4 }, "15.2": { "line": 240, "col": 4 } }, "dist/lib/agents/agency-agent/shared.agency:configureLocalModel": { "2": { "line": 258, "col": 2 }, "3": { "line": 259, "col": 2 }, "4": { "line": 264, "col": 2 }, "5": { "line": 268, "col": 2 }, "6": { "line": 273, "col": 2 }, "3.0": { "line": 260, "col": 4 }, "3.1": { "line": 261, "col": 4 }, "3.2": { "line": 262, "col": 4 } } };
|
|
1997
2152
|
export {
|
|
1998
2153
|
AGENCY_AGENT_DIR,
|
|
2154
|
+
ONE_SHOT_MAX_TOOL_CALL_ROUNDS,
|
|
1999
2155
|
__getCheckpoints,
|
|
2000
2156
|
__invokeFunction,
|
|
2001
2157
|
__setDebugger,
|
|
@@ -2021,6 +2177,7 @@ export {
|
|
|
2021
2177
|
promoteAll,
|
|
2022
2178
|
promoteProvider,
|
|
2023
2179
|
reject,
|
|
2180
|
+
resolveMaxToolCallRounds,
|
|
2024
2181
|
respondToInterrupts,
|
|
2025
2182
|
rewindFrom,
|
|
2026
2183
|
setSlowModel
|
|
@@ -27,7 +27,7 @@ import { skillsDir } from "std::skills"
|
|
|
27
27
|
import { systemMessage } from "std::thread"
|
|
28
28
|
|
|
29
29
|
import { agentNames } from "../lib/config.agency"
|
|
30
|
-
import { withWebSearch } from "../lib/search.agency"
|
|
30
|
+
import { withWebSearch, getSearchBackend } from "../lib/search.agency"
|
|
31
31
|
import { oracleAgent } from "./oracle.agency"
|
|
32
32
|
import { review, renderFeedback, feedbackHasErrors } from "./review.agency"
|
|
33
33
|
|
|
@@ -72,30 +72,16 @@ You are the **code specialist** of a multi-thread Agency-language
|
|
|
72
72
|
assistant. You handle anything that touches code or the file system:
|
|
73
73
|
writing, editing, running, and typechecking Agency or shell code.
|
|
74
74
|
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
`agency compile`, ...)
|
|
86
|
-
Pick whichever matches the question rather than guessing.
|
|
87
|
-
|
|
88
|
-
- If the research involves something else (a research question,
|
|
89
|
-
an external API, a Wikipedia summary, or a URL fetch), call
|
|
90
|
-
`handoff(reason)` — the only valid target for you is the research
|
|
91
|
-
specialist, so just pass a brief reason. The runtime will re-route
|
|
92
|
-
the user's original message there.
|
|
93
|
-
|
|
94
|
-
**Bias toward staying in the code thread.** Most follow-up messages
|
|
95
|
-
("can you make it faster?", "fix the error", "what about edge
|
|
96
|
-
cases?") are continuations of the current coding task, NOT new
|
|
97
|
-
categories. Only call `handoff` when the message clearly needs
|
|
98
|
-
research-specialist tools.
|
|
75
|
+
For Agency-language questions (syntax, control flow, types, the CLI),
|
|
76
|
+
call the bundled docs tools — they are authoritative for Agency:
|
|
77
|
+
* `docSkill` — the language guide (syntax, types, error handling,
|
|
78
|
+
built-ins, callbacks, advanced types)
|
|
79
|
+
* `cliSkill` — the CLI reference (`agency run`, `agency test`, ...)
|
|
80
|
+
Pick whichever matches the question rather than guessing.
|
|
81
|
+
|
|
82
|
+
**Stay focused on the current task.** Most follow-ups ("can you make it
|
|
83
|
+
faster?", "fix the error", "what about edge cases?") are continuations
|
|
84
|
+
of the current work, not new categories.
|
|
99
85
|
|
|
100
86
|
## Style
|
|
101
87
|
|
|
@@ -359,6 +345,40 @@ export static const codeTools: any[] = [
|
|
|
359
345
|
oracleAgent.partial(allowHandoff: false),
|
|
360
346
|
]
|
|
361
347
|
|
|
348
|
+
// Appended to the system prompt only when a web-search backend is active
|
|
349
|
+
// (see `withWebSearch`, which already wires the search tool onto the llm()
|
|
350
|
+
// call). The prompt just needs to tell the model it HAS the capability — on
|
|
351
|
+
// the cloud path `configureSearch` defaults to hosted web search.
|
|
352
|
+
static const WEB_SEARCH_NOTE = """
|
|
353
|
+
You have **web search**. Use it directly whenever a task needs current or
|
|
354
|
+
external information — a fact to verify, a library or API to check, a
|
|
355
|
+
dataset or leaderboard to consult. Do NOT ask the user to look things up,
|
|
356
|
+
and do NOT decline a task as "needs research / out of scope": search for
|
|
357
|
+
what you need and keep going."""
|
|
358
|
+
|
|
359
|
+
// Appended in one-shot / autonomous mode (`agency agent -p`), where there is
|
|
360
|
+
// no human to answer questions and no next turn. Gated on `_oneShot` so the
|
|
361
|
+
// interactive REPL keeps its normal ask-when-unsure behavior.
|
|
362
|
+
static const ONE_SHOT_NOTE = """
|
|
363
|
+
You are running in **one-shot, autonomous mode**: no human will answer
|
|
364
|
+
questions and there is NO next turn. Therefore:
|
|
365
|
+
- NEVER end your turn by asking a clarifying question or waiting for input.
|
|
366
|
+
If something is ambiguous, state the most reasonable assumption and
|
|
367
|
+
proceed.
|
|
368
|
+
- NEVER defer work to "the next turn" or hand back a plan — do it now.
|
|
369
|
+
- Leave the task COMPLETE on disk: write the required file(s), then verify
|
|
370
|
+
(compile, run, run any tests) and fix what fails before you stop.
|
|
371
|
+
- If you are running low on tool budget, spend the remaining calls
|
|
372
|
+
producing and saving the best COMPLETE artifact you can. A working file
|
|
373
|
+
on disk beats a perfect plan that was never written."""
|
|
374
|
+
|
|
375
|
+
// Set by `agent.agency` (`setCodeOneShot`) before the first dispatch when the
|
|
376
|
+
// run is non-interactive. Gates `ONE_SHOT_NOTE`.
|
|
377
|
+
let _oneShot = false
|
|
378
|
+
export def setCodeOneShot(oneShot: boolean) {
|
|
379
|
+
_oneShot = oneShot
|
|
380
|
+
}
|
|
381
|
+
|
|
362
382
|
// only add system message the first time
|
|
363
383
|
let _first = true
|
|
364
384
|
|
|
@@ -397,7 +417,16 @@ export def codeAgent(userMsg: string, allowHandoff: boolean) {
|
|
|
397
417
|
firstIteration = false
|
|
398
418
|
iterations += 1
|
|
399
419
|
if (_first) {
|
|
400
|
-
|
|
420
|
+
// Compose the system prompt from the static base plus the
|
|
421
|
+
// capabilities that are actually active this run.
|
|
422
|
+
let sys = codeSysPrompt
|
|
423
|
+
if (getSearchBackend() != "off") {
|
|
424
|
+
sys = "${sys}\n\n${WEB_SEARCH_NOTE}"
|
|
425
|
+
}
|
|
426
|
+
if (_oneShot) {
|
|
427
|
+
sys = "${sys}\n\n${ONE_SHOT_NOTE}"
|
|
428
|
+
}
|
|
429
|
+
systemMessage(sys)
|
|
401
430
|
_first = false
|
|
402
431
|
}
|
|
403
432
|
reply = llm(
|
|
@@ -11,7 +11,7 @@ import { gitStatus, gitLog, gitDiff, gitShow, gitBranchList, gitRemoteList, gitB
|
|
|
11
11
|
import { skillsDir } from "agency-lang/stdlib/skills.js";
|
|
12
12
|
import { systemMessage } from "agency-lang/stdlib/thread.js";
|
|
13
13
|
import { agentNames } from "../lib/config.js";
|
|
14
|
-
import { withWebSearch } from "../lib/search.js";
|
|
14
|
+
import { withWebSearch, getSearchBackend } from "../lib/search.js";
|
|
15
15
|
import { oracleAgent } from "./oracle.js";
|
|
16
16
|
import { review, renderFeedback, feedbackHasErrors } from "./review.js";
|
|
17
17
|
import { fileURLToPath } from "url";
|
|
@@ -214,6 +214,7 @@ __registerTool(skillsDir);
|
|
|
214
214
|
__registerTool(systemMessage);
|
|
215
215
|
__registerTool(agentNames);
|
|
216
216
|
__registerTool(withWebSearch);
|
|
217
|
+
__registerTool(getSearchBackend);
|
|
217
218
|
__registerTool(oracleAgent);
|
|
218
219
|
__registerTool(review);
|
|
219
220
|
__registerTool(renderFeedback);
|
|
@@ -224,6 +225,8 @@ let docSkill = __UNINIT_STATIC;
|
|
|
224
225
|
let cliSkill = __UNINIT_STATIC;
|
|
225
226
|
let codeSysPrompt = __UNINIT_STATIC;
|
|
226
227
|
let codeTools = __UNINIT_STATIC;
|
|
228
|
+
let WEB_SEARCH_NOTE = __UNINIT_STATIC;
|
|
229
|
+
let ONE_SHOT_NOTE = __UNINIT_STATIC;
|
|
227
230
|
async function __initializeStatic(__ctx) {
|
|
228
231
|
if (__staticInitPromise) {
|
|
229
232
|
return __staticInitPromise;
|
|
@@ -261,30 +264,16 @@ You are the **code specialist** of a multi-thread Agency-language
|
|
|
261
264
|
assistant. You handle anything that touches code or the file system:
|
|
262
265
|
writing, editing, running, and typechecking Agency or shell code.
|
|
263
266
|
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
+
For Agency-language questions (syntax, control flow, types, the CLI),
|
|
268
|
+
call the bundled docs tools \u2014 they are authoritative for Agency:
|
|
269
|
+
* \`docSkill\` \u2014 the language guide (syntax, types, error handling,
|
|
270
|
+
built-ins, callbacks, advanced types)
|
|
271
|
+
* \`cliSkill\` \u2014 the CLI reference (\`agency run\`, \`agency test\`, ...)
|
|
272
|
+
Pick whichever matches the question rather than guessing.
|
|
267
273
|
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
types, error handling, etc.),
|
|
272
|
-
built-ins, callbacks, advanced types
|
|
273
|
-
* \`cliSkill\` \u2014 CLI reference (\`agency run\`, \`agency test\`,
|
|
274
|
-
\`agency compile\`, ...)
|
|
275
|
-
Pick whichever matches the question rather than guessing.
|
|
276
|
-
|
|
277
|
-
- If the research involves something else (a research question,
|
|
278
|
-
an external API, a Wikipedia summary, or a URL fetch), call
|
|
279
|
-
\`handoff(reason)\` \u2014 the only valid target for you is the research
|
|
280
|
-
specialist, so just pass a brief reason. The runtime will re-route
|
|
281
|
-
the user's original message there.
|
|
282
|
-
|
|
283
|
-
**Bias toward staying in the code thread.** Most follow-up messages
|
|
284
|
-
("can you make it faster?", "fix the error", "what about edge
|
|
285
|
-
cases?") are continuations of the current coding task, NOT new
|
|
286
|
-
categories. Only call \`handoff\` when the message clearly needs
|
|
287
|
-
research-specialist tools.
|
|
274
|
+
**Stay focused on the current task.** Most follow-ups ("can you make it
|
|
275
|
+
faster?", "fix the error", "what about edge cases?") are continuations
|
|
276
|
+
of the current work, not new categories.
|
|
288
277
|
|
|
289
278
|
## Style
|
|
290
279
|
|
|
@@ -551,6 +540,24 @@ diagram needs scrolling, prose is probably better.
|
|
|
551
540
|
allowHandoff: false
|
|
552
541
|
}
|
|
553
542
|
})]);
|
|
543
|
+
WEB_SEARCH_NOTE = __deepFreeze(`
|
|
544
|
+
You have **web search**. Use it directly whenever a task needs current or
|
|
545
|
+
external information \u2014 a fact to verify, a library or API to check, a
|
|
546
|
+
dataset or leaderboard to consult. Do NOT ask the user to look things up,
|
|
547
|
+
and do NOT decline a task as "needs research / out of scope": search for
|
|
548
|
+
what you need and keep going.`);
|
|
549
|
+
ONE_SHOT_NOTE = __deepFreeze(`
|
|
550
|
+
You are running in **one-shot, autonomous mode**: no human will answer
|
|
551
|
+
questions and there is NO next turn. Therefore:
|
|
552
|
+
- NEVER end your turn by asking a clarifying question or waiting for input.
|
|
553
|
+
If something is ambiguous, state the most reasonable assumption and
|
|
554
|
+
proceed.
|
|
555
|
+
- NEVER defer work to "the next turn" or hand back a plan \u2014 do it now.
|
|
556
|
+
- Leave the task COMPLETE on disk: write the required file(s), then verify
|
|
557
|
+
(compile, run, run any tests) and fix what fails before you stop.
|
|
558
|
+
- If you are running low on tool budget, spend the remaining calls
|
|
559
|
+
producing and saving the best COMPLETE artifact you can. A working file
|
|
560
|
+
on disk beats a perfect plan that was never written.`);
|
|
554
561
|
})();
|
|
555
562
|
return __staticInitPromise;
|
|
556
563
|
}
|
|
@@ -560,7 +567,9 @@ function __getStaticVars() {
|
|
|
560
567
|
docSkill,
|
|
561
568
|
cliSkill,
|
|
562
569
|
codeSysPrompt,
|
|
563
|
-
codeTools
|
|
570
|
+
codeTools,
|
|
571
|
+
WEB_SEARCH_NOTE,
|
|
572
|
+
ONE_SHOT_NOTE
|
|
564
573
|
};
|
|
565
574
|
}
|
|
566
575
|
__globalCtx.getStaticVars = __getStaticVars;
|
|
@@ -572,6 +581,7 @@ async function __initializeGlobals(__ctx) {
|
|
|
572
581
|
__ctx.globals.markInitialized("dist/lib/agents/agency-agent/subagents/code.agency");
|
|
573
582
|
await __initializeStatic(__ctx);
|
|
574
583
|
await __ctx.writeStaticStateToTrace(__globalCtx.getStaticVars());
|
|
584
|
+
__ctx.globals.set("dist/lib/agents/agency-agent/subagents/code.agency", "_oneShot", false);
|
|
575
585
|
__ctx.globals.set("dist/lib/agents/agency-agent/subagents/code.agency", "_first", true);
|
|
576
586
|
}
|
|
577
587
|
__registerGlobalsInit("dist/lib/agents/agency-agent/subagents/code.agency", __initializeGlobals);
|
|
@@ -713,6 +723,120 @@ const agencyCli = __AgencyFunction.create({
|
|
|
713
723
|
safe: false,
|
|
714
724
|
exported: true
|
|
715
725
|
}, __toolRegistry);
|
|
726
|
+
async function __setCodeOneShot_impl(oneShot) {
|
|
727
|
+
const __setupData = setupFunction();
|
|
728
|
+
const __stack = __setupData.stack;
|
|
729
|
+
const __step = __setupData.step;
|
|
730
|
+
const __self = __setupData.self;
|
|
731
|
+
const __ctx = getRuntimeContext().ctx;
|
|
732
|
+
let __forked;
|
|
733
|
+
let __functionCompleted = false;
|
|
734
|
+
if (!__globals().isInitialized("dist/lib/agents/agency-agent/subagents/code.agency")) {
|
|
735
|
+
await __initializeGlobals(__ctx);
|
|
736
|
+
}
|
|
737
|
+
let __funcStartTime = performance.now();
|
|
738
|
+
__stack.args["oneShot"] = oneShot;
|
|
739
|
+
__self.__retryable = __self.__retryable ?? true;
|
|
740
|
+
const runner = new Runner(__ctx, __stack, { state: __stack, moduleId: "dist/lib/agents/agency-agent/subagents/code.agency", scopeName: "setCodeOneShot", threads: __setupData.threads });
|
|
741
|
+
let __resultCheckpointId = -1;
|
|
742
|
+
if (__ctx._pendingArgOverrides) {
|
|
743
|
+
const __overrides = __ctx._pendingArgOverrides;
|
|
744
|
+
__ctx._pendingArgOverrides = void 0;
|
|
745
|
+
if ("oneShot" in __overrides) {
|
|
746
|
+
oneShot = __overrides["oneShot"];
|
|
747
|
+
__stack.args["oneShot"] = oneShot;
|
|
748
|
+
}
|
|
749
|
+
}
|
|
750
|
+
try {
|
|
751
|
+
await agencyStore.run({
|
|
752
|
+
...getRuntimeContext(),
|
|
753
|
+
ctx: __ctx,
|
|
754
|
+
stack: __setupData.stateStack,
|
|
755
|
+
threads: __setupData.threads
|
|
756
|
+
}, async () => {
|
|
757
|
+
await runner.hook(0, async () => {
|
|
758
|
+
await callHook({
|
|
759
|
+
name: "onFunctionStart",
|
|
760
|
+
data: {
|
|
761
|
+
functionName: "setCodeOneShot",
|
|
762
|
+
args: {
|
|
763
|
+
oneShot
|
|
764
|
+
},
|
|
765
|
+
moduleId: "dist/lib/agents/agency-agent/subagents/code.agency"
|
|
766
|
+
}
|
|
767
|
+
});
|
|
768
|
+
});
|
|
769
|
+
await runner.step(1, async (runner2) => {
|
|
770
|
+
__globals().set("dist/lib/agents/agency-agent/subagents/code.agency", "_oneShot", __stack.args.oneShot);
|
|
771
|
+
});
|
|
772
|
+
});
|
|
773
|
+
if (runner.halted) {
|
|
774
|
+
if (isFailure(runner.haltResult)) {
|
|
775
|
+
runner.haltResult.retryable = runner.haltResult.retryable && __self.__retryable;
|
|
776
|
+
}
|
|
777
|
+
return runner.haltResult;
|
|
778
|
+
}
|
|
779
|
+
} catch (__error) {
|
|
780
|
+
if (__error instanceof RestoreSignal) {
|
|
781
|
+
throw __error;
|
|
782
|
+
}
|
|
783
|
+
if (__error instanceof AgencyAbort) {
|
|
784
|
+
throw __error;
|
|
785
|
+
}
|
|
786
|
+
{
|
|
787
|
+
const __errMsg = __error instanceof Error ? __error.message : String(__error);
|
|
788
|
+
const __errStack = __error instanceof Error && __error.stack ? __error.stack : "";
|
|
789
|
+
const __log = __createLogger(__ctx.logLevel);
|
|
790
|
+
__log.error("Function setCodeOneShot threw an exception (converted to Failure): " + __errMsg);
|
|
791
|
+
if (__errStack) __log.error(__errStack);
|
|
792
|
+
__ctx.statelogClient?.error?.({
|
|
793
|
+
errorType: "runtimeError",
|
|
794
|
+
message: __errMsg,
|
|
795
|
+
functionName: "setCodeOneShot",
|
|
796
|
+
retryable: __self.__retryable
|
|
797
|
+
});
|
|
798
|
+
}
|
|
799
|
+
return failure(
|
|
800
|
+
__error instanceof Error ? __error.message : String(__error),
|
|
801
|
+
{
|
|
802
|
+
checkpoint: getRuntimeContext().ctx.getResultCheckpoint(),
|
|
803
|
+
retryable: __self.__retryable,
|
|
804
|
+
functionName: "setCodeOneShot",
|
|
805
|
+
args: __stack.args
|
|
806
|
+
}
|
|
807
|
+
);
|
|
808
|
+
} finally {
|
|
809
|
+
__stateStack()?.pop();
|
|
810
|
+
if (__functionCompleted) {
|
|
811
|
+
await callHook({
|
|
812
|
+
name: "onFunctionEnd",
|
|
813
|
+
data: {
|
|
814
|
+
functionName: "setCodeOneShot",
|
|
815
|
+
timeTaken: performance.now() - __funcStartTime
|
|
816
|
+
}
|
|
817
|
+
});
|
|
818
|
+
}
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
const setCodeOneShot = __AgencyFunction.create({
|
|
822
|
+
name: "setCodeOneShot",
|
|
823
|
+
module: "dist/lib/agents/agency-agent/subagents/code.agency",
|
|
824
|
+
fn: __setCodeOneShot_impl,
|
|
825
|
+
params: [{
|
|
826
|
+
name: "oneShot",
|
|
827
|
+
hasDefault: false,
|
|
828
|
+
defaultValue: void 0,
|
|
829
|
+
variadic: false,
|
|
830
|
+
isFunctionTyped: false
|
|
831
|
+
}],
|
|
832
|
+
toolDefinition: {
|
|
833
|
+
name: "setCodeOneShot",
|
|
834
|
+
description: "No description provided.",
|
|
835
|
+
schema: z.object({ "oneShot": z.boolean() })
|
|
836
|
+
},
|
|
837
|
+
safe: false,
|
|
838
|
+
exported: true
|
|
839
|
+
}, __toolRegistry);
|
|
716
840
|
async function __codeAgent_impl(userMsg, allowHandoff) {
|
|
717
841
|
const __setupData = setupFunction();
|
|
718
842
|
const __stack = __setupData.stack;
|
|
@@ -854,10 +978,45 @@ async function __codeAgent_impl(userMsg, allowHandoff) {
|
|
|
854
978
|
condition: async () => __globals().get("dist/lib/agents/agency-agent/subagents/code.agency", "_first"),
|
|
855
979
|
body: async (runner4) => {
|
|
856
980
|
await runner4.step(0, async (runner5) => {
|
|
981
|
+
});
|
|
982
|
+
await runner4.step(1, async (runner5) => {
|
|
983
|
+
__stack.locals.sys = __readStatic(codeSysPrompt, "codeSysPrompt", "dist/lib/agents/agency-agent/subagents/code.agency");
|
|
984
|
+
});
|
|
985
|
+
await runner4.ifElse(2, [
|
|
986
|
+
{
|
|
987
|
+
condition: async () => !__eq(await __call(getSearchBackend, {
|
|
988
|
+
type: "positional",
|
|
989
|
+
args: []
|
|
990
|
+
}), `off`),
|
|
991
|
+
body: async (runner5) => {
|
|
992
|
+
await runner5.step(0, async (runner6) => {
|
|
993
|
+
__stack.locals.sys = `${__stack.locals.sys}
|
|
994
|
+
|
|
995
|
+
${__readStatic(WEB_SEARCH_NOTE, "WEB_SEARCH_NOTE", "dist/lib/agents/agency-agent/subagents/code.agency")}`;
|
|
996
|
+
});
|
|
997
|
+
}
|
|
998
|
+
}
|
|
999
|
+
]);
|
|
1000
|
+
await runner4.step(3, async (runner5) => {
|
|
1001
|
+
__self.__retryable = false;
|
|
1002
|
+
});
|
|
1003
|
+
await runner4.ifElse(4, [
|
|
1004
|
+
{
|
|
1005
|
+
condition: async () => __globals().get("dist/lib/agents/agency-agent/subagents/code.agency", "_oneShot"),
|
|
1006
|
+
body: async (runner5) => {
|
|
1007
|
+
await runner5.step(0, async (runner6) => {
|
|
1008
|
+
__stack.locals.sys = `${__stack.locals.sys}
|
|
1009
|
+
|
|
1010
|
+
${__readStatic(ONE_SHOT_NOTE, "ONE_SHOT_NOTE", "dist/lib/agents/agency-agent/subagents/code.agency")}`;
|
|
1011
|
+
});
|
|
1012
|
+
}
|
|
1013
|
+
}
|
|
1014
|
+
]);
|
|
1015
|
+
await runner4.step(5, async (runner5) => {
|
|
857
1016
|
__self.__retryable = false;
|
|
858
1017
|
const __funcResult = await __call(systemMessage, {
|
|
859
1018
|
type: "positional",
|
|
860
|
-
args: [
|
|
1019
|
+
args: [__stack.locals.sys]
|
|
861
1020
|
});
|
|
862
1021
|
if (hasInterrupts(__funcResult)) {
|
|
863
1022
|
await getRuntimeContext().ctx.pendingPromises.awaitAll();
|
|
@@ -865,7 +1024,7 @@ async function __codeAgent_impl(userMsg, allowHandoff) {
|
|
|
865
1024
|
return;
|
|
866
1025
|
}
|
|
867
1026
|
});
|
|
868
|
-
await runner4.step(
|
|
1027
|
+
await runner4.step(6, async (runner5) => {
|
|
869
1028
|
__globals().set("dist/lib/agents/agency-agent/subagents/code.agency", "_first", false);
|
|
870
1029
|
});
|
|
871
1030
|
}
|
|
@@ -1073,7 +1232,7 @@ const codeAgent = __AgencyFunction.create({
|
|
|
1073
1232
|
exported: true
|
|
1074
1233
|
}, __toolRegistry);
|
|
1075
1234
|
var stdin_default = graph;
|
|
1076
|
-
const __sourceMap = { "dist/lib/agents/agency-agent/subagents/code.agency:agencyCli": { "1": { "line": 66, "col": 2 } }, "dist/lib/agents/agency-agent/subagents/code.agency:codeAgent": { "1": { "line":
|
|
1235
|
+
const __sourceMap = { "dist/lib/agents/agency-agent/subagents/code.agency:agencyCli": { "1": { "line": 66, "col": 2 } }, "dist/lib/agents/agency-agent/subagents/code.agency:setCodeOneShot": { "1": { "line": 378, "col": 2 } }, "dist/lib/agents/agency-agent/subagents/code.agency:codeAgent": { "1": { "line": 394, "col": 2 }, "2": { "line": 395, "col": 2 }, "3": { "line": 396, "col": 2 }, "4": { "line": 397, "col": 2 }, "5": { "line": 401, "col": 2 }, "6": { "line": 402, "col": 2 }, "7": { "line": 405, "col": 2 }, "8": { "line": 412, "col": 2 }, "9": { "line": 413, "col": 2 }, "11": { "line": 465, "col": 2 }, "4.0": { "line": 398, "col": 4 }, "9.0": { "line": 414, "col": 4 }, "9.1.0": { "line": 416, "col": 6 }, "9.1.2.1": { "line": 421, "col": 8 }, "9.1.2.2.0": { "line": 423, "col": 10 }, "9.1.2.2": { "line": 422, "col": 8 }, "9.1.2.4.0": { "line": 426, "col": 10 }, "9.1.2.4": { "line": 425, "col": 8 }, "9.1.2.5": { "line": 428, "col": 8 }, "9.1.2.6": { "line": 429, "col": 8 }, "9.1.2": { "line": 418, "col": 6 }, "9.1.4": { "line": 431, "col": 6 }, "9.1.5": { "line": 439, "col": 6 }, "9.1.6.0": { "line": 441, "col": 8 }, "9.1.6.1": { "line": 442, "col": 8 }, "9.1.6.2": { "line": 443, "col": 8 }, "9.1.6.3": { "line": 445, "col": 8 }, "9.1.6": { "line": 440, "col": 6 }, "9.1": { "line": 415, "col": 4 }, "9.3": { "line": 449, "col": 4 }, "9.4": { "line": 463, "col": 4 } }, "dist/lib/agents/agency-agent/subagents/code.agency:__block_0": {} };
|
|
1077
1236
|
export {
|
|
1078
1237
|
__getCheckpoints,
|
|
1079
1238
|
__invokeFunction,
|
|
@@ -1094,5 +1253,6 @@ export {
|
|
|
1094
1253
|
isInterrupt,
|
|
1095
1254
|
reject,
|
|
1096
1255
|
respondToInterrupts,
|
|
1097
|
-
rewindFrom
|
|
1256
|
+
rewindFrom,
|
|
1257
|
+
setCodeOneShot
|
|
1098
1258
|
};
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
// resolveMaxToolCallRounds: an explicit --max-tool-call-rounds always wins;
|
|
2
|
+
// otherwise one-shot runs get the higher default and interactive runs keep the
|
|
3
|
+
// compiled default (null).
|
|
4
|
+
import { resolveMaxToolCallRounds } from "../shared.agency"
|
|
5
|
+
|
|
6
|
+
node explicitWinsOverOneShot(): boolean {
|
|
7
|
+
return resolveMaxToolCallRounds(7, true) == 7
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
node oneShotDefaults50(): boolean {
|
|
11
|
+
return resolveMaxToolCallRounds(null, true) == 50
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
node explicitWinsOverInteractive(): boolean {
|
|
15
|
+
return resolveMaxToolCallRounds(3, false) == 3
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
node interactiveKeepsBaked(): boolean {
|
|
19
|
+
return resolveMaxToolCallRounds(null, false) == null
|
|
20
|
+
}
|