Skip to content

Commit 951a66f

Browse files
ghuntleyampcode-com
andcommitted
Add code search agent with ripgrep integration
- Created code_search_tool.go based on edit_tool.go structure - Replaced edit_file tool with code_search tool using ripgrep - Added support for pattern matching, file type filtering, and case sensitivity - Updated README.md to document the new 6th application in the progression - Added usage examples and documentation for code search capabilities Co-authored-by: Amp <[email protected]> Amp-Thread-ID: https://ampcode.com/threads/T-2857e4e8-8aa6-4c8a-96fc-1de031aa7031
1 parent 9e354ea commit 951a66f

File tree

2 files changed

+536
-12
lines changed

2 files changed

+536
-12
lines changed

README.md

Lines changed: 67 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
# How to Build an Agent - Workshop
1+
# How to Build a Coding Agent - Workshop
2+
3+
A hands-on workshop for learning how to build AI agents with progressively increasing capabilities. This repository contains six different agent implementations that demonstrate the evolution from a simple chat interface to a fully capable agent with file system access, code search, and tool execution.
4+
25

3-
A hands-on workshop for learning how to build AI agents with progressively increasing capabilities. This repository contains five different agent implementations that demonstrate the evolution from a simple chat interface to a fully capable agent with file system access and tool execution.
46

57
## 🎯 Learning Objectives
68

@@ -55,7 +57,7 @@ graph TB
5557

5658
## 📚 Application Progression
5759

58-
The workshop is structured as a progression through five applications, each building upon the previous one's capabilities:
60+
The workshop is structured as a progression through six applications, each building upon the previous one's capabilities:
5961

6062
```mermaid
6163
graph LR
@@ -64,20 +66,23 @@ graph LR
6466
B --> C[list_files.go<br/>+ Directory Listing]
6567
C --> D[bash_tool.go<br/>+ Shell Commands]
6668
D --> E[edit_tool.go<br/>+ File Editing]
69+
E --> F[code_search_tool.go<br/>+ Code Search]
6770
end
6871
6972
subgraph "Tool Capabilities"
70-
F[No Tools] --> G[read_file]
71-
G --> H[read_file<br/>list_files]
72-
H --> I[read_file<br/>list_files<br/>bash]
73-
I --> J[read_file<br/>list_files<br/>bash<br/>edit_file]
73+
G[No Tools] --> H[read_file]
74+
H --> I[read_file<br/>list_files]
75+
I --> J[read_file<br/>list_files<br/>bash]
76+
J --> K[read_file<br/>list_files<br/>bash<br/>edit_file]
77+
K --> L[read_file<br/>list_files<br/>bash<br/>code_search]
7478
end
7579
76-
A -.-> F
77-
B -.-> G
78-
C -.-> H
79-
D -.-> I
80-
E -.-> J
80+
A -.-> G
81+
B -.-> H
82+
C -.-> I
83+
D -.-> J
84+
E -.-> K
85+
F -.-> L
8186
```
8287

8388
### 1. Basic Chat (`chat.go`)
@@ -168,6 +173,26 @@ go run edit_tool.go
168173
# Try: "Add a comment to the top of fizzbuzz.js"
169174
```
170175

176+
### 6. Code Search Agent (`code_search_tool.go`)
177+
**Purpose**: Powerful code search capabilities using ripgrep
178+
179+
**Features**:
180+
- Everything from `list_files.go` and `bash_tool.go`
181+
- `code_search` tool for finding code patterns
182+
- Ripgrep integration for fast searching
183+
- File type filtering and case sensitivity options
184+
- Pattern matching with regex support
185+
186+
**Key Learning**: Code discovery, pattern matching, and search optimization.
187+
188+
**Usage**:
189+
```bash
190+
go run code_search_tool.go
191+
# Try: "Find all function definitions in Go files"
192+
# Try: "Search for TODO comments in the codebase"
193+
# Try: "Find where the Agent struct is defined"
194+
```
195+
171196
## 🛠️ Tool System Architecture
172197

173198
The tool system uses a consistent pattern across all applications:
@@ -208,11 +233,19 @@ classDiagram
208233
+NewStr: string
209234
}
210235
236+
class CodeSearchInput {
237+
+Pattern: string
238+
+Path: string
239+
+FileType: string
240+
+CaseSensitive: bool
241+
}
242+
211243
Agent --> ToolDefinition : uses
212244
ToolDefinition --> ReadFileInput : read_file
213245
ToolDefinition --> ListFilesInput : list_files
214246
ToolDefinition --> BashInput : bash
215247
ToolDefinition --> EditFileInput : edit_file
248+
ToolDefinition --> CodeSearchInput : code_search
216249
```
217250

218251
## 🚀 Setup
@@ -264,6 +297,23 @@ result: I have a mane but I'm not a lion...
264297
Claude: This is a riddle! The answer is "a horse"...
265298
```
266299
300+
### Code Search Operations
301+
```bash
302+
$ go run code_search_tool.go
303+
Chat with Claude (use 'ctrl-c' to quit)
304+
You: Find all function definitions in Go files
305+
tool: code_search({"pattern":"func ","file_type":"go"})
306+
result: edit_tool.go:20:func main() {
307+
edit_tool.go:58:func NewAgent(
308+
edit_tool.go:323:func ReadFile(input json.RawMessage) (string, error) {
309+
Claude: I found several function definitions across the Go files...
310+
311+
You: Search for TODO comments
312+
tool: code_search({"pattern":"TODO","case_sensitive":false})
313+
result: No matches found
314+
Claude: There are no TODO comments in the current codebase.
315+
```
316+
267317
### Debugging with Verbose Mode
268318
```bash
269319
$ go run edit_tool.go --verbose
@@ -328,6 +378,11 @@ hello # Custom greeting script
328378
2. Understand validation and safety measures
329379
3. Build complete agent workflows
330380
381+
### Phase 6: Advanced Code Discovery
382+
1. Use `code_search_tool.go` for powerful code searching
383+
2. Learn ripgrep integration and pattern matching
384+
3. Practice efficient code discovery and analysis
385+
331386
## 🔍 Key Concepts Demonstrated
332387
333388
### Event Loop Pattern

0 commit comments

Comments
 (0)