Skip to content
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

Fix Conversation Memory Autoload #1033

Closed
wants to merge 2 commits into from

Conversation

collindutter
Copy link
Member

@collindutter collindutter commented Jul 30, 2024

[x] I have read and agree to the contributing guidelines for submitting new pull requests.

Describe your changes

Refactors Conversation Memory to support using a Driver set in Structure Config. For instance:

from griptape.config import OpenAiStructureConfig
from griptape.structures import Agent
from griptape.memory.structure import ConversationMemory
from griptape.drivers import LocalConversationMemoryDriver

agent = Agent(
    config=OpenAiStructureConfig(
        conversation_memory_driver=LocalConversationMemoryDriver(),
    ),
    conversation_memory=ConversationMemory(),
)

agent.run("My name is Collin")
agent.run("What is my name")

Issue ticket number and link

NA


📚 Documentation preview 📚: https://griptape--1033.org.readthedocs.build//1033/

Copy link

codecov bot commented Jul 30, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

📢 Thoughts on this report? Let us know!

@collindutter collindutter marked this pull request as ready for review July 30, 2024 22:31
@collindutter collindutter requested a review from vachillo July 31, 2024 16:15
Comment on lines +33 to 40
def conversation_memory_driver(self) -> Optional[BaseConversationMemoryDriver]:
if self._conversation_memory_driver is None:
if hasattr(self, "structure"):
return self.structure.config.conversation_memory_driver
else:
return None
return self._conversation_memory_driver

Copy link
Member

Choose a reason for hiding this comment

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

should the strucuture just set the driver rather than setting the structure itself? also why the hasattr? should it just default to None?

Copy link
Member Author

Choose a reason for hiding this comment

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

This pattern is easier to apply to other areas of the framework (tasks) if the Structure sets itself.

init=False because we don't want users to set the Structure, it should only be done by the Structure itself.

@collindutter collindutter changed the title Conversation memory Fix Conversation Memory Autoload Aug 1, 2024
Copy link
Contributor

@dylanholmes dylanholmes left a comment

Choose a reason for hiding this comment

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

Love the bug fixes

Just one comment/question

Comment on lines +99 to +100
if self.conversation_memory.autoload:
self.conversation_memory.load()
Copy link
Contributor

Choose a reason for hiding this comment

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

Feels to me like this autoloading decision should be made from within the conversation memory class. Like either in the structure setter, or in another method called maybe preprocess (if we wanna be consistent with the way tasks are added to structures)

Also, won't load() get called twice? (Once in the __attrs_post_init__, when there is no structure, then once here after the structure is added) Is that ok?

@collindutter
Copy link
Member Author

Should be fixed by #1045

@collindutter collindutter deleted the fix/convesation-memory-autoload branch August 21, 2024 17:32
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.

3 participants