Index
strands_teams.display ¶
Parameterized Rich TUI display for agent team runs.
The display core is domain-agnostic: panel title, mode label, phase spec (count + names), and discovery-extractor callable are all injected. Nothing here hardcodes a product name, a phase total, or codebase-specific tool keys.
EventConsumer ¶
Bases: ABC
Protocol for consuming agent streaming events.
Implement this interface to create custom event consumers for different output formats (Rich terminal, JSON, web UI, etc.).
Events follow a lifecycle: run starts -> messages/tools -> run finishes.
Example
class LoggingConsumer(EventConsumer): ... async def on_run_started(self, thread_id: str, run_id: str) -> None: ... print(f"Run started: {run_id}")
on_run_started abstractmethod async ¶
Handle run started event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thread_id | str | Unique identifier for the conversation thread. | required |
run_id | str | Unique identifier for this agent run. | required |
Source code in packages/strands-teams/src/strands_teams/display/base.py
on_text_start abstractmethod async ¶
Handle start of a text message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message_id | str | Unique identifier for the message. | required |
role | str | Message role (usually "assistant"). | required |
Source code in packages/strands-teams/src/strands_teams/display/base.py
on_text_content abstractmethod async ¶
Handle streaming text content.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message_id | str | Identifier of the message being streamed. | required |
delta | str | New text chunk to append. | required |
Source code in packages/strands-teams/src/strands_teams/display/base.py
on_text_end abstractmethod async ¶
Handle end of a text message.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message_id | str | Identifier of the completed message. | required |
on_tool_start abstractmethod async ¶
Handle start of tool execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_call_id | str | Unique identifier for this tool call. | required |
tool_name | str | Name of the tool being called. | required |
Source code in packages/strands-teams/src/strands_teams/display/base.py
on_tool_args abstractmethod async ¶
Handle streaming tool arguments.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_call_id | str | Identifier of the tool call. | required |
args_delta | str | JSON string chunk of tool arguments. | required |
Source code in packages/strands-teams/src/strands_teams/display/base.py
on_tool_result abstractmethod async ¶
Handle tool execution result.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_call_id | str | Identifier of the completed tool call. | required |
result | Any | Result returned by the tool. | required |
Source code in packages/strands-teams/src/strands_teams/display/base.py
on_tool_end abstractmethod async ¶
Handle end of tool execution.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
tool_call_id | str | Identifier of the completed tool call. | required |
on_state_snapshot abstractmethod async ¶
Handle state snapshot event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
snapshot | dict[str, Any] | Complete state snapshot dictionary. | required |
on_run_finished abstractmethod async ¶
Handle run finished event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
thread_id | str | Identifier of the conversation thread. | required |
run_id | str | Identifier of the completed run. | required |
Source code in packages/strands-teams/src/strands_teams/display/base.py
on_error abstractmethod async ¶
Handle error event.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
message | str | Error message description. | required |
code | str | None | Optional error code. | None |
start async ¶
Initialize the consumer (optional).
Override to perform setup before events start streaming. Called before the first event is received.
stop async ¶
Cleanup the consumer (optional).
Override to perform cleanup after events stop streaming. Called after the last event is received or on error.
QuietConsumer ¶
Bases: EventConsumer
Silent consumer that only writes errors to stderr.
Initialize quiet consumer.
Source code in packages/strands-teams/src/strands_teams/display/rich.py
start async ¶
Initialize the consumer (optional).
Override to perform setup before events start streaming. Called before the first event is received.
stop async ¶
Cleanup the consumer (optional).
Override to perform cleanup after events stop streaming. Called after the last event is received or on error.
on_run_started async ¶
on_text_start async ¶
on_text_content async ¶
on_text_end async ¶
on_tool_start async ¶
on_tool_args async ¶
on_tool_result async ¶
on_tool_end async ¶
on_state_snapshot async ¶
on_run_finished async ¶
on_error async ¶
Print error to stderr.
RichEventConsumer ¶
Bases: EventConsumer
Dashboard-style consumer for agent execution.
Shows a fixed-height panel with: - Timer and progress bar - Tool category breakdown with mini bars - Active tool with spinner - Recent tool history with timing and status - Phase indicator [i/N] where N comes from the injected phase spec - Discovery feed populated by the injected extractor
No streaming text display. The agent's reasoning is not shown — only tool execution status matters for a long-running analysis agent.
When teams have been dispatched the coordinator layout is rendered (adding a team-status table); otherwise the single-agent layout is used.
Initialize the dashboard consumer.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
state | AgentDisplayState | Display state carrying the injected phase spec. | required |
title | str | Panel title (replaces the hardcoded product name). | required |
mode_label | str | None | Optional badge appended to the title (e.g. | None |
discovery_extractor | Callable[[str, Any], DiscoveryEvent | None] | None | Callable mapping | None |
console | Console | None | Optional Rich Console instance. | None |
Source code in packages/strands-teams/src/strands_teams/display/rich.py
start async ¶
Start the dashboard display.
Source code in packages/strands-teams/src/strands_teams/display/rich.py
stop async ¶
Stop the dashboard and print final summary.
Source code in packages/strands-teams/src/strands_teams/display/rich.py
on_run_started async ¶
Handle run started.
on_text_start async ¶
on_text_content async ¶
Handle text delta — silently accumulate (not displayed).
on_text_end async ¶
Handle text end — increment turn counter.
on_tool_start async ¶
Handle tool start — show in active spinner.
Source code in packages/strands-teams/src/strands_teams/display/rich.py
on_tool_args async ¶
Handle tool args — silently accumulate.
Source code in packages/strands-teams/src/strands_teams/display/rich.py
on_tool_result async ¶
Handle tool result — check for errors and extract discoveries.
Source code in packages/strands-teams/src/strands_teams/display/rich.py
on_tool_end async ¶
Handle tool end — move to completed list.
Source code in packages/strands-teams/src/strands_teams/display/rich.py
on_state_snapshot async ¶
Handle state snapshot.
on_run_finished async ¶
on_error async ¶
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).
Source code in packages/strands-teams/src/strands_teams/display/state.py
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"). |
bind_live_renderable ¶
Point Rich Live's auto-refresh at a custom display builder.
Rich calls get_renderable() on each refresh tick. Replacing it with builder lets the dashboard show fresh state (timer, tool elapsed, etc.) without manually calling live.update() on every change.