agency-lang 0.1.2 → 0.1.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/policy/agent.js +736 -0
- package/dist/lib/backends/agencyGenerator.js +12 -12
- package/dist/lib/backends/agencyGenerator.test.js +58 -0
- package/dist/lib/backends/typescriptBuilder.d.ts +36 -0
- package/dist/lib/backends/typescriptBuilder.js +143 -7
- package/dist/lib/backends/typescriptGenerator/typeToString.d.ts +1 -1
- package/dist/lib/backends/typescriptGenerator/typeToString.js +11 -8
- package/dist/lib/cli/coverage.d.ts +21 -2
- package/dist/lib/cli/coverage.js +51 -2
- package/dist/lib/cli/doc.js +29 -6
- package/dist/lib/cli/doc.test.js +38 -0
- package/dist/lib/cli/schedule/backends/github.d.ts +18 -0
- package/dist/lib/cli/schedule/backends/github.js +110 -0
- package/dist/lib/cli/schedule/backends/github.snapshot.test.d.ts +1 -0
- package/dist/lib/cli/schedule/backends/github.snapshot.test.js +50 -0
- package/dist/lib/cli/schedule/backends/github.test.d.ts +1 -0
- package/dist/lib/cli/schedule/backends/github.test.js +165 -0
- package/dist/lib/cli/schedule/backends/index.d.ts +3 -1
- package/dist/lib/cli/schedule/backends/index.js +4 -0
- package/dist/lib/cli/schedule/backends/index.test.d.ts +1 -0
- package/dist/lib/cli/schedule/backends/index.test.js +9 -0
- package/dist/lib/cli/schedule/backends/pinnedActions.d.ts +5 -0
- package/dist/lib/cli/schedule/backends/pinnedActions.js +16 -0
- package/dist/lib/cli/schedule/index.d.ts +11 -0
- package/dist/lib/cli/schedule/index.github.test.d.ts +1 -0
- package/dist/lib/cli/schedule/index.github.test.js +123 -0
- package/dist/lib/cli/schedule/index.js +56 -5
- package/dist/lib/cli/schedule/registry.d.ts +7 -0
- package/dist/lib/config.d.ts +22 -0
- package/dist/lib/config.js +8 -1
- package/dist/lib/debugger/ui.js +33 -3
- package/dist/lib/ir/prettyPrint.js +9 -1
- package/dist/lib/ir/prettyPrint.test.js +21 -0
- package/dist/lib/parsers/blockArgument.test.js +7 -2
- package/dist/lib/parsers/expression.test.js +58 -0
- package/dist/lib/parsers/literals.test.js +33 -2
- package/dist/lib/parsers/parsers.d.ts +7 -0
- package/dist/lib/parsers/parsers.js +96 -9
- package/dist/lib/parsers/typeHints.test.js +35 -0
- package/dist/lib/parsers/withModifier.test.js +10 -0
- package/dist/lib/runtime/agencyFunction.d.ts +5 -0
- package/dist/lib/runtime/agencyFunction.js +35 -0
- package/dist/lib/runtime/call.js +10 -0
- package/dist/lib/runtime/call.test.js +14 -0
- package/dist/lib/runtime/revivers/functionRefReviver.js +19 -9
- package/dist/lib/stdlib/syntax.js +19 -16
- package/dist/lib/symbolTable.js +5 -0
- package/dist/lib/templates/backends/typescriptGenerator/forkBlockSetup.d.ts +2 -1
- package/dist/lib/templates/backends/typescriptGenerator/forkBlockSetup.js +14 -1
- package/dist/lib/templates/cli/schedule/githubWorkflow.d.ts +13 -0
- package/dist/lib/templates/cli/schedule/githubWorkflow.js +30 -0
- package/dist/lib/tui/builders.js +14 -28
- package/dist/lib/tui/colors.d.ts +9 -0
- package/dist/lib/tui/colors.js +9 -0
- package/dist/lib/tui/frame.d.ts +6 -0
- package/dist/lib/tui/frame.js +9 -1
- package/dist/lib/tui/input/scripted.js +2 -2
- package/dist/lib/tui/input/terminal.js +21 -3
- package/dist/lib/tui/layout.js +16 -30
- package/dist/lib/tui/output/recorder.d.ts +1 -1
- package/dist/lib/tui/output/recorder.js +19 -1
- package/dist/lib/tui/output/terminal.d.ts +2 -1
- package/dist/lib/tui/output/terminal.js +19 -3
- package/dist/lib/tui/render/ansi.js +39 -10
- package/dist/lib/tui/render/html.js +28 -14
- package/dist/lib/tui/render/renderer.js +9 -7
- package/dist/lib/tui/styleParser.js +172 -18
- package/dist/lib/tui/utils.d.ts +12 -1
- package/dist/lib/tui/utils.js +15 -0
- package/dist/lib/typeChecker/assignability.js +18 -0
- package/dist/lib/typeChecker/assignability.test.js +22 -0
- package/dist/lib/typeChecker/checker.js +55 -3
- package/dist/lib/typeChecker/interruptAnalysis.js +16 -12
- package/dist/lib/typeChecker/interruptWarnings.test.js +53 -0
- package/dist/lib/typeChecker/synthesizer.js +16 -3
- package/dist/lib/typeChecker.test.js +27 -0
- package/dist/lib/utils/agentUtils.d.ts +1 -1
- package/dist/lib/utils/agentUtils.js +3 -75
- package/dist/lib/utils/termcolors.d.ts +7 -1
- package/dist/lib/utils/termcolors.js +44 -0
- package/dist/scripts/agency.js +27 -3
- package/package.json +1 -2
- package/stdlib/lib/allowBlockList.js +37 -0
- package/stdlib/lib/browserUse.js +75 -0
- package/stdlib/lib/builtins.js +117 -0
- package/stdlib/lib/calendar.js +145 -0
- package/stdlib/lib/clipboard.js +41 -0
- package/stdlib/lib/date.js +196 -0
- package/stdlib/lib/email.js +145 -0
- package/stdlib/lib/fs.js +285 -0
- package/stdlib/lib/http.js +132 -0
- package/stdlib/lib/imessage.js +49 -0
- package/stdlib/lib/keyring.js +159 -0
- package/stdlib/lib/messaging.js +1 -0
- package/stdlib/lib/oauth.js +288 -0
- package/stdlib/lib/oauthEncryption.js +69 -0
- package/stdlib/lib/path.js +22 -0
- package/stdlib/lib/policy.js +1 -0
- package/stdlib/lib/resolvePath.js +43 -0
- package/stdlib/lib/shell.js +298 -0
- package/stdlib/lib/sms.js +47 -0
- package/stdlib/lib/speech.js +129 -0
- package/stdlib/lib/syntax.js +75 -0
- package/stdlib/lib/system.js +67 -0
- package/stdlib/lib/ui.js +393 -0
- package/stdlib/lib/utils.js +51 -0
- package/stdlib/lib/weather.js +94 -0
- package/stdlib/lib/wikipedia.js +47 -0
|
@@ -0,0 +1,736 @@
|
|
|
1
|
+
import { print, printJSON, input, sleep, round, fetch, fetchJSON, read, write, readImage, notify, range, mostCommon, keys, values, entries, emit } from "agency-lang/stdlib/index.js";
|
|
2
|
+
import { writePolicyFile } from "agency-lang/stdlib/policy.js";
|
|
3
|
+
import { args } from "agency-lang/stdlib/system.js";
|
|
4
|
+
import { fileURLToPath } from "url";
|
|
5
|
+
import __process from "process";
|
|
6
|
+
import { z } from "agency-lang/zod";
|
|
7
|
+
import { goToNode, nanoid } from "agency-lang";
|
|
8
|
+
import { smoltalk } from "agency-lang";
|
|
9
|
+
import path from "path";
|
|
10
|
+
import {
|
|
11
|
+
RuntimeContext,
|
|
12
|
+
ThreadStore,
|
|
13
|
+
Runner,
|
|
14
|
+
setupNode,
|
|
15
|
+
runNode,
|
|
16
|
+
runPrompt,
|
|
17
|
+
callHook,
|
|
18
|
+
checkpoint as __checkpoint_impl,
|
|
19
|
+
getCheckpoint as __getCheckpoint_impl,
|
|
20
|
+
restore as __restore_impl,
|
|
21
|
+
_run as __runtime_run_impl,
|
|
22
|
+
interrupt,
|
|
23
|
+
isInterrupt,
|
|
24
|
+
hasInterrupts,
|
|
25
|
+
isDebugger,
|
|
26
|
+
respondToInterrupts as _respondToInterrupts,
|
|
27
|
+
rewindFrom as _rewindFrom,
|
|
28
|
+
RestoreSignal,
|
|
29
|
+
failure,
|
|
30
|
+
readSkill as _readSkillRaw,
|
|
31
|
+
readSkillTool as __readSkillTool,
|
|
32
|
+
readSkillToolParams as __readSkillToolParams,
|
|
33
|
+
AgencyFunction as __AgencyFunction,
|
|
34
|
+
__call,
|
|
35
|
+
functionRefReviver as __functionRefReviver,
|
|
36
|
+
DeterministicClient as __DeterministicClient
|
|
37
|
+
} from "agency-lang/runtime";
|
|
38
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
39
|
+
const __dirname = path.dirname(__filename);
|
|
40
|
+
const __cwd = __process.cwd();
|
|
41
|
+
const getDirname = () => __dirname;
|
|
42
|
+
const __globalCtx = new RuntimeContext({
|
|
43
|
+
statelogConfig: {
|
|
44
|
+
host: "https://statelog.adit.io",
|
|
45
|
+
apiKey: __process.env["STATELOG_API_KEY"] || "",
|
|
46
|
+
projectId: "agency-lang",
|
|
47
|
+
debugMode: false
|
|
48
|
+
},
|
|
49
|
+
smoltalkDefaults: {
|
|
50
|
+
openAiApiKey: __process.env["OPENAI_API_KEY"] || "",
|
|
51
|
+
googleApiKey: __process.env["GEMINI_API_KEY"] || "",
|
|
52
|
+
model: "gpt-4o-mini",
|
|
53
|
+
logLevel: "warn",
|
|
54
|
+
statelog: {
|
|
55
|
+
host: "https://statelog.adit.io",
|
|
56
|
+
projectId: "smoltalk",
|
|
57
|
+
apiKey: __process.env["STATELOG_SMOLTALK_API_KEY"] || "",
|
|
58
|
+
traceId: nanoid()
|
|
59
|
+
}
|
|
60
|
+
},
|
|
61
|
+
dirname: __dirname,
|
|
62
|
+
traceConfig: {
|
|
63
|
+
program: "lib/agents/policy/agent.agency",
|
|
64
|
+
traceDir: "traces"
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
const graph = __globalCtx.graph;
|
|
68
|
+
function readSkill({ filepath }) {
|
|
69
|
+
return _readSkillRaw({ filepath, dirname: __dirname });
|
|
70
|
+
}
|
|
71
|
+
function approve(value) {
|
|
72
|
+
return { type: "approve", value };
|
|
73
|
+
}
|
|
74
|
+
function reject(value) {
|
|
75
|
+
return { type: "reject", value };
|
|
76
|
+
}
|
|
77
|
+
function propagate() {
|
|
78
|
+
return { type: "propagate" };
|
|
79
|
+
}
|
|
80
|
+
const respondToInterrupts = (interrupts, responses, opts) => _respondToInterrupts({ ctx: __globalCtx, interrupts, responses, overrides: opts?.overrides, metadata: opts?.metadata });
|
|
81
|
+
const rewindFrom = (checkpoint2, overrides, opts) => _rewindFrom({ ctx: __globalCtx, checkpoint: checkpoint2, overrides, metadata: opts?.metadata });
|
|
82
|
+
const __setDebugger = (dbg) => {
|
|
83
|
+
__globalCtx.debuggerState = dbg;
|
|
84
|
+
};
|
|
85
|
+
const __setTraceWriter = (tw) => {
|
|
86
|
+
__globalCtx.traceWriter = tw;
|
|
87
|
+
};
|
|
88
|
+
const __setLLMClient = (client) => {
|
|
89
|
+
__globalCtx.setLLMClient(client);
|
|
90
|
+
};
|
|
91
|
+
const __getCheckpoints = () => __globalCtx.checkpoints;
|
|
92
|
+
if (__process.env.AGENCY_LLM_MOCKS) {
|
|
93
|
+
__globalCtx.setLLMClient(
|
|
94
|
+
new __DeterministicClient(JSON.parse(__process.env.AGENCY_LLM_MOCKS))
|
|
95
|
+
);
|
|
96
|
+
}
|
|
97
|
+
const __toolRegistry = {};
|
|
98
|
+
function __registerTool(value, name) {
|
|
99
|
+
if (__AgencyFunction.isAgencyFunction(value)) {
|
|
100
|
+
__toolRegistry[name ?? value.name] = value;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
const checkpoint = __AgencyFunction.create({ name: "checkpoint", module: "__runtime", fn: __checkpoint_impl, params: [], toolDefinition: null }, __toolRegistry);
|
|
104
|
+
const getCheckpoint = __AgencyFunction.create({ name: "getCheckpoint", module: "__runtime", fn: __getCheckpoint_impl, params: [{ name: "checkpointId", hasDefault: false, defaultValue: void 0, variadic: false }], toolDefinition: null }, __toolRegistry);
|
|
105
|
+
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);
|
|
106
|
+
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 }], toolDefinition: null }, __toolRegistry);
|
|
107
|
+
function setLLMClient(client) {
|
|
108
|
+
__globalCtx.setLLMClient(client);
|
|
109
|
+
}
|
|
110
|
+
function registerTools(tools) {
|
|
111
|
+
for (const tool of tools) {
|
|
112
|
+
if (__AgencyFunction.isAgencyFunction(tool)) {
|
|
113
|
+
__toolRegistry[tool.name] = tool;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
__registerTool(print);
|
|
118
|
+
__registerTool(printJSON);
|
|
119
|
+
__registerTool(input);
|
|
120
|
+
__registerTool(sleep);
|
|
121
|
+
__registerTool(round);
|
|
122
|
+
__registerTool(fetch);
|
|
123
|
+
__registerTool(fetchJSON);
|
|
124
|
+
__registerTool(read);
|
|
125
|
+
__registerTool(write);
|
|
126
|
+
__registerTool(readImage);
|
|
127
|
+
__registerTool(notify);
|
|
128
|
+
__registerTool(range);
|
|
129
|
+
__registerTool(mostCommon);
|
|
130
|
+
__registerTool(keys);
|
|
131
|
+
__registerTool(values);
|
|
132
|
+
__registerTool(entries);
|
|
133
|
+
__registerTool(emit);
|
|
134
|
+
__registerTool(writePolicyFile);
|
|
135
|
+
__registerTool(args);
|
|
136
|
+
async function __initializeGlobals(__ctx) {
|
|
137
|
+
__ctx.globals.markInitialized("lib/agents/policy/agent.agency");
|
|
138
|
+
__ctx.globals.set("lib/agents/policy/agent.agency", "systemPrompt", await __call(read, {
|
|
139
|
+
type: "positional",
|
|
140
|
+
args: [`./prompts/system.md`]
|
|
141
|
+
}, {
|
|
142
|
+
ctx: __ctx
|
|
143
|
+
}));
|
|
144
|
+
}
|
|
145
|
+
__toolRegistry["readSkill"] = __AgencyFunction.create({
|
|
146
|
+
name: "readSkill",
|
|
147
|
+
module: "lib/agents/policy/agent.agency",
|
|
148
|
+
fn: readSkill,
|
|
149
|
+
params: __readSkillToolParams.map((p) => ({ name: p, hasDefault: false, defaultValue: void 0, variadic: false })),
|
|
150
|
+
toolDefinition: __readSkillTool
|
|
151
|
+
}, __toolRegistry);
|
|
152
|
+
__functionRefReviver.registry = __toolRegistry;
|
|
153
|
+
const NextStep = z.union([z.object({ "type": z.literal("showPolicy"), "policy": z.record(z.string(), z.any()) }), z.object({ "type": z.literal("writePolicy"), "policy": z.record(z.string(), z.any()) }), z.object({ "type": z.literal("askQuestion"), "question": z.string() })]);
|
|
154
|
+
graph.node("main", async (__state) => {
|
|
155
|
+
const __setupData = setupNode({
|
|
156
|
+
state: __state
|
|
157
|
+
});
|
|
158
|
+
const __stateStack = __state.ctx.stateStack;
|
|
159
|
+
const __stack = __setupData.stack;
|
|
160
|
+
const __step = __setupData.step;
|
|
161
|
+
const __self = __setupData.self;
|
|
162
|
+
const __threads = __setupData.threads;
|
|
163
|
+
const __ctx = __state.ctx;
|
|
164
|
+
const statelogClient = __ctx.statelogClient;
|
|
165
|
+
const __graph = __ctx.graph;
|
|
166
|
+
let __forked;
|
|
167
|
+
let __functionCompleted = false;
|
|
168
|
+
await callHook({
|
|
169
|
+
callbacks: __ctx.callbacks,
|
|
170
|
+
name: "onNodeStart",
|
|
171
|
+
data: {
|
|
172
|
+
nodeName: "main"
|
|
173
|
+
}
|
|
174
|
+
});
|
|
175
|
+
const runner = new Runner(__ctx, __stack, { nodeContext: true, state: __stack, moduleId: "lib/agents/policy/agent.agency", scopeName: "main" });
|
|
176
|
+
try {
|
|
177
|
+
await runner.step(0, async (runner2) => {
|
|
178
|
+
__stack.locals.cliArgs = await __call(args, {
|
|
179
|
+
type: "positional",
|
|
180
|
+
args: []
|
|
181
|
+
}, {
|
|
182
|
+
ctx: __ctx,
|
|
183
|
+
threads: __threads,
|
|
184
|
+
stateStack: __stateStack
|
|
185
|
+
});
|
|
186
|
+
if (hasInterrupts(__stack.locals.cliArgs)) {
|
|
187
|
+
await __ctx.pendingPromises.awaitAll();
|
|
188
|
+
runner2.halt({
|
|
189
|
+
...__state,
|
|
190
|
+
data: __stack.locals.cliArgs
|
|
191
|
+
});
|
|
192
|
+
return;
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
await runner.ifElse(1, [
|
|
196
|
+
{
|
|
197
|
+
condition: async () => __stack.locals.cliArgs.length < 2,
|
|
198
|
+
body: async (runner2) => {
|
|
199
|
+
await runner2.step(0, async (runner3) => {
|
|
200
|
+
const __funcResult = await __call(print, {
|
|
201
|
+
type: "positional",
|
|
202
|
+
args: [`Usage: agency policy gen <file>`]
|
|
203
|
+
}, {
|
|
204
|
+
ctx: __ctx,
|
|
205
|
+
threads: __threads,
|
|
206
|
+
stateStack: __stateStack
|
|
207
|
+
});
|
|
208
|
+
if (hasInterrupts(__funcResult)) {
|
|
209
|
+
await __ctx.pendingPromises.awaitAll();
|
|
210
|
+
runner3.halt({
|
|
211
|
+
...__state,
|
|
212
|
+
data: __funcResult
|
|
213
|
+
});
|
|
214
|
+
return;
|
|
215
|
+
}
|
|
216
|
+
});
|
|
217
|
+
await runner2.step(1, async (runner3) => {
|
|
218
|
+
__stateStack.pop();
|
|
219
|
+
__functionCompleted = true;
|
|
220
|
+
runner3.halt(goToNode("end", {
|
|
221
|
+
messages: __threads,
|
|
222
|
+
ctx: __ctx,
|
|
223
|
+
data: {}
|
|
224
|
+
}));
|
|
225
|
+
return;
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
]);
|
|
230
|
+
await runner.step(2, async (runner2) => {
|
|
231
|
+
__stack.locals.interruptKindsJson = __stack.locals.cliArgs[0];
|
|
232
|
+
});
|
|
233
|
+
await runner.step(3, async (runner2) => {
|
|
234
|
+
__stack.locals.outputPath = __stack.locals.cliArgs[1];
|
|
235
|
+
});
|
|
236
|
+
await runner.step(4, async (runner2) => {
|
|
237
|
+
__stack.locals.existingPolicyJson = ``;
|
|
238
|
+
});
|
|
239
|
+
await runner.ifElse(5, [
|
|
240
|
+
{
|
|
241
|
+
condition: async () => __stack.locals.cliArgs.length >= 3,
|
|
242
|
+
body: async (runner2) => {
|
|
243
|
+
await runner2.step(0, async (runner3) => {
|
|
244
|
+
__stack.locals.existingPolicyJson = __stack.locals.cliArgs[2];
|
|
245
|
+
});
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
]);
|
|
249
|
+
await runner.step(6, async (runner2) => {
|
|
250
|
+
__stack.locals.interruptKinds = await __call(parseJSON, {
|
|
251
|
+
type: "positional",
|
|
252
|
+
args: [__stack.locals.interruptKindsJson]
|
|
253
|
+
}, {
|
|
254
|
+
ctx: __ctx,
|
|
255
|
+
threads: __threads,
|
|
256
|
+
stateStack: __stateStack
|
|
257
|
+
});
|
|
258
|
+
if (hasInterrupts(__stack.locals.interruptKinds)) {
|
|
259
|
+
await __ctx.pendingPromises.awaitAll();
|
|
260
|
+
runner2.halt({
|
|
261
|
+
...__state,
|
|
262
|
+
data: __stack.locals.interruptKinds
|
|
263
|
+
});
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
await runner.step(7, async (runner2) => {
|
|
268
|
+
__stack.locals.existingPolicy = null;
|
|
269
|
+
});
|
|
270
|
+
await runner.ifElse(8, [
|
|
271
|
+
{
|
|
272
|
+
condition: async () => __stack.locals.existingPolicyJson !== ``,
|
|
273
|
+
body: async (runner2) => {
|
|
274
|
+
await runner2.step(0, async (runner3) => {
|
|
275
|
+
__stack.locals.existingPolicy = await __call(parseJSON, {
|
|
276
|
+
type: "positional",
|
|
277
|
+
args: [__stack.locals.existingPolicyJson]
|
|
278
|
+
}, {
|
|
279
|
+
ctx: __ctx,
|
|
280
|
+
threads: __threads,
|
|
281
|
+
stateStack: __stateStack
|
|
282
|
+
});
|
|
283
|
+
if (hasInterrupts(__stack.locals.existingPolicy)) {
|
|
284
|
+
await __ctx.pendingPromises.awaitAll();
|
|
285
|
+
runner3.halt({
|
|
286
|
+
...__state,
|
|
287
|
+
data: __stack.locals.existingPolicy
|
|
288
|
+
});
|
|
289
|
+
return;
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
]);
|
|
295
|
+
await runner.step(9, async (runner2) => {
|
|
296
|
+
__stack.locals.contextMessage = `This agent can produce the following interrupts:
|
|
297
|
+
`;
|
|
298
|
+
});
|
|
299
|
+
await runner.loop(10, __stack.locals.interruptKinds, async (kind, _, runner2) => {
|
|
300
|
+
await runner2.step(0, async (runner3) => {
|
|
301
|
+
__stack.locals.contextMessage = __stack.locals.contextMessage + `- ${kind}
|
|
302
|
+
`;
|
|
303
|
+
});
|
|
304
|
+
});
|
|
305
|
+
await runner.ifElse(11, [
|
|
306
|
+
{
|
|
307
|
+
condition: async () => __stack.locals.existingPolicy !== null,
|
|
308
|
+
body: async (runner2) => {
|
|
309
|
+
await runner2.step(0, async (runner3) => {
|
|
310
|
+
__stack.locals.contextMessage = __stack.locals.contextMessage + `
|
|
311
|
+
Current policy:
|
|
312
|
+
\`\`\`json
|
|
313
|
+
${await __call(printJSON, {
|
|
314
|
+
type: "positional",
|
|
315
|
+
args: [__stack.locals.existingPolicy]
|
|
316
|
+
}, {
|
|
317
|
+
ctx: __ctx,
|
|
318
|
+
threads: __threads,
|
|
319
|
+
stateStack: __stateStack
|
|
320
|
+
})}
|
|
321
|
+
\`\`\`
|
|
322
|
+
|
|
323
|
+
What would you like to change?
|
|
324
|
+
`;
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
], async (runner2) => {
|
|
329
|
+
await runner2.step(1, async (runner3) => {
|
|
330
|
+
__stack.locals.contextMessage = __stack.locals.contextMessage + `
|
|
331
|
+
What actions would you like to allow?`;
|
|
332
|
+
});
|
|
333
|
+
});
|
|
334
|
+
await runner.step(12, async (runner2) => {
|
|
335
|
+
const __funcResult = await __call(print, {
|
|
336
|
+
type: "positional",
|
|
337
|
+
args: [__stack.locals.contextMessage]
|
|
338
|
+
}, {
|
|
339
|
+
ctx: __ctx,
|
|
340
|
+
threads: __threads,
|
|
341
|
+
stateStack: __stateStack
|
|
342
|
+
});
|
|
343
|
+
if (hasInterrupts(__funcResult)) {
|
|
344
|
+
await __ctx.pendingPromises.awaitAll();
|
|
345
|
+
runner2.halt({
|
|
346
|
+
...__state,
|
|
347
|
+
data: __funcResult
|
|
348
|
+
});
|
|
349
|
+
return;
|
|
350
|
+
}
|
|
351
|
+
});
|
|
352
|
+
await runner.step(13, async (runner2) => {
|
|
353
|
+
__stack.locals.done = false;
|
|
354
|
+
});
|
|
355
|
+
await runner.step(14, async (runner2) => {
|
|
356
|
+
__stack.locals.policy = {};
|
|
357
|
+
});
|
|
358
|
+
await runner.step(15, async (runner2) => {
|
|
359
|
+
__stack.locals.conversationHistory = __stack.locals.contextMessage;
|
|
360
|
+
});
|
|
361
|
+
await runner.whileLoop(16, () => !__stack.locals.done, async (runner2) => {
|
|
362
|
+
await runner2.step(0, async (runner3) => {
|
|
363
|
+
__stack.locals.userInput = await __call(input, {
|
|
364
|
+
type: "positional",
|
|
365
|
+
args: [`> `]
|
|
366
|
+
}, {
|
|
367
|
+
ctx: __ctx,
|
|
368
|
+
threads: __threads,
|
|
369
|
+
stateStack: __stateStack
|
|
370
|
+
});
|
|
371
|
+
if (hasInterrupts(__stack.locals.userInput)) {
|
|
372
|
+
await __ctx.pendingPromises.awaitAll();
|
|
373
|
+
runner3.halt({
|
|
374
|
+
...__state,
|
|
375
|
+
data: __stack.locals.userInput
|
|
376
|
+
});
|
|
377
|
+
return;
|
|
378
|
+
}
|
|
379
|
+
});
|
|
380
|
+
await runner2.step(1, async (runner3) => {
|
|
381
|
+
__stack.locals.conversationHistory = __stack.locals.conversationHistory + `
|
|
382
|
+
User: ${__stack.locals.userInput}`;
|
|
383
|
+
});
|
|
384
|
+
await runner2.thread(2, __threads, "create", async (runner3) => {
|
|
385
|
+
await runner3.step(0, async (runner4) => {
|
|
386
|
+
const __funcResult = __threads.active().push(smoltalk.systemMessage(__ctx.globals.get("lib/agents/policy/agent.agency", "systemPrompt")));
|
|
387
|
+
if (hasInterrupts(__funcResult)) {
|
|
388
|
+
await __ctx.pendingPromises.awaitAll();
|
|
389
|
+
runner4.halt({
|
|
390
|
+
...__state,
|
|
391
|
+
data: __funcResult
|
|
392
|
+
});
|
|
393
|
+
return;
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
await runner3.step(1, async (runner4) => {
|
|
397
|
+
__self.__removedTools = __self.__removedTools || [];
|
|
398
|
+
__stack.locals.step = await runPrompt({
|
|
399
|
+
ctx: __ctx,
|
|
400
|
+
prompt: `
|
|
401
|
+
${__stack.locals.conversationHistory}
|
|
402
|
+
|
|
403
|
+
Current policy: ${await __call(printJSON, {
|
|
404
|
+
type: "positional",
|
|
405
|
+
args: [__stack.locals.policy]
|
|
406
|
+
}, {
|
|
407
|
+
ctx: __ctx,
|
|
408
|
+
threads: __threads,
|
|
409
|
+
stateStack: __stateStack
|
|
410
|
+
})}
|
|
411
|
+
|
|
412
|
+
Decide the next step. If the user is describing what they want, build or update the policy and use showPolicy. If the user approves the shown policy, use writePolicy. If you need clarification, use askQuestion.
|
|
413
|
+
`,
|
|
414
|
+
messages: __threads.getOrCreateActive(),
|
|
415
|
+
responseFormat: z.object({
|
|
416
|
+
response: NextStep
|
|
417
|
+
}),
|
|
418
|
+
clientConfig: {},
|
|
419
|
+
maxToolCallRounds: 10,
|
|
420
|
+
stateStack: __stateStack,
|
|
421
|
+
removedTools: __self.__removedTools,
|
|
422
|
+
checkpointInfo: runner4.getCheckpointInfo()
|
|
423
|
+
});
|
|
424
|
+
if (hasInterrupts(__stack.locals.step)) {
|
|
425
|
+
await __ctx.pendingPromises.awaitAll();
|
|
426
|
+
runner4.halt({
|
|
427
|
+
messages: __threads,
|
|
428
|
+
data: __stack.locals.step
|
|
429
|
+
});
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
});
|
|
433
|
+
});
|
|
434
|
+
await runner2.ifElse(3, [
|
|
435
|
+
{
|
|
436
|
+
condition: async () => __stack.locals.step.type === `showPolicy`,
|
|
437
|
+
body: async (runner3) => {
|
|
438
|
+
await runner3.step(0, async (runner4) => {
|
|
439
|
+
__stack.locals.policy = __stack.locals.step.policy;
|
|
440
|
+
});
|
|
441
|
+
await runner3.step(1, async (runner4) => {
|
|
442
|
+
__stack.locals.policyStr = await __call(printJSON, {
|
|
443
|
+
type: "positional",
|
|
444
|
+
args: [__stack.locals.policy]
|
|
445
|
+
}, {
|
|
446
|
+
ctx: __ctx,
|
|
447
|
+
threads: __threads,
|
|
448
|
+
stateStack: __stateStack
|
|
449
|
+
});
|
|
450
|
+
if (hasInterrupts(__stack.locals.policyStr)) {
|
|
451
|
+
await __ctx.pendingPromises.awaitAll();
|
|
452
|
+
runner4.halt({
|
|
453
|
+
...__state,
|
|
454
|
+
data: __stack.locals.policyStr
|
|
455
|
+
});
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
});
|
|
459
|
+
await runner3.step(2, async (runner4) => {
|
|
460
|
+
const __funcResult = await __call(print, {
|
|
461
|
+
type: "positional",
|
|
462
|
+
args: [`
|
|
463
|
+
Proposed policy:
|
|
464
|
+
\`\`\`json
|
|
465
|
+
${__stack.locals.policyStr}
|
|
466
|
+
\`\`\`
|
|
467
|
+
`]
|
|
468
|
+
}, {
|
|
469
|
+
ctx: __ctx,
|
|
470
|
+
threads: __threads,
|
|
471
|
+
stateStack: __stateStack
|
|
472
|
+
});
|
|
473
|
+
if (hasInterrupts(__funcResult)) {
|
|
474
|
+
await __ctx.pendingPromises.awaitAll();
|
|
475
|
+
runner4.halt({
|
|
476
|
+
...__state,
|
|
477
|
+
data: __funcResult
|
|
478
|
+
});
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
});
|
|
482
|
+
await runner3.step(3, async (runner4) => {
|
|
483
|
+
const __funcResult = await __call(print, {
|
|
484
|
+
type: "positional",
|
|
485
|
+
args: [`Does this look right? (say 'yes' to save, or describe changes)`]
|
|
486
|
+
}, {
|
|
487
|
+
ctx: __ctx,
|
|
488
|
+
threads: __threads,
|
|
489
|
+
stateStack: __stateStack
|
|
490
|
+
});
|
|
491
|
+
if (hasInterrupts(__funcResult)) {
|
|
492
|
+
await __ctx.pendingPromises.awaitAll();
|
|
493
|
+
runner4.halt({
|
|
494
|
+
...__state,
|
|
495
|
+
data: __funcResult
|
|
496
|
+
});
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
});
|
|
500
|
+
await runner3.step(4, async (runner4) => {
|
|
501
|
+
__stack.locals.conversationHistory = __stack.locals.conversationHistory + `
|
|
502
|
+
Assistant: Here is the proposed policy:
|
|
503
|
+
${__stack.locals.policyStr}
|
|
504
|
+
Does this look right?`;
|
|
505
|
+
});
|
|
506
|
+
}
|
|
507
|
+
},
|
|
508
|
+
{
|
|
509
|
+
condition: async () => __stack.locals.step.type === `writePolicy`,
|
|
510
|
+
body: async (runner3) => {
|
|
511
|
+
await runner3.step(5, async (runner4) => {
|
|
512
|
+
__stack.locals.policy = __stack.locals.step.policy;
|
|
513
|
+
});
|
|
514
|
+
await runner3.step(6, async (runner4) => {
|
|
515
|
+
__self.__retryable = false;
|
|
516
|
+
const __funcResult = await __call(writePolicyFile, {
|
|
517
|
+
type: "positional",
|
|
518
|
+
args: [__stack.locals.outputPath, __stack.locals.policy]
|
|
519
|
+
}, {
|
|
520
|
+
ctx: __ctx,
|
|
521
|
+
threads: __threads,
|
|
522
|
+
stateStack: __stateStack
|
|
523
|
+
});
|
|
524
|
+
if (hasInterrupts(__funcResult)) {
|
|
525
|
+
await __ctx.pendingPromises.awaitAll();
|
|
526
|
+
runner4.halt({
|
|
527
|
+
...__state,
|
|
528
|
+
data: __funcResult
|
|
529
|
+
});
|
|
530
|
+
return;
|
|
531
|
+
}
|
|
532
|
+
});
|
|
533
|
+
await runner3.step(7, async (runner4) => {
|
|
534
|
+
const __funcResult = await __call(print, {
|
|
535
|
+
type: "positional",
|
|
536
|
+
args: [`
|
|
537
|
+
Policy written to ${__stack.locals.outputPath}`]
|
|
538
|
+
}, {
|
|
539
|
+
ctx: __ctx,
|
|
540
|
+
threads: __threads,
|
|
541
|
+
stateStack: __stateStack
|
|
542
|
+
});
|
|
543
|
+
if (hasInterrupts(__funcResult)) {
|
|
544
|
+
await __ctx.pendingPromises.awaitAll();
|
|
545
|
+
runner4.halt({
|
|
546
|
+
...__state,
|
|
547
|
+
data: __funcResult
|
|
548
|
+
});
|
|
549
|
+
return;
|
|
550
|
+
}
|
|
551
|
+
});
|
|
552
|
+
await runner3.step(8, async (runner4) => {
|
|
553
|
+
__stack.locals.done = true;
|
|
554
|
+
});
|
|
555
|
+
}
|
|
556
|
+
},
|
|
557
|
+
{
|
|
558
|
+
condition: async () => __stack.locals.step.type === `askQuestion`,
|
|
559
|
+
body: async (runner3) => {
|
|
560
|
+
await runner3.step(9, async (runner4) => {
|
|
561
|
+
const __funcResult = await __call(print, {
|
|
562
|
+
type: "positional",
|
|
563
|
+
args: [__stack.locals.step.question]
|
|
564
|
+
}, {
|
|
565
|
+
ctx: __ctx,
|
|
566
|
+
threads: __threads,
|
|
567
|
+
stateStack: __stateStack
|
|
568
|
+
});
|
|
569
|
+
if (hasInterrupts(__funcResult)) {
|
|
570
|
+
await __ctx.pendingPromises.awaitAll();
|
|
571
|
+
runner4.halt({
|
|
572
|
+
...__state,
|
|
573
|
+
data: __funcResult
|
|
574
|
+
});
|
|
575
|
+
return;
|
|
576
|
+
}
|
|
577
|
+
});
|
|
578
|
+
await runner3.step(10, async (runner4) => {
|
|
579
|
+
__stack.locals.conversationHistory = __stack.locals.conversationHistory + `
|
|
580
|
+
Assistant: ${__stack.locals.step.question}`;
|
|
581
|
+
});
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
]);
|
|
585
|
+
await runner2.step(4, async (runner3) => {
|
|
586
|
+
__self.__retryable = false;
|
|
587
|
+
});
|
|
588
|
+
});
|
|
589
|
+
await runner.step(17, async (runner2) => {
|
|
590
|
+
__self.__retryable = false;
|
|
591
|
+
});
|
|
592
|
+
await runner.step(18, async (runner2) => {
|
|
593
|
+
__stateStack.pop();
|
|
594
|
+
__functionCompleted = true;
|
|
595
|
+
runner2.halt(goToNode("end", {
|
|
596
|
+
messages: __threads,
|
|
597
|
+
ctx: __ctx,
|
|
598
|
+
data: {}
|
|
599
|
+
}));
|
|
600
|
+
return;
|
|
601
|
+
});
|
|
602
|
+
if (runner.halted) return runner.haltResult;
|
|
603
|
+
await callHook({
|
|
604
|
+
callbacks: __ctx.callbacks,
|
|
605
|
+
name: "onNodeEnd",
|
|
606
|
+
data: {
|
|
607
|
+
nodeName: "main",
|
|
608
|
+
data: void 0
|
|
609
|
+
}
|
|
610
|
+
});
|
|
611
|
+
return {
|
|
612
|
+
messages: __threads,
|
|
613
|
+
data: void 0
|
|
614
|
+
};
|
|
615
|
+
} catch (__error) {
|
|
616
|
+
if (__error instanceof RestoreSignal) {
|
|
617
|
+
throw __error;
|
|
618
|
+
}
|
|
619
|
+
console.error(`
|
|
620
|
+
Agent crashed: ${__error.message}`);
|
|
621
|
+
console.error(__error.stack);
|
|
622
|
+
return {
|
|
623
|
+
messages: __threads,
|
|
624
|
+
data: failure(__error instanceof Error ? __error.message : String(__error), { functionName: "main" })
|
|
625
|
+
};
|
|
626
|
+
}
|
|
627
|
+
});
|
|
628
|
+
graph.node("end", async (__state) => {
|
|
629
|
+
const __setupData = setupNode({
|
|
630
|
+
state: __state
|
|
631
|
+
});
|
|
632
|
+
const __stateStack = __state.ctx.stateStack;
|
|
633
|
+
const __stack = __setupData.stack;
|
|
634
|
+
const __step = __setupData.step;
|
|
635
|
+
const __self = __setupData.self;
|
|
636
|
+
const __threads = __setupData.threads;
|
|
637
|
+
const __ctx = __state.ctx;
|
|
638
|
+
const statelogClient = __ctx.statelogClient;
|
|
639
|
+
const __graph = __ctx.graph;
|
|
640
|
+
let __forked;
|
|
641
|
+
let __functionCompleted = false;
|
|
642
|
+
await callHook({
|
|
643
|
+
callbacks: __ctx.callbacks,
|
|
644
|
+
name: "onNodeStart",
|
|
645
|
+
data: {
|
|
646
|
+
nodeName: "end"
|
|
647
|
+
}
|
|
648
|
+
});
|
|
649
|
+
const runner = new Runner(__ctx, __stack, { nodeContext: true, state: __stack, moduleId: "lib/agents/policy/agent.agency", scopeName: "end" });
|
|
650
|
+
try {
|
|
651
|
+
if (runner.halted) return runner.haltResult;
|
|
652
|
+
await callHook({
|
|
653
|
+
callbacks: __ctx.callbacks,
|
|
654
|
+
name: "onNodeEnd",
|
|
655
|
+
data: {
|
|
656
|
+
nodeName: "end",
|
|
657
|
+
data: void 0
|
|
658
|
+
}
|
|
659
|
+
});
|
|
660
|
+
return {
|
|
661
|
+
messages: __threads,
|
|
662
|
+
data: void 0
|
|
663
|
+
};
|
|
664
|
+
} catch (__error) {
|
|
665
|
+
if (__error instanceof RestoreSignal) {
|
|
666
|
+
throw __error;
|
|
667
|
+
}
|
|
668
|
+
console.error(`
|
|
669
|
+
Agent crashed: ${__error.message}`);
|
|
670
|
+
console.error(__error.stack);
|
|
671
|
+
return {
|
|
672
|
+
messages: __threads,
|
|
673
|
+
data: failure(__error instanceof Error ? __error.message : String(__error), { functionName: "end" })
|
|
674
|
+
};
|
|
675
|
+
}
|
|
676
|
+
});
|
|
677
|
+
graph.conditionalEdge("main", ["end", "end"]);
|
|
678
|
+
async function main({ messages, callbacks } = {}) {
|
|
679
|
+
return runNode({
|
|
680
|
+
ctx: __globalCtx,
|
|
681
|
+
nodeName: "main",
|
|
682
|
+
data: {},
|
|
683
|
+
messages,
|
|
684
|
+
callbacks,
|
|
685
|
+
initializeGlobals: __initializeGlobals
|
|
686
|
+
});
|
|
687
|
+
}
|
|
688
|
+
const __mainNodeParams = [];
|
|
689
|
+
async function end({ messages, callbacks } = {}) {
|
|
690
|
+
return runNode({
|
|
691
|
+
ctx: __globalCtx,
|
|
692
|
+
nodeName: "end",
|
|
693
|
+
data: {},
|
|
694
|
+
messages,
|
|
695
|
+
callbacks,
|
|
696
|
+
initializeGlobals: __initializeGlobals
|
|
697
|
+
});
|
|
698
|
+
}
|
|
699
|
+
const __endNodeParams = [];
|
|
700
|
+
if (__process.argv[1] === fileURLToPath(import.meta.url)) {
|
|
701
|
+
try {
|
|
702
|
+
const initialState = {
|
|
703
|
+
messages: new ThreadStore(),
|
|
704
|
+
data: {}
|
|
705
|
+
};
|
|
706
|
+
await main(initialState);
|
|
707
|
+
} catch (__error) {
|
|
708
|
+
console.error(`
|
|
709
|
+
Agent crashed: ${__error.message}`);
|
|
710
|
+
throw __error;
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
var stdin_default = graph;
|
|
714
|
+
const __sourceMap = { "lib/agents/policy/agent.agency:main": { "0": { "line": 8, "col": 2 }, "1": { "line": 9, "col": 2 }, "2": { "line": 13, "col": 2 }, "3": { "line": 14, "col": 2 }, "4": { "line": 15, "col": 2 }, "5": { "line": 16, "col": 2 }, "6": { "line": 20, "col": 2 }, "7": { "line": 21, "col": 2 }, "8": { "line": 22, "col": 2 }, "9": { "line": 26, "col": 2 }, "10": { "line": 27, "col": 2 }, "11": { "line": 31, "col": 2 }, "12": { "line": 39, "col": 2 }, "13": { "line": 41, "col": 2 }, "14": { "line": 42, "col": 2 }, "15": { "line": 43, "col": 2 }, "16": { "line": 44, "col": 2 }, "18": { "line": 71, "col": 2 }, "1.0": { "line": 10, "col": 4 }, "1.1": { "line": 11, "col": 4 }, "5.0": { "line": 17, "col": 4 }, "8.0": { "line": 23, "col": 4 }, "10.0": { "line": 28, "col": 4 }, "11.0": { "line": 32, "col": 4 }, "11.1": { "line": 36, "col": 4 }, "16.0": { "line": 45, "col": 4 }, "16.1": { "line": 46, "col": 4 }, "16.2.0": { "line": 49, "col": 6 }, "16.2.1": { "line": 50, "col": 6 }, "16.2": { "line": 48, "col": 4 }, "16.3.0": { "line": 56, "col": 6 }, "16.3.1": { "line": 57, "col": 6 }, "16.3.2": { "line": 58, "col": 6 }, "16.3.3": { "line": 59, "col": 6 }, "16.3.4": { "line": 60, "col": 6 }, "16.3.5": { "line": 62, "col": 6 }, "16.3.6": { "line": 63, "col": 6 }, "16.3.7": { "line": 64, "col": 6 }, "16.3.8": { "line": 65, "col": 6 }, "16.3.9": { "line": 67, "col": 6 }, "16.3.10": { "line": 68, "col": 6 }, "16.3": { "line": 55, "col": 4 } }, "lib/agents/policy/agent.agency:end": {} };
|
|
715
|
+
export {
|
|
716
|
+
__endNodeParams,
|
|
717
|
+
__getCheckpoints,
|
|
718
|
+
__mainNodeParams,
|
|
719
|
+
__setDebugger,
|
|
720
|
+
__setLLMClient,
|
|
721
|
+
__setTraceWriter,
|
|
722
|
+
__sourceMap,
|
|
723
|
+
__toolRegistry,
|
|
724
|
+
approve,
|
|
725
|
+
stdin_default as default,
|
|
726
|
+
end,
|
|
727
|
+
hasInterrupts,
|
|
728
|
+
interrupt,
|
|
729
|
+
isDebugger,
|
|
730
|
+
isInterrupt,
|
|
731
|
+
main,
|
|
732
|
+
readSkill,
|
|
733
|
+
reject,
|
|
734
|
+
respondToInterrupts,
|
|
735
|
+
rewindFrom
|
|
736
|
+
};
|