Skip to content

Commit 7547201

Browse files
committed
chore: switch to serverless airline
1 parent 8c52a62 commit 7547201

File tree

8 files changed

+47
-54
lines changed

8 files changed

+47
-54
lines changed

docs/features/event-handler/bedrock-agents.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ Currently, we don't support parsing `array` types, so you will receive them as s
8080

8181
=== "Define a tool"
8282

83-
```typescript hl_lines="4 6 22"
83+
```typescript hl_lines="4 6 20"
8484
--8<-- "examples/snippets/event-handler/bedrock-agents/gettingStartedFunctionsTool.ts"
8585
```
8686

@@ -121,7 +121,7 @@ When Bedrock Agents invoke your Lambda function, it can pass session attributes
121121

122122
=== "Working with session attributes"
123123

124-
```typescript hl_lines="25-28"
124+
```typescript hl_lines="24-27"
125125
--8<-- "examples/snippets/event-handler/bedrock-agents/sessionAttributes.ts"
126126
```
127127

examples/snippets/event-handler/bedrock-agents/accessEventAndContext.ts

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,12 @@ app.tool<{ city: string }>(
1010

1111
return {
1212
city,
13-
temperature: '20°C',
14-
condition: 'Sunny',
13+
airportCode: 'XYZ', // Simulated airport code for the city
1514
};
1615
},
1716
{
18-
name: 'getWeatherForCity',
19-
description: 'Get weather for a specific city',
17+
name: 'getAirportCodeForCity',
18+
description: 'Get the airport code for a given city',
2019
}
2120
);
2221

examples/snippets/event-handler/bedrock-agents/debugLogging.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,21 @@ import { Logger } from '@aws-lambda-powertools/logger';
33
import type { Context } from 'aws-lambda';
44

55
const logger = new Logger({
6-
serviceName: 'WeatherServiceAgent',
6+
serviceName: 'serverlessAirline',
77
logLevel: 'DEBUG',
88
});
99
const app = new BedrockAgentFunctionResolver({ logger });
1010

1111
app.tool<{ city: string }>(
1212
async ({ city }) => {
13-
// Simulate fetching weather data for the city
1413
return {
1514
city,
16-
temperature: '20°C',
17-
condition: 'Sunny',
15+
airportCode: 'XYZ', // Simulated airport code for the city
1816
};
1917
},
2018
{
21-
name: 'getWeatherForCity',
22-
description: 'Get weather for a specific city',
19+
name: 'getAirportCodeForCity',
20+
description: 'Get the airport code for a given city',
2321
}
2422
);
2523

examples/snippets/event-handler/bedrock-agents/gettingStartedFunctionsTool.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,14 @@ const app = new BedrockAgentFunctionResolver();
55

66
app.tool<{ city: string }>(
77
async ({ city }) => {
8-
// Simulate fetching weather data for the city
98
return {
109
city,
11-
temperature: '20°C',
12-
condition: 'Sunny',
10+
airportCode: 'XYZ',
1311
};
1412
},
1513
{
16-
name: 'getWeatherForCity',
17-
description: 'Get weather for a specific city', // (1)!
14+
name: 'getAirportCodeForCity',
15+
description: 'Get the airport code for a given city', // (1)!
1816
}
1917
);
2018

examples/snippets/event-handler/bedrock-agents/sessionAttributes.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,25 +14,24 @@ app.tool<{ city: string }>(
1414
knowledgeBasesConfiguration,
1515
} = event;
1616

17-
// your logic to fetch weather data for the city
17+
// your logic to fetch airport code for the city
1818

1919
return new BedrockFunctionResponse({
2020
body: JSON.stringify({
2121
city,
22-
temperature: '20°C',
23-
condition: 'Sunny',
22+
airportCode: 'XYZ',
2423
}),
2524
sessionAttributes: {
2625
...sessionAttributes,
27-
isGoodWeather: true,
26+
isCommercialAirport: true,
2827
},
2928
promptSessionAttributes,
3029
knowledgeBasesConfiguration,
3130
});
3231
},
3332
{
34-
name: 'getWeatherForCity',
35-
description: 'Get weather for a specific city',
33+
name: 'getAirportCodeForCity',
34+
description: 'Get the airport code for a given city',
3635
}
3736
);
3837

examples/snippets/event-handler/bedrock-agents/stopConversation.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ app.tool<{ city: string }>(
1717
knowledgeBasesConfiguration,
1818
} = event;
1919
return new BedrockFunctionResponse({
20-
body: `An error occurred while fetching the weather data for ${city}`,
20+
body: `An error occurred while fetching the airport code for ${city}`,
2121
responseState: 'FAILURE',
2222
sessionAttributes,
2323
promptSessionAttributes,
@@ -26,8 +26,8 @@ app.tool<{ city: string }>(
2626
}
2727
},
2828
{
29-
name: 'getWeatherForCity',
30-
description: 'Get weather for a specific city',
29+
name: 'getAirportCodeForCity',
30+
description: 'Get the airport code for a given city',
3131
}
3232
);
3333

examples/snippets/event-handler/bedrock-agents/templates/gettingStartedCdk.ts

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ export class BedrockAgentsStack extends Stack {
1616
super(scope, id, props);
1717

1818
const fnName = 'BedrockAgentsFn';
19-
const logGroup = new LogGroup(this, 'WeatherAgentLogGroup', {
19+
const logGroup = new LogGroup(this, 'AirlineAgentLogGroup', {
2020
logGroupName: `/aws/lambda/${fnName}`,
2121
removalPolicy: RemovalPolicy.DESTROY,
2222
retention: RetentionDays.ONE_DAY,
2323
});
24-
const fn = new NodejsFunction(this, 'WeatherAgentFunction', {
24+
const fn = new NodejsFunction(this, 'AirlineAgentFunction', {
2525
functionName: fnName,
2626
logGroup,
2727
runtime: Runtime.NODEJS_22_X,
@@ -35,9 +35,9 @@ export class BedrockAgentsStack extends Stack {
3535
},
3636
});
3737

38-
const agentRole = new Role(this, 'WeatherAgentRole', {
38+
const agentRole = new Role(this, 'AirlineAgentRole', {
3939
assumedBy: new ServicePrincipal('bedrock.amazonaws.com'),
40-
description: 'Role for Bedrock weather agent',
40+
description: 'Role for Bedrock Airline agent',
4141
inlinePolicies: {
4242
bedrock: new PolicyDocument({
4343
statements: [
@@ -69,23 +69,24 @@ export class BedrockAgentsStack extends Stack {
6969
},
7070
});
7171

72-
const agent = new CfnAgent(this, 'WeatherAgent', {
73-
agentName: 'weatherAgent',
72+
const agent = new CfnAgent(this, 'AirlineAgent', {
73+
agentName: 'AirlineAgent',
7474
actionGroups: [
7575
{
76-
actionGroupName: 'weatherActionGroup',
76+
actionGroupName: 'AirlineActionGroup',
7777
actionGroupExecutor: {
7878
lambda: fn.functionArn,
7979
},
8080
functionSchema: {
8181
functions: [
8282
{
83-
name: 'getWeatherForCity',
84-
description: 'Get weather for a specific city',
83+
name: 'getAirportCodeForCity',
84+
description: 'Get the airport code for a given city',
8585
parameters: {
8686
city: {
8787
type: 'string',
88-
description: 'The name of the city to get the weather for',
88+
description:
89+
'The name of the city to get the airport code for',
8990
required: true,
9091
},
9192
},
@@ -96,10 +97,10 @@ export class BedrockAgentsStack extends Stack {
9697
],
9798
agentResourceRoleArn: agentRole.roleArn,
9899
autoPrepare: true,
99-
description: 'A simple weather agent',
100+
description: 'A simple Airline agent',
100101
foundationModel: `arn:aws:bedrock:us-west-2:${Stack.of(this).account}:inference-profile/us.amazon.nova-pro-v1:0`,
101102
instruction:
102-
'You are a weather forecast news anchor. You will be asked to provide a weather forecast for one or more cities. You will provide a weather forecast for each city as if you were a TV news anchor. While doing so, include the region or country of the city received from the tool. You will provide the forecast in a conversational tone, as if you were speaking to a viewer on a TV news program.',
103+
'You are an airport traffic control agent. You will be given a city name and you will return the airport code for that city.',
103104
});
104105
fn.addPermission('BedrockAgentInvokePermission', {
105106
principal: new ServicePrincipal('bedrock.amazonaws.com'),

examples/snippets/event-handler/bedrock-agents/templates/gettingStartedSam.yaml

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,11 @@ Resources:
1414
Handler: index.handler
1515
CodeUri: hello_world
1616

17-
# IAM Role for Bedrock Agent
18-
WeatherAgentRole:
17+
AirlineAgentRole:
1918
Type: AWS::IAM::Role
2019
Properties:
21-
RoleName: !Sub '${AWS::StackName}-WeatherAgentRole'
22-
Description: 'Role for Bedrock weather agent'
20+
RoleName: !Sub '${AWS::StackName}-AirlineAgentRole'
21+
Description: 'Role for Bedrock Airline agent'
2322
AssumeRolePolicyDocument:
2423
Version: '2012-10-17'
2524
Statement:
@@ -38,37 +37,36 @@ Resources:
3837
- !Sub 'arn:aws:bedrock:us-*::foundation-model/*'
3938
- !Sub 'arn:aws:bedrock:us-*:*:inference-profile/*'
4039

41-
# Lambda Permission for Bedrock Agent
4240
BedrockAgentInvokePermission:
4341
Type: AWS::Lambda::Permission
4442
Properties:
4543
FunctionName: !Ref HelloWorldFunction
4644
Action: lambda:InvokeFunction
4745
Principal: bedrock.amazonaws.com
4846
SourceAccount: !Ref 'AWS::AccountId'
49-
SourceArn: !Sub 'arn:aws:bedrock:${AWS::Region}:${AWS::AccountId}:agent/${WeatherAgent}'
47+
SourceArn: !Sub 'arn:aws:bedrock:${AWS::Region}:${AWS::AccountId}:agent/${AirlineAgent}'
5048

5149
# Bedrock Agent
52-
WeatherAgent:
50+
AirlineAgent:
5351
Type: AWS::Bedrock::Agent
5452
Properties:
55-
AgentName: weatherAgent
56-
Description: 'A simple weather agent'
53+
AgentName: AirlineAgent
54+
Description: 'A simple Airline agent'
5755
FoundationModel: !Sub 'arn:aws:bedrock:us-west-2:${AWS::AccountId}:inference-profile/us.amazon.nova-pro-v1:0'
5856
Instruction: |
59-
You are a weather forecast news anchor. You will be asked to provide a weather forecast for one or more cities. You will provide a weather forecast for each city as if you were a TV news anchor. While doing so, include the region or country of the city received from the tool. You will provide the forecast in a conversational tone, as if you were speaking to a viewer on a TV news program.
60-
AgentResourceRoleArn: !GetAtt WeatherAgentRole.Arn
57+
You are an airport traffic control agent. You will be given a city name and you will return the airport code for that city.
58+
AgentResourceRoleArn: !GetAtt AirlineAgentRole.Arn
6159
AutoPrepare: true
6260
ActionGroups:
63-
- ActionGroupName: weatherActionGroup
61+
- ActionGroupName: AirlineActionGroup
6462
ActionGroupExecutor:
65-
Lambda: !GetAtt WeatherAgentFunction.Arn
63+
Lambda: !GetAtt AirlineAgentFunction.Arn
6664
FunctionSchema:
6765
Functions:
68-
- Name: getWeatherForCity
69-
Description: 'Get weather for a specific city'
66+
- Name: getAirportCodeForCity
67+
Description: 'Get the airport code for a given city'
7068
Parameters:
7169
city:
7270
Type: string
73-
Description: 'The name of the city to get the weather for'
71+
Description: 'The name of the city to get the airport code for'
7472
Required: true

0 commit comments

Comments
 (0)