aws-bedrock-agent: Bedrock Agent PromptOverrideConfiguration Fails With Valid additionalModelRequestFields Unless Manually "Saved" and "Prepared" in Console
- Dominant language
- TypeScript
- Stars
- 12.9k
- Forks
- 4.6k
- Avg merge
- 1d 19h
- Merged PRs (30d)
- 71
Description
### Describe the bug
**Summary**
When deploying a Bedrock Agent using AWS CDK with the following orchestration prompt override configuration, the agent fails to respond to queries and encounters a validation error regarding budget_tokens, even though the configuration is valid and visually correct in the AWS Console. The agent only begins to function after manually saving the agent through the AWS Console UI, without making any actual changes.
### Regression Issue
- [ ] Select this option if this issue appears to be a regression.
### Last Known Working CDK Library Version
_No response_
### Expected Behavior
The agent should be immediately functional after deployment via CDK/CloudFormation and accept valid additionalModelRequestFields for orchestration overrides.
### Current Behavior
Deploying via CDK with a valid override configuration yields a validation error.
### Reproduction Steps
1. Deploy an agent using the CDK construct below:
`orchestration_prompt_config = bedrock.CfnAgent.PromptConfigurationProperty(
prompt_type="ORCHESTRATION",
prompt_creation_mode="OVERRIDDEN",
base_prompt_template="...",
inference_configuration=bedrock.CfnAgent.InferenceConfigurationProperty(
temperature=0.1,
top_p=0.9,
maximum_length=2048
),
additional_model_request_fields={
"thinking": {
"budget_tokens": 1024,
"type": "enabled"
}
}
)`
2. After deployment, attempt to invoke the agent via the Bedrock API.
3. Observe the error:
`Validation failed with the PromptOverrideConfiguration that you provided.
software.amazon.awssdk.services.bedrockruntime.model.ValidationException:
The model returned the following errors:
thinking.enabled.budget_tokens: Input should be a valid integer
`
4. Open the agent edit page in the AWS Console. Notice all additionalModelRequestFields are correctly reflected.
5. Save the agent from the console without changing any configuration.
6. Invoke the agent again; now it responds correctly.
**Code Snippet**
`from aws_cdk import (
Stack,
aws_bedrock as bedrock
)
from constructs import Construct
import aws_cdk as cdk
class BedrockAgentStack(Stack):
def __init__(self, scope: Construct, construct_id: str, **kwargs):
super().__init__(scope, construct_id, **kwargs)
# Hardcoded values for demonstration
agent_name = "test-agent"
inference_profile_arn = "arn:aws:bedrock:us-east-1:438825807532:inference-profile/us.anthropic.claude-3-7-sonnet-20250219-v1:0"
role_arn = "XXXXXXXXXXX"
knowledge_base_id = "XXXXXXXXXXX"
# Inference configuration properties required for orchestration prompt
orchestration_inference_config = bedrock.CfnAgent.InferenceConfigurationProperty(
temperature=0.1,
top_p=0.9,
maximum_length=2048
)
# Orchestration prompt override configuration
orchestration_prompt_config = bedrock.CfnAgent.PromptConfigurationProperty(
prompt_type="ORCHESTRATION",
prompt_creation_mode="OVERRIDDEN",
base_prompt_template="You have been provided with a set of functions to answer the user's question.\nYou will ALWAYS follow the below guidelines when you are answering a question",
inference_configuration=orchestration_inference_config,
additional_model_request_fields={
"thinking": {
"type": "enabled",
"budget_tokens": 1024
}
}
)
prompt_override_config = bedrock.CfnAgent.PromptOverrideConfigurationProperty(
prompt_configurations=[orchestration_prompt_config]
)
# Minimal knowledge base property
knowledge_base = bedrock.CfnAgent.AgentKnowledgeBaseProperty(
knowledge_base_id=knowledge_base_id,
description="Minimal knowledge base for agent",
knowledge_base_state="ENABLED"
)
# Create the Bedrock Agent with orchestration prompt override
bedrock.CfnAgent(
self,
"BedrockAgent",
agent_name=agent_name,
agent_resource_role_arn=role_arn,
foundation_model=inference_profile_arn,
instruction="You are a minimal Bedrock agent for orchestration override testing.",
knowledge_bases=[knowledge_base],
prompt_override_configuration=prompt_override_config,
idle_session_ttl_in_seconds=300
)
app = cdk.App()
BedrockAgentStack(app, "BedrockAgentPOC")
app.synth()`
### Possible Solution
The agent only begins to function after manually saving the agent through the AWS Console UI, without making any actual changes.
Manual intervention in the AWS Console (simply "saving" the agent and "preparing") resolves the issue, even if no values are changed.
### Additional Information/Context
- Bedrock Foundation Model: anthropic.claude-3-7-sonnet-20250219-v1:0
- Relevant CDK code and exact error are provided above.
- This bug prevents headless automation for agent deployment and causes unexpected runtime validation issues.
### AWS CDK Library version (aws-cdk-lib)
2.214.0
### AWS CDK CLI version
2.1029.0
### Node.js Version
23.7.0
### OS
macOS 15.6.1
### Language
Python
### Language Version
3.11.0
### Other information
Failure Image:
Agent edit page reflecting the values passed into CDK Construct (CfnAgent):
Response after Agent edit page is saved (without edit) and prepared:
Contributor guide
Assessment
This issue has not been assessed yet.