Switchyard lets LLM applications route traffic across models and providers while preserving native OpenAI and Anthropic API compatibility - enabling flexible model selection, benchmarking, and cost/performance optimization.
Rust
refactor(routing): remove plan-execute routing (#149)
nachiketb-nvidia0a03e6edd90c
diff --git a/.agents/skills/switchyard-coding-agent-launchers/SKILL.md b/.agents/skills/switchyard-coding-agent-launchers/SKILL.mdindex 099bb87cf..8af847140 100644--- a/.agents/skills/switchyard-coding-agent-launchers/SKILL.md+++ b/.agents/skills/switchyard-coding-agent-launchers/SKILL.md@@ -41,7 +41,6 @@ after.| Build one launcher chain | `build_tier_passthrough_switchyard(...)` in `switchyard/lib/route_table_builders.py` || Build/merge YAML routes | `load_route_bundle_table(...)` / `build_route_bundle_table(...)` in `switchyard/cli/route_bundle.py` || Look up upstream model catalogs | `fetch_model_ids(...)` in `switchyard/cli/model_catalog/model_discovery.py` |-| Add a plan-execute route | Add `type: plan_execute` in route YAML; `_plan_execute_switchyard` in `route_bundle.py` maps it to `PlanExecuteProfileConfig`. || Add a deterministic route | Add `type: deterministic` in route YAML; `_deterministic_switchyard` maps it to `DeterministicRoutingProfileConfig`. || Add a preset | Put it beside the profile config under `switchyard/lib/profiles/`; presets return typed config objects, not runnable apps. || Inspect saved defaults | `switchyard configure --show` reads `switchyard/cli/config/user_config.py` and renders via `switchyard/cli/status.py`. |@@ -87,8 +86,6 @@ Route YAML and launchers share this model-dispatch path:direct strong/weak passthrough entries.- `type: deterministic`, `type: escalation_router`, and `type: stage_router`register the route key plus direct strong/weak passthrough entries.-- `type: plan_execute` registers the route key plus the executor as a direct- passthrough; the planner is internal routing logic.- `type: latency_service` and `type: noop` register theroute key.diff --git a/.agents/skills/switchyard-lib-core/SKILL.md b/.agents/skills/switchyard-lib-core/SKILL.mdindex 7bf5268bd..be4e8e026 100644--- a/.agents/skills/switchyard-lib-core/SKILL.md+++ b/.agents/skills/switchyard-lib-core/SKILL.md@@ -63,9 +63,9 @@ Profile-owned construction keeps the full behavior in one reviewable module:5. Use `ProfileSwitchyard(config.build())` only when serving through theexisting Python endpoint contract.-Random routing, deterministic routing, escalation-router, plan-execute,-passthrough, no-op, stage-router, and latency-service profiles are the-reference set under `switchyard/lib/profiles/`.+Random routing, deterministic routing, escalation-router, passthrough, no-op,+stage-router, and latency-service profiles are the reference set under+`switchyard/lib/profiles/`.## Anti-Patternsdiff --git a/CHANGELOG.md b/CHANGELOG.mdindex 895befa69..a711afd12 100644--- a/CHANGELOG.md+++ b/CHANGELOG.md@@ -45,15 +45,9 @@ traffic that sits between client applications and LLM backends.`[cli]`, `[tracing]`, `[intake]`, `[affinity-redis]`, `[all]`. See[Installation](INSTALLATION.md).-### Deprecated--- **`--plan-execute` launcher flag** — slated for removal; plan-execute will be- configured through a `--routing-profiles` YAML bundle instead.-### Notes- The `--deterministic` launcher flag was removed during pre-releasedevelopment — LLM-as-classifier routing is now the implicit default for the`claude` / `codex` / `openclaw` launchers.- Inference Hub integration docs are out of scope for this release.-diff --git a/benchmark/run-baseline.sh b/benchmark/run-baseline.shindex ae71e5097..bc4caa830 100755--- a/benchmark/run-baseline.sh+++ b/benchmark/run-baseline.sh@@ -313,7 +313,7 @@ while [[ $# -gt 0 ]]; do--task-list-file) TASK_LIST_FILE="$2"; shift 2 ;;--harbor-extra) HARBOR_EXTRA+=("$2"); shift 2 ;;--server-extra) SERVER_EXTRA+=("$2"); shift 2 ;;- --strong-model|--weak-model|--classifier-model|--executor-model|--planner-model|--profile|--strong-probability|--planner-cadence-n)+ --strong-model|--weak-model|--classifier-model|--profile|--strong-probability)die "$1 belongs to the removed legacy benchmark launchers; encode server routing in --routing-profiles instead";;--dry-run) DRY_RUN=1; shift ;;diff --git a/crates/switchyard-components/src/intake/context.rs b/crates/switchyard-components/src/intake/context.rsindex 9d633494a..fb063ec71 100644--- a/crates/switchyard-components/src/intake/context.rs+++ b/crates/switchyard-components/src/intake/context.rs@@ -91,7 +91,7 @@ pub struct SubModelCall {pub cached_tokens: i64,/// Router family that made the call (e.g. `deterministic`, `stage_router`).pub router_type: String,- /// Route label the router produced (e.g. `classifier`, `planner`).+ /// Route label the router produced (e.g. `classifier`, `judge`).pub routed_to: String,}diff --git a/crates/switchyard-components/src/stats/accumulator.rs b/crates/switchyard-components/src/stats/accumulator.rsindex 61a99f835..36a583cee 100644--- a/crates/switchyard-components/src/stats/accumulator.rs+++ b/crates/switchyard-components/src/stats/accumulator.rs@@ -302,61 +302,6 @@ impl StatsAccumulator {Ok(())}- /// Records one planner-overhead call's token usage.- ///- /// Parallel to :meth:`record_classifier_usage`: the planner runs- /// out-of-band from the routed-backend chain and lives in its own- /// bucket so the planner-model spend never aliases the executor- /// model when both happen to share a model id. Snapshot exposes- /// the bucket under :attr:`StatsSnapshot.planner` and rolls- /// :attr:`CostEstimate.planner_cost` into the headline- /// :attr:`CostEstimate.total_cost`.- pub fn record_planner_usage(- &self,- model: impl Into<String>,- usage: TokenUsage,- latency_ms: Option<f64>,- ) -> Result<()> {- let mut inner = self.lock();- inner.planner_requests = inner.planner_requests.saturating_add(1);- let stats = inner.planner_stats_mut(model.into());- stats.calls = stats.calls.saturating_add(1);- stats.prompt_tokens = stats.prompt_tokens.saturating_add(usage.prompt_tokens);- stats.max_observed_context_tokens = stats- .max_observed_context_tokens- .max(usage.prompt_tokens.saturating_add(usage.completion_tokens));- stats.completion_tokens = stats- .completion_tokens- .saturating_add(usage.completion_tokens);- stats.cached_tokens = stats.cached_tokens.saturating_add(usage.cached_tokens);- stats.cache_creation_tokens = stats- .cache_creation_tokens- .saturating_add(usage.cache_creation_tokens);- stats.reasoning_tokens = stats- .reasoning_tokens- .saturating_add(usage.reasoning_tokens);- if let Some(latency) = latency_ms {- stats.model_call_latency.record(latency);- stats.total_latency.record(latency);- }- Ok(())- }-- /// Records a planner-call failure.- ///- /// Mirror of :meth:`record_classifier_error`. Used by- /// :class:`switchyard.lib.processors.plan_execute.PlanningRequestProcessor`- /// in its fail-open branch so silent planner failures still count- /// against the planner bucket on :attr:`StatsSnapshot.planner`.- pub fn record_planner_error(&self, model: impl Into<String>) -> Result<()> {- let mut inner = self.lock();- inner.planner_requests = inner.planner_requests.saturating_add(1);- inner.planner_errors = inner.planner_errors.saturating_add(1);- let stats = inner.planner_stats_mut(model.into());- stats.errors = stats.errors.saturating_add(1);- Ok(())- }-/// Returns a computed snapshot suitable for JSON serialization.pub fn snapshot(&self) -> Result<StatsSnapshot> {let inner = self.lock().clone();@@ -395,10 +340,6 @@ struct StatsAccumulatorInner {classifier_model_order: Vec<String>,classifier_requests: u64,classifier_errors: u64,- by_planner: BTreeMap<String, ModelStats>,- planner_model_order: Vec<String>,- planner_requests: u64,- planner_errors: u64,routing_decisions: BTreeMap<String, BTreeMap<String, u64>>,}@@ -423,16 +364,6 @@ impl StatsAccumulatorInner {}}- fn planner_stats_mut(&mut self, model: String) -> &mut ModelStats {- match self.by_planner.entry(model) {- Entry::Occupied(entry) => entry.into_mut(),- Entry::Vacant(entry) => {- self.planner_model_order.push(entry.key().clone());- entry.insert(ModelStats::default())- }- }- }-fn tier_stats_mut(&mut self, tier: &str, model: &str) -> Option<&mut TierStats> {let tier = tier.trim();if tier.is_empty() {@@ -482,13 +413,8 @@ impl StatsAccumulatorInner {);cost_estimate.classifier_cost = classifier.cost_estimate.total_cost;- let planner =- build_planner_snapshot(&self.by_planner, self.planner_requests, self.planner_errors);- cost_estimate.planner_cost = planner.cost_estimate.total_cost;-- cost_estimate.total_cost = round6(- cost_estimate.backend_cost + cost_estimate.classifier_cost + cost_estimate.planner_cost,- );+ cost_estimate.total_cost =+ round6(cost_estimate.backend_cost + cost_estimate.classifier_cost);StatsSnapshot {total_requests: self.total_requests,@@ -499,7 +425,6 @@ impl StatsAccumulatorInner {models,routing_overhead: self.routing_overhead.snapshot(),classifier,- planner,routing_decisions: self.routing_decisions.clone(),}}@@ -599,22 +524,6 @@ fn build_classifier_snapshot(}}-fn build_planner_snapshot(- by_planner: &BTreeMap<String, ModelStats>,- total_requests: u64,- total_errors: u64,-) -> PlannerStatsSnapshot {- let (models, totals) = build_model_snapshots(by_planner, total_requests);- let cost_estimate = estimate_cost(&models);- PlannerStatsSnapshot {- total_requests,- total_errors,- total_tokens: totals,- models,- cost_estimate,- }-}-#[derive(Clone, Debug, Default)]struct ModelStats {calls: u64,@@ -758,7 +667,6 @@ pub struct StatsSnapshot {pub routing_overhead: LatencyHistogramSnapshot,pub cost_estimate: CostEstimate,pub classifier: ClassifierStatsSnapshot,- pub planner: PlannerStatsSnapshot,pub routing_decisions: BTreeMap<String, BTreeMap<String, u64>>,}@@ -773,22 +681,6 @@ pub struct ClassifierStatsSnapshot {pub cost_estimate: CostEstimate,}-/// Planner-overhead stats, recorded out-of-band from routed-backend-/// traffic. Parallel to :class:`ClassifierStatsSnapshot`; the-/// :class:`switchyard.lib.processors.plan_execute.PlanningRequestProcessor`-/// emits one record per planner call (usage on success,-/// error-only on fail-open) so the planner's spend and failure rate-/// are first-class on the stats endpoint instead of being inferable-/// only from the per-request audit log.-#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]-pub struct PlannerStatsSnapshot {- pub total_requests: u64,- pub total_errors: u64,- pub total_tokens: TokenTotals,- pub models: BTreeMap<String, ModelStatsSnapshot>,- pub cost_estimate: CostEstimate,-}-/// Aggregate token totals.#[derive(Clone, Debug, Default, Eq, PartialEq, Serialize, Deserialize)]pub struct TokenTotals {diff --git a/crates/switchyard-components/src/stats/cost.rs b/crates/switchyard-components/src/stats/cost.rsindex 2b8d89282..8d1ba43ce 100644--- a/crates/switchyard-components/src/stats/cost.rs+++ b/crates/switchyard-components/src/stats/cost.rs@@ -14,18 +14,15 @@ use super::accumulator::ModelStatsSnapshot;/// `total_cost` is the grand total spend including overhead calls;/// `backend_cost` is the portion attributed to routed-backend traffic;/// `classifier_cost` is the LLM-classifier-overhead portion (zero unless-/// `record_classifier_usage` has been called);-/// `planner_cost` is the planner-overhead portion (zero unless-/// `record_planner_usage` has been called). The split exists because the-/// default TB-lite configs can use the same model id for multiple-/// buckets and a single-row aggregation cannot distinguish them.+/// `record_classifier_usage` has been called). The split exists because the+/// default TB-lite configs can use the same model id for the classifier and+/// backend buckets, and a single-row aggregation cannot distinguish them.#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]pub struct CostEstimate {pub models: BTreeMap<String, CostBreakdown>,pub total_cost: f64,pub backend_cost: f64,pub classifier_cost: f64,- pub planner_cost: f64,}/// Per-model cost breakdown.@@ -70,7 +67,6 @@ pub fn estimate_cost(models: &BTreeMap<String, ModelStatsSnapshot>) -> CostEstimtotal_cost: total,backend_cost: total,classifier_cost: 0.0,- planner_cost: 0.0,}}diff --git a/crates/switchyard-components/tests/intake_response_processor.rs b/crates/switchyard-components/tests/intake_response_processor.rsindex 2a00561f7..56ecd9556 100644--- a/crates/switchyard-components/tests/intake_response_processor.rs+++ b/crates/switchyard-components/tests/intake_response_processor.rs@@ -96,12 +96,12 @@ async fn response_processor_emits_a_record_per_submodel_call() -> Result<()> {routed_to: "classifier".to_string(),},SubModelCall {- model: "planner".to_string(),+ model: "judge".to_string(),prompt_tokens: 50,completion_tokens: 5,cached_tokens: 0,- router_type: "plan_execute".to_string(),- routed_to: "planner".to_string(),+ router_type: "escalation_router".to_string(),+ routed_to: "judge".to_string(),},]));@@ -117,7 +117,7 @@ async fn response_processor_emits_a_record_per_submodel_call() -> Result<()> {.filter_map(|payload| payload["request"]["switchyard"]["routing"]["routed_to"].as_str()).collect();assert!(routed.contains(&"classifier"));- assert!(routed.contains(&"planner"));+ assert!(routed.contains(&"judge"));Ok(())}diff --git a/crates/switchyard-components/tests/stats_accumulator.rs b/crates/switchyard-components/tests/stats_accumulator.rsindex 6ba105904..d6cd37401 100644--- a/crates/switchyard-components/tests/stats_accumulator.rs+++ b/crates/switchyard-components/tests/stats_accumulator.rs@@ -397,7 +397,7 @@ fn tier_rollup_keeps_distinct_tiers_for_shared_model() -> Result<()> {None,Some("weak"),)?;- accumulator.record_success("shared/model", None, Some("executor"))?;+ accumulator.record_success("shared/model", None, Some("primary"))?;accumulator.record_usage("shared/model",TokenUsage {@@ -407,7 +407,7 @@ fn tier_rollup_keeps_distinct_tiers_for_shared_model() -> Result<()> {},None,None,- Some("executor"),+ Some("primary"),)?;let snapshot = accumulator.snapshot()?;@@ -425,14 +425,14 @@ fn tier_rollup_keeps_distinct_tiers_for_shared_model() -> Result<()> {assert_eq!(weak.prompt_tokens, 2);assert_eq!(weak.completion_tokens, 3);- let executor = snapshot+ let primary = snapshot.tiers- .get("executor")- .ok_or_else(|| SwitchyardError::Other("executor tier should exist".to_string()))?;- assert_eq!(executor.model, "shared/model");- assert_eq!(executor.calls, 1);- assert_eq!(executor.prompt_tokens, 5);- assert_eq!(executor.completion_tokens, 7);+ .get("primary")+ .ok_or_else(|| SwitchyardError::Other("primary tier should exist".to_string()))?;+ assert_eq!(primary.model, "shared/model");+ assert_eq!(primary.calls, 1);+ assert_eq!(primary.prompt_tokens, 5);+ assert_eq!(primary.completion_tokens, 7);Ok(())}@@ -461,7 +461,7 @@ fn tier_usage_can_attach_explicit_untiered_success() -> Result<()> {},None,None,- Some("executor"),+ Some("primary"),)?;let snapshot = accumulator.snapshot()?;@@ -478,13 +478,13 @@ fn tier_usage_can_attach_explicit_untiered_success() -> Result<()> {assert_eq!(weak.prompt_tokens, 2);assert_eq!(weak.completion_tokens, 3);- let executor = snapshot+ let primary = snapshot.tiers- .get("executor")- .ok_or_else(|| SwitchyardError::Other("executor tier should exist".to_string()))?;- assert_eq!(executor.calls, 1);- assert_eq!(executor.prompt_tokens, 5);- assert_eq!(executor.completion_tokens, 7);+ .get("primary")+ .ok_or_else(|| SwitchyardError::Other("primary tier should exist".to_string()))?;+ assert_eq!(primary.calls, 1);+ assert_eq!(primary.prompt_tokens, 5);+ assert_eq!(primary.completion_tokens, 7);Ok(())}@@ -545,7 +545,7 @@ fn already_attributed_usage_does_not_consume_legacy_pending_success() -> Result<},None,None,- Some("executor"),+ Some("primary"),)?;let snapshot = accumulator.snapshot()?;@@ -562,13 +562,13 @@ fn already_attributed_usage_does_not_consume_legacy_pending_success() -> Result<assert_eq!(weak.prompt_tokens, 2);assert_eq!(weak.completion_tokens, 3);- let executor = snapshot+ let primary = snapshot.tiers- .get("executor")- .ok_or_else(|| SwitchyardError::Other("executor tier should exist".to_string()))?;- assert_eq!(executor.calls, 1);- assert_eq!(executor.prompt_tokens, 5);- assert_eq!(executor.completion_tokens, 7);+ .get("primary")+ .ok_or_else(|| SwitchyardError::Other("primary tier should exist".to_string()))?;+ assert_eq!(primary.calls, 1);+ assert_eq!(primary.prompt_tokens, 5);+ assert_eq!(primary.completion_tokens, 7);Ok(())}@@ -702,32 +702,6 @@ fn classifier_bucket_keeps_same_model_separate_from_routed_traffic() -> Result<(Ok(())}-#[test]-fn planner_bucket_tracks_max_observed_context_tokens() -> Result<()> {- let accumulator = StatsAccumulator::new();- for (prompt_tokens, completion_tokens) in [(120, 0), (300, 5), (200, 200)] {- accumulator.record_planner_usage(- "planner/model",- TokenUsage {- prompt_tokens,- completion_tokens,- ..TokenUsage::default()- },- None,- )?;- }-- let snapshot = accumulator.snapshot()?;- let planner = snapshot- .planner- .models- .get("planner/model")- .ok_or_else(|| SwitchyardError::Other("planner row missing".to_string()))?;- assert_eq!(planner.prompt_tokens, 620);- assert_eq!(planner.max_observed_context_tokens, 400);- Ok(())-}-#[test]fn classifier_latency_lands_on_classifier_model_call_latency() -> Result<()> {let accumulator = StatsAccumulator::new();diff --git a/crates/switchyard-components/tests/stats_processors.rs b/crates/switchyard-components/tests/stats_processors.rsindex f55e810f2..5ab649d2a 100644--- a/crates/switchyard-components/tests/stats_processors.rs+++ b/crates/switchyard-components/tests/stats_processors.rs@@ -720,8 +720,8 @@ async fn response_processor_uses_selected_target_as_tier_fallback() -> Result<()let accumulator = StatsAccumulator::new();let processor = StatsResponseProcessor::new(accumulator.clone());let mut ctx = ProxyContext::new();- record_backend_selection(&mut ctx, ModelId::new("executor-model")?);- ctx.set_selected_target(LlmTargetId::from_static("executor"));+ record_backend_selection(&mut ctx, ModelId::new("primary-model")?);+ ctx.set_selected_target(LlmTargetId::from_static("primary"));processor.process(@@ -735,9 +735,9 @@ async fn response_processor_uses_selected_target_as_tier_fallback() -> Result<()let snapshot = accumulator.snapshot()?;let tier = snapshot.tiers- .get("executor")- .ok_or_else(|| SwitchyardError::Other("executor tier should be present".to_string()))?;- assert_eq!(tier.model, "executor-model");+ .get("primary")+ .ok_or_else(|| SwitchyardError::Other("primary tier should be present".to_string()))?;+ assert_eq!(tier.model, "primary-model");assert_eq!(tier.prompt_tokens, 3);assert_eq!(tier.completion_tokens, 5);Ok(())diff --git a/crates/switchyard-py/src/component_bindings/stats.rs b/crates/switchyard-py/src/component_bindings/stats.rsindex 170d649b0..c0b09263c 100644--- a/crates/switchyard-py/src/component_bindings/stats.rs+++ b/crates/switchyard-py/src/component_bindings/stats.rs@@ -190,56 +190,6 @@ impl PyStatsAccumulator {})}- #[pyo3(signature = (- model,- prompt_tokens=0,- completion_tokens=0,- cached_tokens=0,- cache_creation_tokens=0,- reasoning_tokens=0,- latency_ms=None,- ))]- #[allow(clippy::too_many_arguments)]- fn record_planner_usage<'py>(- &self,- py: Python<'py>,- model: String,- prompt_tokens: u64,- completion_tokens: u64,- cached_tokens: u64,- cache_creation_tokens: u64,- reasoning_tokens: u64,- latency_ms: Option<f64>,- ) -> PyResult<Bound<'py, PyAny>> {- let accumulator = self.inner.clone();- pyo3_async_runtimes::tokio::future_into_py(py, async move {- let usage = TokenUsage {- prompt_tokens,- completion_tokens,- cached_tokens,- cache_creation_tokens,- reasoning_tokens,- cacheable_prompt_tokens: 0,- };- accumulator- .record_planner_usage(model, usage, latency_ms)- .map_err(py_core_error)- })- }-- fn record_planner_error<'py>(- &self,- py: Python<'py>,- model: String,- ) -> PyResult<Bound<'py, PyAny>> {- let accumulator = self.inner.clone();- pyo3_async_runtimes::tokio::future_into_py(py, async move {- accumulator- .record_planner_error(model)- .map_err(py_core_error)- })- }-fn snapshot<'py>(&self, py: Python<'py>) -> PyResult<Bound<'py, PyAny>> {let accumulator = self.inner.clone();pyo3_async_runtimes::tokio::future_into_py(py, async move {diff --git a/crates/switchyard-py/src/core_bindings/context.rs b/crates/switchyard-py/src/core_bindings/context.rsindex 1a91b0619..57c8fd4b5 100644--- a/crates/switchyard-py/src/core_bindings/context.rs+++ b/crates/switchyard-py/src/core_bindings/context.rs@@ -429,7 +429,7 @@ impl PyProxyContext {/// Records one routing-strategy sub-model call for intake capture.////// Routers that call a model to pick a route (the LLM classifier, the- /// stage-router tier classifier, the plan/execute planner) call this after a+ /// stage-router tier classifier or escalation judge) call this after a/// successful routing call so the response-side intake processor can emit/// each as its own anonymous record — model and token counts only, never the/// messages. Appends to a Rust-typed slot the native intake sink reads, sodiff --git a/switchyard/__init__.py b/switchyard/__init__.pyindex 927385ac5..34b5c35dd 100644--- a/switchyard/__init__.py+++ b/switchyard/__init__.py@@ -62,9 +62,6 @@ from switchyard.lib.profiles import (NoopProfile,NoopProfileConfig,PassthroughProfileConfig,- PlanExecuteConfig,- PlanExecutePresets,- PlanExecuteProfileConfig,Profile,ProfileConfig,ProfileConfigError,@@ -161,9 +158,6 @@ __all__ = ["EscalationRouterProfileConfig","LatencyServiceProfileConfig","PassthroughProfileConfig",- "PlanExecuteConfig",- "PlanExecuteProfileConfig",- "PlanExecutePresets","Profile","ProfileConfig","ProfileConfigError",@@ -206,7 +200,6 @@ __all__ = ["RandomRoutingProcessorConfig","LlmTarget",# Deterministic (LLM-classifier) routing usage case- # Plan-execute (strong planner + weak executor) usage case# Translation engine"TranslationEngine",# ChatResponse typesdiff --git a/switchyard/cli/config/user_config.py b/switchyard/cli/config/user_config.pyindex 3d370c04e..88cddc505 100644--- a/switchyard/cli/config/user_config.py+++ b/switchyard/cli/config/user_config.py@@ -29,7 +29,7 @@ CONFIG_FILENAME = "config.json"CREDENTIALS_FILENAME = "credentials.json"LaunchTarget = Literal["claude", "codex", "openclaw"]-LaunchRouteType = Literal["single", "random", "deterministic", "plan_execute"]+LaunchRouteType = Literal["single", "random", "deterministic"]PRIMARY_TIER = "primary"WEAK_TIER = "weak"@@ -267,8 +267,6 @@ def _route_type_value(data: Mapping[str, object], key: str) -> LaunchRouteType |return "random"if value == "deterministic":return "deterministic"- if value == "plan_execute":- return "plan_execute"return Nonediff --git a/switchyard/cli/launchers/launcher_runtime.py b/switchyard/cli/launchers/launcher_runtime.pyindex 333d424c0..133ca0bc0 100644--- a/switchyard/cli/launchers/launcher_runtime.py+++ b/switchyard/cli/launchers/launcher_runtime.py@@ -270,10 +270,6 @@ def _route_type_summary(route_type: str, route: object, route_key: str) -> str:profile = r.get("profile")profile_part = f", profile={profile}" if profile else ""return f"llm-classifier: strong={_model(r.get('strong'))}, weak={_model(r.get('weak'))}{clf}{profile_part}"- if route_type == "plan_execute":- cadence = r.get("cadence_n")- cadence_part = f", cadence_n={cadence}" if cadence is not None else ""- return f"plan-execute: strong={_model(r.get('strong'))}, weak={_model(r.get('weak'))}{cadence_part}"if route_type == "random_routing":p = r.get("strong_probability", "")return f"random-routing: strong={_model(r.get('strong'))}, weak={_model(r.get('weak'))}, p_strong={p}"diff --git a/switchyard/cli/route_bundle.py b/switchyard/cli/route_bundle.pyindex 02787f99a..a1844900f 100644--- a/switchyard/cli/route_bundle.py+++ b/switchyard/cli/route_bundle.py@@ -41,14 +41,11 @@ from switchyard.lib.profiles import (DeterministicRoutingProfileConfig,EscalationRouterProfileConfig,LatencyServiceProfileConfig,- PlanExecuteProfileConfig,ProfileSwitchyard,StageRouterProfileConfig,)from switchyard.lib.profiles.deterministic_routing_config import DeterministicRoutingConfigfrom switchyard.lib.profiles.escalation_router_config import EscalationRouterConfig-from switchyard.lib.profiles.plan_execute_config import PlanExecuteConfig-from switchyard.lib.profiles.plan_execute_presets import PlanExecutePresetsfrom switchyard.lib.profiles.random_routing import RandomRoutingConfigfrom switchyard.lib.profiles.stage_router_config import StageRouterConfigfrom switchyard.lib.route_table import ChainRuntime, RouteTable@@ -247,19 +244,6 @@ _STAGE_ROUTER_ROUTE_KEYS = ("fallback_target_on_evict",}))-_PLAN_EXECUTE_ROUTE_KEYS = (- _ROUTE_METADATA_KEYS- | _TARGET_DEFAULT_ROUTE_KEYS- | frozenset({- "planner",- "executor",- "cadence_n",- "disable_reasoning",- "fail_open",- "enable_stats",- "fallback_target_on_evict",- })-)_ESCALATION_ROUTE_KEYS = (_ROUTE_METADATA_KEYS| _TARGET_DEFAULT_ROUTE_KEYS@@ -331,7 +315,6 @@ _ROUTE_KEYS_BY_TYPE: Mapping[str, frozenset[str]] = {"deterministic": _DETERMINISTIC_ROUTE_KEYS,"escalation_router": _ESCALATION_ROUTE_KEYS,"stage_router": _STAGE_ROUTER_ROUTE_KEYS,- "plan_execute": _PLAN_EXECUTE_ROUTE_KEYS,}_DEFAULT_KEYS_BY_TYPE: Mapping[str, frozenset[str]] = {"model": _TARGET_DEFAULT_KEYS,@@ -342,16 +325,8 @@ _DEFAULT_KEYS_BY_TYPE: Mapping[str, frozenset[str]] = {"deterministic": _TARGET_DEFAULT_KEYS,"escalation_router": _TARGET_DEFAULT_KEYS,"stage_router": _TARGET_DEFAULT_KEYS,- "plan_execute": _TARGET_DEFAULT_KEYS,}-# Shipping planner/executor model ids for `type: plan_execute` routes, so an-# omitted tier reproduces the retired `--plan-execute` flag. ``api_key=""`` is a-# placeholder — only the tier `.model` strings are read; credentials cascade-# from the route defaults.-_PLAN_EXECUTE_DEFAULTS = PlanExecutePresets.coding_agent_default(api_key="")--def _deterministic_profile_factories() -> dict[str, Any,]:@@ -376,7 +351,7 @@ class _YamlModule(Protocol):#: ``classifier`` tier is intentionally NOT surfaced — it is an internal-only#: LLM call, not a user-facing target._USER_FACING_TIER_FIELDS: tuple[str, ...] = (- "strong", "weak", "planner", "executor", "target",+ "strong", "weak", "target",)@@ -411,8 +386,8 @@ def routing_profile_model_ids(Returns each route's YAML key followed by its tier ``model`` fields(``strong`` / ``weak`` for stage_router/deterministic/random_routing,- ``planner`` / ``executor`` for plan_execute, ``target`` for- ``model`` / ``passthrough``). Declaration order, later duplicates dropped.+ ``target`` for ``model`` / ``passthrough``). Declaration order, later+ duplicates dropped.Returns ``[]`` for a ``None`` or empty bundle.Used by both the configure wizard (preview the picker) and the launchers@@ -878,16 +853,6 @@ def _build_switchyard_for_route(extra_response_processors=extra_response_processors,)- if route_type == "plan_execute":- return _plan_execute_switchyard(- model_id,- route,- target_defaults=target_defaults,- stats=stats,- pre_routing_request_processors=pre_routing_request_processors,- extra_response_processors=extra_response_processors,- )-raise RouteBundleConfigError(f"unsupported route type {route_type!r}")@@ -1247,47 +1212,6 @@ def _stage_router_switchyard()-def _plan_execute_switchyard(- model_id: str,- route: Mapping[str, object],- *,- target_defaults: Mapping[str, object],- stats: StatsAccumulator,- pre_routing_request_processors: Sequence[Any] = (),- extra_response_processors: Sequence[Any] = (),-) -> ChainRuntime:- """Build a strong-planner / weak-executor chain from a ``type: plan_execute`` route.-- Mirrors :func:`_stage_router_switchyard`: tiers and scalar fields go through the- shared ``_route_config`` → :meth:`PlanExecuteConfig.model_validate` path. An- omitted ``planner`` / ``executor`` defaults to the shipping preset model so a- minimal route reproduces the retired ``--plan-execute`` flag; every other- field falls back to ``PlanExecuteConfig``'s own defaults.- """- # Seed omitted tiers with the preset model before the shared coercion path- # (`_route_config` would otherwise reject a missing tier).- route = dict(route)- if route.get("planner") is None:- route["planner"] = _PLAN_EXECUTE_DEFAULTS.planner.model- if route.get("executor") is None:- route["executor"] = _PLAN_EXECUTE_DEFAULTS.executor.model- config_data = _route_config(route, target_defaults, ("planner", "executor"))- config_data.setdefault(- "fallback_target_on_evict", cast(LlmTarget, config_data["planner"]).id,- )- config = PlanExecuteConfig.model_validate(config_data)- return ProfileSwitchyard(- PlanExecuteProfileConfig.from_config(config)- .build()- .with_runtime_components(- stats_accumulator=stats,- enable_stats=config.enable_stats,- pre_request_processors=pre_routing_request_processors,- response_processors=extra_response_processors,- )- )--def _passthrough_target(model_id: str,route: Mapping[str, object],@@ -1531,8 +1455,6 @@ def _route_type(model_id: str, route: Mapping[str, object]) -> str:"escalation_router": "escalation_router","stage_router": "stage_router","stage_router_routing": "stage_router",- "plan": "plan_execute",- "plan_execute": "plan_execute",}try:return aliases[normalized]diff --git a/switchyard/cli/routing/__init__.py b/switchyard/cli/routing/__init__.pyindex 4f64219f9..9e6ed4c86 100644--- a/switchyard/cli/routing/__init__.py+++ b/switchyard/cli/routing/__init__.py@@ -6,7 +6,6 @@from switchyard.cli.routing.route_builder import (LaunchTierConnectivity,build_deterministic_routing_config,- build_plan_execute_config,build_random_routing_config,require_route_model,)@@ -14,7 +13,6 @@ from switchyard.cli.routing.route_builder import (__all__ = ["LaunchTierConnectivity","build_deterministic_routing_config",- "build_plan_execute_config","build_random_routing_config","require_route_model",]diff --git a/switchyard/cli/routing/route_builder.py b/switchyard/cli/routing/route_builder.pyindex 5e86d4491..114d6a84b 100644--- a/switchyard/cli/routing/route_builder.py+++ b/switchyard/cli/routing/route_builder.py@@ -13,8 +13,6 @@ from switchyard.lib.backends.llm_target import BackendFormat, LlmTargetfrom switchyard.lib.profiles import (DeterministicRoutingConfig,DeterministicRoutingPresets,- PlanExecuteConfig,- PlanExecutePresets,)from switchyard.lib.profiles.deterministic_routing_config import ProfileNamefrom switchyard.lib.profiles.random_routing import (@@ -204,86 +202,9 @@ def build_deterministic_routing_config()-def build_plan_execute_config(- route: LaunchRouteConfig,- *,- primary: LaunchTierConnectivity,- backend_format: BackendFormat,- timeout: float | None,-) -> PlanExecuteConfig:- """Layer ``--plan-execute`` CLI overrides on top of the shipping preset.-- The shipping preset (:meth:`PlanExecutePresets.coding_agent_default`)- is the strong-planner + weak-executor pairing carried forward from- commit ``ca5fcd8a``. We start from it and override only the executor- model when the user supplied ``--model``. Planner overrides aren't- exposed on the CLI in v1 — users with a benchmark reason to vary the- planner write a YAML route bundle and pass ``--routing-profiles``.-- Args:- route: Resolved :class:`LaunchRouteConfig`. ``route.model``- carries the user's explicit executor override (``None`` when- not supplied — the preset's Kimi executor wins).- primary: Connectivity for both planner and executor — the- shipping trio runs both against the same NVIDIA Inference- Hub tenancy. The launcher's ``--base-url`` / ``--api-key``- therefore apply uniformly.- backend_format: Wire format pinned by the calling launcher- (codex / openclaw: :class:`BackendFormat.OPENAI`; claude- defaults the same for the shipping pairing).- timeout: Per-request HTTP timeout for the executor backend- (seconds). The planner uses its own timeout from the- preset.- """- preset = PlanExecutePresets.coding_agent_default(- api_key=primary.api_key or "",- base_url=primary.base_url,- timeout_secs=timeout,- )-- # Executor override: --model wins when supplied; otherwise the- # preset's validated weak tier stays.- executor_model = route.model or preset.executor.model- executor_target = LlmTarget(- id="executor",- model=executor_model,- format=backend_format,- api_key=primary.api_key,- base_url=primary.base_url,- timeout_secs=timeout,- )-- # Planner stays on the preset's Opus tier — credentials come- # from the same connectivity bundle so a single --api-key / --base-url- # covers both.- planner_target = LlmTarget(- id="planner",- model=preset.planner.model,- format=preset.planner.format,- api_key=primary.api_key,- base_url=primary.base_url,- timeout_secs=preset.planner.endpoint.timeout_secs,- )-- return PlanExecuteConfig(- planner=planner_target,- executor=executor_target,- cadence_n=preset.cadence_n,- disable_reasoning=preset.disable_reasoning,- fail_open=preset.fail_open,- enable_stats=preset.enable_stats,- fallback_target_on_evict=preset.fallback_target_on_evict,- # Preserve the preset label only when the user did not override- # the executor — once they pin a custom executor the bundle is- # no longer the shipping default.- preset=preset.preset if route.model is None else None,- )--__all__ = ["LaunchTierConnectivity","build_deterministic_routing_config",- "build_plan_execute_config","build_random_routing_config","require_route_model",]diff --git a/switchyard/cli/status.py b/switchyard/cli/status.pyindex 7e07dcdd5..f01d55866 100644--- a/switchyard/cli/status.py+++ b/switchyard/cli/status.py@@ -188,9 +188,7 @@ def render_status(request: StatusRequest) -> str:# bundle on `switchyard launch {claude,codex,openclaw}`.if not isinstance(saved_bundle, dict):lines.append(- "built-in strategies: LLM-as-classifier routing (default, "- "strong/weak); plan-execute (strong-planner + weak-executor) via a "- "type: plan_execute route in a --routing-profiles bundle",+ "built-in strategy: LLM-as-classifier routing (default, strong/weak)",)lines.append(_format_skill_distillation(user_config.skill_distillation))lines += [diff --git a/switchyard/cli/switchyard_cli.py b/switchyard/cli/switchyard_cli.pyindex 5a2d9e260..d5c3c52dd 100644--- a/switchyard/cli/switchyard_cli.py+++ b/switchyard/cli/switchyard_cli.py@@ -932,7 +932,7 @@ def _build_parser() -> argparse.ArgumentParser:" --model X single-model passthrough — every request ""is rewritten to model=X. Falls back to the saved configure default.\n"" --routing-profiles PATH serve a YAML bundle of routes (random, "- "stage_router, plan_execute, passthrough, …); the first declared route "+ "stage_router, passthrough, …); the first declared route ""is the initial model.\n\n""With neither flag, the saved routing bundle from ""`switchyard configure` is used."@@ -1031,7 +1031,7 @@ def _build_parser() -> argparse.ArgumentParser:" --model X single-model passthrough — every request ""is rewritten to model=X. Falls back to the saved configure default.\n"" --routing-profiles PATH serve a YAML bundle of routes (random, "- "stage_router, plan_execute, passthrough, …); the first declared route "+ "stage_router, passthrough, …); the first declared route ""is the initial model.\n\n""With neither flag, the saved routing bundle from ""`switchyard configure` is used."@@ -1126,7 +1126,7 @@ def _build_parser() -> argparse.ArgumentParser:" --model X single-model passthrough — every request ""is rewritten to model=X. Falls back to the saved configure default.\n"" --routing-profiles PATH serve a YAML bundle of routes (random, "- "stage_router, plan_execute, passthrough, …); the first declared route "+ "stage_router, passthrough, …); the first declared route ""is the initial model.\n\n""With neither flag, the saved routing bundle from ""`switchyard configure` is used."diff --git a/switchyard/lib/processors/_structured_output.py b/switchyard/lib/processors/_structured_output.pyindex 9ec73db9a..bdf62aa39 100644--- a/switchyard/lib/processors/_structured_output.py+++ b/switchyard/lib/processors/_structured_output.py@@ -3,11 +3,8 @@"""Strict-mode JSON-schema helpers for OpenAI Structured Outputs.-Shared between :mod:`switchyard.lib.processors.llm_classifier` and-:mod:`switchyard.lib.processors.plan_execute` so the two routers stay in-lock-step on how they ask the upstream model to constrain its JSON-output. Both routers build their ``response_format`` payload via-:func:`build_response_format`; both rely on+Routing processors build their ``response_format`` payload via+:func:`build_response_format` and rely on:func:`to_strict_openai_schema` to translate a pydantic``model_json_schema()`` into the subset OpenAI accepts under``strict: true``.@@ -44,9 +41,8 @@ _STRICT_DROP_KEYS: frozenset[str] = frozenset(# normal schema-annotation dict. Their child keys are user-defined names# (property names, definition names) and must never be filtered against# ``_STRICT_DROP_KEYS`` — a Pydantic model with a field literally named-# ``title`` (e.g. :class:`switchyard.lib.processors.plan_execute.plan.PlanStep`)-# was previously losing that property because ``title`` is also a JSON-# Schema annotation we strip. Recurse into the values; leave the keys+# ``title`` would otherwise lose that property because ``title`` is also a+# JSON Schema annotation we strip. Recurse into the values; leave the keys# untouched._NAME_MAP_KEYS: frozenset[str] = frozenset({diff --git a/switchyard/lib/processors/message_condensing.py b/switchyard/lib/processors/message_condensing.pyindex 7b74832b9..676ac3d55 100644--- a/switchyard/lib/processors/message_condensing.py+++ b/switchyard/lib/processors/message_condensing.py@@ -3,12 +3,12 @@"""Shared helpers for condensing chat requests into routing-side LLM prompts.-The LLM classifier, the escalation judge, and the plan-execute planner all-show an inner LLM a compact view of the live request: anchors (system + first-user message) plus a recent window, with bulk trimmed. These helpers are the-common plumbing — message trimming, content flattening, truncation, and-output-fence stripping — shared so the routing processors condense requests-consistently instead of each keeping a private copy.+The LLM classifier and escalation judge show an inner LLM a compact view of+the live request: anchors (system + first user message) plus a recent window,+with bulk trimmed. These helpers are the common plumbing — message trimming,+content flattening, truncation, and output-fence stripping — shared so the+routing processors condense requests consistently instead of each keeping a+private copy."""from __future__ import annotationsdiff --git a/switchyard/lib/processors/plan_execute/__init__.py b/switchyard/lib/processors/plan_execute/__init__.pydeleted file mode 100644index 8eaff913f..000000000--- a/switchyard/lib/processors/plan_execute/__init__.py+++ /dev/null@@ -1,72 +0,0 @@-# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.-# SPDX-License-Identifier: Apache-2.0--"""LLM-backed planner / executor primitives.--A request-augmentation pattern that calls a planner LLM, which decides-per turn whether the executor needs a (fresh) plan and, if so, emits-``plan_text`` — first-person prefill content that the processor appends-as an ``assistant`` turn at the end of the outbound conversation so-the executor continues from there. When the planner declines-(``plan_needed=False``), the request body is left untouched and the-:class:`PlannerDecision` is stamped on ctx for observability.--The plan is *only* prefilled into the executor's request — it is never-echoed back to the client. Plans guide one turn of executor-generation and do not persist into the agent harness's conversation-history. See the benchmark results in-the project history for the rationale: echoing plans into the response-broke strict-JSON parsers downstream (terminus-2 reported ``Extra text-detected before JSON object``) and provided no measurable lift over a-no-planner baseline.--Independent of :mod:`switchyard.lib.processors.llm_classifier`: the planner-does not read :class:`RouteSignals` or the tier decision, and the-classifier does not read the plan. The two are composable —-typically classifier first to pick a tier, planner after to enrich-the prompt — but should be imported, configured, and reasoned about-separately.--Import explicitly from this subpackage::-- from switchyard.lib.processors.plan_execute import (- PlanningRequestProcessor,- PlanningConfig,- PlannerDecision,- CTX_PLANNER_DECISION,- )-"""--from switchyard.lib.processors.plan_execute.plan import (- CTX_PLANNER_DECISION,- PlannerDecision,-)-from switchyard.lib.processors.plan_execute.request_processor import (- DEFAULT_INITIAL_PLANNER_SYSTEM_PROMPT,- DEFAULT_REVISION_PLANNER_SYSTEM_PROMPT,- OpenAIChatPlannerClient,- PlannerClient,- PlannerCompletion,- PlanningConfig,- PlanningError,- PlanningRequestProcessor,- PlanningTriggerMode,- is_anthropic_model,- parse_planner_decision,-)--__all__ = [- "CTX_PLANNER_DECISION",- "DEFAULT_INITIAL_PLANNER_SYSTEM_PROMPT",- "DEFAULT_REVISION_PLANNER_SYSTEM_PROMPT",- "OpenAIChatPlannerClient",- "PlannerClient",- "PlannerCompletion",- "PlannerDecision",- "PlanningConfig",- "PlanningError",- "PlanningRequestProcessor",- "PlanningTriggerMode",- "is_anthropic_model",- "parse_planner_decision",-]diff --git a/switchyard/lib/processors/plan_execute/plan.py b/switchyard/lib/processors/plan_execute/plan.pydeleted file mode 100644index 0d9e88d12..000000000--- a/switchyard/lib/processors/plan_execute/plan.py+++ /dev/null@@ -1,86 +0,0 @@-# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.-# SPDX-License-Identifier: Apache-2.0--"""Slim planner-decision contract for the planner / executor pattern.--The planner LLM emits a two-field JSON object:--* ``plan_needed`` — boolean gate. ``False`` means the planner declined- to plan (fast path; ``plan_text`` is empty). ``True`` means the- planner is contributing a plan to inject.-* ``plan_text`` — the literal content the executor will see as an- assistant prefill. When ``plan_needed=True`` this is the agent's- drafted thinking written in first-person ("I'll approach this as- follows: ..."); when ``plan_needed=False`` this is empty.--Why so slim:--* Earlier versions emitted a structured :class:`ExecutionPlan` (steps,- risks, test strategy, confidence) and ran the output through a- ``render_execution_plan`` templater. Strict JSON-schema decoder- enforcement on a nested-object shape was fragile (the Pydantic- ``title`` field on the old ``PlanStep`` class collided with- ``_STRICT_DROP_KEYS`` and silently stripped the property — see the- 929/929 silent fail-open on the 2026-05-14 cheap-planner-control- sweep).-* The injection mechanism is now assistant-prefill: we paste the- planner's text directly into the conversation as the executor's- opening response. No template, no field extraction — the planner's- output literally is the prefill content. A flat two-field schema- has no nested objects to collide with strict-mode drop rules, and- the planner can format ``plan_text`` however fits the task- (numbered steps, paragraph, bullets — the executor sees prose, not- structured data).-"""--from __future__ import annotations--from pydantic import BaseModel, ConfigDict, model_validator--#: ``ProxyContext.metadata`` key for the full :class:`PlannerDecision`.-#:-#: Always stamped when the planner runs successfully (both the-#: ``plan_needed=True`` and ``plan_needed=False`` branches).-CTX_PLANNER_DECISION = "_planner_decision"---class PlannerDecision(BaseModel):- """Slim two-field wrapper for the planner LLM's output.-- Shape:-- * ``plan_needed=False``: ``plan_text`` must be empty. The fast- path — the planner is saying "no new plan is warranted on this- turn; the existing conversation anchor is sufficient." The- processor leaves the request body untouched.- * ``plan_needed=True``: ``plan_text`` is non-empty and contains- the prefill content for the executor. The processor appends an- ``{"role": "assistant", "content": plan_text}`` entry to the- outbound conversation so the executor continues from there.-- No nested objects, no rendered-template step types — see the- module docstring for why.- """-- model_config = ConfigDict(frozen=True)-- plan_needed: bool- plan_text: str = ""-- @model_validator(mode="after")- def _validate_consistency(self) -> PlannerDecision:- if not self.plan_needed and self.plan_text:- # Be forgiving but normalize: trust the gate, drop the- # spurious text. The planner system prompt explicitly- # contracts ``plan_needed=false -> plan_text=""``; if the- # model emitted both, the gate wins.- object.__setattr__(self, "plan_text", "")- if self.plan_needed and not self.plan_text.strip():- raise ValueError("plan_needed=True requires non-empty plan_text")- return self---__all__ = [- "CTX_PLANNER_DECISION",- "PlannerDecision",-]diff --git a/switchyard/lib/processors/plan_execute/request_processor.py b/switchyard/lib/processors/plan_execute/request_processor.pydeleted file mode 100644index 2122ed804..000000000--- a/switchyard/lib/processors/plan_execute/request_processor.py+++ /dev/null@@ -1,1009 +0,0 @@-# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.-# SPDX-License-Identifier: Apache-2.0--"""LLM-backed planning request processor."""--import json-import logging-import sys-import time-from dataclasses import dataclass-from enum import Enum-from typing import Any, Protocol--from pydantic import BaseModel, ConfigDict, Field, ValidationError--from switchyard.lib.llm_client import OpenAILLMClient-from switchyard.lib.processors.message_condensing import strip_markdown_fence-from switchyard.lib.processors.plan_execute.plan import (- CTX_PLANNER_DECISION,- PlannerDecision,-)-from switchyard.lib.proxy_context import ProxyContext-from switchyard.lib.stats_accumulator import StatsAccumulator-from switchyard_rust.core import ChatRequest, ChatRequestType--log = logging.getLogger(__name__)--DEFAULT_INITIAL_PLANNER_SYSTEM_PROMPT = """\-You are drafting the agent's opening thought before it tackles a-task. The conversation summary you've been given is the request the-agent is about to handle. **You have not seen the actual codebase-or filesystem** — your job is to outline how the agent should-approach the work, not to prescribe specific file paths or commands-based on assumed structure.--Output exactly one JSON object with two fields:-- {"plan_needed": boolean, "plan_text": string}--# Fast path — no plan--For trivial requests (greetings, single one-line questions,-clarifications, anything answerable in one short turn), emit exactly:-- {"plan_needed": false, "plan_text": ""}--Stop generating immediately. Do not produce any further tokens.--# Slow path — emit a plan--When the task involves multi-step work (debugging, refactoring,-tool orchestration, multi-stage analysis), set plan_needed=true and-populate plan_text with the plan content.--plan_text will be **prepended to the agent's next response** — the-agent will literally start its response with your text and continue-from where you end. So write the plan as the agent's own opening-reasoning, in first-person ("I'll start by ...", "My approach:",-"Let me think this through:").--## What the plan should contain--Use this structure (markdown headers are fine but optional — what-matters is the substance):--* **Context** — one to two sentences on what the task actually- asks for and what success looks like.--* **Approach** — the strategy you'd take, framed as exploration-- first. Start with "I'll first explore the structure to find …"- or "I need to understand X before changing anything," then- describe what comes next. Don't prescribe specific paths or- filenames you'd be guessing at — leave that for the agent to- discover.--* **Steps** — an ordered outline, but framed as *what to investigate- or attempt*, not exact-path-X-do-Y instructions. Example: ✔- "Locate the failing test and read its assertions" rather than ✘- "Edit /app/tests/test_x.py line 42".--* **Risks / unknowns** (optional) — short list of things you're- uncertain about that the agent should pay attention to (e.g.- "Project layout is unknown — agent should verify before assuming- Python vs Node.js"; "Test framework may be pytest or unittest").--* **Verification** — how the agent will know it's done. Frame as- expectations to validate, not commands to run literally.--## What NOT to include--* **Do not list specific file paths** unless the request itself- named them. You're guessing; the agent will discover the real- layout. Bad: "Edit /app/src/main.py line 42". Good: "Locate- the main entry point and adjust the handler."-* **Do not prescribe specific shell commands** unless the request- named them. The agent will choose appropriate commands once it- sees the environment.-* **Do not produce long markdown documentation** — keep the plan- tight, scannable, ~300-500 tokens. This is the agent's *opening- thought*, not a spec.--End with a short transition sentence so the agent rolls naturally-into execution: "Let me start by exploring the workspace." or "I'll-begin with step 1." or similar.--# Do NOT--- Wrap the JSON in markdown code fences (no ``` around the output)-- Include `<plan>` tags or any wrapping markers in plan_text — the- harness adds them-- Emit commentary or chain-of-thought outside the JSON object-"""--DEFAULT_REVISION_PLANNER_SYSTEM_PROMPT = """\-You are a software architect reassessing an ongoing implementation.-The agent has been working on a task using an existing plan, and you-are deciding whether mid-stream revision is warranted.--The conversation summary you've been given starts with the prior-plan (under "Prior plan:"), then the full conversation context-including the agent's actions and any tool results.--Output exactly one JSON object with two fields:-- {"plan_needed": boolean, "plan_text": string}--# Default — no revision--**The dominant case is plan_needed=false.** Most mid-task turns are-steady-state continuation — the existing plan is still good and the-agent should keep working without interruption. Emit exactly:-- {"plan_needed": false, "plan_text": ""}--Stop generating immediately.--# Three reasons to revise--Only set plan_needed=true when one of these applies:--1. **New information contradicts the plan** — the agent discovered the- file layout differs from what was assumed, a dependency is missing,- the test framework is different than the plan presumed.-2. **A tool error reveals a different problem** — the failure makes- clear the original approach won't work as planned.-3. **The user redirected** — the latest user message changes the- task or constrains the approach in a way the prior plan doesn't- cover.--Do **not** revise just to:-- Restate the current plan with cosmetic edits-- Add steps for work the agent has already completed-- Refine wording without substance-- "Improve" a plan that's working fine--# Emitting a revision--If you revise, plan_text will be **prepended to the agent's next-response** with a `<plan>` wrapper. Therefore:--* Briefly acknowledge what changed (one short sentence).-* Update the structured plan (Context / Approach / Steps / Critical- Files / Verification) — preserve continuity with the prior plan;- only revise what actually changed.-* Use first-person voice.-* End with a transition like "Resuming with the revised plan." or- "Continuing from here." so the agent rolls back into execution.--# Do NOT--- Wrap the JSON in markdown code fences-- Include `<plan>` tags or wrapping markers in plan_text — the- harness adds them-- Emit commentary outside the JSON object-"""---class PlanningTriggerMode(str, Enum):- """How :class:`PlanningRequestProcessor` decides whether to run."""-- DISABLED = "disabled"- ALWAYS = "always"---class PlanningError(RuntimeError):- """Raised when the planner cannot produce a valid decision."""---class PlanningConfig(BaseModel):- """Configuration for :class:`PlanningRequestProcessor`.-- Planning is intentionally independent from classifier routing signals.- ``trigger_mode=ALWAYS`` runs the planner LLM for every request; the- planner itself then decides whether the request warrants a plan (see- :class:`PlannerDecision`). ``DISABLED`` skips the planner call- entirely, leaving requests untouched and burning no planner tokens.- """-- model_config = ConfigDict(frozen=True)-- model: str = Field(min_length=1)- api_key: str | None = None- base_url: str | None = None- timeout_s: float | None = Field(default=None, gt=0.0)- max_request_chars: int = Field(default=16_000, ge=256)- trigger_mode: PlanningTriggerMode = PlanningTriggerMode.ALWAYS- inject_plan: bool = True- fail_open: bool = True- initial_system_prompt: str = Field(- default=DEFAULT_INITIAL_PLANNER_SYSTEM_PROMPT,- min_length=1,- )- """Planner system prompt used on the **first** turn of a task —- when the executor conversation has no prior assistant message and- the planner is drafting the opening anchor. The default voice is- "I'll approach this as follows..." (initial intent)."""-- revision_system_prompt: str = Field(- default=DEFAULT_REVISION_PLANNER_SYSTEM_PROMPT,- min_length=1,- )- """Planner system prompt used on **subsequent** turns of a task —- when there is already a prior assistant message and the planner is- deciding whether mid-task replanning is warranted. The default- strongly biases toward ``plan_needed=false`` (fast steady-state)- and only emits a revision when something material changed. The- voice when it does revise is "Pausing to reassess..."."""- #: Hint vLLM upstreams (NVIDIA Inference Hub uses vLLM under LiteLLM)- #: to skip chain-of-thought when generating the planner JSON by- #: sending ``extra_body={"chat_template_kwargs": {"enable_thinking":- #: False}}``. Required for DeepSeek V4 Flash / V4 Pro: without it,- #: those models misroute structured-JSON output into- #: ``reasoning_content`` and leave ``content`` empty, so the planner- #: returns nothing parseable.- #:- #: Defaults to ``False`` because non-DeepSeek upstreams reject the- #: unknown ``chat_template_kwargs`` field — verified empirically:- #: Anthropic Opus on Bedrock 400s with ``"chat_template_kwargs: Extra- #: inputs are not permitted"``. Callers using a DeepSeek planner- #: must set this to ``True`` explicitly.- disable_reasoning: bool = False-- #: Sampling temperature for the planner call. ``0.0`` (default)- #: gives deterministic JSON output on most upstreams. Set to- #: ``None`` to omit the field entirely — required for Bedrock-hosted- #: Anthropic models, which 400 with ``"temperature is deprecated for- #: this model"`` when the field is present at all.- #: :class:`~switchyard.lib.profiles.PlanExecuteProfileConfig`- #: auto-detects Anthropic-family planners (via- #: :func:`is_anthropic_model`) and sets this to ``None`` so Opus 4.7- #: on Bedrock can serve as the planner.- temperature: float | None = 0.0-- #: ``response_format`` override sent on the planner call. Default- #: ``{"type": "json_object"}`` constrains the decoder to valid JSON on- #: most upstreams. Anthropic-via-LiteLLM (Bedrock Opus) has no native- #: ``response_format``: LiteLLM rewrites ``json_object`` into a *forced- #: tool call* to coerce Anthropic's Messages API into emitting JSON, so- #: the planner output arrives in ``tool_calls`` rather than ``content``.- #: :class:`OpenAIChatPlannerClient` reads the tool-call arguments when- #: ``content`` is empty (see :func:`_tool_call_arguments`), so the forced- #: call makes JSON *validity* a hard guarantee rather than a system-prompt- #: hope — there is no need to drop the field for Anthropic planners. Set- #: to ``None`` to omit it entirely.- response_format: dict[str, Any] | None = Field(- default_factory=lambda: {"type": "json_object"},- )-- #: Per-call HTTP headers forwarded on every planner completion.- #: Mirrors :attr:`~switchyard.lib.backends.llm_target.LlmTarget.extra_headers`- #: for the planner's own LLM call, which goes through a separate- #: client (not :class:`LlmTarget`). Typical use: pin- #: ``X-Inference-Priority: batch`` on benchmark deployments so the- #: planner's calls land on the same benchmarking gateway as the- #: executor backend and inherit the relaxed proxy timeout.- #: Unknown headers are silently ignored upstream, so passing them- #: on non-NIH endpoints is benign — except on NIH's Bedrock proxy,- #: where ``X-Inference-Priority`` triggers an alternate IAM-bound- #: route; the benchmark entrypoints gate this header on a- #: ``_NIH_OSS_PROVIDERS`` allowlist.- extra_headers: dict[str, str] | None = None-- #: Throttle the planner LLM call to roughly every ``cadence_n``- #: assistant turns. Default ``2`` empirically beat both ``1``- #: (every turn, expensive + noisy) and ``4`` (too sparse) on the- #: TB-Lite Nemotron-Nano sweep.- #:- #: Turn counting is implicit: the processor scans- #: ``request.body["messages"]`` for ``role: "assistant"`` entries- #: and fires when ``len(assistant_messages) % cadence_n == 0``. So- #: the first turn always plans (zero assistant messages, ``0 % N- #: == 0``); subsequent fires land on turns ``N+1``, ``2N+1``, ...- #:- #: Skipped turns short-circuit with a synthetic "no plan needed"- #: decision — no LLM call, no plan injection, the request flows to- #: the executor unmodified. Use in tandem with ``inject_plan=True``- #: when the executor benefits from a fresh plan periodically but- #: not every turn (e.g. weak open-source executors where the- #: planner is expensive frontier compute). Set to ``1`` to- #: restore the original every-turn behaviour.- cadence_n: int = Field(default=2, ge=1)---@dataclass(frozen=True)-class PlannerCompletion:- """Raw planner LLM output paired with token-usage metadata.-- Mirrors :class:`switchyard.lib.processors.llm_classifier.ClassifierCompletion`:- a thin wrapper that lets :class:`PlanningRequestProcessor` consume- both the JSON payload (which it parses into :class:`PlannerDecision`)- and the upstream's usage report (which it emits in the per-request- audit line so planner-cost can be reconstructed post-hoc).-- ``usage`` is the raw OpenAI-SDK usage object (or any duck-typed- equivalent exposing ``prompt_tokens`` / ``completion_tokens`` /- optional ``prompt_tokens_details.cached_tokens``). It may be- ``None`` when the upstream omits the usage block (some self-hosted- OpenAI-compat servers do).- """-- content: str- usage: Any | None = None---class PlannerClient(Protocol):- """Protocol for the underlying LLM used by the planning processor."""-- async def plan(- self,- *,- model: str,- system_prompt: str,- request_summary: str,- ) -> PlannerCompletion:- """Return the JSON planner output plus its usage block."""- ...---class OpenAIChatPlannerClient:- """OpenAI-chat-compatible implementation of :class:`PlannerClient`."""-- def __init__(- self,- client: OpenAILLMClient,- *,- disable_reasoning: bool = True,- temperature: float | None = 0.0,- response_format: dict[str, Any] | None = None,- extra_headers: dict[str, str] | None = None,- ) -> None:- self._client = client- self._disable_reasoning = disable_reasoning- self._temperature = temperature- # ``response_format=None`` means "omit the field from the- # request"; pass an explicit dict (typically- # ``{"type": "json_object"}``) to send it. PlanningConfig- # supplies the strict-JSON default; direct OpenAIChatPlannerClient- # callers must opt in.- self._response_format = response_format- self._extra_headers = extra_headers-- async def plan(- self,- *,- model: str,- system_prompt: str,- request_summary: str,- ) -> PlannerCompletion:- extra_body: dict[str, Any] | None = None- if self._disable_reasoning:- # Same vLLM ``enable_thinking=False`` hint the classifier- # path uses — see ``PlanningConfig.disable_reasoning``.- extra_body = {"chat_template_kwargs": {"enable_thinking": False}}-- # Build the messages for the planner call. For Anthropic-based- # planners (e.g. Bedrock-Opus) we structure the user message as- # two content blocks with ``cache_control={type: ephemeral}``- # marking the boundary between the stable prefix and the- # varying tail. Anthropic caches everything from the start of- # the prompt through the marker — so the cached prefix- # includes the system prompt AND the stable portion of the- # request_summary. The cached prefix needs to exceed- # **1024 tokens** to hit Anthropic's minimum-cacheable-block- # threshold; the planner system prompt alone is below that, so- # marking just the system block wouldn't cache anything.- # Pairing it with the stable terminus-2-system + first-user- # prefix (typically ~3K tokens of the request_summary) reliably- # clears the threshold on TB-Lite-class tasks.- #- # ``ANTHROPIC_CACHE_PREFIX_CHARS`` slices the request_summary- # at a fixed character offset that should land *past* terminus-2's- # original system + first user message for typical Harbor- # invocations. If the request_summary is shorter than the- # threshold (small smoke tests, etc.), we fall back to no- # splitting since the cache won't fire anyway.- if is_anthropic_model(model) and len(request_summary) > _ANTHROPIC_CACHE_PREFIX_CHARS:- user_content: Any = [- {- "type": "text",- "text": request_summary[:_ANTHROPIC_CACHE_PREFIX_CHARS],- "cache_control": {"type": "ephemeral"},- },- {- "type": "text",- "text": request_summary[_ANTHROPIC_CACHE_PREFIX_CHARS:],- },- ]- else:- user_content = request_summary-- # Build kwargs conditionally so each ``None`` field omits- # itself from the request entirely. Required for Anthropic-via-- # LiteLLM (Bedrock Opus) paths, where ``temperature`` triggers- # a 400 and ``response_format=json_object`` triggers a tool-use- # scaffold that routes the actual output into ``tool_calls``- # rather than ``content``. See the matching PlanningConfig- # fields for the empirical history.- kwargs: dict[str, Any] = {- "model": model,- "messages": [- {"role": "system", "content": system_prompt},- {"role": "user", "content": user_content},- ],- "extra_body": extra_body,- }- if self._temperature is not None:- kwargs["temperature"] = self._temperature- if self._response_format is not None:- kwargs["response_format"] = self._response_format- if self._extra_headers is not None:- kwargs["extra_headers"] = self._extra_headers-- result = await self._client.acompletion(**kwargs)- return PlannerCompletion(- content=_completion_content(result),- usage=getattr(result, "usage", None),- )---def is_anthropic_model(model: str) -> bool:- """True if ``model`` is an Anthropic-based upstream (direct or via- NIH's LiteLLM-Bedrock shim). Used to gate ``cache_control``- markers — Anthropic Messages API requires explicit cache markers- for ephemeral prompt caching, while OpenAI-compatible upstreams- auto-detect cache prefixes.- """- m = model.lower()- return "anthropic" in m or "claude" in m---#: Character offset at which the planner's user content is split so-#: the first chunk carries ``cache_control={type: ephemeral}`` and-#: the second chunk does not. At ~4 chars/token this is ~2000 tokens-#: of user prefix — added to the ~700-1000 tokens of system prompt-#: that precede it, the cached prefix is ~2845 tokens, comfortably-#: above Anthropic's 1024-token minimum cacheable-prefix size.-#:-#: This cut needs to land *inside* the stable portion of the request-#: — for terminus-2-driven Harbor invocations, the first 8K chars of-#: the JSON-dumped request body cover the request envelope plus-#: terminus-2's system prompt plus the original first-user task-#: statement. All three are stable across every turn of a single-#: task, so on turns 2..N the prefix matches turn 1's cache write-#: and Anthropic returns a cache hit. Going larger risks extending-#: into the variable per-turn dialog and breaking cache hits; going-#: smaller still caches but saves fewer tokens. On TB-Lite-class-#: tasks with ~7800-token average prompts, this captures ~36% of-#: each call's input as cacheable.-#:-#: Shorter request_summaries (smoke tests, single-turn requests where-#: the request body is itself < this cut) fall back to a plain-#: string with no split — the cache wouldn't fire anyway since-#: there's no later turn to repeat against.-_ANTHROPIC_CACHE_PREFIX_CHARS = 8000---class PlanningRequestProcessor:- """Generate and optionally inject an execution plan before backend dispatch.-- The planner LLM returns a :class:`PlannerDecision` that either- contains a typed :class:`ExecutionPlan` (``plan_needed=True``) or- declines to plan (``plan_needed=False``). When the planner declines- the request body is left untouched; the decision itself is still- stamped on ctx for observability.- """-- def __init__(- self,- config: PlanningConfig,- *,- client: PlannerClient | None = None,- stats_accumulator: StatsAccumulator | None = None,- ) -> None:- self._config = config- self._client = client or OpenAIChatPlannerClient(- OpenAILLMClient(- api_key=config.api_key,- base_url=config.base_url,- timeout=config.timeout_s,- ),- disable_reasoning=config.disable_reasoning,- temperature=config.temperature,- response_format=config.response_format,- extra_headers=config.extra_headers,- )- #: When set, planner success + failure counts roll into the- #: ``planner`` bucket on ``/v1/routing/stats``. Without it the- #: planner only emits stderr audit lines and is invisible to the- #: stats endpoint. Mirrors the classifier's optional- #: ``stats_accumulator`` pattern.- self._stats_accumulator = stats_accumulator-- async def process(self, ctx: ProxyContext, request: ChatRequest) -> ChatRequest:- if not self._should_plan():- return request-- # Cadence throttle: skip planner LLM call when this turn isn't- # at a cadence boundary. Emits a "skipped" audit line so the- # observer can see how often the cadence elided a call. The- # request flows to the executor unchanged.- if self._config.cadence_n > 1:- body = request.body- messages = body.get("messages", []) if isinstance(body, dict) else []- n_assistant = sum(- 1 for m in messages- if isinstance(m, dict) and m.get("role") == "assistant"- )- if n_assistant % self._config.cadence_n != 0:- print(- f"planner_decision={{"- f"\"skipped\": true, "- f"\"reason\": \"cadence\", "- f"\"n_assistant\": {n_assistant}, "- f"\"cadence_n\": {self._config.cadence_n}"- f"}}",- flush=True,- )- return request-- # Pick initial vs revision system prompt based on whether the- # conversation already contains a ``<plan>...</plan>`` block- # in any prior assistant turn. This is more reliable than- # "any prior assistant turn" because the executor may have- # responded once or twice before the planner started running- # (no prior plan); we only want the revision prompt once an- # actual plan exists in history. See- # :func:`_latest_plan_in_history` for the extraction logic.- prior_plan = _latest_plan_in_history(request)- is_revision = prior_plan is not None- system_prompt = (- self._config.revision_system_prompt- if is_revision- else self._config.initial_system_prompt- )-- request_summary = _summarize_request(- request,- max_chars=self._config.max_request_chars,- )- if is_revision:- # Show the planner the prior plan inline at the top of the- # request summary so it can decide whether to revise.- # Keeps the system prompt cache-friendly (static) while- # giving the revision planner the context it needs. The- # revision system prompt mentions "Prior plan:" so the- # planner knows what to look for here.- request_summary = (- f"Prior plan:\n{prior_plan}\n\n---\n\n{request_summary}"- )- completion: PlannerCompletion | None = None- started_at = time.perf_counter()- try:- completion = await self._client.plan(- model=self._config.model,- system_prompt=system_prompt,- request_summary=request_summary,- )- decision = parse_planner_decision(completion.content)- except Exception as exc:- if not self._config.fail_open:- raise PlanningError("planner failed to produce a valid decision") from exc- log.warning(- "PlanningRequestProcessor: planner failed; continuing without plan: %s",- exc,- )- # Record the failure into the planner bucket on the stats- # accumulator (if wired) so ``/v1/routing/stats`` reports- # ``planner.total_errors`` and the per-model ``errors``- # counter — silent fail-opens otherwise hide the failure- # rate from the benchmark observer. Mirrors the- # classifier's fail-open branch in- # :class:`LLMClassifierRequestProcessor`.- if self._stats_accumulator is not None:- await self._stats_accumulator.record_planner_error(self._config.model)- # Emit a failure-shaped audit line so the same grep that- # tallies plan_needed counts also surfaces fail-open- # invocations. Differentiates ``call`` failures (upstream- # HTTP error before any content) from ``parse`` failures- # (upstream returned content but it didn't validate as a- # PlannerDecision); the latter case includes a truncated- # preview of the raw content so you can iterate the- # planner system prompt without re-running the smoke.- failure_payload: dict[str, Any] = {- "failed": True,- "stage": "parse" if completion is not None else "call",- "error": str(exc)[:200],- }- if completion is not None:- failure_payload["content_preview"] = completion.content[:500]- sys.stderr.write(- f"planner_decision={json.dumps(failure_payload, sort_keys=True)}\n"- )- sys.stderr.flush()- return request-- # Stamp the decision unconditionally so audit logs can see why- # the planner declined to plan when ``plan_needed=False``.- ctx.metadata[CTX_PLANNER_DECISION] = decision-- prompt_tokens, completion_tokens, cached_tokens = _planner_token_counts(- completion.usage,- )- # Record usage so the intake sink emits the planner call as its own- # intake record; the routed-turn record never sees it.- ctx.record_submodel_call(- model=self._config.model,- prompt_tokens=prompt_tokens,- completion_tokens=completion_tokens,- cached_tokens=cached_tokens,- router_type="plan_execute",- routed_to="planner",- )-- # Record planner-side spend into the stats accumulator's- # ``planner`` bucket (if wired). Mirrors the classifier's- # ``record_classifier_usage`` call. Latency captures the full- # planner call: HTTP roundtrip + JSON parse + decision- # validation. When the accumulator isn't wired (e.g. unit- # tests with a fake client), this branch is a no-op and the- # audit line below remains the only observability path.- if self._stats_accumulator is not None:- await self._record_planner_call(- prompt_tokens=prompt_tokens,- completion_tokens=completion_tokens,- cached_tokens=cached_tokens,- latency_ms=(time.perf_counter() - started_at) * 1000,- )-- # One-line audit dump of the planner decision + per-call usage,- # written to stderr directly (not via the logging module) so it- # lands in the captured server log regardless of uvicorn's- # logger config — which does not pick up non-uvicorn package- # loggers. Mirrors the ``classifier_signals=...`` pattern in- # ``LLMClassifierRequestProcessor``. Grep ``planner_decision=``- # to tally plan_needed distribution; cross-reference the- # ``planner`` bucket on ``/v1/routing/stats`` for aggregate- # spend + failure-rate numbers.- audit_payload = _build_audit_payload(- decision, completion.usage, is_revision=is_revision,- )- sys.stderr.write(- f"planner_decision={json.dumps(audit_payload, sort_keys=True)}\n"- )- sys.stderr.flush()-- if not decision.plan_needed:- log.debug(- "PlanningRequestProcessor: planner declined to plan "- "(is_revision=%s); leaving request unmodified.",- is_revision,- )- return request-- # ``PlannerDecision._validate_consistency`` guarantees- # ``plan_text`` is non-empty whenever ``plan_needed`` is True.- # Wrap in ``<plan>...</plan>`` markers so the executor sees an- # explicit, delimited block during prefill generation. The- # plan is never echoed back to the client — terminus-2 sees- # only the executor's continuation.- wrapped = wrap_plan(decision.plan_text)- if self._config.inject_plan:- _inject_plan(request, wrapped)- return request-- def _should_plan(self) -> bool:- return self._config.trigger_mode is PlanningTriggerMode.ALWAYS-- async def _record_planner_call(- self,- prompt_tokens: int,- completion_tokens: int,- cached_tokens: int,- latency_ms: float,- ) -> None:- """Record planner token spend into the ``StatsAccumulator``.-- Records into the planner bucket so the planner model's token spend- doesn't merge with the same-named executor backend (e.g. when running- V4-Pro-as-planner + V4-Pro-as-executor for self-planning sweeps).- Latency is recorded too so the planner-side latency histogram shows up- on the snapshot's ``planner.models`` block. Mirrors- :meth:`switchyard.lib.processors.llm_classifier.LLMClassifierRequestProcessor._record_classifier_call`.- """- assert self._stats_accumulator is not None- await self._stats_accumulator.record_planner_usage(- model=self._config.model,- prompt_tokens=prompt_tokens,- completion_tokens=completion_tokens,- cached_tokens=cached_tokens,- latency_ms=latency_ms,- )---def _planner_token_counts(usage: Any | None) -> tuple[int, int, int]:- """Return ``(prompt, completion, cached)`` tokens from an SDK usage object."""- if usage is None:- return 0, 0, 0- prompt = getattr(usage, "prompt_tokens", 0) or 0- completion = getattr(usage, "completion_tokens", 0) or 0- ptd = getattr(usage, "prompt_tokens_details", None)- cached = (getattr(ptd, "cached_tokens", 0) or 0) if ptd is not None else 0- return prompt, completion, cached---def _build_audit_payload(- decision: PlannerDecision,- usage: Any | None,- *,- is_revision: bool,-) -> dict[str, Any]:- """Build the JSON dict emitted as the ``planner_decision=…`` audit line.-- Pure function so it's trivially testable and the call site stays- short. Tolerates a missing or partial ``usage`` block (some- OpenAI-compat upstreams omit fields) — missing token counts are- reported as ``0`` rather than ``null`` so the field is always- numeric and downstream sums don't have to special-case ``None``.-- Audit shape matches the slim two-field :class:`PlannerDecision`:- ``plan_text_len`` and (when non-empty) a truncated- ``plan_text_preview`` substitute for the old structured- ``plan_step_count`` / ``plan_confidence`` fields. Reading the- audit log feels more like a transcript of the planner's drafted- thoughts than a metrics dump.- """- payload: dict[str, Any] = {- "plan_needed": decision.plan_needed,- "is_revision": is_revision,- "plan_text_len": len(decision.plan_text),- }- if decision.plan_text:- # Truncated preview keeps the audit line scannable while still- # capturing enough content for "did the planner produce- # something coherent?" inspection.- payload["plan_text_preview"] = decision.plan_text[:200]-- prompt_tokens = 0- completion_tokens = 0- cached_tokens = 0- if usage is not None:- prompt_tokens = int(getattr(usage, "prompt_tokens", 0) or 0)- completion_tokens = int(getattr(usage, "completion_tokens", 0) or 0)- prompt_tokens_details = getattr(usage, "prompt_tokens_details", None)- if prompt_tokens_details is not None:- cached_tokens = int(getattr(prompt_tokens_details, "cached_tokens", 0) or 0)- payload["prompt_tokens"] = prompt_tokens- payload["completion_tokens"] = completion_tokens- payload["cached_tokens"] = cached_tokens- return payload---def parse_planner_decision(raw: str) -> PlannerDecision:- """Parse the planner LLM's JSON output into :class:`PlannerDecision`.-- Tolerates a leading ```` ```json ```` fence (some non-strict modes- emit one despite instructions). Any other deviation from the- schema raises :class:`PlanningError`.- """- stripped = strip_markdown_fence(raw)- try:- return PlannerDecision.model_validate_json(stripped)- except ValidationError as exc:- raise PlanningError("planner JSON did not match PlannerDecision") from exc---def _summarize_request(- request: ChatRequest,- *,- max_chars: int,-) -> str:- body = getattr(request, "body", {})- payload = {- "request_type": request.request_type.value,- "body": body,- }- text = json.dumps(payload, default=str, ensure_ascii=False, sort_keys=True)- if len(text) <= max_chars:- return text- return text[: max_chars - 32] + "...<truncated>"---def _latest_plan_in_history(request: ChatRequest) -> str | None:- """Return the content of the most recent ``<plan>...</plan>`` block- in any assistant message in the outbound conversation, or ``None``- if no plan has been emitted yet for this task.-- The presence of such a block in the conversation means the planner- has previously emitted a plan that the response-side prepend- stamped into the executor's content — and terminus-2 has been- echoing it back ever since. When found, the planner uses the- revision system prompt; when absent, it uses the initial prompt.- Walks ``messages`` in reverse so the latest plan (after any- revisions) is what's returned.-- Covers all three wire formats by inspecting the same logical- "messages" array. Anthropic message content can be either a- string or a list of content blocks; both are handled.- """- body = getattr(request, "body", None)- if not isinstance(body, dict):- return None-- if request.request_type is ChatRequestType.OPENAI_CHAT:- messages = body.get("messages")- elif request.request_type is ChatRequestType.ANTHROPIC:- messages = body.get("messages")- elif request.request_type is ChatRequestType.OPENAI_RESPONSES:- raw_input = body.get("input")- messages = raw_input if isinstance(raw_input, list) else None- else:- return None-- if not isinstance(messages, list):- return None-- for msg in reversed(messages):- if not isinstance(msg, dict) or msg.get("role") != "assistant":- continue- text = _assistant_message_text(msg.get("content"))- if not text:- continue- plan = _extract_plan_block(text)- if plan is not None:- return plan- return None---def _assistant_message_text(content: Any) -> str:- """Flatten an assistant message's content into a single string.-- Handles the two common shapes: a plain string (OpenAI Chat) or a- list of content blocks (Anthropic Messages, Responses API). For- block lists, concatenate any text-type block contents.- """- if isinstance(content, str):- return content- if isinstance(content, list):- parts: list[str] = []- for block in content:- if isinstance(block, dict):- # Anthropic-style text block.- if block.get("type") == "text" and isinstance(block.get("text"), str):- parts.append(block["text"])- # OpenAI-style content array also uses {"type": "text", "text": ...}.- elif isinstance(block.get("text"), str):- parts.append(block["text"])- return "\n".join(parts)- return ""---def _extract_plan_block(text: str) -> str | None:- """Extract the content between the most recent ``<plan>`` and- ``</plan>`` markers in ``text``, or ``None`` if no complete block- is present."""- open_idx = text.rfind(PLAN_OPEN_MARKER)- if open_idx < 0:- return None- close_idx = text.find(PLAN_CLOSE_MARKER, open_idx + len(PLAN_OPEN_MARKER))- if close_idx < 0:- return None- return text[open_idx + len(PLAN_OPEN_MARKER) : close_idx].strip()---#: Open marker that wraps the prefilled plan in the executor's-#: request. Used by :func:`_latest_plan_in_history` to detect prior-#: plans in conversation history for revision-mode prompting (a-#: latent path — the chain no longer echoes plans back to the client,-#: so prior plans only appear when an outside caller pre-stamps them).-#: Symmetric open + close form a clean extractable block.-PLAN_OPEN_MARKER = "<plan>"-PLAN_CLOSE_MARKER = "</plan>"---def wrap_plan(plan_text: str) -> str:- """Wrap raw plan content in the ``<plan>...</plan>`` markers.-- The prefill uses the wrapped form so the executor sees an- explicit, delimited block during generation. The markers are- also what :func:`_latest_plan_in_history` searches for when an- upstream pre-stamps a plan into history.- """- return f"{PLAN_OPEN_MARKER}\n{plan_text}\n{PLAN_CLOSE_MARKER}"---def _inject_plan(request: ChatRequest, wrapped_plan: str) -> None:- """Append the wrapped plan as an assistant prefill at the tail of- the outbound conversation.-- The upstream model treats the trailing assistant content as a- prefix and continues from where it ends. Wrapping the plan in- ``<plan>...</plan>`` markers gives the executor an explicit,- delimited block to anchor its generation.-- **Executor contract**: the executor's upstream MUST accept- conversations ending on an ``assistant`` role (assistant prefill).- OpenAI Chat / native Anthropic / OSS-on-NIH vLLM all qualify.- NIH's LiteLLM-Bedrock-Anthropic shim does NOT — Bedrock-hosted- Anthropic models cannot serve as the executor under this- primitive.- """- body = getattr(request, "body", None)- if not isinstance(body, dict):- return-- prefill_msg = {"role": "assistant", "content": wrapped_plan}-- if request.request_type is ChatRequestType.OPENAI_CHAT:- messages = body.get("messages")- if not isinstance(messages, list):- messages = []- body["messages"] = messages- messages.append(prefill_msg)- elif request.request_type is ChatRequestType.ANTHROPIC:- messages = body.get("messages")- if not isinstance(messages, list):- messages = []- body["messages"] = messages- messages.append(prefill_msg)- elif request.request_type is ChatRequestType.OPENAI_RESPONSES:- raw_input = body.get("input")- if isinstance(raw_input, list):- raw_input.append(prefill_msg)- elif isinstance(raw_input, str):- body["input"] = [- {"role": "user", "content": raw_input},- prefill_msg,- ]- else:- body["input"] = [prefill_msg]- else:- return- request.replace_body(body)---def _completion_content(result: Any) -> str:- choices = getattr(result, "choices", None)- if not choices:- raise PlanningError("planner completion had no choices")-- message = getattr(choices[0], "message", None)- content = getattr(message, "content", None)- if isinstance(content, str) and content.strip():- return content-- # Anthropic-via-LiteLLM (Bedrock) fallback: Anthropic's Messages API has- # no native ``response_format``, so LiteLLM coerces- # ``response_format={"type": "json_object"}`` into a forced tool call.- # The planner JSON then arrives in ``tool_calls[0].function.arguments``- # and ``content`` is empty. Read it from there so the forced-tool path- # yields the same JSON string the OpenAI-native path returns in- # ``content`` — ``parse_planner_decision`` validates the shape either way.- tool_arguments = _tool_call_arguments(message)- if tool_arguments is not None:- return tool_arguments-- raise PlanningError("planner completion had empty content")---def _tool_call_arguments(message: Any) -> str | None:- """Return the JSON arguments string of the first tool call, or ``None``.-- LiteLLM rewrites ``response_format={"type": "json_object"}`` into a forced- tool call for Anthropic-on-Bedrock, placing the model's JSON in- ``tool_calls[0].function.arguments`` rather than ``content``. This reads- that argument string so :func:`_completion_content` can fall back to it.- """- tool_calls = getattr(message, "tool_calls", None)- if not tool_calls:- return None- function = getattr(tool_calls[0], "function", None)- arguments = getattr(function, "arguments", None)- if isinstance(arguments, str) and arguments.strip():- return arguments- return None---__all__ = [- "DEFAULT_INITIAL_PLANNER_SYSTEM_PROMPT",- "DEFAULT_REVISION_PLANNER_SYSTEM_PROMPT",- "OpenAIChatPlannerClient",- "PlannerClient",- "PlannerCompletion",- "PlanningConfig",- "PlanningError",- "PlanningRequestProcessor",- "PlanningTriggerMode",- "is_anthropic_model",- "parse_planner_decision",-]diff --git a/switchyard/lib/profiles/__init__.py b/switchyard/lib/profiles/__init__.pyindex b4faa58bf..b7d3de6dc 100644--- a/switchyard/lib/profiles/__init__.py+++ b/switchyard/lib/profiles/__init__.py@@ -24,9 +24,6 @@ from switchyard.lib.profiles.header_routing import (from switchyard.lib.profiles.latency_service import LatencyServiceProfileConfigfrom switchyard.lib.profiles.noop import NoopProfile, NoopProfileConfigfrom switchyard.lib.profiles.passthrough import PassthroughProfileConfig-from switchyard.lib.profiles.plan_execute import PlanExecuteProfileConfig-from switchyard.lib.profiles.plan_execute_config import PlanExecuteConfig-from switchyard.lib.profiles.plan_execute_presets import PlanExecutePresetsfrom switchyard.lib.profiles.protocols import (ContextAwareProfile,Profile,@@ -68,9 +65,6 @@ __all__ = ["NoopProfile","NoopProfileConfig","PassthroughProfileConfig",- "PlanExecuteConfig",- "PlanExecuteProfileConfig",- "PlanExecutePresets","ContextAwareProfile","Profile","ProfileConfig",diff --git a/switchyard/lib/profiles/chain.py b/switchyard/lib/profiles/chain.pyindex 4cd1f1402..0bb1f0849 100644--- a/switchyard/lib/profiles/chain.py+++ b/switchyard/lib/profiles/chain.py@@ -381,7 +381,7 @@ def _attach_stats_to_request_processors(processors: Sequence[Any],stats: StatsAccumulator,) -> None:- """Wire existing classifier/planner stats hooks without config fields."""+ """Wire existing request-processor stats hooks without config fields."""for processor in processors:attach_stats = getattr(processor, "attach_stats_accumulator", None)if callable(attach_stats):diff --git a/switchyard/lib/profiles/plan_execute.py b/switchyard/lib/profiles/plan_execute.pydeleted file mode 100644index 8024cc16a..000000000--- a/switchyard/lib/profiles/plan_execute.py+++ /dev/null@@ -1,87 +0,0 @@-# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.-# SPDX-License-Identifier: Apache-2.0--"""Profile-owned plan-execute construction."""--from __future__ import annotations--from typing import Any, Self--from switchyard.lib.profiles.chain import ComponentChainProfile-from switchyard.lib.profiles.plan_execute_config import PlanExecuteConfig-from switchyard.lib.profiles.table import profile_config-from switchyard.lib.proxy_context import ProxyContext-from switchyard_rust.components import set_stats_route_label-from switchyard_rust.core import ChatRequest--_EXECUTOR_STATS_TARGET = "executor"---class _ExecutorStatsTargetProcessor:- """Stamp executor target metadata so stats rollups stay route-local."""-- def __init__(self, target_id: str) -> None:- self._target_id = target_id-- async def process(self, ctx: ProxyContext, request: ChatRequest) -> ChatRequest:- """Record the executor as the selected stats target before planning."""- ctx.selected_target = self._target_id- set_stats_route_label(ctx, _EXECUTOR_STATS_TARGET)- return request---@profile_config("plan_execute")-class PlanExecuteProfileConfig:- """Profile config wrapper for strong-planner / weak-executor profiles."""-- config: PlanExecuteConfig-- @classmethod- def from_config(cls, config: PlanExecuteConfig) -> Self:- """Create a profile config from the validated parsing model."""- return cls(config=config)-- def build(self) -> ComponentChainProfile:- """Build the plan-execute profile runtime."""- from switchyard.lib.backends.multi_llm_backend import build_native_backend- from switchyard.lib.processors.plan_execute import (- PlanningConfig,- PlanningRequestProcessor,- is_anthropic_model,- )- from switchyard.lib.processors.reasoning_effort_normalizer import (- ReasoningEffortNormalizer,- )-- request_processors: list[Any] = [ReasoningEffortNormalizer()]-- config = self.config- planner_endpoint = config.planner.endpoint- is_anthropic_planner = is_anthropic_model(config.planner.model)- if config.enable_stats:- request_processors.append(_ExecutorStatsTargetProcessor(config.executor.id))- request_processors.append(- PlanningRequestProcessor(- PlanningConfig(- model=config.planner.model,- api_key=planner_endpoint.api_key,- base_url=planner_endpoint.base_url,- timeout_s=planner_endpoint.timeout_secs,- disable_reasoning=config.disable_reasoning,- cadence_n=config.cadence_n,- fail_open=config.fail_open,- temperature=None if is_anthropic_planner else 0.0,- ),- )- )-- backend = build_native_backend(config.executor)-- return ComponentChainProfile(- request_processors=request_processors,- backend=backend,- fallback_target_on_evict=config.fallback_target_on_evict,- )---__all__ = ["PlanExecuteProfileConfig"]diff --git a/switchyard/lib/profiles/plan_execute_config.py b/switchyard/lib/profiles/plan_execute_config.pydeleted file mode 100644index 79d5ccc30..000000000--- a/switchyard/lib/profiles/plan_execute_config.py+++ /dev/null@@ -1,94 +0,0 @@-# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.-# SPDX-License-Identifier: Apache-2.0--"""Config model for the plan-execute profile.--A plan-execute chain pairs a **strong planner** (calls the planner LLM,-emits a :class:`PlannerDecision`, optionally prefills ``plan_text`` into-the executor's request as an assistant turn) with a **weak executor**-that carries out each plan step. The cost-asymmetry is the whole point-— see ``switchyard/lib/profiles/plan_execute_presets.py``-for the rationale.-"""--from __future__ import annotations--from pydantic import BaseModel, ConfigDict, Field, ValidationInfo, field_validator--from switchyard.lib.backends.llm_target import LlmTarget, coerce_llm_target---class PlanExecuteConfig(BaseModel):- """Configuration for the plan-execute profile.-- Attributes:- planner: Strong planner tier. Must support- ``response_format={"type": "json_object"}`` to honour the- :class:`PlanningConfig` default. ``model`` / ``api_key`` /- ``base_url`` / ``timeout_secs`` are forwarded into the- :class:`PlanningConfig` constructed by the profile.- executor: Weak executor tier. Routes the actual user-visible- chat completion. The planner output is prefilled as an- ``assistant`` turn at the end of this tier's request so the- executor continues from the plan rather than re-planning.- cadence_n: Throttle the planner LLM call to roughly every- ``cadence_n`` assistant turns. Default ``2`` empirically beat- both ``1`` (every turn, expensive + noisy) and ``4`` (too- sparse) on the TB-Lite Nemotron-Nano sweep — see commit- ``c9339748``. Set to ``1`` for plan-on-every-turn.- disable_reasoning: Pass through to :class:`PlanningConfig`. ``True``- sends ``extra_body={"chat_template_kwargs":- {"enable_thinking": False}}`` — required for DeepSeek- planners on NVIDIA Inference Hub, harmful for Anthropic-on-- Bedrock planners.- fail_open: When ``True`` (default), planner errors degrade- gracefully — the request flows to the executor unchanged.- When ``False``, planner errors surface as 5xx.- enable_stats: Wire stats request/response processors and a- :class:`StatsLlmBackend` wrapper around the executor.- Default ``True``.- preset: Optional name of the :class:`PlanExecutePresets` preset builder- that produced this config — surfaced via- ``GET /v1/routing/stats`` so saved stats files self-document- which shipping bundle was used.- """-- model_config = ConfigDict(frozen=True, arbitrary_types_allowed=True)-- planner: LlmTarget- executor: LlmTarget- #: Target id the chain executor reroutes to when the picked target is- #: evicted (e.g. context-window overflow). Must match either- #: ``planner.id`` or ``executor.id``.- fallback_target_on_evict: str- cadence_n: int = Field(default=2, ge=1)- disable_reasoning: bool = False- fail_open: bool = True- enable_stats: bool = True- preset: str | None = None-- @field_validator("planner", "executor", mode="before")- @classmethod- def _coerce_target(cls, value: object, info: ValidationInfo) -> LlmTarget:- return coerce_llm_target(value, default_id=info.field_name or "target")-- @field_validator("planner", "executor")- @classmethod- def _target_model_non_empty(cls, tier: LlmTarget) -> LlmTarget:- if not tier.model:- raise ValueError("target.model must be a non-empty string")- return tier-- @field_validator("fallback_target_on_evict")- @classmethod- def _fallback_matches_existing_target(cls, value: str, info: ValidationInfo) -> str:- valid_ids = {info.data[key].id for key in ("planner", "executor") if key in info.data}- if value not in valid_ids:- raise ValueError(- f"fallback_target_on_evict={value!r} must match one of "- f"{sorted(valid_ids)} (the configured planner/executor target ids)"- )- return value---__all__ = ["PlanExecuteConfig"]diff --git a/switchyard/lib/profiles/plan_execute_presets.py b/switchyard/lib/profiles/plan_execute_presets.pydeleted file mode 100644index 831f00ca8..000000000--- a/switchyard/lib/profiles/plan_execute_presets.py+++ /dev/null@@ -1,98 +0,0 @@-# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.-# SPDX-License-Identifier: Apache-2.0--"""Named :class:`PlanExecuteConfig` presets keyed by shipping bundle.--The shipping default :meth:`PlanExecutePresets.coding_agent_default`-pairs a **strong planner** with a **weak executor** — the documented-project stance since commit ``ca5fcd8a`` (April 2026, then on the-LangGraph orchestrator; the principle migrated forward when the-orchestrator was deprecated in favour of the-:class:`switchyard.lib.processors.plan_execute.PlanningRequestProcessor`).--Rationale (verbatim from ``ca5fcd8a``):-- Planning is the high-leverage cognitive task — a bad plan poisons- the whole run and no downstream executor can recover from "step 1:- do the impossible". Decomposition is therefore worth paying a- strong model for. By contrast, each step in a well-decomposed plan- is small, self-contained, and mostly mechanical, so a- weaker/cheaper model can drive it. For plans with more than a- handful of steps the executor cost dominates, and running that- dominant term on the cheap model is the whole point.--Example::-- from switchyard import PlanExecutePresets, PlanExecuteProfileConfig, ProfileSwitchyard-- config = PlanExecutePresets.coding_agent_default(- api_key=nvidia_api_key,- )- switchyard = ProfileSwitchyard(PlanExecuteProfileConfig.from_config(config).build())-"""--from __future__ import annotations--from switchyard.lib.backends.llm_target import BackendFormat, LlmTarget-from switchyard.lib.profiles.plan_execute_config import PlanExecuteConfig--# Shipping presets route through OpenRouter's OpenAI-compatible endpoint-# by default; callers override with ``base_url=`` for another gateway.-_OPENROUTER_BASE_URL = "https://openrouter.ai/api/v1"--# Planner — Claude Opus 4.6 on OpenRouter.-_MODEL_OPUS_4_6_PLANNER = "anthropic/claude-opus-4.6"--# Executor — Kimi K2.6, an OpenRouter-available weak tier for the-# code-level default. NVIDIA executor presets remain available through-# explicit routing profiles.-_MODEL_KIMI_K2_6_EXECUTOR = "moonshotai/kimi-k2.6"---class PlanExecutePresets:- """Builder of pre-built :class:`PlanExecuteConfig` bundles."""-- @staticmethod- def coding_agent_default(- *,- api_key: str,- base_url: str = _OPENROUTER_BASE_URL,- timeout_secs: float | None = 600.0,- ) -> PlanExecuteConfig:- """The coding-agent-launcher default plan-execute pairing.-- Planner: Claude Opus 4.6 (strong reasoning, JSON-strict).- Executor: Kimi K2.6 (cheap, fast, tool-friendly).- Cadence: every 2 assistant turns (validated default).-- Use for any coding-agent launcher (Claude Code, Codex, OpenClaw)- unless you have benchmark numbers showing a different pairing- wins on your workload.- """- return PlanExecuteConfig(- planner=LlmTarget(- id="planner",- model=_MODEL_OPUS_4_6_PLANNER,- format=BackendFormat.OPENAI,- api_key=api_key,- base_url=base_url,- timeout_secs=timeout_secs,- ),- executor=LlmTarget(- id="executor",- model=_MODEL_KIMI_K2_6_EXECUTOR,- format=BackendFormat.OPENAI,- api_key=api_key,- base_url=base_url,- timeout_secs=timeout_secs,- ),- cadence_n=2,- disable_reasoning=False,- fail_open=True,- enable_stats=True,- fallback_target_on_evict="planner",- preset="coding_agent_default",- )---__all__ = ["PlanExecutePresets"]diff --git a/switchyard/lib/route_table_builders.py b/switchyard/lib/route_table_builders.pyindex f4bf5c498..936e6dd52 100644--- a/switchyard/lib/route_table_builders.py+++ b/switchyard/lib/route_table_builders.py@@ -39,7 +39,6 @@ from switchyard.lib.processors.llm_classifier.presets import (from switchyard.lib.profiles.deterministic_routing_config import (DeterministicRoutingConfig,)-from switchyard.lib.profiles.plan_execute_config import PlanExecuteConfigfrom switchyard.lib.profiles.random_routing import RandomRoutingConfigfrom switchyard.lib.route_table import ChainRuntime, RouteTablefrom switchyard.lib.stats_accumulator import StatsAccumulator@@ -438,127 +437,17 @@ def build_deterministic_routing_table(return table-def plan_execute_virtual_model_id(config: PlanExecuteConfig) -> str:- """Stable model id representing this plan-execute bundle.-- Mirrors :func:`deterministic_routing_virtual_model_id` — fingerprints- the planner + executor models so a launcher with multiple plan-execute- bundles per process still produces a unique virtual id per bundle.- """- fingerprint = hashlib.sha1(- "\0".join((- config.planner.model,- config.executor.model,- str(config.cadence_n),- )).encode("utf-8"),- ).hexdigest()[:8]- return f"switchyard-plan-execute-{fingerprint}"---def build_plan_execute_switchyard(- config: PlanExecuteConfig,- stats: StatsAccumulator,- pre_routing_request_processors: Sequence[Any] = (),- extra_response_processors: Sequence[Any] = (),-) -> ChainRuntime:- """Build the plan-execute chain used by the launcher."""- from switchyard.lib.profiles import PlanExecuteProfileConfig, ProfileSwitchyard-- return ProfileSwitchyard(- PlanExecuteProfileConfig.from_config(config)- .build()- .with_runtime_components(- stats_accumulator=stats,- enable_stats=config.enable_stats,- pre_request_processors=pre_routing_request_processors,- response_processors=extra_response_processors,- )- )---def register_plan_execute_policy(- table: RouteTable,- config: PlanExecuteConfig,- plan_execute_switchyard: ChainRuntime,- routing_model: str | None = None,-) -> str:- """Layer a plan-execute policy on top of a passthrough table.-- The executor model is registered separately by- :func:`build_passthrough_table`; the planner is not user-selectable- (it's the routing logic, not a destination).- """- virtual_model = routing_model or plan_execute_virtual_model_id(config)- table.register(- virtual_model,- plan_execute_switchyard,- metadata={- "display_name": "Switchyard plan-execute",- "description": (- f"Strong planner ({config.planner.model}) drafts a plan "- f"every {config.cadence_n} turn(s); cheap executor "- f"({config.executor.model}) continues from the plan."- ),- "capabilities": model_capabilities(config.executor.model),- "switchyard": {- "profile": "plan_execute",- "planner_model": config.planner.model,- "executor_model": config.executor.model,- "cadence_n": config.cadence_n,- },- },- default=True,- )- return virtual_model---def build_plan_execute_table(- config: PlanExecuteConfig,- stats: StatsAccumulator,- plan_execute_switchyard: ChainRuntime,- routing_model: str | None = None,- discovery_fn: DiscoveryFn | None = None,- extra_response_processors: Sequence[Any] = (),- pre_routing_request_processors: Sequence[Any] = (),-) -> RouteTable:- """Compose discovery + plan-execute-policy layers.-- Only the executor tier is registered as a direct passthrough — the- planner is internal to the chain and never user-selectable from the- client's ``/model`` picker.- """- table = build_passthrough_table(- (config.executor,),- stats,- enable_stats=config.enable_stats,- discovery_fn=discovery_fn,- pre_routing_request_processors=pre_routing_request_processors,- extra_response_processors=extra_response_processors,- )- register_plan_execute_policy(- table,- config,- plan_execute_switchyard=plan_execute_switchyard,- routing_model=routing_model,- )- return table--__all__ = ["DiscoveryFn","build_deterministic_routing_table","build_deterministic_routing_switchyard","build_passthrough_table",- "build_plan_execute_table",- "build_plan_execute_switchyard","build_random_routing_table","build_random_routing_switchyard","build_single_model_table","build_tier_passthrough_switchyard","deterministic_routing_virtual_model_id",- "plan_execute_virtual_model_id","random_routing_virtual_model_id","register_deterministic_routing_policy",- "register_plan_execute_policy","register_random_routing_policy",]diff --git a/switchyard_rust/components.pyi b/switchyard_rust/components.pyiindex dc2b76a6e..00a4e876f 100644--- a/switchyard_rust/components.pyi+++ b/switchyard_rust/components.pyi@@ -185,17 +185,6 @@ class StatsAccumulator:latency_ms: float | None = None,) -> None: ...async def record_classifier_error(self, model: str) -> None: ...- async def record_planner_usage(- self,- model: str,- prompt_tokens: int = 0,- completion_tokens: int = 0,- cached_tokens: int = 0,- cache_creation_tokens: int = 0,- reasoning_tokens: int = 0,- latency_ms: float | None = None,- ) -> None: ...- async def record_planner_error(self, model: str) -> None: ...async def snapshot(self) -> dict[str, Any]: ...def snapshot_sync(self) -> dict[str, Any]: ...async def reset(self) -> None: ...diff --git a/tests/_chain_test_helpers.py b/tests/_chain_test_helpers.pyindex a3dfc3ec4..29f290999 100644--- a/tests/_chain_test_helpers.py+++ b/tests/_chain_test_helpers.py@@ -1,18 +1,14 @@# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.# SPDX-License-Identifier: Apache-2.0-"""Shared test infrastructure for classifier and chain-composition tests.+"""Shared test infrastructure for classifier chain tests.Private (underscore-prefixed) module so pytest doesn't try to collectit as a test file. Symbols inside also keep the underscore-privateconvention used by the test files that import them.-Owners are the offline e2e tests for:--* :mod:`tests.test_llm_classifier_e2e` — classifier-only routing chain.-* :mod:`tests.test_classifier_planner_chain` — classifier + planner- composition. The planner-specific stub bodies and URLs live in that- file (not here) so this module stays orthogonal to plan_execute.+The owner is :mod:`tests.test_llm_classifier_e2e`, which exercises the+classifier-only routing chain."""from __future__ import annotations@@ -29,8 +25,8 @@ import httpx# URL + model constants shared between classifier and chain harnesses.# ----------------------------------------------------------------------------#: respx-intercepted classifier endpoint. Distinct from any planner /-#: backend URL so an unexpected hit is caught by missing-mock errors.+#: respx-intercepted classifier endpoint. Distinct from the backend URL so an+#: unexpected hit is caught by missing-mock errors._CLASSIFIER_BASE = "https://classifier.test/v1"_CLASSIFIER_URL = f"{_CLASSIFIER_BASE}/chat/completions"diff --git a/tests/e2e/test_classifier_planner_chain_e2e.py b/tests/e2e/test_classifier_planner_chain_e2e.pydeleted file mode 100644index d9582e4a8..000000000--- a/tests/e2e/test_classifier_planner_chain_e2e.py+++ /dev/null@@ -1,296 +0,0 @@-# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.-# SPDX-License-Identifier: Apache-2.0--"""Real-backend e2e test for the classifier + planner composition.--Exercises the full chain that pairs LLM-classifier routing with the-LLM planner / executor pattern. The two are independent primitives-(:mod:`switchyard.lib.processors.llm_classifier` and-:mod:`switchyard.lib.processors.plan_execute`); this file tests them-**together** to confirm classifier-stamped signals do not interfere-with planner injection and vice versa, end to end against a live backend.--Chain shape::-- inbound ChatRequest- -> LLMClassifierRequestProcessor -> real classifier LLM call- -> SignalTierSelectorRequestProcessor- -> PlanningRequestProcessor -> real planner LLM call- -> DeterministicRoutingLLMBackend- -> per-tier OpenAiPassthroughBackend -> real tier LLM call- (request has planner system- prompt injected)- -> ChatResponse--Sibling pattern: in-process — drive the processors + backend manually-rather than via ``Switchyard.call()`` so we get back the typed-:class:`ChatResponse`.--Dedicated planner-only tests live in-:mod:`tests.e2e.test_planning_request_processor_e2e`; this file is-intentionally focused on **composition**.--Prerequisites:- - ``OPENROUTER_API_KEY`` or ``NVIDIA_API_KEY`` env var (skips otherwise).--Run with::-- OPENROUTER_API_KEY=sk-or-... uv run pytest \- tests/e2e/test_classifier_planner_chain_e2e.py -v-"""--from __future__ import annotations--import logging-from typing import Any--import pytest--from switchyard.lib.backends.deterministic_routing_llm_backend import (- CTX_DETERMINISTIC_ROUTING_TIER,- DeterministicRoutingLLMBackend,-)-from switchyard.lib.backends.llm_target import BackendFormat, LlmTarget-from switchyard.lib.chat_response.base import ChatResponse-from switchyard.lib.processors.llm_classifier import (- CTX_DETERMINISTIC_ROUTE_SIGNALS,- CTX_DETERMINISTIC_TIER_DECISION,- LLMClassifierConfig,- LLMClassifierRequestProcessor,- RouteSignals,- SignalTierSelectorConfig,- SignalTierSelectorRequestProcessor,- TierSelectionDecision,-)-from switchyard.lib.processors.plan_execute import (- CTX_PLANNER_DECISION,- PlannerDecision,- PlanningConfig,- PlanningRequestProcessor,-)-from switchyard.lib.proxy_context import ProxyContext-from switchyard.lib.roles import LLMBackend-from switchyard_rust.core import ChatRequest--from .conftest import get_nvidia_config--# Three real LLM calls per test (classifier + planner + tier). 120s is-# enough headroom for the slowest case under typical live-backend load-# while still failing fast if anything hangs.-pytestmark = [- pytest.mark.integration,- pytest.mark.timeout(120),-]--logger = logging.getLogger("e2e.classifier_planner_chain")--HTTP_TIMEOUT_S = 60.0--_nvidia = get_nvidia_config()-_skip_reason = "OPENROUTER_API_KEY or NVIDIA_API_KEY not set"--BACKEND_BASE_URL = _nvidia["base_url"]--# Same model id for the classifier, planner, and tier backends. This-# test validates end-to-end wiring of the composition, not relative-# capability per role.-CLASSIFIER_MODEL = _nvidia["model"]-PLANNER_MODEL = _nvidia["model"]-BACKEND_MODEL = _nvidia["model"]--# Tier labels mirror the four ``RouteTier`` values so whichever tier-# the live classifier picks resolves to a valid backend.-TIER_LABELS = ("simple", "medium", "complex", "reasoning")---# ----------------------------------------------------------------------------# Helpers-# ------------------------------------------------------------------------------def _chat_request(- *,- user_message: str,- model: str = "placeholder-rewritten-by-router",- **body_overrides: Any,-) -> ChatRequest:- """Build an OpenAI chat :class:`ChatRequest` for the chain.-- The default ``model`` is a placeholder because the deterministic- routing backend rewrites the model per tier.- """- body: dict[str, Any] = {- "model": model,- "messages": [{"role": "user", "content": user_message}],- "max_tokens": 1024,- }- body.update(body_overrides)- return ChatRequest.openai_chat(body)---def _build_classifier_planner_chain() -> tuple[- list[Any], DeterministicRoutingLLMBackend-]:- """Build (processors, backend) for the classifier + planner chain.-- Order: classifier -> tier selector -> planner -> tier backend.- Putting planner *after* the tier selector keeps signal stamping- (which the planner doesn't read) independent of plan generation.- """- classifier = LLMClassifierRequestProcessor(- LLMClassifierConfig(- model=CLASSIFIER_MODEL,- api_key=_nvidia["api_key"],- base_url=BACKEND_BASE_URL,- timeout_s=HTTP_TIMEOUT_S,- ),- )- tier_selector = SignalTierSelectorRequestProcessor(- SignalTierSelectorConfig(default_tier="simple"),- )- planner = PlanningRequestProcessor(- PlanningConfig(- model=PLANNER_MODEL,- api_key=_nvidia["api_key"],- base_url=BACKEND_BASE_URL,- timeout_s=HTTP_TIMEOUT_S,- inject_plan=True,- ),- )- backend = DeterministicRoutingLLMBackend.from_tiers(- tiers={- label: LlmTarget(- model=BACKEND_MODEL,- format=BackendFormat.OPENAI,- api_key=_nvidia["api_key"],- base_url=BACKEND_BASE_URL,- timeout=HTTP_TIMEOUT_S,- )- for label in TIER_LABELS- },- default_tier="simple",- )- return [classifier, tier_selector, planner], backend---async def _call_through_chain(- processors: list[Any],- backend: LLMBackend,- request: ChatRequest,-) -> tuple[ProxyContext, ChatResponse]:- """Run a request through processors + backend in-process."""- ctx = ProxyContext()- for proc in processors:- request = await proc.process(ctx, request)- response = await backend.call(ctx, request)- return ctx, response---def _assistant_text(response: ChatResponse) -> tuple[str, str]:- choice = response.body["choices"][0]- message = choice.get("message", {})- content = message.get("content") or ""- reasoning = str(message.get("reasoning_content") or message.get("reasoning") or "")- return content, reasoning---def _finish_reason(response: ChatResponse) -> object:- return response.body["choices"][0].get("finish_reason")---# ----------------------------------------------------------------------------# Tests — classifier + planner + tier backend-# -----------------------------------------------------------------------------[email protected](not _nvidia["api_key"], reason=_skip_reason)-class TestClassifierPlannerChainLiveE2E:- """Full chain: real classifier + real planner + real tier backend."""-- async def test_classifier_planner_chain_routes_plans_and_serves(self) -> None:- """End-to-end: classifier picks a tier, planner enriches, backend answers.-- Asserts that:-- * the classifier stamped :class:`RouteSignals` and the tier- selector stamped a :class:`TierSelectionDecision`- * the planner stamped a typed :class:`ExecutionPlan` and- rendered plan text on ctx- * the rendered plan text was prepended as a ``system`` turn on- the request the backend received- * the tier backend rewrote the model name to ``BACKEND_MODEL``- * the live backend produced non-empty assistant text- """- processors, backend = _build_classifier_planner_chain()- # Task-shaped prompt: the TB-Lite-tuned planner fast-paths- # ("how would you ...") Q&A asks with ``plan_needed=false``,- # so we phrase as a concrete multi-step engineering task.- request = _chat_request(- user_message=(- "Debug a slow Postgres query in /app/db/reports.py "- "that regresses under concurrent load. Determine "- "whether the cause is lock contention or plan-cache "- "pollution, then implement a fix and verify the "- "p99 latency stays under 100ms at 50-way concurrency."- ),- )-- ctx, response = await _call_through_chain(processors, backend, request)-- assert isinstance(response, ChatResponse), type(response)-- signals = ctx.metadata.get(CTX_DETERMINISTIC_ROUTE_SIGNALS)- assert isinstance(signals, RouteSignals), (- f"classifier did not stamp RouteSignals; metadata keys: "- f"{list(ctx.metadata.keys())}"- )-- decision = ctx.metadata.get(CTX_DETERMINISTIC_TIER_DECISION)- assert isinstance(decision, TierSelectionDecision)- tier = ctx.metadata.get(CTX_DETERMINISTIC_ROUTING_TIER)- assert tier in set(TIER_LABELS), f"unexpected tier picked: {tier!r}"- assert decision.tier == tier-- decision = ctx.metadata.get(CTX_PLANNER_DECISION)- assert isinstance(decision, PlannerDecision), (- f"planner did not stamp PlannerDecision; metadata keys: "- f"{list(ctx.metadata.keys())}"- )- assert decision.plan_needed, (- f"expected plan_needed=True for a multi-step debugging prompt; "- f"planner declined with plan_text_len={len(decision.plan_text)}"- )- assert decision.plan_text.strip(), "PlannerDecision.plan_text was empty"-- messages = request.body["messages"]- # Original user turn preserved at messages[0]; plan prefilled- # as the trailing assistant turn (the executor continues from- # there). The processor wraps plan_text in ``<plan>...</plan>``- # before appending; we validate the prefill directly since the- # plan is never echoed back to the client.- assert messages[0]["role"] == "user"- assert "slow Postgres query" in messages[0]["content"]- assert messages[-1]["role"] == "assistant"- prefill_content = messages[-1]["content"]- assert "<plan>" in prefill_content and "</plan>" in prefill_content- assert decision.plan_text in prefill_content-- actual_model = ctx.selected_model- assert actual_model == BACKEND_MODEL, (- f"unexpected actual model: {actual_model!r}"- )-- content, reasoning = _assistant_text(response)- assert content or reasoning, (- f"expected non-empty assistant text from live backend; "- f"finish_reason={_finish_reason(response)!r}"- )-- logger.info(- " [classifier+planner-e2e] tier=%s task=%s recommended=%s "- "confidence=%.2f plan_text_len=%d content[:80]=%r",- tier,- signals.task_type.value, signals.recommended_tier.value,- signals.confidence,- len(decision.plan_text), content[:80],- )diff --git a/tests/e2e/test_planning_request_processor_e2e.py b/tests/e2e/test_planning_request_processor_e2e.pydeleted file mode 100644index 2222bf04a..000000000--- a/tests/e2e/test_planning_request_processor_e2e.py+++ /dev/null@@ -1,400 +0,0 @@-# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.-# SPDX-License-Identifier: Apache-2.0--"""Real-backend e2e tests for the planner / executor pattern (planner only).--Mirrors :mod:`tests.test_planning_request_processor` (which mocks the-planner via a fake client) but with no mocking — every call hits the selected-live backend::-- inbound ChatRequest- -> PlanningRequestProcessor -> real planner LLM call- -> OpenAiPassthroughBackend -> real downstream LLM call- (request has planner system- prompt injected)- -> ChatResponse--Sibling pattern: in-process — drive the processors + backend manually-rather than via ``Switchyard.call()`` so we get back the typed-:class:`ChatResponse` and can inspect both the post-injection-request body and the response.--Because the planner LLM's output is non-deterministic, tests do not-assert specific plan content. They assert:--* the planner ran (typed :class:`ExecutionPlan` stamped on ctx)-* the rendered plan text was injected into the outbound request body-* the downstream backend produced a well-formed response--This file is **planner-only**. Tests that compose the planner with-the classifier live in-:mod:`tests.e2e.test_classifier_planner_chain_e2e`.--Prerequisites:- - ``OPENROUTER_API_KEY`` or ``NVIDIA_API_KEY`` env var (skips otherwise).--Run with::-- OPENROUTER_API_KEY=sk-or-... uv run pytest \- tests/e2e/test_planning_request_processor_e2e.py -v-"""--from __future__ import annotations--import logging-from typing import Any--import pytest--from switchyard.lib.backends import OpenAiPassthroughBackend-from switchyard.lib.chat_response.base import ChatResponse-from switchyard.lib.processors.plan_execute import (- CTX_PLANNER_DECISION,- PlannerDecision,- PlanningConfig,- PlanningRequestProcessor,- PlanningTriggerMode,-)-from switchyard.lib.proxy_context import ProxyContext-from switchyard.lib.roles import LLMBackend-from switchyard_rust.core import ChatRequest--from .conftest import get_nvidia_config--# Two real LLM calls per planner-only test (planner + downstream). 120s-# is enough headroom under typical live-backend load while still failing fast-# if anything hangs.-pytestmark = [- pytest.mark.integration,- pytest.mark.timeout(120),-]--logger = logging.getLogger("e2e.planning_request_processor")--HTTP_TIMEOUT_S = 60.0--_nvidia = get_nvidia_config()-_skip_reason = "OPENROUTER_API_KEY or NVIDIA_API_KEY not set"--BACKEND_BASE_URL = _nvidia["base_url"]--# Same model name for the planner and the downstream backend. These-# tests validate end-to-end wiring of the planner / executor pattern,-# not relative planner-vs-executor capability. Using one model also-# lets us pin a model known to support-# ``response_format={"type": "json_object"}`` on the selected backend-# (required by :class:`OpenAIChatPlannerClient`).-PLANNER_MODEL = _nvidia["model"]-BACKEND_MODEL = _nvidia["model"]---# ----------------------------------------------------------------------------# Helpers-# ------------------------------------------------------------------------------def _chat_request(- *,- user_message: str,- model: str = BACKEND_MODEL,- **body_overrides: Any,-) -> ChatRequest:- """Build an OpenAI chat :class:`ChatRequest` for the planner-only chain."""- body: dict[str, Any] = {- "model": model,- "messages": [{"role": "user", "content": user_message}],- "max_tokens": 1024,- }- body.update(body_overrides)- return ChatRequest.openai_chat(body)---def _build_planner_only_chain(- *,- trigger_mode: PlanningTriggerMode = PlanningTriggerMode.ALWAYS,- inject_plan: bool = True,- fail_open: bool = True,- planner_base_url: str = BACKEND_BASE_URL,- planner_api_key: str | None = None,- planner_timeout_s: float = HTTP_TIMEOUT_S,-) -> tuple[list[Any], LLMBackend]:- """Build (processors, backend) for the planner-only chain."""- planner = PlanningRequestProcessor(- PlanningConfig(- model=PLANNER_MODEL,- api_key=planner_api_key or _nvidia["api_key"],- base_url=planner_base_url,- timeout_s=planner_timeout_s,- trigger_mode=trigger_mode,- inject_plan=inject_plan,- fail_open=fail_open,- ),- )- backend = OpenAiPassthroughBackend(- api_key=_nvidia["api_key"],- base_url=BACKEND_BASE_URL,- timeout=HTTP_TIMEOUT_S,- )- return [planner], backend---async def _call_through_chain(- processors: list[Any],- backend: LLMBackend,- request: ChatRequest,-) -> tuple[ProxyContext, ChatResponse]:- """Run a request through processors + backend in-process.-- Skips terminal translation on purpose: returning the typed- :class:`ChatResponse` keeps assertions clean.- """- ctx = ProxyContext()- for proc in processors:- request = await proc.process(ctx, request)- response = await backend.call(ctx, request)- return ctx, response---def _assistant_text(response: ChatResponse) -> tuple[str, str]:- choice = response.body["choices"][0]- message = choice.get("message", {})- content = message.get("content") or ""- reasoning = str(message.get("reasoning_content") or message.get("reasoning") or "")- return content, reasoning---def _finish_reason(response: ChatResponse) -> object:- return response.body["choices"][0].get("finish_reason")---# ----------------------------------------------------------------------------# Tests — planner only-# -----------------------------------------------------------------------------[email protected](not _nvidia["api_key"], reason=_skip_reason)-class TestPlanningRequestProcessorLiveE2E:- """Real planner LLM + real downstream backend via the selected live backend."""-- async def test_planner_generates_and_injects_plan(self) -> None:- """Planner decides a multi-step prompt warrants a plan and injects it.-- Verifies the planner / executor contract end-to-end on the- ``plan_needed=True`` branch of :class:`PlannerDecision`:-- * a :class:`PlannerDecision` with ``plan_needed=True`` is- stamped on ``ctx.metadata[CTX_PLANNER_DECISION]``- * a typed :class:`ExecutionPlan` is stamped on- ``ctx.metadata[CTX_EXECUTION_PLAN]`` with at least one- well-formed step- * the rendered plan text on- the wrapped plan in the prefilled assistant message matches what was- prepended as a ``system`` message on the outbound request- * the downstream backend, which sees the injected prompt,- returns a non-empty assistant turn-- The prompt is deliberately multi-step (debugging + diagnostic- proposal) so the planner LLM should reliably choose to plan.- If it doesn't, the assertion failure message surfaces the- decision's ``reason`` to make the model-side regression- obvious.- """- processors, backend = _build_planner_only_chain()- # Phrased as an actionable engineering task (verbs: investigate,- # implement, verify) rather than a Q&A ("outline / suggest").- # The TB-Lite-tuned planner explicitly fast-paths Q&A asks via- # ``plan_needed=false``; task-shaped prompts reliably trigger- # ``plan_needed=true``.- request = _chat_request(- user_message=(- "Debug a flaky pytest in /app/tests/test_cache.py that "- "fails ~1 in 10 runs with a stale-cache error. "- "Investigate whether the cache is per-process or "- "shared across workers, implement a fix in the "- "fixture, and verify the test passes 50 runs in a row."- ),- )-- ctx, response = await _call_through_chain(processors, backend, request)-- assert isinstance(response, ChatResponse), type(response)-- decision = ctx.metadata.get(CTX_PLANNER_DECISION)- assert isinstance(decision, PlannerDecision), (- f"planner did not stamp PlannerDecision; metadata keys: "- f"{list(ctx.metadata.keys())}"- )- assert decision.plan_needed, (- f"expected plan_needed=True for a multi-step debugging prompt; "- f"planner declined with plan_text_len={len(decision.plan_text)}"- )- assert decision.plan_text.strip(), "PlannerDecision.plan_text was empty"-- # Plan was prefilled as the last assistant turn at the tail of- # ``messages`` (the executor continues from where it ends).- # Original user turn is preserved at messages[0]. The- # processor wraps plan_text in ``<plan>...</plan>``; we check- # the prefill directly since the plan is never echoed back to- # the client.- messages = request.body["messages"]- assert messages[0]["role"] == "user"- assert "flaky pytest" in messages[0]["content"]- prefill_content = messages[-1]["content"]- assert messages[-1]["role"] == "assistant"- assert "<plan>" in prefill_content and "</plan>" in prefill_content- assert decision.plan_text in prefill_content-- content, reasoning = _assistant_text(response)- assert content or reasoning, (- f"expected non-empty assistant text from live backend; "- f"finish_reason={_finish_reason(response)!r}"- )-- logger.info(- " [planner-e2e][inject] plan_text_len=%d "- "plan_text[:80]=%r content[:80]=%r",- len(decision.plan_text), decision.plan_text[:80], content[:80],- )-- async def test_planner_declines_to_plan_for_trivial_request(self) -> None:- """Planner decides a one-word reply needs no plan; request stays untouched.-- Verifies the ``plan_needed=False`` branch of- :class:`PlannerDecision`:-- * the planner runs (so :data:`CTX_PLANNER_DECISION` is stamped)- * but it returns ``plan_needed=False`` with a one-line reason- * neither :data:`CTX_EXECUTION_PLAN` nor- the planner declined to plan (no prefill is appended)- * the outbound request body is byte-equal to what the caller- built — no system turn was prepended- * the downstream backend still answers the user-- Prompt is deliberately trivial so the planner should reliably- decline. Like the sibling ``plan_needed=True`` test, this is- sensitive to planner-model variance; the assertion message- flags the model side if the planner ever changes its mind.- """- processors, backend = _build_planner_only_chain()- request = _chat_request(- user_message="Reply with the single word: ok",- )-- ctx, response = await _call_through_chain(processors, backend, request)-- assert isinstance(response, ChatResponse), type(response)-- decision = ctx.metadata.get(CTX_PLANNER_DECISION)- assert isinstance(decision, PlannerDecision)- assert not decision.plan_needed, (- f"expected plan_needed=False for a one-word reply; "- f"planner produced a plan instead "- f"(plan_text[:80]={decision.plan_text[:80]!r})"- )- assert decision.plan_text == ""--- # Request body was not mutated — original user turn is still- # the only message on the outbound request.- messages = request.body["messages"]- assert len(messages) == 1- assert messages[0]["role"] == "user"-- content, reasoning = _assistant_text(response)- assert content or reasoning, (- f"expected non-empty assistant text from live backend; "- f"finish_reason={_finish_reason(response)!r}"- )-- logger.info(- " [planner-e2e][declined] plan_needed=%s content[:80]=%r",- decision.plan_needed, content[:80],- )-- async def test_planner_disabled_leaves_request_untouched(self) -> None:- """``trigger_mode=DISABLED`` skips the planner call entirely.-- No plan is stamped on ctx, no system turn is prepended, and the- downstream backend still answers the original user message.- Sanity check that the disabled path doesn't accidentally inject- a stale plan or burn a planner call.- """- processors, backend = _build_planner_only_chain(- trigger_mode=PlanningTriggerMode.DISABLED,- )- request = _chat_request(- user_message="Reply with the single word: ok",- )-- ctx, response = await _call_through_chain(processors, backend, request)-- assert isinstance(response, ChatResponse), type(response)-- # DISABLED skips the planner call entirely, so no decision is- # even stamped — distinguishable from the ``plan_needed=False``- # case (where the decision IS stamped).- assert CTX_PLANNER_DECISION not in ctx.metadata-- # No system turn was injected — the original user turn is still- # the only message on the outbound request.- messages = request.body["messages"]- assert len(messages) == 1- assert messages[0]["role"] == "user"-- content, reasoning = _assistant_text(response)- assert content or reasoning, (- f"expected non-empty assistant text from live backend; "- f"finish_reason={_finish_reason(response)!r}"- )-- logger.info(- " [planner-e2e][disabled] content[:80]=%r",- content[:80],- )-- async def test_planner_failure_fails_open_to_backend(self) -> None:- """A broken planner upstream must not break downstream inference.-- Points the planner at an unresolvable host while keeping the- downstream backend live. ``fail_open=True`` is the configured- default for :class:`PlanningConfig`, so a planner failure- should leave the request unmodified and still return real- content from the live backend.- """- # Short planner timeout so we don't burn the whole pytest-timeout- # budget waiting for the bogus URL to fail.- processors, backend = _build_planner_only_chain(- planner_base_url="https://planner-does-not-exist.invalid/v1",- planner_api_key="not-used",- planner_timeout_s=5.0,- )- request = _chat_request(- user_message="Reply with the single word: ok",- )-- ctx, response = await _call_through_chain(processors, backend, request)-- assert isinstance(response, ChatResponse), type(response)-- # Planner call failed before producing a valid decision, so- # CTX_PLANNER_DECISION is also absent (distinguishable from a- # valid decision with ``plan_needed=False``, which would stamp- # the decision).- assert CTX_PLANNER_DECISION not in ctx.metadata-- # Request body wasn't mutated — no injected system turn.- messages = request.body["messages"]- assert len(messages) == 1- assert messages[0]["role"] == "user"-- content, reasoning = _assistant_text(response)- assert content or reasoning, (- f"expected non-empty assistant text from live backend after "- f"planner failure; finish_reason="- f"{_finish_reason(response)!r}"- )-- logger.info(- " [planner-e2e][fail-open] content[:80]=%r",- content[:80],- )diff --git a/tests/test_classifier_planner_chain.py b/tests/test_classifier_planner_chain.pydeleted file mode 100644index 21de42c40..000000000--- a/tests/test_classifier_planner_chain.py+++ /dev/null@@ -1,281 +0,0 @@-# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.-# SPDX-License-Identifier: Apache-2.0--"""Production offline e2e test for the classifier + planner composition.--Exercises the chain that pairs LLM-classifier routing with the LLM-planner / executor pattern. The two are independent primitives-(:mod:`switchyard.lib.processors.llm_classifier` and-:mod:`switchyard.lib.processors.plan_execute`); this file tests them-**together** to confirm classifier-stamped signals do not interfere-with planner injection and vice versa.--Chain shape::-- inbound HTTP request- -> Switchyard chain- LLMClassifierRequestProcessor (real OpenAILLMClient -> openai SDK -> httpx)- SignalTierSelectorRequestProcessor- PlanningRequestProcessor (real OpenAILLMClient -> openai SDK -> httpx)- -> DeterministicRoutingLLMBackend- -> per-tier Rust OpenAI backend (real reqwest -> loopback HTTP)- -> TranslationEngine- -> outbound HTTP response--Classifier and planner HTTPS calls are intercepted by ``respx`` on-distinct URLs. Backend tier calls go through local loopback HTTP-servers because Rust reqwest bypasses ``respx``.--Dedicated planner-only tests live in-:mod:`tests.test_planning_request_processor` (mock planner client) and-classifier-only tests in :mod:`tests.test_llm_classifier_e2e`. This-file is intentionally focused on **composition**.-"""--from __future__ import annotations--import json-from collections.abc import AsyncIterator--import httpx-import pytest-import respx--from switchyard.lib.backends.deterministic_routing_llm_backend import (- DeterministicRoutingLLMBackend,-)-from switchyard.lib.backends.llm_target import BackendFormat, LlmTarget-from switchyard.lib.processors.llm_classifier import (- LLMClassifierConfig,- LLMClassifierRequestProcessor,- SignalTierSelectorConfig,- SignalTierSelectorRequestProcessor,-)-from switchyard.lib.processors.plan_execute import (- PlanningConfig,- PlanningRequestProcessor,-)-from switchyard.lib.switchyard import Switchyard-from switchyard.server.switchyard_app import build_switchyard_app-from switchyard_rust.translation import TranslationEngine-from tests._chain_test_helpers import (- _CLASSIFIER_BASE,- _CLASSIFIER_MODEL,- _CLASSIFIER_URL,- _COMPLEX_MODEL,- _SIMPLE_MODEL,- _backend_payload,- _classifier_payload,- _ClassifierHarness,- _last_body,- _OpenAICompatStub,- _signals_json,-)--# ----------------------------------------------------------------------------# Planner-specific URLs / payloads (orthogonal to the classifier helpers, so-# they live here rather than in tests/_chain_test_helpers.py).-# -----------------------------------------------------------------------------_PLANNER_BASE = "https://planner.test/v1"-_PLANNER_URL = f"{_PLANNER_BASE}/chat/completions"--_PLANNER_MODEL = "router-planner-llm"---def _planner_payload(content: str) -> dict[str, object]:- """An OpenAI Chat Completion JSON body whose content is the planner output."""- return {- "id": "chatcmpl-planner",- "object": "chat.completion",- "created": 1700000003,- "model": _PLANNER_MODEL,- "choices": [- {- "index": 0,- "message": {"role": "assistant", "content": content},- "finish_reason": "stop",- }- ],- "usage": {"prompt_tokens": 7, "completion_tokens": 9, "total_tokens": 16},- }---_PLAN_TEXT = (- "I'll approach the traceback systematically:\n"- "1. Inspect the traceback and failing path — identify the component "- "and likely regression surface.\n"- "2. Patch the narrow failure, keeping the change scoped.\n"- "3. Run focused regression tests to verify the fix.\n\n"- "Risk: the traceback may be a symptom of upstream request mutation.\n\n"- "Starting with step 1 now."-)-_WRAPPED_PLAN_TEXT = f"<plan>\n{_PLAN_TEXT}\n</plan>"---def _plan_decision_json(plan_text: str = _PLAN_TEXT) -> str:- """Stub planner output: a ``plan_needed=True`` decision with literal plan text."""- return json.dumps({"plan_needed": True, "plan_text": plan_text})---# ----------------------------------------------------------------------------# Fixture — assembles the classifier + planner composition by hand.-# ------------------------------------------------------------------------------def _build_switchyard_with_planner(- *, simple_base_url: str, complex_base_url: str,-) -> Switchyard:- """Classifier routing chain plus plan-enrichment processor.-- Order mirrors the production wiring: classifier and tier selector- first, planner last among the request processors so the plan is- injected after the tier has been pinned.- """- classifier = LLMClassifierRequestProcessor(- LLMClassifierConfig(- model=_CLASSIFIER_MODEL,- api_key="classifier-key-not-validated",- base_url=_CLASSIFIER_BASE,- ),- )- tier_selector = SignalTierSelectorRequestProcessor(- SignalTierSelectorConfig(default_tier="simple"),- )- planner = PlanningRequestProcessor(- PlanningConfig(- model=_PLANNER_MODEL,- api_key="planner-key-not-validated",- base_url=_PLANNER_BASE,- inject_plan=True,- ),- )- backend = DeterministicRoutingLLMBackend.from_tiers(- tiers={- "simple": LlmTarget(- model=_SIMPLE_MODEL,- format=BackendFormat.OPENAI,- api_key="simple-key",- base_url=simple_base_url,- ),- "complex": LlmTarget(- model=_COMPLEX_MODEL,- format=BackendFormat.OPENAI,- api_key="complex-key",- base_url=complex_base_url,- ),- },- default_tier="simple",- )- return Switchyard(- request_processors=[classifier, tier_selector, planner],- backend=backend,- translator=TranslationEngine(),- )---async def classifier_planner_harness() -> AsyncIterator[_ClassifierHarness]:- """ASGI-transport client wired through classifier, selector, planner, backend."""- with _OpenAICompatStub() as simple, _OpenAICompatStub() as complex:- app = build_switchyard_app(- _build_switchyard_with_planner(- simple_base_url=simple.base_url,- complex_base_url=complex.base_url,- )- )- async with httpx.AsyncClient(- transport=httpx.ASGITransport(app=app, raise_app_exceptions=False),- base_url="http://test",- ) as client:- yield _ClassifierHarness(client=client, simple=simple, complex=complex)---# ----------------------------------------------------------------------------# Tests-# ------------------------------------------------------------------------------class TestClassifierPlannerChainE2E:- """Production offline e2e — classifier routes, planner enriches, backend serves."""-- @respx.mock- async def test_planner_injects_plan_before_backend_dispatch(- self, classifier_planner_harness: _ClassifierHarness,- ) -> None:- """Planner runs as an independent feature and injects plan into backend prompt."""- classifier_route = respx.post(_CLASSIFIER_URL).mock(- return_value=httpx.Response(- 200,- json=_classifier_payload(- _signals_json(- task_type="coding",- complexity="complex",- reasoning_depth="multi_step",- recommended_tier="complex",- confidence=0.92,- reason_code="coding_complex",- ),- ),- )- )- planner_route = respx.post(_PLANNER_URL).mock(- return_value=httpx.Response(- 200,- json=_planner_payload(_plan_decision_json()),- )- )- classifier_planner_harness.complex.respond_json(- _backend_payload(content="planned-complex-reply", model=_COMPLEX_MODEL)- )- classifier_planner_harness.simple.respond_json(- _backend_payload(content="simple-reply", model=_SIMPLE_MODEL)- )-- resp = await classifier_planner_harness.client.post(- "/v1/chat/completions",- json={- "model": "client-requested-model",- "messages": [- {- "role": "user",- "content": "Please debug this traceback and implement the fix.",- }- ],- },- )-- assert resp.status_code == 200, resp.text- body = resp.json()- assert body["choices"][0]["message"]["content"] == "planned-complex-reply"-- assert classifier_route.called- assert planner_route.called- assert classifier_planner_harness.complex.called- assert not classifier_planner_harness.simple.called-- planner_req = json.loads(planner_route.calls.last.request.content)- assert planner_req["model"] == _PLANNER_MODEL- assert planner_req.get("response_format") == {"type": "json_object"}- # The chain has no prior <plan> in history → initial planner- # prompt (which casts the planner as drafting the agent's- # opening thought).- assert "opening thought" in planner_req["messages"][0]["content"].lower()- assert "Please debug this traceback" in planner_req["messages"][1]["content"]- # The planner sees the inbound body but NOT the classifier's- # RouteSignals — the two primitives are decoupled at the prompt- # level too, not just at the import level.- assert '"signals"' not in planner_req["messages"][1]["content"]-- backend_req = _last_body(classifier_planner_harness.complex)- assert backend_req["model"] == _COMPLEX_MODEL- messages = backend_req["messages"]- # User turn is preserved at messages[0]; plan is prefilled as- # the trailing assistant turn (the executor continues from- # there). The prefill is wrapped in ``<plan>...</plan>`` so- # the executor sees an explicit, delimited block during- # generation. The plan is never echoed back to the client.- assert messages[0]["role"] == "user"- assert "Please debug this traceback" in messages[0]["content"]- assert messages[-1]["role"] == "assistant"- assert messages[-1]["content"] == _WRAPPED_PLAN_TEXTdiff --git a/tests/test_configure_model_picker_inputs.py b/tests/test_configure_model_picker_inputs.pyindex 45d7589a9..b9bfa9268 100644--- a/tests/test_configure_model_picker_inputs.py+++ b/tests/test_configure_model_picker_inputs.py@@ -87,23 +87,6 @@ def test_string_shorthand_tier_resolves_to_model_id() -> None:assert _routing_profile_model_ids(bundle) == ["rr", "gpt-4o", "gpt-4o-mini"]-def test_plan_execute_planner_executor_extracted() -> None:- bundle = {- "routes": {- "plan-route": {- "type": "plan_execute",- "planner": {"model": "aws/anthropic/bedrock-claude-opus-4-7"},- "executor": {"model": "nvidia/nvidia/nemotron-3-super-120b-long-ctx"},- },- },- }- assert _routing_profile_model_ids(bundle) == [- "plan-route",- "aws/anthropic/bedrock-claude-opus-4-7",- "nvidia/nvidia/nemotron-3-super-120b-long-ctx",- ]--def test_merge_candidate_ids_dedupes_preserves_first_seen_order() -> None:"""Routing-profile entries first, then upstream catalog. Duplicates fromlater sources drop."""diff --git a/tests/test_launch_claude_plan_execute.py b/tests/test_launch_claude_plan_execute.pydeleted file mode 100644index 96456b358..000000000--- a/tests/test_launch_claude_plan_execute.py+++ /dev/null@@ -1,22 +0,0 @@-# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.-# SPDX-License-Identifier: Apache-2.0--"""Tests asserting ``switchyard launch claude --plan-execute`` is gone.--The ``--plan-execute`` flag has been removed from the ``launch claude``-subparser. Plan-execute routing is now reachable only via a-``type: plan_execute`` route in a ``--routing-profiles`` YAML bundle.-"""--from __future__ import annotations--import pytest---class TestArgparse:- def test_plan_execute_flag_removed(self) -> None:- from switchyard.cli.switchyard_cli import _build_parser-- parser = _build_parser()- with pytest.raises(SystemExit):- parser.parse_args(["launch", "claude", "--plan-execute"])diff --git a/tests/test_launch_codex_plan_execute.py b/tests/test_launch_codex_plan_execute.pydeleted file mode 100644index 1d74e7924..000000000--- a/tests/test_launch_codex_plan_execute.py+++ /dev/null@@ -1,22 +0,0 @@-# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.-# SPDX-License-Identifier: Apache-2.0--"""Tests asserting ``switchyard launch codex --plan-execute`` is gone.--The ``--plan-execute`` flag has been removed from the ``launch codex``-subparser. Plan-execute routing is now reachable only via a-``type: plan_execute`` route in a ``--routing-profiles`` YAML bundle.-"""--from __future__ import annotations--import pytest---class TestArgparse:- def test_plan_execute_flag_removed(self) -> None:- from switchyard.cli.switchyard_cli import _build_parser-- parser = _build_parser()- with pytest.raises(SystemExit):- parser.parse_args(["launch", "codex", "--plan-execute"])diff --git a/tests/test_launch_openclaw_plan_execute.py b/tests/test_launch_openclaw_plan_execute.pydeleted file mode 100644index f5fb450dc..000000000--- a/tests/test_launch_openclaw_plan_execute.py+++ /dev/null@@ -1,22 +0,0 @@-# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.-# SPDX-License-Identifier: Apache-2.0--"""Tests asserting ``switchyard launch openclaw --plan-execute`` is gone.--The ``--plan-execute`` flag has been removed from the ``launch openclaw``-subparser. Plan-execute routing is now reachable only via a-``type: plan_execute`` route in a ``--routing-profiles`` YAML bundle.-"""--from __future__ import annotations--import pytest---class TestArgparse:- def test_plan_execute_flag_removed(self) -> None:- from switchyard.cli.switchyard_cli import _build_parser-- parser = _build_parser()- with pytest.raises(SystemExit):- parser.parse_args(["launch", "openclaw", "--plan-execute"])diff --git a/tests/test_launch_route_builder.py b/tests/test_launch_route_builder.pyindex 3879d3f09..6352302ac 100644--- a/tests/test_launch_route_builder.py+++ b/tests/test_launch_route_builder.py@@ -7,7 +7,6 @@ from switchyard.cli.config.user_config import LaunchRouteConfigfrom switchyard.cli.routing.route_builder import (LaunchTierConnectivity,build_deterministic_routing_config,- build_plan_execute_config,build_random_routing_config,)from switchyard.lib.backends.llm_target import BackendFormat, LlmTarget@@ -189,67 +188,3 @@ def test_deterministic_launch_routes_reject_out_of_range_confidence() -> None:backend_format=BackendFormat.OPENAI,timeout=600.0,)---def test_plan_execute_launch_routes_use_preset_defaults() -> None:- """Zero-override --plan-execute launches use the strong-planner pairing."""- route = LaunchRouteConfig(type="plan_execute")- config = build_plan_execute_config(- route,- primary=_connectivity(),- backend_format=BackendFormat.OPENAI,- timeout=600.0,- )- assert config.planner.model == "anthropic/claude-opus-4.6"- assert config.executor.model == "moonshotai/kimi-k2.6"- assert config.cadence_n == 2- assert config.preset == "coding_agent_default"---def test_plan_execute_launch_routes_apply_executor_override() -> None:- """--model X swaps the executor but leaves the strong planner."""- route = LaunchRouteConfig(- type="plan_execute",- model="my/custom-executor",- )- config = build_plan_execute_config(- route,- primary=_connectivity(),- backend_format=BackendFormat.OPENAI,- timeout=600.0,- )- # Planner stays on the preset; executor adopts the user's override.- assert config.planner.model == "anthropic/claude-opus-4.6"- assert config.executor.model == "my/custom-executor"- # Preset label drops once any tier deviates from the shipping bundle.- assert config.preset is None---def test_plan_execute_launch_routes_pin_backend_format() -> None:- """codex/openclaw pin OPENAI; the executor tier honours the request."""- route = LaunchRouteConfig(type="plan_execute")- config = build_plan_execute_config(- route,- primary=_connectivity(),- backend_format=BackendFormat.OPENAI,- timeout=None,- )- assert config.executor.format is BackendFormat.OPENAI---def test_plan_execute_launch_routes_propagate_connectivity() -> None:- route = LaunchRouteConfig(type="plan_execute")- primary = LaunchTierConnectivity(- api_key="sk-launch",- base_url="https://example.invalid/v1",- )- config = build_plan_execute_config(- route,- primary=primary,- backend_format=BackendFormat.OPENAI,- timeout=600.0,- )- assert config.executor.endpoint.api_key == "sk-launch"- assert config.executor.endpoint.base_url == "https://example.invalid/v1"- assert config.planner.endpoint.api_key == "sk-launch"- assert config.planner.endpoint.base_url == "https://example.invalid/v1"diff --git a/tests/test_llm_classifier_e2e.py b/tests/test_llm_classifier_e2e.pyindex fc081927b..1da464660 100644--- a/tests/test_llm_classifier_e2e.py+++ b/tests/test_llm_classifier_e2e.py@@ -20,8 +20,6 @@ calls go through local loopback HTTP servers because Rust reqwestbypasses ``respx``. The test stays offline while still exercising thereal classifier client, tier mapping, and per-tier backend dispatch.-This file is **classifier-only**. The classifier composed with the-planner lives in :mod:`tests.test_classifier_planner_chain`."""from __future__ import annotationsdiff --git a/tests/test_plan_execute_profile.py b/tests/test_plan_execute_profile.pydeleted file mode 100644index b6e612068..000000000--- a/tests/test_plan_execute_profile.py+++ /dev/null@@ -1,265 +0,0 @@-# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.-# SPDX-License-Identifier: Apache-2.0--"""Unit tests for profile-backed plan-execute construction."""--from __future__ import annotations--from typing import Any--from switchyard.lib.backends.llm_target import BackendFormat, LlmTarget-from switchyard.lib.processors.plan_execute import PlanningRequestProcessor-from switchyard.lib.processors.stats_request_processor import StatsRequestProcessor-from switchyard.lib.processors.stats_response_processor_accumulator import (- StatsResponseProcessor,-)-from switchyard.lib.profiles import (- PlanExecuteConfig,- PlanExecutePresets,- PlanExecuteProfileConfig,- ProfileSwitchyard,-)-from switchyard.lib.profiles.plan_execute import _ExecutorStatsTargetProcessor-from switchyard.lib.proxy_context import ProxyContext-from switchyard.lib.stats_accumulator import StatsAccumulator-from switchyard_rust.core import ChatRequest, ChatResponse-from switchyard_rust.translation import TranslationEngine---def _config(- *,- enable_stats: bool = True,- planner_model: str = "anthropic/claude-opus-4.6",-) -> PlanExecuteConfig:- return PlanExecuteConfig(- planner=LlmTarget(- id="planner",- model=planner_model,- format=BackendFormat.OPENAI,- api_key="sk-test",- base_url="https://example.invalid/v1",- ),- executor=LlmTarget(- id="executor",- model="moonshotai/kimi-k2.6",- format=BackendFormat.OPENAI,- api_key="sk-test",- base_url="https://example.invalid/v1",- ),- cadence_n=2,- enable_stats=enable_stats,- fallback_target_on_evict="planner",- )---def _plan_execute_switchyard(- config: PlanExecuteConfig,- *,- stats_accumulator: StatsAccumulator | None = None,- pre_routing_request_processors: list[Any] | None = None,- extra_request_processors: list[Any] | None = None,- extra_response_processors: list[Any] | None = None,-) -> ProfileSwitchyard:- """Build the profile-backed runtime used by these tests."""- return ProfileSwitchyard(- PlanExecuteProfileConfig.from_config(config)- .build()- .with_runtime_components(- stats_accumulator=stats_accumulator,- enable_stats=config.enable_stats,- pre_request_processors=pre_routing_request_processors or (),- post_request_processors=extra_request_processors or (),- response_processors=extra_response_processors or (),- )- )---def _planner_config(switchyard: ProfileSwitchyard) -> object:- """Pull the built :class:`PlanningConfig` out of the wired planner."""- planner = next(- c for c in switchyard.iter_components()- if isinstance(c, PlanningRequestProcessor)- )- return planner._config---class _NoopRequestProcessor:- async def process(self, _ctx: ProxyContext, request: ChatRequest) -> ChatRequest:- return request---class _NoopResponseProcessor:- async def process(self, _ctx: ProxyContext, response: ChatResponse) -> ChatResponse:- return response---class TestProfileStructure:- def test_returns_profile_backed_switchyard_adapter(self) -> None:- switchyard = _plan_execute_switchyard(_config())- assert isinstance(switchyard, ProfileSwitchyard)-- def test_planner_processor_present(self) -> None:- switchyard = _plan_execute_switchyard(_config())- planners = [- c for c in switchyard.iter_components()- if isinstance(c, PlanningRequestProcessor)- ]- assert len(planners) == 1-- def test_translator_present(self) -> None:- switchyard = _plan_execute_switchyard(_config())- translators = [- c for c in switchyard.iter_components()- if isinstance(c, TranslationEngine)- ]- assert len(translators) == 1-- def test_planner_runs_after_stats(self) -> None:- switchyard = _plan_execute_switchyard(_config())- components = list(switchyard.iter_components())- stats_idx = next(- idx for idx, c in enumerate(components)- if isinstance(c, StatsRequestProcessor)- )- planner_idx = next(- idx for idx, c in enumerate(components)- if isinstance(c, PlanningRequestProcessor)- )- assert stats_idx < planner_idx-- def test_executor_stats_marker_runs_before_planner(self) -> None:- switchyard = _plan_execute_switchyard(_config())- components = list(switchyard.iter_components())- marker_idx = next(- idx for idx, c in enumerate(components)- if isinstance(c, _ExecutorStatsTargetProcessor)- )- planner_idx = next(- idx for idx, c in enumerate(components)- if isinstance(c, PlanningRequestProcessor)- )- assert marker_idx < planner_idx-- def test_stats_processors_wired_when_enabled(self) -> None:- switchyard = _plan_execute_switchyard(_config())- components = list(switchyard.iter_components())- assert any(isinstance(c, StatsRequestProcessor) for c in components)- assert any(isinstance(c, StatsResponseProcessor) for c in components)- assert any(isinstance(c, _ExecutorStatsTargetProcessor) for c in components)-- def test_stats_processors_absent_when_disabled(self) -> None:- switchyard = _plan_execute_switchyard(- _config(enable_stats=False),- )- components = list(switchyard.iter_components())- assert not any(isinstance(c, StatsRequestProcessor) for c in components)- assert not any(isinstance(c, StatsResponseProcessor) for c in components)- assert not any(isinstance(c, _ExecutorStatsTargetProcessor) for c in components)-- def test_extra_processors_are_wired(self) -> None:- request_processor = _NoopRequestProcessor()- response_processor = _NoopResponseProcessor()- switchyard = _plan_execute_switchyard(- _config(),- extra_request_processors=[request_processor],- extra_response_processors=[response_processor],- )- components = list(switchyard.iter_components())- assert request_processor in components- assert response_processor in components-- def test_pre_routing_runs_before_planner(self) -> None:- pre = _NoopRequestProcessor()- switchyard = _plan_execute_switchyard(- _config(),- pre_routing_request_processors=[pre],- )- components = list(switchyard.iter_components())- pre_idx = components.index(pre)- planner_idx = next(- idx for idx, c in enumerate(components)- if isinstance(c, PlanningRequestProcessor)- )- assert pre_idx < planner_idx-- async def test_executor_stats_marker_stamps_executor_tier(self) -> None:- marker = _ExecutorStatsTargetProcessor("executor-target")- stats = StatsAccumulator()- response_processor = StatsResponseProcessor(stats)- ctx = ProxyContext()- request = ChatRequest.openai_chat({- "model": "client-route",- "messages": [{"role": "user", "content": "hi"}],- })-- await marker.process(ctx, request)- ctx.selected_model = "moonshotai/kimi-k2.6"- await response_processor.process(- ctx,- ChatResponse.openai_completion({- "model": "moonshotai/kimi-k2.6",- "usage": {"prompt_tokens": 3, "completion_tokens": 5},- }),- )-- snapshot = await stats.snapshot()- assert ctx.selected_target == "executor-target"- assert snapshot["tiers"]["executor"]["model"] == "moonshotai/kimi-k2.6"- assert snapshot["tiers"]["executor"]["prompt_tokens"] == 3- assert snapshot["tiers"]["executor"]["completion_tokens"] == 5---class TestPlannerParamCompatibility:- """Anthropic-family planners must drop ``temperature`` (Bedrock Claude- 4.7 400s on it) but *keep* ``response_format={"type": "json_object"}``:- LiteLLM turns it into a forced tool call, and the planner reads the JSON- back from ``tool_calls`` (see ``_completion_content``)."""-- def test_anthropic_planner_drops_temperature_keeps_response_format(self) -> None:- switchyard = _plan_execute_switchyard(- _config(planner_model="aws/anthropic/bedrock-claude-opus-4-7"),- )- config = _planner_config(switchyard)- assert config.temperature is None- assert config.response_format == {"type": "json_object"}-- def test_non_anthropic_planner_keeps_defaults(self) -> None:- switchyard = _plan_execute_switchyard(- _config(planner_model="nvidia/deepseek/v4-pro"),- )- config = _planner_config(switchyard)- assert config.temperature == 0.0- assert config.response_format == {"type": "json_object"}---class TestCodingAgentDefaultPreset:- """Pins the validated planner+executor pairing on the shipping default."""-- def test_planner_is_strong_model(self) -> None:- preset = PlanExecutePresets.coding_agent_default(api_key="sk-test")- assert preset.planner.model == "anthropic/claude-opus-4.6"-- def test_executor_is_weak_model(self) -> None:- preset = PlanExecutePresets.coding_agent_default(api_key="sk-test")- # Weak executor — OpenRouter-available Kimi.- assert preset.executor.model == "moonshotai/kimi-k2.6"-- def test_cadence_n_validated_default(self) -> None:- preset = PlanExecutePresets.coding_agent_default(api_key="sk-test")- # Validated cadence per commit c9339748: 2 beat both 1 (too noisy)- # and 4 (too sparse) on the TB-Lite Nemotron-Nano sweep.- assert preset.cadence_n == 2-- def test_preset_label_stamped(self) -> None:- preset = PlanExecutePresets.coding_agent_default(api_key="sk-test")- assert preset.preset == "coding_agent_default"-- def test_credentials_propagate_to_both_tiers(self) -> None:- preset = PlanExecutePresets.coding_agent_default(- api_key="sk-secret",- base_url="https://custom.invalid/v1",- )- assert preset.planner.endpoint.api_key == "sk-secret"- assert preset.executor.endpoint.api_key == "sk-secret"- assert preset.planner.endpoint.base_url == "https://custom.invalid/v1"- assert preset.executor.endpoint.base_url == "https://custom.invalid/v1"diff --git a/tests/test_planning_request_processor.py b/tests/test_planning_request_processor.pydeleted file mode 100644index 856796960..000000000--- a/tests/test_planning_request_processor.py+++ /dev/null@@ -1,428 +0,0 @@-# SPDX-FileCopyrightText: Copyright (c) 2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved.-# SPDX-License-Identifier: Apache-2.0--"""Tests for the planning request processor (slim two-field schema)."""--import json-from types import SimpleNamespace-from typing import Any, cast--import pytest--from switchyard.lib.processors.plan_execute import (- CTX_PLANNER_DECISION,- PlannerCompletion,- PlannerDecision,- PlanningConfig,- PlanningError,- PlanningRequestProcessor,- PlanningTriggerMode,- parse_planner_decision,-)-from switchyard.lib.processors.plan_execute.request_processor import (- _completion_content,-)-from switchyard.lib.proxy_context import ProxyContext-from switchyard_rust.core import ChatRequest--_PLAN_TEXT = (- "I'll approach this in steps:\n"- "1. Read /app/api_bug.py and the existing tests to map the bugs.\n"- "2. Implement /app/api.py satisfying every test behavior.\n"- "3. Run the test suite and iterate until it passes.\n\n"- "Starting now."-)-_REVISION_TEXT = (- "Pausing to reassess — the test harness uses pytest-asyncio rather than "- "the asyncio fixture I assumed. Updated approach: switch to async fixtures "- "and re-run. Resuming work."-)-_WRAPPED_PLAN = f"<plan>\n{_PLAN_TEXT}\n</plan>"-_WRAPPED_REVISION = f"<plan>\n{_REVISION_TEXT}\n</plan>"---class _FakePlannerClient:- """Test double — captures the system_prompt + request_summary the- processor selected, so tests can assert on planner-prompt routing."""-- def __init__(self, response: str | Exception) -> None:- self.response = response- self.calls: list[dict[str, str]] = []-- async def plan(- self,- *,- model: str,- system_prompt: str,- request_summary: str,- ) -> PlannerCompletion:- self.calls.append({- "model": model,- "system_prompt": system_prompt,- "request_summary": request_summary,- })- if isinstance(self.response, Exception):- raise self.response- # ``usage=None`` mirrors the production code's tolerance — the- # audit-line builder treats missing usage as zero counts.- return PlannerCompletion(content=self.response, usage=None)---def _decision_with_plan_json(plan_text: str = _PLAN_TEXT) -> str:- """Planner output that emits a plan (the slim shape)."""- return json.dumps({"plan_needed": True, "plan_text": plan_text})---def _decision_no_plan_json() -> str:- """Planner output declining to plan (fast path)."""- return json.dumps({"plan_needed": False, "plan_text": ""})---def _openai_request_first_turn() -> ChatRequest:- """Outbound conversation with no prior plan in history (initial-plan trigger)."""- return ChatRequest.openai_chat(cast(Any, {- "model": "client-model",- "messages": [{"role": "user", "content": "refactor auth middleware"}],- }))---def _openai_request_with_prior_plan() -> ChatRequest:- """Outbound conversation where a prior assistant turn contains a- ``<plan>...</plan>`` block — this is the revision-mode trigger."""- prior_assistant = (- "<plan>\nPrior approach: 1. inspect /app, 2. patch, 3. test.\n</plan>\n\n"- "I checked /app/middleware.py — found the auth bug."- )- return ChatRequest.openai_chat(cast(Any, {- "model": "client-model",- "messages": [- {"role": "user", "content": "refactor auth middleware"},- {"role": "assistant", "content": prior_assistant},- {"role": "user", "content": "the test is failing now"},- ],- }))---def _openai_request_with_assistant_no_plan() -> ChatRequest:- """Outbound conversation with prior assistant turns but no- ``<plan>...</plan>`` block — should still take the initial-plan- path (the assistant turns alone don't trigger revision mode)."""- return ChatRequest.openai_chat(cast(Any, {- "model": "client-model",- "messages": [- {"role": "user", "content": "refactor auth middleware"},- {"role": "assistant", "content": "Inspecting /app/middleware..."},- {"role": "user", "content": "looking for the bug"},- ],- }))---async def test_planning_processor_prefills_wrapped_plan_on_initial_turn() -> None:- """When the conversation has no prior plan, planner uses the initial- system prompt and the resulting plan is appended as a trailing- assistant turn wrapped in ``<plan>...</plan>``."""- fake = _FakePlannerClient(_decision_with_plan_json())- processor = PlanningRequestProcessor(- PlanningConfig(model="planner-model", cadence_n=1),- client=fake,- )- req = _openai_request_first_turn()- ctx = ProxyContext()-- returned = await processor.process(ctx, req)-- assert returned is req-- decision = ctx.metadata[CTX_PLANNER_DECISION]- assert isinstance(decision, PlannerDecision)- assert decision.plan_needed is True- assert decision.plan_text == _PLAN_TEXT # the raw, unwrapped form-- # Prefill: last message is now an assistant turn carrying the- # wrapped plan.- messages = req.body["messages"]- assert messages[-1] == {"role": "assistant", "content": _WRAPPED_PLAN}-- # Initial-prompt path: the planner saw the initial system prompt.- assert "drafting the agent's opening thought" in fake.calls[0]["system_prompt"]- assert fake.calls[0]["model"] == "planner-model"---async def test_planning_processor_uses_revision_prompt_when_prior_plan_in_history() -> None:- """When an assistant turn already contains a ``<plan>...</plan>``- block, the planner uses the revision system prompt and the prior- plan is shown inline at the top of the request_summary."""- fake = _FakePlannerClient(_decision_with_plan_json(_REVISION_TEXT))- processor = PlanningRequestProcessor(- # cadence_n=1: this test exercises a turn with a prior- # assistant message, which would otherwise be cadence-skipped- # at the default ``cadence_n=2``.- PlanningConfig(model="planner-model", cadence_n=1),- client=fake,- )- req = _openai_request_with_prior_plan()- ctx = ProxyContext()-- await processor.process(ctx, req)-- # Revision-prompt path.- assert "software architect reassessing" in fake.calls[0]["system_prompt"]- # Prior plan was shown inline at the top of the summary so the- # planner can decide whether to revise.- request_summary = fake.calls[0]["request_summary"]- assert request_summary.startswith("Prior plan:\n")- assert "Prior approach: 1. inspect /app" in request_summary-- # The revision plan was prefilled in wrapped form at the tail.- messages = req.body["messages"]- assert messages[-1] == {"role": "assistant", "content": _WRAPPED_REVISION}---async def test_planning_processor_uses_initial_prompt_when_no_plan_in_history() -> None:- """Prior assistant turns *without* a ``<plan>`` block do NOT trigger- revision mode — the planner still uses the initial prompt because- no plan has been emitted yet for this task."""- fake = _FakePlannerClient(_decision_with_plan_json())- processor = PlanningRequestProcessor(- # cadence_n=1: this test has a prior assistant message which- # would be cadence-skipped at the default ``cadence_n=2``.- PlanningConfig(model="planner-model", cadence_n=1),- client=fake,- )- req = _openai_request_with_assistant_no_plan()- ctx = ProxyContext()-- await processor.process(ctx, req)-- # Initial-prompt path even though the conversation already has- # assistant turns — the discriminator is "is there a <plan> block- # in any prior assistant turn," not "any prior assistant turn."- assert "drafting the agent's opening thought" in fake.calls[0]["system_prompt"]- # No "Prior plan:" preamble in the request_summary.- assert "Prior plan:" not in fake.calls[0]["request_summary"]---async def test_planning_processor_skips_injection_when_planner_declines() -> None:- """``plan_needed=False`` leaves the request body untouched."""- fake = _FakePlannerClient(_decision_no_plan_json())- processor = PlanningRequestProcessor(- PlanningConfig(model="planner-model", cadence_n=1),- client=fake,- )- req = _openai_request_first_turn()- ctx = ProxyContext()-- await processor.process(ctx, req)-- decision = ctx.metadata[CTX_PLANNER_DECISION]- assert isinstance(decision, PlannerDecision)- assert decision.plan_needed is False- assert decision.plan_text == ""-- # Request body was not mutated.- messages = req.body["messages"]- assert len(messages) == 1- assert messages[0]["role"] == "user"---async def test_planning_processor_can_be_disabled() -> None:- fake = _FakePlannerClient(_decision_with_plan_json())- processor = PlanningRequestProcessor(- PlanningConfig(model="planner-model", trigger_mode=PlanningTriggerMode.DISABLED),- client=fake,- )- req = _openai_request_first_turn()- ctx = ProxyContext()-- await processor.process(ctx, req)-- assert fake.calls == []- assert CTX_PLANNER_DECISION not in ctx.metadata- assert req.body["messages"][0]["role"] == "user"---def test_parse_planner_decision_accepts_json_fence() -> None:- """``parse_planner_decision`` strips a leading markdown fence."""- decision = parse_planner_decision(f"```json\n{_decision_with_plan_json()}\n```")- assert decision.plan_needed is True- assert decision.plan_text == _PLAN_TEXT---def test_parse_planner_decision_accepts_no_plan_shape() -> None:- decision = parse_planner_decision(_decision_no_plan_json())- assert decision.plan_needed is False- assert decision.plan_text == ""---def test_parse_planner_decision_rejects_inconsistent_shapes() -> None:- """``plan_needed=True`` requires non-empty ``plan_text``."""- with pytest.raises(PlanningError):- parse_planner_decision(json.dumps({"plan_needed": True, "plan_text": ""}))---def test_planner_decision_normalizes_false_with_spurious_text() -> None:- """``plan_needed=False`` with non-empty ``plan_text`` is normalized- to empty — we trust the gate."""- decision = PlannerDecision(plan_needed=False, plan_text="leaked")- assert decision.plan_text == ""---def _completion(content: Any, tool_arguments: str | None = None) -> Any:- """Build a minimal OpenAI-SDK-shaped completion for ``_completion_content``."""- message = SimpleNamespace(content=content, tool_calls=None)- if tool_arguments is not None:- message.tool_calls = [- SimpleNamespace(function=SimpleNamespace(arguments=tool_arguments)),- ]- return SimpleNamespace(choices=[SimpleNamespace(message=message)])---def test_completion_content_prefers_content() -> None:- """When ``content`` is present it wins over any tool call."""- result = _completion(content="real content", tool_arguments='{"ignored": true}')- assert _completion_content(result) == "real content"---def test_completion_content_falls_back_to_tool_call_arguments() -> None:- """Anthropic-via-LiteLLM: empty ``content``, JSON in ``tool_calls`` — the- forced-tool path the planner must read."""- plan_json = _decision_with_plan_json()- result = _completion(content="", tool_arguments=plan_json)- raw = _completion_content(result)- # Round-trips through the same parser the production path uses.- decision = parse_planner_decision(raw)- assert decision.plan_needed is True- assert decision.plan_text == _PLAN_TEXT---def test_completion_content_handles_none_content_with_tool_call() -> None:- """``content=None`` (not just empty string) still falls back to the tool call."""- result = _completion(content=None, tool_arguments=_decision_no_plan_json())- assert parse_planner_decision(_completion_content(result)).plan_needed is False---def test_completion_content_raises_when_no_content_and_no_tool_call() -> None:- """Empty content with no tool call is a genuine empty completion."""- with pytest.raises(PlanningError):- _completion_content(_completion(content="", tool_arguments=None))---async def test_planning_processor_fail_open_continues_without_plan() -> None:- fake = _FakePlannerClient("not json")- processor = PlanningRequestProcessor(- PlanningConfig(model="planner-model", cadence_n=1),- client=fake,- )- ctx = ProxyContext()-- await processor.process(ctx, _openai_request_first_turn())-- assert CTX_PLANNER_DECISION not in ctx.metadata---async def test_planning_processor_fail_closed_raises() -> None:- fake = _FakePlannerClient(RuntimeError("boom"))- processor = PlanningRequestProcessor(- PlanningConfig(- model="planner-model",- fail_open=False,- ),- client=fake,- )-- with pytest.raises(PlanningError):- await processor.process(ProxyContext(), _openai_request_first_turn())---async def test_planning_processor_prefills_anthropic_messages() -> None:- """Anthropic wire format uses the same prefill mechanic — append the- plan as an assistant turn at the tail of ``messages``. The- top-level ``system`` field stays untouched (it's terminus-2's- behavior contract, not a plan slot)."""- fake = _FakePlannerClient(_decision_with_plan_json())- processor = PlanningRequestProcessor(- PlanningConfig(model="planner-model"),- client=fake,- )- req = ChatRequest.anthropic(cast(Any, {- "model": "claude-test",- "max_tokens": 128,- "system": "Existing system contract — preserved untouched.",- "messages": [{"role": "user", "content": "refactor auth middleware"}],- }))-- await processor.process(ProxyContext(), req)-- # System field stays the original behavior contract.- assert req.body["system"] == "Existing system contract — preserved untouched."- # Plan appears as a prefilled (wrapped) assistant turn at the tail.- messages = req.body["messages"]- assert messages[-1] == {"role": "assistant", "content": _WRAPPED_PLAN}---async def test_planning_processor_prefills_responses_input_string() -> None:- """Responses API with a string ``input``: wrap into list form and- append the plan as an assistant prefill turn."""- fake = _FakePlannerClient(_decision_with_plan_json())- processor = PlanningRequestProcessor(- PlanningConfig(model="planner-model"),- client=fake,- )- req = ChatRequest.openai_responses(cast(Any, {- "model": "gpt-test",- "input": "refactor auth middleware",- }))-- await processor.process(ProxyContext(), req)-- input_value = req.body["input"]- assert isinstance(input_value, list)- assert input_value[0] == {"role": "user", "content": "refactor auth middleware"}- assert input_value[-1] == {"role": "assistant", "content": _WRAPPED_PLAN}---class _UsagePlannerClient:- """Planner double that returns a token-usage block, so the producer has- counts to record for the intake sink."""-- def __init__(self, content: str, usage: object) -> None:- self.content = content- self.usage = usage-- async def plan(- self,- model: str,- system_prompt: str,- request_summary: str,- ) -> PlannerCompletion:- return PlannerCompletion(content=self.content, usage=self.usage)---async def test_process_stashes_planner_submodel_call_for_intake() -> None:- """A successful planner call is recorded for the intake sink to emit."""- fake = _UsagePlannerClient(- _decision_with_plan_json(),- SimpleNamespace(- prompt_tokens=512,- completion_tokens=64,- prompt_tokens_details=SimpleNamespace(cached_tokens=8),- ),- )- processor = PlanningRequestProcessor(- PlanningConfig(model="planner-model", cadence_n=1),- client=fake,- )- ctx = ProxyContext()-- await processor.process(ctx, _openai_request_first_turn())-- assert ctx.submodel_calls == [- {- "model": "planner-model",- "prompt_tokens": 512,- "completion_tokens": 64,- "cached_tokens": 8,- "router_type": "plan_execute",- "routed_to": "planner",- }- ]diff --git a/tests/test_route_bundle.py b/tests/test_route_bundle.pyindex 684b25ac2..b1a7e68a1 100644--- a/tests/test_route_bundle.py+++ b/tests/test_route_bundle.py@@ -1327,90 +1327,6 @@ class TestStageRouterRouteType:assert snapshot["routing_decisions"]["stage_router"]["llm-classifier"] == 1-class TestPlanExecuteRouteType:- """`type: plan_execute` wires the strong-planner / weak-executor chain via YAML."""-- def _bundle(self) -> dict:- return {- "routes": {- "myrouter/plan-execute": {- "type": "plan_execute",- "cadence_n": 3,- "planner": {- "model": "azure/anthropic/claude-opus-4-6",- "api_key": "sk-planner",- "base_url": "https://planner.invalid/v1",- },- "executor": {- "model": "nvidia/nvidia/nemotron-3-super-v3",- "api_key": "sk-executor",- "base_url": "https://executor.invalid/v1",- },- },- },- }-- def test_registers_under_route_key(self):- table = build_route_bundle_table(self._bundle())- assert table.registered_models() == ["myrouter/plan-execute"]-- def test_metadata_records_plan_execute_profile(self):- table = build_route_bundle_table(self._bundle())- _, _, metadata = next(iter(table.items()))- assert metadata["switchyard"]["profile"] == "plan_execute"-- def test_plan_alias_registers_plan_execute_route(self):- bundle = self._bundle()- bundle["routes"]["myrouter/plan-execute"]["type"] = "plan"- table = build_route_bundle_table(bundle)- _, _, metadata = next(iter(table.items()))- assert metadata["switchyard"]["profile"] == "plan_execute"-- def test_tiers_default_to_shipping_preset(self):- # A minimal route (no planner/executor) reproduces the retired- # --plan-execute flag: tiers fall back to the coding-agent preset.- bundle = {- "defaults": {"api_key": "sk-x", "base_url": "https://x.invalid/v1"},- "routes": {"router/pe": {"type": "plan_execute"}},- }- table = build_route_bundle_table(bundle)- assert table.registered_models() == ["router/pe"]-- def test_rejects_unknown_route_key(self):- bundle = self._bundle()- bundle["routes"]["myrouter/plan-execute"]["bogus_field"] = 1- with pytest.raises(RouteBundleConfigError) as exc:- build_route_bundle_table(bundle)- assert "bogus_field" in str(exc.value)-- def test_rejects_invalid_cadence(self):- bundle = self._bundle()- bundle["routes"]["myrouter/plan-execute"]["cadence_n"] = 0- with pytest.raises((RouteBundleConfigError, ValueError)):- build_route_bundle_table(bundle)-- def test_string_tier_shorthand_accepted(self):- bundle = self._bundle()- bundle["routes"]["myrouter/plan-execute"]["executor"] = "nvidia/nvidia/nemotron-3-super-v3"- table = build_route_bundle_table(bundle)- assert "myrouter/plan-execute" in table.registered_models()-- def test_enable_stats_false_disables_stats_processors(self):- from switchyard.lib.processors.stats_request_processor import (- StatsRequestProcessor,- )- from switchyard.lib.processors.stats_response_processor_accumulator import (- StatsResponseProcessor,- )-- bundle = self._bundle()- bundle["routes"]["myrouter/plan-execute"]["enable_stats"] = False- table = build_route_bundle_table(bundle)- components = list(table.iter_components())- assert not any(isinstance(c, StatsRequestProcessor) for c in components)- assert not any(isinstance(c, StatsResponseProcessor) for c in components)--def test_stage_router_route_hydrates_tier_catalogs(monkeypatch: pytest.MonkeyPatch,) -> None:diff --git a/tests/test_stats_accumulator.py b/tests/test_stats_accumulator.pyindex ffa96941f..c8b881a31 100644--- a/tests/test_stats_accumulator.py+++ b/tests/test_stats_accumulator.py@@ -81,12 +81,12 @@ async def test_same_model_can_contribute_to_distinct_tier_rollups():completion_tokens=3,tier="weak",)- await stats.record_success(model="shared/model", tier="executor")+ await stats.record_success(model="shared/model", tier="primary")await stats.record_usage(model="shared/model",prompt_tokens=5,completion_tokens=7,- tier="executor",+ tier="primary",)snapshot = await stats.snapshot()@@ -97,9 +97,9 @@ async def test_same_model_can_contribute_to_distinct_tier_rollups():assert snapshot["tiers"]["weak"]["calls"] == 1assert snapshot["tiers"]["weak"]["prompt_tokens"] == 2assert snapshot["tiers"]["weak"]["completion_tokens"] == 3- assert snapshot["tiers"]["executor"]["calls"] == 1- assert snapshot["tiers"]["executor"]["prompt_tokens"] == 5- assert snapshot["tiers"]["executor"]["completion_tokens"] == 7+ assert snapshot["tiers"]["primary"]["calls"] == 1+ assert snapshot["tiers"]["primary"]["prompt_tokens"] == 5+ assert snapshot["tiers"]["primary"]["completion_tokens"] == 7async def test_usage_can_attach_explicit_untiered_success_to_tier():