Skip to content

Commit 135c658

Browse files
committed
Enh/ref: Include notes on limit in config; simplify agent
Closes #27
1 parent 604dea2 commit 135c658

2 files changed

Lines changed: 11 additions & 30 deletions

File tree

codeclash/agents/minisweagent.py

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,13 @@
11
import logging
2-
import os
3-
import platform
42
import traceback
53
from collections.abc import Callable
6-
from dataclasses import asdict
74

8-
from jinja2 import Template
95
from minisweagent import Model
106
from minisweagent.agents.default import AgentConfig, DefaultAgent
117
from minisweagent.environments.docker import DockerEnvironment
128
from minisweagent.models import get_model
139
from minisweagent.models.test_models import DeterministicModel
1410
from minisweagent.run.utils.save import save_traj
15-
from rich.console import Console
1611

1712
from codeclash.agents.abstract import Player
1813
from codeclash.agents.utils import GameContext
@@ -29,38 +24,17 @@ def __init__(
2924
self,
3025
model: Model,
3126
env: DockerEnvironment,
32-
name: str,
33-
game_context: GameContext,
3427
*,
3528
logger: logging.Logger,
3629
config_class: Callable = AgentConfig,
3730
**kwargs,
3831
):
3932
super().__init__(model, env, config_class=config_class, **kwargs)
40-
self.name = name
41-
self.game_context = game_context
42-
self.console = Console()
4333
self.logger = logger
4434

4535
def add_message(self, role: str, content: str, **kwargs):
4636
super().add_message(role, content, **kwargs)
4737
self.logger.debug(f"[{role}] {content}", extra={"highlighter": None})
48-
if role == "assistant":
49-
self.logger.info(f"Step taken (step {self.model.n_calls}, cost {self.model.cost:.2f})")
50-
51-
def render_template(self, template: str, **kwargs) -> str:
52-
cs = (
53-
asdict(self.config)
54-
| asdict(self.env.config)
55-
| asdict(self.model.config)
56-
| platform.uname()._asdict()
57-
| self.game_context.to_template_vars()
58-
)
59-
return Template(template).render(**kwargs, **cs, **os.environ)
60-
61-
def run(self) -> tuple[str, str]:
62-
"""Run step() until agent is finished. Return exit status & message"""
63-
return super().run(task="")
6438

6539

6640
class MiniSWEAgent(Player):
@@ -78,15 +52,13 @@ def run(self):
7852
self.agent = ClashAgent(
7953
model=model,
8054
env=self.environment,
81-
name=self.name,
82-
game_context=self.game_context,
8355
logger=self.logger,
8456
**self.config["config"]["agent"],
8557
)
8658
exit_status = None
8759
result = None
8860
try:
89-
exit_status, result = self.agent.run()
61+
exit_status, result = self.agent.run(task="", **self.game_context.to_template_vars())
9062
except Exception as e:
9163
exit_status = str(e)
9264
exc_message = traceback.format_exc()

configs/mini/default.yaml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,14 @@ instance_template: |
3232
- `trajs/`: History of your edits
3333
- and a lot more. It's up to you to explore and utilize these resources.
3434
35-
The game is played in rounds. You won't remember past rounds.
35+
The game is played in rounds and you will be evaluated on the performance over all the rounds. You won't remember past rounds.
36+
37+
In every round, you have a limit of {{step_limit}} steps and a cost limit of {{cost_limit}} dollars.
38+
We will show you the number of steps and cost used so far after every response in the `<limit_note>` tag.
39+
After you've reached the step or cost limit, you cannot continue working on this task, and we will play the game with your codebase.
40+
This means that it's fine to reach the step or cost limit while working on documentation or testing, but you shouldn't
41+
reach the limit while working on the actual game logic to avoid submitting an invalid codebase.
42+
3643
So if you want to carry knowledge forward — leave tools, notes, or strategies in the codebase.
3744
Good documentation means you (and others) can pick up right where you left off.
3845
@@ -112,6 +119,7 @@ instance_template: |
112119
</example_response>
113120
114121
If you need to run multiple commands, either:
122+
115123
1. Combine them in one block using && or ||
116124
```bash
117125
command1 && command2 || echo "Error occurred"
@@ -179,6 +187,7 @@ instance_template: |
179187
This command will submit your work.
180188
You cannot continue working (reading, editing, testing) in any way on this task after submitting.
181189
action_observation_template: |
190+
<limit_note>This is the output of step {{n_model_calls}} ({{step_limit}} limit). You've used {{model_cost | round(2)}} USD ({{cost_limit}} USD limit).</limit_note>
182191
<returncode>{{output.returncode}}</returncode>
183192
{% if output.output | length < 10000 -%}
184193
<output>

0 commit comments

Comments
 (0)