langchain icon indicating copy to clipboard operation
langchain copied to clipboard

AutoGPT Implementation: AttributeError: 'Tool' object has no attribute 'args'

Open drcostco opened this issue 1 year ago • 4 comments

When I run this notebook: https://python.langchain.com/en/latest/use_cases/autonomous_agents/autogpt.html

I get an error: 'AttributeError: 'Tool' object has no attribute 'args'


AttributeError Traceback (most recent call last) Cell In[25], line 1 ----> 1 agent.run(["write a weather report for SF today"])

File ~/opt/anaconda3/envs/langchain/lib/python3.11/site-packages/langchain/experimental/autonomous_agents/autogpt/agent.py:91, in AutoGPT.run(self, goals) 88 loop_count += 1 90 # Send message to AI, get response ---> 91 assistant_reply = self.chain.run( 92 goals=goals, 93 messages=self.full_message_history, 94 memory=self.memory, 95 user_input=user_input, 96 ) 98 # Print Assistant thoughts 99 print(assistant_reply)

File ~/opt/anaconda3/envs/langchain/lib/python3.11/site-packages/langchain/chains/base.py:216, in Chain.run(self, *args, **kwargs) 213 return self(args[0])[self.output_keys[0]] 215 if kwargs and not args: --> 216 return self(kwargs)[self.output_keys[0]] 218 raise ValueError( 219 f"run supported with either positional arguments or keyword arguments" 220 f" but not both. Got args: {args} and kwargs: {kwargs}." 221 )

File ~/opt/anaconda3/envs/langchain/lib/python3.11/site-packages/langchain/chains/base.py:116, in Chain.call(self, inputs, return_only_outputs) 114 except (KeyboardInterrupt, Exception) as e: 115 self.callback_manager.on_chain_error(e, verbose=self.verbose) --> 116 raise e 117 self.callback_manager.on_chain_end(outputs, verbose=self.verbose) 118 return self.prep_outputs(inputs, outputs, return_only_outputs)

File ~/opt/anaconda3/envs/langchain/lib/python3.11/site-packages/langchain/chains/base.py:113, in Chain.call(self, inputs, return_only_outputs) 107 self.callback_manager.on_chain_start( 108 {"name": self.class.name}, 109 inputs, 110 verbose=self.verbose, 111 ) 112 try: --> 113 outputs = self._call(inputs) 114 except (KeyboardInterrupt, Exception) as e: 115 self.callback_manager.on_chain_error(e, verbose=self.verbose)

File ~/opt/anaconda3/envs/langchain/lib/python3.11/site-packages/langchain/chains/llm.py:57, in LLMChain._call(self, inputs) 56 def _call(self, inputs: Dict[str, Any]) -> Dict[str, str]: ---> 57 return self.apply([inputs])[0]

File ~/opt/anaconda3/envs/langchain/lib/python3.11/site-packages/langchain/chains/llm.py:118, in LLMChain.apply(self, input_list) 116 def apply(self, input_list: List[Dict[str, Any]]) -> List[Dict[str, str]]: 117 """Utilize the LLM generate method for speed gains.""" --> 118 response = self.generate(input_list) 119 return self.create_outputs(response)

File ~/opt/anaconda3/envs/langchain/lib/python3.11/site-packages/langchain/chains/llm.py:61, in LLMChain.generate(self, input_list) 59 def generate(self, input_list: List[Dict[str, Any]]) -> LLMResult: 60 """Generate LLM result from inputs.""" ---> 61 prompts, stop = self.prep_prompts(input_list) 62 return self.llm.generate_prompt(prompts, stop)

File ~/opt/anaconda3/envs/langchain/lib/python3.11/site-packages/langchain/chains/llm.py:79, in LLMChain.prep_prompts(self, input_list) 77 for inputs in input_list: 78 selected_inputs = {k: inputs[k] for k in self.prompt.input_variables} ---> 79 prompt = self.prompt.format_prompt(**selected_inputs) 80 _colored_text = get_colored_text(prompt.to_string(), "green") 81 _text = "Prompt after formatting:\n" + _colored_text

File ~/opt/anaconda3/envs/langchain/lib/python3.11/site-packages/langchain/prompts/chat.py:127, in BaseChatPromptTemplate.format_prompt(self, **kwargs) 126 def format_prompt(self, **kwargs: Any) -> PromptValue: --> 127 messages = self.format_messages(**kwargs) 128 return ChatPromptValue(messages=messages)

File ~/opt/anaconda3/envs/langchain/lib/python3.11/site-packages/langchain/experimental/autonomous_agents/autogpt/prompt.py:40, in AutoGPTPrompt.format_messages(self, **kwargs) 39 def format_messages(self, **kwargs: Any) -> List[BaseMessage]: ---> 40 base_prompt = SystemMessage(content=self.construct_full_prompt(kwargs["goals"])) 41 time_prompt = SystemMessage( 42 content=f"The current time and date is {time.strftime('%c')}" 43 ) 44 used_tokens = self.token_counter(base_prompt.content) + self.token_counter( 45 time_prompt.content 46 )

File ~/opt/anaconda3/envs/langchain/lib/python3.11/site-packages/langchain/experimental/autonomous_agents/autogpt/prompt.py:36, in AutoGPTPrompt.construct_full_prompt(self, goals) 33 for i, goal in enumerate(goals): 34 full_prompt += f"{i+1}. {goal}\n" ---> 36 full_prompt += f"\n\n{get_prompt(self.tools)}" 37 return full_prompt

File ~/opt/anaconda3/envs/langchain/lib/python3.11/site-packages/langchain/experimental/autonomous_agents/autogpt/prompt_generator.py:184, in get_prompt(tools) 178 prompt_generator.add_performance_evaluation( 179 "Every command has a cost, so be smart and efficient. " 180 "Aim to complete tasks in the least number of steps." 181 ) 183 # Generate the prompt string --> 184 prompt_string = prompt_generator.generate_prompt_string() 186 return prompt_string

File ~/opt/anaconda3/envs/langchain/lib/python3.11/site-packages/langchain/experimental/autonomous_agents/autogpt/prompt_generator.py:113, in PromptGenerator.generate_prompt_string(self) 104 """Generate a prompt string. 105 106 Returns: 107 str: The generated prompt string. 108 """ 109 formatted_response_format = json.dumps(self.response_format, indent=4) 110 prompt_string = ( 111 f"Constraints:\n{self._generate_numbered_list(self.constraints)}\n\n" 112 f"Commands:\n" --> 113 f"{self._generate_numbered_list(self.commands, item_type='command')}\n\n" 114 f"Resources:\n{self._generate_numbered_list(self.resources)}\n\n" 115 f"Performance Evaluation:\n" 116 f"{self._generate_numbered_list(self.performance_evaluation)}\n\n" 117 f"You should only respond in JSON format as described below " 118 f"\nResponse Format: \n{formatted_response_format} " 119 f"\nEnsure the response can be parsed by Python json.loads" 120 ) 122 return prompt_string

File ~/opt/anaconda3/envs/langchain/lib/python3.11/site-packages/langchain/experimental/autonomous_agents/autogpt/prompt_generator.py:84, in PromptGenerator._generate_numbered_list(self, items, item_type) 72 """ 73 Generate a numbered list from given items based on the item_type. 74 (...) 81 str: The formatted numbered list. 82 """ 83 if item_type == "command": ---> 84 command_strings = [ 85 f"{i + 1}. {self._generate_command_string(item)}" 86 for i, item in enumerate(items) 87 ] 88 finish_description = ( 89 "use this to signal that you have finished all your objectives" 90 ) 91 finish_args = ( 92 '"response": "final response to let ' 93 'people know you have finished your objectives"' 94 )

File ~/opt/anaconda3/envs/langchain/lib/python3.11/site-packages/langchain/experimental/autonomous_agents/autogpt/prompt_generator.py:85, in (.0) 72 """ 73 Generate a numbered list from given items based on the item_type. 74 (...) 81 str: The formatted numbered list. 82 """ 83 if item_type == "command": 84 command_strings = [ ---> 85 f"{i + 1}. {self._generate_command_string(item)}" 86 for i, item in enumerate(items) 87 ] 88 finish_description = ( 89 "use this to signal that you have finished all your objectives" 90 ) 91 finish_args = ( 92 '"response": "final response to let ' 93 'people know you have finished your objectives"' 94 )

File ~/opt/anaconda3/envs/langchain/lib/python3.11/site-packages/langchain/experimental/autonomous_agents/autogpt/prompt_generator.py:50, in PromptGenerator._generate_command_string(self, tool) 48 def _generate_command_string(self, tool: BaseTool) -> str: 49 output = f"{tool.name}: {tool.description}" ---> 50 output += f", args json schema: {json.dumps(tool.args)}" 51 return output

drcostco avatar Apr 20 '23 02:04 drcostco

I am also getting the same error. I am trying to use AzureChatOpenAI.

Adityadt68 avatar Apr 20 '23 06:04 Adityadt68

Hello, Did you find any solution?

JeremyBon avatar Apr 21 '23 12:04 JeremyBon

same here.

gallaghercareer avatar Apr 22 '23 03:04 gallaghercareer

same

MrMitochondria avatar May 10 '23 04:05 MrMitochondria

Hi, @drcostco! I'm Dosu, and I'm here to help the LangChain team manage their backlog. I wanted to let you know that we are marking this issue as stale.

From what I understand, you reported an AttributeError that occurs when running a notebook for AutoGPT implementation. It seems that several other users, such as Adityadt68, JeremyBon, gallaghercareer, and MrMitochondria, have also encountered the same error and are looking for a solution. Unfortunately, at this time, the issue remains unresolved.

Before we close this issue, we wanted to check with you if it is still relevant to the latest version of the LangChain repository. If it is, please let us know by commenting on this issue. Otherwise, feel free to close the issue yourself, or it will be automatically closed in 7 days.

Thank you for your understanding and contribution to the LangChain community!

dosubot[bot] avatar Sep 17 '23 17:09 dosubot[bot]