Adds MaxStepsCallback to stop the execution after a predefined number of steps#244
Open
philipph-askui wants to merge 9 commits intomainfrom
Open
Adds MaxStepsCallback to stop the execution after a predefined number of steps#244philipph-askui wants to merge 9 commits intomainfrom
philipph-askui wants to merge 9 commits intomainfrom
Conversation
… number of steps
… with `from askui.callbacks import ...`
programminx-askui
requested changes
Mar 10, 2026
docs/11_callbacks.md
Outdated
| ```python | ||
| from askui import ComputerAgent, MaxStepsCallback | ||
|
|
||
| with ComputerAgent(callbacks=[MaxStepsCallback(max_steps=10)]) as agent: |
Collaborator
There was a problem hiding this comment.
We should talk about if a Callback is allowed to throw an exception and manipulate the controll flow. or should this be an parameter of the agentic loop
Contributor
Author
There was a problem hiding this comment.
Is there a reason why it should not be allowed to do so?
src/askui/models/exceptions.py
Outdated
Comment on lines
+159
to
+165
| def __init__(self, max_steps: int, message: str | None = None): | ||
| self.max_steps = max_steps | ||
| error_msg = ( | ||
| f"Agent stopped due to reaching maximum step limit of {max_steps} steps" | ||
| if message is None | ||
| else message | ||
| ) |
Collaborator
There was a problem hiding this comment.
Why should I want to pass an extra message into the MaxStepsReachedError
-> Why is it called Error? and not exception? inside the expecptions.py
Suggested change
| def __init__(self, max_steps: int, message: str | None = None): | |
| self.max_steps = max_steps | |
| error_msg = ( | |
| f"Agent stopped due to reaching maximum step limit of {max_steps} steps" | |
| if message is None | |
| else message | |
| ) | |
| def __init__(self, max_steps: int): | |
| self.max_steps = max_steps | |
| error_msg = | |
| f"Agent stopped due to reaching maximum step limit of {max_steps} steps" |
Contributor
Author
There was a problem hiding this comment.
@programminx-askui
answer to both: to align with the AutomationError class it inherits from.
same as for example the MaxTokensExceededError
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
also moves all callbacks to askui.callbacks so that they can be imported and discovered easier.