Skip to content

SWE-agent takes a GitHub issue and tries to automatically fix it, using your LM of choice. It can also be employed for offensive cybersecurity or competitive coding challenges. [NeurIPS 2024]

Enh: Make progress less jumpy with min lengths

Kilian Lieretec48293fd920
diff --git a/sweagent/agent/hooks/status.py b/sweagent/agent/hooks/status.py
index 52b14fa3..a2f80eff 100644
--- a/sweagent/agent/hooks/status.py
+++ b/sweagent/agent/hooks/status.py
@@ -16,7 +16,7 @@ class SetStatusAgentHook(AbstractAgentHook):
def on_step_start(self):
self._i_step += 1
- self._update(f"Step {self._i_step} (${self._cost:.2f})")
+ self._update(f"Step {self._i_step:<3} (${self._cost:.2f})")
def on_step_done(self, *, step: StepOutput, info: AgentInfo):
self._cost = info["model_stats"]["instance_cost"] # type: ignore
diff --git a/sweagent/run/_progress.py b/sweagent/run/_progress.py
index 59285969..b85d0e06 100644
--- a/sweagent/run/_progress.py
+++ b/sweagent/run/_progress.py
@@ -19,6 +19,11 @@ from rich.table import Table
from sweagent.agent.models import GLOBAL_STATS
+def _shorten_str(s: str, max_len: int) -> str:
+ s = s[: max_len - 3] + "..." if len(s) > max_len else s
+ return f"{s:<{max_len}}"
+
+
class RunBatchProgressManager:
def __init__(
self,
@@ -46,7 +51,7 @@ class RunBatchProgressManager:
)
self._task_progress_bar = Progress(
SpinnerColumn(),
- TextColumn("{task.fields[instance_id]}: "),
+ TextColumn("{task.fields[instance_id]}"),
TextColumn("{task.fields[status]}"),
TimeElapsedColumn(),
)
@@ -72,7 +77,7 @@ class RunBatchProgressManager:
t.show_header = True
# self._exit_status_table.rows.clear()
for status, instances in self._instances_by_exit_status.items():
- instances_str = ", ".join(reversed(instances))[:40] + "..."
+ instances_str = _shorten_str(", ".join(reversed(instances)), 40)
t.add_row(status, str(len(instances)), instances_str)
assert self.render_group is not None
self.render_group.renderables[0] = t
@@ -85,7 +90,11 @@ class RunBatchProgressManager:
assert self._task_progress_bar is not None
assert self._main_progress_bar is not None
with self._lock:
- self._task_progress_bar.update(self._spinner_tasks[instance_id], status=message, instance_id=instance_id)
+ self._task_progress_bar.update(
+ self._spinner_tasks[instance_id],
+ status=_shorten_str(message, 30),
+ instance_id=_shorten_str(instance_id, 25),
+ )
self._update_total_costs()
def on_instance_start(self, instance_id: str):
diff --git a/sweagent/run/run_batch.py b/sweagent/run/run_batch.py
index bc62ee45..d7ddda6c 100644
--- a/sweagent/run/run_batch.py
+++ b/sweagent/run/run_batch.py
@@ -160,9 +160,8 @@ class RunBatch:
)
self.logger.info(msg)
executor.shutdown(wait=False, cancel_futures=True)
- raise _BreakLoop
-
- self._progress_manager.print_report()
+ finally:
+ self._progress_manager.print_report()
def run_instance(self, instance: BatchInstance) -> None:
self._progress_manager.on_instance_start(instance.problem_statement.id)