mini-swe-agent 1.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (47) hide show
  1. mini_swe_agent-1.1.0.dist-info/METADATA +288 -0
  2. mini_swe_agent-1.1.0.dist-info/RECORD +47 -0
  3. mini_swe_agent-1.1.0.dist-info/WHEEL +5 -0
  4. mini_swe_agent-1.1.0.dist-info/entry_points.txt +5 -0
  5. mini_swe_agent-1.1.0.dist-info/licenses/LICENSE.md +21 -0
  6. mini_swe_agent-1.1.0.dist-info/top_level.txt +1 -0
  7. minisweagent/__init__.py +67 -0
  8. minisweagent/__main__.py +7 -0
  9. minisweagent/agents/__init__.py +1 -0
  10. minisweagent/agents/default.py +129 -0
  11. minisweagent/agents/interactive.py +148 -0
  12. minisweagent/agents/interactive_textual.py +324 -0
  13. minisweagent/config/README.md +9 -0
  14. minisweagent/config/__init__.py +24 -0
  15. minisweagent/config/__pycache__/__init__.cpython-313.pyc +0 -0
  16. minisweagent/config/default.yaml +143 -0
  17. minisweagent/config/extra/__init__.py +1 -0
  18. minisweagent/config/extra/swebench.yaml +229 -0
  19. minisweagent/config/github_issue.yaml +146 -0
  20. minisweagent/config/local.yaml +154 -0
  21. minisweagent/config/local2.tcss +128 -0
  22. minisweagent/environments/__init__.py +1 -0
  23. minisweagent/environments/docker.py +98 -0
  24. minisweagent/environments/extra/__init__.py +0 -0
  25. minisweagent/environments/extra/swerex_docker.py +39 -0
  26. minisweagent/environments/local.py +33 -0
  27. minisweagent/environments/singularity.py +52 -0
  28. minisweagent/models/__init__.py +81 -0
  29. minisweagent/models/anthropic.py +19 -0
  30. minisweagent/models/litellm_model.py +64 -0
  31. minisweagent/models/test_models.py +38 -0
  32. minisweagent/models/utils/cache_control.py +42 -0
  33. minisweagent/models/utils/key_per_thread.py +18 -0
  34. minisweagent/py.typed +0 -0
  35. minisweagent/run/__init__.py +1 -0
  36. minisweagent/run/extra/__init__.py +0 -0
  37. minisweagent/run/extra/config.py +100 -0
  38. minisweagent/run/extra/swebench.py +235 -0
  39. minisweagent/run/extra/swebench_single.py +53 -0
  40. minisweagent/run/extra/utils/batch_progress.py +164 -0
  41. minisweagent/run/github_issue.py +80 -0
  42. minisweagent/run/hello_world.py +36 -0
  43. minisweagent/run/inspector.py +212 -0
  44. minisweagent/run/mini.py +118 -0
  45. minisweagent/run/mini_extra.py +44 -0
  46. minisweagent/run/utils/__init__.py +0 -0
  47. minisweagent/run/utils/save.py +35 -0
@@ -0,0 +1,148 @@
1
+ """A small generalization of the default agent that puts the user in the loop.
2
+
3
+ There are three modes:
4
+ - human: commands issued by the user are executed immediately
5
+ - confirm: commands issued by the LM but not whitelisted are confirmed by the user
6
+ - yolo: commands issued by the LM are executed immediately without confirmation
7
+ """
8
+
9
+ import re
10
+ from dataclasses import dataclass, field
11
+ from typing import Literal
12
+
13
+ from prompt_toolkit.history import FileHistory
14
+ from prompt_toolkit.shortcuts import PromptSession
15
+ from rich.console import Console
16
+ from rich.rule import Rule
17
+
18
+ from minisweagent import global_config_dir
19
+ from minisweagent.agents.default import AgentConfig, DefaultAgent, LimitsExceeded, NonTerminatingException, Submitted
20
+
21
+ console = Console(highlight=False)
22
+ prompt_session = PromptSession(history=FileHistory(global_config_dir / "interactive_history.txt"))
23
+
24
+
25
+ @dataclass
26
+ class InteractiveAgentConfig(AgentConfig):
27
+ mode: Literal["human", "confirm", "yolo"] = "confirm"
28
+ """Whether to confirm actions."""
29
+ whitelist_actions: list[str] = field(default_factory=list)
30
+ """Never confirm actions that match these regular expressions."""
31
+
32
+
33
+ class InteractiveAgent(DefaultAgent):
34
+ _MODE_COMMANDS_MAPPING = {"/u": "human", "/c": "confirm", "/y": "yolo"}
35
+
36
+ def __init__(self, *args, **kwargs):
37
+ super().__init__(*args, config_class=InteractiveAgentConfig, **kwargs)
38
+ self.cost_last_confirmed = 0.0
39
+
40
+ def add_message(self, role: str, content: str):
41
+ # Extend supermethod to print messages
42
+ super().add_message(role, content)
43
+ if role == "assistant":
44
+ console.print(
45
+ f"\n[red][bold]mini-swe-agent[/bold] (step [bold]{self.model.n_calls}[/bold], [bold]${self.model.cost:.2f}[/bold]):[/red]\n",
46
+ end="",
47
+ highlight=False,
48
+ )
49
+ else:
50
+ console.print(f"\n[bold green]{role.capitalize()}[/bold green]:\n", end="", highlight=False)
51
+ console.print(content, highlight=False, markup=False)
52
+
53
+ def query(self) -> dict:
54
+ # Extend supermethod to handle human mode
55
+ if self.config.mode == "human":
56
+ match command := self._prompt_and_handle_special("[bold yellow]>[/bold yellow] "):
57
+ case "/y" | "/c": # Just go to the super query, which queries the LM for the next action
58
+ pass
59
+ case _:
60
+ return {"content": f"\n```bash\n{command}\n```"}
61
+ try:
62
+ with console.status("Waiting for the LM to respond..."):
63
+ return super().query()
64
+ except LimitsExceeded:
65
+ console.print(
66
+ f"Limits exceeded. Limits: {self.config.step_limit} steps, ${self.config.cost_limit}.\n"
67
+ f"Current spend: {self.model.n_calls} steps, ${self.model.cost:.2f}."
68
+ )
69
+ self.config.step_limit = int(input("New step limit: "))
70
+ self.config.cost_limit = float(input("New cost limit: "))
71
+ return super().query()
72
+
73
+ def step(self) -> dict:
74
+ # Override the step method to handle user interruption
75
+ try:
76
+ console.print(Rule())
77
+ return super().step()
78
+ except KeyboardInterrupt:
79
+ # We always add a message about the interrupt and then just proceed to the next step
80
+ interruption_message = self._prompt_and_handle_special(
81
+ "\n\n[bold yellow]Interrupted.[/bold yellow] "
82
+ "[green]Type a comment/command[/green] (/h for available commands)"
83
+ "\n[bold yellow]>[/bold yellow] "
84
+ ).strip()
85
+ if not interruption_message or interruption_message in self._MODE_COMMANDS_MAPPING:
86
+ interruption_message = "Temporary interruption caught."
87
+ raise NonTerminatingException(f"Interrupted by user: {interruption_message}")
88
+
89
+ def execute_action(self, action: dict) -> dict:
90
+ # Override the execute_action method to handle user confirmation
91
+ if self.should_ask_confirmation(action["action"]):
92
+ self.ask_confirmation()
93
+ return super().execute_action(action)
94
+
95
+ def should_ask_confirmation(self, action: str) -> bool:
96
+ return self.config.mode == "confirm" and not any(re.match(r, action) for r in self.config.whitelist_actions)
97
+
98
+ def ask_confirmation(self) -> None:
99
+ prompt = (
100
+ "[bold yellow]Execute?[/bold yellow] [green][bold]Enter[/bold] to confirm[/green], "
101
+ "or [green]Type a comment/command[/green] (/h for available commands)\n"
102
+ "[bold yellow]>[/bold yellow] "
103
+ )
104
+ match user_input := self._prompt_and_handle_special(prompt).strip():
105
+ case "" | "/y":
106
+ pass # confirmed, do nothing
107
+ case "/u": # Skip execution action and get back to query
108
+ raise NonTerminatingException("Command not executed. Switching to human mode")
109
+ case _:
110
+ raise NonTerminatingException(
111
+ f"Command not executed. The user rejected your command with the following message: {user_input}"
112
+ )
113
+
114
+ def _prompt_and_handle_special(self, prompt: str) -> str:
115
+ """Prompts the user, takes care of /h (followed by requery) and sets the mode. Returns the user input."""
116
+ console.print(prompt, end="")
117
+ user_input = prompt_session.prompt("")
118
+ if user_input == "/h":
119
+ console.print(
120
+ f"Current mode: [bold green]{self.config.mode}[/bold green]\n"
121
+ f"[bold green]/y[/bold green] to switch to [bold yellow]yolo[/bold yellow] mode (execute LM commands without confirmation)\n"
122
+ f"[bold green]/c[/bold green] to switch to [bold yellow]confirmation[/bold yellow] mode (ask for confirmation before executing LM commands)\n"
123
+ f"[bold green]/u[/bold green] to switch to [bold yellow]human[/bold yellow] mode (execute commands issued by the user)\n"
124
+ )
125
+ return self._prompt_and_handle_special(prompt)
126
+ if user_input in self._MODE_COMMANDS_MAPPING:
127
+ if self.config.mode == self._MODE_COMMANDS_MAPPING[user_input]:
128
+ return self._prompt_and_handle_special(
129
+ f"[bold red]Already in {self.config.mode} mode.[/bold red]\n{prompt}"
130
+ )
131
+ self.config.mode = self._MODE_COMMANDS_MAPPING[user_input]
132
+ console.print(f"Switched to [bold green]{self.config.mode}[/bold green] mode.")
133
+ return user_input
134
+ return user_input
135
+
136
+ def has_finished(self, output: dict[str, str]):
137
+ try:
138
+ return super().has_finished(output)
139
+ except Submitted as e:
140
+ console.print(
141
+ "[bold green]Agent wants to finish.[/bold green] "
142
+ "[green]Type a comment to give it a new task or press enter to quit.\n"
143
+ "[bold yellow]>[/bold yellow] ",
144
+ end="",
145
+ )
146
+ if new_task := self._prompt_and_handle_special("").strip():
147
+ raise NonTerminatingException(f"The user added a new task: {new_task}")
148
+ raise e
@@ -0,0 +1,324 @@
1
+ """
2
+ Extension of the `default.py` agent that uses Textual for an interactive TUI.
3
+ For a simpler version of an interactive UI that does not require threading and more, see `interactive.py`.
4
+ """
5
+
6
+ import logging
7
+ import os
8
+ import re
9
+ import threading
10
+ import time
11
+ from dataclasses import dataclass, field
12
+ from pathlib import Path
13
+ from typing import Literal
14
+
15
+ from rich.spinner import Spinner
16
+ from rich.text import Text
17
+ from textual.app import App, ComposeResult
18
+ from textual.binding import Binding
19
+ from textual.containers import Container, Vertical, VerticalScroll
20
+ from textual.css.query import NoMatches
21
+ from textual.events import Key
22
+ from textual.widgets import Footer, Header, Static, TextArea
23
+
24
+ from minisweagent.agents.default import AgentConfig, DefaultAgent, NonTerminatingException
25
+
26
+
27
+ @dataclass
28
+ class TextualAgentConfig(AgentConfig):
29
+ mode: Literal["confirm", "yolo"] = "confirm"
30
+ """Mode for action execution: 'confirm' requires user confirmation, 'yolo' executes immediately."""
31
+ whitelist_actions: list[str] = field(default_factory=list)
32
+ """Never confirm actions that match these regular expressions."""
33
+
34
+
35
+ class TextualAgent(DefaultAgent):
36
+ def __init__(self, app: "AgentApp", *args, **kwargs):
37
+ """Connects the DefaultAgent to the TextualApp."""
38
+ self.app = app
39
+ super().__init__(*args, config_class=TextualAgentConfig, **kwargs)
40
+
41
+ def add_message(self, role: str, content: str):
42
+ super().add_message(role, content)
43
+ if self.app.agent_state != "UNINITIALIZED":
44
+ self.app.call_from_thread(self.app.on_message_added)
45
+
46
+ def run(self, task: str) -> tuple[str, str]:
47
+ try:
48
+ exit_status, result = super().run(task)
49
+ except Exception as e:
50
+ result = str(e)
51
+ self.app.call_from_thread(self.app.on_agent_finished, "ERROR", result)
52
+ return "ERROR", result
53
+ else:
54
+ self.app.call_from_thread(self.app.on_agent_finished, exit_status, result)
55
+ return exit_status, result
56
+
57
+ def execute_action(self, action: dict) -> dict:
58
+ if self.config.mode == "confirm" and not any(
59
+ re.match(r, action["action"]) for r in self.config.whitelist_actions
60
+ ):
61
+ if result := self.app.confirmation_container.request_confirmation(action["action"]):
62
+ raise NonTerminatingException(f"Command not executed: {result}")
63
+ return super().execute_action(action)
64
+
65
+
66
+ class AddLogEmitCallback(logging.Handler):
67
+ def __init__(self, callback):
68
+ """Custom log handler that forwards messages via callback."""
69
+ super().__init__()
70
+ self.callback = callback
71
+
72
+ def emit(self, record: logging.LogRecord):
73
+ self.callback(record) # type: ignore[attr-defined]
74
+
75
+
76
+ def _messages_to_steps(messages: list[dict]) -> list[list[dict]]:
77
+ """Group messages into "pages" as shown by the UI."""
78
+ steps = []
79
+ current_step = []
80
+ for message in messages:
81
+ current_step.append(message)
82
+ if message["role"] == "user":
83
+ steps.append(current_step)
84
+ current_step = []
85
+ if current_step:
86
+ steps.append(current_step)
87
+ return steps
88
+
89
+
90
+ class ConfirmationPromptContainer(Container):
91
+ def __init__(self, app: "AgentApp"):
92
+ """This class is responsible for handling the action execution confirmation."""
93
+ super().__init__(id="confirmation-container")
94
+ self._app = app
95
+ self.rejecting = False
96
+ self.can_focus = True
97
+ self.display = False
98
+
99
+ self._pending_action: str | None = None
100
+ self._confirmation_event = threading.Event()
101
+ self._confirmation_result: str | None = None
102
+
103
+ def compose(self) -> ComposeResult:
104
+ yield Static(
105
+ "Press [bold]ENTER[/bold] to confirm action or [bold]BACKSPACE[/bold] to reject (or [bold]y[/bold] to toggle YOLO mode)",
106
+ classes="confirmation-prompt",
107
+ )
108
+ yield TextArea(id="rejection-input")
109
+ rejection_help = Static(
110
+ "Press [bold]Ctrl+D[/bold] to submit rejection message",
111
+ id="rejection-help",
112
+ classes="rejection-help",
113
+ )
114
+ rejection_help.display = False
115
+ yield rejection_help
116
+
117
+ def request_confirmation(self, action: str) -> str | None:
118
+ """Request confirmation for an action. Returns rejection message or None."""
119
+ self._confirmation_event.clear()
120
+ self._confirmation_result = None
121
+ self._pending_action = action
122
+ self._app.call_from_thread(self._app.update_content)
123
+ self._confirmation_event.wait()
124
+ return self._confirmation_result
125
+
126
+ def _complete_confirmation(self, rejection_message: str | None):
127
+ """Internal method to complete the confirmation process."""
128
+ self._confirmation_result = rejection_message
129
+ self._pending_action = None
130
+ self.display = False
131
+ self.rejecting = False
132
+ rejection_input = self.query_one("#rejection-input", TextArea)
133
+ rejection_input.display = False
134
+ rejection_input.text = ""
135
+ rejection_help = self.query_one("#rejection-help", Static)
136
+ rejection_help.display = False
137
+ # Reset agent state to RUNNING after confirmation is completed
138
+ if rejection_message is None:
139
+ self._app.agent_state = "RUNNING"
140
+ self._confirmation_event.set()
141
+ self._app.update_content()
142
+
143
+ def on_key(self, event: Key) -> None:
144
+ if self.rejecting and event.key == "ctrl+d":
145
+ event.prevent_default()
146
+ rejection_input = self.query_one("#rejection-input", TextArea)
147
+ self._complete_confirmation(rejection_input.text)
148
+ return
149
+ if not self.rejecting:
150
+ if event.key == "enter":
151
+ event.prevent_default()
152
+ self._complete_confirmation(None)
153
+ elif event.key == "backspace":
154
+ event.prevent_default()
155
+ self.rejecting = True
156
+ rejection_input = self.query_one("#rejection-input", TextArea)
157
+ rejection_input.display = True
158
+ rejection_input.focus()
159
+ rejection_help = self.query_one("#rejection-help", Static)
160
+ rejection_help.display = True
161
+
162
+
163
+ class AgentApp(App):
164
+ BINDINGS = [
165
+ Binding("right,l", "next_step", "Step++"),
166
+ Binding("left,h", "previous_step", "Step--"),
167
+ Binding("0", "first_step", "Step=0"),
168
+ Binding("$", "last_step", "Step=-1"),
169
+ Binding("j,down", "scroll_down", "Scroll down"),
170
+ Binding("k,up", "scroll_up", "Scroll up"),
171
+ Binding("q", "quit", "Quit"),
172
+ Binding("y", "yolo", "Switch to YOLO Mode"),
173
+ Binding("c", "confirm", "Switch to Confirm Mode"),
174
+ ]
175
+
176
+ def __init__(self, model, env, task: str, **kwargs):
177
+ css_path = os.environ.get(
178
+ "MSWEA_LOCAL2_STYLE_PATH", str(Path(__file__).parent.parent / "config" / "local2.tcss")
179
+ )
180
+ self.__class__.CSS = Path(css_path).read_text()
181
+ super().__init__()
182
+ self.agent_state = "UNINITIALIZED"
183
+ self.agent_task = task
184
+ self.agent = TextualAgent(self, model=model, env=env, **kwargs)
185
+ self._i_step = 0
186
+ self.n_steps = 1
187
+ self.confirmation_container = ConfirmationPromptContainer(self)
188
+ self.log_handler = AddLogEmitCallback(lambda record: self.call_from_thread(self.on_log_message_emitted, record))
189
+ logging.getLogger().addHandler(self.log_handler)
190
+ self._spinner = Spinner("dots")
191
+ self.exit_status: str | None = None
192
+ self.result: str | None = None
193
+
194
+ # --- Basics ---
195
+
196
+ @property
197
+ def i_step(self) -> int:
198
+ """Current step index."""
199
+ return self._i_step
200
+
201
+ @i_step.setter
202
+ def i_step(self, value: int) -> None:
203
+ """Set current step index, automatically clamping to valid bounds."""
204
+ if value != self._i_step:
205
+ self._i_step = max(0, min(value, self.n_steps - 1))
206
+ self.query_one(VerticalScroll).scroll_to(y=0, animate=False)
207
+ self.update_content()
208
+
209
+ def compose(self) -> ComposeResult:
210
+ yield Header()
211
+ with Container(id="main"):
212
+ with VerticalScroll():
213
+ yield Vertical(id="content")
214
+ yield self.confirmation_container
215
+ yield Footer()
216
+
217
+ def on_mount(self) -> None:
218
+ self.agent_state = "RUNNING"
219
+ self.update_content()
220
+ self.set_interval(1 / 8, self._update_headers)
221
+ threading.Thread(target=lambda: self.agent.run(self.agent_task), daemon=True).start()
222
+
223
+ # --- Reacting to events ---
224
+
225
+ def on_message_added(self) -> None:
226
+ vs = self.query_one(VerticalScroll)
227
+ auto_follow = self.i_step == self.n_steps - 1 and vs.scroll_target_y <= 1
228
+ self.n_steps = len(_messages_to_steps(self.agent.messages))
229
+ self.update_content()
230
+ if auto_follow:
231
+ self.action_last_step()
232
+
233
+ def on_log_message_emitted(self, record: logging.LogRecord) -> None:
234
+ """Handle log messages of warning level or higher by showing them as notifications."""
235
+ if record.levelno >= logging.WARNING:
236
+ self.notify(f"[{record.levelname}] {record.getMessage()}", severity="warning")
237
+
238
+ def on_unmount(self) -> None:
239
+ """Clean up the log handler when the app shuts down."""
240
+ if hasattr(self, "log_handler"):
241
+ logging.getLogger().removeHandler(self.log_handler)
242
+
243
+ def on_agent_finished(self, exit_status: str, result: str):
244
+ self.agent_state = "STOPPED"
245
+ self.notify(f"Agent finished with status: {exit_status}")
246
+ self.exit_status = exit_status
247
+ self.result = result
248
+ self.update_content()
249
+
250
+ # --- UI update logic ---
251
+
252
+ def update_content(self) -> None:
253
+ container = self.query_one("#content", Vertical)
254
+ container.remove_children()
255
+ items = _messages_to_steps(self.agent.messages)
256
+
257
+ if not items:
258
+ container.mount(Static("Waiting for agent to start..."))
259
+ return
260
+
261
+ for message in items[self.i_step]:
262
+ if isinstance(message["content"], list):
263
+ content_str = "\n".join([item["text"] for item in message["content"]])
264
+ else:
265
+ content_str = str(message["content"])
266
+ message_container = Vertical(classes="message-container")
267
+ container.mount(message_container)
268
+ role = message["role"].replace("assistant", "mini-swe-agent")
269
+ message_container.mount(Static(role.upper(), classes="message-header"))
270
+ message_container.mount(Static(Text(content_str, no_wrap=False), classes="message-content"))
271
+
272
+ if self.confirmation_container._pending_action is not None:
273
+ self.agent_state = "AWAITING_CONFIRMATION"
274
+ self.confirmation_container.display = (
275
+ self.confirmation_container._pending_action is not None and self.i_step == len(items) - 1
276
+ )
277
+ if self.confirmation_container.display:
278
+ self.confirmation_container.focus()
279
+
280
+ self._update_headers()
281
+ self.refresh()
282
+
283
+ def _update_headers(self) -> None:
284
+ """Update just the title with current state and spinner if needed."""
285
+ status_text = self.agent_state
286
+ if self.agent_state == "RUNNING":
287
+ spinner_frame = str(self._spinner.render(time.time())).strip()
288
+ status_text = f"{self.agent_state} {spinner_frame}"
289
+ self.title = f"Step {self.i_step + 1}/{self.n_steps} - {status_text} - Cost: ${self.agent.model.cost:.2f}"
290
+ try:
291
+ self.query_one("Header").set_class(self.agent_state == "RUNNING", "running")
292
+ except NoMatches: # might be called when shutting down
293
+ pass
294
+
295
+ # --- Textual bindings ---
296
+
297
+ def action_yolo(self):
298
+ self.agent.config.mode = "yolo"
299
+ self.confirmation_container._complete_confirmation(None)
300
+ self.notify("YOLO mode enabled - actions will execute immediately")
301
+
302
+ def action_confirm(self):
303
+ self.agent.config.mode = "confirm"
304
+ self.notify("Confirm mode enabled - actions will require confirmation")
305
+
306
+ def action_next_step(self) -> None:
307
+ self.i_step += 1
308
+
309
+ def action_previous_step(self) -> None:
310
+ self.i_step -= 1
311
+
312
+ def action_first_step(self) -> None:
313
+ self.i_step = 0
314
+
315
+ def action_last_step(self) -> None:
316
+ self.i_step = self.n_steps - 1
317
+
318
+ def action_scroll_down(self) -> None:
319
+ vs = self.query_one(VerticalScroll)
320
+ vs.scroll_to(y=vs.scroll_target_y + 15)
321
+
322
+ def action_scroll_up(self) -> None:
323
+ vs = self.query_one(VerticalScroll)
324
+ vs.scroll_to(y=vs.scroll_target_y - 15)
@@ -0,0 +1,9 @@
1
+ # Configs
2
+
3
+ * `local.yaml` - Default config for `mini`/`agents/interactive.py` or `mini -v`/`agents/interactive_textual.py` agent.
4
+ * `default.yaml` - Default config for the `default.py` agent.
5
+ * `github_issue.yaml` - Config for the `run/github_issue.py` entry point.
6
+
7
+ ## Extras
8
+
9
+ * `extra/swebench.yaml` - Config for the `run/extra/swebench.py` entry point.
@@ -0,0 +1,24 @@
1
+ """Configuration files and utilities for mini-SWE-agent."""
2
+
3
+ import os
4
+ from pathlib import Path
5
+
6
+ builtin_config_dir = Path(__file__).parent
7
+
8
+
9
+ def get_config_path(config_spec: str | Path) -> Path:
10
+ """Get the path to a config file."""
11
+ candidates = [
12
+ Path(config_spec),
13
+ Path(os.getenv("MSWEA_CONFIG_DIR", ".")) / config_spec,
14
+ builtin_config_dir / config_spec,
15
+ builtin_config_dir / "extra" / config_spec,
16
+ ]
17
+ for candidate in candidates:
18
+ if candidate.exists():
19
+ return candidate
20
+
21
+ raise FileNotFoundError(f"Could not find config file for {config_spec} (tried: {candidates})")
22
+
23
+
24
+ __all__ = ["builtin_config_dir", "get_config_path"]
@@ -0,0 +1,143 @@
1
+ agent:
2
+ system_template: |
3
+ You are a helpful assistant that can interact with a computer.
4
+
5
+ Your response must contain exactly ONE bash code block with ONE command (or commands connected with && or ||).
6
+ Include a THOUGHT section before your command where you explain your reasoning process.
7
+ Format your response as shown in <format_example>.
8
+
9
+ <format_example>
10
+ Your reasoning and analysis here. Explain why you want to perform the action.
11
+
12
+ ```bash
13
+ your_command_here
14
+ ```
15
+ </format_example>
16
+
17
+ Failure to follow these rules will cause your response to be rejected.
18
+ To finish, issue the following command: `echo MINI_SWE_AGENT_FINAL_OUTPUT`
19
+ without any other command.
20
+ instance_template: |
21
+ Please solve this issue: {{task}}
22
+
23
+ You can execute bash commands and edit files to implement the necessary changes.
24
+
25
+ ## Recommended Workflow
26
+ 1. Analyze the codebase by finding and reading relevant files
27
+ 2. Create a script to reproduce the issue
28
+ 3. Edit the source code to resolve the issue
29
+ 4. Verify your fix works by running your script again
30
+ 5. Test edge cases to ensure your fix is robust
31
+
32
+ ## Important Rules
33
+
34
+ 1. Every response must contain exactly one action
35
+ 2. The action must be enclosed in triple backticks
36
+ 3. Directory or environment variable changes are not persistent. Every action is executed in a new subshell.
37
+ However, you can prefix any action with `MY_ENV_VAR=MY_VALUE cd /path/to/working/dir && ...` or write/load environment variables from files
38
+ 4. To finish, issue the following command: `echo MINI_SWE_AGENT_FINAL_OUTPUT`.
39
+ Do not combine it with any other command.
40
+
41
+ ## Formatting your response
42
+
43
+ Here is an example of a correct response:
44
+
45
+ <example_response>
46
+ THOUGHT: I need to understand the structure of the repository first. Let me check what files are in the current directory to get a better understanding of the codebase.
47
+
48
+ ```bash
49
+ ls -la
50
+ ```
51
+ </example_response>
52
+
53
+ ## Useful command examples
54
+
55
+ ### Create a new file:
56
+
57
+ ```bash
58
+ cat <<'EOF' > newfile.py
59
+ import numpy as np
60
+ hello = "world"
61
+ print(hello)
62
+ EOF
63
+ ```
64
+
65
+ ### Edit files with sed:
66
+
67
+ ```bash
68
+ # Replace all occurrences
69
+ sed -i 's/old_string/new_string/g' filename.py
70
+
71
+ # Replace only first occurrence
72
+ sed -i 's/old_string/new_string/' filename.py
73
+
74
+ # Replace first occurrence on line 1
75
+ sed -i '1s/old_string/new_string/' filename.py
76
+
77
+ # Replace all occurrences in lines 1-10
78
+ sed -i '1,10s/old_string/new_string/g' filename.py
79
+ ```
80
+
81
+ ### View file content:
82
+
83
+ ```bash
84
+ # View specific lines with numbers
85
+ nl -ba filename.py | sed -n '10,20p'
86
+ ```
87
+
88
+ ### Any other command you want to run
89
+
90
+ ```bash
91
+ anything
92
+ ```
93
+ action_observation_template: |
94
+ <returncode>{{output.returncode}}</returncode>
95
+ {% if output.output | length < 10000 -%}
96
+ <output>
97
+ {{ output.output -}}
98
+ </output>
99
+ {%- else -%}
100
+ <warning>
101
+ The output of your last command was too long.
102
+ Please try a different command that produces less output.
103
+ If you're looking at a file you can try use head, tail or sed to view a smaller number of lines selectively.
104
+ If you're using grep or find and it produced too much output, you can use a more selective search pattern.
105
+ If you really need to see something from the full command's output, you can redirect output to a file and then search in that file.
106
+ </warning>
107
+ {%- set elided_chars = output.output | length - 10000 -%}
108
+ <output_head>
109
+ {{ output.output[:5000] }}
110
+ </output_head>
111
+ <elided_chars>
112
+ {{ elided_chars }} characters elided
113
+ </elided_chars>
114
+ <output_tail>
115
+ {{ output.output[-5000:] }}
116
+ </output_tail>
117
+ {%- endif -%}
118
+ format_error_template: |
119
+ Please always provide EXACTLY ONE action in triple backticks, found {{actions|length}} actions.
120
+ If you want to end the task, please issue the following command: `echo MINI_SWE_AGENT_FINAL_OUTPUT`
121
+ without any other command.
122
+ Else, please format your response exactly as follows:
123
+
124
+ <response_example>
125
+ Here are some thoughts about why you want to perform the action.
126
+
127
+ ```bash
128
+ <action>
129
+ ```
130
+ </response_example>
131
+ step_limit: 0.
132
+ cost_limit: 0.
133
+ environment:
134
+ env:
135
+ PAGER: cat
136
+ MANPAGER: cat
137
+ LESS: -R
138
+ PIP_PROGRESS_BAR: 'off'
139
+ TQDM_DISABLE: '1'
140
+ model:
141
+ model_kwargs:
142
+ temperature: 0.0
143
+ drop_params: true
@@ -0,0 +1 @@
1
+ """Extra configuration files for mini-SWE-agent."""