-
Notifications
You must be signed in to change notification settings - Fork 154
Feature request: Amazon Bedrock Agents Functions #3710
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
Comments
I'll take a look at this |
There are two additional parts I think it would be useful to consider in the RFC.
1. ErrorsWhen there is an unhandled exception in the execution, the Agent returns an The lambda function can also signify two possible error states to the Bedrock Agent with a property in the response object:
I think it would be useful for the user to be able to emit both of these error states when using the function resolver. Bedrock Agents - Response Object 2. Session Attributes, Prompt Session Attributes and KnowledgeBaseConfigurationThe lambda response object can contain three extra properties, It would be useful to support setting these on the response object when using the function resolver. |
@ConnorKirk ! One question regarding:
What's the user experience you're thinking here? It's that the |
Use case
Bedrock Agents allows you to define action groups for your agents in two ways: OpenAPI schemas, and direct function integration. This issue focuses on the latter.
As a customer I can create Bedrock Agents that have tools at their disposal. These tools, or functions, can be defined as AWS Lambda functions. One Lambda function can hold one or more tools and when looked at together, they are what makes an action group.
When I build a Lambda function with multiple tools in it, I am responsible for parsing the payload sent by Bedrock and, based on certain fields, call the corresponding tool in my code (aka the tool use). The response of this tool use is then returned by my Lambda function handler according to a specific format that Bedrock expects.
This can result in some degree of boilerplate code that I have to repeat for each action group, specifically:
Click to see Action Group example
As a customer I would like to abstract all of that and instead focus primarily on building the tools for my agents, which are the only part of this that is specific to my business.
Solution/User Experience
When paired with a Lambda function via action group, Bedrock sends and expects payloads of known shapes.
Click to see request payload example
Documentation
Click to response payload example
Documentation
Since the input event includes both the
function
andparameters
fields, we can abstract most/all the boilerplate and provide a more streamlined experience.For example, borrowing heavily from the Event Handler RFC we concluded a few weeks ago, we could implement a
BedrockAgentFunctionResolver
resolver that provides a structured way to register functions, resolve function calls, and handle requests within Lambda.For reference, the example shown above could be rewritten like:
The implementation above allows customers to focus on defining and implementing the tools within the action group rather than the undifferentiated boilerplate required to parse an event, resolve which tool to use, call it, and build the response payload.
Similar to what we do with the API Event Handler, customers can use the pattern above as well as the class method decorator-based pattern, which would look like this (simplified for brevity):
Contrary to the API Event Handler, validation and parsing via Zod or other Standard Schema-compliant libraries cannot be disabled. This is because we want to ensure both inputs and outputs are always compliant to the expected shapes, but also because we want to allow customers to automatically generate the schema for the action group to create the resource more easily.
Finally, customers can also access the current request
event
andcontext
in the tool definitions. This is useful when the tools rely on information included in the request like the session, or they need to access the context. Theevent
andcontext
are passed to the tool handler as second argument, i.e.:In terms of practical directions, the resolver and its logic will be reside under
packages/event-handler
and be part of the event handler package. With that said, the implementation will be completely independent form the rest of the event handler at least for its initial version.Alternative solutions
See this discussion for considerations on alternative solutions: aws-powertools/powertools-lambda-python#6081
Acknowledgment
Future readers
Please react with 👍 and your use case to help us understand customer demand.
The text was updated successfully, but these errors were encountered: