griptape-ai / griptape

Modular Python framework for AI agents and workflows with chain-of-thought reasoning, tools, and memory.
https://www.griptape.ai
Apache License 2.0
2.03k stars 171 forks source link

Document `Chat` and `Conversation` Utilities When Using Summary Conversation Memory #1217

Open shhlife opened 1 month ago

shhlife commented 1 month ago

Describe the bug It appears like SummaryConversationMemory is maintaining the entire thread of memory instead of summarizing it.

To Reproduce

from griptape.memory.structure import SummaryConversationMemory
from griptape.structures import Agent
from griptape.utils import Conversation

agent = Agent(
    conversation_memory=SummaryConversationMemory(offset=2, autoprune=True), stream=True
)

agent.run("Hi, I'm jason")
agent.run("I love bananas and trees")
agent.run("I left my heart in San Francisco")
agent.run("I'm quite fond of apples")
agent.run("I just love food in general")
# Chat(agent).start()

print(Conversation(agent.conversation_memory))

prints out

Q: Hi, I'm jason
A: Hello, Jason! How can I assist you today?
Q: I love bananas and trees
A: That's great to hear, Jason! Bananas are delicious and nutritious, and trees are essential for the environment. Do you have a favorite type of tree or a particular way you like to enjoy bananas?
Q: I left my heart in San Francisco
A: That's a beautiful sentiment, Jason! San Francisco is a city that captures the hearts of many with its iconic landmarks, vibrant culture, and stunning scenery. Do you have any special memories or favorite places in San Francisco that you'd like to share?
Q: I'm quite fond of apples
A: It sounds like you have a love for fruits! Apples are another fantastic choice—crisp, sweet, and versatile. Do you have a favorite variety of apple, or perhaps a favorite way to enjoy them, like in a pie or as a snack?
Q: I just love food in general
A: That's wonderful! Food can be such a delightful and diverse experience. Do you have any favorite cuisines or dishes that you particularly enjoy? Whether it's something savory, sweet, or a specific type of cuisine, I'd love to hear more about your food preferences!
Summary: Jason introduces himself, and the assistant responds by greeting him and asking how it can help. Jason mentions that he loves bananas and trees. The assistant responds by expressing enthusiasm about bananas and trees, noting their benefits, and asking Jason if he has a favorite type of tree or a particular way he likes to enjoy bananas. Jason then shares that he left his heart in San Francisco. The assistant responds by acknowledging the sentiment and asking if Jason has any special memories or favorite places in San Francisco that he'd like to share.

Expected behavior I would expect it to just have the last 2 Q/A entries, and the summary.

Screenshots If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

Additional context I also noticed that when using the Chat utility, it outputs the response AND the summary with each interaction.

collindutter commented 1 month ago

@shhlife ah I had misunderstood; the behavior you see with the Conversation utility is expected. It just prints out the full list of runs followed by a summary. The auto-pruning only happens when sending to the LLM since pruning will happen at different times for different LLMs.

That said, this output is concerning:

...
The human greeted the assistant with "hi," and the assistant responded with a friendly greeting and asked how they could help.

Does the LLM consistently reply with a summary as part of its response? I can't seem to reproduce it with:

from griptape.memory.structure import SummaryConversationMemory
from griptape.structures import Agent

agent = Agent(conversation_memory=SummaryConversationMemory(offset=2, autoprune=True), stream=True)

agent.run("Hi, I'm jason")
agent.run("I love bananas and trees")
agent.run("I left my heart in San Francisco")
agent.run("I'm quite fond of apples")
agent.run("I just love food in general")
[10/03/24 15:26:59] INFO     PromptTask a294ff22be244accb2ac0ad01784bc06
                             Input: Hi, I'm jason
                    INFO     PromptTask a294ff22be244accb2ac0ad01784bc06
                             Output: Hello Jason! How can I assist you today?
                    INFO     PromptTask a294ff22be244accb2ac0ad01784bc06
                             Input: I love bananas and trees
kk[10/03/24 15:27:02] INFO     PromptTask a294ff22be244accb2ac0ad01784bc06                                                                                                 
                             Output: That's great! Bananas are delicious and nutritious, and trees are vital for the environment. Do you have a favorite type of banana or
                             tree, or is there something specific you'd like to know or discuss about them?
                    INFO     PromptTask a294ff22be244accb2ac0ad01784bc06
                             Input: I left my heart in San Francisco
[10/03/24 15:27:03] INFO     PromptTask a294ff22be244accb2ac0ad01784bc06
                             Output: It sounds like San Francisco holds a special place in your heart! It's a beautiful city with its iconic Golden Gate Bridge, vibrant
                             culture, and diverse neighborhoods. Do you have any favorite memories or places in San Francisco that you'd like to share?
[10/03/24 15:27:04] INFO     PromptTask a294ff22be244accb2ac0ad01784bc06
                             Input: I'm quite fond of apples
                    INFO     PromptTask a294ff22be244accb2ac0ad01784bc06
                             Output: Apples are a fantastic choice! They're not only tasty but also packed with nutrients. Do you have a favorite variety of apple, like
                             Fuji, Granny Smith, or Honeycrisp? Or perhaps you enjoy them in a particular dish or recipe?
[10/03/24 15:27:05] INFO     PromptTask a294ff22be244accb2ac0ad01784bc06
                             Input: I just love food in general
[10/03/24 15:27:06] INFO     PromptTask a294ff22be244accb2ac0ad01784bc06
                             Output: That's great to hear! Food is such a wonderful way to explore different cultures and flavors. Do you have any favorite cuisines or
                             dishes that you particularly enjoy? Or are there any new foods you're interested in trying?
shhlife commented 1 month ago

@collindutter ahh.. I didn't understand how that worked. Maybe we can update the docs to show what's expected & show what is being sent to the LLM?

Is it possible to get just the summary itself?

Also, the showing of the summary is happening when using the Chat utility.

User: Hi, I'm jason
Thinking...
Assistant: Hello, Jason! How can I assist you today?
User: I love haikus
Thinking...
Assistant: That's wonderful! Haikus are a beautiful form of poetry. Would you like me to create one for you?
User: yes, that'd be great!
Thinking...
Assistant: Sure, here's a haiku for you:

Whispering soft winds,  
Leaves dance in the golden light,  
Autumn's gentle breath.
Jason introduced himself, and the assistant greeted him and asked how it could help him.
User: I also love apples, haiku that for me
Thinking...
Assistant: Of course! Here's a haiku about apples:

Red and green delight,  
Crisp bite in the orchard's glow,  
Autumn's sweet treasure.
Conversation summary:
"""
Jason introduced himself, and the assistant greeted him and asked how it could help him. Jason mentioned that he loves haikus, and the assistant responded by expressing appreciation for haikus and offering to create one for him.
"""