teff.node.supervisor¶
teff.node.supervisor
¶
Supervisor node — decide which routed agent runs next.
A single node owns the routing decision in a
:meth:teff.flow.Flow.route loop: it renders the shared sections into
the model context, asks the model for a single-word proposal, and writes
the chosen route to output_key. Deterministic guards keep the loop safe
even when the model never says finish:
- bounded loop — every call increments
rounds_key; once it reachesmax_roundsthe node returnsfinishwithout another model call; - done_keys — once the listed output slots are filled (
done_modeis"all"or"any") the node returnsfinishwith no model call: the answer already exists; - route_keys — a map route value → output slot. Picking an agent whose slot already has content would just overwrite finished work, so the pick is ignored and the loop finishes instead;
- fallback_agent —
finishbefore anything was produced routes to fallback_agent so the user still gets a real answer; - fill_order — a
[(agent, slot), ...]pipeline. The model picks the entry agent once, then the chain runs in order (each missing slot → its agent) and finishes when every slot is full; a mid-chain agent picked directly runs once and finishes. No subclass needed for the common "run the agents in order, then finish" pattern.
The finish token is configurable via finish (default "finish") — for
prompts that spell out their own terminator such as <end>. The parser
normalizes enclosing punctuation and <> on both sides, so a model replying
<finish> still matches the default token.
The decider's user message carries the accumulated progress (sections),
the current round and the latest user message, so the model can see what
already exists and route — or finish — accordingly.
Extensibility: subclasses override :meth:decide for a deterministic,
state-driven policy and :meth:_needs_model to control when the model is
consulted (see examples/release_coordinator for a fill-order policy).
Classes:
| Name | Description |
|---|---|
Supervisor |
Decide which agent handles the latest user message. |
Supervisor
¶
Bases: Node
Decide which agent handles the latest user message.
Reads the last user message (plus any work already produced), asks the
model which agent fits it best (a single word), and writes the chosen
route to output_key. When the round counter reached max_rounds
or the done_keys are already filled, the conversation is finished
without another model call.
fill_order turns the supervisor into a deterministic pipeline
without a subclass: the model picks only the entry agent, then every
mid-pipeline round runs the chain in order (planner → estimator
→ ... → finish) with no further model calls. A mid-chain agent
picked directly (a targeted question) runs once and finishes. See
examples/applications/repair-ai-chat for a chat that routes a
direct branch through done_keys while chaining the repair
agents through fill_order.
finish renames the terminator token the model answers with (default
"finish"); the same value is written to output_key for the
finish route branch. Set it to whatever your system prompt tells
the model to reply, e.g. finish="<end>".
Methods:
| Name | Description |
|---|---|
decide |
Resolve the route from the parsed proposal plus the guards. |
Source code in teff/node/supervisor.py
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 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 | |
decide
¶
decide(state, proposal)
Resolve the route from the parsed proposal plus the guards.
Default implements the chat guards on top of the model's single word:
a filled done_keys set short-circuits to finish, a premature
finish falls back to fallback_agent, and a route_keys agent
whose slot is already filled is not re-routed. With a fill_order
the mid-pipeline route is deterministic (see :meth:_chain_route);
only the entry decision comes from the model. Subclasses override
this for a deterministic policy; proposal is "" when the model
was not consulted.
Source code in teff/node/supervisor.py
220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 | |