Skip to content

Ollama Provider ​

The Ollama provider enables local LLM inference using the Ollama platform. Run models like Llama 3, Mistral, and Gemma locally without sending data to external APIs, perfect for privacy-sensitive applications and development. The same provider reaches Ollama Cloud — the large open models Ollama serves from ollama.com, metered per token — and lists and describes the models any Ollama host serves.

Configuration ​

Basic Setup ​

Configure Ollama in your agent:

ruby
class OllamaAgent < ApplicationAgent
  generate_with :ollama, model: "deepseek-r1:latest"

  # @return [ActiveAgent::Generation]
  def ask
    prompt(message: params[:message])
  end
end

Basic Usage Example ​

ruby
response = OllamaAgent.with(
  message: "What is a design pattern?"
).ask.generate_now
Response Example

Configuration File ​

Set up Ollama in config/active_agent.yml:

yaml
ollama: &ollama
  service: "Ollama"
  model: "gpt-oss:20b"

Environment Variables ​

A local server needs no API key. The provider reads the same variables the ollama command does:

bash
OLLAMA_HOST=http://localhost:11434   # the server; a bare origin is completed to its /v1 endpoint
OLLAMA_API_KEY=...                   # Ollama Cloud, or a remote server behind an authenticating proxy

OLLAMA_HOST is read the way ollama reads it: a scheme-less host[:port] is http on port 11434, https://ollama.com is the cloud, and an explicit path (https://ai.example.com/ollama/v1, a reverse proxy) is kept. A host: given to generate_with or in config/active_agent.yml wins over the variable. OLLAMA_ACCESS_TOKEN is read as OLLAMA_API_KEY is.

Ollama Cloud ​

Ollama Cloud serves open models too large for most machines — gpt-oss:120b, kimi-k3, glm-5.3, deepseek-v4-flash, qwen3.5:397b and more — behind the same OpenAI-compatible API as a local server, metered per token. There are two ways to reach it, and the provider handles both.

Directly, with cloud: true and an API key (created at ollama.com/settings/keys), the model named as the cloud lists it:

ruby
class OllamaCloudAgent < ApplicationAgent
  generate_with :ollama, cloud: true, model: "gpt-oss:120b"

  # @return [ActiveAgent::Generation]
  def ask
    prompt(message: params[:message])
  end
end

The key comes from OLLAMA_API_KEY or api_key:; a request to the cloud without one fails before it is sent, with ActiveAgent::Providers::Errors::AuthenticationFailed naming what to set. cloud: true sends requests to https://ollama.com/v1 unless a host: is given, so a proxy in front of the cloud keeps its address.

ruby
response = OllamaCloudAgent.with(
  message: "What is a design pattern?"
).ask.generate_now