Skip to content

Commit

Permalink
Bugfix: problems with the prompt refactoring of the planning step (#564)
Browse files Browse the repository at this point in the history
  • Loading branch information
IlyaGusev authored Feb 10, 2025
1 parent 75b2a10 commit 75fe8cd
Showing 1 changed file with 23 additions and 17 deletions.
40 changes: 23 additions & 17 deletions src/smolagents/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,12 +464,14 @@ def planning_step(self, task, is_first_step: bool, step: int) -> None:
"content": [
{
"type": "text",
"text": f"""Here is the task:
```
{task}
```
Now begin!""",
}
"text": textwrap.dedent(
f"""Here is the task:
```
{task}
```
Now begin!"""
),
},
],
}
input_messages = [message_prompt_facts, message_prompt_task]
Expand Down Expand Up @@ -500,14 +502,18 @@ def planning_step(self, task, is_first_step: bool, step: int) -> None:
)
answer_plan = chat_message_plan.content

final_plan_redaction = f"""Here is the plan of action that I will follow to solve the task:
```
{answer_plan}
```"""
final_facts_redaction = f"""Here are the facts that I know so far:
```
{answer_facts}
```""".strip()
final_plan_redaction = textwrap.dedent(
f"""Here is the plan of action that I will follow to solve the task:
```
{answer_plan}
```"""
)
final_facts_redaction = textwrap.dedent(
f"""Here are the facts that I know so far:
```
{answer_facts}
```""".strip()
)
self.memory.steps.append(
PlanningStep(
model_input_messages=input_messages,
Expand All @@ -533,7 +539,7 @@ def planning_step(self, task, is_first_step: bool, step: int) -> None:
"content": [{"type": "text", "text": self.prompt_templates["planning"]["update_facts_pre_messages"]}],
}
facts_update_post_messages = {
"role": MessageRole.SYSTEM,
"role": MessageRole.USER,
"content": [{"type": "text", "text": self.prompt_templates["planning"]["update_facts_post_messages"]}],
}
input_messages = [facts_update_pre_messages] + memory_messages + [facts_update_post_messages]
Expand All @@ -553,12 +559,12 @@ def planning_step(self, task, is_first_step: bool, step: int) -> None:
],
}
update_plan_post_messages = {
"role": MessageRole.SYSTEM,
"role": MessageRole.USER,
"content": [
{
"type": "text",
"text": populate_template(
self.prompt_templates["planning"]["update_plan_pre_messages"],
self.prompt_templates["planning"]["update_plan_post_messages"],
variables={
"task": task,
"tools": self.tools,
Expand Down

0 comments on commit 75fe8cd

Please sign in to comment.