fix : blocks not appearing on front for planner agent

This commit is contained in:
martin legrand
2025-04-24 12:22:52 +02:00
parent 812af254b5
commit 82aecd0aae
5 changed files with 42 additions and 19 deletions
+12 -2
View File
@@ -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()
+4 -5
View File
@@ -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.")