Skip to content

feat(bedrockprompt): add prompt management to bedrock agents #34754

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

dineshSajwan
Copy link
Contributor

Issue # (if applicable)

Closes #.

Reason for this change

This change adds comprehensive support for Amazon Bedrock Prompt Management to the aws-bedrock-alpha package.

Description of changes

Amazon Bedrock Prompt Management allows users to create, save, and version prompts to streamline AI workflows and ensure consistent prompt usage across different applications.

Prompt Construct : Main construct for creating and managing Bedrock prompts with support for multiple variants.

Prompt Variants: Three types of prompt variants:
TextPromptVariant: Simple text-based prompts with variable substitution
ChatPromptVariant: Conversational prompts supporting system messages, message history, and tool configurations
AgentPromptVariant: Prompts designed for integration with Bedrock Agents

Prompt Versioning : PromptVersion construct for creating immutable snapshots of prompts

Tool Configuration : Support for tool choice and tool specifications in chat prompts

Prompt Routing : Integration with Amazon Bedrock intelligent prompt routing for cost optimization

Describe any new or updated permissions being added

bedrock:GetPrompt - Required to retrieve prompt details (granted via grantGet() method)

Description of how you validated changes

Added Unit test and Integration test.

Checklist


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@github-actions github-actions bot added beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK p2 labels Jun 18, 2025
@aws-cdk-automation aws-cdk-automation requested a review from a team June 18, 2025 17:40
@dineshSajwan dineshSajwan marked this pull request as ready for review June 18, 2025 20:41
@krokoko krokoko mentioned this pull request Jun 19, 2025
2 tasks
@aws-cdk-automation
Copy link
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

@alvazjor alvazjor self-assigned this Jun 24, 2025
@alvazjor alvazjor self-requested a review June 25, 2025 15:32
Copy link
Contributor

@alvazjor alvazjor left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dineshSajwan Added initial comments. Not fully done reviewing the full PR but in the mean time, you can start addressing what I already added. Thanks!

export interface PromptProps {
/**
* The name of the prompt.
* This will be used as the physical name of the prompt.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we also document the allowed name pattern?
Pattern: ^([0-9a-zA-Z][_-]?){1,100}$

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack , Pushed - 23f290c

* A description of what the prompt does.
*
* @default - No description provided.
* Length Maximum: 250
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, Pushed - 23f290c

/**
* The variants of your prompt. Variants can use different messages, models,
* or configurations so that you can compare their outputs to decide the best
* variant for your use case. Maximum of 3 variants.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per the service it supports 3 max variant but the cloudformation support max variant as 1 for now. I have opened an issue in CFN repo for the same . For now the CDK will also support max variant as 1. updated the doc and pushed here - 23f290c

/**
* Class to create (or import) a Prompt with CDK.
*
* Prompts are a specific set of inputs that guide FMs on Amazon Bedrock to
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume FMs here means Foundational Models? Lets explain what it means before we start using the acronym

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack, Thanks - 23f290c

* @default - No description provided
* @returns The version string of the created prompt version
*/
public createVersion(description?: string): string {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any specific reason to return the version identifier here, instead of a PromptVersion object? For example, if a user creates a version of the prompt, and then wants to do something with it, that requires the version's ARN, it would require additional effort on their side

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The PromptVersion object is returned by instantiating promptVersion instance. However, I agree we can update the createVersion to return the same instance from this method too.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/**
* The inference configuration.
*/
readonly inferenceConfiguration?: bedrock.CfnPrompt.PromptInferenceConfigurationProperty;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For this, templateConfiguration and genAiResource, they are exposing L1 types, which is not recommended. Instead please write proper abstractions for it (simple interfaces if that is the only thing you need).

*
* @default - No inference configuration provided.
*/
readonly inferenceConfiguration?: bedrock.CfnPrompt.PromptModelInferenceConfigurationProperty;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exposing L1 types, which is not recommended. Instead please write proper abstractions for it (simple interfaces if that is the only thing you need).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Make sense, created a new interface - yarn integ-runner test/bedrock/agents/integ.action-group.js --update-on-failed

},
templateConfiguration: {
chat: {
inputVariables: props.promptVariables?.flatMap((variable: string) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to use flatMap here? The promptVariables is an array of strings, so just using map will do the trick

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for pointing it out - yarn integ-runner test/bedrock/agents/integ.action-group.js --update-on-failed

*
* @default - No inference configuration provided.
*/
readonly inferenceConfiguration?: bedrock.CfnPrompt.PromptModelInferenceConfigurationProperty;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exposing L1 types, which is not recommended. Instead please write proper abstractions for it (simple interfaces if that is the only thing you need).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ack - yarn integ-runner test/bedrock/agents/integ.action-group.js --update-on-failed

},
templateConfiguration: {
text: {
inputVariables: props.promptVariables?.flatMap((variable: string) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do you need to use flatMap here? The promptVariables is an array of strings, so just using map will do the trick

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yarn integ-runner test/bedrock/agents/integ.action-group.js --update-on-failed

@aws-cdk-automation
Copy link
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

2 similar comments
@aws-cdk-automation
Copy link
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

@aws-cdk-automation
Copy link
Collaborator

This PR cannot be merged because it has conflicts. Please resolve them. The PR will be considered stale and closed if it remains in an unmergeable state.

@mergify mergify bot dismissed alvazjor’s stale review June 30, 2025 19:33

Pull request has been modified.

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: 69e8ffa
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@aws-cdk-automation aws-cdk-automation added the pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member. label Jul 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
beginning-contributor [Pilot] contributed between 0-2 PRs to the CDK p2 pr/needs-community-review This PR needs a review from a Trusted Community Member or Core Team Member.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants