Repository navigation
feat(judge): decide tool approvals with a decision model through /v1/decisions - #1691
Conversation
…decisions Adds the decision bounded context (typed predicate, choice and score questions answered with native probabilities) with one adapter on the gateway's Decisions API via the Go SDK, and a DecisionJudge behind judge.yaml backend: decisions that asks one predicate per gated call plus a risk choice and thresholds p(approve) against min_confidence. The cli-managed gateway starts with DECISIONS_ENABLED=true when the backend is selected. The offline example runs the judge on a local ollama clef, and a labelled eval set runs through any decision model via task test:judge-eval. Closes #1342.
|
@infer can you review this PR? is it ready for merge? use /ponytail:ponytail /ponytail:ponytail-review /go /go-concurrency /clean-architecture /clean-code /domain-driven-design /cobra-viper |
|
Model: Todos
Pull Request✅ Infer Result: SuccessAll verification is done - the What this change does: Adds a second judge backend behind the existing Short answer for "is it ready for merge": yes, practically - the code is correct, well tested, and follows the repo's DDD conventions, and the findings below are small. Findings are one docs gap and three nice-to-haves. What I checked, all passing:
Must fix: none. Should fix:
Nice to have: Pre-merge note (not a code finding): the eval has not been run against a real decision model - the PR body says so itself. The backend is opt-in, default Downstream: the PR body's promised Not this PR but noticed while running the suites: Verdict: fix 1 first (trivial docs), then ship. Model: Tokens: 2,930,244 in · 41,970 out · 2,972,214 total (31 requests) Tool calls: 59 total · 100% success rate TracesStatsTriggered by edenreich · Infer Action · OSS |
… question surface Both judge backends built the same judge-unavailable verdict, so one onErrorVerdict helper now serves both. The decision context only asks predicates and one choice, so the score question type, its levels and the confidence and probabilities answer fields go until a consumer needs them. The configuration reference documents judge.backend, judge.min_confidence and their env overrides, and marks the keys that only apply to one backend.
|
🎉 This PR is included in version 0.243.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Summary
The tool-approval judge gains a second backend.
judge.yamlbackend: decisionsasks a decision model through the gateway'sPOST /v1/decisionsand thresholds itsp(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. Theprovider/modelprefix picks the upstream exactly as for chat completions.Closes #1342
Changes
internal/decision/- new bounded context.domain/holdsQuestion(predicate|choice|score),Answer,Decisionsand theDeciderport.infrastructure/gateway/is the only adapter: buildssdk.CreateDecisionRequest, callsCreateDecision, maps the typed answers back by name. README explains what, why and how it plugs in.internal/agent/loop/decision_judge.go-DecisionJudgeimplementsJudgeApprover. Evidence is the same rendered prompt the LLM judge sees. Per batch: onepredicateper gated call named by its tool call id, plus onechoicenamedrisk(benign,destructive,network,secrets,out_of_scope, each with a criterion). Approved iffprobability >= min_confidence. Reasons carry the probability and risk class so the agent adjusts andRequestApprovalescalation keeps working.on_error, batching (20 calls), usage accounting,judge_verdictevents and the TUI indicator are unchanged.newJudgepicks the backend,judge.gateway_urlapplies to both.config/judge.go-backend(llmdefault |decisions) andmin_confidence(default 0.7), validated.internal/gateway/supervisor.go- the cli-managed gateway starts withDECISIONS_ENABLED=truewhen the backend isdecisions(container and binary paths).internal/platform/adapters/anthropic_messages.go- delegatesCreateDecisionlike the other SDK methods. Go SDK bumped to v1.45.0, SDK fake regenerated,Deciderfake added tomocks:generate.POST /v1/decisionsand listsmock/ollama_cloud/clef:27bas a decision model, soINFER_GATEWAY_MOCK=trueexercises the whole judge path with no tokens.decision_judge_test.go(threshold at, above and below, question shape, missing answer fails closed alone,on_errorboth 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.internal/agent/loop/testdata/judge_eval.jsonlholds 30 labelled cases (requested installs, builds, writes and commits vsrm -rf,curl | sh, secret reads, force-push after a bare "continue", prompt injection in arguments, out-of-scope writes).task test:judge-evalwithINFER_JUDGE_EVAL_MODEL=provider/modelruns them through a gateway and logs accuracy, false approves, p50/p95 latency and tokens per decision.docs/judge-mode.mdgains the "Decision-model judge" section and the new env overrides.examples/working-offlineruns the judge on a localollama/clef: the compose setsDECISIONS_ENABLED=trueon the gateway and the judge env on the cli, and the README has theollama pull clefwalkthrough plus theollama_cloud/clef:27bvariant.Verified in the TUI against the mock
With
INFER_GATEWAY_MOCK=true,INFER_JUDGE_BACKEND=decisions,INFER_JUDGE_MODEL=mock/ollama_cloud/clef:27band a scenarios file carrying adecisions:rule (match: 'rm -rf',probability: 0.05,choice: destructive):Write note.txtin Auto+Judge ran with no prompt (p_approve 0.95).Bash rm -rf ./binwas 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. RunINFER_JUDGE_EVAL_MODEL=ollama_cloud/clef:27b task test:judge-evalagainst your gateway and paste the summary line here. The defaultmin_confidence: 0.7is the vendor-neutral starting point until those numbers say otherwise.Deliberate limits
input_jsonitems. Same information, one code path shared with the LLM judge.Downstream impact
DECISIONS_ENABLED, the modality gate and the Ollama translation (feat(api): gate /v1/decisions on the decisions modality and DECISIONS_ENABLED (schemas v1.9.0) inference-gateway#831, [REFACTOR] Cache lipgloss styles per theme change; optional terminal background detection #832).[DOCS]ticket forinference-gateway/docsto be filed with this PR (judge mode page: the decisions backend and the offline example).Verification
task precommit:runpasses (mod tidy, mocks, fmt, lint).go test ./...passes.