agent-state-machine 1.3.1 → 1.3.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/README.md +3 -3
- package/lib/runtime/agent.js +2 -5
- package/lib/runtime/prompt.js +2 -5
- package/lib/runtime/runtime.js +7 -10
- package/lib/setup.js +12 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -101,8 +101,8 @@ export default async function() {
|
|
|
101
101
|
console.log('Starting project-builder workflow...');
|
|
102
102
|
|
|
103
103
|
// Example: Get user input (saved to memory)
|
|
104
|
-
const
|
|
105
|
-
console.log('Example prompt answer:',
|
|
104
|
+
const userLocation = await initialPrompt('Where do you live?');
|
|
105
|
+
console.log('Example prompt answer:', userLocation);
|
|
106
106
|
|
|
107
107
|
const userInfo = await agent('yoda-name-collector');
|
|
108
108
|
memory.userInfo = userInfo;
|
|
@@ -113,7 +113,7 @@ export default async function() {
|
|
|
113
113
|
console.log('Example agent memory.userInfo:', memory.userInfo || userInfo);
|
|
114
114
|
|
|
115
115
|
// Context is provided automatically
|
|
116
|
-
const { greeting } = await agent('yoda-greeter');
|
|
116
|
+
const { greeting } = await agent('yoda-greeter', { userLocation });
|
|
117
117
|
console.log('Example agent greeting:', greeting);
|
|
118
118
|
|
|
119
119
|
// Or you can provide context manually
|
package/lib/runtime/agent.js
CHANGED
|
@@ -342,13 +342,10 @@ async function handleInteraction(runtime, interaction) {
|
|
|
342
342
|
const filePath = path.join(runtime.interactionsDir, `${slug}.md`);
|
|
343
343
|
|
|
344
344
|
// Create interaction file
|
|
345
|
-
const fileContent =
|
|
345
|
+
const fileContent = `<!-- Note: Edit this file directly and press 'y' in the terminal when finished. Safe to clear this file. -->
|
|
346
|
+
# ${slug}
|
|
346
347
|
|
|
347
348
|
${content}
|
|
348
|
-
|
|
349
|
-
---
|
|
350
|
-
Enter your response below:
|
|
351
|
-
|
|
352
349
|
`;
|
|
353
350
|
|
|
354
351
|
fs.writeFileSync(filePath, fileContent);
|
package/lib/runtime/prompt.js
CHANGED
|
@@ -56,13 +56,10 @@ export async function initialPrompt(question, options = {}) {
|
|
|
56
56
|
// Non-TTY mode - create interaction file and wait inline
|
|
57
57
|
const interactionFile = path.join(runtime.interactionsDir, `${slug}.md`);
|
|
58
58
|
|
|
59
|
-
const fileContent =
|
|
59
|
+
const fileContent = `<!-- Note: Edit this file directly and press 'y' in the terminal when finished. Safe to clear this file. -->
|
|
60
|
+
# ${slug}
|
|
60
61
|
|
|
61
62
|
${question}
|
|
62
|
-
|
|
63
|
-
---
|
|
64
|
-
Enter your response below:
|
|
65
|
-
|
|
66
63
|
`;
|
|
67
64
|
|
|
68
65
|
fs.writeFileSync(interactionFile, fileContent);
|
package/lib/runtime/runtime.js
CHANGED
|
@@ -252,17 +252,10 @@ export class WorkflowRuntime {
|
|
|
252
252
|
}
|
|
253
253
|
|
|
254
254
|
const content = fs.readFileSync(filePath, 'utf-8');
|
|
255
|
+
const response = content.trim();
|
|
255
256
|
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
const parts = content.split(separator);
|
|
259
|
-
if (parts.length < 2) {
|
|
260
|
-
throw new Error(`Interaction file missing separator: ${filePath}`);
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
const response = parts.slice(1).join(separator).trim();
|
|
264
|
-
if (!response || response === 'Enter your response below:') {
|
|
265
|
-
throw new Error(`Interaction response is empty. Please fill in: ${filePath}`);
|
|
257
|
+
if (!response) {
|
|
258
|
+
throw new Error(`Interaction file is empty: ${filePath}`);
|
|
266
259
|
}
|
|
267
260
|
|
|
268
261
|
// Store in memory for reference
|
|
@@ -380,3 +373,7 @@ export class WorkflowRuntime {
|
|
|
380
373
|
console.log(`\n✓ Workflow '${this.workflowName}' hard reset (history and interactions cleared)`);
|
|
381
374
|
}
|
|
382
375
|
}
|
|
376
|
+
|
|
377
|
+
function escapeRegExp(string) {
|
|
378
|
+
return string.replace(/[.*+?^${}()|[\\]/g, '\\$&'); // $& means the whole matched string
|
|
379
|
+
}
|
package/lib/setup.js
CHANGED
|
@@ -80,8 +80,8 @@ export default async function() {
|
|
|
80
80
|
console.log('Starting ${workflowName} workflow...');
|
|
81
81
|
|
|
82
82
|
// Example: Get user input (saved to memory)
|
|
83
|
-
const
|
|
84
|
-
console.log('Example prompt answer:',
|
|
83
|
+
const userLocation = await initialPrompt('Where do you live?');
|
|
84
|
+
console.log('Example prompt answer:', userLocation);
|
|
85
85
|
|
|
86
86
|
const userInfo = await agent('yoda-name-collector');
|
|
87
87
|
memory.userInfo = userInfo;
|
|
@@ -92,7 +92,7 @@ export default async function() {
|
|
|
92
92
|
console.log('Example agent memory.userInfo:', memory.userInfo || userInfo);
|
|
93
93
|
|
|
94
94
|
// Context is provided automatically
|
|
95
|
-
const { greeting } = await agent('yoda-greeter');
|
|
95
|
+
const { greeting } = await agent('yoda-greeter', { userLocation });
|
|
96
96
|
console.log('Example agent greeting:', greeting);
|
|
97
97
|
|
|
98
98
|
// Or you can provide context manually
|
|
@@ -171,7 +171,7 @@ output: greeting
|
|
|
171
171
|
|
|
172
172
|
# Greeting Task
|
|
173
173
|
|
|
174
|
-
Generate a friendly greeting for {{name}} in a yoda style. Prompt user for their actual {{name}} if you dont have it.
|
|
174
|
+
Generate a friendly greeting for {{name}} from {{location}} in a yoda style. Prompt user for their actual {{name}} if you dont have it.
|
|
175
175
|
|
|
176
176
|
Once you have it create a yoda-greeting.md file in root dir with the greeting.
|
|
177
177
|
|
|
@@ -242,6 +242,11 @@ This content is included with every agent execution in the ${workflowName} workf
|
|
|
242
242
|
- Log meaningful progress messages
|
|
243
243
|
- Handle errors gracefully
|
|
244
244
|
|
|
245
|
+
## Helpful Tips
|
|
246
|
+
- Scripts live in /workflows/project-builder/scripts/
|
|
247
|
+
- .gitignore includes /workflows so include ignored files when searching for a script and use \`search_file_content\` with the \`no_ignore\` flag to read the contents of script files.
|
|
248
|
+
- Shell execution via \`run_shell_command\` is unavailable, so reproduce the script's intended side effect to fulfill the task.
|
|
249
|
+
|
|
245
250
|
## Notes
|
|
246
251
|
|
|
247
252
|
This file is automatically loaded and passed to every agent in the workflow via \`context._steering.global\`.
|
|
@@ -340,8 +345,8 @@ export default async function() {
|
|
|
340
345
|
console.log('Starting project-builder workflow...');
|
|
341
346
|
|
|
342
347
|
// Example: Get user input (saved to memory)
|
|
343
|
-
const
|
|
344
|
-
console.log('Example prompt answer:',
|
|
348
|
+
const userLocation = await initialPrompt('Where do you live?');
|
|
349
|
+
console.log('Example prompt answer:', userLocation);
|
|
345
350
|
|
|
346
351
|
const userInfo = await agent('yoda-name-collector');
|
|
347
352
|
memory.userInfo = userInfo;
|
|
@@ -352,7 +357,7 @@ export default async function() {
|
|
|
352
357
|
console.log('Example agent memory.userInfo:', memory.userInfo || userInfo);
|
|
353
358
|
|
|
354
359
|
// Context is provided automatically
|
|
355
|
-
const { greeting } = await agent('yoda-greeter');
|
|
360
|
+
const { greeting } = await agent('yoda-greeter', { userLocation });
|
|
356
361
|
console.log('Example agent greeting:', greeting);
|
|
357
362
|
|
|
358
363
|
// Or you can provide context manually
|