{"record":{"id":"00e9dfcbe5066e78","repo":"Unity-Technologies/ml-agents","slug":"agent-id-is-did-not-request-a-decision-at-the-p","errorCode":null,"errorMessage":"agent_id {} is did not request a decision at the previous step","messagePattern":"agent_id (.+?) is did not request a decision at the previous step","errorType":"exception","errorClass":"IndexError","httpStatus":null,"severity":"error","filePath":"ml-agents-envs/mlagents_envs/environment.py","lineNumber":392,"sourceCode":"        self._env_actions[behavior_name] = action\n\n    def set_action_for_agent(\n        self, behavior_name: BehaviorName, agent_id: AgentId, action: ActionTuple\n    ) -> None:\n        self._assert_behavior_exists(behavior_name)\n        if behavior_name not in self._env_state:\n            return\n        action_spec = self._env_specs[behavior_name].action_spec\n        action = action_spec._validate_action(action, 1, behavior_name)\n        if behavior_name not in self._env_actions:\n            num_agents = len(self._env_state[behavior_name][0])\n            self._env_actions[behavior_name] = action_spec.empty_action(num_agents)\n        try:\n            index = np.where(self._env_state[behavior_name][0].agent_id == agent_id)[0][\n                0\n            ]\n        except IndexError as ie:\n            raise IndexError(\n                \"agent_id {} is did not request a decision at the previous step\".format(\n                    agent_id\n                )\n            ) from ie\n        if action_spec.continuous_size > 0:\n            self._env_actions[behavior_name].continuous[index] = action.continuous[0, :]\n        if action_spec.discrete_size > 0:\n            self._env_actions[behavior_name].discrete[index] = action.discrete[0, :]\n\n    def get_steps(\n        self, behavior_name: BehaviorName\n    ) -> Tuple[DecisionSteps, TerminalSteps]:\n        self._assert_behavior_exists(behavior_name)\n        return self._env_state[behavior_name]\n\n    def _poll_process(self) -> None:\n        \"\"\"\n        Check the status of the subprocess. If it has exited, raise a UnityEnvironmentException","sourceCodeStart":374,"sourceCodeEnd":410,"githubUrl":"https://github.com/Unity-Technologies/ml-agents/blob/3ecb446f75d1e7400eb404c562dc005d3164cffc/ml-agents-envs/mlagents_envs/environment.py#L374-L410","documentation":"IndexError raised by UnityEnvironment.set_action_for_agent when the requested agent_id is not found in the last recorded DecisionSteps for that behavior (self._env_state[behavior_name][0]). np.where over the agent_id array produced no match, so the agent did not request a decision in the previous step, and per-agent action setting is impossible.","triggerScenarios":"env.set_action_for_agent(behavior_name, agent_id, action) with an agent_id that was absent from the previous env.get_steps(behavior_name) DecisionSteps tuple, or an agent that used ActionBuffers instead, or a stale id from an earlier step after the agent was removed/terminated.","commonSituations":"Caching agent_ids across steps while agents come and go (agents only appear in DecisionSteps when they request decisions); using ids from terminated/Episode-Ended agents; off-by-one or wrong behavior_name lookups.","solutions":["Read the current DecisionSteps each step and only set actions for ids present in decision_steps.agent_id.","Use set_actions(behavior_name, action) for all agents at once instead of per-agent calls.","Verify agent_id belongs to the given behavior_name, not another group.","Re-check after env.reset(); agent ids reset between episodes."],"exampleFix":"// before\nenv.set_action_for_agent('Walker', 7, action)  # agent 7 didn't request a decision -> IndexError\n\n// after\ndecision_steps, _ = env.get_steps('Walker')\nif 7 in decision_steps.agent_id:\n    env.set_action_for_agent('Walker', 7, action)","handlingStrategy":"validation","validationCode":"decision_steps, terminal_steps = env.get_steps(behavior_name)\nif agent_id not in decision_steps.agent_id:\n    print(f'Skipping agent {agent_id}: did not request a decision this step')\nelse:\n    env.set_action_for_agent(behavior_name, agent_id, action)","typeGuard":null,"tryCatchPattern":"try:\n    env.set_action_for_agent(behavior_name, agent_id, action)\nexcept IndexError as e:\n    if 'did not request a decision' in str(e):\n        decision_steps, _ = env.get_steps(behavior_name)\n        print(f'agent_id {agent_id} not in {list(decision_steps.agent_id)}')\n    else:\n        raise","preventionTips":["Re-read DecisionSteps every step; do not cache agent_ids across steps.","Prefer set_actions() over set_action_for_agent() when acting on whole groups.","Remember agents appear in DecisionSteps only on decision-requesting steps; others land in TerminalSteps.","After reset(), refresh all tracked agent ids."],"tags":["agent-id","decision-steps","validation"],"backgroundTag":"agent-not-requesting-decision","analyzedSha":"3ecb446f75d1e7400eb404c562dc005d3164cffc","analyzedAt":"2026-09-02T16:33:12.832Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-09T21:17:11.164Z"}