kaboo_workflows.testing¶
Scripted models and an in-process pipeline for testing your own workflows. See Testing your workflows for the guide.
kaboo_workflows.testing ¶
Test your own workflows end to end, with no model provider or network.
:class:ScriptedModel stands in for an LLM with a fixed per-agent script, and
:class:Pipeline drives a config through the same AG-UI path a deployed
service uses, returning what a client would see as a :class:TurnResult.
Pipeline ¶
Pipeline(config, *, session_config_key=None)
A resolved config that can be driven turn by turn in one event loop.
Resolve config once for every turn this pipeline drives.
By default one session serves every turn, as a process with a fixed
config does. Pass session_config_key and each turn builds its own
session from the config it submits in forwarded_props, exactly as
the endpoint does — which is also how a test simulates a restart,
since a rebuilt session shares nothing with the last one.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
ConfigInput | list[ConfigInput]
|
A file path, a raw YAML string, or a list of either, as
:func: |
required |
session_config_key
|
str | None
|
The |
None
|
Source code in src/kaboo_workflows/testing/pipeline.py
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 | |
turn
async
¶
turn(
message=None,
*,
thread_id="t1",
run_id="r1",
state=None,
messages=None,
resume=None,
forwarded_props=None,
tools=None,
context=None,
)
Drive one run and collect what a client would see.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message
|
str | None
|
The user's message. Ignored when |
None
|
thread_id
|
str
|
The conversation id. |
't1'
|
run_id
|
str
|
This run's id. |
'r1'
|
state
|
dict[str, Any] | None
|
The client state to send, usually the previous turn's
:meth: |
None
|
messages
|
list[Any] | None
|
A full AG-UI transcript to send instead of |
None
|
resume
|
list[dict[str, Any]] | None
|
Answers to the pending interrupts, as a client sends them to resume a paused run. |
None
|
forwarded_props
|
dict[str, Any] | None
|
The run's forwarded props, such as a run token or,
with |
None
|
tools
|
list[Any] | None
|
The browser tools the client declares, as AG-UI |
None
|
context
|
list[Any] | None
|
The client's context items, as AG-UI |
None
|
Returns:
| Type | Description |
|---|---|
TurnResult
|
The events and activity groups the run produced. |
Raises:
| Type | Description |
|---|---|
LookupError
|
|
Source code in src/kaboo_workflows/testing/pipeline.py
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 | |
forget ¶
forget(thread_id)
Drop a conversation's session and events, as a process that never saw it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thread_id
|
str
|
The conversation id. |
required |
Source code in src/kaboo_workflows/testing/pipeline.py
423 424 425 426 427 428 429 430 | |
close ¶
close()
Stop the MCP servers and clients the config started.
Source code in src/kaboo_workflows/testing/pipeline.py
432 433 434 | |
TurnResult
dataclass
¶
TurnResult(
events,
groups,
exchange=HistoryExchange(),
usage_by_run=dict(),
sent=list(),
)
Outcome of one run: the AG-UI events and the sub-agent groups.
Attributes:
| Name | Type | Description |
|---|---|---|
events |
list[Any]
|
Every AG-UI event the run streamed, in order. |
groups |
dict[str, dict[str, Any]]
|
One group per sub-agent invocation of the thread so far,
keyed by its |
exchange |
HistoryExchange
|
The history carried in and out of the run. |
usage_by_run |
dict[str, dict[str, int]]
|
The run's token totals per run id, from |
sent |
list[Any]
|
The messages the client sent with the run. |
types ¶
types()
Return the AG-UI event types, in order.
Returns:
| Type | Description |
|---|---|
list[str]
|
Each event's type as a string, such as |
Source code in src/kaboo_workflows/testing/pipeline.py
80 81 82 83 84 85 86 | |
of_type ¶
of_type(agui_type)
Return the events of one AG-UI type.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
agui_type
|
EventType
|
The |
required |
Returns:
| Type | Description |
|---|---|
list[Any]
|
The matching events, in order. |
Source code in src/kaboo_workflows/testing/pipeline.py
88 89 90 91 92 93 94 95 96 97 | |
text ¶
text()
Return the chat reply the run streamed.
Returns:
| Type | Description |
|---|---|
str
|
Every |
str
|
concatenated; sub-agents' text belongs to their cards. |
Source code in src/kaboo_workflows/testing/pipeline.py
99 100 101 102 103 104 105 106 107 108 109 110 111 | |
finished ¶
finished()
Return whether the run reached RUN_FINISHED.
Returns:
| Type | Description |
|---|---|
bool
|
True when a |
Source code in src/kaboo_workflows/testing/pipeline.py
113 114 115 116 117 118 119 | |
errored ¶
errored()
Return whether the run ended in RUN_ERROR.
Returns:
| Type | Description |
|---|---|
bool
|
True when a |
Source code in src/kaboo_workflows/testing/pipeline.py
121 122 123 124 125 126 127 | |
run_outcome ¶
run_outcome()
Return the outcome carried by RUN_FINISHED.
Returns:
| Type | Description |
|---|---|
Any
|
The outcome, which holds the pending interrupts when the run |
Any
|
paused, or |
Source code in src/kaboo_workflows/testing/pipeline.py
129 130 131 132 133 134 135 136 137 138 | |
messages ¶
messages()
Return the transcript a client holds after the run.
The messages it sent, followed by the ones the run's text, tool-call
and tool-result events build, sub-agents' included. Pass it back as
messages= on the next turn, the way a client does.
Returns:
| Type | Description |
|---|---|
list[Any]
|
The messages, in order. |
Source code in src/kaboo_workflows/testing/pipeline.py
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 | |
state ¶
state()
Return the state the run left, as a host would persist it.
The last STATE_SNAPSHOT with every STATE_DELTA after it applied.
Pass it back as state= on the next turn to carry history and pending
interrupts forward, the way a client does.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The state, or an empty dict when none was streamed. |
Source code in src/kaboo_workflows/testing/pipeline.py
192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 | |
group_ids ¶
group_ids()
Return the sub-agent group ids.
Returns:
| Type | Description |
|---|---|
list[str]
|
The ids, sorted. |
Source code in src/kaboo_workflows/testing/pipeline.py
212 213 214 215 216 217 218 | |
agent_names ¶
agent_names()
Return the names of the sub-agents that ran.
Returns:
| Type | Description |
|---|---|
set[str]
|
The agent names across all groups. |
Source code in src/kaboo_workflows/testing/pipeline.py
220 221 222 223 224 225 226 | |
group ¶
group(group_id)
Return one sub-agent group.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
group_id
|
str
|
The group's id. |
required |
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The group as the UI would hold it. |
Raises:
| Type | Description |
|---|---|
KeyError
|
No group has that id. |
Source code in src/kaboo_workflows/testing/pipeline.py
228 229 230 231 232 233 234 235 236 237 238 239 240 | |
children_of ¶
children_of(parent)
Return the groups nested directly under parent.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
parent
|
str | None
|
A group id, or |
required |
Returns:
| Type | Description |
|---|---|
list[str]
|
The child group ids, sorted. |
Source code in src/kaboo_workflows/testing/pipeline.py
242 243 244 245 246 247 248 249 250 251 | |
ScriptedModel ¶
ScriptedModel(
model_id="scripted",
*,
script=None,
turns=None,
final_text="Done.",
stream_chunk=0,
stream_delay_ms=0,
**_,
)
Bases: Model
A strands model that replays a fixed script instead of calling a provider.
Initialize the scripted model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model_id
|
str
|
Reported as the model id; any value works. |
'scripted'
|
script
|
list[dict[str, Any]] | None
|
The steps to replay, one per model turn. See the module docstring for the step shapes. |
None
|
turns
|
list[list[dict[str, Any]]] | None
|
One script per human turn; the last repeats. Overrides
|
None
|
final_text
|
str
|
The reply once the script is exhausted. |
'Done.'
|
stream_chunk
|
int
|
Characters per streamed delta; 0 sends each text and each tool's arguments as one delta. |
0
|
stream_delay_ms
|
int
|
Pause between deltas, for watching a UI render. |
0
|
**_
|
Any
|
Extra model params from the config, accepted and ignored so a config written for a real provider still loads. |
{}
|
Source code in src/kaboo_workflows/testing/scripted_model.py
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 | |
update_config ¶
update_config(**model_config)
Merge model_config into the model's config.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
**model_config
|
Any
|
Config keys to set. |
{}
|
Source code in src/kaboo_workflows/testing/scripted_model.py
144 145 146 147 148 149 150 | |
get_config ¶
get_config()
Return the model's config.
Returns:
| Type | Description |
|---|---|
dict[str, Any]
|
The config dict, including |
Source code in src/kaboo_workflows/testing/scripted_model.py
152 153 154 155 156 157 158 | |
structured_output
async
¶
structured_output(output_model, prompt=None, **kwargs)
Yield a default instance of output_model.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_model
|
Any
|
The Pydantic model to instantiate. |
required |
prompt
|
Any
|
Ignored. |
None
|
**kwargs
|
Any
|
Ignored. |
{}
|
Yields:
| Type | Description |
|---|---|
AsyncIterator[dict[str, Any]]
|
One |
Source code in src/kaboo_workflows/testing/scripted_model.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 | |
stream
async
¶
stream(
messages, tool_specs=None, system_prompt=None, **kwargs
)
Replay the next script step as a strands model event stream.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
messages
|
Any
|
The conversation strands sends; recorded on |
required |
tool_specs
|
Any
|
The tools available this turn, used to resolve tool names and fill tool inputs. |
None
|
system_prompt
|
Any
|
Recorded on |
None
|
**kwargs
|
Any
|
Ignored. |
{}
|
Yields:
| Type | Description |
|---|---|
AsyncIterator[dict[str, Any]]
|
strands model stream events for one assistant message. |
Raises:
| Type | Description |
|---|---|
RuntimeError
|
The step is an |
ValueError
|
A tool step names a tool that is not available. |
Source code in src/kaboo_workflows/testing/scripted_model.py
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 | |
run_pipeline
async
¶
run_pipeline(
config,
message,
*,
thread_id="t1",
run_id="r1",
state=None,
)
Build a fresh pipeline, drive one turn, and close it.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
ConfigInput | list[ConfigInput]
|
A file path, a raw YAML string, or a list of either. |
required |
message
|
str
|
The user's message. |
required |
thread_id
|
str
|
The conversation id. |
't1'
|
run_id
|
str
|
The run's id. |
'r1'
|
state
|
dict[str, Any] | None
|
The client state to send. |
None
|
Returns:
| Type | Description |
|---|---|
TurnResult
|
The events and activity groups the run produced. |
Source code in src/kaboo_workflows/testing/pipeline.py
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 | |