teff.node.context¶
teff.node.context
¶
Execution context and context-building nodes for agent flows.
Two concerns live here:
- :class:
ExecContext— the runtime handle passed to every node. - :class:
ContextBuilder/ :class:AppendAssistantand :func:last_user_message— shared building blocks for routing a conversation turn to an agent: compose a plain-textinputfrom state, then append the agent's reply back to the shared conversation. They are used by :func:teff.flow.agent_stepand by every scaffold/example.
Classes:
| Name | Description |
|---|---|
AppendAssistant |
Append an agent's response to the shared conversation as assistant. |
ContextBuilder |
Compose a plain-text |
ExecContext |
Context available to nodes during graph execution. |
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 | |
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 | |
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 | |