ausername-12345 commited on
Commit ·
52a4c62
1
Parent(s): 5c490f9
increase iter limit; fix prompt to push model to act; don't log intermediate file reads to UI
Browse files- src/agent.js +15 -28
src/agent.js
CHANGED
|
@@ -5,7 +5,7 @@ const sandbox = require('./sandbox');
|
|
| 5 |
const errorHealer = require('./errorHealer');
|
| 6 |
|
| 7 |
const AGENT_NAME = process.env.AGENT_NAME || 'Forge';
|
| 8 |
-
const MAX_TOOL_ITERATIONS =
|
| 9 |
|
| 10 |
const path = require('path');
|
| 11 |
const fs = require('fs');
|
|
@@ -14,21 +14,19 @@ const projectRoot = path.resolve(__dirname, '..');
|
|
| 14 |
function systemPrompt() {
|
| 15 |
return [
|
| 16 |
`You are ${AGENT_NAME}, a sharp, direct AI assistant with a personality.`,
|
| 17 |
-
'Short sentences, no filler.',
|
| 18 |
'',
|
| 19 |
-
'
|
| 20 |
'',
|
| 21 |
-
'```read path/to/file.js```',
|
|
|
|
| 22 |
'',
|
| 23 |
-
'
|
|
|
|
|
|
|
|
|
|
| 24 |
'',
|
| 25 |
-
'
|
| 26 |
-
'file contents here',
|
| 27 |
-
'```',
|
| 28 |
-
'',
|
| 29 |
-
'The server will write the file and tell you it succeeded before continuing.',
|
| 30 |
-
'',
|
| 31 |
-
'You can chain multiple reads and writes in a single response. Always read a file before writing it so you know the current contents.',
|
| 32 |
].join('\n');
|
| 33 |
}
|
| 34 |
|
|
@@ -114,32 +112,21 @@ function createAgent(io) {
|
|
| 114 |
const { cleanText, actions } = processFileActions(rawContent);
|
| 115 |
|
| 116 |
if (actions.length > 0) {
|
| 117 |
-
if (cleanText) {
|
| 118 |
-
pushLog(makeLogEntry('assistant', { content: cleanText }));
|
| 119 |
-
llmHistory.push({ role: 'assistant', content: cleanText });
|
| 120 |
-
}
|
| 121 |
-
|
| 122 |
for (const action of actions) {
|
| 123 |
if (action.type === 'read') {
|
| 124 |
-
|
| 125 |
-
pushLog(makeLogEntry('system', { content: msg }));
|
| 126 |
-
llmHistory.push({ role: 'system', content: msg });
|
| 127 |
} else if (action.type === 'write') {
|
| 128 |
-
|
| 129 |
-
pushLog(makeLogEntry('system', { content: msg }));
|
| 130 |
-
llmHistory.push({ role: 'system', content: msg });
|
| 131 |
} else if (action.type === 'error') {
|
| 132 |
-
|
| 133 |
-
pushLog(makeLogEntry('system', { content: msg }));
|
| 134 |
-
llmHistory.push({ role: 'system', content: msg });
|
| 135 |
}
|
| 136 |
}
|
| 137 |
-
|
| 138 |
continue;
|
| 139 |
}
|
| 140 |
|
| 141 |
setStatus('idle');
|
| 142 |
-
|
|
|
|
| 143 |
return;
|
| 144 |
}
|
| 145 |
} catch (err) {
|
|
|
|
| 5 |
const errorHealer = require('./errorHealer');
|
| 6 |
|
| 7 |
const AGENT_NAME = process.env.AGENT_NAME || 'Forge';
|
| 8 |
+
const MAX_TOOL_ITERATIONS = 20;
|
| 9 |
|
| 10 |
const path = require('path');
|
| 11 |
const fs = require('fs');
|
|
|
|
| 14 |
function systemPrompt() {
|
| 15 |
return [
|
| 16 |
`You are ${AGENT_NAME}, a sharp, direct AI assistant with a personality.`,
|
| 17 |
+
'Short sentences, no filler. When the user asks you to change the site, DO IT - read the relevant files, then write them with your changes.',
|
| 18 |
'',
|
| 19 |
+
'File commands (use these directly in your response, one response can have multiple):',
|
| 20 |
'',
|
| 21 |
+
' ```read path/to/file.js```',
|
| 22 |
+
' The server reads the file and shows you its contents. Use this to see current code before editing.',
|
| 23 |
'',
|
| 24 |
+
' ```write path/to/file.js',
|
| 25 |
+
' file contents here',
|
| 26 |
+
' ```',
|
| 27 |
+
' The server writes the new file contents. Include the COMPLETE file, not just a diff.',
|
| 28 |
'',
|
| 29 |
+
'When asked to add a feature, do this in ONE response: read all files you need, then immediately write the updated files. Dont ask for confirmation - just do it.',
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
].join('\n');
|
| 31 |
}
|
| 32 |
|
|
|
|
| 112 |
const { cleanText, actions } = processFileActions(rawContent);
|
| 113 |
|
| 114 |
if (actions.length > 0) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
for (const action of actions) {
|
| 116 |
if (action.type === 'read') {
|
| 117 |
+
llmHistory.push({ role: 'system', content: `Contents of \`${action.path}\`:\n\`\`\`\n${action.result}\n\`\`\`` });
|
|
|
|
|
|
|
| 118 |
} else if (action.type === 'write') {
|
| 119 |
+
llmHistory.push({ role: 'system', content: `Written \`${action.path}\`` });
|
|
|
|
|
|
|
| 120 |
} else if (action.type === 'error') {
|
| 121 |
+
llmHistory.push({ role: 'system', content: `Error on \`${action.path}\`: ${action.message}` });
|
|
|
|
|
|
|
| 122 |
}
|
| 123 |
}
|
|
|
|
| 124 |
continue;
|
| 125 |
}
|
| 126 |
|
| 127 |
setStatus('idle');
|
| 128 |
+
const displayContent = rawContent || '...';
|
| 129 |
+
pushLog(makeLogEntry('assistant', { content: displayContent }));
|
| 130 |
return;
|
| 131 |
}
|
| 132 |
} catch (err) {
|