(self, observation: dict[str, Any])
| 283 | self._start_worker() |
| 284 | |
| 285 | def decide(self, observation: dict[str, Any]) -> dict[str, Any]: |
| 286 | if self.disabled: |
| 287 | return {} |
| 288 | event = str(observation.get("event", "unknown")) |
| 289 | if self.startup_error is not None: |
| 290 | self._record_error(event, self.startup_error) |
| 291 | if not self.disabled: |
| 292 | self.restart() |
| 293 | return {} |
| 294 | request_id = self._next_request_id |
| 295 | self._next_request_id += 1 |
| 296 | self.command_queue.put({"request_id": request_id, "observation": observation}) |
| 297 | try: |
| 298 | result = self.result_queue.get(timeout=self.timeout) |
| 299 | except queue.Empty: |
| 300 | self._record_error(event, f"decide exceeded {self.timeout}s timeout") |
| 301 | if not self.disabled: |
| 302 | self.restart() |
| 303 | return {} |
| 304 | |
| 305 | if result.get("request_id") not in {request_id, None}: |
| 306 | self._record_error(event, "received stale policy result") |
| 307 | return {} |
| 308 | if "error" in result: |
| 309 | self._record_error(event, result["error"]) |
| 310 | if result.get("request_id") is None and not self.disabled: |
| 311 | self.restart() |
| 312 | return {} |
| 313 | decision = result.get("decision") |
| 314 | if decision is None: |
| 315 | self.decisions += 1 |
| 316 | return {} |
| 317 | if not isinstance(decision, dict): |
| 318 | self._record_error(event, "decide must return a dictionary or None", invalid=True) |
| 319 | return {} |
| 320 | self.decisions += 1 |
| 321 | return decision |
| 322 | |
| 323 | |
| 324 | def build_agent_class(player_name: str, path: str, *, decision_timeout: float, max_policy_errors: int): |
no test coverage detected