From 8b199869c70728a536f3a34c5f5a5ad05a7a2e18 Mon Sep 17 00:00:00 2001 From: martin legrand Date: Thu, 24 Apr 2025 13:23:17 +0200 Subject: [PATCH] fix : planner agent bug --- frontend/agentic-seek-front/src/App.js | 1 - sources/agents/browser_agent.py | 17 ++++++++++++++++- sources/agents/planner_agent.py | 2 +- 3 files changed, 17 insertions(+), 3 deletions(-) diff --git a/frontend/agentic-seek-front/src/App.js b/frontend/agentic-seek-front/src/App.js index 74862a1..a5bcfdc 100644 --- a/frontend/agentic-seek-front/src/App.js +++ b/frontend/agentic-seek-front/src/App.js @@ -142,7 +142,6 @@ function App() { console.log('Response:', res.data); const data = res.data; updateData(data); - fetchLatestAnswer(); } catch (err) { console.error('Error:', err); setError('Failed to process query.'); diff --git a/sources/agents/browser_agent.py b/sources/agents/browser_agent.py index 7aea549..1588600 100644 --- a/sources/agents/browser_agent.py +++ b/sources/agents/browser_agent.py @@ -287,7 +287,19 @@ class BrowserAgent(Agent): for res in search_result: pretty_print(f"Title: {res['title']} - ", color="info", no_newline=True) pretty_print(f"Link: {res['link']}", color="status") - + + def stuck_prompt(self, user_prompt: str, unvisited: List[str]) -> str: + """ + Prompt for when the agent repeat itself, can happen when fail to extract a link. + """ + prompt = self.make_newsearch_prompt(user_prompt, unvisited) + prompt += f""" + You previously said: + {self.answer} + You must consider other options. Choose other link. + """ + return prompt + async def process(self, user_prompt: str, speech_module: type) -> Tuple[str, str]: """ Process the user prompt to conduct an autonomous web search. @@ -320,6 +332,9 @@ class BrowserAgent(Agent): print("Debug history:", self.search_history) unvisited = self.select_unvisited(search_result) answer, reasoning = await self.llm_decide(prompt, show_reasoning = False) + if self.last_answer == answer: + prompt = self.stuck_prompt(user_prompt, unvisited) + continue self.last_answer = answer pretty_print('▂'*32, color="status") diff --git a/sources/agents/planner_agent.py b/sources/agents/planner_agent.py index 94fd1e7..47da48d 100644 --- a/sources/agents/planner_agent.py +++ b/sources/agents/planner_agent.py @@ -80,7 +80,7 @@ class PlannerAgent(Agent): if len(tasks_names) != len(tasks): names = [task['task'] for task in tasks] return list(map(list, zip(names, tasks))) - return list(map(list, zip(names, tasks))) + return list(map(list, zip(tasks_names, tasks))) def make_prompt(self, task: str, agent_infos_dict: dict) -> str: """