teff.node¶
teff.node
¶
Modules:
| Name | Description |
|---|---|
agent |
ReAct agent: graph-visible tool-calling loop. |
ask |
Ask — declarative validation strategy for interrupt answers. |
command |
Command — a node return value that combines state updates with control flow. |
command_node |
Declarative |
context |
Execution context and context-building nodes for agent flows. |
extract |
Extract — declarative structured-extraction recipe. |
gate |
Gate — deterministic loop decider with a retry budget. |
interrupt |
Interrupt node — pause a workflow for external (human) input. |
llm |
LLM chat node — multi-provider, tool calling, structured output. |
loop |
Loop node — repeat a body chain until a state condition holds. |
map |
Map node — dynamically fan a state list out across concurrent branches. |
node |
Abstract base for all graph nodes. |
parallel |
Parallel node — runs independent branches concurrently. |
registry |
Node registry and decorator for registering node types. |
retry |
Retry wrapper node with configurable attempts, backoff, and timeout. |
supervisor |
Supervisor node — decide which routed agent runs next. |
tool_call |
Tool-call node — invoke a registered tool deterministically. |
transform |
Transform node — simple string/data transformations. |
Classes:
| Name | Description |
|---|---|
AppendAssistant |
Append an agent's response to the shared conversation as assistant. |
Ask |
Declarative validation strategy for an interrupt answer. |
Command |
Combine a state update with an explicit next-node route. |
CommandNode |
Declarative |
ContextBuilder |
Compose a plain-text |
ExecContext |
Context available to nodes during graph execution. |
Extract |
Declarative structured-extraction recipe ( |
Fallback |
Deterministic fallback that fills a field the model left empty. |
GraphInterrupt |
Raised by |
Interrupt |
Pause the workflow and wait for external (human) input. |
LLM |
Call an LLM chat API with tool calling and structured output. |
Loop |
Repeat a body chain until |
Map |
Run a processor over each item of a state list, in parallel. |
Node |
Abstract base class for all graph nodes. |
NodeRegistry |
Registry mapping node type names to factory functions. |
Parallel |
Execute several branch chains concurrently and merge their results. |
ReActAgent |
Single-step LLM node for a graph-level ReAct loop. |
Retry |
Wrap a node with retry logic. |
StructuredOutputError |
Raised when an LLM response fails structured-output parsing/validation. |
Supervisor |
Decide which agent handles the latest user message. |
ToolCall |
Call a registered tool by name with config-driven arguments. |
ToolExec |
Executes tools signalled by :class: |
Transform |
Apply a transform to state values. |
Validate |
Decode an interrupt answer into a |
Functions:
| Name | Description |
|---|---|
last_user_message |
Return the most recent |
AppendAssistant
¶
Bases: Node
Append an agent's response to the shared conversation as assistant.
Source code in teff/node/context.py
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 | |
Ask
¶
Declarative validation strategy for an interrupt answer.
Use the classmethod constructors to pick a strategy::
Ask.equals("yes")
Ask.any_of("yes", "ok", "sure")
Ask.regex(r"^[A-Z0-9]{4,12}$", value_key="discount_code")
Ask.check(lambda v: v.lower() in {"yes", "ok"})
Ask.llm(system=..., user=..., schema=..., model=..., provider=...)
The strategy is auto-detected from the constructor kwargs, so plain
Ask(equals="yes", value_key="code") also works.
Methods:
| Name | Description |
|---|---|
classifier |
Build the verdict classifier |
from_mapping |
Build an :class: |
validate_node |
Build the :class: |
Source code in teff/node/ask.py
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 | |
classifier
¶
classifier()
Build the verdict classifier LLM for the "llm" strategy.
Source code in teff/node/ask.py
204 205 206 207 208 209 210 211 212 213 | |
from_mapping
classmethod
¶
from_mapping(mapping)
Build an :class:Ask from a declarative strategy mapping.
Mirrors the YAML shorthand on an interrupt step::
strategy:
equals: yes
# or: any_of: [yes, ok] | regex: "^[A-Z0-9]{4}$"
# or: llm: {system, user, schema, model, provider}
The mapping's other keys (value_key, decision_key,
pass_value, fail_value, verdict_key, ok_field,
clear_field, clarify_value, rounds_key, max_rounds)
are passed through to the chosen strategy constructor.
Raises:
| Type | Description |
|---|---|
ValueError
|
When no known strategy key is present. |
Source code in teff/node/ask.py
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 | |
validate_node
¶
validate_node(input_key)
Build the :class:Validate node wired to input_key.
Source code in teff/node/ask.py
215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 | |
Command
¶
Combine a state update with an explicit next-node route.
Attributes:
| Name | Type | Description |
|---|---|---|
update |
State keys merged after the node (same as returning a plain dict; per-key reducers apply). |
|
goto |
Node id to route to next — any node in the graph (a dynamic
edge), or :data: |
Source code in teff/node/command.py
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 | |
CommandNode
¶
Bases: Node
Declarative command node: route the graph from YAML state.
Returns a :class:~teff.node.command.Command whose goto is chosen
from routes (the first route whose when condition matches
state, using the same expressions as edges: conditions) and falls
back to goto. update merges state keys after routing (reducers
apply).
Use STOP as a target to terminate the run::
- id: route
type: command
config:
routes:
- when: score >= 0.8
goto: approve
- when: score < 0.3
goto: reject
goto: review
update: {routed: true}
Source code in teff/node/command_node.py
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 | |
ContextBuilder
¶
Bases: Node
Compose a plain-text input for an agent from shared state.
Renders each configured section as <label>:\n<value> plus the latest
user message, and clears scratch keys so a routed agent starts clean.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
sections
|
dict[str, str] | None
|
State key → section label mapping. |
None
|
messages_key
|
str
|
State key holding the conversation. |
'messages'
|
output_key
|
str
|
State key receiving the composed text. |
'input'
|
reset_keys
|
tuple[str, ...]
|
Scratch state keys to clear before the agent runs. |
()
|
Source code in teff/node/context.py
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 | |
ExecContext
¶
Context available to nodes during graph execution.
Provides access to registered tools and a placeholder for LLM calls (overridden by the built-in LLM node).
Attributes:
| Name | Type | Description |
|---|---|---|
state |
Current workflow state dict. |
|
tools |
Dict of tool name to Tool instance. |
|
node_id |
Graph node id of the running node. |
|
node_type |
Node type string of the running node. |
|
tracer |
Optional :class: |
|
reducers |
Per-key merge strategies for state updates. |
|
emit |
Optional async sink receiving :class: |
|
providers |
Optional |
|
default_provider |
Optional default provider name for the graph. LLM
nodes use it when they don't set |
|
default_model |
Optional default model name for the graph. LLM
nodes use it when they don't set |
|
hooks |
Observability hooks dict (forwarded to nested runs, e.g.
:class: |
|
node_timeout |
Per-node timeout for nested runs (seconds). |
|
checkpointer |
Optional persistence backend, forwarded to nested runs so interrupts inside a subflow stay resumable. |
|
checkpoint_id |
Run key of the enclosing run, used to namespace nested run checkpoints. |
|
owner |
Owner scope of the enclosing run. |
|
resume |
Resume dict of the enclosing run, forwarded to nested runs so a sub-flow interrupted by human input resumes in place. |
|
on_llm_payload |
Optional async callback receiving the raw request /
response of every LLM call: |
Methods:
| Name | Description |
|---|---|
llm |
Placeholder for LLM calls (not used by built-in LLM node). |
tool |
Look up a tool by name. |
Source code in teff/node/context.py
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 | |
llm
async
¶
llm(model, messages)
Placeholder for LLM calls (not used by built-in LLM node).
Source code in teff/node/context.py
227 228 229 | |
tool
¶
tool(name)
Look up a tool by name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Tool name registered in the tool registry. |
required |
Returns:
| Type | Description |
|---|---|
Tool
|
Tool instance. |
Raises:
| Type | Description |
|---|---|
KeyError
|
If the tool is not registered. |
Source code in teff/node/context.py
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 | |
Extract
¶
Declarative structured-extraction recipe (Ask's sibling).
Builds [LLM extractor, *Fallback nodes] from a single spec — the
extraction half of a done chain::
extractor = Extract.model(
system="You extract project data...",
schema=PROJECT_INFO_SCHEMA,
model="llama3.1:8b",
provider="ollama",
messages_key="messages",
output_key="project_info",
fallbacks=[
Extract.fallback("room_type", room_from_first_user),
],
)
flow.interrupt_loop(key="approved", ..., done=extractor.nodes())
Use :meth:model to configure the LLM pass (equivalent to a plain
LLM with json_schema) and :meth:fallback to declare a
deterministic fill for a field the model may drop. Everything else is
threaded through to :class:~teff.node.LLM.
Methods:
| Name | Description |
|---|---|
fallback |
Declare a deterministic fill for field via |
llm |
Build the extraction |
model |
Build an extraction recipe around a structured |
nodes |
Build |
Source code in teff/node/extract.py
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 | |
fallback
classmethod
¶
fallback(field, fn)
Declare a deterministic fill for field via fn(state).
fn receives the whole workflow state and returns the field value
(or None to skip). Runs after the LLM pass, only when the
model left field empty.
Source code in teff/node/extract.py
110 111 112 113 114 115 116 117 118 | |
llm
¶
llm()
Build the extraction LLM node.
Source code in teff/node/extract.py
120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | |
model
classmethod
¶
model(*, system, schema, model, provider, **kwargs)
Build an extraction recipe around a structured LLM pass.
id (optional) names the built nodes in the compiled graph: the
extractor LLM becomes <id> and each fallback
<id>-fallback-<n>, so the topology shows extractor instead of
an auto-generated llm_chat_7.
Source code in teff/node/extract.py
85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | |
nodes
¶
nodes()
Build [LLM extractor, *Fallback nodes] for flow wiring.
Source code in teff/node/extract.py
137 138 139 140 141 142 143 144 145 146 147 148 149 | |
Fallback
¶
Bases: Node
Deterministic fallback that fills a field the model left empty.
Reads a dict from input_key; when field in it is empty / None,
calls fn(state) and merges the returned value under field. No-op
when the dict already has the field or fn returns None.
Config
input_key: State key holding the extracted dict.
field: Dict field to fill when empty.
fn: Callable fn(state) -> value | None.
Source code in teff/node/extract.py
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 | |
GraphInterrupt
¶
Bases: TeffError
Raised by graph.run() when a workflow pauses for human input.
Attributes:
| Name | Type | Description |
|---|---|---|
key |
State key the resume value will be written to. |
|
prompt |
Human-readable question shown to the operator. |
|
node_id |
Id of the interrupt node that paused execution. |
|
checkpoint_id |
Pass this back to |
|
nested_checkpoint_id |
str | None
|
When the interrupt fired inside a
:class: |
Source code in teff/node/interrupt.py
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 | |
Interrupt
¶
Bases: Node
Pause the workflow and wait for external (human) input.
When execution reaches this node, graph.run() saves a checkpoint
and raises :class:GraphInterrupt. The operator provides a value
and the graph is resumed with the same checkpoint_id and
resume::
try:
await graph.run(state, checkpointer=cp, checkpoint_id="run-1")
except GraphInterrupt as interrupt:
print(interrupt.prompt)
value = input("> ")
await graph.run(
state, checkpointer=cp, checkpoint_id="run-1", resume=value
)
The resumed value is written to the state under key before continuing with the node that follows this one.
Requires a checkpointer to be set on graph.run().
Config
key: State key that receives the resume value. prompt: Human-readable question for the operator.
Source code in teff/node/interrupt.py
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 | |
LLM
¶
Bases: Node
Call an LLM chat API with tool calling and structured output.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str | None
|
Model name (e.g. |
None
|
system
|
str
|
System prompt. Supports |
''
|
prompt
|
str | None
|
User prompt template. Supports |
None
|
input_key
|
str | None
|
State key for user message (default: whole state). |
None
|
output_key
|
str
|
State key for the response (default |
'output'
|
provider
|
str | None
|
Provider name ( |
None
|
use_tools
|
bool
|
Tool capability for the node: a list of names restricts
it to exactly those tools; |
False
|
temperature
|
float | None
|
Sampling temperature. |
None
|
max_tokens
|
int | None
|
Max tokens in response. |
None
|
response_format
|
dict | None
|
|
None
|
stream
|
bool
|
If |
False
|
on_token
|
Callable[[str], None] | None
|
Optional callback |
None
|
json_schema
|
dict | None
|
JSON Schema dict describing the expected response.
When set, the response is parsed as JSON, validated against
the schema, and re-asked (with the validation error fed back)
up to max_retries times. The parsed object is stored under
output_key. Adds |
None
|
output_type
|
Type[Any] | None
|
Python type spec — a |
None
|
parse
|
bool
|
If |
False
|
max_retries
|
int
|
How many times to re-ask after a validation failure. |
2
|
tool_timeout
|
float | None
|
Per-tool execution timeout in seconds. |
None
|
tool_retries
|
int
|
Extra attempts per tool call after a failure. |
0
|
tool_approval
|
Any
|
Gate on tool execution — |
None
|
http_max_retries
|
int
|
HTTP request retries (429/5xx/timeouts). |
2
|
fallbacks
|
list[str] | None
|
Fallback model names for provider failover. |
None
|
base_url
|
str | None
|
Custom base URL (overrides provider default). |
None
|
chat_path
|
str | None
|
Custom API path (overrides provider default). |
None
|
auth_header
|
str | None
|
Custom auth header name. |
None
|
auth_prefix
|
str | None
|
Custom auth header prefix. |
None
|
api_key_env
|
str | None
|
Custom env var for API key. |
None
|
tools
|
list[dict] | None
|
List of raw tool definition dicts. |
None
|
messages_key
|
str | None
|
State key for message history.
If set, the conversation history is read/written from/to
|
None
|
memory
|
MemoryConfig | dict | None
|
Optional long-term memory injection — a
:class: |
None
|
response_path
|
str
|
Dot-separated path to extract content from response. |
''
|
skills
|
list | None
|
Skills to mount on this call — a :class: |
None
|
skill_dir
|
str
|
Directory to resolve bare skill names from
(default |
'skills'
|
Source code in teff/node/llm.py
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 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 | |
Loop
¶
Bases: Node
Repeat a body chain until state[key] equals until.
This is the self-contained sibling of :meth:Flow.loop <teff.flow.Flow.loop>:
instead of wiring decider/done/body chains together with condition edges,
the whole repeat lives inside one node, so a loop is expressible directly
in YAML::
- id: refine
type: loop
config:
key: approved
until: "yes"
max_rounds: 3
body:
- {type: transform, config: {action: value, value: "no", output_key: approved}}
Each round runs the body chain (a single node or a list), then evaluates
the condition key=until against the merged state using the same
expression language as edges: conditions (so until: "yes" matches
"Yes" or "yes."). When the condition holds the loop stops; the body
still runs at least once even if the condition already held on entry, which
matches the Flow-loop contract where a decider writes key and then the
body decides whether to re-run.
max_rounds (default 10) bounds the repetition so a body that never
reaches until cannot hang the workflow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
body
|
Node | list[Node] | dict | list[dict]
|
Node or list of Nodes (or their declarative dict specs) run per round, sequentially. |
required |
key
|
str
|
State key the condition reads. |
''
|
until
|
str
|
Value of key that stops the loop. |
''
|
max_rounds
|
int
|
Maximum number of body rounds before giving up. |
10
|
Source code in teff/node/loop.py
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 | |
Map
¶
Bases: Node
Run a processor over each item of a state list, in parallel.
Reads one or more lists from input_keys, splits them into chunks, and runs the processor (a single node or a chain) concurrently on each chunk — with the chunk placed back under its key in an isolated state copy. The per-chunk result is gathered into a list stored at output_key, preserving the order of the source lists.
With several input_keys the lists are zipped: chunk i contains
key[0][i], key[1][i], etc., so the processor can read
multiple per-item values straight from state.
This is the dynamic sibling of :class:Parallel: branches are
derived from data at runtime instead of being declared up front.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
processor
|
Node | list[Node] | dict | list[dict]
|
Node or list of Nodes run per chunk (sequentially). |
required |
input_keys
|
str | list[str]
|
One or more state keys holding the lists to fan out. The processor reads these same keys from the branch state. |
''
|
output_key
|
str
|
State key that receives the list of per-chunk results. |
''
|
result_key
|
str | None
|
State key holding each chunk's result. Defaults to
the processor's own |
None
|
chunk_size
|
int | None
|
Items per branch (default 1 = one item per branch). |
None
|
max_concurrency
|
int | None
|
Limit on simultaneously running branches
(default |
None
|
Usage::
node = Map(
processor=LLM(model="llama3.1:8b",
input_key="chunk", output_key="summary"),
input_keys=["chunks"],
output_key="summaries",
chunk_size=4,
max_concurrency=2,
)
Source code in teff/node/map.py
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 209 210 211 212 213 214 215 216 | |
Node
¶
Bases: ABC
Abstract base class for all graph nodes.
Subclasses must set type and implement execute.
Attributes:
| Name | Type | Description |
|---|---|---|
type |
str
|
Unique node type identifier used for registry lookups. |
config |
Configuration dict (merged from constructor kwargs). |
Methods:
| Name | Description |
|---|---|
execute |
Execute the node's logic. |
Source code in teff/node/node.py
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 | |
execute
abstractmethod
async
¶
execute(ctx, state)
Execute the node's logic.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
ctx
|
Any
|
Execution context providing tool/LLM access. |
required |
state
|
dict
|
Current workflow state dict (shallow-merge in/out). |
required |
Returns:
| Type | Description |
|---|---|
dict | Command
|
State updates to shallow-merge into the workflow state, or a |
dict | Command
|
class: |
dict | Command
|
to a specific next node. |
Source code in teff/node/node.py
24 25 26 27 28 29 30 31 32 33 34 35 36 | |
NodeRegistry
¶
Registry mapping node type names to factory functions.
Used by the YAML loader and pipeline compiler to instantiate nodes by their string type identifier.
Methods:
| Name | Description |
|---|---|
copy |
Return a shallow copy with the same factory registrations. |
create |
Create a node instance by type name. |
list |
Return all registered node type names. |
register |
Register a node factory under a type name. |
Source code in teff/node/registry.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 | |
copy
¶
copy()
Return a shallow copy with the same factory registrations.
Source code in teff/node/registry.py
52 53 54 55 56 | |
create
¶
create(name, config=None, **kwargs)
Create a node instance by type name.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
name
|
str
|
Registered node type name. |
required |
config
|
dict | None
|
Optional configuration dict (backward-compatible). |
None
|
**kwargs
|
Any
|
Additional keyword arguments merged into config. |
{}
|
Returns:
| Type | Description |
|---|---|
Node
|
A Node instance. |
Raises:
| Type | Description |
|---|---|
ConfigError
|
If the type name is not registered
(also a |
Source code in teff/node/registry.py
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 | |
list
¶
list()
Return all registered node type names.
Source code in teff/node/registry.py
48 49 50 | |
register
¶
register(name, factory)
Register a node factory under a type name.
Source code in teff/node/registry.py
23 24 25 | |
Parallel
¶
Bases: Node
Execute several branch chains concurrently and merge their results.
Each branch is a list of nodes run sequentially on an isolated
copy of the state. Branches run concurrently via gather_or_cancel;
only the updates each node returns are merged back (per-key
reducers apply, so append branches accumulate instead of
overwriting one another).
Because branches read from independent copies, direct in-place mutation of the passed state is not propagated. Nodes inside branches should return their updates — the constitution's contract: receive state → return state.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
branches
|
list[Node | list[Node]]
|
Sequence of branches, each a single :class: |
required |
Usage::
node = Parallel([[upper_node, count_node], [tag_node]])
Source code in teff/node/parallel.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 | |
ReActAgent
¶
Bases: Node
Single-step LLM node for a graph-level ReAct loop.
Executes one LLM call, then signals any requested tools by setting
state["_tool_calls"] (a list of {id, name, args}) and a
non-empty state["_tool_call_name"].
When the LLM responds without calling a tool, the output key is
set and _tool_call_name is cleared — the parent graph stops
because no outgoing edge matches.
Expected graph edges::
agent ──(_tool_call_name!=)──→ tool_exec
tool_exec ──(unconditional)──→ agent
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
str | None
|
Model name (e.g. |
None
|
system
|
str
|
System prompt. |
''
|
input_key
|
str
|
State key for user input (default |
'input'
|
output_key
|
str
|
State key for final response (default |
'output'
|
messages_key
|
str
|
State key for conversation (default |
'messages'
|
tool_call_key
|
str
|
Signal key (default |
'_tool_call_name'
|
temperature
|
float | None
|
Sampling temperature. |
None
|
max_tokens
|
int | None
|
Max tokens in response. |
None
|
response_format
|
dict | None
|
|
None
|
provider
|
str | None
|
Force a provider (auto-detected from model). |
None
|
base_url
|
str | None
|
Custom base URL. |
None
|
api_key_env
|
str | None
|
Custom env var name for API key. |
None
|
chat_path
|
str | None
|
Custom API path. |
None
|
auth_header
|
str | None
|
Custom auth header name. |
None
|
auth_prefix
|
str | None
|
Custom auth header prefix. |
None
|
max_tool_rounds
|
int | None
|
Round limit used by the harness loop. |
None
|
parse_text_tool_calls
|
bool | None
|
Decode text-embedded tool calls. |
None
|
tool_error_mode
|
str | None
|
|
None
|
tool_timeout
|
float | None
|
Per-tool execution timeout in seconds. |
None
|
tool_retries
|
int
|
Extra attempts per tool call after a failure. |
0
|
max_retries
|
int
|
HTTP request retries (429/5xx/timeouts). |
2
|
fallbacks
|
list[str] | None
|
Fallback model names for provider failover. |
None
|
tool_approval
|
Any
|
Gate on tool execution — |
None
|
memory
|
MemoryConfig | dict | None
|
Optional long-term memory injection — a
:class: |
None
|
stream
|
bool
|
Stream the final assistant text (tokens forwarded to
|
False
|
on_token
|
Callable[[str], None] | None
|
Callback |
None
|
Source code in teff/node/agent.py
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 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 | |
Retry
¶
Bases: Node
Wrap a node with retry logic.
Retries the inner node up to max_retries attempts total. Between
attempts it waits delay seconds (scaled by backoff per retry,
e.g. backoff=2.0 gives delay, 2×, 4×, …). Each attempt is bounded
by timeout seconds when set. retry_on restricts which failures are
retried (exception type names or HTTP status codes); by default any
exception is retried.
Config (all optional): max_retries (default 3), delay (default
0.0), backoff (default 1.0), timeout (default None),
retry_on (default [] = all).
Source code in teff/node/retry.py
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 | |
StructuredOutputError
¶
Bases: TeffError, ValueError
Raised when an LLM response fails structured-output parsing/validation.
Attributes:
| Name | Type | Description |
|---|---|---|
schema |
The JSON Schema the output was validated against (or |
|
content |
Raw text the LLM returned. |
|
errors |
Parse/validation error message from the last attempt. |
|
attempts |
Number of attempts made before giving up. |
Source code in teff/node/llm.py
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 | |
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 | |
ToolCall
¶
Bases: Node
Call a registered tool by name with config-driven arguments.
Each argument value may contain {key} templates that are rendered
from the current state before the call. The tool's string result is
written to output_key (default: output). When on_error is
"message" a failure is stored under output_key as "error: ..."
instead of raising.
Config
tool: Registered tool name to invoke.
args: Mapping of tool argument name to value or {key} template.
output_key: State key for the result (default "output").
on_error: "raise" (default) or "message".
max_chars: Truncate the result to this many characters.
Source code in teff/node/tool_call.py
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 | |
ToolExec
¶
Bases: Node
Executes tools signalled by :class:ReActAgent in parallel and feeds
the results back into the conversation history.
Handles multiple tool calls per round: the agent writes the whole
_tool_calls list, which is executed concurrently and appended as
tool messages in one go. Falls back to the legacy single-call
signals (_tool_call_name / _tool_call_args / _tool_call_id).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
messages_key
|
str
|
State key for messages (default |
'messages'
|
tool_call_key
|
str
|
Signal key (default |
'_tool_call_name'
|
tool_error_mode
|
str
|
|
'message'
|
tool_timeout
|
float | None
|
Per-tool execution timeout in seconds. |
None
|
tool_retries
|
int
|
Extra attempts per tool call after a failure. |
0
|
tool_approval
|
Any
|
Gate on tool execution — |
None
|
human_key
|
State key / tool name of the human-in-the-loop
question (default |
required |
Source code in teff/node/agent.py
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 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 | |
Transform
¶
Bases: Node
Apply a transform to state values.
Supported actions: uppercase, lowercase, trim,
count_lines, value, render, json_get, append,
plus the pipeline-building actions contains, compare, split,
join, replace, coalesce, pick, to_int, to_float,
now.
render formats a template ({key} placeholders rendered from
state) and stores the resulting string under output_key — the scalar
counterpart of append (which accumulates into a list).
json_get extracts field from a dict in input_key. Non-string
values are stringified by default; pass raw=True to keep the value
as-is (e.g. to hand a parsed list to a Map).
append formats a template ({key} placeholders rendered from
state) and appends the result to the list in output_key. When no
template is given, input_key/value supplies the item instead. The
list is created if absent — the common "accumulate formatted results"
pattern (report sections, chapter text, step logs).
contains outputs "true"/"false" when input_key contains
value; compare does the same for input_key against value
with op in eq/ne/gt/ge/lt/le (numeric when both sides parse as
numbers). split/join convert between strings and lists with
sep (default ,). replace swaps old→new in
input_key. coalesce returns input_key unless it is empty, then
value. pick reads field out of a dict (like json_get).
to_int/to_float coerce input_key to a number (as a string).
now writes the current UTC ISO timestamp. Every action writes to
output_key; boolean-like actions emit "true"/"false" so they
can drive edges: conditions like has_refund=true.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
action
|
str
|
Transform action name. |
''
|
input_key
|
str
|
State key to read from. |
''
|
output_key
|
str
|
State key to write to. |
''
|
value
|
str | None
|
Literal value (used with |
None
|
template
|
str | None
|
Template string for |
None
|
raw
|
bool
|
Return |
False
|
Source code in teff/node/transform.py
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 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 | |
Validate
¶
Bases: Node
Decode an interrupt answer into a flow.loop decider value.
Works on two kinds of input:
- a raw answer (a string from the interrupt resume) matched by the
equals/any_of/regex/checkstrategies; - a verdict dict (from an
LLMclassifier) read via ok_field, with value_field captured into value_key.
Each evaluation increments rounds_key; once it reaches
max_rounds the node is forced to pass_value so the enclosing
loop terminates deterministically instead of spinning forever.
Config
input_key: State key holding the raw answer or verdict object.
strategy: Matching strategy for raw answers.
equals/any_of/regex/check: Strategy parameters (raw answers).
verdict_key: State key holding the classifier's verdict object.
ok_field: Pass-flag field of the verdict object.
output_key: State key receiving pass_value / fail_value.
pass_value/fail_value: Decision values written on pass / fail.
clear_field: Optional verdict boolean naming "is this answer
decipherable". When it is False the node writes
clarify_value instead of pass/fail (re-ask, no body).
clarify_value: Decision value written when clear_field is
False (falls back to fail_value when empty).
value_key: State key receiving the extracted value (cleared on a
fail). Empty to skip.
value_field: Verdict field captured into value_key.
rounds_key: State key with the evaluation counter (incremented).
max_rounds: After this many evaluations the node is forced to pass.
missing_is_ok: Treat a missing / non-dict input as a pass.
Source code in teff/node/ask.py
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 | |
last_user_message
¶
last_user_message(messages)
Return the most recent user message from a conversation list.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
messages
|
list
|
List of |
required |
Returns:
| Type | Description |
|---|---|
str
|
The latest user content, or |
Source code in teff/node/context.py
25 26 27 28 29 30 31 32 33 34 35 36 37 | |