Repository navigation
feat(gateway): serve POST /v1/decisions with scriptable answers - #94
Merged
Merged
Conversation
One answer per question: predicate probability 0.95, first choice and score 0 by default, or the first top-level decisions: rule whose match regex hits the request input. The built-in model list gains mock/ollama_cloud/clef:27b with decisions among its output modalities, so clients that check the listing find a decision model.
edenreich
marked this pull request as ready for review
November 3, 2026 22:53
Contributor
|
🎉 This PR is included in version 0.12.0 🎉 The release is available on GitHub release Your semantic-release bot 📦🚀 |
edenreich
added a commit
to inference-gateway/cli
that referenced
this pull request
Nov 4, 2026
…decisions (#1691) ## Summary The tool-approval judge gains a second backend. `judge.yaml` `backend: decisions` asks a **decision model** through the gateway's `POST /v1/decisions` and thresholds its `p(approve)`, instead of asking a generative model for a JSON verdict and parsing prose. Every decision call goes through the gateway via the Go SDK: the cli never speaks a vendor's decision format and holds no vendor credential. The `provider/model` prefix picks the upstream exactly as for chat completions. Closes #1342 ## Changes - `internal/decision/` - new bounded context. `domain/` holds `Question` (`predicate` | `choice` | `score`), `Answer`, `Decisions` and the `Decider` port. `infrastructure/gateway/` is the only adapter: builds `sdk.CreateDecisionRequest`, calls `CreateDecision`, maps the typed answers back by name. README explains what, why and how it plugs in. - `internal/agent/loop/decision_judge.go` - `DecisionJudge` implements `JudgeApprover`. Evidence is the same rendered prompt the LLM judge sees. Per batch: one `predicate` per gated call named by its tool call id, plus one `choice` named `risk` (`benign`, `destructive`, `network`, `secrets`, `out_of_scope`, each with a criterion). Approved iff `probability >= min_confidence`. Reasons carry the probability and risk class so the agent adjusts and `RequestApproval` escalation keeps working. `on_error`, batching (20 calls), usage accounting, `judge_verdict` events and the TUI indicator are unchanged. `newJudge` picks the backend, `judge.gateway_url` applies to both. - `config/judge.go` - `backend` (`llm` default | `decisions`) and `min_confidence` (default 0.7), validated. - `internal/gateway/supervisor.go` - the cli-managed gateway starts with `DECISIONS_ENABLED=true` when the backend is `decisions` (container and binary paths). - `internal/platform/adapters/anthropic_messages.go` - delegates `CreateDecision` like the other SDK methods. Go SDK bumped to v1.45.0, SDK fake regenerated, `Decider` fake added to `mocks:generate`. - tokenless bumped to v0.12.0 (inference-gateway/tokenless#94), which serves `POST /v1/decisions` and lists `mock/ollama_cloud/clef:27b` as a decision model, so `INFER_GATEWAY_MOCK=true` exercises the whole judge path with no tokens. - Tests: `decision_judge_test.go` (threshold at, above and below, question shape, missing answer fails closed alone, `on_error` both ways, batch split with summed usage, invalid model, backend selection), `decider_test.go` (request shape for all three question types, answer parsing, errors, empty decision), config validation cases. - Eval: `internal/agent/loop/testdata/judge_eval.jsonl` holds 30 labelled cases (requested installs, builds, writes and commits vs `rm -rf`, `curl | sh`, secret reads, force-push after a bare "continue", prompt injection in arguments, out-of-scope writes). `task test:judge-eval` with `INFER_JUDGE_EVAL_MODEL=provider/model` runs them through a gateway and logs accuracy, false approves, p50/p95 latency and tokens per decision. - Docs: `docs/judge-mode.md` gains the "Decision-model judge" section and the new env overrides. `examples/working-offline` runs the judge on a local `ollama/clef`: the compose sets `DECISIONS_ENABLED=true` on the gateway and the judge env on the cli, and the README has the `ollama pull clef` walkthrough plus the `ollama_cloud/clef:27b` variant. ## Verified in the TUI against the mock With `INFER_GATEWAY_MOCK=true`, `INFER_JUDGE_BACKEND=decisions`, `INFER_JUDGE_MODEL=mock/ollama_cloud/clef:27b` and a scenarios file carrying a `decisions:` rule (`match: 'rm -rf'`, `probability: 0.05`, `choice: destructive`): - `Write note.txt` in Auto+Judge ran with no prompt (p_approve 0.95). - `Bash rm -rf ./bin` was rejected: `rejected by judge: mock/ollama_cloud/clef:27b: rejected by the judge (decisions: p_approve=0.05, risk: destructive, below min_confidence 0.70)`, and the model read the reason and replied accordingly. ## Eval results Not run in this PR: the harness is in place but running it needs a gateway with an Ollama Cloud key or a local `clef`. Run `INFER_JUDGE_EVAL_MODEL=ollama_cloud/clef:27b task test:judge-eval` against your gateway and paste the summary line here. The default `min_confidence: 0.7` is the vendor-neutral starting point until those numbers say otherwise. ## Deliberate limits - Evidence is sent as one text block (the rendered judge prompt), not as structured `input_json` items. Same information, one code path shared with the LLM judge. - No cascade to the LLM judge on low confidence. Add when the eval shows the decision model needs it. - Local Ollama decision models are not yet marked in the gateway's model listing, so the gateway relays them unchecked. Fine for the offline example. ## Downstream impact - Gateway: needs a release carrying `DECISIONS_ENABLED`, the modality gate and the Ollama translation (inference-gateway/inference-gateway#831, #832). - Docs: `[DOCS]` ticket for `inference-gateway/docs` to be filed with this PR (judge mode page: the decisions backend and the offline example). ## Verification - `task precommit:run` passes (mod tidy, mocks, fmt, lint). - `go test ./...` passes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds the OpenAI-compatible Decisions API to the mock so agents whose approval judge calls
POST /v1/decisions(theinferCLI judge withbackend: decisions, inference-gateway/cli#1691) run hermetically.POST /v1/decisions: one answer per question. Defaults are safe (predicateprobability0.95, the firstchoice,score0). Top-leveldecisions:rules script rejections: the first rule whosematchregex hits the request input (a string as is, an item list as JSON text) setsprobability,choiceandscore. Invalid regexes and probabilities outside 0..1 failLoad.Recorded.DecisionsBody,RawBody) like every other endpoint, so tests can assert the questions the agent asked.mock/ollama_cloud/clef:27bwithdecisionsamong its output modalities, so clients that checkGET /v1/modelsbefore calling find a decision model (gateway.DecisionModel).Verification
gofmt -l .clean,go vet ./...,go test ./..., and the examples module vet and tests all pass.