index.ts
1.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/**
* Refiner Agent: Code editor specialist.
*
* Simplified actor-critic pattern with structured output via post-processor.
* Uses evoltjs Agent class for file editing tools.
*/
import { Agent } from 'evoltagent';
import type { ModelConfig } from 'evoltagent';
import { REFINER_PROMPT } from './prompt';
import { getModelConfig } from '../../utils/config';
import { AGENT_CONTEXT_WINDOW_TOKENS, MAX_OUTPUT_TOKENS } from '../../constants';
import { parseRefinerResult } from './utils';
export { formatRefinerInstruction } from './instruction';
/**
* Create refiner agent (actor) for applying fixes.
*
* @param workspaceDir - Optional workspace directory to restrict file access
* @returns Agent configured with FileEditor tools and structured output
*/
export function createRefinerAgent(workspaceDir?: string): Agent {
let systemPrompt = REFINER_PROMPT;
if (workspaceDir) {
systemPrompt += `\n\nWORKSPACE: ${workspaceDir}\nOnly modify files within this workspace.`;
}
const modelConfig: ModelConfig = {
...getModelConfig(),
contextWindowTokens: AGENT_CONTEXT_WINDOW_TOKENS,
maxOutputTokens: MAX_OUTPUT_TOKENS,
stream: true,
};
return new Agent({
name: 'RefinerAgent',
profile: 'Code editor specialist',
system: systemPrompt,
tools: ['FileEditor.read', 'FileEditor.find', 'FileEditor.findAndReplace'],
modelConfig,
postProcessor: parseRefinerResult,
verbose: 2,
});
}