-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Improve error messaging for short output token lengths #1790
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
base: main
Are you sure you want to change the base?
Conversation
src/smolagents/utils.py
Outdated
return json_data, json_blob[:first_accolade_index] | ||
except IndexError: | ||
raise ValueError("The model output does not contain any JSON blob.") | ||
raise ValueError("The model output does not contain any JSON blob. Try increasing the maximum output token length.") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For the tool calling agent, I've added some details to the error message. This gets fed back to the ReAct loop but only the user can edit the model parameters. Maybe we should print it at the end of the trace?
For the CodeAgent, Shall I add a similar error in parse_code_blobs
?
smolagents/src/smolagents/utils.py
Line 224 in f76dee1
Your code snippet is invalid, because the regex pattern {code_block_tags[0]}(.*?){code_block_tags[1]} was not found in it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should print it at the end of the trace?
Actually thinking again, we shouldn't pass this part to the ReAct loop. It could confuse the model
Maybe print a warning message that doesn't get added to the agent's memory
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we shouldn't pass this part to the ReAct loop. It could confuse the model
Modified the code to print a warning. The warning wont get added to the error and hence shouldn't get added to the agent's memory.
It won't be visible to the LLM in the next steps
smolagents/src/smolagents/agents.py
Line 596 in f042c0c
action_step.error = e |
Perhaps in the "How to debug your agent" section, We could add another point 5. Increase token lengthIf you experience issues with parsing code (for CodeAgents) or JSON objects (for ToolCallingAgents) like the following, it could be due to insufficient output token length. Please adjust your model's parameters accordingly.
for ToolCallingAgents and
for CodeAgents |
cc: @albertvillanova (For review) |
I think this is indeed the best way to go! It's more future-proof |
"Here is an invalid code snippet `x = 10", | ||
], | ||
) | ||
def test_parse_code_blobs_without_valid_code(raw_text): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Added some simple tests to check the exact string. If the error message is changed in parse_code_blobs
or parse_json_blob
the note in the failing test will serve as a reminder to change the logic in agents.py
level=level, | ||
) | ||
|
||
def log_warning(self, title: str, level: int = LogLevel.INFO) -> None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@aymeric-roucher thanks for the comments on the PR |
When the output token length is smaller than required for a particular use case, the user sees parsing errors. It is unclear to them that the issue might be with the shorter token length. They might see errors like
for ToolCallingAgents and
for CodeAgents
Issues: #1783, #1732, etc. There are older threads were the issue is mentioned. #201 (comment), Workaround was to increase the output tokens
It is also mentioned that longer contexts are better in an example in the docs
smolagents/docs/source/en/guided_tour.md
Line 189 in f76dee1
This PR tries to
Testing
After the change it should look something like this. (For the screenshot I simulated the situation by modifying the code flow on my local setup)
