Skip to content

KetanPandya/code-editing-agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 

Repository files navigation

Code Editing Agent

A powerful command-line AI agent built with Go that enables Claude to interact with your file system through a comprehensive set of tools. This agent can read, list, and edit files, making it perfect for code editing and file management tasks.

Features

🤖 AI-Powered Chat

  • Interactive chat interface with Claude 3.5 Sonnet
  • Colored output for better readability
  • Conversation memory across multiple exchanges

🛠️ File System Tools

  • Read Files: Read contents of any file in the working directory
  • List Files: Browse directories and list files recursively
  • Edit Files: Search and replace text in files with validation
  • Create Files: Automatically create new files and directories

🔧 Technical Features

  • Type-safe tool definitions with automatic JSON schema generation
  • Robust error handling and input validation
  • Cross-platform file path handling
  • Extensible tool system for adding new capabilities

Installation

Prerequisites

  • Go 1.25.1 or later
  • Anthropic API key

Setup

  1. Clone this repository:

    git clone <your-repo-url>
    cd code-editing-agent
  2. Install dependencies:

    go mod tidy
  3. Set your Anthropic API key:

    export ANTHROPIC_API_KEY="your-api-key-here"
  4. Run the agent:

    go run main.go

Usage

Once running, you can interact with the agent using natural language:

You: Read the contents of main.go
Claude: [Reads and displays the file contents]

You: List all Go files in this project
Claude: [Shows a list of .go files]

You: Replace 'fmt.Println' with 'log.Println' in main.go
Claude: [Makes the replacement and confirms success]

Available Tools

read_file

Reads the contents of a file at the specified path.

  • Parameters: path (string) - Relative path to the file

list_files

Lists files and directories at a given path.

  • Parameters: path (string, optional) - Path to list (defaults to current directory)

edit_file

Makes text replacements in files using search and replace.

  • Parameters:
    • path (string) - Path to the file
    • old_str (string) - Text to search for
    • new_str (string) - Text to replace with

Architecture

The agent is built with a clean, modular architecture:

  • Agent: Main chat loop and tool orchestration
  • Tool System: Extensible framework for adding new capabilities
  • Schema Generation: Automatic JSON schema generation using reflection
  • Error Handling: Comprehensive error handling and user feedback

Development

Adding New Tools

To add a new tool, create a new ToolDefinition:

var MyToolDefinition = ToolDefinition{
    Name:        "my_tool",
    Description: "Description of what the tool does",
    InputSchema: MyToolInputSchema,
    Function:    MyToolFunction,
}

type MyToolInput struct {
    Param1 string `json:"param1" jsonschema_description:"Description of param1"`
}

var MyToolInputSchema = GenerateSchema[MyToolInput]()

func MyToolFunction(input json.RawMessage) (string, error) {
    // Tool implementation
}

Attribution

This project was inspired by the excellent work on AI agents and tool systems. Special thanks to:

  • Agents for the Agent for inspiration on AI agent architecture and tool integration patterns
  • Anthropic for the Claude API and Go SDK
  • The Go community for excellent libraries and patterns

License

This project is open source and available under the MIT License.

Contributing

Contributions are welcome! Please feel free to submit issues, feature requests, or pull requests.

Support

If you encounter any issues or have questions, please open an issue on GitHub.

About

Building a code editing agent using go as described in the excellent https://ampcode.com/how-to-build-an-agent

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages