# Skill: Configure Google Gemini

Use when you want to use Google's Gemini models as your LLM provider.
Gemini's standout feature is its 1M token context window, making it ideal for
long-document processing agents.

## API Key Setup

### Step 1: Get the Key

Get your Google AI API key at: https://aistudio.google.com/app/apikey

### Step 2: Add to `.env`

```bash
# .env
GOOGLE_API_KEY=AIzaSy...
```

### Step 3: Set `GOOGLE_API_KEY` in `.env`

`langchain-google-genai` reads `GOOGLE_API_KEY` directly from `os.environ`. Since you
already set it in `.env` in Step 2 and pydantic-settings loads `.env` on startup, the key
will be available automatically — no code changes needed.

### Step 4: Install the Package

```bash
pip install langchain-google-genai
```

## Model Strings

```bash
AGENT_MODEL=google_genai/gemini-2.0-flash           # Fast, cheap, 1M context
AGENT_MODEL=google_genai/gemini-2.5-pro             # Most capable, best reasoning
AGENT_MODEL=google_genai/gemini-2.5-flash-thinking  # Flash with extended thinking
```

## Model Comparison

### Gemini 2.0 Flash
```
google_genai/gemini-2.0-flash
```
- **Speed/cost profile**: equivalent to Claude Haiku or GPT-4o-mini
- **Context window**: 1,000,000 tokens (1M)
- **Best for**: tool-calling agents, research agents, fast iteration
- **Key advantage**: the 1M context window lets it read entire codebases or document sets

### Gemini 2.5 Pro
```
google_genai/gemini-2.5-pro
```
- **Speed/cost profile**: equivalent to Claude Sonnet or GPT-4o
- **Context window**: 1,000,000 tokens (1M)
- **Best for**: complex reasoning, long-form synthesis, agentic tasks
- **Key advantage**: strongest reasoning at Gemini-class speed

### Gemini 2.5 Flash Thinking
```
google_genai/gemini-2.5-flash-thinking
```
- Extended thinking variant of Flash
- Shows reasoning traces internally before answering
- Good for: problems that benefit from step-by-step reasoning without full Pro cost

## Flash vs Pro Decision Guide

| Scenario | Use |
|----------|-----|
| Research agent calling `web_search` many times | Flash — speed matters more than reasoning depth |
| Writer agent producing long structured content | Pro — better at multi-step composition |
| Reviewer agent checking output quality | Flash — short task, judgment over speed |
| Long-document analysis (>100K tokens of input) | Either — both have 1M context |
| Code generation and explanation | Pro — stronger code reasoning |
| Prototyping a new pipeline | Flash — cheap iteration |

## Using Gemini's 1M Context Window

Gemini's biggest differentiator is the context window. Use it for agents that need to
process large documents:

```python
class DocumentAnalystAgent(BaseAgent):
    def __init__(self):
        super().__init__(name="doc_analyst", prompts_dir=PROMPTS_DIR)

    @track_timing
    async def execute(self, state: dict) -> Command:
        # Read a large document into the task directly
        large_doc = Path(state.get("workspace_dir", "tmp")) / "large_report.txt"
        content = large_doc.read_text() if large_doc.exists() else ""

        result = await self.generate(
            f"Analyze this entire document and extract key themes:\n\n{content}"
        )
        data = self.extract_json(result) or {"raw": result}
        return Command(goto="next", update={"result": data})
```

Set `DOC_ANALYST_MODEL=google_genai/gemini-2.0-flash` in `.env` — only this agent uses Gemini
while others use your default model.

## Per-Agent Gemini Override

To use Gemini for only one specific agent while others use Claude:

```bash
# .env
AGENT_MODEL=anthropic/claude-haiku-4-5-20251001    # default
DOC_ANALYST_MODEL=google_genai/gemini-2.0-flash    # this agent uses Gemini
```

Add `doc_analyst_model` to `Settings` in `arccrew/config.py`:
```python
class Settings(BaseSettings):
    doc_analyst_model: str = ""
```

## Verify Configuration

```bash
arccrew check
```

If it prints a model initialization error mentioning `google_genai`, check:
1. `GOOGLE_API_KEY` is in `.env`
2. `langchain-google-genai` is installed
