This tutorial introduces the Strands Agents Plugin abstraction. A plugin is a single Python class that bundles @hook-decorated lifecycle callbacks, @tool-decorated methods, and any plugin-resident state into one installable unit you attach to an agent via Agent(plugins=[...]). By the end you will know how to lift any existing HookProvider into a Plugin, how to expose hook-collected state as a tool the agent itself can call, how to reason about isolated vs. shared plugin instances, and how registration order drives middleware-style composition.
| Information | Details |
|---|---|
| Strands Features | Plugin, @hook, @tool, BeforeToolCallEvent, AfterToolCallEvent, BeforeModelCallEvent, AfterModelCallEvent, cancel_tool |
| Agent Pattern | Single agent with one or more attached plugins; multi-agent composition through registration order |
| Tools | Two small in-memory tools (get_weather, lookup_user) defined in Section 0; one @tool (get_audit_metrics) bundled inside MetricsPlugin |
| Model | Claude Haiku 4.5 on Amazon Bedrock (any Strands-supported model works) |
- Section 1 — Raw hooks → Plugin transition. The same two-event handler is implemented twice (once as a
HookProvider, once as aPlugin); a captured firing sequence proves the two are observably equivalent. - Section 2 —
@toolinside a plugin.MetricsPlugincollects per-tool call counts via hooks and exposes them through aget_audit_metricstool the agent can call. - Section 3 — Plugin state and sharing. Two agents with their own plugin instances stay isolated; two agents sharing one plugin instance accumulate combined state.
- Section 4 — Composing multiple plugins.
SecurityPlugin,LoggingPlugin, andMetricsPluginare stacked in two different orders, demonstrating that registration order drives execution order.
- Python 3.10 or later.
- An AWS account with Amazon Bedrock model access (Claude Haiku 4.5 by default; see the notebook for how to swap models).
- Basic familiarity with Strands Agents (Quickstart). We recommend completing
13-human-in-the-loopfirst for hooks fundamentals.
14-plugins/
├── README.md
├── requirements.txt
└── plugins-in-strands.ipynb
| File | Description |
|---|---|
| plugins-in-strands.ipynb | Single end-to-end notebook covering all four plugin concepts in five sections plus a recap. |
- Lift a
HookProviderinto aPluginwith@hook-decorated methods. - Bundle a
@toolinside a plugin so the agent can introspect plugin-collected state. - Reason about isolated vs. shared plugin instances across multiple agents.
- Compose multiple plugins and predict execution order from registration order.
pip install -r requirements.txtThen open plugins-in-strands.ipynb and run cells top-to-bottom.
13-human-in-the-loop— hooks fundamentals; this tutorial assumes you have seenHookProvider.15-skills—AgentSkillsis a real plugin you can install today; come back to this tutorial after that one to see howAgentSkillsis built.16-hooks-lifecycle— full event catalogue and writable fields.
- Build your own plugin that adds a system-prompt fragment plus an audit tool.
- Explore the multi-agent hook events (
BeforeNodeCallEvent,AfterNodeCallEvent) once you move toGraphorSwarmorchestration.