1515
1616from codeclash .agents .abstract import Player
1717from codeclash .agents .utils import resolve_api_key
18- from codeclash .games .abstract import CodeGame
1918
2019
2120class ClashAgent (DefaultAgent ):
@@ -29,14 +28,14 @@ def __init__(
2928 model : Model ,
3029 env : Environment ,
3130 name : str ,
32- game : CodeGame ,
31+ format_vars : dict ,
3332 * ,
3433 config_class : Callable = AgentConfig ,
3534 ** kwargs ,
3635 ):
3736 super ().__init__ (model , env , config_class = config_class , ** kwargs )
3837 self .name = name
39- self .game = game
38+ self .format_vars = format_vars
4039 self .console = Console ()
4140
4241 def add_message (self , role : str , content : str , ** kwargs ):
@@ -52,10 +51,7 @@ def render_template(self, template: str, **kwargs) -> str:
5251 | asdict (self .env .config )
5352 | asdict (self .model .config )
5453 | platform .uname ()._asdict ()
55- | {
56- "rounds" : self .game .rounds ,
57- "round" : self .game .round ,
58- }
54+ | self .format_vars
5955 )
6056 return Template (template ).render (** kwargs , ** cs , ** os .environ )
6157
@@ -68,16 +64,16 @@ def run(self) -> tuple[str, str]:
6864class MiniSWEAgent (Player ):
6965 """Player with agentic code editing capabilities"""
7066
71- def __init__ (self , config : dict , game : CodeGame ):
72- super ().__init__ (config , game )
67+ def __init__ (self , config : dict , environment : Environment , format_vars : dict ):
68+ super ().__init__ (config , environment = environment , format_vars = format_vars )
7369 self .agent = ClashAgent (
7470 LitellmModel (
7571 model_name = config ["model" ],
7672 model_kwargs = {"api_key" : resolve_api_key (config ["model" ])},
7773 ),
78- self .container ,
74+ self .environment ,
7975 self .name ,
80- game ,
76+ format_vars ,
8177 ** yaml .safe_load (Path (config ["config" ]).read_text ())["agent" ],
8278 )
8379
@@ -94,7 +90,7 @@ def run(self):
9490 finally :
9591 save_traj (
9692 self .agent , # type: ignore
97- Path (f"{ self .name } _r{ self .game . round } .traj.json" ),
93+ Path (f"{ self .name } _r{ self .format_vars [ ' round' ] } .traj.json" ),
9894 exit_status = exit_status ,
9995 result = result ,
10096 )
0 commit comments