Skip to content

Commit f16b932

Browse files
committed
docs: enhance Bedrock Agent Function documentation with response format details and examples
1 parent 93f0891 commit f16b932

File tree

2 files changed

+42
-1
lines changed

2 files changed

+42
-1
lines changed

docs/core/event_handler/bedrock_agent_function.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,48 @@ To create an agent, use the `BedrockAgentFunctionResolver` to register your tool
208208
```
209209
When the Bedrock Agent invokes your Lambda function with a request to use the "GetWeather" tool and a parameter for "city", the resolver automatically extracts the parameter, passes it to your function, and formats the response.
210210

211+
## Response Format
212+
213+
You can return any type from your tool function, the library will automatically format the response in a way that Bedrock Agents expect.
214+
215+
The response will include:
216+
217+
- The action group name
218+
- The function name
219+
- The function response body, which can be a text response or other structured data in string format
220+
- Any session attributes that were passed in the request or modified during the function execution
221+
222+
The response body will **always be a string**.
223+
224+
If you want to return an object the best practice is to override the `ToString()` method of your return type to provide a custom string representation, or if you don't override, create an anonymous object `return new {}` and pass your object, or simply return a string directly.
225+
226+
```csharp
227+
public class AirportInfo
228+
{
229+
public string City { get; set; } = string.Empty;
230+
public string Code { get; set; } = string.Empty;
231+
public string Name { get; set; } = string.Empty;
232+
233+
public override string ToString()
234+
{
235+
return $"{Name} ({Code}) in {City}";
236+
}
237+
}
238+
239+
resolver.Tool("getAirportCodeForCity", "Get airport code and full name for a specific city", (string city, ILambdaContext context) =>
240+
{
241+
var airportService = new AirportService();
242+
var airportInfo = airportService.GetAirportInfoForCity(city);
243+
// Note: Best approach is to override the ToString method in the AirportInfo class
244+
return airportInfo;
245+
});
246+
247+
//Alternatively, you can return an anonymous object if you dont override ToString()
248+
// return new {
249+
// airportInfo
250+
// };
251+
```
252+
211253
## How It Works with Amazon Bedrock Agents
212254

213255
1. When a user interacts with a Bedrock Agent, the agent identifies when it needs to call an action to fulfill the user's request.

examples/Event Handler/BedrockAgentFunction/infra/lib/bedrockagents-stack.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import { Runtime, Function as LambdaFunction, Code, Architecture } from 'aws-cdk
1111
import { LogGroup, RetentionDays } from 'aws-cdk-lib/aws-logs';
1212
import { CfnAgent } from 'aws-cdk-lib/aws-bedrock';
1313
import {
14-
Effect,
1514
PolicyDocument,
1615
PolicyStatement,
1716
Role,

0 commit comments

Comments
 (0)