{"record":{"id":"bce5df10812a64c3","repo":"microsoft/semantic-kernel","slug":"agent-does-not-exist-please-create-the-agent-befo-bce5df","errorCode":null,"errorMessage":"Agent does not exist. Please create the agent before creating an action group for it.","messagePattern":"Agent does not exist\\. Please create the agent before creating an action group for it\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"python/semantic_kernel/agents/bedrock/bedrock_agent_base.py","lineNumber":189,"sourceCode":"        for _ in range(max_attempts):\n            await self._get_agent()\n            if self.agent_model.agent_status == status:\n                return\n\n            await asyncio.sleep(interval)\n\n        raise TimeoutError(\n            f\"Agent did not reach status {status} within the specified time.\"\n            f\" Current status: {self.agent_model.agent_status}\"\n        )\n\n    # endregion Agent Management\n\n    # region Action Group Management\n    async def create_code_interpreter_action_group(self, **kwargs) -> BedrockActionGroupModel:\n        \"\"\"Create a code interpreter action group.\"\"\"\n        if not self.agent_model.agent_id:\n            raise ValueError(\"Agent does not exist. Please create the agent before creating an action group for it.\")\n\n        try:\n            response = await run_in_executor(\n                None,\n                partial(\n                    self.bedrock_client.create_agent_action_group,\n                    agentId=self.agent_model.agent_id,\n                    agentVersion=self.agent_model.agent_version or \"DRAFT\",\n                    actionGroupName=f\"{self.agent_model.agent_name}_code_interpreter\",\n                    actionGroupState=\"ENABLED\",\n                    parentActionGroupSignature=\"AMAZON.CodeInterpreter\",\n                    **kwargs,\n                ),\n            )\n\n            await self.prepare_agent_and_wait_until_prepared()\n\n            return BedrockActionGroupModel(**response[\"agentActionGroup\"])","sourceCodeStart":171,"sourceCodeEnd":207,"githubUrl":"https://github.com/microsoft/semantic-kernel/blob/c028a0c7dc4f0814cdcbaba9d998f187a41197bf/python/semantic_kernel/agents/bedrock/bedrock_agent_base.py#L171-L207","documentation":"Raised by create_code_interpreter_action_group when self.agent_model.agent_id is falsy. Creating an action group via bedrock_client.create_agent_action_group requires an agentId, so the method guards upfront. The agent must already exist in the AWS service before attaching a code interpreter action group.","triggerScenarios":"Triggered when calling create_code_interpreter_action_group() on a BedrockAgent whose agent_model.agent_id is None/empty — e.g. a manually constructed agent not yet provisioned in AWS.","commonSituations":"Constructing BedrockAgent from a partial dict and immediately attaching an action group without creating the agent first; the agent was deleted; deserialized config missing agent_id.","solutions":["Create the agent first via create_and_prepare_agent (or ensure agent_id is set from an existing agent).","Guard the call: if agent.agent_model.agent_id: await agent.create_code_interpreter_action_group().","Verify agent_id is populated after creation before calling action-group methods."],"exampleFix":"// before\nagent = BedrockAgent({'agentName': 'x'})\nawait agent.create_code_interpreter_action_group()  # no agent_id -> raises\n\n// after\nagent = await BedrockAgent.create_and_prepare_agent(name='x', instructions='...')\nawait agent.create_code_interpreter_action_group()  # agent_id is set","handlingStrategy":"validation","validationCode":"def assert_agent_exists(agent) -> None:\n    if not agent.agent_model.agent_id:\n        raise ValueError(\"Agent must be created before attaching action groups.\")","typeGuard":"def agent_has_id(agent) -> bool:\n    return bool(getattr(getattr(agent, \"agent_model\", None), \"agent_id\", None))","tryCatchPattern":"try:\n    await agent.create_code_interpreter_action_group()\nexcept ValueError as e:\n    if \"create the agent before creating an action group\" in str(e):\n        agent = await BedrockAgent.create_and_prepare_agent(name=..., instructions=...)\n        await agent.create_code_interpreter_action_group()\n    else:\n        raise","preventionTips":["Provision the agent via create_and_prepare_agent before calling any action-group method.","Check agent.agent_model.agent_id before attaching action groups.","Avoid constructing agents from partial dicts for action-group workflows."],"tags":["bedrock","action-group","code-interpreter","missing-agent-id","validation"],"backgroundTag":null,"analyzedSha":"c028a0c7dc4f0814cdcbaba9d998f187a41197bf","analyzedAt":"2026-08-13T13:48:05.040Z","schemaVersion":2},"datasetVersion":"2026-08-13T14:17:21.547Z"}