agency-lang 0.0.83 → 0.0.84
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.js +934 -0
- package/dist/lib/agents/agency-agent/subagents/code.js +261 -0
- package/dist/lib/agents/agency-agent/subagents/plan.js +353 -0
- package/dist/lib/agents/agency-agent/subagents/task.js +250 -0
- package/dist/lib/backends/agencyGenerator.js +3 -2
- package/dist/lib/backends/typescriptBuilder.js +32 -11
- package/dist/lib/cli/test.js +1 -1
- package/dist/lib/ir/prettyPrint.js +2 -1
- package/dist/lib/ir/prettyPrint.test.js +1 -1
- package/dist/lib/ir/tsIR.d.ts +1 -1
- package/dist/lib/parser.js +2 -2
- package/dist/lib/parsers/assignment.test.js +41 -1
- package/dist/lib/parsers/function.d.ts +1 -0
- package/dist/lib/parsers/function.js +4 -0
- package/dist/lib/preprocessors/typescriptPreprocessor.js +14 -6
- package/dist/lib/runtime/interrupts.js +17 -22
- package/dist/lib/runtime/node.d.ts +2 -1
- package/dist/lib/runtime/node.js +12 -8
- package/dist/lib/runtime/prompt.js +0 -2
- package/dist/lib/runtime/state/context.d.ts +2 -0
- package/dist/lib/runtime/state/context.js +18 -0
- package/dist/lib/simplemachine/graph.d.ts +3 -3
- package/dist/lib/simplemachine/graph.js +2 -7
- package/dist/lib/templates/backends/typescriptGenerator/interruptAssignment.d.ts +1 -1
- package/dist/lib/templates/backends/typescriptGenerator/interruptAssignment.js +0 -1
- package/dist/lib/templates/backends/typescriptGenerator/interruptReturn.d.ts +1 -1
- package/dist/lib/templates/backends/typescriptGenerator/interruptReturn.js +0 -1
- package/dist/lib/types.d.ts +5 -1
- package/package.json +3 -2
- package/dist/test.d.ts +0 -11
- package/dist/test.js +0 -7
|
@@ -0,0 +1,934 @@
|
|
|
1
|
+
import { addTask, __addTaskTool, __addTaskToolParams, listTasks, __listTasksTool, __listTasksToolParams, markTaskDone, __markTaskDoneTool, __markTaskDoneToolParams } from "./subagents/task.js";
|
|
2
|
+
import { newPlan, __newPlanTool, __newPlanToolParams, getCurrentPlan, __getCurrentPlanTool, __getCurrentPlanToolParams, listPlans, __listPlansTool, __listPlansToolParams, updateCurrentPlan, __updateCurrentPlanTool, __updateCurrentPlanToolParams, updateGoal, __updateGoalTool, __updateGoalToolParams, updateActions, __updateActionsTool, __updateActionsToolParams } from "./subagents/plan.js";
|
|
3
|
+
import { writeCode, __writeCodeTool, __writeCodeToolParams, appendCode, __appendCodeTool, __appendCodeToolParams, readCode, __readCodeTool, __readCodeToolParams } from "./subagents/code.js";
|
|
4
|
+
import { syntaxHighlight } from "../../utils/agentUtils.js";
|
|
5
|
+
import { fileURLToPath } from "url";
|
|
6
|
+
import process from "process";
|
|
7
|
+
import { readFileSync, writeFileSync } from "fs";
|
|
8
|
+
import { z } from "zod";
|
|
9
|
+
import { goToNode, color, nanoid } from "agency-lang";
|
|
10
|
+
import * as smoltalk from "agency-lang";
|
|
11
|
+
import path from "path";
|
|
12
|
+
import {
|
|
13
|
+
RuntimeContext, MessageThread, ThreadStore,
|
|
14
|
+
setupNode, setupFunction, runNode, runPrompt, callHook,
|
|
15
|
+
interrupt, isInterrupt,
|
|
16
|
+
respondToInterrupt as _respondToInterrupt,
|
|
17
|
+
approveInterrupt as _approveInterrupt,
|
|
18
|
+
rejectInterrupt as _rejectInterrupt,
|
|
19
|
+
resolveInterrupt as _resolveInterrupt,
|
|
20
|
+
modifyInterrupt as _modifyInterrupt,
|
|
21
|
+
resumeFromState as _resumeFromState,
|
|
22
|
+
deepClone as __deepClone,
|
|
23
|
+
not, eq, neq, lt, lte, gt, gte, and, or,
|
|
24
|
+
head, tail, empty,
|
|
25
|
+
builtinFetch as _builtinFetch,
|
|
26
|
+
builtinFetchJSON as _builtinFetchJSON,
|
|
27
|
+
builtinInput as _builtinInput,
|
|
28
|
+
builtinRead as _builtinReadRaw,
|
|
29
|
+
builtinWrite as _builtinWriteRaw,
|
|
30
|
+
builtinReadImage as _builtinReadImageRaw,
|
|
31
|
+
builtinSleep as _builtinSleep,
|
|
32
|
+
builtinRound as _builtinRound,
|
|
33
|
+
printJSON as _printJSON,
|
|
34
|
+
print as _print,
|
|
35
|
+
readSkill as _readSkillRaw,
|
|
36
|
+
readSkillTool as __readSkillTool,
|
|
37
|
+
readSkillToolParams as __readSkillToolParams,
|
|
38
|
+
printTool as __printTool,
|
|
39
|
+
printToolParams as __printToolParams,
|
|
40
|
+
printJSONTool as __printJSONTool,
|
|
41
|
+
printJSONToolParams as __printJSONToolParams,
|
|
42
|
+
inputTool as __inputTool,
|
|
43
|
+
inputToolParams as __inputToolParams,
|
|
44
|
+
readTool as __readTool,
|
|
45
|
+
readToolParams as __readToolParams,
|
|
46
|
+
readImageTool as __readImageTool,
|
|
47
|
+
readImageToolParams as __readImageToolParams,
|
|
48
|
+
writeTool as __writeTool,
|
|
49
|
+
writeToolParams as __writeToolParams,
|
|
50
|
+
fetchTool as __fetchTool,
|
|
51
|
+
fetchToolParams as __fetchToolParams,
|
|
52
|
+
fetchJSONTool as __fetchJSONTool,
|
|
53
|
+
fetchJSONToolParams as __fetchJSONToolParams,
|
|
54
|
+
fetchJsonTool as __fetchJsonTool,
|
|
55
|
+
fetchJsonToolParams as __fetchJsonToolParams,
|
|
56
|
+
sleepTool as __sleepTool,
|
|
57
|
+
sleepToolParams as __sleepToolParams,
|
|
58
|
+
roundTool as __roundTool,
|
|
59
|
+
roundToolParams as __roundToolParams,
|
|
60
|
+
} from "agency-lang/runtime";
|
|
61
|
+
|
|
62
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
63
|
+
const __dirname = path.dirname(__filename);
|
|
64
|
+
const __cwd = process.cwd();
|
|
65
|
+
|
|
66
|
+
const __globalCtx = new RuntimeContext({
|
|
67
|
+
statelogConfig: {
|
|
68
|
+
host: "https://agency-lang.com",
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
apiKey: process.env.STATELOG_API_KEY || "",
|
|
72
|
+
|
|
73
|
+
projectId: "agency-lang",
|
|
74
|
+
debugMode: false,
|
|
75
|
+
},
|
|
76
|
+
smoltalkDefaults: {
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
openAiApiKey: process.env.OPENAI_API_KEY || "",
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
googleApiKey: process.env.GEMINI_API_KEY || "",
|
|
84
|
+
|
|
85
|
+
model: "gpt-4o-mini",
|
|
86
|
+
logLevel: "warn",
|
|
87
|
+
statelog: {
|
|
88
|
+
host: "https://agency-lang.com",
|
|
89
|
+
projectId: "smoltalk",
|
|
90
|
+
apiKey: process.env.STATELOG_SMOLTALK_API_KEY || "",
|
|
91
|
+
traceId: nanoid()
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
dirname: __dirname,
|
|
95
|
+
});
|
|
96
|
+
const graph = __globalCtx.graph;
|
|
97
|
+
|
|
98
|
+
// Path-dependent builtin wrappers
|
|
99
|
+
function _builtinRead(filename) {
|
|
100
|
+
return _builtinReadRaw({ filename, dirname: __dirname });
|
|
101
|
+
}
|
|
102
|
+
function _builtinWrite(filename, content) {
|
|
103
|
+
return _builtinWriteRaw({ filename, content, dirname: __dirname });
|
|
104
|
+
}
|
|
105
|
+
function _builtinReadImage(filename) {
|
|
106
|
+
return _builtinReadImageRaw({ filename, dirname: __dirname });
|
|
107
|
+
}
|
|
108
|
+
export function readSkill({filepath}) {
|
|
109
|
+
return _readSkillRaw({ filepath, dirname: __dirname });
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
// Interrupt re-exports bound to this module's context
|
|
113
|
+
export { interrupt, isInterrupt };
|
|
114
|
+
export const respondToInterrupt = (i, r, m) => _respondToInterrupt({ ctx: __globalCtx, interrupt: i, interruptResponse: r, metadata: m });
|
|
115
|
+
export const approveInterrupt = (i, m) => _approveInterrupt({ ctx: __globalCtx, interrupt: i, metadata: m });
|
|
116
|
+
export const rejectInterrupt = (i, m) => _rejectInterrupt({ ctx: __globalCtx, interrupt: i, metadata: m });
|
|
117
|
+
export const modifyInterrupt = (i, a, m) => _modifyInterrupt({ ctx: __globalCtx, interrupt: i, newArguments: a, metadata: m });
|
|
118
|
+
export const resolveInterrupt = (i, v, m) => _resolveInterrupt({ ctx: __globalCtx, interrupt: i, value: v, metadata: m });
|
|
119
|
+
export const __printCodeTool = {
|
|
120
|
+
name: "printCode",
|
|
121
|
+
description: `Use this tool to print code to the terminal with syntax highlighting.
|
|
122
|
+
Use this to print any generated code you want the user to look at.`,
|
|
123
|
+
schema: z.object({"code": z.string(), })
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
export const __printCodeToolParams = ["code"];
|
|
127
|
+
export const __writeCodeWithConfirmTool = {
|
|
128
|
+
name: "writeCodeWithConfirm",
|
|
129
|
+
description: `Use this tool to write code to a file to the filesystem. The filename should include the path and extension (e.g., 'lib/agents/myAgent.agency').`,
|
|
130
|
+
schema: z.object({"filename": z.string(), "content": z.string(), })
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
export const __writeCodeWithConfirmToolParams = ["filename","content"];
|
|
134
|
+
// todo allow this
|
|
135
|
+
// import { Plan } from "./subagents/plan.agency"
|
|
136
|
+
__globalCtx.stateStack.globals.strategy = {"type": `race`, "params": {"strategies": [{"type": `fallback`, "params": {"strategies": [`gemini-2.5-flash`, `gemini-2.5-pro`], "config": {"fallbackOn": [`error`]}}}, {"type": `fallback`, "params": {"strategies": [`gemini-2.5-flash-lite`, `gemini-2.5-pro`], "config": {"fallbackOn": [`error`]}}}]}};
|
|
137
|
+
__globalCtx.stateStack.globals.config = {"strategy": __globalCtx.stateStack.globals.strategy, "responseFormatOptions": {"strict": true, "numRetries": 2, "allowExtraKeys": true}};
|
|
138
|
+
|
|
139
|
+
export async function printCode(code, __state=undefined) {
|
|
140
|
+
const { stack: __stack, step: __step, self: __self, threads: __threads } =
|
|
141
|
+
setupFunction({ state: __state });
|
|
142
|
+
|
|
143
|
+
// __state will be undefined if this function is
|
|
144
|
+
// being called as a tool by an llm
|
|
145
|
+
const __ctx = __state?.ctx || __globalCtx;
|
|
146
|
+
const statelogClient = __ctx.statelogClient;
|
|
147
|
+
const __graph = __ctx.graph;
|
|
148
|
+
const __funcStartTime = performance.now();
|
|
149
|
+
await callHook({ callbacks: __ctx.callbacks, name: "onFunctionStart", data: { functionName: "printCode", args: { code }, isBuiltin: false } });
|
|
150
|
+
|
|
151
|
+
// put all args on the state stack
|
|
152
|
+
__stack.args["code"] = code;
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
if (__step <= 0) {
|
|
156
|
+
|
|
157
|
+
__stack.step++;
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
if (__step <= 1) {
|
|
162
|
+
await _print(syntaxHighlight(__stack.args.code, `ts`));
|
|
163
|
+
__stack.step++;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
|
|
167
|
+
if (__step <= 2) {
|
|
168
|
+
__ctx.stateStack.pop();
|
|
169
|
+
return `printed code successfully`
|
|
170
|
+
__stack.step++;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
await callHook({ callbacks: __ctx.callbacks, name: "onFunctionEnd", data: { functionName: "printCode", timeTaken: performance.now() - __funcStartTime } });
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
export async function writeCodeWithConfirm(filename, content, __state=undefined) {
|
|
178
|
+
const { stack: __stack, step: __step, self: __self, threads: __threads } =
|
|
179
|
+
setupFunction({ state: __state });
|
|
180
|
+
|
|
181
|
+
// __state will be undefined if this function is
|
|
182
|
+
// being called as a tool by an llm
|
|
183
|
+
const __ctx = __state?.ctx || __globalCtx;
|
|
184
|
+
const statelogClient = __ctx.statelogClient;
|
|
185
|
+
const __graph = __ctx.graph;
|
|
186
|
+
const __funcStartTime = performance.now();
|
|
187
|
+
await callHook({ callbacks: __ctx.callbacks, name: "onFunctionStart", data: { functionName: "writeCodeWithConfirm", args: { filename, content }, isBuiltin: false } });
|
|
188
|
+
|
|
189
|
+
// put all args on the state stack
|
|
190
|
+
__stack.args["filename"] = filename;
|
|
191
|
+
__stack.args["content"] = content;
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
if (__step <= 0) {
|
|
195
|
+
|
|
196
|
+
__stack.step++;
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
if (__step <= 1) {
|
|
201
|
+
await _print(color.yellow());
|
|
202
|
+
__stack.step++;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
|
|
206
|
+
if (__step <= 2) {
|
|
207
|
+
__stack.locals.message = `\nYou're about to write to the file ${__stack.args.filename} with the following content\n\n`;
|
|
208
|
+
__stack.step++;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
|
|
212
|
+
if (__step <= 3) {
|
|
213
|
+
// Remember this will be called both in a tool call context
|
|
214
|
+
// and when the user is simply calling a function.
|
|
215
|
+
|
|
216
|
+
if (__state.interruptData?.interruptResponse?.type === "approve") {
|
|
217
|
+
// approved, clear interrupt response and continue execution
|
|
218
|
+
__state.interruptData.interruptResponse = null;
|
|
219
|
+
} else if (__state.interruptData?.interruptResponse?.type === "reject" && !__state.isToolCall) {
|
|
220
|
+
// rejected, clear interrupt response and return early
|
|
221
|
+
// tool calls will instead tell the llm that the call was rejected
|
|
222
|
+
__state.interruptData.interruptResponse = null;
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
__ctx.stateStack.pop();
|
|
226
|
+
return null;
|
|
227
|
+
|
|
228
|
+
} else if (__state.interruptData?.interruptResponse?.type === "modify") {
|
|
229
|
+
if (__state.isToolCall) {
|
|
230
|
+
// continue, args will get modified in the tool call handler
|
|
231
|
+
} else {
|
|
232
|
+
throw new Error("Interrupt response of type 'modify' is not supported outside of tool calls yet.");
|
|
233
|
+
}
|
|
234
|
+
} else if (__state.interruptData?.interruptResponse?.type === "resolve") {
|
|
235
|
+
console.log(JSON.stringify(__state.interruptData, null, 2));
|
|
236
|
+
throw new Error("Interrupt response of type 'resolve' cannot be returned from an interrupt call. It can only be assigned to a variable.");
|
|
237
|
+
const __resolvedValue = __state.interruptData.interruptResponse.value;
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
__ctx.stateStack.pop();
|
|
241
|
+
return __resolvedValue;
|
|
242
|
+
|
|
243
|
+
} else {
|
|
244
|
+
const __interruptResult = interrupt({"tool": `writeCodeWithConfirm`, "message": __stack.locals.message, "content": __stack.args.content});
|
|
245
|
+
__ctx.stateStack.nodesTraversed = __graph.getNodesTraversed();
|
|
246
|
+
__interruptResult.state = __ctx.stateStack.toJSON();
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
return __interruptResult;
|
|
250
|
+
|
|
251
|
+
}
|
|
252
|
+
__stack.step++;
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
|
|
256
|
+
if (__step <= 4) {
|
|
257
|
+
await _builtinWrite(__stack.args.filename, __stack.args.content);
|
|
258
|
+
__stack.step++;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
await callHook({ callbacks: __ctx.callbacks, name: "onFunctionEnd", data: { functionName: "writeCodeWithConfirm", timeTaken: performance.now() - __funcStartTime } });
|
|
263
|
+
}
|
|
264
|
+
__globalCtx.stateStack.globals.systemPrompt = await await _builtinRead(`./prompts/system.md`);
|
|
265
|
+
|
|
266
|
+
__globalCtx.stateStack.globals.planPrompt = await await _builtinRead(`./prompts/plan.md`);
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
graph.node("main", async (__state) => {
|
|
270
|
+
const { stack: __stack, step: __step, self: __self, threads: __threads } =
|
|
271
|
+
setupNode({ state: __state });
|
|
272
|
+
const __ctx = __state.ctx;
|
|
273
|
+
const statelogClient = __ctx.statelogClient;
|
|
274
|
+
const __graph = __ctx.graph;
|
|
275
|
+
await callHook({ callbacks: __ctx.callbacks, name: "onNodeStart", data: { nodeName: "main" } });
|
|
276
|
+
|
|
277
|
+
if (__state.isResume) {
|
|
278
|
+
__globalCtx.stateStack.globals = __state.ctx.stateStack.globals;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
|
|
282
|
+
|
|
283
|
+
if (__step <= 0) {
|
|
284
|
+
|
|
285
|
+
__stack.step++;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
|
|
289
|
+
if (__step <= 1) {
|
|
290
|
+
await _print(color.cyan(`Welcome to the Agency Agent!`));
|
|
291
|
+
__stack.step++;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
if (__step <= 2) {
|
|
296
|
+
__stack.locals.action = {"type": `askUser`, "question": `What would you like to do?`};
|
|
297
|
+
__stack.step++;
|
|
298
|
+
}
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
if (__step <= 3) {
|
|
302
|
+
|
|
303
|
+
{
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
const __tid = __threads.create();
|
|
307
|
+
|
|
308
|
+
__threads.pushActive(__tid);
|
|
309
|
+
|
|
310
|
+
__threads.active().push(smoltalk.systemMessage(`
|
|
311
|
+
${__globalCtx.stateStack.globals.systemPrompt}
|
|
312
|
+
${__globalCtx.stateStack.globals.planPrompt}
|
|
313
|
+
`));
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
while (__stack.locals.action.type != `done`) {
|
|
318
|
+
__stack.locals.userMsg = await _builtinInput(`\n${__stack.locals.action.question} `);
|
|
319
|
+
|
|
320
|
+
|
|
321
|
+
if (isInterrupt(__stack.locals.userMsg)) {
|
|
322
|
+
|
|
323
|
+
return { ...__state, data: __stack.locals.userMsg };
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
|
|
331
|
+
|
|
332
|
+
async function _response(userMsg, __metadata) {
|
|
333
|
+
return runPrompt({
|
|
334
|
+
ctx: __ctx,
|
|
335
|
+
prompt: `Respond to the user's message and decide on the next action. User message: ${userMsg}`,
|
|
336
|
+
messages: __metadata?.messages || new MessageThread(),
|
|
337
|
+
|
|
338
|
+
responseFormat: z.object({
|
|
339
|
+
response: z.union([z.object({ "type": z.literal("askUser"), "question": z.string() }), z.object({ "type": z.literal("done") })])
|
|
340
|
+
}),
|
|
341
|
+
|
|
342
|
+
tools: [__newPlanTool, __getCurrentPlanTool, __listPlansTool, __updateCurrentPlanTool, __updateGoalTool, __updateActionsTool, __printTool, __readTool, __writeCodeWithConfirmTool],
|
|
343
|
+
toolHandlers: [{ name: "newPlan", params: __newPlanToolParams, execute: newPlan, isBuiltin: false }, { name: "getCurrentPlan", params: __getCurrentPlanToolParams, execute: getCurrentPlan, isBuiltin: false }, { name: "listPlans", params: __listPlansToolParams, execute: listPlans, isBuiltin: false }, { name: "updateCurrentPlan", params: __updateCurrentPlanToolParams, execute: updateCurrentPlan, isBuiltin: false }, { name: "updateGoal", params: __updateGoalToolParams, execute: updateGoal, isBuiltin: false }, { name: "updateActions", params: __updateActionsToolParams, execute: updateActions, isBuiltin: false }, { name: "print", params: __printToolParams, execute: _print, isBuiltin: true }, { name: "read", params: __readToolParams, execute: _builtinRead, isBuiltin: true }, { name: "writeCodeWithConfirm", params: __writeCodeWithConfirmToolParams, execute: writeCodeWithConfirm, isBuiltin: false }],
|
|
344
|
+
clientConfig: __globalCtx.stateStack.globals.config,
|
|
345
|
+
stream: false,
|
|
346
|
+
maxToolCallRounds: 10,
|
|
347
|
+
interruptData: __state?.interruptData
|
|
348
|
+
});
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
|
|
354
|
+
__self.response = await _response(__stack.locals.userMsg, {
|
|
355
|
+
messages: __threads.getOrCreateActive()
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
// return early from node if this is an interrupt
|
|
359
|
+
if (isInterrupt(__self.response)) {
|
|
360
|
+
|
|
361
|
+
return { messages: __threads, data: __self.response };
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
__threads.popActive();
|
|
373
|
+
}
|
|
374
|
+
__stack.step++;
|
|
375
|
+
}
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
await callHook({ callbacks: __ctx.callbacks, name: "onNodeEnd", data: { nodeName: "main", data: undefined } });
|
|
379
|
+
return { messages: __threads, data: undefined };
|
|
380
|
+
});
|
|
381
|
+
|
|
382
|
+
graph.node("readExisting", async (__state) => {
|
|
383
|
+
const { stack: __stack, step: __step, self: __self, threads: __threads } =
|
|
384
|
+
setupNode({ state: __state });
|
|
385
|
+
const __ctx = __state.ctx;
|
|
386
|
+
const statelogClient = __ctx.statelogClient;
|
|
387
|
+
const __graph = __ctx.graph;
|
|
388
|
+
await callHook({ callbacks: __ctx.callbacks, name: "onNodeStart", data: { nodeName: "readExisting" } });
|
|
389
|
+
|
|
390
|
+
if (__state.isResume) {
|
|
391
|
+
__globalCtx.stateStack.globals = __state.ctx.stateStack.globals;
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
|
|
395
|
+
|
|
396
|
+
if (__step <= 0) {
|
|
397
|
+
|
|
398
|
+
__stack.step++;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
|
|
402
|
+
if (__step <= 1) {
|
|
403
|
+
__stack.locals.filepath = await _builtinInput(`Enter the path to the .agency file you want to modify: `);
|
|
404
|
+
|
|
405
|
+
|
|
406
|
+
if (isInterrupt(__stack.locals.filepath)) {
|
|
407
|
+
|
|
408
|
+
return { ...__state, data: __stack.locals.filepath };
|
|
409
|
+
|
|
410
|
+
|
|
411
|
+
}
|
|
412
|
+
__stack.step++;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
|
|
416
|
+
if (__step <= 2) {
|
|
417
|
+
__stack.locals.existingCode = await await _builtinRead(__stack.locals.filepath);
|
|
418
|
+
|
|
419
|
+
|
|
420
|
+
if (isInterrupt(__stack.locals.existingCode)) {
|
|
421
|
+
|
|
422
|
+
return { ...__state, data: __stack.locals.existingCode };
|
|
423
|
+
|
|
424
|
+
|
|
425
|
+
}
|
|
426
|
+
__stack.step++;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
|
|
430
|
+
if (__step <= 3) {
|
|
431
|
+
await _print(color.cyan(`Here's the existing code:`));
|
|
432
|
+
__stack.step++;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
|
|
436
|
+
if (__step <= 4) {
|
|
437
|
+
[__self.existingCode] = await Promise.all([__self.existingCode]);
|
|
438
|
+
__stack.step++;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
|
|
442
|
+
if (__step <= 5) {
|
|
443
|
+
const __funcResult = printCode(__stack.locals.existingCode, {
|
|
444
|
+
ctx: __ctx,
|
|
445
|
+
threads: __threads,
|
|
446
|
+
interruptData: __state?.interruptData
|
|
447
|
+
});
|
|
448
|
+
if (isInterrupt(__funcResult)) {
|
|
449
|
+
return { ...__state, data: __funcResult };
|
|
450
|
+
}
|
|
451
|
+
__stack.step++;
|
|
452
|
+
}
|
|
453
|
+
|
|
454
|
+
|
|
455
|
+
if (__step <= 6) {
|
|
456
|
+
__ctx.stateStack.pop();
|
|
457
|
+
return goToNode("plan",
|
|
458
|
+
{
|
|
459
|
+
messages: __stack.messages,
|
|
460
|
+
ctx: __ctx,
|
|
461
|
+
|
|
462
|
+
data: { mode: `modify`, existingCode: __stack.locals.existingCode, existingFilename: __stack.locals.filepath }
|
|
463
|
+
|
|
464
|
+
|
|
465
|
+
});
|
|
466
|
+
__stack.step++;
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
|
|
470
|
+
await callHook({ callbacks: __ctx.callbacks, name: "onNodeEnd", data: { nodeName: "readExisting", data: undefined } });
|
|
471
|
+
return { messages: __threads, data: undefined };
|
|
472
|
+
});
|
|
473
|
+
|
|
474
|
+
graph.node("plan", async (__state) => {
|
|
475
|
+
const { stack: __stack, step: __step, self: __self, threads: __threads } =
|
|
476
|
+
setupNode({ state: __state });
|
|
477
|
+
const __ctx = __state.ctx;
|
|
478
|
+
const statelogClient = __ctx.statelogClient;
|
|
479
|
+
const __graph = __ctx.graph;
|
|
480
|
+
await callHook({ callbacks: __ctx.callbacks, name: "onNodeStart", data: { nodeName: "plan" } });
|
|
481
|
+
|
|
482
|
+
if (__state.isResume) {
|
|
483
|
+
__globalCtx.stateStack.globals = __state.ctx.stateStack.globals;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
|
|
487
|
+
if (!__state.isResume) {
|
|
488
|
+
__stack.args["mode"] = __state.data.mode;
|
|
489
|
+
__stack.args["existingCode"] = __state.data.existingCode;
|
|
490
|
+
__stack.args["existingFilename"] = __state.data.existingFilename;
|
|
491
|
+
}
|
|
492
|
+
|
|
493
|
+
|
|
494
|
+
if (__step <= 0) {
|
|
495
|
+
|
|
496
|
+
__stack.step++;
|
|
497
|
+
}
|
|
498
|
+
|
|
499
|
+
|
|
500
|
+
if (__step <= 1) {
|
|
501
|
+
await _print(color.cyan(`Let's start by coming up with a plan for what you want to accomplish.`));
|
|
502
|
+
__stack.step++;
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
|
|
506
|
+
if (__step <= 2) {
|
|
507
|
+
__stack.locals.modeContext = ``;
|
|
508
|
+
__stack.step++;
|
|
509
|
+
}
|
|
510
|
+
|
|
511
|
+
|
|
512
|
+
if (__step <= 3) {
|
|
513
|
+
if (__stack.args.mode == `modify`) {
|
|
514
|
+
__stack.locals.modeContext = `
|
|
515
|
+
You are in MODIFY mode. The user has an existing agent they want to modify. Here is the existing code:
|
|
516
|
+
|
|
517
|
+
```
|
|
518
|
+
${__stack.args.existingCode}
|
|
519
|
+
```
|
|
520
|
+
|
|
521
|
+
Focus on understanding what changes the user wants to make to this existing agent.
|
|
522
|
+
`;
|
|
523
|
+
|
|
524
|
+
|
|
525
|
+
}
|
|
526
|
+
__stack.step++;
|
|
527
|
+
}
|
|
528
|
+
|
|
529
|
+
|
|
530
|
+
if (__step <= 4) {
|
|
531
|
+
|
|
532
|
+
{
|
|
533
|
+
|
|
534
|
+
|
|
535
|
+
const __tid = __threads.create();
|
|
536
|
+
|
|
537
|
+
__threads.pushActive(__tid);
|
|
538
|
+
|
|
539
|
+
__threads.active().push(smoltalk.systemMessage(`${__globalCtx.stateStack.globals.systemPrompt}\n\n${__globalCtx.stateStack.globals.planPrompt}${__stack.locals.modeContext}`));
|
|
540
|
+
|
|
541
|
+
|
|
542
|
+
__stack.locals.userMsg = await _builtinInput(`What would you like to accomplish today? `);
|
|
543
|
+
|
|
544
|
+
|
|
545
|
+
if (isInterrupt(__stack.locals.userMsg)) {
|
|
546
|
+
|
|
547
|
+
return { ...__state, data: __stack.locals.userMsg };
|
|
548
|
+
|
|
549
|
+
|
|
550
|
+
}
|
|
551
|
+
|
|
552
|
+
|
|
553
|
+
__stack.locals.nextAction = {"type": `start`};
|
|
554
|
+
|
|
555
|
+
|
|
556
|
+
while (__stack.locals.nextAction.type != `done`) {
|
|
557
|
+
|
|
558
|
+
|
|
559
|
+
|
|
560
|
+
async function _nextAction(userMsg, __metadata) {
|
|
561
|
+
return runPrompt({
|
|
562
|
+
ctx: __ctx,
|
|
563
|
+
prompt: `${userMsg}`,
|
|
564
|
+
messages: __metadata?.messages || new MessageThread(),
|
|
565
|
+
|
|
566
|
+
responseFormat: z.object({
|
|
567
|
+
response: z.union([z.object({ "type": z.literal("askUser"), "question": z.string() }), z.object({ "type": z.literal("done") })])
|
|
568
|
+
}),
|
|
569
|
+
|
|
570
|
+
tools: [__printTool],
|
|
571
|
+
toolHandlers: [{ name: "print", params: __printToolParams, execute: _print, isBuiltin: true }],
|
|
572
|
+
clientConfig: __globalCtx.stateStack.globals.config,
|
|
573
|
+
stream: false,
|
|
574
|
+
maxToolCallRounds: 10,
|
|
575
|
+
interruptData: __state?.interruptData
|
|
576
|
+
});
|
|
577
|
+
}
|
|
578
|
+
|
|
579
|
+
|
|
580
|
+
|
|
581
|
+
|
|
582
|
+
__self.nextAction = await _nextAction(__stack.locals.userMsg, {
|
|
583
|
+
messages: __threads.getOrCreateActive()
|
|
584
|
+
});
|
|
585
|
+
|
|
586
|
+
// return early from node if this is an interrupt
|
|
587
|
+
if (isInterrupt(__self.nextAction)) {
|
|
588
|
+
|
|
589
|
+
return { messages: __threads, data: __self.nextAction };
|
|
590
|
+
|
|
591
|
+
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
|
|
595
|
+
if (__stack.locals.nextAction.type == `askUser`) {
|
|
596
|
+
__stack.locals.userMsg = await _builtinInput(`${__stack.locals.nextAction.question} `);
|
|
597
|
+
|
|
598
|
+
|
|
599
|
+
if (isInterrupt(__stack.locals.userMsg)) {
|
|
600
|
+
|
|
601
|
+
return { ...__state, data: __stack.locals.userMsg };
|
|
602
|
+
|
|
603
|
+
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
|
|
613
|
+
|
|
614
|
+
__stack.locals.plan = readPlan();
|
|
615
|
+
|
|
616
|
+
|
|
617
|
+
if (isInterrupt(__stack.locals.plan)) {
|
|
618
|
+
|
|
619
|
+
return { ...__state, data: __stack.locals.plan };
|
|
620
|
+
|
|
621
|
+
|
|
622
|
+
}
|
|
623
|
+
|
|
624
|
+
|
|
625
|
+
await _print(color.cyan(`Here's the plan we've come up with`))
|
|
626
|
+
|
|
627
|
+
await _printJSON(__stack.locals.plan)
|
|
628
|
+
|
|
629
|
+
|
|
630
|
+
|
|
631
|
+
__threads.popActive();
|
|
632
|
+
}
|
|
633
|
+
__stack.step++;
|
|
634
|
+
}
|
|
635
|
+
|
|
636
|
+
|
|
637
|
+
if (__step <= 5) {
|
|
638
|
+
__ctx.stateStack.pop();
|
|
639
|
+
return goToNode("design",
|
|
640
|
+
{
|
|
641
|
+
messages: __stack.messages,
|
|
642
|
+
ctx: __ctx,
|
|
643
|
+
|
|
644
|
+
data: { plan: __stack.locals.plan, mode: __stack.args.mode, existingCode: __stack.args.existingCode, existingFilename: __stack.args.existingFilename }
|
|
645
|
+
|
|
646
|
+
|
|
647
|
+
});
|
|
648
|
+
__stack.step++;
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
|
|
652
|
+
await callHook({ callbacks: __ctx.callbacks, name: "onNodeEnd", data: { nodeName: "plan", data: undefined } });
|
|
653
|
+
return { messages: __threads, data: undefined };
|
|
654
|
+
});
|
|
655
|
+
|
|
656
|
+
graph.node("design", async (__state) => {
|
|
657
|
+
const { stack: __stack, step: __step, self: __self, threads: __threads } =
|
|
658
|
+
setupNode({ state: __state });
|
|
659
|
+
const __ctx = __state.ctx;
|
|
660
|
+
const statelogClient = __ctx.statelogClient;
|
|
661
|
+
const __graph = __ctx.graph;
|
|
662
|
+
await callHook({ callbacks: __ctx.callbacks, name: "onNodeStart", data: { nodeName: "design" } });
|
|
663
|
+
|
|
664
|
+
if (__state.isResume) {
|
|
665
|
+
__globalCtx.stateStack.globals = __state.ctx.stateStack.globals;
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
|
|
669
|
+
if (!__state.isResume) {
|
|
670
|
+
__stack.args["plan"] = __state.data.plan;
|
|
671
|
+
__stack.args["mode"] = __state.data.mode;
|
|
672
|
+
__stack.args["existingCode"] = __state.data.existingCode;
|
|
673
|
+
__stack.args["existingFilename"] = __state.data.existingFilename;
|
|
674
|
+
}
|
|
675
|
+
|
|
676
|
+
|
|
677
|
+
if (__step <= 0) {
|
|
678
|
+
|
|
679
|
+
__stack.step++;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
|
|
683
|
+
if (__step <= 1) {
|
|
684
|
+
__stack.locals.designPrompt = await await _builtinRead(`./prompts/design.md`);
|
|
685
|
+
|
|
686
|
+
|
|
687
|
+
if (isInterrupt(__stack.locals.designPrompt)) {
|
|
688
|
+
|
|
689
|
+
return { ...__state, data: __stack.locals.designPrompt };
|
|
690
|
+
|
|
691
|
+
|
|
692
|
+
}
|
|
693
|
+
__stack.step++;
|
|
694
|
+
}
|
|
695
|
+
|
|
696
|
+
|
|
697
|
+
if (__step <= 2) {
|
|
698
|
+
__stack.locals.prompt = ``;
|
|
699
|
+
__stack.step++;
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
|
|
703
|
+
if (__step <= 3) {
|
|
704
|
+
if (__stack.args.mode == `modify`) {
|
|
705
|
+
await _print(color.cyan(`Now let's modify the existing agent based on the plan.`));
|
|
706
|
+
|
|
707
|
+
|
|
708
|
+
__stack.locals.prompt = `
|
|
709
|
+
You are in MODIFY mode. Here is the existing agent code:
|
|
710
|
+
|
|
711
|
+
```
|
|
712
|
+
${__stack.args.existingCode}
|
|
713
|
+
```
|
|
714
|
+
|
|
715
|
+
The user wants to make the following modifications:
|
|
716
|
+
Goal: ${__stack.args.plan.overallGoal}
|
|
717
|
+
Desired changes: ${__stack.args.plan.desiredActions}
|
|
718
|
+
|
|
719
|
+
Modify the existing code to accomplish these changes. Preserve the existing style and structure where possible.
|
|
720
|
+
`;
|
|
721
|
+
|
|
722
|
+
|
|
723
|
+
} else {
|
|
724
|
+
await _print(color.cyan(`Now let's design an agent to accomplish that plan.`));
|
|
725
|
+
|
|
726
|
+
|
|
727
|
+
__stack.locals.prompt = `
|
|
728
|
+
Help the user design an agent that can accomplish the following goal: ${__stack.args.plan.overallGoal}
|
|
729
|
+
with the following actions: ${__stack.args.plan.desiredActions}.
|
|
730
|
+
`;
|
|
731
|
+
|
|
732
|
+
|
|
733
|
+
}
|
|
734
|
+
__stack.step++;
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
|
|
738
|
+
if (__step <= 4) {
|
|
739
|
+
|
|
740
|
+
{
|
|
741
|
+
|
|
742
|
+
|
|
743
|
+
const __tid = __threads.create();
|
|
744
|
+
|
|
745
|
+
__threads.pushActive(__tid);
|
|
746
|
+
|
|
747
|
+
[__self.designPrompt] = await Promise.all([__self.designPrompt]);
|
|
748
|
+
__threads.active().push(smoltalk.systemMessage(__stack.locals.designPrompt));
|
|
749
|
+
|
|
750
|
+
|
|
751
|
+
__stack.locals.userMsg = __stack.locals.prompt;
|
|
752
|
+
|
|
753
|
+
|
|
754
|
+
__stack.locals.nextAction = {"type": `start`};
|
|
755
|
+
|
|
756
|
+
|
|
757
|
+
__stack.locals.i = 0;
|
|
758
|
+
|
|
759
|
+
|
|
760
|
+
while (__stack.locals.nextAction.type != `done`) {
|
|
761
|
+
__stack.locals.i += 1
|
|
762
|
+
|
|
763
|
+
await _print(color.blue(`Design iteration ${__stack.locals.i}`));
|
|
764
|
+
|
|
765
|
+
|
|
766
|
+
|
|
767
|
+
async function _nextAction(userMsg, __metadata) {
|
|
768
|
+
return runPrompt({
|
|
769
|
+
ctx: __ctx,
|
|
770
|
+
prompt: `${userMsg}`,
|
|
771
|
+
messages: __metadata?.messages || new MessageThread(),
|
|
772
|
+
|
|
773
|
+
responseFormat: z.object({
|
|
774
|
+
response: z.union([z.object({ "type": z.literal("askUser"), "question": z.string() }), z.object({ "type": z.literal("done"), "finalCode": z.string(), "filename": z.string() }), z.object({ "type": z.literal("start") })])
|
|
775
|
+
}),
|
|
776
|
+
|
|
777
|
+
tools: undefined,
|
|
778
|
+
toolHandlers: [],
|
|
779
|
+
clientConfig: __globalCtx.stateStack.globals.config,
|
|
780
|
+
stream: false,
|
|
781
|
+
maxToolCallRounds: 10,
|
|
782
|
+
interruptData: __state?.interruptData
|
|
783
|
+
});
|
|
784
|
+
}
|
|
785
|
+
|
|
786
|
+
|
|
787
|
+
|
|
788
|
+
|
|
789
|
+
__self.nextAction = await _nextAction(__stack.locals.userMsg, {
|
|
790
|
+
messages: __threads.getOrCreateActive()
|
|
791
|
+
});
|
|
792
|
+
|
|
793
|
+
// return early from node if this is an interrupt
|
|
794
|
+
if (isInterrupt(__self.nextAction)) {
|
|
795
|
+
|
|
796
|
+
return { messages: __threads, data: __self.nextAction };
|
|
797
|
+
|
|
798
|
+
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
|
|
802
|
+
if (__stack.locals.nextAction.type == `askUser`) {
|
|
803
|
+
__stack.locals.userMsg = await _builtinInput(`\n${__stack.locals.nextAction.question} `);
|
|
804
|
+
|
|
805
|
+
|
|
806
|
+
if (isInterrupt(__stack.locals.userMsg)) {
|
|
807
|
+
|
|
808
|
+
return { ...__state, data: __stack.locals.userMsg };
|
|
809
|
+
|
|
810
|
+
|
|
811
|
+
}
|
|
812
|
+
|
|
813
|
+
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
|
|
817
|
+
}
|
|
818
|
+
|
|
819
|
+
|
|
820
|
+
|
|
821
|
+
|
|
822
|
+
__threads.popActive();
|
|
823
|
+
}
|
|
824
|
+
__stack.step++;
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
|
|
828
|
+
if (__step <= 5) {
|
|
829
|
+
await _print(color.green(`Great! We've designed the agent. Now let's write the code for it.`));
|
|
830
|
+
__stack.step++;
|
|
831
|
+
}
|
|
832
|
+
|
|
833
|
+
|
|
834
|
+
if (__step <= 6) {
|
|
835
|
+
await _printJSON(color.magenta(__stack.locals.nextAction));
|
|
836
|
+
__stack.step++;
|
|
837
|
+
}
|
|
838
|
+
|
|
839
|
+
|
|
840
|
+
if (__step <= 7) {
|
|
841
|
+
__stack.locals.nextAction.filename = __stack.locals.nextAction.filename || `agent.agency`;
|
|
842
|
+
__stack.step++;
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
|
|
846
|
+
if (__step <= 8) {
|
|
847
|
+
const __funcResult = await writeCodeWithConfirm(__stack.args.existingFilename || __stack.locals.nextAction.filename, __stack.locals.nextAction.finalCode, {
|
|
848
|
+
ctx: __ctx,
|
|
849
|
+
threads: __threads,
|
|
850
|
+
interruptData: __state?.interruptData
|
|
851
|
+
});
|
|
852
|
+
if (isInterrupt(__funcResult)) {
|
|
853
|
+
return { ...__state, data: __funcResult };
|
|
854
|
+
}
|
|
855
|
+
__stack.step++;
|
|
856
|
+
}
|
|
857
|
+
|
|
858
|
+
|
|
859
|
+
await callHook({ callbacks: __ctx.callbacks, name: "onNodeEnd", data: { nodeName: "design", data: undefined } });
|
|
860
|
+
return { messages: __threads, data: undefined };
|
|
861
|
+
});
|
|
862
|
+
|
|
863
|
+
graph.conditionalEdge("readExisting", ["plan"]);
|
|
864
|
+
|
|
865
|
+
graph.conditionalEdge("plan", ["design"]);
|
|
866
|
+
|
|
867
|
+
|
|
868
|
+
|
|
869
|
+
export async function main({ messages, callbacks } = {}) {
|
|
870
|
+
|
|
871
|
+
return runNode({
|
|
872
|
+
ctx: __globalCtx,
|
|
873
|
+
nodeName: "main",
|
|
874
|
+
data: { },
|
|
875
|
+
messages,
|
|
876
|
+
callbacks,
|
|
877
|
+
});
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
export const __mainNodeParams = [];
|
|
881
|
+
|
|
882
|
+
|
|
883
|
+
export async function readExisting({ messages, callbacks } = {}) {
|
|
884
|
+
|
|
885
|
+
return runNode({
|
|
886
|
+
ctx: __globalCtx,
|
|
887
|
+
nodeName: "readExisting",
|
|
888
|
+
data: { },
|
|
889
|
+
messages,
|
|
890
|
+
callbacks,
|
|
891
|
+
});
|
|
892
|
+
}
|
|
893
|
+
|
|
894
|
+
export const __readExistingNodeParams = [];
|
|
895
|
+
|
|
896
|
+
export async function plan(mode, existingCode, existingFilename, { messages, callbacks } = {}) {
|
|
897
|
+
|
|
898
|
+
|
|
899
|
+
return runNode({
|
|
900
|
+
ctx: __globalCtx,
|
|
901
|
+
nodeName: "plan",
|
|
902
|
+
data: { mode, existingCode, existingFilename },
|
|
903
|
+
messages,
|
|
904
|
+
callbacks,
|
|
905
|
+
});
|
|
906
|
+
}
|
|
907
|
+
|
|
908
|
+
export const __planNodeParams = ["mode", "existingCode", "existingFilename"];
|
|
909
|
+
|
|
910
|
+
export async function design(plan, mode, existingCode, existingFilename, { messages, callbacks } = {}) {
|
|
911
|
+
|
|
912
|
+
|
|
913
|
+
return runNode({
|
|
914
|
+
ctx: __globalCtx,
|
|
915
|
+
nodeName: "design",
|
|
916
|
+
data: { plan, mode, existingCode, existingFilename },
|
|
917
|
+
messages,
|
|
918
|
+
callbacks,
|
|
919
|
+
});
|
|
920
|
+
}
|
|
921
|
+
|
|
922
|
+
export const __designNodeParams = ["plan", "mode", "existingCode", "existingFilename"];
|
|
923
|
+
if (process.argv[1] === fileURLToPath(import.meta.url)) {
|
|
924
|
+
try {
|
|
925
|
+
const initialState = { messages: new ThreadStore(), data: {} };
|
|
926
|
+
await main(initialState);
|
|
927
|
+
} catch (__error) {
|
|
928
|
+
console.error(`
|
|
929
|
+
Agent crashed: ${__error.message}`);
|
|
930
|
+
throw __error;
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
|
|
934
|
+
export default graph;
|