teff.flow.harness¶
teff.flow.harness
¶
ReAct agent harness builders for :class:~teff.flow.Flow.
:class:HarnessBuilder builds the ReAct agent loop (LLM ↔ tools) used by
Flow.harness / Flow.react. :class:Flow owns an instance and
delegates to it.
Classes:
| Name | Description |
|---|---|
HarnessBuilder |
Build a ReAct agent loop on a :class: |
HarnessBuilder
¶
Build a ReAct agent loop on a :class:~teff.flow.Flow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
flow
|
Flow
|
The owning |
required |
Methods:
| Name | Description |
|---|---|
harness |
Build a ReAct-style agent loop (LLM ↔ tools) inside this flow. |
react |
Alias for :meth: |
Source code in teff/flow/harness.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 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 | |
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.
Creates an agent node and a tool executor wired in a cycle. The
agent calls the LLM; if the LLM requests tools, they are signalled
to the executor, which runs them all in parallel and loops back
to the agent. When the LLM answers without a tool call, the output
is stored at output_key and execution continues after the loop
(any node chained with step()/branch() after this call).
Multiple tools can be requested in a single round (e.g. read from
RAG and compute at once); the executor fans them out with
asyncio.gather.
id names the two nodes created by this helper as {id}/agent
and {id}/tool; when omitted they keep the auto-generated
{type}_{n} ids.
The agent node is a :class:~teff.node.agent.ReActAgent. Pass a
pre-built instance or a subclass to override its behaviour::
flow.react(agent=MyAgent(model="gpt-4", system="..."))
flow.react(agent=MyAgentClass, model="gpt-4", system="...")
With an instance, model/system and the other agent knobs are
ignored (the instance is used as-is); with a subclass they are
forwarded to its constructor. When agent is omitted the
ReActAgent class is used and model is required.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
LLM model name (e.g. |
None
|
|
system
|
str
|
Optional system prompt. |
''
|
agent
|
A |
None
|
|
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'
|
memory
|
Long-term memory injection — a
:class: |
None
|
|
max_tool_rounds
|
int
|
Max model calls per graph visit. |
10
|
tool_error_mode
|
str
|
|
'message'
|
parse_text_tool_calls
|
bool
|
Decode tool calls embedded in plain text. |
True
|
temperature / max_tokens / response_format
|
Sampling knobs. |
required | |
use_tools
|
|
None
|
|
skills
|
list | None
|
Skills to mount on the agent — names resolved against
skill_dir, skill paths, or :class: |
None
|
skill_dir
|
str
|
Directory to resolve bare skill names from
(default |
'skills'
|
**config
|
Extra kwargs passed to :class: |
{}
|
Remember to pass max_iterations to graph.run()::
result = await graph.run(state, tools=tools, max_iterations=20)
Source code in teff/flow/harness.py
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 | |
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).
Source code in teff/flow/harness.py
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 | |