teff.flow¶
teff.flow
¶
Modules:
| Name | Description |
|---|---|
agent |
High-level agent helpers built on :class: |
base |
Linear chain builders for :class: |
case |
Branch case for conditional routing. |
compile |
Compilation and serialization builders for :class: |
compiler |
Declarative |
control |
Branching, looping and routing builders for :class: |
flow |
Fluid flow builder for constructing graphs. |
harness |
ReAct agent harness builders for :class: |
sub_flow |
SubFlow — a node that executes a nested graph. |
team |
Supervised team builder for :class: |
Classes:
| Name | Description |
|---|---|
AgentRole |
One routed agent role for :meth: |
Case |
A single branch case used with |
Flow |
Fluid builder for constructing graphs with branching. |
SubFlow |
A node that executes a sub-graph with optional key mapping. |
Functions:
| Name | Description |
|---|---|
agent_step |
One routed agent: context builder → ReAct harness → append to conversation. |
AgentRole
¶
One routed agent role for :meth:teff.flow.Flow.team.
Describes how a role performs its slot: the system prompt, the state
key that receives its final answer, and optional model/provider/tool
knobs. :meth:build turns it into a :class:~teff.flow.SubFlow
(the agent_step recipe) that plugs straight into the team's
supervisor route loop::
flow.team(
"Route to the coder, then finish.",
roles={
"coder": AgentRole("You write code.", output_key="code"),
"planner": AgentRole(
"You plan.", output_key="plan", use_tools=["web_search"]
),
},
)
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
str
|
System prompt for the role. |
''
|
output_key
|
str
|
State key that receives the role's final answer. |
required |
model
|
str | None
|
Model override; when omitted the team/flow default is used. |
None
|
provider
|
str | None
|
Provider override; when omitted the team/flow default is used. |
None
|
sections
|
dict[str, str] | None
|
Shared state key → label mapping rendered into the agent's
context (defaults to |
None
|
messages_key
|
str
|
State key holding the shared conversation. |
'messages'
|
use_tools
|
str | list[str] | None
|
|
None
|
stream
|
bool
|
Emit tokens as stream events (live rendering). |
True
|
**config
|
Extra kwargs forwarded to the ReAct harness. |
{}
|
Methods:
| Name | Description |
|---|---|
build |
Render the role as a routed |
from_mapping |
Build a role from a |
Source code in teff/flow/agent.py
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 | |
build
¶
build(*, model=None, provider=None, id='')
Render the role as a routed agent_step SubFlow.
model/provider fall back from the arguments (the team/flow
defaults) to the role's own overrides. Raises ValueError when
neither provides them.
Source code in teff/flow/agent.py
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 | |
from_mapping
classmethod
¶
from_mapping(data, *, name='')
Build a role from a {system, output_key, ...} mapping.
Normalises the YAML team.roles entries (and plain dicts passed
to :meth:Flow.team) into an :class:AgentRole. tools: is
accepted as the legacy alias for use_tools:; any other keys are
kept and forwarded to the ReAct harness via :meth:build.
Source code in teff/flow/agent.py
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 | |
Case
¶
A single branch case used with Flow.branch().
Methods:
| Name | Description |
|---|---|
add |
Add a node to this case branch. |
Source code in teff/flow/case.py
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | |
add
¶
add(node, id=None)
Add a node to this case branch.
id optionally names the node in the compiled graph instead of
the auto-generated {type}_{n}.
Source code in teff/flow/case.py
14 15 16 17 18 19 20 21 22 | |
Flow
¶
Fluid builder for constructing graphs with branching.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Optional flow name. |
''
|
default_provider
|
str | None
|
Optional default provider name used by LLM nodes
that don't set |
None
|
default_model
|
str | None
|
Optional default model name used by LLM nodes that
don't set |
None
|
providers
|
dict | ProviderRegistry | None
|
The |
None
|
Usage::
flow = Flow(
"my-flow",
providers=ProviderRegistry.from_presets("ollama"),
default_provider="ollama",
)
flow.step(LLM(model="llama3.1:8b"))
flow.branch("status", Case("ok").add(ok_node), default=err_node)
graph = flow.compile()
The graph-building methods are implemented by dedicated builders:
- :mod:
teff.flow.base—step/llm/transform& co. (linear chain). - :mod:
teff.flow.team—team(supervised agent team). - :mod:
teff.flow.control—parallel/map/branch/interrupt/loop/route/command(control flow). - :mod:
teff.flow.harness—harness/react(ReAct agent loop). - :mod:
teff.flow.compile—compile/label/to_yaml(serialization).
Methods:
| Name | Description |
|---|---|
add_flow |
Embed a sub-flow as a single node (SubFlow). See |
append_assistant |
Add a :class: |
branch |
Add conditional branching from the last added node. See |
command |
Add a declarative |
compile |
Compile the flow into a |
context_builder |
Add a :class: |
converge |
Merge all branch ends into a single node. See |
default |
Add a fallback node for the most recent guarded |
harness |
Build a ReAct-style agent loop (LLM ↔ tools) inside this flow. |
interrupt |
Pause the flow for human input at this point. See |
interrupt_loop |
Ask the human through an interrupt and re-ask until the answer |
label |
Attach a route name to the most recently added node. See |
label_target |
Resolve a declarative |
llm |
Add an :class: |
loop |
Run a chain repeatedly until |
map |
Dynamically fan a state list out across parallel branches. See |
parallel |
Run several branch chains concurrently from the last node. See |
react |
Alias for :meth: |
route |
Route between agent chains under a supervisor decider. See |
step |
Append a node to the linear chain. See |
supervisor |
Add a :class: |
team |
Compose a supervised agent team in one call. See |
to_yaml |
Export the compiled flow as a |
transform |
Add a :class: |
Source code in teff/flow/flow.py
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 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 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 | |
add_flow
¶
add_flow(flow, id=None, **kw)
Embed a sub-flow as a single node (SubFlow). See
:meth:teff.flow.control.ControlBuilder.add_flow.
Source code in teff/flow/flow.py
263 264 265 266 | |
append_assistant
¶
append_assistant(node=None, id=None, **config)
Add a :class:~teff.node.context.AppendAssistant node. See
:meth:teff.flow.base.BaseBuilder.append_assistant.
Source code in teff/flow/flow.py
204 205 206 207 208 209 210 211 212 | |
branch
¶
branch(key, *cases, default=None)
Add conditional branching from the last added node. See
:meth:teff.flow.control.ControlBuilder.branch.
Source code in teff/flow/flow.py
296 297 298 299 | |
command
¶
command(*, routes=None, goto=None, update=None, id=None)
Add a declarative command node that routes by state. See
:meth:teff.flow.control.ControlBuilder.command.
Source code in teff/flow/flow.py
368 369 370 371 372 373 374 375 376 377 378 | |
compile
¶
compile()
Compile the flow into a Graph ready for execution. See
:meth:teff.flow.compile.CompileBuilder.compile.
Source code in teff/flow/flow.py
458 459 460 461 | |
context_builder
¶
context_builder(node=None, id=None, **config)
Add a :class:~teff.node.context.ContextBuilder node. See
:meth:teff.flow.base.BaseBuilder.context_builder.
Source code in teff/flow/flow.py
194 195 196 197 198 199 200 201 202 | |
converge
¶
converge(node, id=None)
Merge all branch ends into a single node. See
:meth:teff.flow.control.ControlBuilder.converge.
Source code in teff/flow/flow.py
306 307 308 309 | |
default
¶
default(node, id=None)
Add a fallback node for the most recent guarded step(). See
:meth:teff.flow.control.ControlBuilder.default.
Source code in teff/flow/flow.py
301 302 303 304 | |
harness
¶
harness(
model=None,
system="",
*,
agent=None,
input_key="input",
output_key="output",
messages_key="messages",
memory=None,
max_tool_rounds=10,
tool_error_mode="message",
parse_text_tool_calls=True,
temperature=None,
max_tokens=None,
response_format=None,
use_tools=None,
skills=None,
skill_dir="skills",
id=None,
**config,
)
Build a ReAct-style agent loop (LLM ↔ tools) inside this flow.
See :meth:teff.flow.harness.HarnessBuilder.harness.
Source code in teff/flow/flow.py
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 | |
interrupt
¶
interrupt(key, prompt='', *, accept=None, id=None)
Pause the flow for human input at this point. See
:meth:teff.flow.control.ControlBuilder.interrupt.
Source code in teff/flow/flow.py
311 312 313 314 315 316 317 318 319 320 321 | |
interrupt_loop
¶
interrupt_loop(key, *, accept, body, done, prompt='', id=None)
Ask the human through an interrupt and re-ask until the answer
passes. See :meth:teff.flow.control.ControlBuilder.interrupt_loop.
Source code in teff/flow/flow.py
336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 | |
label
¶
label(name)
Attach a route name to the most recently added node. See
:meth:teff.flow.compile.CompileBuilder.label.
Source code in teff/flow/flow.py
463 464 465 466 | |
label_target
¶
label_target(goto)
Resolve a declarative goto against labels to a real node id.
See :meth:teff.flow.compile.CompileBuilder.label_target.
Source code in teff/flow/flow.py
468 469 470 471 | |
llm
¶
llm(node=None, id=None, *, memory=None, **config)
Add an :class:~teff.node.llm.LLM chat node. See
:meth:teff.flow.base.BaseBuilder.llm.
Source code in teff/flow/flow.py
175 176 177 178 179 180 181 182 183 184 185 | |
loop
¶
loop(key, until, done, body, *, max_rounds=None)
Run a chain repeatedly until state[key] equals until. See
:meth:teff.flow.control.ControlBuilder.loop.
Source code in teff/flow/flow.py
323 324 325 326 327 328 329 330 331 332 333 334 | |
map
¶
map(
processor,
*,
input_keys="",
output_key="",
chunk_size=None,
max_concurrency=None,
id=None,
**kwargs,
)
Dynamically fan a state list out across parallel branches. See
:meth:teff.flow.control.ControlBuilder.map.
Source code in teff/flow/flow.py
273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 | |
parallel
¶
parallel(*branches, id=None)
Run several branch chains concurrently from the last node. See
:meth:teff.flow.control.ControlBuilder.parallel.
Source code in teff/flow/flow.py
268 269 270 271 | |
react
¶
react(
model=None,
system="",
*,
agent=None,
input_key="input",
output_key="output",
messages_key="messages",
memory=None,
**config,
)
Alias for :meth:harness (ReAct agent loop). See
:meth:teff.flow.harness.HarnessBuilder.react.
Source code in teff/flow/flow.py
429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 | |
route
¶
route(key, *, finish=None, **agents)
Route between agent chains under a supervisor decider. See
:meth:teff.flow.control.ControlBuilder.route.
Source code in teff/flow/flow.py
357 358 359 360 361 362 363 364 365 366 | |
step
¶
step(node, id=None, *, when=None)
Append a node to the linear chain. See
:meth:teff.flow.base.BaseBuilder.step.
Source code in teff/flow/flow.py
164 165 166 167 168 169 170 171 172 173 | |
supervisor
¶
supervisor(node=None, id=None, **config)
Add a :class:~teff.node.supervisor.Supervisor decider node. See
:meth:teff.flow.base.BaseBuilder.supervisor.
Source code in teff/flow/flow.py
214 215 216 217 218 219 220 221 222 | |
team
¶
team(
system="",
*,
roles,
model=None,
provider=None,
messages_key="messages",
sections=None,
route_keys=None,
done_keys=None,
done_mode="all",
fallback="",
max_rounds=6,
finish=None,
id=None,
)
Compose a supervised agent team in one call. See
:meth:teff.flow.team.TeamBuilder.team.
Source code in teff/flow/flow.py
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 | |
to_yaml
¶
to_yaml(*, tools=None, initial=None, reducers=None)
Export the compiled flow as a workflow.yaml document. See
:meth:teff.flow.compile.CompileBuilder.to_yaml.
Source code in teff/flow/flow.py
473 474 475 476 477 478 479 480 481 482 | |
transform
¶
transform(node=None, id=None, **config)
Add a :class:~teff.node.transform.Transform node. See
:meth:teff.flow.base.BaseBuilder.transform.
Source code in teff/flow/flow.py
187 188 189 190 191 192 | |
SubFlow
¶
Bases: Node
A node that executes a sub-graph with optional key mapping.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
graph
|
Graph
|
Compiled sub-graph to run. |
required |
input_map
|
dict[str, str] | None
|
Parent key → sub-graph key (default: passthrough). |
None
|
output_map
|
dict[str, str] | None
|
Sub-graph key → parent key (default: passthrough). |
None
|
max_iterations
|
int | None
|
Max node executions inside the sub-graph
(passed to |
None
|
Source code in teff/flow/sub_flow.py
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 | |
agent_step
¶
agent_step(
system,
output_key,
*,
model,
provider,
sections=None,
messages_key="messages",
use_tools=None,
stream=True,
id=None,
**config,
)
One routed agent: context builder → ReAct harness → append to conversation.
Builds a small Flow wrapped as a :class:~teff.flow.SubFlow::
ContextBuilder ──► ReAct harness ──► AppendAssistant
- The context builder composes a plain-text
inputfrom the shared state sections (plus the latest user message) and resets the agent's scratch keys, so each run starts clean. - The harness runs the model against that
inputwith use_tools, writing its final answer to output_key. AppendAssistantcopies that answer into the shared conversation.
The agent's scratch conversation lives in a private _<output_key>_messages
state slot (reset by the context builder); only the final reply reaches
messages_key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
system
|
str
|
System prompt for the agent. |
required |
output_key
|
str
|
State key that receives the agent's final answer. |
required |
model
|
str
|
LLM model name (e.g. |
required |
provider
|
str
|
Provider name (e.g. |
required |
sections
|
dict[str, str] | None
|
Shared state key → label mapping rendered into the agent's
context. Defaults to |
None
|
messages_key
|
str
|
State key holding the shared conversation. |
'messages'
|
use_tools
|
str | list[str] | None
|
|
None
|
stream
|
bool
|
Emit tokens as stream events (live rendering). |
True
|
**config
|
Extra kwargs for the ReAct harness / |
{}
|
Returns:
| Type | Description |
|---|---|
SubFlow
|
A |
SubFlow
|
meth: |
Source code in teff/flow/agent.py
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 | |