Skip to content

feat(bedrock): add guardrail support for agents #564

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

Merged
merged 3 commits into from
Jul 17, 2024

Conversation

krokoko
Copy link
Collaborator

@krokoko krokoko commented Jul 17, 2024

Fixes #561

  • Add guardrail support for agents
  • Update CDK library version
  • Update Projen version

Testing:

  • Using the [https://github.com/aws-samples/generative-ai-cdk-constructs-samples/tree/main/samples/bedrock-agent](Bedrock Agent sample) , creating a guardrail and associating it with the agent

With agent.addGuardrail(guardrail); API:

image

Through constructor :

const agent = new bedrock.Agent(this, 'Agent', {
      foundationModel: bedrock.BedrockFoundationModel.ANTHROPIC_CLAUDE_INSTANT_V1_2,
      instruction: 'You are a helpful and friendly agent that answers questions about literature.',
      knowledgeBases: [kb],
      enableUserInput: true,
      shouldPrepareAgent:true,
      guardrailConfiguration: {
        guardrailId: guardrail.guardrailId,
        guardrailVersion: guardrail.guardrailVersion
      },
    });
image

Note: when providing guardrail config through the constructor, the customer has to provide correct permissions to the agent to use the guardrail. This is because we are currently not able to retrieve programmatically a guardrail based on id/version.

Use:

When asking a question, the trace shows correct use of guardrails:

image image

When asking a question which falls under the guardrails boundaries, the correct fallback message is returned:

image

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of the project license.

@krokoko krokoko marked this pull request as ready for review July 17, 2024 17:10
@krokoko krokoko requested a review from a team as a code owner July 17, 2024 17:10
@krokoko krokoko enabled auto-merge (squash) July 17, 2024 17:12
dineshSajwan
dineshSajwan previously approved these changes Jul 17, 2024
Copy link
Contributor

@dineshSajwan dineshSajwan left a comment

Choose a reason for hiding this comment

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

LGTM

@krokoko krokoko merged commit 4e848bb into awslabs:main Jul 17, 2024
14 checks passed
@krokoko krokoko deleted the agent_guardrail branch July 25, 2024 14:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

(Bedrock agent): guardrail support
4 participants