Skip to content

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

MervinPraison
Copy link
Owner

Implements all three proposed memory agents features from issue #969:

Features Implemented

  1. Session Summaries

    • Automatic conversation summarization every N turns
    • LLM-based summary generation with configurable model
    • Session context inclusion in agent responses
  2. Agentic Memory Management

    • Autonomous memory importance analysis using LLM
    • Agent-driven CRUD operations (remember, update, forget, search)
    • Auto-classification of information importance
  3. Memory References

    • Structured reference metadata with confidence scores
    • Multiple reference formats (inline, footnote, metadata)
    • Enhanced search with reference tracking

Backward Compatibility

  • All existing memory functionality preserved
  • New features are opt-in through configuration
  • No breaking changes to current API
  • Seamless integration with existing agents

Closes #969

Generated with Claude Code

…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]>
Copy link
Contributor

coderabbitai bot commented Jul 17, 2025

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 @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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.

📥 Commits

Reviewing files that changed from the base of the PR and between 39fbb76 and 2c5a455.

📒 Files selected for processing (5)
  • src/praisonai-agents/praisonaiagents/memory/__init__.py (1 hunks)
  • src/praisonai-agents/praisonaiagents/memory/memory.py (2 hunks)
  • src/praisonai-agents/praisonaiagents/memory/tools.py (1 hunks)
  • src/praisonai-agents/test_memory_agents.py (1 hunks)
  • src/praisonai-agents/test_memory_basic.py (1 hunks)
✨ Finishing Touches
  • 📝 Generate Docstrings

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.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need 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)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 and get_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

  1. 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.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a 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.

Comment on lines +1300 to +1303
c.execute(
"UPDATE long_mem SET content = ?, meta = ? WHERE id = ?",
(new_fact, json.dumps({"updated": True, "updated_at": time.time()}), memory_id)
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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()}],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Imports should be at the top of the file to avoid circular dependency issues and improve readability.

from praisonaiagents.memory.tools import get_memory_tools

        agent = Agent(

Copy link

@cursor cursor bot left a 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

# -------------------------------------------------------------------------
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

Fix in CursorFix in Web


Bug: Metadata Loss and Data Inconsistency

The update_memory method has two issues:

  1. 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).
  2. 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

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

Fix in CursorFix in Web


BugBot free trial expires on July 22, 2025
Learn more in the Cursor dashboard.

Was this report helpful? Give feedback by reacting with 👍 or 👎

@MervinPraison
Copy link
Owner Author

@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.

Copy link
Contributor

github-actions bot commented Jul 17, 2025

Claude encountered an error —— View job


I'll analyze this and get back to you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

memory agents
1 participant