11import pytest
22
33from strands import Agent , tool
4+ from strands .experimental .hooks import AfterModelInvocationEvent , BeforeModelInvocationEvent
5+ from strands .hooks import AfterInvocationEvent , AgentInitializedEvent , BeforeInvocationEvent , MessageAddedEvent
46from strands .multiagent .graph import GraphBuilder
57from strands .types .content import ContentBlock
8+ from tests .fixtures .mock_hook_provider import MockHookProvider
69
710
811@tool
@@ -18,49 +21,59 @@ def multiply_numbers(x: int, y: int) -> int:
1821
1922
2023@pytest .fixture
21- def math_agent ():
24+ def hook_provider ():
25+ return MockHookProvider ("all" )
26+
27+
28+ @pytest .fixture
29+ def math_agent (hook_provider ):
2230 """Create an agent specialized in mathematical operations."""
2331 return Agent (
2432 model = "us.amazon.nova-pro-v1:0" ,
2533 system_prompt = "You are a mathematical assistant. Always provide clear, step-by-step calculations." ,
34+ hooks = [hook_provider ],
2635 tools = [calculate_sum , multiply_numbers ],
2736 )
2837
2938
3039@pytest .fixture
31- def analysis_agent ():
40+ def analysis_agent (hook_provider ):
3241 """Create an agent specialized in data analysis."""
3342 return Agent (
3443 model = "us.amazon.nova-pro-v1:0" ,
44+ hooks = [hook_provider ],
3545 system_prompt = "You are a data analysis expert. Provide insights and interpretations of numerical results." ,
3646 )
3747
3848
3949@pytest .fixture
40- def summary_agent ():
50+ def summary_agent (hook_provider ):
4151 """Create an agent specialized in summarization."""
4252 return Agent (
4353 model = "us.amazon.nova-lite-v1:0" ,
54+ hooks = [hook_provider ],
4455 system_prompt = "You are a summarization expert. Create concise, clear summaries of complex information." ,
4556 )
4657
4758
4859@pytest .fixture
49- def validation_agent ():
60+ def validation_agent (hook_provider ):
5061 """Create an agent specialized in validation."""
5162 return Agent (
5263 model = "us.amazon.nova-pro-v1:0" ,
64+ hooks = [hook_provider ],
5365 system_prompt = "You are a validation expert. Check results for accuracy and completeness." ,
5466 )
5567
5668
5769@pytest .fixture
58- def image_analysis_agent ():
70+ def image_analysis_agent (hook_provider ):
5971 """Create an agent specialized in image analysis."""
6072 return Agent (
73+ hooks = [hook_provider ],
6174 system_prompt = (
6275 "You are an image analysis expert. Describe what you see in images and provide detailed analysis."
63- )
76+ ),
6477 )
6578
6679
@@ -149,7 +162,7 @@ def proceed_to_second_summary(state):
149162
150163
151164@pytest .mark .asyncio
152- async def test_graph_execution_with_image (image_analysis_agent , summary_agent , yellow_img ):
165+ async def test_graph_execution_with_image (image_analysis_agent , summary_agent , yellow_img , hook_provider ):
153166 """Test graph execution with multi-modal image input."""
154167 builder = GraphBuilder ()
155168
@@ -186,3 +199,16 @@ async def test_graph_execution_with_image(image_analysis_agent, summary_agent, y
186199 # Verify both nodes completed
187200 assert "image_analyzer" in result .results
188201 assert "summarizer" in result .results
202+
203+ expected_hook_events = [
204+ AgentInitializedEvent ,
205+ BeforeInvocationEvent ,
206+ MessageAddedEvent ,
207+ BeforeModelInvocationEvent ,
208+ AfterModelInvocationEvent ,
209+ MessageAddedEvent ,
210+ AfterInvocationEvent ,
211+ ]
212+
213+ assert hook_provider .extract_for (image_analysis_agent ).event_types_received == expected_hook_events
214+ assert hook_provider .extract_for (summary_agent ).event_types_received == expected_hook_events
0 commit comments