Skip to content

Commit 4852954

Browse files
committed
Combine agent-builder and base-agent builder. Add diff-reviewer1, 2, and 3 as example agents.
1 parent 8a4bb98 commit 4852954

File tree

19 files changed

+622
-1239
lines changed

19 files changed

+622
-1239
lines changed

.agents/agent-builder.ts

Lines changed: 0 additions & 215 deletions
This file was deleted.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { AgentConfig } from '@codebuff/common/util/types/agent-config.d'
2+
3+
const config: AgentConfig = {
4+
id: 'diff-reviewer-1',
5+
6+
displayName: 'Diff Reviewer (Level 1)',
7+
model: 'openai/gpt-5',
8+
toolNames: ['read_files', 'run_terminal_command'],
9+
10+
parentPrompt: 'Spawn when you need to review code changes in the git diff',
11+
12+
instructionsPrompt: `Execute the following steps:
13+
1. Run git diff
14+
2. Read the files that have changed
15+
3. Review the changes and suggest improvements`,
16+
}
17+
18+
export default config
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
import {
2+
AgentConfig,
3+
AgentStepContext,
4+
} from '@codebuff/common/util/types/agent-config.d'
5+
6+
const config: AgentConfig = {
7+
id: 'diff-reviewer-2',
8+
displayName: 'Diff Reviewer (Level 2)',
9+
model: 'openai/gpt-5',
10+
11+
inputSchema: {
12+
prompt: {
13+
type: 'string',
14+
description:
15+
'Please provide a short description of the changes you want to review',
16+
},
17+
},
18+
toolNames: ['read_files', 'run_terminal_command'],
19+
20+
parentPrompt: 'Spawn when you need to review code changes in the git diff',
21+
22+
systemPrompt:
23+
'You are an expert software developer. Your job is to review code changes and provide helpful feedback.',
24+
25+
instructionsPrompt: `Execute the following steps:
26+
1. Run git diff
27+
2. Read the files that have changed
28+
3. Review the changes and suggest improvements
29+
30+
Use the following guidelines while reviewing the changes:
31+
- Find ways to simplify the code
32+
- Reuse existing code as much as possible instead of writing new code
33+
- Preserve as much behavior as possible in the existing code
34+
- Prefer changing as few lines of code as possible
35+
- Look for opportunities to improve the code's readability
36+
- Look for logical errors in the code
37+
- Look for missed cases in the code
38+
- Look for any other bugs`,
39+
40+
handleSteps: function* ({ agentState, prompt, params }: AgentStepContext) {
41+
// Step 1: Run git diff immediately. Saves the agent a step, lowering cost and latency!
42+
yield {
43+
toolName: 'run_terminal_command',
44+
args: {
45+
command: 'git diff',
46+
},
47+
}
48+
49+
// Step 2: Let AI run the rest of the steps!
50+
yield 'STEP_ALL'
51+
},
52+
}
53+
54+
export default config
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
import {
2+
AgentConfig,
3+
AgentStepContext,
4+
} from '@codebuff/common/util/types/agent-config.d'
5+
6+
const config: AgentConfig = {
7+
id: 'diff-reviewer-3',
8+
9+
displayName: 'Diff Reviewer (Level 3)',
10+
model: 'openai/gpt-5',
11+
inputSchema: {
12+
prompt: {
13+
type: 'string',
14+
description:
15+
'Please provide a short description of the changes you want to review',
16+
},
17+
},
18+
outputMode: 'last_message',
19+
20+
toolNames: ['read_files', 'run_terminal_command', 'spawn_agents'],
21+
subagents: ['james/file-explorer@0.1.3'],
22+
23+
parentPrompt: 'Spawn when you need to review code changes in the git diff',
24+
25+
systemPrompt:
26+
'You are an expert software developer. Your job is to review code changes and provide helpful feedback.',
27+
28+
instructionsPrompt: `Review the changes and suggest improvements.
29+
30+
Use the following guidelines while reviewing the changes:
31+
- Find ways to simplify the code
32+
- Reuse existing code as much as possible instead of writing new code
33+
- Preserve as much behavior as possible in the existing code
34+
- Prefer changing as few lines of code as possible
35+
- Look for opportunities to improve the code's readability
36+
- Look for logical errors in the code
37+
- Look for missed cases in the code
38+
- Look for any other bugs`,
39+
40+
handleSteps: function* ({ agentState, prompt, params }: AgentStepContext) {
41+
// Step 1: Get list of changed files from git diff --name-only
42+
const { toolResult: gitDiffFilesResult } = yield {
43+
toolName: 'run_terminal_command',
44+
args: {
45+
command: 'git diff --name-only',
46+
},
47+
}
48+
49+
// Then, extract file paths from the result
50+
const changedFiles = (gitDiffFilesResult || '')
51+
.split('\n')
52+
.map((line) => line.trim())
53+
.filter((line) => line && !line.startsWith('??') && !line.includes('OSC'))
54+
55+
// Step 2: Read the files
56+
if (changedFiles.length > 0) {
57+
yield {
58+
toolName: 'read_files',
59+
args: {
60+
paths: changedFiles,
61+
},
62+
}
63+
}
64+
65+
// Step 3: Run full git diff to see the actual changes
66+
yield {
67+
toolName: 'run_terminal_command',
68+
args: {
69+
command: 'git diff',
70+
},
71+
}
72+
73+
// Step 4: Put words in the AI's mouth to get it to spawn the file explorer.
74+
yield {
75+
toolName: 'add_message',
76+
args: {
77+
role: 'assistant',
78+
content:
79+
'Now I will spawn a file explorer to find any missing codebase context.',
80+
},
81+
}
82+
83+
yield 'STEP'
84+
85+
// Step 5: Put words in the AI's mouth to review the changes.
86+
yield {
87+
toolName: 'add_message',
88+
args: {
89+
role: 'assistant',
90+
content: 'Here is my comprehensive review of the changes.',
91+
},
92+
}
93+
94+
// Step 6: Let AI review the changes in a final step. (The last message is also the agent's output.)
95+
yield 'STEP'
96+
},
97+
}
98+
99+
export default config

.agents/file-explorer.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const config: AgentConfig = {
1010
parentPrompt:
1111
'Spawns multiple file picker agents in parallel to comprehensively explore the codebase from different perspectives',
1212
model: 'anthropic/claude-4-sonnet-20250522',
13-
outputMode: 'json',
13+
outputMode: 'structured_output',
1414
includeMessageHistory: false,
1515
toolNames: ['spawn_agents', 'set_output'],
1616
subagents: [`file-picker`],

0 commit comments

Comments
 (0)