Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
123 changes: 123 additions & 0 deletions bedrock-agent-openai-cdk/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
# Amazon Bedrock Agent with OpenAI model

This pattern deploys an Amazon Bedrock Agent powered by an OpenAI GPT OSS foundation model with an AWS Lambda action group that provides tool-use capabilities.

Learn more about this pattern at Serverless Land Patterns: https://serverlessland.com/patterns/bedrock-agent-openai-cdk

Important: this application uses various AWS services and there are costs associated with these services after the Free Tier usage - please see the [AWS Pricing page](https://aws.amazon.com/pricing/) for details. You are responsible for any AWS costs incurred. No warranty is implied in this example.

## Requirements

* [Create an AWS account](https://portal.aws.amazon.com/gp/aws/developer/registration/index.html) if you do not already have one and log in. The IAM user that you use must have sufficient permissions to make necessary AWS service calls and manage AWS resources.
* [AWS CLI](https://docs.aws.amazon.com/cli/latest/userguide/install-cliv2.html) installed and configured
* [Git Installed](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
* [Node.js 22+](https://nodejs.org/en/download/) installed
* [AWS CDK v2](https://docs.aws.amazon.com/cdk/v2/guide/getting-started.html) installed
* [Amazon Bedrock model access](https://docs.aws.amazon.com/bedrock/latest/userguide/model-access.html) enabled for OpenAI GPT OSS 20B in your target region

## Architecture
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Convert this to an image, rather than ASCII.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed in 0759a62. Thank you!


![Architecture diagram showing User sending a request to Amazon Bedrock Agent (OpenAI GPT OSS), which orchestrates tool use by invoking an AWS Lambda action group handler with getWeather and getTime tools](architecture.png)

*Figure 1: The user sends a natural language query to the Bedrock Agent. The agent uses the OpenAI GPT OSS model to reason about which tools to call, invokes the Lambda action group, and synthesizes the result.*

## How it works

1. The Bedrock Agent receives a natural language query from the user.
2. The agent uses the OpenAI GPT OSS foundation model to reason about the query and decide which tools to call.
3. When the agent determines it needs weather or time data, it invokes the Lambda action group with the appropriate API path and parameters.
4. The Lambda function returns structured data, which the agent incorporates into its final natural language response.

## Deployment Instructions

1. Clone the repository:
```bash
git clone https://github.com/aws-samples/serverless-patterns
cd serverless-patterns/bedrock-agent-openai-cdk
```

2. Install dependencies:
```bash
npm install
```

3. Deploy the stack:
```bash
cdk deploy
```

4. Note the outputs printed after deployment. You will need `AgentId` and `AgentAliasId` for testing.
Example output:
```
Outputs:
BedrockAgentOpenaiStack.AgentId = 2VHQREVYJM
BedrockAgentOpenaiStack.AgentAliasId = WRP0JKNQFL
BedrockAgentOpenaiStack.FunctionName = BedrockAgentOpenaiStack-ActionGroupFn-AbCdEfGh
```

## Testing

The Bedrock Agent `InvokeAgent` API returns a streaming response, so use the Python SDK (not the CLI). Replace `<AgentId>` and `<AgentAliasId>` with the values from the deploy output:

```bash
python3 -c "
import boto3, json
client = boto3.client('bedrock-agent-runtime', region_name='us-east-1')
response = client.invoke_agent(
agentId='<AgentId>',
agentAliasId='<AgentAliasId>',
sessionId='test-session-1',
inputText='What is the weather in Tokyo?'
)
for event in response['completion']:
if 'chunk' in event:
print(event['chunk']['bytes'].decode())
"
```

For example, if your deploy output showed AgentId = `2VHQREVYJM` and AgentAliasId = `WRP0JKNQFL`:

```bash
python3 -c "
import boto3
client = boto3.client('bedrock-agent-runtime', region_name='us-east-1')
response = client.invoke_agent(
agentId='2VHQREVYJM',
agentAliasId='WRP0JKNQFL',
sessionId='test-session-1',
inputText='What is the weather in Tokyo?'
)
for event in response['completion']:
if 'chunk' in event:
print(event['chunk']['bytes'].decode())
"
```

Try a multi-tool query:

```bash
python3 -c "
import boto3
client = boto3.client('bedrock-agent-runtime', region_name='us-east-1')
response = client.invoke_agent(
agentId='<AgentId>',
agentAliasId='<AgentAliasId>',
sessionId='test-session-2',
inputText='What is the weather and current time in London?'
)
for event in response['completion']:
if 'chunk' in event:
print(event['chunk']['bytes'].decode())
"
```

## Cleanup

```bash
cdk destroy
```

----
Copyright 2026 Amazon.com, Inc. or its affiliates. All Rights Reserved.

SPDX-License-Identifier: MIT-0
Binary file added bedrock-agent-openai-cdk/architecture.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
83 changes: 83 additions & 0 deletions bedrock-agent-openai-cdk/bedrock-agent-openai-cdk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
{
"title": "Amazon Bedrock Agent with OpenAI model",
"description": "Deploy an Amazon Bedrock Agent powered by OpenAI GPT OSS with an AWS Lambda action group for tool use.",
"language": "TypeScript",
"level": "300",
"framework": "AWS CDK",
"services": {
"from": "bedrock",
"to": "lambda"
},
"introBox": {
"headline": "How it works",
"text": [
"This pattern deploys an Amazon Bedrock Agent that uses an OpenAI GPT OSS foundation model to orchestrate tool-use workflows. The agent reasons about user queries and invokes a Lambda action group to retrieve weather and time data.",
"OpenAI GPT OSS models are available on Amazon Bedrock with the same security, governance, and API experience as other Bedrock models. The agent uses the standard Bedrock Agent orchestration to plan and execute multi-step tool calls."
]
},
"gitHub": {
"template": {
"repoURL": "https://github.com/aws-samples/serverless-patterns/tree/main/bedrock-agent-openai-cdk",
"templateURL": "serverless-patterns/bedrock-agent-openai-cdk",
"projectFolder": "bedrock-agent-openai-cdk",
"templateFile": "lib/bedrock-agent-openai-stack.ts"
}
},
"resources": {
"bullets": [
{
"text": "Amazon Bedrock Agents",
"link": "https://docs.aws.amazon.com/bedrock/latest/userguide/agents.html"
},
{
"text": "OpenAI models on Amazon Bedrock",
"link": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-openai.html"
},
{
"text": "Bedrock Agent action groups",
"link": "https://docs.aws.amazon.com/bedrock/latest/userguide/agents-action-create.html"
}
]
},
"deploy": {
"text": [
"cdk deploy"
],
"file": "lib/bedrock-agent-openai-stack.ts"
},
"testing": {
"text": [
"See the README for testing instructions."
]
},
"cleanup": {
"text": [
"cdk destroy"
]
},
"authors": [
{
"name": "Nithin Chandran R",
"bio": "Technical Account Manager at AWS",
"linkedin": "nithin-chandran-r"
}
],
"patternArch": {
"icon1": {
"x": 20,
"y": 50,
"service": "bedrock",
"label": "Bedrock Agent"
},
"icon2": {
"x": 50,
"y": 50,
"service": "lambda",
"label": "Lambda"
},
"line1": {
"from": "icon1",
"to": "icon2"
}
}
}
8 changes: 8 additions & 0 deletions bedrock-agent-openai-cdk/bin/app.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env node
import "source-map-support/register";
import * as cdk from "aws-cdk-lib";
import { BedrockAgentOpenaiStack } from "../lib/bedrock-agent-openai-stack";

const description = "Sample app (uksb-1tthgi812) (tag:bedrock-agent-openai-cdk)"
const app = new cdk.App();
new BedrockAgentOpenaiStack(app, "BedrockAgentOpenaiStack",{description});
3 changes: 3 additions & 0 deletions bedrock-agent-openai-cdk/cdk.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"app": "npx ts-node --prefer-ts-exts bin/app.ts"
}
50 changes: 50 additions & 0 deletions bedrock-agent-openai-cdk/example-pattern.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"title": "Amazon Bedrock Agent with OpenAI model",
"description": "Deploy an Amazon Bedrock Agent powered by OpenAI GPT OSS with a Lambda action group for tool use.",
"language": "TypeScript",
"level": "300",
"framework": "AWS CDK",
"services": {
"from": "bedrock",
"to": "lambda"
},
"introBox": {
"headline": "How it works",
"text": [
"This pattern deploys an Amazon Bedrock Agent that uses an OpenAI GPT OSS foundation model to orchestrate tool-use workflows. The agent reasons about user queries and invokes a Lambda action group to retrieve weather and time data.",
"OpenAI GPT OSS models are available on Amazon Bedrock with the same security, governance, and API experience as other Bedrock models. The agent uses the standard Bedrock Agent orchestration to plan and execute multi-step tool calls."
]
},
"gitHub": {
"template": {
"repoURL": "https://github.com/aws-samples/serverless-patterns/tree/main/bedrock-agent-openai-cdk",
"templateURL": "serverless-patterns/bedrock-agent-openai-cdk",
"projectFolder": "bedrock-agent-openai-cdk",
"templateFile": "lib/bedrock-agent-openai-stack.ts"
}
},
"resources": {
"bullets": [
{ "text": "Amazon Bedrock Agents", "link": "https://docs.aws.amazon.com/bedrock/latest/userguide/agents.html" },
{ "text": "OpenAI models on Amazon Bedrock", "link": "https://docs.aws.amazon.com/bedrock/latest/userguide/model-parameters-openai.html" },
{ "text": "Bedrock Agent action groups", "link": "https://docs.aws.amazon.com/bedrock/latest/userguide/agents-action-create.html" }
]
},
"deploy": {
"text": ["cdk deploy"],
"file": "lib/bedrock-agent-openai-stack.ts"
},
"testing": {
"text": ["See the README for testing instructions."]
},
"cleanup": {
"text": ["cdk destroy"]
},
"authors": [
{
"name": "Nithin Chandran R",
"bio": "Technical Account Manager at AWS",
"linkedin": "nithin-chandran-r"
}
]
}
Loading