# Workload Optimization (/docs/routing/workload-optimization)

> For AI agents, the [documentation index](https://bitrouter-docs-staging.up.railway.app/llms.txt) lists all pages. Append .md to a documentation URL to read its Markdown.

> **info**
>
> Coming soon: continuous optimization for recurring workloads. The feature overview below describes the plan; the later policy-tools section documents the existing manual evaluation and publication workflow.

Define a recurring agentic workload. Auto Router learns from its runs and refines the routing policy toward your quality, cost, and latency goals.

## What is a recurring workload? \[#what-is-a-recurring-workload]

A workload is a class of work your agent performs repeatedly, such as reviewing pull requests, handling support tickets, or producing research reports. Each run can have different inputs while sharing a purpose and a way to assess the outcome.

Workload Optimization focuses on the routing policy used for that work: which model and inference source to select. Your agent continues to own the task and its tools.

## How it works \[#how-it-works]

1. **Define the workload and goals.** Identify the recurring work, acceptable quality, and the cost or latency you want to improve. Provide an evaluator or feedback signal aligned with task success.
2. **Run the workload.** Collect outcomes from comparable runs, including task results, serving routes, cost, and latency.
3. **Learn from the results.** Use that evidence to explore and evaluate candidate routing policies for the workload.
4. **Adopt supported improvements.** Compare candidates against the existing policy and the workload's goals before changing the policy that serves requests.

The aim is to find better routing over repeated runs. Each individual run need not improve on the last, and a cheaper request alone does not establish acceptable task quality.

## Existing policy tools \[#existing-policy-tools]

The continuous workload-learning feature above is planned. The tools below document the existing evidence and policy lifecycle. Collecting observations or deriving a candidate does not automatically publish it. Review the evidence and apply changes explicitly.

Use [Routing Traces](https://bitrouter-docs-staging.up.railway.app/docs/routing/routing-traces) to inspect router behavior across the available workflow trajectory, [Auto Router](https://bitrouter-docs-staging.up.railway.app/docs/routing/auto-router) for setup, and [Strategies](https://bitrouter-docs-staging.up.railway.app/docs/routing/strategies) for candidate constraints.

### Policy artifacts and audit boundaries \[#policy-artifacts-and-audit-boundaries]

| Artifact or record                             | What it identifies                                                                 |
| ---------------------------------------------- | ---------------------------------------------------------------------------------- |
| `bitrouter.yaml`                               | Connected sources, named routers, legacy presets, variants, and the policy binding |
| `policy-lock.yaml`                             | Model-selection tiers and adequacy inputs for compilation                          |
| Request receipts                               | The route that served a call and its recorded execution outcome                    |
| Sealed subjects and admitted evaluator results | The evidence eligible for an objective-scored evaluation                           |
| Frozen evidence snapshots                      | The exact admitted evidence set consumed by a later policy decision                |

These records have distinct roles. A request receipt does not establish task success, a matching digest does not establish evaluator quality, and a compiled candidate is not an active policy. This guide describes the existing evidence and publication workflow; it does not promise that every upstream execution can be reproduced.

### Let evidence improve the policy \[#let-evidence-improve-the-policy]

The active lock determines request-time routes; unmatched fingerprints use its configured default tier. In alpha.33, both frozen and adaptive modes route from the lock and disable legacy request-time adequacy learning. Adequacy thresholds in a lock remain compiler inputs, not switches for live escalation or exploration.

### Review and publish a change \[#review-and-publish-a-change]

After admitting evaluation results, freeze a snapshot and use its evidence root to compile a candidate. Publication requires `policy.mode: adaptive` in `bitrouter.yaml`; frozen mode permits inspection but refuses publication. Replace `<EVIDENCE_ROOT>` with the root returned by the freeze command, then review the mode and candidate before publishing:

```bash
bro policy status
bro eval snapshot freeze
bro policy compile --eval-snapshot <EVIDENCE_ROOT> --output candidate-policy.yaml
bro policy diff policy-lock.yaml candidate-policy.yaml
bro policy publish candidate-policy.yaml
```

Compilation can add or update compiler-owned routes while preserving operator-authored routes. Publication validates the candidate and rejects stale or conflicting changes. Review and commit the resulting lock-file diff. To freeze later publication, set `policy.mode: frozen` in `bitrouter.yaml` and reload the configuration.

### Evaluations \[#evaluations]

An evaluation answers whether a result met an objective. It is deliberately separate from telemetry, which records what ran, and from optimization, which decides how admitted evidence may change a routing policy.

| Responsibility | Question it answers                                                  | Primary surface                                     |
| -------------- | -------------------------------------------------------------------- | --------------------------------------------------- |
| Telemetry      | What route ran, what did it cost, and what happened on each attempt? | Request receipts, traces, and metrics               |
| Evaluation     | Did the result satisfy the declared objective?                       | Subjects, evaluator results, and evidence snapshots |
| Optimization   | What policy transition is justified by admitted evidence?            | Controller state and policy candidates              |

An HTTP `200`, a completed stream, or a cheaper route is not proof of task success. Those are observations that an evaluator may use, not the objective result itself.

<a id="two-evidence-paths" />

#### Evaluation evidence \[#evaluation-evidence]

The evaluator-neutral exchange accepts immutable evaluation subjects and results from an evaluator you choose. Admitted results can be frozen into a reproducible snapshot for optimization or policy compilation. A trace does not evaluate its outcome by itself.

In alpha.33, legacy request-time adequacy learning is disabled in both policy modes. Adequacy fields remain compiler inputs; they do not enable live escalation or exploration.

#### Evidence lifecycle \[#evidence-lifecycle]

##### 1. Define and seal a subject \[#1-define-and-seal-a-subject]

An evaluation subject identifies what is being evaluated and carries redacted evidence items. Seal a draft to calculate its canonical digest and write validated JSON:

```bash
bro eval subject seal --output subject.json subject.yaml
bro eval subject put subject.json
```

The digest makes the subject content-addressed. Changing the evidence creates a different subject rather than mutating the one an evaluator already scored.

##### 2. Evaluate outside the router \[#2-evaluate-outside-the-router]

Run the evaluator appropriate to the objective: a test suite, benchmark harness, rubric implementation, human review, or another process whose configuration you can identify. BitRouter does not infer task success from model text or choose an evaluator for you.

The result should name the sealed subject and preserve enough evaluator identity to distinguish materially different scoring configurations.

##### 3. Submit the result \[#3-submit-the-result]

Submit the result through the configured authority boundary:

```bash
bro eval result submit result.json
bro eval status
```

Admission determines which results are eligible evidence. A stored result is not permission to rewrite a policy, and an unadmitted or malformed result must not influence optimization.

##### 4. Freeze a snapshot \[#4-freeze-a-snapshot]

Freeze the currently admitted results into an immutable, content-addressed manifest:

```bash
bro eval snapshot freeze
bro eval snapshot get <EVIDENCE_ROOT>
```

The evidence root pins the exact set used for a later decision. This prevents a candidate from changing meaning when new results arrive.

##### 5. Consume the evidence explicitly \[#5-consume-the-evidence-explicitly]

Optimization can advance its controller from admitted evaluation history. `status` is read-only; `run` authorizes one controller step, may enable adaptive mode, and can publish a policy change without a separate approval:

```bash
bro optimize status --policy auto
bro optimize run --policy auto
```

Policy compilation can also pin a frozen evaluation snapshot:

```bash
bro policy compile \
  --eval-snapshot <EVIDENCE_ROOT> \
  --output candidate-policy.yaml
bro policy diff policy-lock.yaml candidate-policy.yaml
```

Compilation does not make the candidate active. Review it and use `bro policy publish candidate-policy.yaml` when it should serve traffic. The optimizer is a separate, explicitly authorized workflow and can publish its own transition during `bro optimize run`.

#### Reproducibility boundary \[#reproducibility-boundary]

A defensible evaluation decision needs all of the following to stay identifiable:

* the sealed subject and its evidence digest;
* the evaluator and materially relevant evaluator configuration;
* the submitted result and admission decision;
* the frozen evidence root consumed by optimization or compilation;
* the active and candidate policy digests being compared.

Keep private prompts, responses, and artifacts out of the subject unless the evaluator requires them. Redaction changes the evidence and therefore belongs before sealing, not as an undocumented post-processing step.

#### What evaluation does not establish \[#what-evaluation-does-not-establish]

* A successful transport or HTTP status does not establish task success.
* Lower token cost does not establish acceptable quality.
* A trace or request receipt does not become evaluation evidence merely because it is detailed.
* One admitted result does not prove a general routing policy is better.
* A compiled candidate is not active until it passes publication; an authorized optimizer step can publish its own transition.

Use repeated, comparable subjects and an evaluator aligned with the workload objective. Keep exploratory conclusions separate from policy changes you are prepared to serve.

### Inspect the active policy \[#inspect-the-active-policy]

```bash
bro policy status
bro policy check -c bitrouter.yaml
bro requests --limit 25
```

Review the active binding and policy artifact alongside the evidence used for a proposed change. [Configuration (YAML)](https://bitrouter-docs-staging.up.railway.app/docs/routing/configuration#apply-and-review-changes) covers validation and reload boundaries; [Request receipts](https://bitrouter-docs-staging.up.railway.app/docs/cli/request-receipts) covers recorded execution outcomes.

* [Auto Router](https://bitrouter-docs-staging.up.railway.app/docs/routing/auto-router) — Initialize bitrouter/auto and inspect a policy-bound request.

* [Routing Traces](https://bitrouter-docs-staging.up.railway.app/docs/routing/routing-traces) — Trace routing decisions and upstream attempts across a workflow.

* [CLI reference](https://bitrouter-docs-staging.up.railway.app/docs/usage/cli#bro-eval) — Inspect captured evaluation, optimization, and policy commands.