-
Notifications
You must be signed in to change notification settings - Fork 5.2k
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
[Draft, Feedback Needed] Memory in AgentChat #4438
Draft
victordibia
wants to merge
6
commits into
main
Choose a base branch
from
agentchat_memory_vd
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from 2 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
48d7ecb
initial base memroy impl
victordibia f70f61e
update, add example with chromadb
victordibia 24fa684
include mimetype consideration
victordibia 9e94ec8
Merge remote-tracking branch 'origin/main' into agentchat_memory_vd
victordibia 0b7469e
add transform method
victordibia 138ee05
update to address feedback, will update after 4681 is merged
victordibia File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
101 changes: 101 additions & 0 deletions
101
python/packages/autogen-agentchat/src/autogen_agentchat/memory/_base_memory.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
from datetime import datetime | ||
from typing import Any, Dict, List, Protocol, Union, runtime_checkable | ||
|
||
from autogen_core.base import CancellationToken | ||
from autogen_core.components import Image | ||
from pydantic import BaseModel, ConfigDict, Field | ||
|
||
|
||
class BaseMemoryConfig(BaseModel): | ||
"""Base configuration for memory implementations.""" | ||
|
||
k: int = Field(default=5, description="Number of results to return") | ||
score_threshold: float | None = Field(default=None, description="Minimum relevance score") | ||
context_format: str = Field( | ||
default="Context {i}: {content} (score: {score:.2f})\n Use this information to address relevant tasks.", | ||
description="Format string for memory results in prompt", | ||
) | ||
|
||
model_config = ConfigDict(arbitrary_types_allowed=True) | ||
|
||
|
||
class MemoryEntry(BaseModel): | ||
"""A memory entry containing content and metadata.""" | ||
|
||
content: Union[str, List[Union[str, Image]]] | ||
colombod marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"""The content of the memory entry - can be text or multimodal.""" | ||
|
||
metadata: Dict[str, Any] = Field(default_factory=dict) | ||
"""Optional metadata associated with the memory entry.""" | ||
|
||
timestamp: datetime = Field(default_factory=datetime.now) | ||
"""When the memory was created.""" | ||
|
||
source: str | None = None | ||
"""Optional source identifier for the memory.""" | ||
|
||
model_config = ConfigDict(arbitrary_types_allowed=True) | ||
|
||
|
||
class MemoryQueryResult(BaseModel): | ||
"""Result from a memory query including the entry and its relevance score.""" | ||
|
||
entry: MemoryEntry | ||
"""The memory entry.""" | ||
|
||
score: float | ||
"""Relevance score for this result. Higher means more relevant.""" | ||
|
||
model_config = ConfigDict(arbitrary_types_allowed=True) | ||
|
||
|
||
@runtime_checkable | ||
class Memory(Protocol): | ||
"""Protocol defining the interface for memory implementations.""" | ||
|
||
@property | ||
def name(self) -> str | None: | ||
"""The name of this memory implementation.""" | ||
... | ||
|
||
@property | ||
def config(self) -> BaseMemoryConfig: | ||
"""The configuration for this memory implementation.""" | ||
... | ||
|
||
async def query( | ||
self, | ||
query: Union[str, Image, List[Union[str, Image]]], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. query also could benefit of mimetypes |
||
cancellation_token: CancellationToken | None = None, | ||
**kwargs: Any, | ||
) -> List[MemoryQueryResult]: | ||
""" | ||
Query the memory store and return relevant entries. | ||
|
||
Args: | ||
query: Text, image or multimodal query | ||
cancellation_token: Optional token to cancel operation | ||
**kwargs: Additional implementation-specific parameters | ||
|
||
Returns: | ||
List of memory entries with relevance scores | ||
""" | ||
... | ||
|
||
async def add(self, entry: MemoryEntry, cancellation_token: CancellationToken | None = None) -> None: | ||
""" | ||
Add a new entry to memory. | ||
|
||
Args: | ||
entry: The memory entry to add | ||
cancellation_token: Optional token to cancel operation | ||
""" | ||
... | ||
|
||
async def clear(self) -> None: | ||
"""Clear all entries from memory.""" | ||
... | ||
|
||
async def cleanup(self) -> None: | ||
"""Clean up any resources used by the memory implementation.""" | ||
... |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 guess this is saying that the default memory implementation is RAG with the last message.
I feel that using the last message for the RAG is reasonable but restrictive, could we just pass messages and have the memory query decide?
A high level comment that I'm not sure whether to call this memory or datastore/database.
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.
@husseinmozannar , I agree about passing the entire context and let the query method decide.
I am flexible on naming.
I like Memory because it connotes "just in time" retrieval/recall of content relevant to a step (in a task) an agent is about to take. Memory also gives a sense of what is stored inside the memory - in this case it really should be content relevant to task completion (not just anything that can be in a database).