1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
//! High-level **model router** — the declarative workload-tier layer over the
//! named model registry (registry component kind
//! [`Router`](crate::registry::ComponentKind::Router)).
//!
//! # Why this exists
//!
//! [`CapabilityRegistry`](crate::registry::CapabilityRegistry) and the harness
//! [`ModelRegistry`](crate::harness::runtime::ModelRegistry) resolve a model *by
//! name* and the agent loop can fail over across a
//! [`FallbackPolicy`](crate::harness::retry::FallbackPolicy) — but neither owns
//! the *policy* that maps a host's **workload tiers** (`chat-v1`, `reasoning-v1`,
//! `vision-v1`, …) onto concrete models, nor the per-tier capability gates and
//! same-family fallback ordering that go with them. Hosts have historically
//! re-implemented that projection by hand (OpenHuman's `RouterProvider` +
//! `routes.rs`): register a model per tier alias, build a `FallbackPolicy`, stamp
//! a required [`CapabilitySet`](crate::harness::model::CapabilitySet) per turn.
//!
//! [`ModelRouter`] is the crate-owned home for exactly that policy. A host
//! *declares* its tier table once — each [`WorkloadRoute`] names the model an
//! alias forwards to, the capabilities a request routed there must satisfy, and
//! the ordered sibling aliases to fall back to — and the router answers the three
//! questions the turn assembly needs:
//!
//! - **resolution**: which registered model does this alias forward to?
//! ([`target_model`](ModelRouter::target_model))
//! - **fallback**: the [`FallbackPolicy`] for a turn whose primary is this alias
//! (`[alias, fallbacks…]`) ([`fallback_policy`](ModelRouter::fallback_policy))
//! - **capability gate**: the [`CapabilitySet`] to stamp on requests routed here
//! ([`required_capabilities`](ModelRouter::required_capabilities))
//!
//! It holds no models and drives no I/O — it is pure, cheap, cloneable policy
//! that a harness assembler reads while wiring a registry + run policy. That
//! keeps the *what routes where* declarative and testable in isolation from the
//! *how a model is built* (which stays with the host provider/factory).
//!
//! # Example
//!
//! ```
//! use tinyagents::harness::model::CapabilitySet;
//! use tinyagents::registry::router::{ModelRouter, WorkloadRoute};
//!
//! let router = ModelRouter::new()
//! .with_route(WorkloadRoute::new("chat-v1", "chat-v1").with_fallbacks(["burst-v1"]))
//! .with_route(WorkloadRoute::new("burst-v1", "burst-v1").with_fallbacks(["chat-v1"]))
//! .with_route(
//! WorkloadRoute::new("vision-v1", "vision-v1")
//! .requiring(CapabilitySet { image_in: true, ..CapabilitySet::default() }),
//! )
//! .with_default("chat-v1");
//!
//! // A chat turn fails over to its sibling burst tier.
//! let policy = router.fallback_policy("chat-v1").unwrap();
//! assert_eq!(policy.next_after("chat-v1"), Some("burst-v1"));
//!
//! // A vision turn is capability-gated and primary-only (no fallback).
//! assert!(router.required_capabilities("vision-v1").unwrap().image_in);
//! assert!(router.fallback_policy("vision-v1").is_none());
//! ```
pub use WorkloadRoute;
use crate;
use crateCapabilitySet;
use crateFallbackPolicy;
/// A declarative, name-addressable router over registered models: it maps named
/// workload tiers to concrete registered model names and owns the per-tier
/// capability gates and same-family fallback ordering.
///
/// Insertion order is preserved so [`routes`](Self::routes) and
/// [`aliases`](Self::aliases) iterate deterministically (registration order),
/// which callers rely on when projecting the table onto a registry.
///
/// See the [module docs](self) for the design rationale and an example.