-
Notifications
You must be signed in to change notification settings - Fork 432
feat(bedrock_agent): add new Amazon Bedrock Agents Functions Resolver #6564
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: develop
Are you sure you want to change the base?
Conversation
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## develop #6564 +/- ##
===========================================
+ Coverage 96.09% 96.15% +0.05%
===========================================
Files 254 256 +2
Lines 12179 12350 +171
Branches 905 916 +11
===========================================
+ Hits 11704 11875 +171
Misses 373 373
Partials 102 102 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Signed-off-by: Ana Falcão <[email protected]>
…tools/powertools-lambda-python into feat/bedrock_functions
|
|
|
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.
Left a few comments/questions
error_response = BedrockFunctionResponse(body=f"Error: {str(error)}", response_state="FAILURE") | ||
return BedrockFunctionsResponseBuilder(error_response).build(self.current_event) | ||
|
||
def append_context(self, **additional_context): |
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.
Are we ever calling this method to append the context?
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.
This is a function to allow customer to inject additional data - like dependency injection - to access this within the route (tool in this case).
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.
Ok, but are we ever passing the context
to the tool handler?
func = self._tools[function_name]["function"] | ||
# Filter parameters to only include those expected by the function | ||
sig = inspect.signature(func) | ||
valid_params = {name: value for name, value in parameters.items() if name in sig.parameters} |
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.
We can't parse array
types, but we can "trust" number
, integer
, boolean
and string
types and potentially cast them to the correct type before passing them to the handler.
Otherwise customers will always get strings.
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.
Hmm make sense, I see your point. Ok, I'll cast them before passing to the function.
@@ -26,72 +30,53 @@ Create [Agents for Amazon Bedrock](https://docs.aws.amazon.com/bedrock/latest/us | |||
|
|||
**[OpenAPI schema](https://www.openapis.org/){target="_blank"}** is an industry standard JSON-serialized string that represents the structure and parameters of your API. | |||
|
|||
**Function details** consist of a list of parameters, defined by their name, [data type](https://docs.aws.amazon.com/bedrock/latest/APIReference/API_agent_ParameterDetail.html), and whether they are required. The agent uses these configurations to determine what information it needs to elicit from the user. | |||
|
|||
**Action group** is a collection of two resources where you define the actions that the agent should carry out: an OpenAPI schema to define the APIs that the agent can invoke to carry out its tasks, and a Lambda function to execute those actions. |
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.
This could be confusing, with the new feature an action group is only a function and its tool definitions, without OpenAPI schema
|----------------------|------------------------------------------------------------------|----------------------------------------------------------------| | ||
| Definition Style | `@app.get("/path", description="")`<br>`@app.post("/path", description="")` | `@app.tool(name="")` | | ||
| Parameter Handling | Path, query, and body parameters | Function parameters | | ||
| Use Case | REST-like APIs, complex request/response structures | Direct function calls, simpler input/output | |
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 think simpler input
is probably the most correct.
Based on tests Bedrock is able to work with complex outputs just fine even with the function-based resolver, there's just not a schema but it does fine.
| Parameter Handling | Path, query, and body parameters | Function parameters | | ||
| Use Case | REST-like APIs, complex request/response structures | Direct function calls, simpler input/output | | ||
| Response object | Via `BedrockResponse` | Via `BedrockFunctionResponse` | | ||
| Best For | - Complex APIs with multiple endpoints<br>- When OpenAPI spec is required<br>- Integration with existing REST APIs | - Simple function-based actions<br>- Direct LLM-to-function mapping<br>- When function descriptions are sufficient | |
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'd remove this When function descriptions are sufficient
.
In practice, you still need to configure Bedrock and specify the tools, parameters, and description - it just happens in the Agent config rather than in the function's code.
``` | ||
|
||
#### When validation fails | ||
??? note "What happens under the hood?" |
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.
Based on the content of the mermaid diagram, this should probably be under the OpenAPI section since it mentions both the OpenAPI schema and validation, which don't happen in this new implementation.
|
|
|
|
|
Issue number: #6300
Summary
This PR introduces support for Bedrock Agents Functions, providing the user a similar experience from the current Bedrock Agents with OpenAPI Resolver.
Changes
User experience
Checklist
If your change doesn't seem to apply, please leave them unchecked.
Is this a breaking change?
RFC issue number:
Checklist:
Acknowledgment
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.