From 82aecd0aae984a54e4b9c7cde5b8809c9293b809 Mon Sep 17 00:00:00 2001 From: martin legrand Date: Thu, 24 Apr 2025 12:22:52 +0200 Subject: [PATCH] fix : blocks not appearing on front for planner agent --- README.md | 5 ++--- frontend/agentic-seek-front/src/App.js | 15 +++++++++++++-- sources/agents/browser_agent.py | 14 ++++++++++++-- sources/agents/planner_agent.py | 9 ++++----- sources/browser.py | 18 +++++++++++------- 5 files changed, 42 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index b18d1a1..fd66a31 100644 --- a/README.md +++ b/README.md @@ -12,12 +12,12 @@ English | [中文](./README_CHS.md) | [繁體中文](./README_CHT.md) | [Franç [![Visit AgenticSeek](https://img.shields.io/static/v1?label=Website&message=AgenticSeek&color=blue&style=flat-square)](https://fosowl.github.io/agenticSeek.html) ![License](https://img.shields.io/badge/license-GPL--3.0-green) [![Discord](https://img.shields.io/badge/Discord-Join%20Us-7289DA?logo=discord&logoColor=white)](https://discord.gg/m37d7XxZ) [![Twitter](https://img.shields.io/twitter/url/https/twitter.com/fosowl.svg?style=social&label=Update%20%40Fosowl)](https://x.com/Martin993886460) [![GitHub stars](https://img.shields.io/github/stars/Fosowl/agenticSeek?style=social)](https://github.com/Fosowl/agenticSeek/stargazers) -> 🛠️ **Work in Progress** – Looking for contributors! -> *Plan a 3 days trip to Budapest, find me a list of attractions and hotels, save everything in a CSV file* +> *Plan a 3 days solo trip to Budapest, find me a list of attractions and hostels, save everything in a CSV file* https://github.com/user-attachments/assets/4bd5faf6-459f-4f94-bd1d-238c4b331469 +> 🛠️ **Work in Progress** – Looking for contributors! - **100% Local**: *No cloud, runs on your hardware. Your data stays yours.* @@ -31,7 +31,6 @@ https://github.com/user-attachments/assets/4bd5faf6-459f-4f94-bd1d-238c4b331469 - **Memory**: *Efficient memory and sessions management.* - ## Installation Make sure you have chrome driver, docker and python3.10 (or newer) installed. diff --git a/frontend/agentic-seek-front/src/App.js b/frontend/agentic-seek-front/src/App.js index f7dd952..74862a1 100644 --- a/frontend/agentic-seek-front/src/App.js +++ b/frontend/agentic-seek-front/src/App.js @@ -79,6 +79,7 @@ function App() { const res = await axios.get('http://0.0.0.0:8000/latest_answer'); const data = res.data; + updateData(data); if (!data.answer || data.answer.trim() === '') { return; } @@ -98,7 +99,6 @@ function App() { }, ]); setStatus(data.status); - setResponseData(data); scrollToBottom(); } else { console.log('Duplicate answer detected, skipping:', data.answer); @@ -108,6 +108,17 @@ function App() { } }; + const updateData = (data) => { + setResponseData((prev) => ({ + ...prev, + blocks: data.blocks || prev.blocks || null, + done: data.done, + answer: data.answer, + agent_name: data.agent_name, + status: data.status, + uid: data.uid, + })); + }; const handleSubmit = async (e) => { e.preventDefault(); @@ -130,7 +141,7 @@ function App() { setQuery('Enter your query...'); console.log('Response:', res.data); const data = res.data; - setResponseData(data); + updateData(data); fetchLatestAnswer(); } catch (err) { console.error('Error:', err); diff --git a/sources/agents/browser_agent.py b/sources/agents/browser_agent.py index 204455b..7aea549 100644 --- a/sources/agents/browser_agent.py +++ b/sources/agents/browser_agent.py @@ -317,6 +317,8 @@ class BrowserAgent(Agent): while not complete and len(unvisited) > 0: self.memory.clear() + print("Debug history:", self.search_history) + unvisited = self.select_unvisited(search_result) answer, reasoning = await self.llm_decide(prompt, show_reasoning = False) self.last_answer = answer pretty_print('▂'*32, color="status") @@ -339,6 +341,11 @@ class BrowserAgent(Agent): links = self.parse_answer(answer) link = self.select_link(links) + if link == self.current_page: + pretty_print(f"Already visited {link}. Search callback.", color="status") + prompt = self.make_newsearch_prompt(user_prompt, unvisited) + self.search_history.append(link) + continue if Action.REQUEST_EXIT.value in answer: self.status_message = "Exiting web browser..." @@ -349,7 +356,6 @@ class BrowserAgent(Agent): if (link == None and len(extracted_form) < 3) or Action.GO_BACK.value in answer or link in self.search_history: pretty_print(f"Going back to results. Still {len(unvisited)}", color="status") self.status_message = "Going back to search results..." - unvisited = self.select_unvisited(search_result) prompt = self.make_newsearch_prompt(user_prompt, unvisited) self.search_history.append(link) self.current_page = link @@ -357,8 +363,12 @@ class BrowserAgent(Agent): animate_thinking(f"Navigating to {link}", color="status") if speech_module: speech_module.speak(f"Navigating to {link}") - self.browser.go_to(link) + nav_ok = self.browser.go_to(link) self.search_history.append(link) + if not nav_ok: + pretty_print(f"Failed to navigate to {link}.", color="failure") + prompt = self.make_newsearch_prompt(user_prompt, unvisited) + continue self.current_page = link page_text = self.browser.get_text() self.navigable_links = self.browser.get_navigable() diff --git a/sources/agents/planner_agent.py b/sources/agents/planner_agent.py index 9d09585..94fd1e7 100644 --- a/sources/agents/planner_agent.py +++ b/sources/agents/planner_agent.py @@ -135,10 +135,6 @@ class PlannerAgent(Agent): animate_thinking("Thinking...", color="status") self.memory.push('user', prompt) answer, reasoning = await self.llm_request() - print("LLM answer:") - print(reasoning) - print(answer) - print("LLM answer end") if "NO_UPDATE" in answer: return [] agents_tasks = self.parse_agent_tasks(answer) @@ -160,6 +156,7 @@ class PlannerAgent(Agent): Returns: dict: The updated plan. """ + self.status_message = "Updating plan..." last_agent_work = agents_work_result[id] tool_success_str = "success" if success else "failure" pretty_print(f"Agent {id} work {tool_success_str}.", color="success" if success else "failure") @@ -196,6 +193,7 @@ class PlannerAgent(Agent): Returns: str: The result of the agent process. """ + self.status_message = f"Starting task {task['task']}..." agent_prompt = self.make_prompt(task['task'], required_infos) pretty_print(f"Agent {task['agent']} started working...", color="status") agent_answer, _ = await self.agents[task['agent'].lower()].process(agent_prompt, None) @@ -219,6 +217,7 @@ class PlannerAgent(Agent): agents_tasks = [] agents_work_result = dict() + self.status_message = "Making a plan..." agents_tasks = await self.make_plan(goal) if agents_tasks == []: @@ -227,7 +226,7 @@ class PlannerAgent(Agent): steps = len(agents_tasks) while i < steps: task_name, task = agents_tasks[i][0], agents_tasks[i][1] - self.status_message = "Starting agent process..." + self.status_message = "Starting agents..." pretty_print(f"I will {task_name}.", color="info") pretty_print(f"Assigned agent {task['agent']} to {task_name}", color="info") if speech_module: speech_module.speak(f"I will {task_name}. I assigned the {task['agent']} agent to the task.") diff --git a/sources/browser.py b/sources/browser.py index bef67f5..e68da01 100644 --- a/sources/browser.py +++ b/sources/browser.py @@ -166,13 +166,17 @@ class Browser: try: initial_handles = self.driver.window_handles self.driver.get(url) - wait = WebDriverWait(self.driver, timeout=10) - wait.until( - lambda driver: ( - not any(keyword in driver.page_source.lower() for keyword in ["checking your browser", "captcha"]) - ), - message="stuck on 'checking browser' or verification screen" - ) + try: + wait = WebDriverWait(self.driver, timeout=10) + wait.until( + lambda driver: ( + not any(keyword in driver.page_source.lower() for keyword in ["checking your browser", "captcha"]) + ), + message="stuck on 'checking browser' or verification screen" + ) + except TimeoutException: + self.logger.warning("Timeout while waiting for page to bypass 'checking your browser'") + return False self.apply_web_safety() self.logger.log(f"Navigated to: {url}") return True