A Java-based AI agent that uses the OpenRouter API to interact with language models capable of tool use. The agent can read and write files autonomously by exposing tools to the model and executing them in an agentic loop.
- Agentic loop that continues until the model stops requesting tools
- Read tool: reads file contents and returns them to the model
- Write tool: creates or overwrites files with model-generated content
- Multi-turn conversation history maintained across tool calls
- Works with any OpenRouter-compatible model that supports tool use
- Java 17 or higher
- Maven
- OpenRouter API key
- Clone the repository
- Replace the API key in Main.java with your OpenRouter API key
- Build the project with Maven
Run the program with a prompt using the -p flag: ./your_program.sh -p "Your prompt here"
Ask the agent to read a file: ./your_program.sh -p "Read README.md and summarize it"
Ask the agent to create a file based on instructions: ./your_program.sh -p "Read README.md and create the indicated file"
- The user prompt is added to the message history
- The model is called with the Read and Write tools available
- If the model requests a tool call, the tool is executed and the result is added to the message history
- The loop repeats until the model responds with no tool calls
- The final text response is printed to stdout
Currently configured to use google/gemini-2.0-flash-001 via OpenRouter, which has reliable tool use support. Everything is plain text with no inline bold, italics, or tables — just headings and code blocks which render automatically in any Markdown viewer and are easy to read even as raw text.