Repository navigation
feat: add batch and serial multi-step routing plans - #1
Merged
BillionsBobby merged 1 commit intoSep 18, 2026
Merged
Conversation
route() answers a single Choice question. This adds plan(), which answers
'which capability should handle step 1..N' in two modes:
- serial (default): one full routing decision per step; selected
capabilities are fed forward in the state so later steps are
conditioned on earlier ones. Any candidate count; two-stage routing
still applies per step.
- batch: all step questions (step1..stepN) in one provider call over the
same candidate set. Limited to single_stage_max_candidates.
Provider layer: JevRouteRequest gains an optional questions map so
providers are no longer hardcoded to a single 'tool' question; the demo
provider answers every requested key; the cache key covers questions.
Every plan step is a full routing decision (per-step policy, fallback,
raw responses). Plans are saved append-only to .jevrouter/plans/.
CLI: jevrouter plan --request ... [--steps N] [--mode batch|serial]
SDK: plan(input, { steps, mode, ...RouteOptions })
Validated against the live OpenRouter Jev endpoint (batch: one call,
three step answers; serial: sequential state threading with the
per-step confidence gate).
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.
Motivation
route()answers a single Choice question (questions: { tool: ... }). When an agent needs a multi-step tool plan (e.g. "search issues, then summarize, then save"), the only option today is to driveroute()in a hand-rolled loop with no shared contract. This PR adds first-class multi-step plans in two modes, while keeping the existing routing contract untouched.What changed
Provider layer — providers are no longer hardcoded to a single
toolquestion:JevRouteRequest.questions: optional map of question key →{ instructions }. Both the TypeSafe and OpenRouter providers build the full batch payload from it (one HTTP call, oneusage); absent means the defaulttoolquestion, fully backward compatible.getChoiceAnswer(raw, key)reads any question key (defaults totool).DemoProvideranswers every requested key;CachedJevProviderincludesquestionsin the cache key.Router layer —
JevRouter.plan(input, candidates, { steps, mode }):Capabilities already routed in previous steps, in order: ...), so later steps are conditioned on the plan so far. Any candidate count — two-stage routing still applies per step. Only post-policyselectedcapabilities are fed forward; ano_decisionstep adds nothing.step1..stepN) in a single provider call over the same candidate set — cheapest and fastest. Requires candidates ≤single_stage_max_candidates(no per-step two-stage); larger sets get a clear error pointing to serial mode.selected/jev_choice/status, probabilities,routerannotations, per-stepfallback(confidence gate and filters apply independently per step). Batch stores the single envelope inplan.raw_jev; serial keeps each step's ownraw_jev.finalize/decideWithStages) soroute()and plans run identical policy code;route()behavior is unchanged (all 11 existing tests pass unmodified).Interfaces:
jevrouter plan --request "..." [--steps 5] [--mode batch|serial], plans saved append-only to.jevrouter/plans/.plan(input, { steps, mode, ...RouteOptions }).Tests
tsc --noEmitclean.typesafe/jev-1.13-20260917): batch mode returned three step answers in one call (search → search → summarize, all selected); serial mode threaded state across three sequential decisions and applied the per-step confidence gate correctly (both the abstention and selection paths exercised).