Repository navigation
feat(agent): add auto-with-judge mode with an LLM judge as the tool approver - #1148
Conversation
tools.safety.approval_behaviour gains a judge value decided by an LLM judge; judge.yaml (model/timeout/max_tokens/on_error/prompt) loads next to hooks.yaml with INFER_JUDGE_* env overrides, and selecting the judge with no resolvable model fails fast at config validation.
requestToolApproval routes to requestJudgeApproval when the mode is auto-with-judge or approval_behaviour=judge: one no-tools GenerateContent call (judge.yaml model/timeout/max_tokens/on_error/prompt) over the latest non-hidden user message plus the pending tool call, verdict parsed via ParseJudgeVerdict, rejections flow through the existing rejection path with the judge reason appended, a judge_verdict chat event drives the TUI flash / headless stderr / json+ag-ui output and the debug mirror. headless gains --mode (validated via ParseAgentMode, env INFER_AGENT_MODE, subagent fallback) with fail-fast validation for an unresolvable judge model; the extension bridge now reports the canonical mode key.
|
@infer Can you finalise the work on this PR? Make it ready for review. use /ponytail:ponytail /go /go-concurrency /bubbles-v2 /lipgloss-v2 /bubbletea-v2 |
|
Model: Todos
Pull Request✅ Infer Result: SuccessAll checks pass except PR #1148 is finalised and ready for review. Here is what landed in this session (4 commits pushed to Tests (closing the PR's remaining-work checklist)
Docs (c18395c)
Two deliberate calls, noted for reviewers:
Checks: Model: Tokens: 11,391,944 in · 42,587 out · 11,434,531 total (93 requests) Tool calls: 117 total · 100% success rate TracesStatsTriggered by edenreich · Infer Action · OSS |
Co-authored-by: Eden Reich <[email protected]>
type the judge verdict constants and retype judgeverdict.decision and judgeverdictchatevent.decision as agentdomain.judgedecision; wire format and behavior unchanged
- key mode-change guidance, subagent inheritance, and telemetry by ModeKey so auto-with-judge no longer collapses to standard - JudgeRequired only reads approval_behaviour; headless fail-fasts on --mode - send judge instructions as a system message with tagged data (judge.system_prompt) - record judge token usage in session totals and telemetry - emit judge_request on the debug channel; carry the reason in the tool result error - drop dead fence stripping and the private effective() wrapper - add e2e judge scenario, four-way mode cycle test
- a judge rejection is a failed tool result (rejected by judge: <reason>) so the driver reads the reason and continues; only a human rejection ends the turn - route JudgeVerdictChatEvent through isDomainEvent and re-arm the chat listener in its handler; the TUI was dropping every event after a verdict - show the error text in the collapsed failed tool card - e2e asserts the driver's follow-up after a judge rejection
…tool card A judge rejection produces no tool data, so the card only said Execution failed; the reason was hidden behind ctrl+o.
- judge.gateway_url / INFER_JUDGE_GATEWAY_URL gives the judge its own client so a real judge can approve a mock-driven session - the judge model appears in the AUTO+JUDGE mode indicator, the verdict events (json / ag-ui / debug), the flash, and the rejected tool result
Co-authored-by: Eden Reich <[email protected]>
|
🎉 This PR is included in version 0.188.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
## Context AGENTS.md already follows the open standard at https://agents.md (a README for coding agents at a predictable location, no required structure). Auditing it against the current tree found it accurate except one stale spot: the tool-approval guidance predates the `auto-with-judge` agent mode (#1148). ## Changes Two bullets in **Security Gotchas**: - `approval_behaviour` now includes `judge` — an LLM judge decides gated calls (config `judge.yaml`; forced by the `auto-with-judge` agent mode — see docs/judge-mode.md). - `auto-with-judge` maps to the `standard` bash allow-list bucket: the judge gates calls, it never widens the list (`config/bash_allowedlist.go`). `CLAUDE.md` is a symlink to `AGENTS.md`, so both stay in sync from this one edit. ## Verification - Facts cross-checked against `config/bash_allowedlist.go`, `config/judge.go`, `docs/judge-mode.md`, `internal/agent/domain/agent_mode_test.go`. - `flox activate -- task precommit:run` passes (mod:tidy → fmt → lint:imports → golangci-lint `0 issues` → markdownlint). Per the /init flow, this PR is left open for human review — not merging.
Resolves #1147
Summary
Adds the
auto-with-judgeagent mode: no human in the loop, but tool calls that would normally prompt a human are decided by one LLM judge call instead of bypassing approval like Auto-Accept. The judge gets the latest non-hidden user message plus the pending tool call and answers a JSON verdict contract; rejections flow through the existing rejection path with the judge's reason appended. Configured via a new.infer/judge.yaml(model/timeout/max_tokens/on_error/prompt,INFER_JUDGE_*env overrides) ortools.safety.approval_behaviour: judge. Disabled by default - standard/plan/auto behavior is unchanged.Changes
config/judge.go:JudgeConfig, defaults,LoadJudge,Validate(on_error deny|allow),ResolveModelfalling back toagent.model; wired incmd/runtime/config.gonext toLoadHookswithINFER_JUDGE_*env overrides.config/config.go:ApprovalBehaviourJudgevalue accepted byApprovalBehaviourFor/Validate/ResolveApprovalDelivery(judge is never downgraded to block for lack of a broker);JudgeRequired()+ fail-fast validation when the judge is selected with no resolvable model.internal/agent/domain:AgentModeAutoWithJudge(ParseAgentMode/String/DisplayName "Auto+Judge",AllowedlistKey()returns "standard"),JudgeVerdict+ParseJudgeVerdict(strips fences/prose, enforces the JSON contract),JudgeApproverport,JudgeVerdictChatEvent.internal/agent/judge.go:LLMJudge- one no-toolsGenerateContentshaped likeGenerateLLMSummary(SkipMCP, own timeout, bounded max_tokens);on_errordeny (default, fail closed like the no-approver block path) or allow.requestToolApprovalroutes torequestJudgeApproval(returns(false, judgeReason, nil));createRejectionEntry/buildRejectionEntryappend the judge reason;ApprovalDeliveryforces judge in the mode. Allow-listed commands still pass for free (AllowedlistKey()= "standard").judge_verdicton--format json, ag-ui custom event, text/stderr line for rejections, and the hidden debug channel viastreamevent.EmitDebugEvent.JudgeVerdictChatEventflashes "Action rejected by judge policy: " viaSetStatusEvent.--modeflag (validated viaParseAgentMode;INFER_AGENT_MODE, then subagent-inherited mode) with judge-model fail-fast before the gateway/agent starts.config/judge_test.go(defaults, LoadJudge file handling, Effective defaults, ResolveModel, Validate), config behaviour-value tests (judgeaccepted by ApprovalBehaviourFor/Validate/ResolveApprovalDelivery, JudgeRequired + model fail-fast),approval_policy_test.goauto-with-judge cases (keeps standard rules, allow-listed bash never reaches the judge),internal/agent/domain/judge_test.go(ParseJudgeVerdict contract: fences, prose, invalid decisions),internal/agent/judge_test.go(LLMJudge prompt shaping, on_error deny/allow, unparseable output denies, latestUserIntent filtering).docs/judge-mode.md;docs/configuration-reference.md(approval_behaviour judge bullet + Judge Approval (judge.yaml) section with INFER_JUDGE_* overrides);docs/commands-reference.md(four-way Shift+Tab cycle, Auto+Judge mode entry, headless--mode);docs/plan-mode.md+ README mode cycle/index updated. (shortcuts-guide.md covers only/shortcuts- the Shift+Tab docs live in commands-reference.md.)Notes for review
INFER_GATEWAY_MOCKcanned judge verdict) skipped: the judge decision path is covered by unit tests, and a scenario would have to match the judge prompt text - fragile for little gain.cmd/runtime/config_pointer_env_test.gotests (TestPointerDefaultsSurviveWithoutEnvOverride,TestPointerOptionPrecedence) fail in Actions-runner sandboxes identically on main - pre-existing and environmental, not touched by this PR.Resolves #1147
Review follow-ups (pushed on this branch)
ModeKey(); before this, auto-with-judge collapsed to standard in all three places and a judge-mode parent spawned children that blocked on every gated tool.JudgeRequired()only readsapproval_behaviour; the headless runner fail-fasts on--mode/INFER_AGENT_MODEitself.system_prompt(instructions, with a data-not-instructions rule) and a tagged user message; newINFER_JUDGE_SYSTEM_PROMPToverride.judge.gateway_url/INFER_JUDGE_GATEWAY_URLgives the judge its own client, so a real judge can approve a mock-driven session.rejected by judge: <model>: <reason>) and the turn continues; only a human rejection ends the turn. Previously the run ended after the first judge rejection and the driver never saw the reason.JudgeVerdictChatEventthroughisDomainEventand re-arms the chat listener; before this the TUI dropped every event after the first verdict and the tool card stayed "queued". The collapsed failed card shows the error text.judge_requestis emitted on the debug channel with the rendered prompt.Docs ticket: inference-gateway/docs#633 (updated with these follow-ups). Refactors spun out of the review: #1151, #1152, #1153, #1154, #1155.