Skip to content

Commit e95ef5d

Browse files
dirkbrndLockeysama
authored andcommitted
Fix loading of sessions if no run has occurred (agno-agi#3084)
## Summary If a run has not yet happened, then the session in memory would not exist, but it could still exist in the DB. This avoids the agent failing. Fixes agno-agi#3078 ## Type of change - [x] Bug fix - [ ] New feature - [ ] Breaking change - [ ] Improvement - [ ] Model update - [ ] Other: --- ## Checklist - [ ] Code complies with style guidelines - [ ] Ran format/validation scripts (`./scripts/format.sh` and `./scripts/validate.sh`) - [ ] Self-review completed - [ ] Documentation updated (comments, docstrings) - [ ] Examples and guides: Relevant cookbook examples have been included or updated (if applicable) - [ ] Tested in clean environment - [ ] Tests added/updated (if applicable) --- ## Additional Notes Add any important context (deployment instructions, screenshots, security considerations, etc.)
1 parent 04dbb85 commit e95ef5d

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

libs/agno/agno/agent/agent.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2261,7 +2261,7 @@ def get_agent_session(self, session_id: str, user_id: Optional[str] = None) -> A
22612261
else:
22622262
self.memory = cast(Memory, self.memory)
22632263
# We fake the structure on storage, to maintain the interface with the legacy implementation
2264-
run_responses = self.memory.runs[session_id] # type: ignore
2264+
run_responses = self.memory.runs.get(session_id, []) # type: ignore
22652265
memory_dict = self.memory.to_dict()
22662266
memory_dict["runs"] = [rr.to_dict() for rr in run_responses]
22672267
else:

libs/agno/agno/team/team.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ def _run(
909909
self._make_memories_and_summaries(run_messages, session_id, user_id)
910910

911911
session_messages: List[Message] = []
912-
for run in self.memory.runs[session_id]: # type: ignore
912+
for run in self.memory.runs.get(session_id, []): # type: ignore
913913
if run.messages is not None:
914914
for m in run.messages:
915915
session_messages.append(m)
@@ -1270,7 +1270,7 @@ def _run_stream(
12701270
self._make_memories_and_summaries(run_messages, session_id, user_id)
12711271

12721272
session_messages: List[Message] = []
1273-
for run in self.memory.runs[session_id]: # type: ignore
1273+
for run in self.memory.runs.get(session_id, []): # type: ignore
12741274
if run.messages is not None:
12751275
for m in run.messages:
12761276
session_messages.append(m)
@@ -1699,7 +1699,7 @@ async def _amake_memories_and_summaries(run_messages: RunMessages, session_id: s
16991699
)
17001700

17011701
session_messages: List[Message] = []
1702-
for run in self.memory.runs[session_id]:
1702+
for run in self.memory.runs.get(session_id, []):
17031703
for m in run.messages:
17041704
session_messages.append(m)
17051705

@@ -2078,7 +2078,7 @@ async def _amake_memories_and_summaries(run_messages: RunMessages, session_id: s
20782078
)
20792079

20802080
session_messages: List[Message] = []
2081-
for run in self.memory.runs[session_id]: # type: ignore
2081+
for run in self.memory.runs.get(session_id, []): # type: ignore
20822082
if run.messages is not None:
20832083
for m in run.messages:
20842084
session_messages.append(m)

0 commit comments

Comments
 (0)