-
-
Notifications
You must be signed in to change notification settings - Fork 717
feat: implement memory agents with session summaries, agentic management, and enhanced references #978
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
base: main
Are you sure you want to change the base?
Conversation
…ent, and references - Add session summary configuration with auto-summarization every N turns - Implement agentic memory management with auto-classification and confidence thresholds - Add memory references with inline/footnote/metadata formatting options - Create MemoryTools class with remember(), update_memory(), forget(), search_memories() - Maintain full backward compatibility with existing memory functionality - Add comprehensive test suites for all new features Resolves #969 🤖 Generated with [Claude Code](https://claude.ai/code) Co-authored-by: Mervin Praison <[email protected]>
Warning Rate limit exceeded@MervinPraison has exceeded the limit for the number of commits or files that can be reviewed per hour. Please wait 2 minutes and 52 seconds before requesting another review. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. 📒 Files selected for processing (5)
✨ Finishing Touches
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
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.
Summary of Changes
Hello @MervinPraison, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request significantly enhances the memory capabilities of the PraisonAI agents by introducing advanced features for managing conversational context, intelligently storing and retrieving information, and providing traceable references. The changes are designed to be opt-in and fully backward compatible, allowing for a seamless upgrade path while empowering agents with more sophisticated memory management.
Highlights
- Session Summaries: Implemented automatic conversation summarization, allowing the system to generate LLM-based summaries every N turns and include session context in agent responses. This enhances the agent's ability to maintain conversational coherence over time.
- Agentic Memory Management: Introduced autonomous memory importance analysis using an LLM, enabling agents to perform intelligent CRUD operations (remember, update, forget, search) on their long-term memory. This includes auto-classification of information importance to prioritize critical facts.
- Memory References: Added support for structured reference metadata with confidence scores, allowing for multiple reference formats (inline, footnote, metadata). This provides enhanced search capabilities by linking responses directly to their source memories.
- Agent Tooling and Integration: Created a dedicated
MemoryTools
class andget_memory_tools
function to expose these new memory functionalities as callable tools for agents, ensuring seamless integration with the existing agent system. New comprehensive test suites have also been added to validate these features and ensure backward compatibility.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command>
or @gemini-code-assist <command>
. Below is a summary of the supported commands.
Feature | Command | Description |
---|---|---|
Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/
folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
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.
Code Review
This pull request introduces session summaries, agentic memory management, and memory references. The code is well-organized and includes tests. The review highlights a critical issue regarding potential data loss when updating memories, and an opportunity to improve test file maintainability.
c.execute( | ||
"UPDATE long_mem SET content = ?, meta = ? WHERE id = ?", | ||
(new_fact, json.dumps({"updated": True, "updated_at": time.time()}), memory_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.
The UPDATE
statement overwrites the existing metadata. This will cause any pre-existing metadata associated with the memory entry to be lost. To prevent this data loss, fetch the existing metadata, update it, and then write it back.
# First, fetch existing metadata
c.execute("SELECT meta FROM long_mem WHERE id = ?", (memory_id,))
row = c.fetchone()
if not row:
return False # Or handle as an error
existing_meta = json.loads(row[0] or '{}')
existing_meta.update({"updated": True, "updated_at": time.time()})
# Then, update the record with the merged metadata
c.execute(
"UPDATE long_mem SET content = ?, meta = ? WHERE id = ?",
(new_fact, json.dumps(existing_meta), memory_id)
)
|
||
self.chroma_col.add( | ||
documents=[new_fact], | ||
metadatas=[{"updated": True, "updated_at": time.time()}], |
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.
Similar to the SQLite update, the metadata for the ChromaDB entry is being overwritten here. When you delete and re-add the document, preserve the original metadata and merge it with the update information to avoid data loss.
# get existing metadata
existing_metadata = self.chroma_col.get(ids=[memory_id], include=["metadatas"])
if existing_metadata and existing_metadata['metadatas']:
# Merge existing metadata with new metadata
updated_metadata = existing_metadata['metadatas'][0]
updated_metadata.update({"updated": True, "updated_at": time.time()})
else:
updated_metadata = {"updated": True, "updated_at": time.time()}
self.chroma_col.add(
documents=[new_fact],
metadatas=[updated_metadata],
ids=[memory_id],
embeddings=[embedding]
)
|
||
# Create an agent with memory tools | ||
memory = Memory(memory_config, verbose=5) | ||
from praisonaiagents.memory.tools import get_memory_tools |
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 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.
Bug: Undefined Variable in Conditional Logic
A NameError
occurs in the remember()
method when agentic memory is enabled but auto-classification is disabled. The importance_score
variable is referenced in the metadata update but is only assigned when self.auto_classify
is True
, causing it to be undefined when self.auto_classify
is False
.
src/praisonai-agents/praisonaiagents/memory/memory.py#L1268-L1292
PraisonAI/src/praisonai-agents/praisonaiagents/memory/memory.py
Lines 1268 to 1292 in 2c5a455
# ------------------------------------------------------------------------- | |
def remember(self, fact: str, metadata: Optional[Dict[str, Any]] = None) -> bool: | |
"""Store important information with agentic classification""" | |
if not self.agentic_enabled: | |
# Fallback to regular long-term storage | |
self.store_long_term(fact, metadata=metadata) | |
return True | |
# Auto-classify the importance if enabled | |
if self.auto_classify: | |
importance_score = self._classify_importance(fact) | |
if importance_score < self.confidence_threshold: | |
self._log_verbose(f"Fact importance {importance_score} below threshold {self.confidence_threshold}") | |
return False | |
# Store with agentic metadata | |
agentic_metadata = metadata or {} | |
agentic_metadata.update({ | |
"stored_by": "agentic_memory", | |
"importance_score": importance_score if self.auto_classify else 1.0, | |
"auto_classified": self.auto_classify | |
}) | |
self.store_long_term(fact, metadata=agentic_metadata) | |
return True |
Bug: Metadata Loss and Data Inconsistency
The update_memory
method has two issues:
- It incorrectly replaces all existing metadata with only update flags in both the SQLite database and ChromaDB, leading to the loss of original metadata (e.g., quality, importance scores).
- In ChromaDB, if embedding generation fails after a memory is deleted for an update, the memory is not re-added, causing data inconsistency where the record exists in SQLite but is missing from the vector store.
src/praisonai-agents/praisonaiagents/memory/memory.py#L1299-L1329
PraisonAI/src/praisonai-agents/praisonaiagents/memory/memory.py
Lines 1299 to 1329 in 2c5a455
c = conn.cursor() | |
c.execute( | |
"UPDATE long_mem SET content = ?, meta = ? WHERE id = ?", | |
(new_fact, json.dumps({"updated": True, "updated_at": time.time()}), memory_id) | |
) | |
updated = c.rowcount > 0 | |
conn.commit() | |
conn.close() | |
# Update in vector store if available | |
if self.use_rag and hasattr(self, "chroma_col"): | |
try: | |
# ChromaDB doesn't support direct updates, so we delete and re-add | |
self.chroma_col.delete(ids=[memory_id]) | |
if LITELLM_AVAILABLE: | |
import litellm | |
response = litellm.embedding( | |
model=self.embedding_model, | |
input=new_fact | |
) | |
embedding = response.data[0]["embedding"] | |
elif OPENAI_AVAILABLE: | |
from openai import OpenAI | |
client = OpenAI() | |
response = client.embeddings.create( | |
input=new_fact, | |
model=self.embedding_model | |
) | |
embedding = response.data[0].embedding | |
else: | |
return updated |
BugBot free trial expires on July 22, 2025
Learn more in the Cursor dashboard.
Was this report helpful? Give feedback by reacting with 👍 or 👎
@claude review this pull request and do a detailed analysis and fix this if the existing code doesn't have the solution implemented. Making sure it has backward compatibility, no existing features removed. After making those changes, again review the applied changes. Use @web to search if you dont know any information or to find the latest documentation or to find the latest version. Run the code if you think you need to run it to test it. Minimal code change to start with if required any changes. |
Claude encountered an error —— View job I'll analyze this and get back to you. |
Implements all three proposed memory agents features from issue #969:
Features Implemented
Session Summaries
Agentic Memory Management
Memory References
Backward Compatibility
Closes #969
Generated with Claude Code