fix: drives
This commit is contained in:
1 parent
0d79b1f706
commit
b74f7cd3d9
11 files changed
+598
-16
No files matched your search
@@ -0,0 +1,79 @@
|
||||
import fs from 'node:fs';
|
||||
import path from 'node:path';
|
||||
|
||||
const READ_TOOLS = ['list-dir', 'read-file', 'find-files', 'search-files'];
|
||||
const WRITE_TOOLS = ['write-file', 'update-file', 'multi-edit'];
|
||||
|
||||
const parentSystem = `You must execute the given task to completion.
|
||||
You don't revise, you don't ideate. You execute and build. All the information has already been gathered and evaluted before presenting it to you, you go straight to the code and update exactly as instructed.
|
||||
If the goal involves a complex plan, split it into independent parts and use the \`delegate\` tool to give each part to a fresh subagent, saving your own context.
|
||||
Do not delegate trivial single-step work; do it yourself. Work iteratively until the task is fully implemented.
|
||||
CONSTRAINTS:
|
||||
- Prefer reading only files present in the prompt.
|
||||
- Do not test anything beyond syntax nor run any command.
|
||||
- Extrapolating requirements or inferring updates is FORBIDDEN. If insufficient context, terminate.
|
||||
`;
|
||||
|
||||
const childSystem = `Your goal is to execute the specific instruction you were given.
|
||||
Your task was asigned autonomously by a coordinator. Focus only on your assigned part.
|
||||
Note: task is terminated after 20 turns, reasoning traces are not persisted after agent turns.
|
||||
CONSTRAINTS:
|
||||
- You must ONLY read files mentioned in your instruction, and only explore to find them.
|
||||
`;
|
||||
|
||||
function resolveInstruction (input) {
|
||||
if (input.prompt) return input.prompt;
|
||||
|
||||
const candidates = ['prompt.md', 'prompt.txt', 'prompt', 'plan.md', 'report.md'];
|
||||
for (const name of candidates) {
|
||||
const file = path.resolve(Gral.path, '.gral', name);
|
||||
if (fs.existsSync(file)) {
|
||||
console.log("Prompt read from: " + name);
|
||||
return fs.readFileSync(file, 'utf8');
|
||||
}
|
||||
}
|
||||
|
||||
throw new Error("Instruction required.");
|
||||
}
|
||||
|
||||
// Delegate tool: spawn a subagent with the same permissions, but no delegate tool.
|
||||
const delegate = {
|
||||
name: 'delegate',
|
||||
description: 'Spawn a subagent to execute a specific part of the plan. Use it to split complex plans into parts and save context. The subagent has the same file permissions but cannot delegate further.',
|
||||
parameters: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
prompt: { type: 'string', description: 'The specific instruction the subagent must execute.' },
|
||||
},
|
||||
required: ['prompt'],
|
||||
},
|
||||
handler: async (args) => {
|
||||
const res = await Gral.run({
|
||||
instruction: childSystem,
|
||||
messages: [{ role: 'user', content: args.prompt }],
|
||||
agentId: 7,
|
||||
read: true,
|
||||
write: true,
|
||||
defaultTools: [...READ_TOOLS, ...WRITE_TOOLS],
|
||||
// no `delegate` tool: the subagent cannot delegate further
|
||||
});
|
||||
return res;
|
||||
},
|
||||
};
|
||||
|
||||
export default async function build (input) {
|
||||
const instruction = resolveInstruction(input);
|
||||
|
||||
let res = await Gral.run({
|
||||
instruction: parentSystem,
|
||||
messages: [{ role: 'user', content: instruction }],
|
||||
agentId: 7,
|
||||
read: true,
|
||||
write: true,
|
||||
defaultTools: [...READ_TOOLS, ...WRITE_TOOLS],
|
||||
tools: [delegate],
|
||||
maxIter: 64,
|
||||
});
|
||||
|
||||
console.log(res);
|
||||
};
|
||||
Reference in new issue
Block a user