Skip to main content
Version: Latest (main)

Tune and Verify a Recipe

A useful recipe sends requests to the right handling path and delivers better results within your latency, cost, and safety requirements. This guide shows how to improve one using real Preview requests, routed responses, and session traces.

Start with a running deployment and reachable model endpoints. Follow the agent installation guide to set up a new deployment. Use the management origin for configuration and Preview, and the inference origin for real model requests.

Choose an objective and a baseline​

Pick an outcome you can measure: fewer unnecessary reasoning calls, better answers to consequential questions, faster tool turns, or fewer model switches during an agent run. Set a quality floor and acceptable latency or cost before adjusting thresholds.

Export the built-in bundle or save your current configuration. Record the active recipe, runtime image, model revisions, and assignments. Keep the original test cases so you can run the same requests before and after a change.

Build a small representative dataset for every decision and fallback. Include normal requests, near-boundary cases, multilingual paraphrases, long inputs, quoted instructions, and multi-turn conversations. Add negative examples: a medical definition need not receive the same route as personalized treatment advice, and a quoted attack should not automatically be treated as an instruction.

  • Pair requests with identical background information but different tasks, and vary concise and detailed answer styles separately. That tests whether effort signals recognize the required work, not the topic or the response length.
  • Count families. Treat related paraphrases and tool variants as one family when reporting coverage.

Give each part a clear job​

PartUse it to
SignalsObserve meaning, risk, effort, and explicit request constraints.
ProjectionsCombine evidence into scores or categories that decisions can use.
DecisionsChoose a small set of distinct handling paths.
AlgorithmsSelect or coordinate models within each path.
PluginsApply retrieval, tools, caching, and data-handling behavior.
ModelsExecute the request within declared capabilities and context limits.

Keep decision names short, such as simple, medium, and reasoning. Add a new decision when the action changes, rather than for every topic or language.

Use heuristics for explicit facts, such as required tools and structured output. Use learned signals where meaning matters:

To observeUse
IntentEmbedding
EffortComplexity
Consequential questionsDomain with FactCheck
RecoveryFeedback with Reask

Combine clues through projections when one signal is too broad. Topic alone doesn't establish difficulty, and FactCheck predicts a need for checking; it doesn't verify a claim.

  • Unknown signals. Review how they affect every decision, especially conditions using NOT: a failed signal shouldn't turn into evidence for a cheaper route.
  • Thresholds. Compare easy and hard signal scores before changing thresholds. Strong overlap calls for better task examples or a better model; sending every uncertain request to reasoning increases usage without establishing better discrimination.
  • Keywords don't save inference. Adding a keyword condition doesn't guarantee less inference, because used signal families can run concurrently before decisions are evaluated. Measure the actual request cost.
  • Recovery. Include the earlier assistant reply, because Feedback routing skips requests without one. Test direct repair instructions and self-contained error reports separately from Feedback matches, with harmless tone or formatting edits as controls.
  • Collaboration. Distinguish multiple-worker authorization from a discussion of agents, or a request for one independent worker. The workflow handles its internal stages; users shouldn't have to name them to request collaboration.

Validate and preview the candidate​

Discover the running contract before editing configuration:

vllm-sr config schema --endpoint "$ROUTER_ORIGIN" \
--surface algorithm:multi_factor
vllm-sr config validate --config candidate.yaml \
--endpoint "$ROUTER_ORIGIN"
vllm-sr config plan --config candidate.yaml \
--endpoint "$ROUTER_ORIGIN"

Then apply it:

  • A hot-reloadable change: vllm-sr config apply.
  • RESTART_REQUIRED: use the deployment workflow. On a local stack, vllm-sr config apply saves the change and the next vllm-sr serve applies it; for an authorized local-stack replacement, run vllm-sr serve --config candidate.yaml --replace-active-config.

Confirm readiness and the active revision before testing.

Set ENTRYPOINT to the published entrypoint you are evaluating, then preview a case from your dataset:

vllm-sr route preview \
--endpoint "$ROUTER_ORIGIN" --model "$ENTRYPOINT" \
--prompt 'Give a brief definition of a readiness probe.' \
--trace --json --timeout 300

Recombining saved signal values can help isolate a rule change, but it is not a new Preview result. First reproduce the baseline decisions and heuristic matches exactly, then test the candidate with real requests.

Preview evaluates the configured signals, decision-model questions included, without backend generation. Check the matched signals, projection results, decision, algorithm, selection status, and errors. Preserve the full messages and tool fields for multi-turn cases; use the discovered Preview HTTP schema when the CLI cannot express a request shape.

Report policy coverage and deployment coverage separately. None of these outcomes is a successful backend call:

  • a correct decision with no eligible backend, which shows a capacity or assignment problem;
  • an immediate response, which needs no selected model;
  • a multi-model plan, which still needs execution.

Verify delivery and the application result​

Send the same request through the inference listener:

vllm-sr route probe \
--config candidate.yaml \
--base-url "$INFERENCE_BASE_URL" --model "$ENTRYPOINT" \
--prompt 'Give a brief definition of a readiness probe.' \
--expect-recipe "$RECIPE" --expect-decision "$DECISION" \
--expect-selected-model "$SELECTED_MODEL" \
--expect-response-model "$RESPONSE_MODEL" \
--timeout 300

Set the expected values from your test case and the backend's verified response identity. The selected-model header and upstream response model are separate assertions. Omit the response-model assertion only when the backend does not expose a stable identity.

Check completed output as well as routing: an HTTP 200 containing only reasoning, an empty answer or a truncated response is not successful delivery. Use a completion budget that fits the actual input and leaves room for the final answer:

  • When the request omits a limit, a configured request_params.default_max_tokens supplies the decision default; otherwise the backend default applies.
  • On supported vLLM deployments, default_max_tokens: auto uses each model's remaining native capacity.
  • Keep the forecast separate. Keep the selector's output cost forecast separate from this capacity, and report the effective deployment limits.

Assign at least two eligible, reachable models when comparing selection policies. With one candidate, the test verifies delivery but cannot measure a choice between models.

Measure cold startup separately from warm median and p95 latency. Compare route quality, answer quality, decision-model work, backend calls, token use, and cost. For executors, verify that the intended distinct workers and final stage actually ran.

Test retrieval, risk handling, and agent continuity​

Retrieval​

Attach a context plugin with a RAG source to a path with a real knowledge base, recall a wider candidate set, and let the source's relevance judge keep the most relevant documents:

  • Check document identities, retrieval coverage, ranking, grounded answers and added latency.
  • Preview selects the plugin; a routed request executes it.
  • Start small. Start with a single-model path before adding retrieval to every stage of a multi-model workflow.

Risk handling​

Jailbreak detects prompt attacks; Safety identifies content risks and harm categories. Test harmful facilitation against help-seeking and benign analysis before choosing refusal rules. PII can select a restricted model pool; it does not redact content or establish a provider's retention policy.

Agent continuity​

Use Router Learning protection with stable session and conversation identities:

  • Test a full tool cycle, continuation, explicit correction, backend failure, decision change and a new conversation.
  • Compare apply, observe and bypass: an observed recommendation to keep a model is different from an actual hold.
  • Check together the selected backend, route headers, Replay API and Dashboard.
  • Isolation. Repeat a session ID across recipes to verify their isolation. A hold must not keep an ineligible model.

Built-in recipe initialization enables conversation protection and leaves online adaptation off, preserving any settings already present in the base configuration. Clients need stable identities for protection to retain a model. Adopt adaptation after evaluating your application's outcomes.

Preview can report execution_required when protection participates in selection. It evaluates request signals without advancing conversation state; verify an actual hold or switch through a routed request and its Replay record.

Inspect Replay and the Dashboard before activating the next candidate. Records that keep prompt text stay in memory unless a store is configured (where Replay keeps records), and memory is cleared by configuration reloads and restarts; save the traces needed for comparison first.

Keep changes that improve the objective​

Run baseline and candidate against the same dataset. Review regressions by language, input length, use case, and session stage. Keep the candidate when it improves the chosen outcome without violating the quality floor or hard constraints; otherwise restore the baseline and preserve the evidence.

Use sr-bench 1.0 for frozen development and holdout datasets, and reusable single-model and MoM comparisons:

CommandDoes
benchmark previewRecords live routing choices
benchmark replayEstimates eligible direct routing changes from saved answers; it's diagnostic only
benchmark runMeasures actual model execution
benchmark compareReports paired quality uncertainty and cost saving against the best observed single

A measured MoM score needs its real routed endpoint. Keep partial runs and unknown costs visible, instead of presenting them as a complete score or a zero-cost success.

The agent tuning reference provides a reusable checklist. Keep raw evaluation outputs outside Git and credentials in environment variables named by --token-env or --api-key-env.