Skip to content

feat: plan strategies — decomposition, beam sequences, hierarchical routing, richer state - #9

Merged
BillionsBobby merged 1 commit into
BillionsBobby:mainfrom
Arcobalneo:feat/plan-optimizations
Sep 18, 2026
Merged

BillionsBobby merged 1 commit into
BillionsBobby:mainfrom
Arcobalneo:feat/plan-optimizations

Conversation

@Arcobalneo

Copy link
Copy Markdown
Collaborator

Motivation

Follow-up to #1. Our Toolathlon experiment (issue #2) showed that plain serial plans fix stateless repetition only partially: Jev still answers "which capability handles the whole request" (favoring deliverable tools like write_file), degrades on large candidate sets, and locks onto one tool across steps. This PR adds four measured plan strategies that address those failure modes, and reports both the wins and the honest negative results.

Strategies added (PlanStrategy, CLI flags in parentheses)

  • decompose: "rule" | DecomposeFn (--decompose rule): split the request into ordered sub-goals — a built-in discourse-marker splitter, or an injected function (e.g. an LLM given the tool catalog) — then route each sub-goal as a single-step decision. Decomposition turns a multi-step request into the single-action question shape Jev answers most confidently (confidence ≈ 1.0 in the README demo regime).
  • thread_context: true: in decompose mode, each step's state includes the original request, a Sub-goal k of N marker, and the capabilities routed so far.
  • sequence: "beam" + diversity_penalty: λ (--sequence beam --diversity-penalty 2.0): batch mode beam-searches the joint sequence over Jev's per-step probability distributions with a repetition penalty, instead of independent argmax. Zero extra provider calls. jev_choice keeps the argmax; overrides are recorded in fallback.reason (Jev owns probabilities, the router owns the sequence policy). The same penalty also enables per-step diversity re-ranking in serial/decompose modes.
  • group_by: "server" | "type" (--group-by server): hierarchical routing — coarse Choice over candidate groups (metadata.group/metadata.server, falling back to capability type), then a Choice within the winning group. Both calls preserved in raw_jev_stages.
  • state_detail: "targets" and plan_hint: string[] (SDK): richer serial state options (extracted files/URLs/identifiers; a caller-supplied plan sketch).

Also fixes a regression from #1: serial steps now actually ask the per-step question (...at step N...) instead of the generic route question.

Measured results (all real live calls, Jev typesafe/jev-1.13-20260917)

Toolathlon, 10 tasks, first-5 tool-call prediction vs labeled gold, real tool inventories from 9 live MCP servers (16–68 candidates/task):

Metric serial baseline best config DeepSeek V4.1 Flash (reference)
Position-wise hits 38% 44% (tool-aware LLM decompose + thread_context) 24%
Unordered overlap 54% 58% 64%
Latency / cost per task ~2.1s / $0.0006 ~10.6s / $0.0005 (+1 decompose call) ~8.6s / ~$0.004

Batch mode: sequence: "beam" (λ=2.0) lifts hits 28% → 36% and overlap 32% → 48% at zero extra provider cost.

MCP-Atlas regression check (10 tasks, same best config): hits 29% → 44%, overlap 44% → 69% (DeepSeek reference: 49% / 73%).

Negative results, documented: standalone group_by (26%), state_detail: "targets" (30%), serial diversity re-rank, and plan_hint did not beat the serial baseline on Toolathlon; they remain available as options.

Engineering

  • New pure helpers in src/planning.ts (beamSelectSequence, ruleDecompose, extractTargets, grouping); strategy orchestration in router.ts reusing the shared finalize/decideWithStages path — route() behavior unchanged.
  • SDK plan() accepts all strategy options; CLI exposes them as flags; plans still append-only in .jevrouter/plans/.
  • 10 new tests (pure helpers + beam override + diversity re-rank + decompose threading + hierarchical + plan_hint): 27/27 pass, tsc --noEmit clean.
  • Live-verified against the OpenRouter Jev endpoint: batch+beam end-to-end with per-step policy gate, CLI decompose mode, and the full winning configuration across 20 benchmark tasks (30 routed decisions each leg).

…al routing, richer state

Four measured plan strategies on top of the multi-step plan contract:

- decompose: split the request into ordered sub-goals (built-in rule
  splitter or an injected function, e.g. an LLM with the tool catalog),
  then route each sub-goal as a single-step decision — the question shape
  Jev answers most confidently. thread_context threads the original
  request, the Sub-goal k of N marker, and routing progress into each
  step's state.
- sequence=beam with diversity_penalty (batch): beam-search the joint
  sequence over Jev's per-step probability distributions with a
  repetition penalty instead of independent argmax. jev_choice keeps the
  argmax; overrides are recorded in fallback. The same penalty enables
  per-step diversity re-ranking in serial/decompose modes.
- group_by: hierarchical routing (coarse Choice over candidate groups,
  then within the winning group), both calls kept in raw_jev_stages.
- state_detail=targets (serial) and plan_hint: richer state options.

Measured (10 Toolathlon tasks, first-5 tool-call prediction, real MCP
tool inventories, Jev typesafe/jev-1.13-20260917): position-wise hits
38% -> 44% with tool-aware LLM decomposition + thread_context, set
overlap 54% -> 58%; batch+beam (lambda=2.0) 28% -> 36% at zero extra
provider calls. MCP-Atlas regression check with the same configuration:
29% -> 44% hits. Standalone group_by / state_detail=targets did not
improve the baseline and are documented as negative results.

27/27 tests pass, tsc clean, live-verified against the OpenRouter Jev
endpoint.
@BillionsBobby
BillionsBobby merged commit 6a649cc into BillionsBobby:main Sep 18, 2026
1 check passed
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