# Skill: Configure Ollama

Use when you want to run models locally — no API key, no cost, no data leaving your machine.
Good for: development without API costs, air-gapped environments, private data pipelines.

## Prerequisites

Ollama must be installed and running on the machine where arccrew runs.

```bash
# Install Ollama (macOS/Linux)
curl -fsSL https://ollama.com/install.sh | sh

# Start the Ollama server (keep this running)
ollama serve

# Pull a model
ollama pull llama3.2
```

Download Ollama: https://ollama.com

## Install the LangChain Integration

```bash
pip install langchain-ollama
```

## Model Strings

```bash
# Lightweight — fast on CPU, minimal RAM
AGENT_MODEL=ollama/llama3.2:1b      # 1B params — very fast, basic tasks
AGENT_MODEL=ollama/gemma3:1b        # Google Gemma 1B
AGENT_MODEL=ollama/phi4-mini        # Microsoft Phi-4 Mini, punches above its size

# Capable — requires decent GPU or fast CPU
AGENT_MODEL=ollama/llama3.2         # Llama 3.2 3B — good default
AGENT_MODEL=ollama/llama3.1:8b      # Llama 3.1 8B — strong general model
AGENT_MODEL=ollama/mistral          # Mistral 7B — solid for tool calling
AGENT_MODEL=ollama/qwen2.5          # Qwen 2.5 7B — good multilingual

# Code
AGENT_MODEL=ollama/codellama        # Meta CodeLlama — code generation
AGENT_MODEL=ollama/qwen2.5-coder    # Qwen Coder — strong at code tasks

# Large (GPU recommended)
AGENT_MODEL=ollama/llama3.1:70b     # Llama 3.1 70B — near-frontier quality
AGENT_MODEL=ollama/qwen2.5:72b      # Qwen 72B — strong at reasoning
```

Full model library: https://ollama.com/library

## Configuration

```bash
# .env
AGENT_MODEL=ollama/llama3.2
```

No API key needed. arccrew passes `ollama:llama3.2` to LangChain's `init_chat_model`
which uses `langchain-ollama` to connect to the local Ollama server at
`http://localhost:11434`.

## Custom Ollama Host

If Ollama runs on a different host (e.g., a GPU server):

```bash
# In your agent's __init__, set the base_url explicitly
from langchain_ollama import ChatOllama

self.model = ChatOllama(
    model="llama3.1:8b",
    base_url="http://gpu-server:11434",
)
```

Or set the `OLLAMA_HOST` environment variable before starting arccrew:
```bash
OLLAMA_HOST=http://gpu-server:11434 arccrew serve
```

## Per-Agent Overrides

```bash
# .env — use Ollama for cheap agents, Claude for critical ones
AGENT_MODEL=anthropic/claude-haiku-4-5-20251001   # default

CLASSIFIER_MODEL=ollama/llama3.2                   # local, free
FORMATTER_MODEL=ollama/llama3.2                    # local, free
WRITER_MODEL=anthropic/claude-sonnet-4-20250514    # quality matters here
```

Add per-agent fields to `arccrew/config.py` → `Settings`:
```python
classifier_model: str = ""
formatter_model: str = ""
writer_model: str = ""
```

## Model Recommendations by Task

| Task | Recommended | RAM needed |
|------|-------------|------------|
| Simple tool calls, classification | `llama3.2` / `phi4-mini` | 4–8 GB |
| General research / summarization | `llama3.1:8b` / `mistral` | 8–16 GB |
| Code generation | `qwen2.5-coder` / `codellama` | 8–16 GB |
| Complex reasoning (local) | `llama3.1:70b` / `qwen2.5:72b` | 48+ GB |

## Limitations vs API Models

- **Slower** — local inference is slower than API calls, especially without GPU
- **No streaming parallelism** — concurrent agents share the same local GPU/CPU
- **Smaller context windows** — most local models max out at 8k–32k tokens
- **Tool calling quality** — smaller models are less reliable at structured JSON output;
  use `circuit_breaker_errors=3` (already default) to recover from malformed responses

## Verify Configuration

```bash
# Check Ollama is running
curl http://localhost:11434/api/tags

# Check arccrew config
arccrew check
```

Common errors:
- `Connection refused` → Ollama is not running, run `ollama serve`
- `model not found` → Pull the model first: `ollama pull llama3.2`
- `langchain_ollama not found` → `pip install langchain-ollama`
