|
8 | 8 | from agno.memory.v2.db.sqlite import SqliteMemoryDb
|
9 | 9 | from agno.memory.v2.memory import Memory
|
10 | 10 | from agno.models.anthropic.claude import Claude
|
| 11 | +from agno.models.google.gemini import Gemini |
11 | 12 | from agno.models.openai.chat import OpenAIChat
|
12 | 13 | from agno.storage.sqlite import SqliteStorage
|
13 | 14 | from agno.team.team import Team
|
@@ -77,6 +78,36 @@ def route_team(team_storage, memory):
|
77 | 78 | )
|
78 | 79 |
|
79 | 80 |
|
| 81 | +@pytest.fixture |
| 82 | +def route_team_with_members(team_storage, agent_storage, memory): |
| 83 | + """Create a route team with storage and memory for testing.""" |
| 84 | + |
| 85 | + def get_weather(city: str) -> str: |
| 86 | + return f"The weather in {city} is sunny." |
| 87 | + |
| 88 | + def get_open_restaurants(city: str) -> str: |
| 89 | + return f"The open restaurants in {city} are: {', '.join(['Restaurant 1', 'Restaurant 2', 'Restaurant 3'])}" |
| 90 | + |
| 91 | + travel_agent = Agent( |
| 92 | + name="Travel Agent", |
| 93 | + model=Gemini(id="gemini-2.0-flash-001"), |
| 94 | + storage=agent_storage, |
| 95 | + memory=memory, |
| 96 | + add_history_to_messages=True, |
| 97 | + role="Search the web for travel information. Don't call multiple tools at once. First get weather, then restaurants.", |
| 98 | + tools=[get_weather, get_open_restaurants], |
| 99 | + ) |
| 100 | + return Team( |
| 101 | + name="Route Team", |
| 102 | + mode="route", |
| 103 | + model=Gemini(id="gemini-2.0-flash-001"), |
| 104 | + members=[travel_agent], |
| 105 | + storage=team_storage, |
| 106 | + memory=memory, |
| 107 | + instructions="Route a single question to the travel agent. Don't make multiple requests.", |
| 108 | + enable_user_memories=True, |
| 109 | + ) |
| 110 | + |
80 | 111 | @pytest.mark.asyncio
|
81 | 112 | async def test_run_history_persistence(route_team, team_storage, memory):
|
82 | 113 | """Test that all runs within a session are persisted in storage."""
|
@@ -142,6 +173,57 @@ async def test_run_session_summary(route_team, team_storage, memory):
|
142 | 173 | assert len(team_session.memory["summaries"][user_id][session_id]) > 0
|
143 | 174 |
|
144 | 175 |
|
| 176 | +@pytest.mark.asyncio |
| 177 | +async def test_member_run_history_persistence(route_team_with_members, agent_storage, memory): |
| 178 | + """Test that all runs within a member's session are persisted in storage.""" |
| 179 | + |
| 180 | + session_id = "session_123" |
| 181 | + |
| 182 | + # Clear memory for this specific test case |
| 183 | + memory.clear() |
| 184 | + |
| 185 | + # First request |
| 186 | + await route_team_with_members.arun("I'm traveling to Tokyo, what is the weather and open restaurants?", user_id=user_id, session_id=session_id) |
| 187 | + |
| 188 | + agent_session = agent_storage.read(session_id=session_id) |
| 189 | + |
| 190 | + stored_memory_data = agent_session.memory |
| 191 | + assert stored_memory_data is not None, "Memory data not found in stored session." |
| 192 | + |
| 193 | + agent_runs = stored_memory_data["runs"] |
| 194 | + |
| 195 | + assert len(agent_runs[-1]["messages"]) == 7, "Only system message, user message, two tool calls (and results), and response" |
| 196 | + |
| 197 | + first_user_message_content = agent_runs[0]["messages"][1]["content"] |
| 198 | + assert "I'm traveling to Tokyo, what is the weather and open restaurants?" in first_user_message_content |
| 199 | + |
| 200 | + # Second request |
| 201 | + await route_team_with_members.arun("I'm traveling to Munich, what is the weather and open restaurants?", user_id=user_id, session_id=session_id) |
| 202 | + |
| 203 | + agent_session = agent_storage.read(session_id=session_id) |
| 204 | + |
| 205 | + stored_memory_data = agent_session.memory |
| 206 | + assert stored_memory_data is not None, "Memory data not found in stored session." |
| 207 | + |
| 208 | + agent_runs = stored_memory_data["runs"] |
| 209 | + |
| 210 | + assert len(agent_runs[-1]["messages"]) == 13, "Full history of messages" |
| 211 | + |
| 212 | + # Third request (to the member directly) |
| 213 | + await route_team_with_members.members[0].arun("Write me a report about all the places I have requested information about", user_id=user_id, session_id=session_id) |
| 214 | + |
| 215 | + agent_session = agent_storage.read(session_id=session_id) |
| 216 | + |
| 217 | + stored_memory_data = agent_session.memory |
| 218 | + assert stored_memory_data is not None, "Memory data not found in stored session." |
| 219 | + |
| 220 | + agent_runs = stored_memory_data["runs"] |
| 221 | + |
| 222 | + assert len(agent_runs[-1]["messages"]) == 15, "Full history of messages" |
| 223 | + |
| 224 | + |
| 225 | + |
| 226 | + |
145 | 227 | @pytest.mark.asyncio
|
146 | 228 | async def test_multi_user_multi_session_route_team(route_team, team_storage, memory):
|
147 | 229 | """Test multi-user multi-session route team with storage and memory."""
|
|
0 commit comments