griptape
griptape copied to clipboard
feat: persist summary in conversation memory
- [x] I have read and agree to the contributing guidelines.
Overrode after_add_run method to add summary in metadata so it can persist.
#1590
I used this code to test it. I ran it one time as it is and second time after commenting the agent.run and found that I was able to load the runs but not summaries.
import os
from griptape.drivers.prompt.google import GooglePromptDriver
from griptape.memory.structure import SummaryConversationMemory
from griptape.structures import Agent
from griptape.drivers.memory.conversation.redis import RedisConversationMemoryDriver
prompt_driver = GooglePromptDriver(model="gemini-2.0-flash", api_key=os.environ["GOOGLE_API_KEY"])
redis_conversation_driver = RedisConversationMemoryDriver(
host=os.environ["REDIS_HOST"],
username=os.environ["REDIS_USERNAME"],
port=int(os.environ["REDIS_PORT"]),
password=os.environ["REDIS_PASSWORD"],
index=os.environ["REDIS_INDEX"],
conversation_id='torab_test',
)
conversation_memory = SummaryConversationMemory(
offset=2,
conversation_memory_driver=redis_conversation_driver,
prompt_driver=prompt_driver
)
agent = Agent(
conversation_memory=conversation_memory,
prompt_driver=prompt_driver
)
agent.run("My name is Torab?")
agent.run("I am trying to resolve summary conversation issue.")
agent.run("What am I doing?")
print('conversation: ', conversation_memory.to_dict())
print('conversation summary: ', conversation_memory.summary)
I did not update the TestSummaryConversationMemory since it does not uses persistent memory.
Thanks @torabshaikh! Could you please share a reproducible code snippet that uses LocalConversationMemoryDriver with a persist_file? That will make it easy for me to verify whether things are working as expected.
Codecov Report
:white_check_mark: All modified and coverable lines are covered by tests.
:loudspeaker: Thoughts on this report? Let us know!
Thanks for the review. As I understand this, It will be something like this, right?
def after_add_run(self) -> None:
self.meta["summary"] = self.summary
self.meta["summary_index"] = self.summary_index
super().after_add_run()
def load_runs(self) -> list[Run]:
runs, meta = self.conversation_memory_driver.load()
self.runs.extend(runs)
self.meta = dict_merge(self.meta, meta)
self.summary = meta['summary']
self.summary_index = meta['summary_index']
return self.runs
We could have called super().load_runs() when overriding load_runs but we can't do it since it returns only self.runs. Right?
@torabshaikh looks like tests are failing. You can run make test/unit locally to see why.
Yeah. I was able to replicate the issue locally. I will update the PR.
@collindutter I debugged this and found out that metadata was not getting initialized properly.
@torabshaikh thanks for the continued updates. Could you please some unit tests to cover this new behavior? Then I think we can consider this done.
Hi @collindutter, Sorry for the late response. I had been busy. I added some test cases to track this behavior and to test the full run.