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
Copy file name to clipboardExpand all lines: docs/core/event_handler/bedrock_agent_function.md
+42Lines changed: 42 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -208,6 +208,48 @@ To create an agent, use the `BedrockAgentFunctionResolver` to register your tool
208
208
```
209
209
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.
210
210
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
+
publicclassAirportInfo
228
+
{
229
+
publicstringCity { get; set; } =string.Empty;
230
+
publicstringCode { get; set; } =string.Empty;
231
+
publicstringName { get; set; } =string.Empty;
232
+
233
+
publicoverridestringToString()
234
+
{
235
+
return$"{Name} ({Code}) in {City}";
236
+
}
237
+
}
238
+
239
+
resolver.Tool("getAirportCodeForCity", "Get airport code and full name for a specific city", (stringcity, ILambdaContextcontext) =>
0 commit comments