Skip to content

Commit 50535ba

Browse files
authored
Merge pull request #134 from mongodb-developer/openai-agents-sdk-js
OpenAI Agents SDK for TypeScript
2 parents f90ac3b + 6ed4b09 commit 50535ba

File tree

11 files changed

+1864
-0
lines changed

11 files changed

+1864
-0
lines changed

apps/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ Javascript and Python apps and demos showcasing how to use MongoDB in GenAI appl
66
| Local RAG PDF | MongoDB Atlas, Python | Local RAG implementation for PDF processing and querying | [![View Code](https://img.shields.io/badge/view-code-blue?logo=github)](local-rag-pdf) |
77
| Lyric Semantic Search | MongoDB Atlas, Spring AI, Java | Semantic search service for song lyrics with metadata filtering using Spring AI framework | [![View Code](https://img.shields.io/badge/view-code-blue?logo=github)](lyric-semantic-search) |
88
| MongoMP | MongoDB Atlas, Next.js 14, Node.js | Music streaming platform with AI-powered recommendations using vector search and real-time tracking | [![View Code](https://img.shields.io/badge/view-code-blue?logo=github)](mongo-mp) |
9+
| OpenAI Agents SDK | MongoDB Atlas, TypeScript, OpenAI Agents SDK | Template for using OpenAI Agents SDK with MongoDB as a memory store for conversation history | [![View Code](https://img.shields.io/badge/view-code-blue?logo=github)](openai-agents-sdk) |
910
| RT Voice TS Store Agent | MongoDB Atlas, Next.js, WebRTC, OpenAI | Voice-controlled e-commerce platform with real-time voice processing and hybrid search | [![View Code](https://img.shields.io/badge/view-code-blue?logo=github)](RT-voice-ts-store-agent) |
1011
| SpringAI Terraform RAG | MongoDB Atlas, Spring Boot, Terraform, OpenAI | RAG application with automated infrastructure setup using Terraform and Spring Boot | [![View Code](https://img.shields.io/badge/view-code-blue?logo=github)](springai-terraform-rag) |
1112
| Voice OpenAI Rentals Agent | MongoDB Atlas, Python, Flask, OpenAI | Voice interaction agent for real estate listings using vector search and real-time voice processing | [![View Code](https://img.shields.io/badge/view-code-blue?logo=github)](voice-openai-mongo-rentals-agent) |
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
MONGODB_URI=your_connection_string
2+
OPENAI_API_KEY=sk-...

apps/openai-agents-sdk/.gitignore

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Dependency directories
2+
node_modules/
3+
jspm_packages/
4+
5+
# Build outputs
6+
dist/
7+
build/
8+
out/
9+
.next/
10+
.nuxt/
11+
12+
# Coverage directories
13+
coverage/
14+
.nyc_output/
15+
16+
# Environment variables
17+
.env
18+
.env.local
19+
.env.development.local
20+
.env.test.local
21+
.env.production.local
22+
23+
# Logs
24+
logs/
25+
*.log
26+
npm-debug.log*
27+
yarn-debug.log*
28+
yarn-error.log*
29+
lerna-debug.log*
30+
31+
# Cache directories
32+
.npm/
33+
.eslintcache
34+
.stylelintcache
35+
.rpt2_cache/
36+
.rts2_cache_cjs/
37+
.rts2_cache_es/
38+
.rts2_cache_umd/
39+
40+
# Editor directories and files
41+
.idea/
42+
.vscode/
43+
*.swp
44+
*.swo
45+
.DS_Store
46+
Thumbs.db
47+
48+
# TypeScript cache
49+
*.tsbuildinfo
50+
51+
# Next.js
52+
.vercel
53+
54+
# MongoDB
55+
*.pem

apps/openai-agents-sdk/README.md

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# OpenAI Agents SDK with MongoDB Memory
2+
3+
This demo app shows how to use the [OpenAI Agents SDK](https://openai.github.io/openai-agents-js/) with [MongoDB](https://www.mongodb.com/cloud/atlas/register/?utm_campaign=devrel&utm_source=third-party-content&utm_medium=cta&utm_content=openai-agents-sdk-template&utm_term=jesse.hall) for persistent conversation history.
4+
5+
## Key Features
6+
7+
- Uses MongoDB to store conversation history
8+
- Leverages the SDK's built-in message handling capabilities
9+
- Custom tool to access user profile information
10+
- Simple implementation for educational purposes
11+
12+
## Getting Started
13+
14+
1. Download this app folder using:
15+
```bash
16+
npx degit mongodb-developer/GenAI-Showcase/apps/openai-agents-sdk my-openai-agent
17+
```
18+
19+
2. Make sure MongoDB is set up and running
20+
21+
3. Copy the example environment file and add your credentials:
22+
```bash
23+
cp .env.example .env
24+
```
25+
Then update the `.env` file with your information:
26+
```
27+
MONGODB_URI=mongodb://localhost:27017/agent_memory
28+
OPENAI_API_KEY=your_openai_api_key
29+
```
30+
31+
4. Install dependencies:
32+
```bash
33+
npm install
34+
```
35+
36+
5. Build the TypeScript:
37+
```bash
38+
npm run build
39+
```
40+
41+
6. Run the demo:
42+
```bash
43+
npm start
44+
```
45+
46+
## How It Works
47+
48+
The demo shows a hybrid approach to conversation memory:
49+
50+
1. **MongoDB for Persistence**: Messages are saved to MongoDB so they persist across server restarts
51+
2. **SDK's Message Handling**: We use the SDK's built-in `user()` and `assistant()` functions to format message history
52+
3. **Context-Aware Tools**: Custom tools can access application context including user profiles
53+
4. **Simple Interface**: Clean implementation with minimal code
54+
55+
## Demo Conversation
56+
57+
The demo runs a simple conversation that demonstrates:
58+
1. Basic question answering
59+
2. Memory of previous questions (asking about "its population" after asking about France)
60+
3. Using a tool to fetch user profile information
61+
62+
## Project Structure
63+
64+
- `src/db.ts`: MongoDB connection and conversation storage functions
65+
- `src/agent.ts`: OpenAI Agents SDK implementation with custom tools
66+
- `src/types.ts`: TypeScript type definitions for conversations and context
67+
- `src/index.ts`: Demo script that runs a sample conversation
68+
69+
## License
70+
71+
MIT

0 commit comments

Comments
 (0)