-
Notifications
You must be signed in to change notification settings - Fork 4.6k
refactor: memory #3816
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: memory #3816
Conversation
| if self.memory is None: | ||
| self.memory = Memory() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would this still be needed? Before this was the only source of runs, so it was needed, but now I don't think it is needed by default?
| self.db = db | ||
|
|
||
| # We are making memories | ||
| def __post_init__(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets rather only instantiate on runtime?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would be instantiated on runtime, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought post-init runs after the init? When you create the object
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry yes - though the post init is only valid for the cases where user sets a model on the Memory. So for most use cases, the logic that is inside the post init only occurs at runtime. I think this pattern works, wdyt?
| def read_from_db(self, user_id: Optional[str] = None): | ||
| if self.db: | ||
| # If no user_id is provided, read all memories | ||
| if user_id is None: | ||
| all_memories = self.db.get_user_memories() | ||
| else: | ||
| all_memories = self.db.get_user_memories(user_id=user_id) | ||
|
|
||
| # Reset the memories | ||
| self.memories = {} | ||
| memories = {} | ||
| for memory in all_memories: | ||
| if memory.user_id is not None and memory.id is not None: | ||
| self.memories.setdefault(memory.user_id, {})[memory.id] = UserMemory.from_dict(memory.memory) | ||
| if memory.user_id is not None and memory.memory_id is not None: | ||
| memories.setdefault(memory.user_id, {})[memory.memory_id] = memory.memory | ||
| return memories |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All uses of this method now pass user_id to filter by.
Do you think it's still useful to return a dictionary ({<user_id>: <memories>}) vs just a flat list? I think we will always have only one item in the dict
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There can be a provision to view all memories at once, right? I am thinking of a use case when the user wants to see all the Db level memories
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah... the flat list could handle that case and still make reads now simpler. But I don't think this is too important, we can keep it as is if you're happy!
|
|
||
| gen_session_name_prompt = "Conversation\n" | ||
| messages_for_generating_session_name = self.memory.get_messages_for_session(session_id=session_id) | ||
| messages_for_generating_session_name = self.agent_session.get_messages_for_session(session_id=session_id) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe not now but in a next iteration we should try and pass the session around as opposed to having it set on the agent. In an effort to make things stateless
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes that is interesting
libs/agno/agno/db/schemas/memory.py
Outdated
|
|
||
| class MemoryRow(BaseModel): | ||
| """Memory Row that is stored in the database""" | ||
| class SummaryRow(BaseModel): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe this can also get a better name now? Just SessionSummary?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed SummaryRow as it was not needed, we just use the SessionSummary object
| # Else read from the db | ||
| if self.memory is not None and self.memory.db is not None: | ||
| return self.memory.read_chat_history(session_id=self.session_id, session_type="agent") | ||
| if self.agent_session is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In the interest of removing state we might have to only do this on the DB object
…gi/agno into refactor/memory_update_10
…/memory_update_10
Summary
Refactor and cleanup of Memory, Agent and Team classes
(If applicable, issue number: #____)
Type of change
Checklist
./scripts/format.shand./scripts/validate.sh)Additional Notes
Add any important context (deployment instructions, screenshots, security considerations, etc.)