Skip to content

feat: add batch and serial multi-step routing plans - #1

Merged
BillionsBobby merged 1 commit into
BillionsBobby:mainfrom
Arcobalneo:feat/multi-step-plans
Sep 18, 2026
Merged

BillionsBobby merged 1 commit into
BillionsBobby:mainfrom
Arcobalneo:feat/multi-step-plans

Conversation

@Arcobalneo

Copy link
Copy Markdown
Collaborator

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 drive route() 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 tool question:

  • JevRouteRequest.questions: optional map of question key → { instructions }. Both the TypeSafe and OpenRouter providers build the full batch payload from it (one HTTP call, one usage); absent means the default tool question, fully backward compatible.
  • getChoiceAnswer(raw, key) reads any question key (defaults to tool).
  • DemoProvider answers every requested key; CachedJevProvider includes questions in the cache key.

Router layer — JevRouter.plan(input, candidates, { steps, mode }):

  • serial (default): one full routing decision per step. Capabilities selected in earlier steps are appended to the state (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-policy selected capabilities are fed forward; a no_decision step adds nothing.
  • batch: all step questions (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.
  • Every step is a full routing decision: per-step selected/jev_choice/status, probabilities, router annotations, per-step fallback (confidence gate and filters apply independently per step). Batch stores the single envelope in plan.raw_jev; serial keeps each step's own raw_jev.
  • The shared post-decision logic was extracted (finalize/decideWithStages) so route() and plans run identical policy code; route() behavior is unchanged (all 11 existing tests pass unmodified).

Interfaces:

  • CLI: jevrouter plan --request "..." [--steps 5] [--mode batch|serial], plans saved append-only to .jevrouter/plans/.
  • SDK: plan(input, { steps, mode, ...RouteOptions }).

Tests

  • 6 new unit tests (batch single-call question mapping, per-step confidence gate, serial state threading, batch candidate cap + serial two-stage, step validation, SDK demo provider): 17/17 pass, tsc --noEmit clean.
  • Live-verified against the real OpenRouter Jev endpoint (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).

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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants