-
Notifications
You must be signed in to change notification settings - Fork 267
Enh: Allow extending cost limit in textual UI #567
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?
Changes from 2 commits
8e49de1
b6ab515
f780b10
a1bce59
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -24,7 +24,7 @@ | |
| from textual.screen import Screen | ||
| from textual.widgets import Footer, Header, Input, Static, TextArea | ||
|
|
||
| from minisweagent.agents.default import AgentConfig, DefaultAgent, NonTerminatingException, Submitted | ||
| from minisweagent.agents.default import AgentConfig, DefaultAgent, LimitsExceeded, NonTerminatingException, Submitted | ||
|
|
||
|
|
||
| @dataclass | ||
|
|
@@ -57,7 +57,33 @@ def query(self) -> dict: | |
| self.add_message("assistant", msg["content"]) | ||
| return msg | ||
| self._current_action_from_human = False | ||
| return super().query() | ||
| try: | ||
| return super().query() | ||
| except LimitsExceeded: | ||
| # Show current limits and prompt for new ones (matching interactive.py behavior) | ||
| # Show notification with the limits info | ||
| self.app.notify( | ||
| f"Limits exceeded. Limit: ${self.config.cost_limit:.2f}. " | ||
| f"Current: {self.model.n_calls} steps, ${self.model.cost:.2f}.", | ||
| severity="warning", | ||
| timeout=10, | ||
| ) | ||
|
|
||
| # First prompt: new step limit (short message near input) | ||
| new_step_limit = self.app.input_container.request_input("New step limit:", placeholder="0 for unlimited") | ||
| try: | ||
| self.config.step_limit = int(new_step_limit) if new_step_limit.strip() else 0 | ||
| except ValueError: | ||
| self.config.step_limit = 0 | ||
|
||
|
|
||
| # Second prompt: new cost limit (short message near input) | ||
| new_cost_limit = self.app.input_container.request_input("New cost limit:", placeholder="0.0 for unlimited") | ||
| try: | ||
| self.config.cost_limit = float(new_cost_limit) if new_cost_limit.strip() else 0.0 | ||
| except ValueError: | ||
| self.config.cost_limit = 0.0 | ||
|
|
||
| return super().query() | ||
|
|
||
| def run(self, task: str, **kwargs) -> tuple[str, str]: | ||
| try: | ||
|
|
@@ -162,12 +188,14 @@ def on_focus(self) -> None: | |
| else: | ||
| self._single_input.focus() | ||
|
|
||
| def request_input(self, prompt: str) -> str: | ||
| def request_input(self, prompt: str, placeholder: str | None = None) -> str: | ||
| """Request input from user. Returns input text (empty string if confirmed without reason).""" | ||
| self._input_event.clear() | ||
| self._input_result = None | ||
| self.pending_prompt = prompt | ||
| self._header_display.update(prompt) | ||
| if placeholder: | ||
| self._single_input.placeholder = placeholder | ||
| self._update_mode_display() | ||
| self._app.call_from_thread(self._app.update_content) | ||
| self._input_event.wait() | ||
|
|
||
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.
Can we move that into the prompt, i.e., the first prompt is
"Some limit was exceeded. Current number of steps xx, current limit yy. Enter new limit (0 for unconstrained)"
and I expect that the step limit is probably always 0, so it might be good to test if "step limit == 0" (we skip asking for a new step limit, because that's not the one we blew).
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.
Okay, great, let's move that to the prompt, leave the placeholder as it was, and remove the notification for simplicity. Yes, it makes sense that the step limit probably is always 0, so let's add an if statement for that.