-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
base: main
Are you sure you want to change the base?
Conversation
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. |
There was a problem hiding this 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. |
There was a problem hiding this comment.
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}$
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to CFN doc, the max length is 200. https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-bedrock-prompt.html
Also, lets fix the text to be 'Maximum Length'
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CFN docs also states that the max size of the array of variants is just 1. https://docs.aws.amazon.com/AWSCloudFormation/latest/TemplateReference/aws-resource-bedrock-prompt.html
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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) => { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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) => { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
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
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. |
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 CodeBuild CI Report
Powered by github-codebuild-logs, available on the AWS Serverless Application Repository |
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 substitutionChatPromptVariant
: Conversational prompts supporting system messages, message history, and tool configurationsAgentPromptVariant
: Prompts designed for integration with Bedrock AgentsPrompt Versioning :
PromptVersion
construct for creating immutable snapshots of promptsTool 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 viagrantGet()
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