goal_runner
strands_teams.goal_runner ¶
Durable lead-controller runner run_goal (spec 006, User Story 5).
A NEW runner alongside :func:strands_teams.runner.run_teams (never a replacement — plan §4 Phase 5 bullet 2; AC-5-1). run_goal drives the ASTR durable lead loop (ASTR §9.2)::
decompose → compose → assign → dispatch → integrate → replan
Each stage runs as a :class:~strands_teams.durable.DurableStep on the in-process :class:~strands_teams.durable.AsyncioDurableEngine, so every transition is recorded as a :class:~strands_teams.models.TeamEvent on the run's :class:~strands_teams.events.EventLog and the whole loop is replayable (AC-5-3). The loop:
- Propagates
goal_id/task_id/thread_idand the run's :class:~strands_teams.layout.TeamsLayoutto dispatched teams throughinvocation_state— a plain in-process dict passed by reference, treated read-only inside concurrently-executing node tools (AC-5-4;research-coding-runtimes.yamllines 19-22, 29-30). No module-level globals. - Dispatches through an injectable dispatch callable defaulting to the native
Swarm:func:~strands_teams.teams.dispatch_teamtool (AC-5-5), so tests can substitute a stub and run with no Bedrock call (AC-7-4). - Re-enters decompose (replan) whenever :func:
~strands_teams.events.should_replanfires, recording a replan event first (AC-5-7). - Terminates with a terminal status on convergence, on reaching
max_lead_iterations, or on crossing the budget threshold — never looping indefinitely (AC-5-6).
It issues no live model / Bedrock call itself: dispatch is the only model-touching stage and it is injected. run_goal never calls asyncio.run; :func:run_goal_sync is the sync boundary, mirroring :func:~strands_teams.runner.run_teams_sync (AC-5-2).
LEAD_STAGES module-attribute ¶
The ordered per-iteration lead-loop stages (AC-5-3).
GoalResult ¶
Bases: FrozenModel
The terminal outcome of a :func:run_goal run (AC-5-6).
Attributes:
| Name | Type | Description |
|---|---|---|
goal_id | str | The goal this run drove. |
status | str | Terminal status — |
iterations | int | How many lead-loop iterations executed. |
replans | int | How many times the loop re-entered decompose via |
event_log_path | str | The path the run's :class: |
transitions | list[str] | The ordered |
run_goal async ¶
run_goal(
goal,
*,
layout,
invocation_state=None,
dispatch=None,
engine=None,
max_iterations=8,
budget_threshold=0.0,
goal_id=None,
thread_id="",
)
Drive the durable lead loop for goal to a terminal status (AC-5-1, AC-5-3..AC-5-7).
Runs decompose → compose → assign → dispatch → integrate each iteration, each as a :class:~strands_teams.durable.DurableStep recording a :class:~strands_teams.models.TeamEvent (AC-5-3). After integrate it consults :func:~strands_teams.events.should_replan over the run's :class:EventLog; when a trigger fires it records a goal.replan event and re-enters decompose (AC-5-7). Terminates — with a final goal.terminated event — on convergence (no replan), on reaching max_iterations, or on crossing budget_threshold (AC-5-6). Never calls asyncio.run (AC-5-2 is the sync boundary).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
goal | str | The goal statement driving the loop. | required |
layout | TeamsLayout | The run's :class: | required |
invocation_state | dict[str, Any] | None | The by-reference dict propagated to dispatched teams; | None |
dispatch | Callable[[dict[str, Any], dict[str, Any]], Awaitable[dict[str, Any]]] | None | Injectable dispatch callable (AC-5-5); defaults to :func: | None |
engine | DurableStep | None | The :class: | None |
max_iterations | int | Hard cap on lead-loop iterations (AC-5-6). | 8 |
budget_threshold | float | Cumulative-cost bound; crossing it terminates the loop and fires the budget replan trigger (AC-5-6, AC-6-4). | 0.0 |
goal_id | str | None | Stable id for the goal (auto-assigned when omitted). | None |
thread_id | str | Optional conversation/thread id propagated to teams. | '' |
Returns:
| Name | Type | Description |
|---|---|---|
A | GoalResult | class: |
Source code in packages/strands-teams/src/strands_teams/goal_runner.py
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 | |
run_goal_sync ¶
run_goal_sync(
goal,
*,
layout,
invocation_state=None,
dispatch=None,
engine=None,
max_iterations=8,
budget_threshold=0.0,
goal_id=None,
thread_id="",
)
Synchronous wrapper around :func:run_goal (AC-5-2).
Mirrors :func:~strands_teams.runner.run_teams_sync: the single asyncio.run boundary. Never call this from inside an already-running event loop — use the async :func:run_goal there (research-coding-runtimes.yaml line 18).