BREAKING CHANGE(aidoc): migrate agent orchestration to new runAgent API and filesystem tools; refactor model handling and update README and tests
This commit is contained in:
@@ -19,53 +19,29 @@ export class Description {
|
||||
}
|
||||
|
||||
public async build() {
|
||||
// Use DualAgentOrchestrator with filesystem tool for agent-driven exploration
|
||||
const descriptionOrchestrator = new plugins.smartagent.DualAgentOrchestrator({
|
||||
smartAiInstance: this.aiDocsRef.smartAiInstance,
|
||||
defaultProvider: 'openai',
|
||||
maxIterations: 15,
|
||||
maxResultChars: 10000, // Limit tool output to prevent token explosion
|
||||
maxHistoryMessages: 15, // Limit history window
|
||||
logPrefix: '[Description]',
|
||||
onProgress: (event) => logger.log(event.logLevel, event.logMessage),
|
||||
guardianPolicyPrompt: `
|
||||
You validate description generation tool calls and outputs.
|
||||
// Use runAgent with filesystem tool for agent-driven exploration
|
||||
const fsTools = plugins.smartagentTools.filesystemTool({ rootDir: this.projectDir });
|
||||
|
||||
APPROVE tool calls for:
|
||||
- Reading package.json, npmextra.json, or source files in the ts/ directory
|
||||
- Listing directory contents to understand project structure
|
||||
- Using tree to see project structure
|
||||
const descriptionSystemPrompt = `
|
||||
You create project descriptions and keywords for npm packages.
|
||||
|
||||
REJECT tool calls for:
|
||||
- Reading files outside the project directory
|
||||
- Writing, deleting, or modifying any files
|
||||
- Any destructive operations
|
||||
You have access to filesystem tools to explore the project.
|
||||
|
||||
For final output, APPROVE if:
|
||||
- JSON is valid and parseable
|
||||
- Description is a clear, concise one-sentence summary
|
||||
- Keywords are relevant to the project's use cases
|
||||
- Both description and keywords fields are present
|
||||
|
||||
REJECT final output if:
|
||||
- JSON is malformed or wrapped in markdown code blocks
|
||||
- Description is too long or vague
|
||||
- Keywords are irrelevant or generic
|
||||
`,
|
||||
});
|
||||
|
||||
// Register scoped filesystem tool for agent exploration
|
||||
descriptionOrchestrator.registerScopedFilesystemTool(this.projectDir);
|
||||
|
||||
await descriptionOrchestrator.start();
|
||||
IMPORTANT RULES:
|
||||
- Only READ files (package.json, npmextra.json, source files in ts/)
|
||||
- Do NOT write, delete, or modify any files
|
||||
- Your final response must be valid JSON only
|
||||
- Description must be a clear, concise one-sentence summary
|
||||
- Keywords must be relevant to the project's use cases
|
||||
- Both description and keywords fields must be present
|
||||
- Do NOT wrap JSON in markdown code blocks
|
||||
`;
|
||||
|
||||
const descriptionTaskPrompt = `
|
||||
You create a project description and keywords for an npm package.
|
||||
|
||||
PROJECT DIRECTORY: ${this.projectDir}
|
||||
|
||||
Use the filesystem tool to explore the project and understand what it does:
|
||||
1. First, use tree to see the project structure
|
||||
Use the filesystem tools to explore the project and understand what it does:
|
||||
1. First, use list_directory to see the project structure
|
||||
2. Read package.json to understand the package name and current description
|
||||
3. Read npmextra.json if it exists for additional metadata
|
||||
4. Read key source files in ts/ directory to understand the implementation
|
||||
@@ -83,16 +59,20 @@ Your answer should be parseable with JSON.parse() without modifying anything.
|
||||
Don't wrap the JSON in \`\`\`json\`\`\` - just return the raw JSON object.
|
||||
`;
|
||||
|
||||
const descriptionResult = await descriptionOrchestrator.run(descriptionTaskPrompt);
|
||||
await descriptionOrchestrator.stop();
|
||||
logger.log('info', 'Starting description generation with agent...');
|
||||
|
||||
if (!descriptionResult.success) {
|
||||
throw new Error(`Description generation failed: ${descriptionResult.status}`);
|
||||
}
|
||||
const descriptionResult = await plugins.smartagent.runAgent({
|
||||
model: this.aiDocsRef.model,
|
||||
prompt: descriptionTaskPrompt,
|
||||
system: descriptionSystemPrompt,
|
||||
tools: fsTools,
|
||||
maxSteps: 15,
|
||||
onToolCall: (toolName) => logger.log('info', `[Description] Tool call: ${toolName}`),
|
||||
});
|
||||
|
||||
console.log(descriptionResult.result);
|
||||
console.log(descriptionResult.text);
|
||||
const resultObject: IDescriptionInterface = JSON.parse(
|
||||
descriptionResult.result.replace('```json', '').replace('```', ''),
|
||||
descriptionResult.text.replace('```json', '').replace('```', ''),
|
||||
);
|
||||
|
||||
// Use ProjectContext to get file handles for writing
|
||||
@@ -120,6 +100,6 @@ Don't wrap the JSON in \`\`\`json\`\`\` - just return the raw JSON object.
|
||||
console.log(`\n======================\n`);
|
||||
console.log(JSON.stringify(resultObject, null, 2));
|
||||
console.log(`\n======================\n`);
|
||||
return descriptionResult.result;
|
||||
return descriptionResult.text;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user