1515from rich .console import Console
1616
1717from codeclash .agents .abstract import Player
18- from codeclash .agents .utils import resolve_api_key
18+ from codeclash .agents .utils import GameContext , resolve_api_key
1919from codeclash .constants import DIR_LOGS
20+ from codeclash .utils .environment import copy_file_to_container
2021
2122
2223class ClashAgent (DefaultAgent ):
@@ -30,15 +31,15 @@ def __init__(
3031 model : Model ,
3132 env : Environment ,
3233 name : str ,
33- template_vars : dict ,
34+ game_context : GameContext ,
3435 * ,
3536 logger : logging .Logger ,
3637 config_class : Callable = AgentConfig ,
3738 ** kwargs ,
3839 ):
3940 super ().__init__ (model , env , config_class = config_class , ** kwargs )
4041 self .name = name
41- self .template_vars = template_vars
42+ self .game_context = game_context
4243 self .console = Console ()
4344 self .logger = logger
4445
@@ -56,7 +57,7 @@ def render_template(self, template: str, **kwargs) -> str:
5657 | asdict (self .env .config )
5758 | asdict (self .model .config )
5859 | platform .uname ()._asdict ()
59- | self .template_vars
60+ | self .game_context . to_dict ()
6061 )
6162 return Template (template ).render (** kwargs , ** cs , ** os .environ )
6263
@@ -68,16 +69,18 @@ def run(self) -> tuple[str, str]:
6869class MiniSWEAgent (Player ):
6970 """Player with agentic code editing capabilities"""
7071
71- def __init__ (self , config : dict , environment : Environment , template_vars : dict ):
72- super ().__init__ (config , environment = environment , template_vars = template_vars )
72+ def __init__ (
73+ self , config : dict , environment : Environment , game_context : GameContext
74+ ):
75+ super ().__init__ (config , environment = environment , game_context = game_context )
7376 self .agent = ClashAgent (
7477 LitellmModel (
7578 model_name = config ["model" ],
7679 model_kwargs = {"api_key" : resolve_api_key (config ["model" ])},
7780 ),
7881 self .environment ,
7982 self .name ,
80- template_vars ,
83+ game_context ,
8184 logger = self .logger ,
8285 ** yaml .safe_load (Path (config ["config" ]).read_text ())["agent" ],
8386 )
@@ -93,11 +96,16 @@ def run(self):
9396 result = exc_message
9497 print (exc_message )
9598 finally :
99+ traj_path = (
100+ DIR_LOGS
101+ / self .game_context .id
102+ / f"{ self .name } _r{ self .game_context .round } .traj.json"
103+ )
96104 save_traj (
97105 self .agent , # type: ignore
98- DIR_LOGS
99- / f"{ self .template_vars ['game_id' ]} /{ self .name } _r{ self .template_vars ['round' ]} .traj.json" ,
106+ traj_path ,
100107 exit_status = exit_status ,
101108 result = result ,
102109 )
110+ copy_file_to_container (self .environment , traj_path , traj_path )
103111 self .commit ()
0 commit comments