Skip to content

Commit 8c52a62

Browse files
committed
chore: add bedrock agents to readme
1 parent 42efba0 commit 8c52a62

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

packages/event-handler/README.md

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,86 @@ export const handler = async (event, context) =>
104104

105105
## Bedrock Agent Functions
106106

107+
Event Handler for Amazon Bedrock Agent Functions.
108+
109+
* Easily expose tools for your Large Language Model (LLM) agents
110+
* Automatic routing based on tool name and function details
111+
* Graceful error handling and response formatting
112+
113+
### Handle tool use
114+
115+
When using the Bedrock Agent Functions event handler, you can register a handler for a specific tool name. The handler will be called when the agent uses that tool.
116+
117+
```typescript
118+
import { BedrockAgentFunctionResolver } from '@aws-lambda-powertools/event-handler/bedrock-agent';
119+
import type { Context } from 'aws-lambda';
120+
121+
const app = new BedrockAgentFunctionResolver();
122+
123+
app.tool<{ city: string }>(
124+
async ({ city }) => {
125+
// Simulate fetching weather data for the city
126+
return {
127+
city,
128+
temperature: '20°C',
129+
condition: 'Sunny',
130+
};
131+
},
132+
{
133+
name: 'getWeatherForCity',
134+
description: 'Get weather for a specific city', // (1)!
135+
}
136+
);
137+
138+
export const handler = async (event: unknown, context: Context) =>
139+
app.resolve(event, context);
140+
```
141+
142+
You can also work with session attributes, which are key-value pairs that can be used to store information about the current session. The session attributes are automatically passed to the handler and can be used to store information that needs to be persisted across multiple tool invocations.
143+
144+
```typescript
145+
import {
146+
BedrockAgentFunctionResolver,
147+
BedrockFunctionResponse,
148+
} from '@aws-lambda-powertools/event-handler/bedrock-agent';
149+
import type { Context } from 'aws-lambda';
150+
151+
const app = new BedrockAgentFunctionResolver();
152+
153+
app.tool<{ city: string }>(
154+
async ({ city }, { event }) => {
155+
const {
156+
sessionAttributes,
157+
promptSessionAttributes,
158+
knowledgeBasesConfiguration,
159+
} = event;
160+
161+
// your logic to fetch weather data for the city
162+
163+
return new BedrockFunctionResponse({
164+
body: JSON.stringify({
165+
city,
166+
temperature: '20°C',
167+
condition: 'Sunny',
168+
}),
169+
sessionAttributes: {
170+
...sessionAttributes,
171+
isGoodWeather: true,
172+
},
173+
promptSessionAttributes,
174+
knowledgeBasesConfiguration,
175+
});
176+
},
177+
{
178+
name: 'getWeatherForCity',
179+
description: 'Get weather for a specific city',
180+
}
181+
);
182+
183+
export const handler = async (event: unknown, context: Context) =>
184+
app.resolve(event, context);
185+
```
186+
107187
See the [documentation](https://docs.powertools.aws.dev/lambda/typescript/latest/features/event-handler/appsync-events) for more details on how to use the AppSync event handler.
108188

109189
## Contribute

0 commit comments

Comments
 (0)