Gemini Agent

Google Gemini CLI agent integration for Spring AI Bench.

1. Overview

The Gemini agent provides integration with Google’s Gemini models through the Spring AI Agents framework.

  • AI-Powered - Uses Google’s Gemini models for task execution

  • JBang Integration - Seamless execution via JBang launcher

  • Provider Selection - Can be used as a provider for hello-world-ai agent

  • Autonomous Operation - Executes tasks without manual intervention

2. Prerequisites

2.1. API Key Setup

# Set your Google Gemini API key
export GEMINI_API_KEY=your-gemini-api-key

# Verify key is set
echo $GEMINI_API_KEY

2.2. Agent Availability

The Gemini agent is integrated through the Spring AI Agents framework:

# Verify spring-ai-agents is built locally
ls -la /home/mark/community/spring-ai-agents/jbang/launcher.java

3. Configuration

3.1. Basic Agent Specification

agent:
  kind: gemini
  model: gemini-2.0-flash-exp
  autoApprove: true
  prompt: |
    Create a Java class that implements a simple calculator.
    Include basic arithmetic operations and unit tests.

3.2. Advanced Configuration

agent:
  kind: gemini
  model: gemini-2.0-flash-exp
  autoApprove: true
  genParams:
    temperature: 0.7
    max_tokens: 2048
  extras:
    yolo: true          # Enable autonomous mode
    provider: gemini    # Specify provider explicitly
  prompt: |
    This Spring Boot application needs refactoring.

    Tasks:
    1. Improve code structure and organization
    2. Add proper error handling
    3. Include comprehensive tests
    4. Follow Spring Boot best practices

4. Features

4.1. Task Execution

The Gemini provider handles various development tasks:

  • File Operations - Create and modify files as needed

  • Code Generation - Generate code based on natural language prompts

  • Task Automation - Execute multi-step workflows autonomously

4.2. Framework Integration

  • Spring AI Agents - Uses the unified agent framework

  • JBang Launcher - Executes via JBang command-line interface

  • Provider Model - Works as a pluggable provider implementation

5. Integration with Spring AI Bench

5.1. Performance Comparison

Recent benchmark results for hello-world task across different implementations:

Implementation Duration Performance Ratio

hello-world (deterministic)

115 ms

1x (baseline)

hello-world-ai (Gemini provider)

5.3 seconds

46x slower

hello-world-ai (Claude provider)

99 seconds

862x slower

5.2. Multi-Agent Testing

Run comparative benchmarks:

# Single Gemini test
./mvnw test -Dtest=HelloWorldAIIntegrationTest -pl bench-agents

# Multi-agent comparison
./mvnw test -Dtest=HelloWorldMultiAgentTest -pl bench-agents

6. Best Practices

6.1. Prompt Design

Effective prompts for Gemini:

# Good prompt - clear and specific
prompt: |
  Create a REST controller for user management.

  Requirements:
  - CRUD operations for User entity
  - Input validation with Bean Validation
  - Proper HTTP status codes
  - Exception handling with @ControllerAdvice

  Use Spring Boot 3.x conventions.
# Avoid - too vague
prompt: "Make a user controller"

6.2. Configuration Tips

  • Temperature Settings - Adjust temperature for different task types

  • Token Limits - Set appropriate max_tokens based on expected output

  • Model Selection - Use gemini-2.0-flash-exp for current integration

  • Provider Parameter - Specify provider: gemini in agent configuration

7. Troubleshooting

7.1. Common Issues

7.1.1. API Key Problems

# Check API key configuration
echo $GEMINI_API_KEY

# Test key validity (if you have gcloud CLI)
gcloud auth application-default print-access-token

7.1.2. Integration Issues

# Verify spring-ai-agents installation
jbang --version
ls -la /home/mark/community/spring-ai-agents/jbang/launcher.java

# Test JBang launcher
jbang /home/mark/community/spring-ai-agents/jbang/launcher.java hello-world-agent-ai --help

7.2. Debug Mode

Enable detailed logging:

# Run with verbose output
./mvnw test -Dtest=HelloWorldAIIntegrationTest -pl bench-agents -X

# Check specific Gemini logs
grep -i gemini /tmp/bench-reports/{run-id}/run.log

8. Next Steps