Skip to content

feat(gateway): serve POST /v1/decisions with scriptable answers - #94

Merged
edenreich merged 1 commit into
mainfrom
feat/decisions-endpoint
Nov 3, 2026
Merged

edenreich merged 1 commit into
mainfrom
feat/decisions-endpoint

Conversation

@edenreich

Copy link
Copy Markdown
Contributor

Summary

Adds the OpenAI-compatible Decisions API to the mock so agents whose approval judge calls POST /v1/decisions (the infer CLI judge with backend: decisions, inference-gateway/cli#1691) run hermetically.

  • POST /v1/decisions: one answer per question. Defaults are safe (predicate probability 0.95, the first choice, score 0). Top-level decisions: rules script rejections: the first rule whose match regex hits the request input (a string as is, an item list as JSON text) sets probability, choice and score. Invalid regexes and probabilities outside 0..1 fail Load.
  • Requests are recorded (Recorded.DecisionsBody, RawBody) like every other endpoint, so tests can assert the questions the agent asked.
  • The built-in model list gains mock/ollama_cloud/clef:27b with decisions among its output modalities, so clients that check GET /v1/models before calling find a decision model (gateway.DecisionModel).
  • README section and skill file updated.

Verification

  • gofmt -l . clean, go vet ./..., go test ./..., and the examples module vet and tests all pass.

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
edenreich marked this pull request as ready for review November 3, 2026 22:53
@edenreich
edenreich merged commit fc6d04b into main Nov 3, 2026
4 checks passed
@edenreich
edenreich deleted the feat/decisions-endpoint branch November 3, 2026 22:53
inference-gateway-releaser Bot added a commit that referenced this pull request Nov 3, 2026
## [0.12.0](v0.11.0...v0.12.0) (2026-11-03)

### ✨ Features

* **gateway:** serve POST /v1/decisions with scriptable answers ([#94](#94)) ([fc6d04b](fc6d04b))

### 🔧 Miscellaneous

* **deps:** bump github.com/openai/openai-go/v3 in /examples ([#92](#92)) ([1bc46d1](1bc46d1))
@inference-gateway-releaser

Copy link
Copy Markdown
Contributor

🎉 This PR is included in version 0.12.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

@inference-gateway-releaser inference-gateway-releaser Bot added the released Shipped in a release label Nov 3, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

released Shipped in a release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant