[api][plan][python][examples] Framework-managed LLM-as-judge routing (Strategies.llm) #1042
All Vouch review confidence checks passed
Residual risk 0.23 = Change Risk (0.57) × (1 − Review Confidence (0.60)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.57 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.17 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.289
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #1042"
general
weight: 0.35
weiqingy
What
Implements the
Strategies.llm(...)follow-up promised in discussion #897: the engine — not the strategy — executes the judge call, on the same durable, metered, observable chat path as any model call. Tracking: #1062.Revised after review (thanks @wenjin272, @weiqingy): the PR now adopts the declaration/executor architecture proposed in review — one serializable
RoutingStrategydeclaration at the API layer, executors in Plan, dispatch by a language-neutral strategy type — plus all eleven review items. The user-facing builder is unchanged:Architecture (revised per review)
RoutingStrategyis a declaration, not behavior:RoutingStrategyType(RULE_BASED|LLM_JUDGE|CUSTOM) + arguments (+ executor class forCUSTOM). There is noroute()at the API layer — the previousUnsupportedOperationException-throwing judge class is gone.LlmJudgeRoutingExecutor(package-private pure helpers). Noinstanceofon concrete classes.strategy_type: "llm_judge"+strategy_args— no Java class names for built-ins. A Java-emitted snapshot is committed and the Python cross-language test deserializes it verbatim, so Python parity (#1062) needs only Python-side executors.route:<router>) for every strategy type — no executor can skip persistence; replay short-circuits execution, so neither the strategy nor the judge is re-invoked on recovery.CustomRoutingExecutorwith the data-onlyRoutingContext(v1's select-don't-delegate fence, verbatim): a custom executor cannot make hidden model calls. The engine-facing signature stays plan-internal.Judge semantics (unchanged from the original design, per #897)
"judge:<router>"(engine retries, trace events, token attribution); decision persisted with source and judge-inclusivedecision_msunder"route:<router>"; abstains persist as abstains, so replay after a candidate-set change resolves to the current default.FAILloud,IGNOREabstain-with-cause). Cancellation is determined from the thread's interrupt state plus explicit cancellation types (isCancellation); a bareInterruptedIOException(the shape Okio uses for ordinary HTTP timeouts) follows the normal failure policy — with a regression test.BaseChatModelSetup.prepareRequestMessagesthe chat path uses, so the judge's view cannot drift from what the selected model receives. Opt-in cost cap:withMaxContextChars(n)(rendered request + SYSTEM pinned, newest-first fill, truncation flagged asjudge_context_truncated).Strategies.llm(...)/plan construction — no reflective validation path to bypass). Plan construction verifies the judge model is registered and its descriptor binds no prompt/tools/skills; a slim runtime backstop catches instance-level bindings plan-time cannot see. Custom executor classes are checked (exists / implements / constructor) without instantiation.add_resource(..., MODEL_ROUTER)raises an explicit not-yet-supported error.Deliberate trade-offs (reviewed, kept)
route:in addition tojudge:) to keep the route-record schema uniform and preserve replayeddecision_ms.Claims → tests
| claim | test |
|---|---|
| verdict routes to named candidate, durable ids, metadata |
llmJudgeVerdictRoutesToNamedCandidate|| unparseable / non-candidate / ambiguous verdicts abstain |
llmJudgeUnparseableVerdictAbstainsToDefault,llmJudgeVerdictOutsideCandidatesAbstainsToDefault,parseVerdictAcceptsOnlyCandidates|| replay: stored abstain → current default; strategy not re-run |
storedAbstainReplaysToCurrentDefaultWithoutRerunningStrategy|| replay: original
decision_msreported |storedDecisionReplaysWithOriginalDecisionMs|| judge timeout (
InterruptedIOException) under IGNORE abstains, thread not left interrupted |judgeInterruptedIOTimeoutAbstainsToDefaultUnderIgnore|| judge sees full conversation / rendered bound prompt |
judgeSeesFullConversation,judgeSeesRenderedBoundPrompt|| cap pins SYSTEM + rendered template + newest; flags truncation |
maxContextCharsCapsJudgeInputAndFlagsTruncation,contextCapPinsRenderedTemplateMessages|| SYSTEM + empty USER + promptArgs does not route blind |
judgeMessagesFallBackToPromptArgsWithSystemAndEmptyUser|| judge token keys actually produced |
judgeTokenCountsLandInDecisionMetadata|| bad-args judge / missing judge model / non-plain judge fail at plan construction |
judgeWithMissingJudgeModelFailsAtPlanConstruction,typoedJudgeModelFailsAtPlanConstruction,judgeWithBoundPrompt/ToolsFailsAtPlanConstruction|| instance-level bound prompt caught at runtime (FAIL loud / IGNORE degrade) |
llmJudgeRejectsInstanceLevelPromptBoundJudgeSetupUnderFail,llmJudgePromptBoundSetupAbstainsToDefaultUnderIgnore|| custom executors never instantiated at plan time |
customExecutorIsNotInstantiatedDuringPlanConstruction|| Java plan deserializes in Python | committed Java snapshot +
test_python_can_deserialize_java_plan_with_judge_router|Compatibility impact
CustomRoutingExecutor.route(strategy, context)instead ofRoutingStrategy.route(context);Strategies.of(...)is nowStrategies.custom(...); the plan wire format usesstrategy_type/strategy_args(+strategy_executor_classfor CUSTOM) instead ofstrategy_clazz.decision_sourcevaluellm_judgeand optional metadata keysjudge_model,judge_prompt_tokens,judge_completion_tokens,judge_context_truncated. (decision_sourceis no longer duplicated inside the metadata map — it contradicted the top-level key on the judge+fallback path.)Test evidence
flink runofModelRoutingJudgeExample, local Ollama): judge verdicts routed with full metadata; fallback composition exercised live.Generative AI was used for this change.
Generated-by: Claude Code 2.1.239 (Claude Fable 5)