Remote
Source: examples/model_selection/remote.py
Introduction
Remote model selection has the same routing tradeoffs as local selection but adds external service variability; FrugalGPT and RouteLLM motivate policy-driven routing, and Toward Engineering AGI motivates engineering-task-aware evaluation of those routes. This example implements remote selection with deterministic logging.
Technical Implementation
Configure
Tracerwith JSONL + console output so each run emits machine-readable traces and lifecycle logs.Build the runtime surface (public APIs only) and execute
ModelSelector.select(...)with a fixedrequest_id.Evaluate model constraints and policy, then expose selector metadata in the traced payload.
Print a compact JSON payload including
trace_infofor deterministic tests and docs examples.
flowchart LR
A["Input prompt or scenario"] --> B["main(): runtime wiring"]
B --> C["ModelSelector.select(...)"]
C --> D["policy and constraints resolve one model-selection outcome"]
C --> E["Tracer JSONL + console events"]
D --> F["ExecutionResult/payload"]
E --> F
F --> G["Printed JSON output"]
1from __future__ import annotations
2
3import json
4from dataclasses import asdict
5from pathlib import Path
6
7from design_research_agents import ModelSelector, Tracer
8
9
10def _select_remote() -> dict[str, object]:
11 selector = ModelSelector()
12 decision = selector.select(
13 task="Handle a fast design triage chat during incident response.",
14 priority="speed",
15 max_latency_ms=800,
16 hardware_profile={
17 "total_ram_gb": 16.0,
18 "available_ram_gb": 12.0,
19 "cpu_count": 4,
20 "load_average": (6.0, 5.5, 5.0),
21 "gpu_present": False,
22 "gpu_vram_gb": None,
23 "gpu_name": None,
24 "platform_name": "example",
25 },
26 output="decision",
27 )
28 return asdict(decision)
29
30
31def main() -> None:
32 """Run traced remote-favoring model selection and print decision."""
33 # Fixed request id keeps traces and docs output deterministic across runs.
34 request_id = "example-model-selection-remote-design-001"
35 tracer = Tracer(
36 enabled=True,
37 trace_dir=Path("artifacts/examples/traces"),
38 enable_jsonl=True,
39 enable_console=True,
40 )
41 payload = tracer.run_callable(
42 agent_name="ExamplesModelSelectionRemote",
43 request_id=request_id,
44 input_payload={"scenario": "remote-selection"},
45 function=_select_remote,
46 )
47 assert isinstance(payload, dict)
48 payload["example"] = "model_selection/remote.py"
49 payload["trace"] = tracer.trace_info(request_id)
50 print(json.dumps(payload, ensure_ascii=True, indent=2, sort_keys=True))
51
52
53if __name__ == "__main__":
54 main()
Expected Results
Run Command
PYTHONPATH=src python3 examples/model_selection/remote.py
Example output captured with DRA_EXAMPLE_LLM_MODE=deterministic
(timestamps, durations, and trace filenames vary by run):
{
"catalog_signature": "440e215f0fee",
"example": "model_selection/remote.py",
"model_id": "gpt-4o-mini",
"policy_id": "default",
"provider": "openai",
"rationale": "priority=speed; selection_reason=high_load_remote; ram_budget_gb=10.0; max_latency_ms=800; gpu_p...
"safety_constraints": {
"max_cost_usd": null,
"max_latency_ms": 800
},
"trace": {
"request_id": "example-model-selection-remote-design-001",
"trace_dir": "artifacts/examples/traces",
"trace_path": "artifacts/examples/traces/run_20260222T162207Z_example-model-selection-remote-design-001.jsonl"
}
}