Run a staging gateway pilot
Run a real tool-calling agent through two serving configurations and see whether it still completes the task. The reference agent looks up synthetic order receipts. Each arm starts a fresh agent with its own read-only lookup tool. An answer succeeds when the agent looks up the correct order exactly once and returns the correct receipt.
First run
Use a fresh source checkout or extract the staging preview kit. From its root, on macOS or Linux, install Rust with Cargo, Python 3.11–3.13, and uv. Compiling and installing the locked packages requires internet access. The fixture run uses loopback networking, needs no credentials, and makes no paid API calls.
cargo build --release --locked --manifest-path gateway/Cargo.toml
uv run --locked --project examples/staging_pilot python examples/staging_pilot/run.py \
--gateway gateway/target/release/runeconomy-gateway --output ../pilot-output/pilot-fixture
Open ../pilot-output/pilot-fixture/summary.json. The baseline should complete eight of eight orders using 16 model requests. The scripted candidate skips the lookup on odd orders. It should use 12 requests and succeed on four of eight orders. The scripts exercise Hugging Face’s smolagents ToolCallingAgent, two independently running agent loops, the Rust ingress and the Python evidence recorder. Token counts in fixture mode are scripted.
Replay a captured cohort
uv run --locked --project examples/staging_pilot python examples/staging_pilot/run.py \
--gateway gateway/target/release/runeconomy-gateway --output ../pilot-output/pilot-replay \
--capture-session ../pilot-output/pilot-fixture/baseline.jsonl --sample-bps 5000
Sampling is deterministic by workflow ID. This example selects five distinct orders from the baseline capture at 50%. Each selected order runs against both arms from the beginning. The replay adapter accepts only task IDs in the synthetic catalog. It reads correlation metadata from the closed session and reconstructs tools from local fixtures. This keeps replay off the request path and prevents a replay from repeating an external transaction. For another workload, supply a separately reviewed task catalog, isolated tool implementation and terminal evaluator.
For recurring replay, point the worker at a private directory of completed captures. Each eligible session and configuration has a separate job directory. The worker snapshots its input, locks each job, records completion, and skips completed work across restarts. It retries failed jobs up to three attempts. A sample with zero eligible orders finishes without running an agent.
uv run --locked --project examples/staging_pilot python examples/staging_pilot/shadow_worker.py \
--inbox ../pilot-output/pilot-fixture --state ../pilot-output/shadow-state \
--gateway gateway/target/release/runeconomy-gateway --sample-bps 5000 --watch
Stop the worker with Ctrl-C. The fixture mode uses local scripted endpoints. Supply two reviewed loopback endpoints and a model alias to exercise a local model pair.
What happened with real models
Two local llama.cpp servers ran Qwen2.5-0.5B-Instruct on one Apple Silicon host. The baseline used Q8_0 weights and the candidate used Q4_K_M. Both arms used the same agent, evaluator, model alias, context size and generation limits. Baseline-first and candidate-first ordering alternated by order. The agent submitted tool calls and chose its later actions independently on each arm.
| Eight paired synthetic orders | Q8_0 baseline | Q4_K_M candidate |
|---|---|---|
| Correctly completed orders | 4 | 8 |
| Model requests | 24 | 16 |
| Lookup calls | 12 | 8 |
| Reported prompt tokens | 25,819 | 18,329 |
| Reported completion tokens | 1,404 | 619 |
| Total elapsed agent time | 26.59 s | 10.21 s |
An earlier engineering run on the same eight orders produced four and seven successes, respectively. These were exploratory runs on one small model and one task family. The receipt evaluator also penalizes a repeated lookup that returns the correct answer. The aggregate records include paired inference and the reproduction identifiers. A shipping decision needs representative held-out tasks and a frozen design.
Independent GPU run
We ran the same eight orders in a private, ephemeral Modal container with one NVIDIA A10G. Q8_0 completed five orders correctly across 22 model requests. Q4_K_M completed eight across 16 requests. The two model servers shared the GPU. The complete worker took 27.00 seconds, including model downloads and digest verification. At the configured resource limits and published rates, that successful worker window represents approximately $0.011 in compute. Image builds, initialization attempts and billing adjustments are outside that estimate. Modal resource pricing
To reproduce with an authenticated Modal account, run the command below from the source root. This creates a billable ephemeral job. The function allows one A10 container, sets a 900-second execution timeout and configures zero function retries. Image build and startup have separate lifecycles. The runner returns only aggregate evidence.
uv run --with modal==1.6.4 modal run examples/staging_pilot/modal_pilot.py \
--output modal-reference-result.json
Reproduce the local deployment
The measured run used llama.cpp release b12870 and the official Qwen GGUF repository at revision 9217f5db79a29953eb74d5343926648285ec7e67. Obtain the llama-server executable for your platform. Run python3 examples/staging_pilot/fetch_weights.py ../pilot-models to download and verify the weights. The reference files' SHA-256 digests are in examples/staging_pilot/results/local-deployment.json. The two weights occupy approximately 1.1 GiB combined. The runner starts both servers on loopback, bounds startup and run duration, and shuts down the processes when the comparison ends.
uv run --locked --project examples/staging_pilot python examples/staging_pilot/serve_pair.py \
--server /path/to/llama-server --baseline /path/to/qwen2.5-0.5b-instruct-q8_0.gguf \
--candidate /path/to/qwen2.5-0.5b-instruct-q4_k_m.gguf \
--gateway gateway/target/release/runeconomy-gateway --output ../pilot-output/model-pair
python3 gateway/economics.py ../pilot-output/model-pair --baseline-hourly 1 --candidate-hourly 1
The observed shared-host window was 45.80 seconds, including both startups and shutdowns. The pricing command models two dedicated replicas at the rates you supply, charging each for that entire window and dividing by successful orders. At the illustrative rate of $1 per replica-hour, the result is $0.00318 and $0.00159 per success. The model includes idle reservation and unsuccessful attempts. Use the extra-cost flags for attributed charges. The run itself incurred $0 in cloud or inference-service charges. We did not measure electricity or hardware depreciation.
Test step routing and speculative decoding
Add --candidate-planner-baseline to the paired deployment command to send the candidate agent’s first model turn to the baseline model and its later turns to the candidate model. In this run, the mixed configuration succeeded on 7/8 orders and the Q8 baseline on 4/8. The agent labels its own first turn. The ingress accepts operator-configured candidate_steps mapping a role to a dedicated loopback capture sidecar. A client role affects routing only within a selected candidate cohort.
To test speculation alone, select Q4_K_M weights for both arms and add --candidate-speculation ngram-simple. Across eight orders, the baseline completed seven and the candidate completed eight. Elapsed agent time totaled 12.10 s and 8.81 s. This experiment uses llama.cpp’s built-in n-gram draft strategy. The samples are exploratory and share the same synthetic tasks as the other runs.
Reproduce the replica comparison
uv run --locked --project examples/staging_pilot python examples/staging_pilot/affinity.py \
--server /path/to/llama-server --weights /path/to/qwen2.5-0.5b-instruct-q4_k_m.gguf \
--gateway gateway/target/release/runeconomy-gateway --output ../pilot-output/replica-comparison
We sent 16 sequential requests with two repeating synthetic prefixes to two fresh single-slot replicas per scheduling strategy. Round-robin routing yielded 6,398 backend-reported cached tokens and 2,184 evaluated prompt tokens. Prefix affinity yielded 7,410 cached tokens and 1,172 evaluated prompt tokens. Median end-to-end request latency was 24.04 ms and 19.87 ms, respectively. The workload deliberately balances the two prefixes across replicas. Skewed traffic and concurrent queueing need separate evaluation.
Gateway operation
The Rust ingress accepts bearer-authenticated inference requests on loopback. It binds each tenant to separate capture sidecars. Python writes the versioned session evidence. The ingress streams the response body and strips ingress credentials, cookies and hop-by-hop headers. An operator can place a TLS terminator in front of a private staging installation. Use private networks and tightly scoped downstream credentials.
Each tenant configuration specifies a name, a token environment variable with at least 32 characters, baseline and candidate sidecar origins, and an absolute policy file path. The pilot generates a working configuration in the output directory with ephemeral ports. For a persistent staging installation, run the two capture proxies against your reviewed upstreams, set the token in the service environment and substitute their actual loopback origins. An absent policy sends all traffic to the baseline.
{
"listen": "127.0.0.1:8769",
"tenants": [{
"name": "staging", "token_env": "STAGING_GATEWAY_TOKEN",
"baseline": "http://127.0.0.1:8771", "candidate": "http://127.0.0.1:8772",
"policy_file": "/path/to/private/staging/policy.json",
"routing": "affinity"
}]
}
Start the edge with gateway/target/release/runeconomy-gateway CONFIG.json. Point the agent’s base URL at the listener’s /v1 path. Send the gateway bearer token and an explicit x-runeconomy-workflow-id. The reference agent also sends span and dependency headers for its sequential model turns. Requests without workflow IDs use the baseline. For additional replicas, supply baseline_replicas or candidate_replicas as arrays of distinct loopback capture origins. Affinity uses the caller’s x-runeconomy-prefix-id or its workflow ID. Round robin is the default. A prefix ID identifies a routing preference. Only backend telemetry measures a cache hit.
Roll out and roll back
The operator can start a canary after reviewing a verified result from an intact, complete freeze and confirming that the configured sidecars point at the exact deployment that was tested. Run the following with Python from the RunEconomy environment. The reviewed SHA-256 is the hex digest of the actual result file.
python -m runeconomy.staging_policy --directory /path/to/private/staging --tenant staging canary \
--workspace /path/to/frozen-workspace --result /path/to/result.json --reviewed-sha256 "$RESULT_SHA256" \
--basis-points 100 --seconds 600 --reason "Reviewed staging canary"
python -m runeconomy.staging_policy --directory /path/to/private/staging --tenant staging status
python -m runeconomy.staging_policy --directory /path/to/private/staging --tenant staging rollback \
--reason "Return all new requests to baseline"
The control command limits a canary to 5% and one hour. Each change creates a private history record and atomically replaces the routing policy. Malformed, expired and wrong-tenant policies select baseline. Three consecutive candidate connection or HTTP 5xx failures open that tenant’s in-memory circuit for the current epoch. Subsequent requests use baseline. A request already sent upstream is never automatically replayed. The circuit counts response headers and connection errors. An interrupted body propagates to its client. A new policy epoch or process restart resets in-memory state. Apply rollback to persist the decision. A changed epoch can reassign an active workflow, so issue routine promotions between workflow batches.
A verification pipeline can invoke observe --epoch EPOCH --workspace WORKSPACE --result RESULT --reviewed-sha256 SHA256 on the same policy command. Attach the rollout epoch when launching the verification job. A frozen regression or invalid verdict returns that epoch to baseline. A delayed observation cannot roll back a newer epoch. Verified and inconclusive observations leave exposure at its configured level.
Verification history and alerts
Use python -m runeconomy.staging_history --db PRIVATE.db record --tenant staging --workspace WORKSPACE --result RESULT to ingest an operator-reviewed local run. Repeated ingestion is idempotent. The database stores the verdict, result and freeze digests, timestamp and tenant. Serve read-only history with python -m runeconomy.staging_history --db PRIVATE.db serve --config CONFIG.json. Authenticated clients can read their latest 100 records at /runs or their regressions and invalid results at /alerts on loopback port 8768. Status in the policy tool describes the configured rollout. Runtime routing can also fall back because of the circuit.
Check your installation
cargo test --release --locked --manifest-path gateway/Cargo.toml
python3 gateway/qualify.py gateway/target/release/runeconomy-gateway
The qualification command exercises two tenants, partial stream delivery, expired and malformed policy handling, and upstream failure fallback. It then measures 128 direct and 128 proxied requests at four concurrent clients. The included record measures same-host HTTP handling. A production throughput or availability target requires its own workload, payload sizes, deployment topology, and sustained load test.
Feedback from a first staging run
Record time from installation to the first usable comparison, the serving change you were deciding on, the first tool turn where the arms diverged, and the shipping decision you reached. If the harness could not produce a decision, include the failing command and a sanitized error. For a subsequent run, record what changed and whether the first result helped you choose the next test.
What to share with the team
Start with the aggregate summary.json, the agent and serving revisions, the evaluator definition, and the decision the result informed. Keep session JSONL, server logs, policy directories, model weights and credentials private. Run the example twice in distinct output directories if you want to see run-to-run variability. The independent reference tests cover local staging, operator-managed canaries and single-host serving. Customer retention, savings on customer traffic and a contractual quality guarantee require a customer deployment.