From 79ef849de158e400aead392d2749214e0ea5b15c Mon Sep 17 00:00:00 2001 From: Sambhav Dixit <94298612+sambhavnoobcoder@users.noreply.github.com> Date: Sat, 19 Oct 2024 00:07:31 +0530 Subject: [PATCH] Ensure tool execution regardless of long-term memory usage Modified the `run` method in the Agent class to check and execute tools after generating a response, regardless of whether long-term memory is used or not. This fixes the issue where tools were not being executed when long-term memory was present. Changes: - Moved tool execution check and call outside of the long-term memory conditional block - Ensures consistent tool usage across all agent runs --- swarms/structs/agent.py | 60 +++++++++++++++++++---------------------- 1 file changed, 28 insertions(+), 32 deletions(-) diff --git a/swarms/structs/agent.py b/swarms/structs/agent.py index be02c704..9f3692dd 100644 --- a/swarms/structs/agent.py +++ b/swarms/structs/agent.py @@ -711,45 +711,41 @@ class Agent: while attempt < self.retry_attempts and not success: try: if self.long_term_memory is not None: - logger.info( - "Querying long term memory..." - ) + logger.info("Querying long term memory...") self.memory_query(task_prompt) - else: - response_args = ( - (task_prompt, *args) - if img is None - else (task_prompt, img, *args) - ) - response = self.call_llm( - *response_args, **kwargs - ) + # Generate response using LLM + response = self.llm(task_prompt, *args, **kwargs) - # Log the step metadata - logged = self.log_step_metadata( - loop_count, task_prompt, response - ) - logger.info(logged) + # Check and execute tools + if self.tools is not None: + print(f"self.tools is not None: {response}") + self.parse_and_execute_tools(response) - # Conver to a str if the response is not a str - response = self.llm_output_parser( - response - ) + # Log the step metadata + logged = self.log_step_metadata( + loop_count, task_prompt, response + ) + logger.info(logged) - # Print - if self.streaming_on is True: - self.stream_response(response) - else: - print(response) + # Conver to a str if the response is not a str + response = self.llm_output_parser( + response + ) - # Add the response to the memory - self.short_memory.add( - role=self.agent_name, content=response - ) + # Print + if self.streaming_on is True: + self.stream_response(response) + else: + print(response) + + # Add the response to the memory + self.short_memory.add( + role=self.agent_name, content=response + ) - # Add to all responses - all_responses.append(response) + # Add to all responses + all_responses.append(response) # TODO: Implement reliablity check if self.tools is not None: