4
4
import os
5
5
import textwrap
6
6
import unittest .mock
7
- from unittest .mock import call
8
7
9
8
import pytest
10
9
from pydantic import BaseModel
14
13
from strands .agent import AgentResult
15
14
from strands .agent .conversation_manager .null_conversation_manager import NullConversationManager
16
15
from strands .agent .conversation_manager .sliding_window_conversation_manager import SlidingWindowConversationManager
17
- from strands .experimental .hooks import AgentInitializedEvent , EndRequestEvent , StartRequestEvent
18
16
from strands .handlers .callback_handler import PrintingCallbackHandler , null_callback_handler
19
17
from strands .models .bedrock import DEFAULT_BEDROCK_MODEL_ID , BedrockModel
20
18
from strands .types .content import Messages
21
19
from strands .types .exceptions import ContextWindowOverflowException , EventLoopException
22
- from tests .fixtures .mock_hook_provider import MockHookProvider
23
20
24
21
25
22
@pytest .fixture
@@ -162,11 +159,6 @@ def tools(request, tool):
162
159
return request .param if hasattr (request , "param" ) else [tool_decorated ]
163
160
164
161
165
- @pytest .fixture
166
- def hook_provider ():
167
- return MockHookProvider ([AgentInitializedEvent , StartRequestEvent , EndRequestEvent ])
168
-
169
-
170
162
@pytest .fixture
171
163
def agent (
172
164
mock_model ,
@@ -178,7 +170,6 @@ def agent(
178
170
tool_registry ,
179
171
tool_decorated ,
180
172
request ,
181
- hook_provider ,
182
173
):
183
174
agent = Agent (
184
175
model = mock_model ,
@@ -188,9 +179,6 @@ def agent(
188
179
tools = tools ,
189
180
)
190
181
191
- # for now, hooks are private
192
- agent ._hooks .add_hook (hook_provider )
193
-
194
182
# Only register the tool directly if tools wasn't parameterized
195
183
if not hasattr (request , "param" ) or request .param is None :
196
184
# Create a new function tool directly from the decorated function
@@ -720,48 +708,6 @@ def test_agent__call__callback(mock_model, agent, callback_handler):
720
708
)
721
709
722
710
723
- @unittest .mock .patch ("strands.experimental.hooks.registry.HookRegistry.invoke_callbacks" )
724
- def test_agent_hooks__init__ (mock_invoke_callbacks ):
725
- """Verify that the AgentInitializedEvent is emitted on Agent construction."""
726
- agent = Agent ()
727
-
728
- # Verify AgentInitialized event was invoked
729
- mock_invoke_callbacks .assert_called_once ()
730
- assert mock_invoke_callbacks .call_args == call (AgentInitializedEvent (agent = agent ))
731
-
732
-
733
- def test_agent_hooks__call__ (agent , mock_hook_messages , hook_provider ):
734
- """Verify that the correct hook events are emitted as part of __call__."""
735
-
736
- agent ("test message" )
737
-
738
- assert hook_provider .events_received == [StartRequestEvent (agent = agent ), EndRequestEvent (agent = agent )]
739
-
740
-
741
- @pytest .mark .asyncio
742
- async def test_agent_hooks_stream_async (agent , mock_hook_messages , hook_provider ):
743
- """Verify that the correct hook events are emitted as part of stream_async."""
744
- iterator = agent .stream_async ("test message" )
745
- await anext (iterator )
746
- assert hook_provider .events_received == [StartRequestEvent (agent = agent )]
747
-
748
- # iterate the rest
749
- async for _ in iterator :
750
- pass
751
-
752
- assert hook_provider .events_received == [StartRequestEvent (agent = agent ), EndRequestEvent (agent = agent )]
753
-
754
-
755
- def test_agent_hooks_structured_output (agent , mock_hook_messages , hook_provider ):
756
- """Verify that the correct hook events are emitted as part of structured_output."""
757
-
758
- expected_user = User (name = "Jane Doe" , age = 30 , email = "jane@doe.com" )
759
- agent .model .structured_output = unittest .mock .Mock (return_value = [{"output" : expected_user }])
760
- agent .structured_output (User , "example prompt" )
761
-
762
- assert hook_provider .events_received == [StartRequestEvent (agent = agent ), EndRequestEvent (agent = agent )]
763
-
764
-
765
711
def test_agent_tool (mock_randint , agent ):
766
712
conversation_manager_spy = unittest .mock .Mock (wraps = agent .conversation_manager )
767
713
agent .conversation_manager = conversation_manager_spy
0 commit comments