This project is strongly based on the tutorial from How to Build an Agent. However, this implementation uses the Gemini model instead of Anthropic's.
This project implements a coding agent powered by the Gemini language model. The agent can perform the following actions:
- Read files
- List files in a directory
- Edit files
The agent takes user input from the console, sends it to Gemini, and then executes tool calls based on Gemini's response. The results of the tool calls are then sent back to Gemini to refine its response. This process continues until the agent has completed the user's request.
main.go: The entry point of the application. It initializes the Gemini client, sets up the available tools, and starts the agent's main loop.agent/agent.go: This file contains theAgentstruct and its methods. TheAgentstruct holds the Gemini client, a function to get user input, and the available tools. TheRunmethod is the main loop of the agent.tools/tools.go: This file defines theToolDefinitionstruct and related helper functions. It includes functions to generate JSON schemas for tools and to convert the tool definitions into a format that Gemini can understand.tools/editFile.go: This file defines theedit_filetool, which allows the agent to edit files. It takes the file path, the old string to replace, and the new string as input.tools/listFiles.go: This file defines thelist_filestool, which allows the agent to list files in a directory. It takes an optional path as input; if no path is provided, it lists the files in the current directory.tools/readFile.go: This file defines theread_filetool, which allows the agent to read the contents of a file. It takes the file path as input.
- Set the
GENAI_API_KEYenvironment variable to your Gemini API key. - Run
go run main.goto start the agent.
Type your instructions into the console, and the agent will attempt to follow them, using the available tools as needed.