Skip to content

Adds MaxStepsCallback to stop the execution after a predefined number of steps#244

Open
philipph-askui wants to merge 9 commits intomainfrom
feat/max_steps
Open

Adds MaxStepsCallback to stop the execution after a predefined number of steps#244
philipph-askui wants to merge 9 commits intomainfrom
feat/max_steps

Conversation

@philipph-askui
Copy link
Contributor

also moves all callbacks to askui.callbacks so that they can be imported and discovered easier.

```python
from askui import ComputerAgent, MaxStepsCallback

with ComputerAgent(callbacks=[MaxStepsCallback(max_steps=10)]) as agent:
Copy link
Collaborator

Choose a reason for hiding this comment

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

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is there a reason why it should not be allowed to do so?

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
)
Copy link
Collaborator

Choose a reason for hiding this comment

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

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"

Copy link
Contributor Author

@philipph-askui philipph-askui Mar 10, 2026

Choose a reason for hiding this comment

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

@programminx-askui
answer to both: to align with the AutomationError class it inherits from.
same as for example the MaxTokensExceededError

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.

2 participants