A Java-based conversational AI agent that supports multiple AI providers (Anthropic Claude and Google Gemini), following Thorsten Ball's tutorial at How to Build an Agent. This application provides both CLI and web interfaces for interacting with AI models.
- Total Commits: 64
- AI-Assisted Commits: 44 (68.75%)
- Total Lines Added: 9216
- AI-Assisted Lines Added: 7545 (81.87%)
- Total Lines Changed: 13659
- AI-Assisted Lines Changed: 11254 (82.39%)
- Commits: 34 (53.12%)
- Lines Added: 6182
- Lines Deleted: 2794
- Lines Changed: 8976 (65.71%)
- Commits: 8 (12.50%)
- Lines Added: 1292
- Lines Deleted: 841
- Lines Changed: 2133 (15.62%)
- Commits: 2 (3.12%)
- Lines Added: 71
- Lines Deleted: 74
- Lines Changed: 145 (1.06%)
Statistics are automatically updated on each commit.
- Multi-Provider Support: Choose between Anthropic Claude and Google Gemini
- Dual Interface Support: Run as a command-line application or web server
- File Operations: Built-in tools for reading, editing, and listing files (supports both Claude and Gemini)
- Test Execution: Run all Gradle tests with detailed output (1-minute timeout)
- Clean Architecture: Hexagonal architecture with clear separation of concerns
- Hot Reloading: Development server with automatic restart and live reload
- Separate Logging: Mode-specific log files (CLI:
logs/application-cli.log
, Web:logs/application-web.log
) - Simple Launchers: Clean scripts for both CLI (
./cli-app.sh
) and web (./dev-server.sh
) modes - Comprehensive Testing: Full test suite with JUnit 5
- Java 24 or higher
- Gradle (wrapper included)
- API Key: Either Anthropic API Key (for Claude) or Google API Key (for Gemini)
Get an API key from Anthropic's Console.
export code_editing_agent_api_key="your-api-key-here"
Get an API key from Google AI Studio.
export GOOGLE_API_KEY="your-api-key-here"
export AI_PROVIDER=gemini
git clone <repository-url>
cd code-editing-agent-java
./run_build.sh
To automatically update AI contribution statistics in the README:
./scripts/install-hooks.sh
./cli-app.sh
./dev-server.sh start
Then open http://localhost:8080 in your browser to access the chat interface.
For active development with hot reloading:
# Start development server (web mode with auto-restart)
./dev-server.sh start
# Check status
./dev-server.sh status
# View logs
./dev-server.sh logs
# Stop server
./dev-server.sh stop
# Run all tests with formatted output
./run_tests.sh
# Run specific test class
./gradlew test --tests "ConversationServiceTest"
# Build and run tests
./run_build.sh
- Start CLI:
./cli-app.sh
(builds and runs interactively) - View CLI logs:
tail -f logs/application-cli.log
- Start dev server:
./dev-server.sh start
(with hot reloading) - Stop dev server:
./dev-server.sh stop
- View web logs:
./dev-server.sh logs
- Build:
./run_build.sh
(applies formatting and builds - recommended) - Alternative build:
./gradlew build
(includes fatJar creation) - Test:
./run_tests.sh
(runs tests with formatted output) - Clean:
./gradlew clean
- Fat JAR: Created automatically during build in
app/build/libs/
This application follows hexagonal architecture principles:
- ConversationService: Handles Claude API communication
- ChatService: Orchestrates conversation flow
- ConversationContext: Domain model for conversation history
- Tool System: Extensible file operation tools (read, edit, list)
- CLI Adapters: Console-based I/O using Scanner and System.out
- Web Adapters: Spring Boot REST API with HTML chat interface
The agent comes with these built-in tools:
- ReadFileTool: Read file contents with encoding support
- EditFileTool: Modify existing files with automatic backup creation
- ListFilesTool: Browse directory contents with hidden file options
- RunTestsTool: Execute all Gradle tests (1-minute timeout)
Note: All tools are available for both Anthropic Claude and Google Gemini providers.
Security Note: These file tools are designed exclusively for CLI mode where they operate on the user's local file system. In web mode, these tools would pose serious security risks by allowing web users to access the server's file system. A proper web implementation would require either disabling file tools entirely or implementing sandboxed alternatives.
code_editing_agent_api_key
: Required for Claude - Your Anthropic API keyGOOGLE_API_KEY
: Required for Gemini - Your Google API keyAI_PROVIDER
: Optional - Set to "gemini" to use Gemini (default: Claude)app.mode
: Optional - Set to "web" for web mode (default: CLI)
The application uses Claude 3.5 Haiku by default.
You can modify the model in ConversationService.java:66
.
app/src/main/java/com/larseckart/
├── App.java # Application entry point
├── adapters/
│ ├── cli/ # Command-line interface
│ └── web/ # Web interface (Spring Boot)
├── core/
│ ├── domain/ # Domain models
│ ├── ports/ # Interface definitions
│ ├── services/ # Business logic
│ └── tools/ # File operation tools
└── resources/
└── static/index.html # Web interface
$ ./cli-app.sh
Building application...
Starting CLI application...
Chat with a LLM (use 'ctrl-c' to quit or press Enter on empty line)
You: Can you read the contents of my config file?
TheAgent: I can help you read a file. What's the path to your config file?
You: ./app.properties
TheAgent: [Reads and displays file contents]
- Start:
./dev-server.sh start
- Open: http://localhost:8080
- Chat through the web interface
- Anthropic Java SDK 2.0.0 - Claude API integration
- Google Gen AI Java SDK 1.5.0 - Gemini API integration
- Spring Boot 3.5.0 - Web framework
- JUnit 5 - Testing framework
- Java 24 - Runtime platform
- Missing API Key: Ensure
code_editing_agent_api_key
is set - Java Version: Requires Java 24 or higher
- Port Conflicts: Web mode uses port 8080 by default