microsoft/semantic-kernel · error · ValueError
Agent does not exist. Please create the agent before creatin
Error message
Agent does not exist. Please create the agent before creating an action group for it.
What it means
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.
Source
Thrown at python/semantic_kernel/agents/bedrock/bedrock_agent_base.py:189
for _ in range(max_attempts):
await self._get_agent()
if self.agent_model.agent_status == status:
return
await asyncio.sleep(interval)
raise TimeoutError(
f"Agent did not reach status {status} within the specified time."
f" Current status: {self.agent_model.agent_status}"
)
# endregion Agent Management
# region Action Group Management
async def create_code_interpreter_action_group(self, **kwargs) -> BedrockActionGroupModel:
"""Create a code interpreter action group."""
if not self.agent_model.agent_id:
raise ValueError("Agent does not exist. Please create the agent before creating an action group for it.")
try:
response = await run_in_executor(
None,
partial(
self.bedrock_client.create_agent_action_group,
agentId=self.agent_model.agent_id,
agentVersion=self.agent_model.agent_version or "DRAFT",
actionGroupName=f"{self.agent_model.agent_name}_code_interpreter",
actionGroupState="ENABLED",
parentActionGroupSignature="AMAZON.CodeInterpreter",
**kwargs,
),
)
await self.prepare_agent_and_wait_until_prepared()
return BedrockActionGroupModel(**response["agentActionGroup"])View on GitHub (pinned to c028a0c7dc)
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.
Example fix
// before
agent = BedrockAgent({'agentName': 'x'})
await agent.create_code_interpreter_action_group() # no agent_id -> raises
// after
agent = await BedrockAgent.create_and_prepare_agent(name='x', instructions='...')
await agent.create_code_interpreter_action_group() # agent_id is set Defensive patterns
Strategy: validation
Validate before calling
def assert_agent_exists(agent) -> None:
if not agent.agent_model.agent_id:
raise ValueError("Agent must be created before attaching action groups.") Type guard
def agent_has_id(agent) -> bool:
return bool(getattr(getattr(agent, "agent_model", None), "agent_id", None)) Try / catch
try:
await agent.create_code_interpreter_action_group()
except ValueError as e:
if "create the agent before creating an action group" in str(e):
agent = await BedrockAgent.create_and_prepare_agent(name=..., instructions=...)
await agent.create_code_interpreter_action_group()
else:
raise Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- Agent does not exist. Please create the agent before prepari
- Agent does not exist. Please create the agent before deletin
- Agent does not exist. Please create the agent before getting
- No file found in the response.
- The Bedrock agent requires a message to be invoked.
AI-assisted analysis of microsoft/semantic-kernel@c028a0c7dc (2026-08-13).
Data as JSON: /api/errors/bce5df10812a64c3.
Report an issue: GitHub.