Skip to content

master-of-null/go-coding-agent

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go Coding Agent

A simple AI coding agent built in Go that can read, list, and edit files using Claude 3.7 Sonnet. This agent demonstrates how AI can interact with your local filesystem to help you with coding tasks.

Prerequisites

  • Go installed on your system (version 1.21+ recommended)
  • An Anthropic API key for Claude 3.7 Sonnet

Setup

  1. Clone this repository:

    git clone https://github.com/yourusername/go-coding-agent.git
    cd go-coding-agent
    
  2. Set your Anthropic API key in one of these ways:

    • Edit the .env file with your API key:

      ANTHROPIC_API_KEY="your-api-key-here"
      
    • Or set it as an environment variable:

      export ANTHROPIC_API_KEY="your-api-key-here"
      
  3. Install dependencies:

    go mod tidy
    
  4. Run the agent:

    ./run.sh
    

    Or directly with Go:

    go run main.go
    

Features

This agent can:

  • List files (list_files): View files and directories in your workspace
  • Read files (read_file): View the contents of any text file
  • Edit files (edit_file): Modify existing files or create new ones

Example Usage

Once the agent is running, you can ask it to perform tasks like:

What files are in this directory?

The agent will use the list_files tool to show you all files in the current directory.

Create a file called hello.js that prints "Hello, world!" to the console

The agent will create a new JavaScript file with appropriate code.

Show me what's in the main.go file

The agent will read and display the contents of main.go.

Edit the README.md file to add a license section at the end

The agent will append a license section to the README.md file.

Create a Python script that calculates Fibonacci numbers

The agent will create a new Python file with a Fibonacci implementation.

The agent will automatically decide which tools to use to accomplish each task based on your request.

For more examples, check out the examples/example.md file in this repository.

How It Works

The coding agent is built with:

  1. Tool-Based Architecture:

    • Each capability (reading files, listing directories, editing files) is implemented as a "tool"
    • The agent receives a description of available tools and decides when to use them
    • Each tool has a name, description, input schema, and function implementation
  2. Claude Integration:

    • Uses Claude 3.7 Sonnet via the Anthropic SDK for Go
    • The model autonomously decides when to use tools based on your requests
    • Conversation history is maintained throughout the session
  3. File System Interaction:

    • File operations are performed safely with error handling
    • The agent can create, read, and modify files in your local filesystem
    • String replacement is used for file editing to keep the implementation simple

Project Structure

  • main.go - Main application code including tool definitions and Claude integration
  • go.mod and go.sum - Go module definition and dependencies
  • .env - Environment variables for API keys
  • run.sh - Convenience script to run the agent

Future Improvements

The current implementation is intentionally minimal (under 400 lines of code). Here are potential areas for enhancement:

  1. Additional Tools:

    • Add a run_code tool to execute scripts and display output
    • Add a search_code tool to find patterns across multiple files
    • Add git integration for version control operations
  2. Better File Editing:

    • Implement more sophisticated editing capabilities beyond string replacement
    • Add support for structural code transformations
    • Add a diff preview before applying changes
  3. Enhanced Security:

    • Add a confirmation prompt before file modifications
    • Implement sandbox restrictions for file operations
    • Add allowlist/denylist for file locations and operations
  4. UI Improvements:

    • Create a web interface or terminal UI
    • Add syntax highlighting for code display
    • Implement a better conversation history viewer
  5. Performance Enhancements:

    • Add caching for model responses
    • Implement streaming responses for large file operations
    • Optimize token usage for longer conversations
  6. Multi-Agent Coordination:

    • Allow multiple specialized agents to collaborate
    • Implement a coordinator agent to delegate tasks

License

MIT

Acknowledgements

This project was inspired by the "How to Build an Agent" guide by Thorsten Ball and the team at Amp.

About

Coding Agent using Claude, implemented in Go

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published