Skip to content

Commit

Permalink
refactor: improve coder agent (#131)
Browse files Browse the repository at this point in the history
  • Loading branch information
sigoden authored Nov 29, 2024
1 parent 139bd5a commit c4ba6ff
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 17 deletions.
2 changes: 1 addition & 1 deletion Argcfile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ build-declarations@tool() {
if [[ -n "$build_failed_tools" ]]; then
_die "error: invalid tools: ${build_failed_tools[*]}"
fi
json_data="$(echo "["$(IFS=,; echo "${json_list[*]}")"]" | jq '.')"
json_data="$(echo "${json_list[@]}" | jq -s '.')"
if [[ "$argc_declarations_file" == "-" ]]; then
echo "$json_data"
else
Expand Down
9 changes: 3 additions & 6 deletions agents/coder/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Coder

A AI agent that assists your coding tasks.
An AI agent that assists your coding tasks.

## Features

Expand All @@ -9,15 +9,12 @@ A AI agent that assists your coding tasks.
- 📁 Comprehensive file system operations (create folders, files, read/write files)
- 🧐 Advanced code analysis and improvement suggestions
- 📊 Precise diff-based file editing for controlled code modifications
- 🔍 Web search capabilities for up-to-date information

## Examples

![image](https://github.com/user-attachments/assets/ad9c9d94-5248-46ba-be30-cc885bda9333)
![image](https://github.com/user-attachments/assets/97324fa9-f5ea-44cd-8aea-024d1442ca81)

https://github.com/user-attachments/assets/0851b9e7-3ac5-4ec1-ab8b-d845c460446b

https://github.com/user-attachments/assets/df459938-3abf-442b-bc51-42bdb9c72c43
https://github.com/user-attachments/assets/9363990f-15a9-48c6-b227-8900cfbe0a18

## Similar Projects

Expand Down
8 changes: 3 additions & 5 deletions agents/coder/index.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: Coder
description: A AI agent that assists your coding tasks
description: An AI agent that assists your coding tasks
version: 0.1.0
instructions: |
You are an exceptional software developer with vast knowledge across multiple programming languages, frameworks, and best practices. Your capabilities include:
Expand All @@ -18,14 +18,12 @@ instructions: |
3. fs_patch: Examine and modify existing files.
4. fs_cat: View the contents of existing files without making changes.
5. fs_ls: Understand the current project structure or locate specific files.
6. web_search: Obtain current information on technologies, libraries, or best practices.
7. Analyzing images provided by the user
6. Analyzing images provided by the user
Tool Usage Guidelines:
- Always use the most appropriate tool for the task at hand.
- For file modifications, use fs_edit. Read the file first, then apply changes if needed.
- After making changes, always review the diff output to ensure accuracy.
- Proactively use web_search when you need up-to-date information or context.
Error Handling and Recovery:
- If a tool operation fails, analyze the error message and attempt to resolve the issue.
Expand All @@ -43,7 +41,7 @@ instructions: |
3. Pay close attention to existing code structure to avoid unintended alterations.
4. Review changes thoroughly after each modification.
Always strive for accuracy, clarity, and efficiency in your responses and actions. If uncertain, use the web_search tool or admit your limitations.
Always strive for accuracy, clarity, and efficiency in your responses and actions.
Answer the user's request using relevant tools (if they are available). Before calling a tool, do some analysis within <thinking></thinking> tags. First, think about which of the provided tools is the relevant tool to answer the user's request. Second, go through each of the required parameters of the relevant tool and determine if the user has directly provided or given enough information to infer a value. When deciding if the parameter can be inferred, carefully consider all the context to see if it supports a specific value. If all of the required parameters are present or can be reasonably inferred, close the thinking tag and proceed with the tool call. BUT, if one of the values for a required parameter is missing, DO NOT invoke the function (not even with fillers for the missing params) and instead, ask the user to provide the missing parameters. DO NOT ask for more information on optional parameters if it is not provided.
Expand Down
3 changes: 1 addition & 2 deletions agents/coder/tools.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
fs_mkdir.sh
fs_ls.sh
fs_patch.sh
fs_cat.sh
web_search.sh
fs_cat.sh
6 changes: 3 additions & 3 deletions utils/patch.awk
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ END {
}

if (mode == "hunk") {
while (patchLineIndex <= totalPatchLines && line ~ /^[-+ ]/ && line !~ /^--- /) {
while (patchLineIndex <= totalPatchLines && line ~ /^[-+ ]|^\s*$/ && line !~ /^--- /) {
sanitizedLine = substr(line, 2)
if (line !~ /^\+/) {
hunkTotalOriginalLines[hunkIndex]++;
Expand Down Expand Up @@ -68,7 +68,7 @@ END {
line = lines[lineIndex]
nextLineIndex = 0

if (line == hunkOriginalLines[hunkIndex,1]) {
if (hunkIndex <= totalHunks && line == hunkOriginalLines[hunkIndex,1]) {
nextLineIndex = lineIndex + 1
for (i = 2; i <= hunkTotalOriginalLines[hunkIndex]; i++) {
if (lines[nextLineIndex] != hunkOriginalLines[hunkIndex,i]) {
Expand All @@ -83,7 +83,7 @@ END {
print hunkUpdatedLines[hunkIndex,i]
}
hunkIndex++
lineIndex = nextLineIndex -1;
lineIndex = nextLineIndex - 1;
} else {
print line
}
Expand Down

0 comments on commit c4ba6ff

Please sign in to comment.