-
Notifications
You must be signed in to change notification settings - Fork 5.5k
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
[ReAct][Robustness++] Avoid "Reached max iterations" errors by telling Agent how many steps are allowed #12426
base: main
Are you sure you want to change the base?
Conversation
@tslmy just curious, do you think this will influence the agent to run for all steps, rather than stopping when it is ready? Or what has your experience been like? |
@logan-markewich good question. I have not yet encountered a case where
only cases where
But I think that really owes to the lack of cases I tested & the low intelligence of the 7B LLMs I tried locally. |
@tslmy sorry for any delay here. I'm a tad worried about merging a change like this to the prompt. Would it better to use the error handling we added before to handle when max iterations is reached? |
No worries at all @logan-markewich . I barely have time to attend to my side projects during weekdays anyway. Let me try to convince you that this must go into the prompt. The whole point is to let the Agent know that it must take less than N steps to complete a task at the beginning, so that it can better plan out the procedure. The error handling won't cut it. Why? Let's suppose the Agent is at its (N+1)-th step out of N allowed steps. We raise an exception. The error handler catches it. The handler offers Agent a 2nd chance to fix it. The Agent tries something different, which would be the (N+2)-th step. We raise an exception. The error handler catches it. The handler offers Agent a 3rd chance to fix it... You see where this is going ;) I'm actually kinda OK to remove the "(X of Y steps)" part at every "Thought:" line, if that's what making you uncomfortable, because it only serves as a reminder of the LLM that "hey, you've consumed X steps out of your allowance of Y, so you gotta hurry up in your next Y-X steps". |
@tslmy Yea, you nailed it, the (1 of x) in the thought line was making me a tad nervous 👀 |
975452a
to
3680116
Compare
@logan-markewich no problem, Logan. I've updated the PR, removing the "(X of Y steps)" part at every "Thought:" line but keeping the "you should cap it at X steps" line. Does it look good to you? In my own projects, I always override the default prompt anyway, so no hard feelings. |
@tslmy, can you describe the behavior of agent if the max_iteration value is being set to 5? As per my understanding, Then out of 5 steps, agent will take
Is is the way it will work? |
Hi @CP-Geeky , When The agent will say,
which counts as one iteration. This action will yield an output. The agent will take a 2nd iteration to parse it:
The agent then takes a 3rd iteration to come up with a follow-up action:
This action will yield an output. The agent will take a 4th iteration to parse it:
The LLM is then invited to think over the current situation, which would be our 5th (and final) iteration. In this iteration, the LLM should notice (from the "step A out of B" prefixes it has been prepending to the thoughts) that it has run out of allowed steps. Thus, it should give up:
Note that some LLMs (and sometimes the same LLM) will treat the final "thought-answer" pair as a step, just like the "after" screenshot I pasted to the PR descrption. That's fine. |
Description
Fixes #12209 . TL;DR: Agent can avoid "Reached max iterations" problems if it has been told how many steps it can try.
New Package?
Not a new package.
Version Bump?
Not applicable.
Type of Change
Please delete options that are not relevant.
How Has This Been Tested?
Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration
Suggested Checklist:
make format; make lint
to appease the lint gods