From 3b5c99e87a6da20b1ee2198ad6c4ebef897d7fd2 Mon Sep 17 00:00:00 2001 From: BUI Van Tuan <37981884+bvantuan@users.noreply.github.com> Date: Tue, 28 Jan 2025 09:21:58 +0100 Subject: [PATCH] Fix Extra planning (#362) * fix Extra planning --- src/smolagents/agents.py | 29 +++++++++++++++++------------ src/smolagents/prompts.py | 2 +- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/src/smolagents/agents.py b/src/smolagents/agents.py index 2ad9af5..c9decd9 100644 --- a/src/smolagents/agents.py +++ b/src/smolagents/agents.py @@ -265,14 +265,14 @@ class MultiStepAgent: elif isinstance(step_log, PlanningStep): thought_message = { "role": MessageRole.ASSISTANT, - "content": "[FACTS LIST]:\n" + step_log.facts.strip(), + "content": [{"type": "text", "text": "[FACTS LIST]:\n" + step_log.facts.strip()}], } memory.append(thought_message) if not summary_mode: thought_message = { "role": MessageRole.ASSISTANT, - "content": "[PLAN]:\n" + step_log.plan.strip(), + "content": [{"type": "text", "text": "[PLAN]:\n" + step_log.plan.strip()}], } memory.append(thought_message) @@ -700,28 +700,33 @@ Now begin!""", # Redact updated facts facts_update_system_prompt = { "role": MessageRole.SYSTEM, - "content": SYSTEM_PROMPT_FACTS_UPDATE, + "content": [{"type": "text", "text": SYSTEM_PROMPT_FACTS_UPDATE}], } facts_update_message = { "role": MessageRole.USER, - "content": USER_PROMPT_FACTS_UPDATE, + "content": [{"type": "text", "text": USER_PROMPT_FACTS_UPDATE}], } facts_update = self.model([facts_update_system_prompt] + agent_memory + [facts_update_message]).content # Redact updated plan plan_update_message = { "role": MessageRole.SYSTEM, - "content": SYSTEM_PROMPT_PLAN_UPDATE.format(task=task), + "content": [{"type": "text", "text": SYSTEM_PROMPT_PLAN_UPDATE.format(task=task)}], } plan_update_message_user = { "role": MessageRole.USER, - "content": USER_PROMPT_PLAN_UPDATE.format( - task=task, - tool_descriptions=get_tool_descriptions(self.tools, self.tool_description_template), - managed_agents_descriptions=(show_agents_descriptions(self.managed_agents)), - facts_update=facts_update, - remaining_steps=(self.max_steps - step), - ), + "content": [ + { + "type": "text", + "text": USER_PROMPT_PLAN_UPDATE.format( + task=task, + tool_descriptions=get_tool_descriptions(self.tools, self.tool_description_template), + managed_agents_descriptions=(show_agents_descriptions(self.managed_agents)), + facts_update=facts_update, + remaining_steps=(self.max_steps - step), + ), + } + ], } plan_update = self.model( [plan_update_message] + agent_memory + [plan_update_message_user], diff --git a/src/smolagents/prompts.py b/src/smolagents/prompts.py index ce905c8..c8dfb37 100644 --- a/src/smolagents/prompts.py +++ b/src/smolagents/prompts.py @@ -433,7 +433,7 @@ Now begin! Write your plan below.""" SYSTEM_PROMPT_FACTS_UPDATE = """ You are a world expert at gathering known and unknown facts based on a conversation. -Below you will find a task, and ahistory of attempts made to solve the task. You will have to produce a list of these: +Below you will find a task, and a history of attempts made to solve the task. You will have to produce a list of these: ### 1. Facts given in the task ### 2. Facts that we have learned ### 3. Facts still to look up