Ollama provider added: local models with document preloading
brauliogusmao wired Ollama in as a fourth LLM backend alongside Claude, OpenAI, and Gemini. The key design decision: instead of letting local models call document-fetch tools reactively, the adapter preloads document content into the system prompt before the first LLM call.
The implementation is a 309-line streaming adapter in backend/src/lib/llm/ollama.ts plus routing, a model-discovery endpoint, and frontend model-picker changes. Model IDs use an ollama/ prefix -- providerForModel() checks for this prefix and routes accordingly, and resolveModel() lets ollama/* IDs bypass the static model allowlist.
A GET /ollama/models route proxies the local Ollama instance's model list to the frontend. The model picker's "Local (Ollama)" group populates from this at runtime, so it only appears when Ollama is running and has at least one model installed. The OLLAMA_URL env var (defaulting to http://localhost:11434) controls which Ollama instance the backend talks to.
The document-preloading strategy is the most opinionated part. Two tools -- read_document and fetch_documents -- are in a CONTEXT_TOOLS set. When either fires, the adapter injects the result into the system prompt and removes the tool from the list so the model can't call it again. Smaller local models are unreliable at reactive tool use, so the adapter front-loads what they'll need rather than hoping they ask for it correctly.
Existing remote-provider flows are untouched. The integration adds a new branch in the dispatcher; nothing in the Claude or OpenAI paths changed.
Spotted something wrong? Or know the PR text has fresher detail than the writeup above?