# Portability: UNIVERSAL
# Last validated: 2026-05-17
# Next review: 2027-05-17

BACH OLLAMA INTEGRATION
-----------------------
Local LLM server for token saving mode and offline use.

COMMANDS
-------
bach ollama status           Check connection, installed models
bach ollama ask "prompt"     Direct request to Ollama
bach ollama embed "text"     Generate embedding
bach ollama models           List available models

OPTIONS
--------
--model=NAME Select model (default: llama3.2)

EXAMPLES
---------
# Check status
bach ollama status

# Simple question
bach ollama ask "Was ist BACH?" --model=llama3.2

# Delegate code review
bach ollama ask "Review diesen Code: def add(a,b): return a+b"

# Embedding for search
bach ollama embed "Suchtext fuer RAG"

INTEGRATION WITH PARTNER SYSTEM
------------------------------
Ollama is registered as a local partner and is automatically
preferred for high token consumption:

Zone 3 (60-80% tokens): Ollama is preferred
Zone 4 (80-100%): Human/emergency only (Ollama still possible)

Automatic delegation:
  bach partner delegate "Task" --to=ollama

Fallback in case of network problems:
  bach ollama ask "Task"   (direct local execution)

REQUIREMENTS
---------------
- Ollama must be installed locally
- Default port: http://localhost:11434
- At least one model must be pulled

Check installation:
  ollama --version
  ollama list

Install model:
  ollama pull llama3.2
  ollama pull codellama

TROUBLESHOOTING
---------------
Error: "Connection refused"
  → Start Ollama server: ollama serve
  → Check port: http://localhost:11434

Error: “Model not found”
  → Pull model: ollama pull llama3.2
  → Check model names: ollama list

Slow answers:
  → Choose a smaller model (llama3.2 instead of llama3.1:70b)
  → Check GPU usage (CUDA/Metal)

Memory problems:
  → Use a smaller model
  → Unload other models: ollama stop

CONFIGURATION
-------------
Ollama settings in BACH:
  - Partner ID: ollama
  - Type: local
  - Standard model: llama3.2 (configurable)
  - Timeout: 120 seconds

Adjustment via:
  bach partner info ollama

SEE ALSO
----------
bach help partner          Partner system overview
bach help delegate         Task delegation
bach help tools            Tool inventory (ollama_client.py)
