Skip to content

Commit a86b921

Browse files
committed
update
1 parent 4093658 commit a86b921

File tree

1 file changed

+85
-85
lines changed

1 file changed

+85
-85
lines changed

libs/agno/tests/integration/agent/test_agent_with_storage_and_memory.py

Lines changed: 85 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -27,91 +27,91 @@ def memory_agent(agent_storage, memory):
2727
)
2828

2929

30-
# def test_agent_session_state(chat_agent, agent_storage):
31-
# session_id = "session_1"
32-
33-
# chat_agent.session_id = session_id
34-
# chat_agent.session_name = "my_test_session"
35-
# chat_agent.session_state = {"test_key": "test_value"}
36-
# chat_agent.team_session_state = {"team_test_key": "team_test_value"}
37-
38-
# response = chat_agent.run("Hello, how are you?")
39-
# assert response.run_id is not None
40-
# assert chat_agent.session_id == session_id
41-
# assert chat_agent.session_name == "my_test_session"
42-
# assert chat_agent.session_state == {"current_session_id": session_id, "test_key": "test_value"}
43-
# assert chat_agent.team_session_state == {"team_test_key": "team_test_value"}
44-
# session_from_storage = agent_storage.read(session_id=session_id)
45-
# assert session_from_storage is not None
46-
# assert session_from_storage.session_id == session_id
47-
# assert session_from_storage.session_data["session_name"] == "my_test_session"
48-
# assert session_from_storage.session_data["session_state"] == {
49-
# "current_session_id": session_id,
50-
# "test_key": "test_value",
51-
# }
52-
53-
# # Run again with the same session ID
54-
# response = chat_agent.run("What can you do?", session_id=session_id)
55-
# assert response.run_id is not None
56-
# assert chat_agent.session_id == session_id
57-
# assert chat_agent.session_name == "my_test_session"
58-
# assert chat_agent.session_state == {"current_session_id": session_id, "test_key": "test_value"}
59-
60-
# # Run with a different session ID
61-
# response = chat_agent.run("What can you do?", session_id="session_2")
62-
# assert response.run_id is not None
63-
# assert chat_agent.session_id == "session_2"
64-
# assert chat_agent.session_name is None
65-
# assert chat_agent.session_state == {"current_session_id": "session_2"}
66-
# assert chat_agent.team_session_state is None
67-
68-
# # Run again with original session ID
69-
# response = chat_agent.run("What name should I call you?", session_id=session_id)
70-
# assert response.run_id is not None
71-
# assert chat_agent.session_id == session_id
72-
# assert chat_agent.session_name == "my_test_session"
73-
# assert chat_agent.session_state == {"current_session_id": session_id, "test_key": "test_value"}
74-
75-
76-
# def test_agent_runs_in_memory(chat_agent):
77-
# session_id = "test_session"
78-
# response = chat_agent.run("Hello, how are you?", session_id=session_id)
79-
# assert response is not None
80-
# assert response.content is not None
81-
# assert response.run_id is not None
82-
83-
# assert len(chat_agent.memory.runs[session_id]) == 1
84-
# stored_run_response = chat_agent.memory.runs[session_id][0]
85-
# assert stored_run_response.run_id == response.run_id
86-
# assert len(stored_run_response.messages) == 2
87-
88-
# # Check that the run is also stored in the agent session
89-
# assert len(chat_agent.agent_session.memory["runs"]) == 1
90-
91-
92-
# def test_agent_runs_in_memory_legacy(chat_agent):
93-
# chat_agent.memory = AgentMemory()
94-
# session_id = "test_session"
95-
# response = chat_agent.run(
96-
# "What can you do?",
97-
# messages=[
98-
# Message(role="user", content="Hello, how are you?"),
99-
# Message(role="assistant", content="I'm good, thank you!"),
100-
# ],
101-
# session_id=session_id,
102-
# )
103-
# assert response is not None
104-
# assert response.content is not None
105-
# assert response.run_id is not None
106-
107-
# assert len(chat_agent.memory.runs) == 1
108-
# stored_agent_run = chat_agent.memory.runs[0]
109-
# assert stored_agent_run.response.run_id == response.run_id
110-
# assert len(stored_agent_run.response.messages) == 4
111-
# assert len(stored_agent_run.messages) == 2
112-
113-
# # Check that the run is also stored in the agent session
114-
# assert len(chat_agent.agent_session.memory["runs"]) == 1
30+
def test_agent_session_state(chat_agent, agent_storage):
31+
session_id = "session_1"
32+
33+
chat_agent.session_id = session_id
34+
chat_agent.session_name = "my_test_session"
35+
chat_agent.session_state = {"test_key": "test_value"}
36+
chat_agent.team_session_state = {"team_test_key": "team_test_value"}
37+
38+
response = chat_agent.run("Hello, how are you?")
39+
assert response.run_id is not None
40+
assert chat_agent.session_id == session_id
41+
assert chat_agent.session_name == "my_test_session"
42+
assert chat_agent.session_state == {"current_session_id": session_id, "test_key": "test_value"}
43+
assert chat_agent.team_session_state == {"team_test_key": "team_test_value"}
44+
session_from_storage = agent_storage.read(session_id=session_id)
45+
assert session_from_storage is not None
46+
assert session_from_storage.session_id == session_id
47+
assert session_from_storage.session_data["session_name"] == "my_test_session"
48+
assert session_from_storage.session_data["session_state"] == {
49+
"current_session_id": session_id,
50+
"test_key": "test_value",
51+
}
52+
53+
# Run again with the same session ID
54+
response = chat_agent.run("What can you do?", session_id=session_id)
55+
assert response.run_id is not None
56+
assert chat_agent.session_id == session_id
57+
assert chat_agent.session_name == "my_test_session"
58+
assert chat_agent.session_state == {"current_session_id": session_id, "test_key": "test_value"}
59+
60+
# Run with a different session ID
61+
response = chat_agent.run("What can you do?", session_id="session_2")
62+
assert response.run_id is not None
63+
assert chat_agent.session_id == "session_2"
64+
assert chat_agent.session_name is None
65+
assert chat_agent.session_state == {"current_session_id": "session_2"}
66+
assert chat_agent.team_session_state is None
67+
68+
# Run again with original session ID
69+
response = chat_agent.run("What name should I call you?", session_id=session_id)
70+
assert response.run_id is not None
71+
assert chat_agent.session_id == session_id
72+
assert chat_agent.session_name == "my_test_session"
73+
assert chat_agent.session_state == {"current_session_id": session_id, "test_key": "test_value"}
74+
75+
76+
def test_agent_runs_in_memory(chat_agent):
77+
session_id = "test_session"
78+
response = chat_agent.run("Hello, how are you?", session_id=session_id)
79+
assert response is not None
80+
assert response.content is not None
81+
assert response.run_id is not None
82+
83+
assert len(chat_agent.memory.runs[session_id]) == 1
84+
stored_run_response = chat_agent.memory.runs[session_id][0]
85+
assert stored_run_response.run_id == response.run_id
86+
assert len(stored_run_response.messages) == 2
87+
88+
# Check that the run is also stored in the agent session
89+
assert len(chat_agent.agent_session.memory["runs"]) == 1
90+
91+
92+
def test_agent_runs_in_memory_legacy(chat_agent):
93+
chat_agent.memory = AgentMemory()
94+
session_id = "test_session"
95+
response = chat_agent.run(
96+
"What can you do?",
97+
messages=[
98+
Message(role="user", content="Hello, how are you?"),
99+
Message(role="assistant", content="I'm good, thank you!"),
100+
],
101+
session_id=session_id,
102+
)
103+
assert response is not None
104+
assert response.content is not None
105+
assert response.run_id is not None
106+
107+
assert len(chat_agent.memory.runs) == 1
108+
stored_agent_run = chat_agent.memory.runs[0]
109+
assert stored_agent_run.response.run_id == response.run_id
110+
assert len(stored_agent_run.response.messages) == 4
111+
assert len(stored_agent_run.messages) == 2
112+
113+
# Check that the run is also stored in the agent session
114+
assert len(chat_agent.agent_session.memory["runs"]) == 1
115115

116116

117117
@pytest.mark.asyncio

0 commit comments

Comments
 (0)