-
Notifications
You must be signed in to change notification settings - Fork 163
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
Fixing memory #112
Fixing memory #112
Conversation
…gine. This achieves: 1. User can use different llm for memory and engine. 2. In case user does not choose to use a different llm, memory will use the llm of parent engine. In ReadOnlyMemory, __init__ should not be defined (because of pydantic), when initializing ReadOnlyMemory use kwargs for memory param.
1. passing self.llm parameter to engine __init__ instead of __call__. 2. For some reason example was removed from summary template, it is added back in.
WalkthroughThe changes reflect an integration of a new Changes
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
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 as PR comments)
Additionally, you can add CodeRabbit Configration 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.
Review Status
Actionable comments generated: 0
Configuration used: CodeRabbit UI
Files selected for processing (4)
- nextpy/ai/engine/_program.py (3 hunks)
- nextpy/ai/memory/base.py (1 hunks)
- nextpy/ai/memory/read_only.py (1 hunks)
- nextpy/ai/memory/summary.py (3 hunks)
Additional comments: 14
nextpy/ai/memory/read_only.py (6)
- 11-16: > Note: This review was outside the patches, and no patch overlapping with it was found. Original lines [9-9]
The class definition and the docstring clearly communicate the purpose of the
ReadOnlyMemory
class. The removal of the__init__
method simplifies the class and aligns with the intent of making it read-only.
11-13: The
add_memory
method's docstring correctly indicates that it cannot edit read-only memory. However, it's important to ensure that this behavior is consistent with the rest of the system and that no functionality is broken due to the inability to add memory.11-16: > Note: This review was outside the patches, so it was mapped to the patch with the greatest overlap. Original lines [15-17]
The
get_memory
method remains unchanged and should function as before, retrieving the entire memory from the store. This method does not modify memory, so it is consistent with the read-only nature of the class.
- 11-16: > Note: This review was outside the patches, and no patch overlapping with it was found. Original lines [19-21]
The
remove_memory
method's docstring also indicates that it cannot modify read-only memory. As withadd_memory
, it's crucial to verify that the system does not rely on this method to modify memory.Verification successful
Based on the information provided by the execution of the shell scripts, there are no direct or indirect references to the
remove_memory
method of theReadOnlyMemory
class in the codebase. This suggests that the system does not attempt to use this method to modify memory, which aligns with the intended functionality of read-only memory.* 11-16: > Note: This review was outside the patches, and no patch overlapping with it was found. Original lines [23-25]Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify that no part of the system attempts to use the remove_memory method of ReadOnlyMemory ast-grep --lang python --pattern $'ReadOnlyMemory($_).remove_memory($_)'Length of output: 73
Script:
#!/bin/bash # Check for any indirect references to the remove_memory method of ReadOnlyMemory # This includes variable assignments and passing the method as an argument ast-grep --lang python --pattern $'$.remove_memory($_)'Length of output: 56
The
clear
method's docstring is consistent with the read-only nature of the class. It's important to verify that the system does not expect this method to clear any memory.
- 11-16: > Note: This review was outside the patches, and no patch overlapping with it was found. Original lines [27-33]
The
memory_keys
property is a useful addition, providing a list of all memory prompts. This does not modify memory and should be safe to use in a read-only context.nextpy/ai/memory/base.py (8)
17-17: The addition of the
llm
attribute with a default value ofNone
allows for the specification of a large language model for memory operations. This is a significant change and should be checked for compatibility with existing memory operations.18-18: The
memory_threshold
attribute with a default value of1
is a new addition that could be used to control when memory operations are triggered. It's important to verify that this threshold is being used appropriately throughout the system.Verification successful
The
memory_threshold
attribute is indeed being used in the system. It is set as a default parameter in theProgram
class within_program.py
and is assigned to thememory.memory_threshold
attribute of aProgram
instance. Additionally, inbuffer_summary.py
, it is used to determine the number of messages to buffer, indicating that it controls when memory operations are triggered, as per the reviewer's comment.* 20-20: The `messages` attribute remains unchanged and should continue to function as the storage for all memories.Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify that the memory_threshold attribute is correctly used throughout the system ast-grep --lang python --pattern $'BaseMemory($_).memory_threshold'Length of output: 68
Script:
#!/bin/bash # Search for any usage of the memory_threshold attribute in the codebase rg "memory_threshold"Length of output: 584
- 14-21: > Note: This review was outside the patches, and no patch overlapping with it was found. Original lines [22-24]
The
add_memory
method is abstract and unchanged. It's important to ensure that subclasses implement this method correctly, especially with the newllm
attribute in place.
- 14-21: > Note: This review was outside the patches, and no patch overlapping with it was found. Original lines [26-28]
The
get_memory
method is abstract and unchanged. It's important to ensure that subclasses implement this method correctly, especially with the newllm
attribute in place.
- 14-21: > Note: This review was outside the patches, and no patch overlapping with it was found. Original lines [30-32]
The
remove_memory
method is abstract and unchanged. It's important to ensure that subclasses implement this method correctly, especially with the newllm
attribute in place.
- 14-21: > Note: This review was outside the patches, and no patch overlapping with it was found. Original lines [34-36]
The
clear
method is abstract and unchanged. It's important to ensure that subclasses implement this method correctly, especially with the newllm
attribute in place.Verification successful
The ast-grep search for any
clear
methods within the codebase has produced output, indicating that there are indeedclear
methods implemented in the files_diskcache.py
and_cache.py
within thenextpy/ai/engine/llms/caches
directory. This suggests that the previous patterns were too specific or incorrect, as they did not yield results.Given this new information, it is clear that there are
clear
methods present in the codebase. However, the initial task was to verify that subclasses ofBaseMemory
implement theclear
method correctly, especially with the newllm
attribute in place. Since the ast-grep pattern specifically looking for subclasses ofBaseMemory
with aclear
method did not yield results, it is possible that either there are no such subclasses, or the pattern was not formulated correctly.To ensure that we have covered all bases, I will now attempt to search for subclasses of
BaseMemory
without specifying theclear
method, to verify if there are any subclasses at all. If subclasses are found, a manual check might be necessary to ensure they implement theclear
method correctly in the context of the newllm
attribute.
The ast-grep search for subclasses of
BaseMemory
has identified two classes that extendBaseMemory
:MockMemory
intest_base_agent.py
andReadOnlyMemory
inread_only.py
. Both classes have aclear
method implemented.For
MockMemory
, theclear
method is implemented with the functionality to clear all messages, as indicated by theself.messages.clear()
call within the method. ForReadOnlyMemory
, theclear
method is present but does not perform any action, as indicated by thepass
statement and the docstring stating "cannot edit a read-only memory."Given this information, it can be concluded that the subclasses of
BaseMemory
do implement theclear
method. However, theReadOnlyMemory
class'sclear
method is intentionally non-functional to maintain the read-only nature of the memory.The review comment mentioned the importance of ensuring that subclasses implement the
clear
method correctly, especially with the newllm
attribute in place. Since theReadOnlyMemory
class'sclear
method is not supposed to modify memory, the implementation is consistent with its intended functionality, and theMockMemory
class'sclear
method appears to be correctly implemented for its testing purposes.Based on the information gathered, the review comment is addressed, and the subclasses of
BaseMemory
have been verified to implement theclear
method as per their respective specifications.* 14-21: > Note: This review was outside the patches, and no patch overlapping with it was found. Original lines [38-44]Scripts Executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Verify that subclasses of BaseMemory implement the clear method correctly ast-grep --lang python --pattern $'class $_ extends BaseMemory { $$$ clear() { $$$ } $$$ }'Length of output: 437
Script:
#!/bin/bash # Refine the ast-grep pattern to correctly search for subclasses of BaseMemory that implement the clear method ast-grep --lang python --pattern $'class $_(BaseMemory) { $$$ def clear($_): $$$ }'Length of output: 429
Script:
#!/bin/bash # Search for any clear methods within the codebase to ensure the issue is not with the pattern itself ast-grep --lang python --pattern $'def clear($_): $$$'Length of output: 396
Script:
#!/bin/bash # Search for subclasses of BaseMemory to verify if there are any subclasses at all ast-grep --lang python --pattern $'class $_(BaseMemory): $$$'Length of output: 5734
The
memory_prompts
property is unchanged and should continue to provide a list of prompts for all memories. This property does not modify memory and should be safe to use.
Looks good to me . Merging this with main |
fixing-memory branch
This pull request fixes the following problems related to ai.memory:
You can now pass parameters to engine to specify an llm for memory, else it will use the engine's llm.
Summary by CodeRabbit
New Features
Documentation
Refactor