2 Commits
Author SHA1 Message Date
sausheong 50b791d3b6 Rename providers/ollama to providers/local
Ollama is one local-model server among several (LM Studio, llama.cpp's
server, vLLM, ...) that all speak the same OpenAI-compatible shape —
naming the package (and provider name downstream) after one of them
was misleading. Same constructor, same default endpoint (Ollama's,
being the most common), just generically named: NewLocalProvider.

This renames a package published minutes ago in v0.3.8 with no other
known consumers yet, so no compatibility shim is kept.
2026-09-07 13:27:58 +08:00
sausheong 3b5aadb31f Add an ollama provider for local models
Thin constructor over the existing OpenAI-compatible path, same shape
as litellm/openrouter: NewOllamaProvider(baseURL) defaults to Ollama's
local endpoint (http://localhost:11434/v1) and needs no API key, since
Ollama doesn't authenticate requests. Also covers other local servers
that share Ollama's OpenAI-compatible endpoint shape (LM Studio,
llama.cpp's server, vLLM).
2026-09-07 11:57:56 +08:00
4 changed files with 87 additions and 13 deletions

No files matched your search

+10 -11
View File
@@ -87,9 +87,8 @@ a lot. The package is optimized for the use cases above, not these.
hardened in 1.25. Older toolchains will fail at `go build`.
- **An LLM API key**, depending on which provider(s) you wire in:
`ANTHROPIC_API_KEY`, `OPENAI_API_KEY`, Google ADC for Gemini, or a
LiteLLM/OpenRouter key for those aggregators. For local models, point
`openai.NewOpenAIProviderWithKind` at an Ollama endpoint — no key
required.
LiteLLM/OpenRouter key for those aggregators. For local models
(Ollama, LM Studio, etc.), `local.NewLocalProvider` needs no key at all.
- **Optional: an MCP server** for `tools/mcp` integrations (any
binary that speaks the Model Context Protocol — `npx
@modelcontextprotocol/server-filesystem`, etc.).
@@ -120,10 +119,11 @@ github.com/sausheong/harness/
│ # MemoryProvider/SkillProvider/KnowledgeGraph interfaces
├── providers/
│ ├── anthropic/ # Anthropic LLMProvider (with prompt caching)
│ ├── openai/ # OpenAI / OpenAI-compatible / local Ollama
│ ├── openai/ # OpenAI / OpenAI-compatible
│ ├── gemini/ # Google Gemini via google.golang.org/genai
│ ├── litellm/ # Self-hosted LiteLLM proxy (OpenAI-compatible)
│ └── openrouter/ # OpenRouter aggregator (OpenAI-compatible)
│ ├── openrouter/ # OpenRouter aggregator (OpenAI-compatible)
│ └── local/ # Local model server — Ollama, LM Studio, etc. (OpenAI-compatible, no API key)
└── tools/ # Batteries-included concrete tools (each importable separately)
├── file/ # read_file (with vision), write_file, edit_file
├── bash/ # bash (with ExecPolicy: deny | allowlist | full)
@@ -315,12 +315,11 @@ Deliberately not in scope (numbers from the same conceptual list):
`clientcredentials.Config.Client(ctx)`) as `HTTPClient` —
auto-refresh comes for free. Call `Runtime.Close()` to release
sessions.
- **Five providers, one interface.** Anthropic, OpenAI (and
OpenAI-compatible / local Ollama), Gemini, LiteLLM, and OpenRouter ship
built-in — LiteLLM and OpenRouter cost none of that ~300 LOC each,
since both are thin constructors over the existing OpenAI-compatible
path. Adding a genuinely new wire format is implementing
`llm.Provider` (~300 LOC).
- **Six providers, one interface.** Anthropic, OpenAI, Gemini, LiteLLM,
OpenRouter, and local (Ollama, LM Studio, etc.) ship built-in — LiteLLM,
OpenRouter, and local cost none of that ~300 LOC each, since all three
are thin constructors over the existing OpenAI-compatible path. Adding
a genuinely new wire format is implementing `llm.Provider` (~300 LOC).
See [`developer.md`](./developer.md) for a step-by-step guide to
building agents on top of Harness, including diagrams of the
+3 -2
View File
@@ -59,8 +59,8 @@ required pieces are inside `inputs`; everything in `deps` is optional;
The four mandatory pieces:
* **`llm.LLMProvider`** (in `RuntimeInputs.Provider`) — a streaming
chat client (Anthropic / OpenAI / Gemini / LiteLLM / OpenRouter, or
your own).
chat client (Anthropic / OpenAI / Gemini / LiteLLM / OpenRouter /
local (Ollama, LM Studio, etc.), or your own).
* **`tool.Registry`** (in `RuntimeInputs.Tools`) — the tools the LLM
may invoke. Each tool implements `tool.Tool`.
* **`session.Session`** (in `RuntimeInputs.Session`) — append-only
@@ -392,6 +392,7 @@ Each provider has its own constructor. All return an `llm.LLMProvider`.
| Gemini | `gemini.NewGeminiProvider(ctx, apiKey)` | takes `context.Context` |
| LiteLLM | `litellm.NewLiteLLMProvider(apiKey, baseURL)` | `baseURL` required (self-hosted) |
| OpenRouter | `openrouter.NewOpenRouterProvider(apiKey, baseURL)` | `baseURL == ""` → OpenRouter's public endpoint |
| Local | `local.NewLocalProvider(baseURL)` | `baseURL == ""` → `http://localhost:11434/v1` (Ollama's default; override for LM Studio, llama.cpp, vLLM, etc.); no API key |
The provider you pass on `RuntimeInputs.Provider` only needs to match the
provider prefix in `AgentSpec.Model` — `runtime.BuildRuntime` parses
+28
View File
@@ -0,0 +1,28 @@
// Package local provides an llm.LLMProvider for a locally-served model —
// Ollama, LM Studio, llama.cpp's server, vLLM, or anything else exposing
// an OpenAI-compatible endpoint on the caller's own machine or network.
// Like providers/litellm and providers/openrouter, this adds no new
// request/stream-translation code of its own — it's a thin constructor
// around harness's existing OpenAI-compatible support.
package local
import "github.com/sausheong/harness/providers/openai"
// DefaultBaseURL is used when NewLocalProvider is called with an empty
// baseURL. It's Ollama's endpoint specifically — the most common local
// server — but any other one works the same way via an explicit baseURL.
const DefaultBaseURL = "http://localhost:11434/v1"
// NewLocalProvider returns an OpenAI-compatible provider pointed at
// baseURL, or DefaultBaseURL when baseURL is empty. No API key is
// needed — local servers generally don't authenticate requests.
// kind="local" suppresses reasoning_effort, since locally-served models
// don't uniformly support it, and keeps retryable-error classification
// from treating a down local server the way it would a hosted API
// outage (see llm/retry.go).
func NewLocalProvider(baseURL string) *openai.OpenAIProvider {
if baseURL == "" {
baseURL = DefaultBaseURL
}
return openai.NewOpenAIProviderWithKind("", baseURL, "local")
}
+46
View File
@@ -0,0 +1,46 @@
package local
import (
"context"
"net/http"
"net/http/httptest"
"testing"
"github.com/stretchr/testify/require"
"github.com/sausheong/harness/llm"
)
func TestDefaultBaseURL(t *testing.T) {
require.Equal(t, "http://localhost:11434/v1", DefaultBaseURL)
}
// TestNewLocalProvider_HitsGivenBaseURL confirms a custom baseURL
// overrides the default and is actually what the provider talks to.
func TestNewLocalProvider_HitsGivenBaseURL(t *testing.T) {
var hit bool
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
hit = true
w.Header().Set("Content-Type", "text/event-stream")
_, _ = w.Write([]byte("data: [DONE]\n\n"))
}))
t.Cleanup(srv.Close)
p := NewLocalProvider(srv.URL + "/v1")
stream, err := p.ChatStream(context.Background(), llm.ChatRequest{SystemPrompt: "hi"})
require.NoError(t, err)
for range stream {
}
require.True(t, hit, "provider did not hit the configured baseURL")
}
// TestNewLocalProvider_EmptyBaseURLDoesNotPanic confirms the empty ->
// DefaultBaseURL fallback path constructs a usable provider (the actual
// outbound host isn't inspectable from outside the openai package —
// OpenAIProvider's client config is unexported — so this checks the
// fallback doesn't panic or return nil, and DefaultBaseURL's own value
// is asserted separately above).
func TestNewLocalProvider_EmptyBaseURLDoesNotPanic(t *testing.T) {
p := NewLocalProvider("")
require.NotNil(t, p)
}