Skip to content

kodi73/codecrafters-claude-code-java

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Java AI Agent with Tool Use

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.

Features

  • 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

Requirements

  • Java 17 or higher
  • Maven
  • OpenRouter API key

Setup

  1. Clone the repository
  2. Replace the API key in Main.java with your OpenRouter API key
  3. Build the project with Maven

Usage

Run the program with a prompt using the -p flag: ./your_program.sh -p "Your prompt here"

Examples

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"

How It Works

  1. The user prompt is added to the message history
  2. The model is called with the Read and Write tools available
  3. If the model requests a tool call, the tool is executed and the result is added to the message history
  4. The loop repeats until the model responds with no tool calls
  5. The final text response is printed to stdout

Model

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.

About

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.

Topics

Resources

Stars

Watchers

Forks

Contributors