A class that gives agent access to a partial view of the game state. NOTE: Instead of passing `game` directly as a reference to the agent, we create this interface instead to make the communication of game state more explicit and controlled. We go with this loose coupling to avoid
| 8 | |
| 9 | |
| 10 | class GameContext(BaseModel): |
| 11 | """ |
| 12 | A class that gives agent access to a partial view of the game state. |
| 13 | |
| 14 | NOTE: Instead of passing `game` directly as a reference to the agent, |
| 15 | we create this interface instead to make the communication of game state |
| 16 | more explicit and controlled. We go with this loose coupling to avoid |
| 17 | making the agent too dependent on the entire game object. |
| 18 | """ |
| 19 | |
| 20 | id: str |
| 21 | log_env: Path |
| 22 | log_local: Path |
| 23 | name: str |
| 24 | player_id: str |
| 25 | prompts: dict |
| 26 | round: int |
| 27 | rounds: int |
| 28 | working_dir: str |
| 29 | arena_description: str = "" |
| 30 | |
| 31 | def _render_prompt_templates(self) -> dict: |
| 32 | context = self.model_dump() |
| 33 | return {key: Template(template_str).render(**context) for key, template_str in self.prompts.items()} |
| 34 | |
| 35 | def to_template_vars(self) -> dict[str, str]: |
| 36 | """Convert the GameContext to a dictionary for rendering prompts in the agent""" |
| 37 | out = self.model_dump() | self._render_prompt_templates() |
| 38 | out.pop("prompts") |
| 39 | return out |
no outgoing calls
no test coverage detected