Skip to content

[BugFix] Fix Agent update planning logic #1417

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 17, 2025

Conversation

Zoe14
Copy link
Contributor

@Zoe14 Zoe14 commented Jun 6, 2025

Describe the bug

  1. Create an agent, inject the agent with some memory steps => agent.step_number would still be 0
    Start agent.run(reset=False), the injected memory is not used in planning, llm doesn't have any of the previous conversation context.
  2. in generate_planning_step, the task is part of the update_plan_pre_message and would be the last message in memory_messages. it is redundant.

Proposed fix

  1. When call generate_planning_step, instead of relying on the agent step number, check the agent memory.
  2. removed the last message from memory_messages because it is the current task, and it already present in update_plan_pre_message.

Added a test

@Zoe14
Copy link
Contributor Author

Zoe14 commented Jun 9, 2025

@albertvillanova Can you take a look at this? this fixes this bug.

@albertvillanova albertvillanova linked an issue Jun 10, 2025 that may be closed by this pull request
Copy link
Member

@albertvillanova albertvillanova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the proposed fix.

Just a general comment:

If I understand correctly, your proposed solution assumes that 2 consecutive tasks are related, so the 2nd task can skip planning if the first one has already handled it.

That makes sense in some scenarios, but what about if the second task is completely unrelated to the 1st one?

@Zoe14
Copy link
Contributor Author

Zoe14 commented Jun 10, 2025

The fix ensures that when an agent has reset to false and has previous memory (whether injected or restored), that memory is actually used during planning with the update planning prompt. Currently, the code checks step_number == 1 instead of checking for existing memory, so agent memory always gets ignored.
This doesn't change behavior when the reset flag is set to true, as before.
If tasks are unrelated, users simply shouldn't inject memory or restore agent state, or should set the reset flag to true. This fix is essential for any scenario where users want to persist and utilize agent state across runs.

@Zoe14 Zoe14 requested a review from albertvillanova June 10, 2025 17:24
Copy link
Member

@albertvillanova albertvillanova left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense, thanks for the clarification. The reasoning is sound, and the change looks good to me.

@albertvillanova albertvillanova merged commit 7a128db into huggingface:main Jun 17, 2025
3 checks passed
@@ -617,7 +617,8 @@ def _generate_planning_step(
}
],
}
input_messages = [plan_update_pre] + memory_messages + [plan_update_post]
# remove last message from memory_messages because it is the current task
input_messages = [plan_update_pre] + memory_messages[:-1] + [plan_update_post]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the last message from memory_messages isn't necessarily the current task; it could be an action step I believe?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[BUG] Agent memory not used when planning step
3 participants