Skip to content

Task Memory

Overview

Task Memory augments activity inputs and outputs with storage capabilities. It's a way to keep any data generated by tools off prompt but still allow LLMs to operate on that data remotely. This is useful in the following scenarios:

  • Security requirements: many organizations don't want data to leave their cloud for regulatory and security reasons.
  • Long textual content: when textual content returned by tools can't fit in the token limit, it's often useful to perform operations on it in a separate process, not in the main LLM.
  • Non-textual content: tools can generate images, videos, PDFs, and other non-textual content that can be stored in memory and acted upon later by other tools.

By default, Griptape augments all tool outputs with TaskMemory but you can override at the structure, task, or tool activity level.

Task Memory

Here is an example of how memory can be used in unison with multiple tools to store and load content:

from griptape.artifacts import TextArtifact, BlobArtifact
from griptape.memory.task.storage import TextArtifactStorage, BlobArtifactStorage
from griptape.structures import Agent
from griptape.tools import WebScraper, FileManager, TaskMemoryClient
from griptape.engines import VectorQueryEngine, PromptSummaryEngine, CsvExtractionEngine, JsonExtractionEngine
from griptape.drivers import LocalVectorStoreDriver, OpenAiEmbeddingDriver, OpenAiChatPromptDriver

prompt_driver = OpenAiChatPromptDriver(model="gpt-3.5-turbo")

agent = Agent(
    tools=[WebScraper(), FileManager(), TaskMemoryClient(off_prompt=True)]
)

agent.run(
    "Load https://www.griptape.ai, summarize it, "
    "and store it in griptape.txt"
)
[10/20/23 13:31:40] INFO     ToolkitTask 82211eeb10374e75ad77135373d816e6       
                             Input: Load https://www.griptape.ai, summarize it, 
                             and store it in griptape.txt                       
[10/20/23 13:31:52] INFO     Subtask 17b3d35197eb417b834a7db49039ae4f           
                             Thought: The user wants to load the webpage at     
                             https://www.griptape.ai, summarize its content, and
                             store the summary in a file named griptape.txt. To 
                             achieve this, I need to first use the WebScraper   
                             tool to get the content of the webpage. Then, I    
                             will use the TaskMemoryClient to summarize the  
                             content. Finally, I will use the FileManager tool  
                             to save the summarized content to a file named     
                             griptape.txt.                                      

                             Action: {"name": "WebScraper",     
                             "path": "get_content", "input": {"values":     
                             {"url": "https://www.griptape.ai"}}}               
[10/20/23 13:31:53] INFO     Subtask 17b3d35197eb417b834a7db49039ae4f           
                             Response: Output of "WebScraper.get_content" was
                             stored in memory with memory_name "TaskMemory" and 
                             artifact_namespace                                 
                             "82543abe79984d11bb952bd6036a7a01"                 
[10/20/23 13:32:00] INFO     Subtask 58bac35adda94157ac6f9482e7c41c9f           
                             Thought: Now that I have the content of the webpage
                             stored in memory, I can use the TaskMemoryClient
                             tool to summarize this content.                    
                             Action: {"name":                   
                             "TaskMemoryClient", "path": "summarize",    
                             "input": {"values": {"memory_name": "TaskMemory",  
                             "artifact_namespace":                              
                             "82543abe79984d11bb952bd6036a7a01"}}}              
[10/20/23 13:32:03] INFO     Subtask 58bac35adda94157ac6f9482e7c41c9f           
                             Response: Output of                             
                             "TaskMemoryClient.summarize" was stored in      
                             memory with memory_name "TaskMemory" and           
                             artifact_namespace                                 
                             "01b8015f8c5647f09e8d103198404db0"                 
[10/20/23 13:32:12] INFO     Subtask a630f649007b4d7fa0b6cf85be6b2f4f           
                             Thought: Now that I have the summarized content of 
                             the webpage stored in memory, I can use the        
                             FileManager tool to save this content to a file    
                             named griptape.txt.                                
                             Action: {"name": "FileManager",    
                             "path": "save_memory_artifacts_to_disk",       
                             "input": {"values": {"dir_name": ".", "file_name": 
                             "griptape.txt", "memory_name": "TaskMemory",       
                             "artifact_namespace":                              
                             "01b8015f8c5647f09e8d103198404db0"}}}              
                    INFO     Subtask a630f649007b4d7fa0b6cf85be6b2f4f           
                             Response: saved successfully                    
[10/20/23 13:32:14] INFO     ToolkitTask 82211eeb10374e75ad77135373d816e6       
                             Output: The summarized content of the webpage at   
                             https://www.griptape.ai has been successfully      
                             stored in a file named griptape.txt.