-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcoding-agent.ts
More file actions
71 lines (67 loc) · 1.87 KB
/
coding-agent.ts
File metadata and controls
71 lines (67 loc) · 1.87 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import {
Agent,
BashTool,
FileReadTool,
FileWriteTool,
FileEditTool,
GlobTool,
GrepTool,
} from "@avasis-ai/synthcode";
import { AnthropicProvider } from "@avasis-ai/synthcode/llm";
const agent = new Agent({
model: new AnthropicProvider({
apiKey: process.env.ANTHROPIC_API_KEY!,
model: "claude-sonnet-4-20250514",
}),
tools: [
new BashTool(),
new FileReadTool(),
new FileWriteTool(),
new FileEditTool(),
new GlobTool(),
new GrepTool(),
],
systemPrompt: [
"You are an expert coding assistant.",
"When writing code, follow these rules:",
"- Use TypeScript for JavaScript projects",
"- Include proper error handling",
"- Write clean, readable code",
"- When running commands, explain what each command does",
].join("\n"),
maxTurns: 50,
context: {
maxTokens: 200_000,
compactThreshold: 0.85,
},
permissions: {
defaultAction: "allow",
},
});
console.log("Synth Coding Agent\n");
console.log("Tools: bash, file_read, file_write, file_edit, glob, grep\n");
console.log("---\n");
const prompt = process.argv[2] || "Create a simple Express.js API with CRUD endpoints for a todo app";
for await (const event of agent.run(prompt)) {
switch (event.type) {
case "text":
process.stdout.write(event.text);
break;
case "tool_use":
console.log(`\n \x1b[36m[${event.name}]\x1b[0m`);
break;
case "tool_result":
if (event.isError) {
console.log(`\n \x1b[31m[ERROR]\x1b[0m ${event.output.slice(0, 200)}`);
}
break;
case "done":
console.log(`\n\n---`);
console.log(`Tokens: ${event.usage.inputTokens} in, ${event.usage.outputTokens} out`);
console.log(`Turns: ${event.messages.filter((m) => m.role === "assistant").length}`);
break;
case "error":
console.error(`\n \x1b[31m${event.error.message}\x1b[0m`);
break;
}
}