state
strands_teams.display.state ¶
Mutable display state and phase/discovery models for event rendering.
This module provides the runtime state a consumer accumulates while an agent run streams: active/completed tool calls, phase progression, discovery events, and dispatched-team status. All types are domain-agnostic — phase identity and names come from an injected :class:~strands_teams.phases.PhaseSpec, and discovery-event kinds are plain strings supplied by the use case.
DiscoveryEvent ¶
Bases: FrozenModel
A notable discovery made during a run.
kind is a free-form string tag supplied by the use case's discovery extractor (e.g. "files_discovered"); the framework imposes no enum.
PhaseState ¶
Bases: StrictModel
Mutable runtime state for a single run phase.
The phase index and name/description are resolved against the injected :class:~strands_teams.phases.PhaseSpec when the phase is entered.
TeamDispatchState ¶
Bases: StrictModel
State for a dispatched specialist team.
Attributes:
| Name | Type | Description |
|---|---|---|
team_id | str | Unique identifier for the team (e.g., "security", "architecture"). |
mandate | str | One-line description of the team's investigation focus. |
agent_count | int | Number of agents in the team swarm. |
status | str | Current status ("running", "done", "error"). |
started_at | float | None | Monotonic timestamp when the team was dispatched. |
duration_seconds | float | Total elapsed seconds (set when completed). |
ToolCallState ¶
Bases: StrictModel
State for a single tool call.
Attributes:
| Name | Type | Description |
|---|---|---|
tool_call_id | str | Unique identifier for the tool call. |
tool_name | str | Name of the tool being executed. |
agent_name | str | Name of the agent that invoked this tool. |
args_buffer | str | Accumulated tool arguments (streaming). |
result | Any | Tool execution result (when complete). |
status | str | Current status ("running", "completed", "error"). |
AgentDisplayState ¶
Bases: StrictModel
Mutable state for agent display rendering.
This class tracks all state needed to render an agent's progress in a terminal or UI. It accumulates streaming text, tracks active and completed tool calls, phase progression, discoveries, dispatched teams, and error state. Phase identity is resolved against the injected phase_spec.
Attributes:
| Name | Type | Description |
|---|---|---|
phase_spec | PhaseSpec | Injected phase specification (names, count, tool map). |
current_phase | str | Description of the current phase. |
text_buffer | str | Accumulated streaming text from the agent. |
active_message_id | str | None | ID of currently streaming message. |
active_tool | ToolCallState | None | Currently executing tool state (if any). |
completed_tools | list[ToolCallState] | List of completed tool executions. |
state_snapshot | dict[str, Any] | Latest state snapshot from the agent. |
error | str | None | Error message if the run failed. |
completed | bool | Whether the run has finished. |
thread_id | str | None | Current thread identifier. |
run_id | str | None | Current run identifier. |
Example
state = AgentDisplayState(phase_spec=my_spec) state.text_buffer += "Analyzing repository..."
clear_text_buffer ¶
Clear and return the text buffer.
Returns:
| Type | Description |
|---|---|
str | The text buffer contents before clearing. |
complete_active_tool ¶
Mark the active tool as completed and move to history.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
result | Any | Optional result to store with the tool call. | None |
Source code in packages/strands-teams/src/strands_teams/display/state.py
record_tool ¶
Record a tool call's start or completion for the dashboard.
Called by ToolDisplayHook on both the before- and after-tool-call events. A running status opens a new active tool (and advances the phase resolved from the tool name); any other status closes it and moves it to history, counting errors.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_id | str | The tool-use identifier from the event. | required |
tool_name | str | Name of the tool being executed. | required |
status | str |
| required |
result | str | Truncated result string to store when closing the call. | required |
Source code in packages/strands-teams/src/strands_teams/display/state.py
get_recent_tools ¶
Get the most recent completed tools.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
count | int | Maximum number of tools to return. | 5 |
Returns:
| Type | Description |
|---|---|
list[ToolCallState] | List of recently completed tool states. |
Source code in packages/strands-teams/src/strands_teams/display/state.py
get_tool_stats ¶
Get tool call counts grouped by prefix.
Groups tools by their name prefix (e.g., lsp_*, git_*) for display in the TUI dashboard.
Returns:
| Type | Description |
|---|---|
dict[str, int] | Dictionary mapping tool prefixes to call counts. |
Source code in packages/strands-teams/src/strands_teams/display/state.py
get_elapsed_seconds ¶
Get elapsed time since the run started.
Returns:
| Type | Description |
|---|---|
float | Elapsed seconds, or 0.0 if not started. |
Source code in packages/strands-teams/src/strands_teams/display/state.py
get_tool_elapsed_seconds ¶
Get elapsed time for the current tool.
Returns:
| Type | Description |
|---|---|
float | Elapsed seconds for the active tool, or 0.0 if no active tool. |
Source code in packages/strands-teams/src/strands_teams/display/state.py
get_success_count ¶
Get count of successful tool calls.
Returns:
| Type | Description |
|---|---|
int | Number of completed tools minus errors. |
advance_phase ¶
Advance to a new phase if it is higher than the current one.
Phase name and description are resolved from the injected phase_spec.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
phase | int | 1-based phase index to advance to. | required |
Source code in packages/strands-teams/src/strands_teams/display/state.py
add_discovery ¶
Add a discovery event, evicting oldest if at capacity.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
event | DiscoveryEvent | DiscoveryEvent to add. | required |
Source code in packages/strands-teams/src/strands_teams/display/state.py
start_team ¶
Register a newly dispatched team.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
team_id | str | Unique team identifier. | required |
mandate | str | One-line description of the team's focus. | required |
agent_count | int | Number of agents in the team. | 0 |
Source code in packages/strands-teams/src/strands_teams/display/state.py
complete_team ¶
Mark a team as completed.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
team_id | str | Team identifier to mark complete. | required |
status | str | Final status ("done" or "error"). | 'done' |
Source code in packages/strands-teams/src/strands_teams/display/state.py
reset ¶
Reset state for a new run (preserves the injected phase_spec).