engine: add the ollama System One provider
A third decision-engine provider alongside the local SemIf GGUF and the remote Winnow server: `engine.provider == "ollama"` talks to ollama's native `/v1/systemone` route via `semif_agent/ollama_systemone.py`. It reuses the Winnow DecisionRequest -> choice mapping and the same strict distribution validation over exactly the requested option ids, and adds the edges only ollama has: - no `/health`: `warm()` probes `GET /api/version` + `POST /api/show`, which also proves the model is pulled and advertises the `decision` capability; - `engine.ollama.context_tokens: 0` follows the model's real `num_ctx` from `/api/show`; - `keep_alive` rides on the request, criteria descriptions use the ollama subset `string | null`, and a choice question needs >= 2 options; - decision models do not generate text, so `generate()` raises `EngineUnavailable` (use `llm.provider == "ollama"` for chat). Every failure is an `EngineUnavailable` (fatal, like the local engine) and the engine lock still serializes on the single-slot server. `cli.build_engine` selects it, the setup interview and `--answers` accept it, and the install plan skips the engine clone/GGUF/tokenizer for it. Docs, config.example.json, and tests updated.
This commit is contained in:
1 parent
894a85ec2d
commit
addbe53392
12 files changed
+903
-41
No files matched your search
+28
-5
@@ -41,6 +41,7 @@ from .console import (
|
||||
)
|
||||
from .decisions import DecisionRequest, Option
|
||||
from .engine import DecisionEngine, EngineConfig, EngineUnavailable, SemIfEngine
|
||||
from .ollama_systemone import OllamaSystemOneConfig, OllamaSystemOneEngine
|
||||
from .winnow import WinnowConfig, WinnowEngine
|
||||
from .llm import LLMClient, SemIfLLMClient
|
||||
from .log import DecisionLog
|
||||
@@ -54,6 +55,7 @@ from .trace import TraceLog
|
||||
REPO_ROOT = Path(__file__).resolve().parent.parent
|
||||
|
||||
DEFAULT_WINNOW_URL = "http://127.0.0.1:8091"
|
||||
DEFAULT_OLLAMA_SYSTEMONE_URL = "http://127.0.0.1:11434"
|
||||
|
||||
_PATH_KEYS = (
|
||||
"skill_packs",
|
||||
@@ -221,14 +223,19 @@ def build_engine(config: dict, pins: dict | None = None) -> DecisionEngine:
|
||||
|
||||
* ``"semif"`` (default) — the local llama.cpp GGUF (`SemIfEngine`), built
|
||||
from the per-machine `engine` knobs + the pinned refs in pins.json.
|
||||
* ``"winnow"`` — a remote `/v1/systemone` typed-decision API
|
||||
* ``"winnow"`` — a remote Winnow `/v1/systemone` typed-decision API
|
||||
(`WinnowEngine`), configured by the nested `engine.winnow` block
|
||||
(`base_url`/`model`/`api_key`/`timeout`/`retries`).
|
||||
* ``"ollama"`` — ollama's native System One `/v1/systemone` route
|
||||
(`OllamaSystemOneEngine`), configured by the nested `engine.ollama` block
|
||||
(`base_url`/`model`/`keep_alive`/`api_key`/`timeout`/`retries`), probed
|
||||
through ollama's own `/api/version` + `/api/show` endpoints.
|
||||
|
||||
The engine is always real: a provider that cannot be reached raises
|
||||
`EngineUnavailable` at call time, which the scheduler treats as fatal. The
|
||||
`winnow` model is required (no default) exactly as `llm.model`/`codegen.model`
|
||||
are, so a misconfigured endpoint fails as an actionable config error.
|
||||
`winnow` and `ollama` models are required (no default) exactly as
|
||||
`llm.model`/`codegen.model` are, so a misconfigured endpoint fails as an
|
||||
actionable config error.
|
||||
"""
|
||||
eng = config.get("engine", {}) or {}
|
||||
provider = str(eng.get("provider", "semif") or "semif").lower()
|
||||
@@ -247,6 +254,22 @@ def build_engine(config: dict, pins: dict | None = None) -> DecisionEngine:
|
||||
user_agent=str(win.get("user_agent") or "semif-agent"),
|
||||
)
|
||||
)
|
||||
if provider == "ollama":
|
||||
block = eng.get("ollama", {}) or {}
|
||||
endpoint = _provider_endpoint(block, DEFAULT_OLLAMA_SYSTEMONE_URL)
|
||||
return OllamaSystemOneEngine(
|
||||
OllamaSystemOneConfig(
|
||||
base_url=endpoint["base_url"],
|
||||
model=_required_model(block, "engine.ollama"),
|
||||
context_tokens=int(block.get("context_tokens", 16384)),
|
||||
timeout=float(block.get("timeout", 120.0)),
|
||||
retries=int(block.get("retries", 0)),
|
||||
api_key=endpoint["api_key"],
|
||||
extra_headers=endpoint["extra_headers"],
|
||||
user_agent=str(block.get("user_agent") or "semif-agent"),
|
||||
keep_alive=str(block.get("keep_alive") or ""),
|
||||
)
|
||||
)
|
||||
return SemIfEngine(build_engine_config(config, pins))
|
||||
|
||||
|
||||
@@ -1164,8 +1187,8 @@ def main(argv: list[str] | None = None) -> int:
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||
epilog=(
|
||||
"answers JSON fields (all optional; --answers FILE):\n"
|
||||
" engine_provider (semif|winnow), winnow_base_url, winnow_model,\n"
|
||||
" winnow_api_key\n"
|
||||
" engine_provider (semif|winnow|ollama), winnow_base_url, winnow_model,\n"
|
||||
" winnow_api_key, ollama_base_url, ollama_model, ollama_api_key\n"
|
||||
" new_skill_creation (deny|ask|allow)\n"
|
||||
" llm_provider (semif|ollama|opencode|openai), llm_base_url,\n"
|
||||
" llm_model, llm_api_key\n"
|
||||
|
||||
Reference in new issue
Block a user