Skip to content

Commit 3127130

Browse files
revert: keep hooks param as list, not Sequence
Per @mkmeral's feedback: keep hooks as list[...] for devx simplicity. If users want explicit tuple/Sequence control, they can use add_hook(). Changes: - Revert Sequence -> list in hooks type hint - Revert docstring to not mention tuple support - Remove Sequence import (no longer needed) - Remove test_hooks_param_accepts_tuple test
1 parent abc819d commit 3127130

2 files changed

Lines changed: 3 additions & 17 deletions

File tree

src/strands/agent/agent.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import logging
1313
import threading
1414
import warnings
15-
from collections.abc import AsyncGenerator, AsyncIterator, Callable, Mapping, Sequence
15+
from collections.abc import AsyncGenerator, AsyncIterator, Callable, Mapping
1616
from typing import (
1717
TYPE_CHECKING,
1818
Any,
@@ -132,7 +132,7 @@ def __init__(
132132
description: str | None = None,
133133
state: AgentState | dict | None = None,
134134
plugins: list[Plugin] | None = None,
135-
hooks: Sequence[HookProvider | HookCallback] | None = None,
135+
hooks: list[HookProvider | HookCallback] | None = None,
136136
session_manager: SessionManager | None = None,
137137
structured_output_prompt: str | None = None,
138138
tool_executor: ToolExecutor | None = None,
@@ -187,8 +187,7 @@ def __init__(
187187
Plugins are initialized with the agent instance after construction and can register hooks,
188188
modify agent attributes, or perform other setup tasks.
189189
Defaults to None.
190-
hooks: Hooks to be added to the agent hook registry. Accepts any sequence
191-
(list, tuple) of HookProvider instances
190+
hooks: Hooks to be added to the agent hook registry. Accepts HookProvider instances
192191
or plain callable hook callbacks (functions with typed event parameters).
193192
Defaults to None.
194193
session_manager: Manager for handling agent sessions including conversation history and state.

tests/strands/agent/test_agent_hooks.py

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1054,19 +1054,6 @@ def my_callback(event: AgentInitializedEvent) -> None:
10541054
assert length == 1
10551055

10561056

1057-
def test_hooks_param_accepts_tuple():
1058-
"""Verify that a tuple of hooks can be passed (Sequence support)."""
1059-
events_received = []
1060-
1061-
def my_callback(event: AgentInitializedEvent) -> None:
1062-
events_received.append(event)
1063-
1064-
agent = Agent(hooks=(my_callback,), callback_handler=None)
1065-
1066-
assert len(events_received) == 1
1067-
assert events_received[0].agent is agent
1068-
1069-
10701057
def test_hooks_param_invalid_hook_raises_error():
10711058
"""Verify that passing an invalid hook raises ValueError."""
10721059
with pytest.raises(ValueError, match="Invalid hook"):

0 commit comments

Comments
 (0)