You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
parsing/validating the incoming Bedrock Agent request payload
handling the event using the correct tool/function
building the response according to the response Bedrock Agent payload schema
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.
Payload example
{
"messageVersion": "1.0",
"agent": {
"alias": "PROD",
"name": "hr-assistant-function-def",
"version": "1",
"id": "1234abcd-56ef-78gh-90ij-klmn12345678"
},
"sessionId": "87654321-abcd-efgh-ijkl-mnop12345678",
"sessionAttributes": {
"employeeId": "EMP123",
"department": "Engineering"
},
"promptSessionAttributes": {
"lastInteraction": "2024-02-01T15:30:00Z",
"requestType": "vacation"
},
"inputText": "I want to request vacation from March 15 to March 20",
"actionGroup": "VacationsActionGroup",
"function": "submitVacationRequest",
"parameters": [{
"employeeId": "EMP123",
"startDate": "2024-03-15",
"endDate": "2024-03-20",
"vacationType": "annual"
}]
}
Since the input event includes both the function and parameters fields, we can abstract most/all the boilerplate and provide a more streamlined experience.
We could implement a BedrockAgentFunctionResolver resolver that provides a structured way to register functions, resolve function calls, and handle requests within Lambda.
fromaws_lambda_powertools.event_handlerimportBedrockAgentFunctionResolverfromaws_lambda_powertools.utilities.typingimportLambdaContextapp=BedrockAgentFunctionResolver()
@app.tool(name="currentTime", description="Gets the current UTC time")defget_current_time():
...
@app.tool(description="Greets the user using name")defgreet_user(name):
...
@app.tool(description="Add two numbers")defsimple_calculator(a, b, operation):
...
deflambda_handler(event: dict, context: LambdaContext) → dict:
returnapp.resolve(event, context)
Similar to the experience for Bedrock Agents with OpenAPI, we need a decorator tool that have name parameter as Optional. If customers want to make this more resilient to refactoring or want to have special naming conventions they can optionally specify a name parameter and in that case that takes precedence over the actual function name.
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.
Finally, customers can also access the current request event in the tool definitions, as app.current_event, ang get information like session_id or prompt_session_attributes similar to Bedrock Agents OpenAPI - accessing custom request fields
Alternative solutions
See this discussion for considerations on alternative solutions: #6081
Use case
RFC: #6081
Issue in TS: aws-powertools/powertools-lambda-typescript/issues/3710
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:
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.
Payload example
Documentation
Response payload example
Documentation
Since the input event includes both the function and parameters fields, we can abstract most/all the boilerplate and provide a more streamlined experience.
We could implement a
BedrockAgentFunctionResolver
resolver that provides a structured way to register functions, resolve function calls, and handle requests within Lambda.Similar to the experience for Bedrock Agents with OpenAPI, we need a decorator
tool
that havename
parameter asOptional
. If customers want to make this more resilient to refactoring or want to have special naming conventions they can optionally specify aname
parameter and in that case that takes precedence over the actual function name.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.
Finally, customers can also access the current request
event
in the tool definitions, asapp.current_event
, ang get information likesession_id
orprompt_session_attributes
similar to Bedrock Agents OpenAPI - accessing custom request fieldsAlternative solutions
See this discussion for considerations on alternative solutions: #6081
Acknowledgment
The text was updated successfully, but these errors were encountered: