From 8b5bb28c9478621757eab613e1aecd8b5660c4d5 Mon Sep 17 00:00:00 2001 From: martin legrand Date: Sun, 23 Mar 2025 17:25:49 +0100 Subject: [PATCH] fix : various bugs & improve memory system --- sources/agents/browser_agent.py | 2 +- sources/agents/casual_agent.py | 2 +- sources/agents/code_agent.py | 2 +- sources/agents/file_agent.py | 18 +++++------------- sources/browser.py | 4 ++-- sources/memory.py | 8 ++++---- sources/tools/PyInterpreter.py | 1 + 7 files changed, 15 insertions(+), 22 deletions(-) diff --git a/sources/agents/browser_agent.py b/sources/agents/browser_agent.py index 8a14028..a9bb4b9 100644 --- a/sources/agents/browser_agent.py +++ b/sources/agents/browser_agent.py @@ -17,7 +17,7 @@ class BrowserAgent(Agent): self.tools = { "web_search": searxSearch(), } - self.role = "Web Research" + self.role = "Web surfing, website & news" self.type = "browser_agent" self.browser = Browser() self.current_page = "" diff --git a/sources/agents/casual_agent.py b/sources/agents/casual_agent.py index 44ccf42..87f07d6 100644 --- a/sources/agents/casual_agent.py +++ b/sources/agents/casual_agent.py @@ -18,7 +18,7 @@ class CasualAgent(Agent): "file_finder": FileFinder(), "bash": BashInterpreter() } - self.role = "Chat and Conversation" + self.role = "talk, quick search" self.type = "casual_agent" def process(self, prompt, speech_module) -> str: diff --git a/sources/agents/code_agent.py b/sources/agents/code_agent.py index 797c02f..735c5f5 100644 --- a/sources/agents/code_agent.py +++ b/sources/agents/code_agent.py @@ -20,7 +20,7 @@ class CoderAgent(Agent): "go": GoInterpreter(), "file_finder": FileFinder() } - self.role = "Code Assistance" + self.role = "Coding task" self.type = "code_agent" def process(self, prompt, speech_module) -> str: diff --git a/sources/agents/file_agent.py b/sources/agents/file_agent.py index d8aee5c..b062e4a 100644 --- a/sources/agents/file_agent.py +++ b/sources/agents/file_agent.py @@ -18,23 +18,15 @@ class FileAgent(Agent): self.type = "file_agent" def process(self, prompt, speech_module) -> str: - complete = False exec_success = False self.memory.push('user', prompt) self.wait_message(speech_module) - while not complete: - if exec_success: - complete = True - animate_thinking("Thinking...", color="status") - answer, reasoning = self.llm_request() - exec_success, _ = self.execute_modules(answer) - answer = self.remove_blocks(answer) - self.last_answer = answer - complete = True - for name, tool in self.tools.items(): - if tool.found_executable_blocks(): - complete = False # AI read results and continue the conversation + animate_thinking("Thinking...", color="status") + answer, reasoning = self.llm_request() + exec_success, _ = self.execute_modules(answer) + answer = self.remove_blocks(answer) + self.last_answer = answer return answer, reasoning if __name__ == "__main__": diff --git a/sources/browser.py b/sources/browser.py index a229606..789d255 100644 --- a/sources/browser.py +++ b/sources/browser.py @@ -28,7 +28,7 @@ class Browser: 'Accept-Language': 'en-US,en;q=0.9', 'Referer': 'https://www.google.com/', } - self.js_scripts_folder = "./web_scripts/" + self.js_scripts_folder = "./sources/web_scripts/" try: chrome_options = Options() chrome_path = self.get_chrome_path() @@ -258,7 +258,7 @@ class Browser: except Exception as e: self.logger.error(f"Error extracting form inputs: {str(e)}") - return f"Error extracting form inputs." + return [f"Error extracting form inputs."] def get_buttons_xpath(self) -> List[str]: """ diff --git a/sources/memory.py b/sources/memory.py index d03da29..a7187ab 100644 --- a/sources/memory.py +++ b/sources/memory.py @@ -80,10 +80,10 @@ class Memory(): def push(self, role: str, content: str) -> None: """Push a message to the memory.""" - self.memory.append({'role': role, 'content': content}) - # EXPERIMENTAL if self.memory_compression and role == 'assistant': self.compress() + # we don't compress the last message + self.memory.append({'role': role, 'content': content}) def clear(self) -> None: self.memory = [] @@ -133,9 +133,9 @@ class Memory(): if not self.memory_compression: return for i in range(len(self.memory)): - if i <= 2: + if i < 3: continue - if self.memory[i]['role'] == 'assistant': + if len(self.memory[i]['content']) > 1024: self.memory[i]['content'] = self.summarize(self.memory[i]['content']) if __name__ == "__main__": diff --git a/sources/tools/PyInterpreter.py b/sources/tools/PyInterpreter.py index 2c250c9..3e2c59f 100644 --- a/sources/tools/PyInterpreter.py +++ b/sources/tools/PyInterpreter.py @@ -35,6 +35,7 @@ class PyInterpreter(Tools): try: try: buffer = exec(code, global_vars) + print(buffer) if buffer is not None: output = buffer + '\n' except Exception as e: