@@ -64,51 +64,54 @@ def memory(memory_db):
6464
6565
6666@pytest .fixture
67- def web_agent ():
68- """Create a web agent for testing."""
69- from agno .tools .duckduckgo import DuckDuckGoTools
70-
71- return Agent (
72- name = "Web Agent" ,
73- model = OpenAIChat (id = "gpt-4o-mini" ),
74- role = "Search the web for information" ,
75- tools = [DuckDuckGoTools (cache_results = True )],
76- )
77-
78-
79- @pytest .fixture
80- def finance_agent ():
81- """Create a finance agent for testing."""
82- from agno .tools .yfinance import YFinanceTools
83-
84- return Agent (
85- name = "Finance Agent" ,
86- model = OpenAIChat (id = "gpt-4o-mini" ),
87- role = "Get financial data" ,
88- tools = [YFinanceTools (stock_price = True )],
89- )
90-
91-
92- @pytest .fixture
93- def analysis_agent ():
94- """Create an analysis agent for testing."""
95- return Agent (name = "Analysis Agent" , model = OpenAIChat (id = "gpt-4o-mini" ), role = "Analyze data and provide insights" )
96-
97-
98- @pytest .fixture
99- def route_team (web_agent , finance_agent , analysis_agent , team_storage , memory ):
67+ def route_team (team_storage , memory ):
10068 """Create a route team with storage and memory for testing."""
10169 return Team (
10270 name = "Route Team" ,
10371 mode = "route" ,
10472 model = OpenAIChat (id = "gpt-4o-mini" ),
105- members = [web_agent , finance_agent , analysis_agent ],
10673 storage = team_storage ,
10774 memory = memory ,
10875 enable_user_memories = True ,
10976 )
11077
78+ @pytest .mark .asyncio
79+ async def test_run_history_persistence (route_team , team_storage , memory ):
80+ """Test that all runs within a session are persisted in storage."""
81+ user_id = "john@example.com"
82+ session_id = "session_123"
83+ num_turns = 5
84+
85+ # Clear memory for this specific test case
86+ memory .clear ()
11187
88+ # Perform multiple turns
89+ conversation_messages = [
90+ "What's the weather like today?" ,
91+ "What about tomorrow?" ,
92+ "Any recommendations for indoor activities?" ,
93+ "Search for nearby museums." ,
94+ "Which one has the best reviews?" ,
95+ ]
96+
97+ assert len (conversation_messages ) == num_turns
98+
99+ for i , msg in enumerate (conversation_messages ):
100+ print (f"Turn { i + 1 } : { msg } " )
101+ await route_team .arun (msg , user_id = user_id , session_id = session_id )
102+
103+ # Verify the stored session data after all turns
104+ team_session = team_storage .read (session_id = session_id )
105+
106+ stored_memory_data = team_session .memory
107+ assert stored_memory_data is not None , "Memory data not found in stored session."
108+
109+ stored_runs = stored_memory_data ["runs" ]
110+ assert isinstance (stored_runs , list ), "Stored runs data is not a list."
111+
112+ first_user_message_content = stored_runs [0 ]["messages" ][1 ]["content" ]
113+ assert first_user_message_content == conversation_messages [0 ]
114+
112115@pytest .mark .asyncio
113116async def test_multi_user_multi_session_route_team (route_team , team_storage , memory ):
114117 """Test multi-user multi-session route team with storage and memory."""
0 commit comments