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
1.99k stars 164 forks source link

WebScraper tool not accessing memory #173

Closed shhlife closed 1 year ago

shhlife commented 1 year ago

Describe the bug When using WebScraper I'm getting an error saying that it can't find the memory. If I specify TextToolMemory it can find the memory and operate properly.

To Reproduce

from griptape.drivers import OpenAiChatPromptDriver
from griptape.structures import Agent
from griptape.tools import WebScraper

agent = Agent(
    tools=[WebScraper()]
)

response = agent.run("Summarize what Griptape is by looking at https://www.griptape.ai/")
print(response.output.value)

returns:

08/22/23 08:47:58] INFO     Task 035916f8021b4eb384da49f892e5efc0                                                                        
                             Input: Summarize what Griptape is by looking at https://www.griptape.ai/                                      
[08/22/23 08:48:07] INFO     Subtask 46a51414a85e4ee3a29dd5dca34a7ed8                                                                     
                             Thought: To summarize what Griptape is, I need to first use the WebScraper tool to get the content of the    
                             provided URL. Then, I can use the TextToolMemory to store the scraped content. Finally, I can use the        
                             TextToolMemory again to summarize the stored content.                                                        
                             Action: {"type": "tool", "name": "WebScraper", "activity": "get_content", "input": {"values": {"url":        
                             "https://www.griptape.ai/"}}}                                                                                 
                    INFO     Subtask 46a51414a85e4ee3a29dd5dca34a7ed8                                                                     
                             Observation: Output of "WebScraper.get_content" was stored in memory: {"memory_id":"TextToolMemory",         
                             "artifact_namespace": "ac7b600dce844a3286803bdcc4ae65fa"}                                                    
[08/22/23 08:48:18] INFO     Subtask 3cddc0aef647435f93e1a6ab57a6ce7d                                                                     
                             Thought: Now that the content of the webpage is stored in memory, I can use the TextToolMemory tool to       
                             summarize this content.                                                                                      
                             Action: {"type": "memory", "name": "TextToolMemory", "activity": "summarize", "input": {"values":            
                             {"memory_id": "ac7b600dce844a3286803bdcc4ae65fa", "artifact_namespace": "ac7b600dce844a3286803bdcc4ae65fa"}}}
                    INFO     Subtask 3cddc0aef647435f93e1a6ab57a6ce7d                                                                     
                             Observation: memory not found                                                                                
[08/22/23 08:48:29] INFO     Subtask 5aa124da6d934b0899139bdb82e85eb4                                                                     
                             Thought: It seems there was an error with the memory retrieval. The memory ID and artifact namespace should  
                             be correct as they were provided by the system. I'll try to retrieve the content from the memory again.      
                             Action: {"type": "memory", "name": "TextToolMemory", "activity": "summarize", "input": {"values":            
                             {"memory_id": "ac7b600dce844a3286803bdcc4ae65fa", "artifact_namespace": "ac7b600dce844a3286803bdcc4ae65fa"}}}
                    INFO     Subtask 5aa124da6d934b0899139bdb82e85eb4                                                                     
                             Observation: memory not found                                                                                
[08/22/23 08:48:35] INFO     Task 035916f8021b4eb384da49f892e5efc0                                                                        
                             Answer: I'm sorry, but I'm currently unable to summarize the content of the webpage due to a technical issue.
I'm sorry, but I'm currently unable to summarize the content of the webpage due to a technical issue.

However, if I use:

from griptape.drivers import OpenAiChatPromptDriver
from griptape.structures import Agent
from griptape.tools import WebScraper, ToolOutputProcessor
from griptape.memory.tool import TextToolMemory

text_memory = TextToolMemory(
    allowlist=[]
)

web_scraper = WebScraper(
    output_memory={
        "get_content": [text_memory]
    }
)

memory_browser = ToolOutputProcessor(
    input_memory=[text_memory]
)

agent = Agent(
    tools=[web_scraper, memory_browser]
)

response = agent.run("Summarize what Griptape is by looking at https://www.griptape.ai/")
print(response.output.value)

I get the expected response:

Griptape is an open source framework that enables developers to build and deploy AI applications using large language models. It provides tools for creating AI systems that balance predictability and creativity, and it allows for safe prompting of these models, connecting them to external APIs and data stores. Griptape also includes features such as sequential pipelines, DAG-based workflows, and long-term memory. Additionally, Griptape Cloud is a managed platform for deploying and managing AI agents, pipelines, and workflows.

Expected behavior WebScraper should have tool memory by default, but it's not able to find it.

Additional context This behavior is new as of 0.15

vasinov commented 1 year ago

v0.15.2 fixes this issue.