structure
__all__ = ['BaseConversationMemory', 'ConversationMemory', 'Run', 'SummaryConversationMemory']
module-attribute
BaseConversationMemory
Bases: SerializableMixin, ABC
Source code in griptape/memory/structure/base_conversation_memory.py
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 | |
autoload = field(default=True, kw_only=True)
class-attribute
instance-attribute
autoprune = field(default=True, kw_only=True)
class-attribute
instance-attribute
conversation_memory_driver = field(default=Factory(lambda: Defaults.drivers_config.conversation_memory_driver), kw_only=True)
class-attribute
instance-attribute
max_runs = field(default=None, kw_only=True, metadata={'serializable': True})
class-attribute
instance-attribute
meta = field(factory=dict, kw_only=True, metadata={'serializable': True})
class-attribute
instance-attribute
runs = field(factory=list, kw_only=True, metadata={'serializable': True})
class-attribute
instance-attribute
__attrs_post_init__()
add_run(run)
add_to_prompt_stack(prompt_driver, prompt_stack, index=None)
Add the Conversation Memory runs to the Prompt Stack by modifying the messages in place.
If autoprune is enabled, this will fit as many Conversation Memory runs into the Prompt Stack as possible without exceeding the token limit.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
prompt_driver
|
BasePromptDriver
|
The Prompt Driver to use for token counting. |
required |
prompt_stack
|
PromptStack
|
The Prompt Stack to add the Conversation Memory to. |
required |
index
|
int | None
|
Optional index to insert the Conversation Memory runs at. Defaults to appending to the end of the Prompt Stack. |
None
|
Source code in griptape/memory/structure/base_conversation_memory.py
after_add_run()
before_add_run()
load_runs()
to_prompt_stack(last_n=None)
abstractmethod
ConversationMemory
Bases: BaseConversationMemory
Source code in griptape/memory/structure/conversation_memory.py
to_prompt_stack(last_n=None)
Source code in griptape/memory/structure/conversation_memory.py
Run
Bases: SerializableMixin
Source code in griptape/memory/structure/run.py
id = field(default=Factory(lambda: uuid.uuid4().hex), metadata={'serializable': True})
class-attribute
instance-attribute
input = field(metadata={'serializable': True})
class-attribute
instance-attribute
meta = field(default=None, metadata={'serializable': True})
class-attribute
instance-attribute
output = field(metadata={'serializable': True})
class-attribute
instance-attribute
SummaryConversationMemory
Bases: BaseConversationMemory
Conversation memory that automatically summarizes older runs, keeping a configurable number of recent runs in full detail.
The memory stores all runs in self.runs and automatically generates an LLM-powered
summary of older runs as new ones are added. Only the summary and the most recent runs
(controlled by offset) are included in the prompt context via to_prompt_stack().
Note on display utilities:
-
Conversation utility (
griptape.utils.Conversation): Displays all runs stored in memory, not just the summary or the unsummarized portion. When used withSummaryConversationMemory, it prints every Q/A pair fromself.runsfollowed by the generated summary. This is expected behavior -- the runs list preserves the full history for inspection, while the summary is used internally for prompt context. -
Chat utility (
griptape.utils.Chat): CallsStructure.run(), which invokesto_prompt_stack()internally. This means only the summary and the unsummarized recent runs (those withinoffset) are sent to the LLM as context.
Attributes:
| Name | Type | Description |
|---|---|---|
offset |
int
|
Maximum number of recent runs to keep unsummarized. When a new run is
added and the count of unsummarized runs exceeds |
autoprune |
bool
|
Inherited from |
Source code in griptape/memory/structure/summary_conversation_memory.py
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 | |