Skip to content

Bedrock agents function calling pass auth context

0

Hi Everyone,

I am trying to figure out what pattern to use when I want my bedrock agent to use auth information for the user when calling functions. We want to build a chat interface with access to company resources via tool calling, but not all tools should be available for all users. We have company wide federated auth which we can use as authorisation method for most APIs, and I am trying to figure out how to pass the auth token for the tool call.

Basically the flow is: User inputs a message -> cognito auth on the API -> passes the auth token to the Lambda which triggers the agent. After this point I have not found a way to pass the token except by providing it as context for the agent, which I would like to avoid if possible.

I am open to any suggestion.

If anyone knows of a way to limit which tools are available to a given agent based on what user is calling it that would be even better.

Regards, Bart

1 Answer
1
Accepted Answer

To address your need for passing authentication context to Bedrock agents when calling functions, there are a few approaches you can consider:

  1. Session Attributes: You can pass the authentication token through the SessionState object when invoking the agent. Specifically, you can include the token in the sessionAttributes field. This allows you to maintain the auth context across multiple turns of conversation without exposing it directly in the agent's prompt.

  2. Lambda Function Handling: In your action group Lambda function, you can retrieve the authentication header from the event object. This allows you to use the token to verify the user's access for specific actions using a service like Amazon Verified Permissions.

  3. Return of Control: You can use the "return of control" pattern, where the agent doesn't directly call the actions but instead notifies your application code when it determines a tool call is needed. This gives you the opportunity to implement your own authorization logic before executing the action.

As for limiting which tools are available to a given agent based on the user, you have a couple of options:

  1. Dynamic Tool Selection: You can implement logic in your Lambda function to dynamically select which tools to make available based on the user's permissions. This would involve checking the user's authorization before allowing certain tool calls.

  2. Layered Authorization: Implement a layered authorization approach where you use Amazon Verified Permissions to check if a user is authorized for a specific action before the agent executes it. This allows you to have fine-grained control over which actions a user can perform, effectively limiting the available tools based on their permissions.

  3. Multiple Agents: Create different agents with varying sets of tools and route users to the appropriate agent based on their authorization level.

Remember to always follow security best practices, such as using strong authentication (e.g., OpenID Connect with MFA) and implementing proper threat modeling for your application. These approaches allow you to maintain security while providing a personalized experience for different user roles within your company.
Sources
Design secure generative AI application workflows with Amazon Verified Permissions and Amazon Bedrock Agents | AWS Machine Learning Blog
Bedrock Get user confirmation before invoking action group | AWS re:Post
Control agent session context - Amazon Bedrock
Enhancing data privacy with layered authorization for Amazon Bedrock Agents | AWS Security Blog

answered a year ago

EXPERT

reviewed a year ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.