|
| 1 | +# Strands Agents Samples |
| 2 | + |
| 3 | +These samples demonstrate the [Temporal Strands plugin](https://github.com/temporalio/sdk-python/tree/main/temporalio/contrib/strands), which runs [Strands Agents](https://strandsagents.com/) inside Temporal Workflows. Model invocations, tool calls, and MCP tool calls all execute as Temporal Activities, so you get durable execution, Temporal-managed retries, and timeouts. |
| 4 | + |
| 5 | +## Samples |
| 6 | + |
| 7 | +| Sample | Description | |
| 8 | +|--------|-------------| |
| 9 | +| [hello_world](hello_world) | Minimal `TemporalAgent` invocation. Start here. | |
| 10 | +| [tools](tools) | Three tool patterns side by side: in-workflow `@tool`, custom `@activity.defn` wrapped via `activity_as_tool`, and a `strands_tools` tool wrapped as a Temporal activity. | |
| 11 | +| [human_in_the_loop](human_in_the_loop) | Pause a tool call on `BeforeToolCallEvent.interrupt()`, resume via Temporal signal. The canonical Strands HITL pattern. | |
| 12 | +| [tool_interrupt](tool_interrupt) | Raise `InterruptException` from a Temporal activity to surface a HITL prompt across the activity boundary. Plugin-specific feature. | |
| 13 | +| [hooks](hooks) | `HookProvider` with both an in-workflow callback and an `activity_as_hook` callback for I/O. | |
| 14 | +| [mcp](mcp) | Connect to an MCP server (`FastMCP` echo) via `TemporalMCPClient`. | |
| 15 | +| [structured_output](structured_output) | Pydantic-typed agent output via `structured_output_model`. | |
| 16 | +| [streaming](streaming) | Forward model chunks to an external subscriber via `streaming_topic` + `WorkflowStream`. | |
| 17 | +| [continue_as_new](continue_as_new) | Chat-style workflow that hands off `agent.messages` when history grows large. | |
| 18 | + |
| 19 | +## Prerequisites |
| 20 | + |
| 21 | +1. Install dependencies: |
| 22 | + |
| 23 | + ```bash |
| 24 | + uv sync --group strands |
| 25 | + ``` |
| 26 | + |
| 27 | + > The `strands` extra of `temporalio` is shipping in an upcoming release. Until then, install the SDK from the strands branch: |
| 28 | + > |
| 29 | + > ```bash |
| 30 | + > uv pip install -e ../sdk-python --extra strands --extra pydantic |
| 31 | + > ``` |
| 32 | +
|
| 33 | +2. Configure AWS credentials. The samples use the plugin's default `BedrockModel()`, which picks up the standard AWS SDK credential chain. Make sure the credentials grant access to a Bedrock model in your selected region (e.g., `us-west-2`). |
| 34 | +
|
| 35 | + ```bash |
| 36 | + export AWS_REGION=us-west-2 |
| 37 | + # plus AWS_ACCESS_KEY_ID / AWS_SECRET_ACCESS_KEY or an SSO profile |
| 38 | + ``` |
| 39 | +
|
| 40 | + You can pick a specific model by passing it to `BedrockModel(model_id="...")` in each sample's worker. |
| 41 | +
|
| 42 | +3. Start a [Temporal dev server](https://docs.temporal.io/cli#start-dev-server): |
| 43 | +
|
| 44 | + ```bash |
| 45 | + temporal server start-dev |
| 46 | + ``` |
| 47 | +
|
| 48 | +## Running a Sample |
| 49 | + |
| 50 | +Each sample has two scripts. Start the Worker first, then the Workflow starter in a separate terminal: |
| 51 | + |
| 52 | +```bash |
| 53 | +# Terminal 1: start the Worker |
| 54 | +uv run strands_plugin/<sample>/run_worker.py |
| 55 | + |
| 56 | +# Terminal 2: start the Workflow |
| 57 | +uv run strands_plugin/<sample>/run_workflow.py |
| 58 | +``` |
| 59 | + |
| 60 | +For example, to run the tools sample: |
| 61 | + |
| 62 | +```bash |
| 63 | +# Terminal 1 |
| 64 | +uv run strands_plugin/tools/run_worker.py |
| 65 | + |
| 66 | +# Terminal 2 |
| 67 | +uv run strands_plugin/tools/run_workflow.py |
| 68 | +``` |
| 69 | + |
| 70 | +## Key Features Demonstrated |
| 71 | + |
| 72 | +- **Durable model invocation** — every model call runs in an `invoke_model` activity with configurable timeouts and retries. |
| 73 | +- **Three ways to define tools** — pure Strands `@tool`, custom Temporal activities, and ecosystem `strands_tools` wrapped as activities. |
| 74 | +- **Human-in-the-loop** — both hook-based (`BeforeToolCallEvent.interrupt()`) and tool-body (`raise InterruptException`) styles. |
| 75 | +- **Hook system** — deterministic in-workflow callbacks plus I/O callbacks dispatched via `activity_as_hook`. |
| 76 | +- **MCP integration** — connect to MCP servers at worker startup; tool calls dispatched through per-server activities. |
| 77 | +- **Structured output** — Pydantic-typed agent results via the plugin's `pydantic_data_converter`. |
| 78 | +- **Streaming** — forward model chunks live to external subscribers. |
| 79 | +- **Long-lived chats** — hand off `agent.messages` via `continue-as-new` to stay under Temporal's history limit. |
| 80 | + |
| 81 | +## Related |
| 82 | + |
| 83 | +- [Temporal Strands plugin docs](https://github.com/temporalio/sdk-python/tree/main/temporalio/contrib/strands) |
| 84 | +- [Strands Agents](https://strandsagents.com/) |
0 commit comments