AWS.Lambda.Powertools.EventHandler.Resolvers.BedrockAgentFunction.AspNetCore
1.0.0
Prefix Reserved
dotnet add package AWS.Lambda.Powertools.EventHandler.Resolvers.BedrockAgentFunction.AspNetCore --version 1.0.0
NuGet\Install-Package AWS.Lambda.Powertools.EventHandler.Resolvers.BedrockAgentFunction.AspNetCore -Version 1.0.0
<PackageReference Include="AWS.Lambda.Powertools.EventHandler.Resolvers.BedrockAgentFunction.AspNetCore" Version="1.0.0" />
<PackageVersion Include="AWS.Lambda.Powertools.EventHandler.Resolvers.BedrockAgentFunction.AspNetCore" Version="1.0.0" />
<PackageReference Include="AWS.Lambda.Powertools.EventHandler.Resolvers.BedrockAgentFunction.AspNetCore" />
paket add AWS.Lambda.Powertools.EventHandler.Resolvers.BedrockAgentFunction.AspNetCore --version 1.0.0
#r "nuget: AWS.Lambda.Powertools.EventHandler.Resolvers.BedrockAgentFunction.AspNetCore, 1.0.0"
#:package AWS.Lambda.Powertools.EventHandler.Resolvers.BedrockAgentFunction.AspNetCore@1.0.0
#addin nuget:?package=AWS.Lambda.Powertools.EventHandler.Resolvers.BedrockAgentFunction.AspNetCore&version=1.0.0
#tool nuget:?package=AWS.Lambda.Powertools.EventHandler.Resolvers.BedrockAgentFunction.AspNetCore&version=1.0.0
Experimental work in progress, not yet released
AWS Lambda Powertools for .NET - Bedrock Agent Function Resolver for ASP.NET Core
Overview
This library provides ASP.NET Core integration for the AWS Lambda Powertools Bedrock Agent Function Resolver. It enables you to easily expose Bedrock Agent functions as endpoints in your ASP.NET Core applications using a simple, fluent API.
Features
- Minimal API Integration: Register Bedrock Agent functions using familiar ASP.NET Core Minimal API patterns
- AOT Compatibility: Full support for .NET 8 AOT compilation through source generation
- Simple Function Registration: Register functions with a fluent API
- Automatic Request Processing: Automatic parsing of Bedrock Agent requests and formatting of responses
- Error Handling: Built-in error handling for Bedrock Agent function requests
Installation
Install the package via NuGet:
dotnet add package AWS.Lambda.Powertools.EventHandler.Resolvers.BedrockAgentFunction.AspNetCore
Basic Usage
Here's how to register Bedrock Agent functions in your ASP.NET Core application:
using AWS.Lambda.Powertools.EventHandler.Resolvers.BedrockAgentFunction.AspNetCore;
var builder = WebApplication.CreateBuilder(args);
var app = builder.Build();
// Register individual functions
app.MapBedrockFunction("GetWeather", (string city, int month) =>
$"Weather forecast for {city} in month {month}: Warm and sunny");
app.MapBedrockFunction("Calculate", (int x, int y) =>
$"Result: {x + y}");
app.Run();
When Amazon Bedrock Agent sends a request to your application, the appropriate function will be invoked with the extracted parameters, and the response will be formatted correctly for the agent.
Using with Dependency Injection
Register the Bedrock resolver with dependency injection for more advanced scenarios:
using AWS.Lambda.Powertools.EventHandler.Resolvers;
using AWS.Lambda.Powertools.EventHandler.Resolvers.BedrockAgentFunction.AspNetCore;
var builder = WebApplication.CreateBuilder(args);
// Register the resolver and any other services
builder.Services.AddBedrockResolver();
builder.Services.AddSingleton<IWeatherService, WeatherService>();
var app = builder.Build();
// Register functions that use injected services
app.MapBedrockFunction("GetWeatherForecast",
(string city, IWeatherService weatherService) =>
weatherService.GetForecast(city),
"Gets weather forecast for a city");
app.Run();
Advanced Usage
Function Documentation
Add descriptions to your functions for better documentation:
app.MapBedrockFunction("GetWeather",
(string city, int month) => $"Weather forecast for {city} in month {month}: Warm and sunny",
"Gets weather forecast for a specific city and month");
Working with Tool Classes
Use the MapBedrockToolClass<T>()
method to register all functions from a class directly:
[BedrockFunctionType]
public class WeatherTools
{
[BedrockFunctionTool(Name = "GetWeather", Description = "Gets weather forecast")]
public static string GetWeather(string location, int days)
{
return $"Weather forecast for {location} for the next {days} days";
}
}
// In Program.cs - directly register the tool class
app.MapBedrockToolClass<WeatherTools>();
How It Works
- When you call
MapBedrockFunction
, the function is registered with the resolver - An HTTP endpoint is set up at the root path (/) to handle incoming Bedrock Agent requests
- When a request arrives, the library:
- Deserializes the JSON payload
- Extracts the function name and parameters
- Invokes the matching function with the appropriate parameters
- Serializes the result and returns it as a response
Requirements
- .NET 8.0 or later
- ASP.NET Core 8.0 or later
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net8.0
- AWS.Lambda.Powertools.EventHandler.Resolvers.BedrockAgentFunction (>= 1.0.0)
- Microsoft.AspNetCore.Http (>= 2.3.0)
- Microsoft.AspNetCore.Http.Abstractions (>= 2.3.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
1.0.0 | 153 | 6/3/2025 |