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
5 changes: 5 additions & 0 deletions .changeset/mongodb-feature-storage.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@voltagent/mongodb": minor
---

Initial release of MongoDB memory storage adapter
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Suggested change
Initial release of MongoDB memory storage adapter
feat: initial release of MongoDB memory storage adapter

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we also add minimal usage example?

7 changes: 7 additions & 0 deletions examples/with-mongodb/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# MongoDB Configuration
MONGO_URI=mongodb://localhost:27017
# or for Atlas:
# MONGO_URI=mongodb+srv://user:password@cluster.mongodb.net

# OpenAI API Key (required)
OPENAI_API_KEY=your_openai_api_key_here
3 changes: 3 additions & 0 deletions examples/with-mongodb/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules
dist
.env
53 changes: 53 additions & 0 deletions examples/with-mongodb/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<div align="center">
<a href="https://voltagent.dev/">
<img width="1800" alt="435380213-b6253409-8741-462b-a346-834cd18565a9" src="https://github.com/user-attachments/assets/452a03e7-eeda-4394-9ee7-0ffbcf37245c" />
</a>

<br/>
<br/>

<div align="center">
<a href="https://voltagent.dev">Home Page</a> |
<a href="https://voltagent.dev/docs/">Documentation</a> |
<a href="https://github.com/voltagent/voltagent/tree/main/examples">Examples</a> |
<a href="https://s.voltagent.dev/discord">Discord</a> |
<a href="https://voltagent.dev/blog/">Blog</a>
</div>
</div>

<br/>

<div align="center">
<strong>VoltAgent is an open source TypeScript framework for building and orchestrating AI agents.</strong><br>
Escape the limitations of no-code builders and the complexity of starting from scratch.
<br />
<br />
</div>

<div align="center">

[![npm version](https://img.shields.io/npm/v/@voltagent/core.svg)](https://www.npmjs.com/package/@voltagent/core)
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.0-4baaaa.svg)](CODE_OF_CONDUCT.md)
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.

⚠️ Potential issue | 🟡 Minor

Fix broken Contributor Covenant link path.

Line 30 links to CODE_OF_CONDUCT.md relative to this example folder, which likely breaks. Point it to the repo-root file.

Suggested fix
-[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.0-4baaaa.svg)](CODE_OF_CONDUCT.md)
+[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.0-4baaaa.svg)](../../CODE_OF_CONDUCT.md)
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.0-4baaaa.svg)](CODE_OF_CONDUCT.md)
[![Contributor Covenant](https://img.shields.io/badge/Contributor%20Covenant-2.0-4baaaa.svg)](../../CODE_OF_CONDUCT.md)
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@examples/with-mongodb/README.md` at line 30, The Contributor Covenant badge
links to a relative CODE_OF_CONDUCT.md that breaks for this example; update the
badge link target (the Markdown starting with [![Contributor Covenant] and
pointing to CODE_OF_CONDUCT.md) to reference the repo root (e.g.
/CODE_OF_CONDUCT.md) so it resolves correctly from the example folder.

[![Discord](https://img.shields.io/discord/1361559153780195478.svg?label=&logo=discord&logoColor=ffffff&color=7389D8&labelColor=6A7EC2)](https://s.voltagent.dev/discord)
[![Twitter Follow](https://img.shields.io/twitter/follow/voltagent_dev?style=social)](https://twitter.com/voltagent_dev)

</div>

<br/>

<div align="center">
<a href="https://voltagent.dev/">
<img width="896" alt="VoltAgent Schema" src="https://github.com/user-attachments/assets/f0627868-6153-4f63-ba7f-bdfcc5dd603d" />
</a>

</div>

## VoltAgent: Build AI Agents Fast and Flexibly

VoltAgent is an open-source TypeScript framework for creating and managing AI agents. It provides modular components to build, customize, and scale agents with ease. From connecting to APIs and memory management to supporting multiple LLMs, VoltAgent simplifies the process of creating sophisticated AI systems. It enables fast development, maintains clean code, and offers flexibility to switch between models and tools without vendor lock-in.

## Try Example

```bash
npm create voltagent-app@latest -- --example with-mongodb
```
41 changes: 41 additions & 0 deletions examples/with-mongodb/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "voltagent-example-with-mongodb",
"description": "VoltAgent example demonstrating MongoDB integration for memory.",
"author": "",
"dependencies": {
"@voltagent/cli": "^0.1.21",
"@voltagent/core": "^2.3.1",
"@voltagent/logger": "^2.0.2",
"@voltagent/mongodb": "^2.0.2",
"@voltagent/server-hono": "^2.0.4",
"ai": "^6.0.0",
"mongodb": "^7.0.0",
"zod": "^3.25.76"
},
"devDependencies": {
"@types/node": "^24.2.1",
"tsx": "^4.19.3",
"typescript": "^5.8.2"
},
"keywords": [
"agent",
"ai",
"memory",
"mongodb",
"voltagent"
],
"license": "MIT",
"private": true,
"repository": {
"type": "git",
"url": "https://github.com/VoltAgent/voltagent.git",
"directory": "examples/with-mongodb"
},
"scripts": {
"build": "tsc",
"dev": "tsx watch --env-file=.env ./src",
"start": "node dist/index.js",
"volt": "volt"
},
"type": "module"
}
42 changes: 42 additions & 0 deletions examples/with-mongodb/src/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import { Agent, Memory, VoltAgent } from "@voltagent/core";
import { createPinoLogger } from "@voltagent/logger";
import { MongoDBMemoryAdapter } from "@voltagent/mongodb";
import { honoServer } from "@voltagent/server-hono";

// Configure MongoDB Memory
const memoryStorage = new MongoDBMemoryAdapter({
// MongoDB connection URI
connection: process.env.MONGO_URI || "mongodb://localhost:27017",

// Optional: Database name (default: "voltagent")
database: "voltagent",

// Optional: Customize collection name prefix
collectionPrefix: "voltagent_memory",

// Optional: Enable debug logging for storage
debug: process.env.NODE_ENV === "development",
});

const agent = new Agent({
name: "MongoDB Memory Agent",
instructions: "A helpful assistant that remembers conversations using MongoDB.",
model: "openai/gpt-4o-mini",
memory: new Memory({
storage: memoryStorage,
}),
});

// Create logger
const logger = createPinoLogger({
name: "with-mongodb",
level: "info",
});

new VoltAgent({
agents: {
agent,
},
logger,
server: honoServer({ port: 3141 }),
});
17 changes: 17 additions & 0 deletions examples/with-mongodb/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "./dist",
"rootDir": "./src",
"module": "ESNext",
"target": "ES2022",
"moduleResolution": "node"
Comment on lines +6 to +8
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.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

cat -n tsconfig.json

Repository: VoltAgent/voltagent

Length of output: 902


🏁 Script executed:

cat -n packages/mongodb/package.json | head -50

Repository: VoltAgent/voltagent

Length of output: 1780


🏁 Script executed:

cat -n examples/with-mongodb/tsconfig.json

Repository: VoltAgent/voltagent

Length of output: 507


Align ESM resolution with NodeNext to properly resolve conditional package exports.

Line 8 uses "moduleResolution": "node", which ignores package.json exports field and can cause resolution mismatches with packages like @voltagent/mongodb that use conditional exports. Since the example uses "module": "ESNext" (ESM), set moduleResolution to "NodeNext" to ensure correct export variant resolution.

Suggested fix
   "compilerOptions": {
       "outDir": "./dist",
       "rootDir": "./src",
       "module": "ESNext",
       "target": "ES2022",
-      "moduleResolution": "node"
+      "moduleResolution": "NodeNext"
   },
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@examples/with-mongodb/tsconfig.json` around lines 6 - 8, The tsconfig sets
"module": "ESNext" but uses "moduleResolution": "node", which can ignore
package.json "exports" and break ESM conditional exports; update the
tsconfig.json by changing the moduleResolution field from "node" to "NodeNext"
so TypeScript resolves the correct ESM export variants when compiling with
"module": "ESNext".

},
"include": [
"src/**/*"
],
"exclude": [
"dist",
"node_modules"
]
}
40 changes: 40 additions & 0 deletions packages/mongodb/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# @voltagent/mongodb

MongoDB storage adapter for VoltAgent memory.

## Installation

```bash
npm install @voltagent/mongodb
```

## Usage

```typescript
import { MongoDBMemoryAdapter } from "@voltagent/mongodb";
import { Memory } from "@voltagent/core";

const memory = new Memory({
storage: new MongoDBMemoryAdapter({
connection: process.env.MONGO_URI,
database: "voltagent", // optional
collectionPrefix: "voltagent_memory", // optional
}),
});
```

## Features

- **Persistent Storage**: Stores messages, conversations, and workflow states in MongoDB.
- **Efficient Queries**: Indexed for fast retrieval by user, conversation, or date.
- **Type Safe**: Fully typed implementation of the VoltAgent StorageAdapter interface.
- **Workflow Support**: Native support for resuming suspended workflows.

## Configuration

| Option | Type | Default | Description |
| ------------------ | --------- | -------------------- | ---------------------- |
| `connection` | `string` | required | MongoDB connection URI |
| `database` | `string` | `"voltagent"` | Database name |
| `collectionPrefix` | `string` | `"voltagent_memory"` | Prefix for collections |
| `debug` | `boolean` | `false` | Enable debug logging |
18 changes: 18 additions & 0 deletions packages/mongodb/docker-compose.test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
services:
mongodb-test:
image: mongo:7.0
container_name: 'voltagent-mongodb-test'
ports:
- '27017:27017'
environment:
MONGO_INITDB_DATABASE: voltagent_test
volumes:
- test_mongodb_data:/data/db
healthcheck:
test: ["CMD", "mongosh", "--eval", "db.adminCommand('ping')"]
interval: 2s
timeout: 5s
retries: 10

volumes:
test_mongodb_data:
55 changes: 55 additions & 0 deletions packages/mongodb/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"name": "@voltagent/mongodb",
"description": "VoltAgent MongoDB - MongoDB Memory provider integration for VoltAgent",
"version": "2.0.2",
"dependencies": {
"mongodb": "^7.0.0"
},
"devDependencies": {
"@vitest/coverage-v8": "^3.2.4",
"@voltagent/core": "^2.0.2",
"ai": "^6.0.0"
},
"exports": {
".": {
"import": {
"types": "./dist/index.d.mts",
"default": "./dist/index.mjs"
},
"require": {
"types": "./dist/index.d.ts",
"default": "./dist/index.js"
}
}
},
"files": [
"dist"
],
"license": "MIT",
"main": "dist/index.js",
"module": "dist/index.mjs",
"peerDependencies": {
"@voltagent/core": "^2.0.0",
"ai": "^6.0.0"
},
"repository": {
"type": "git",
"url": "https://github.com/VoltAgent/voltagent.git",
"directory": "packages/mongodb"
},
"scripts": {
"attw": "attw --pack",
"build": "tsup",
"dev": "tsup --watch",
"lint": "biome check .",
"lint:fix": "biome check . --write",
"publint": "publint --strict",
"test": "vitest",
"test:coverage": "vitest run --coverage",
"test:integration": "npm run test:integration:setup && vitest run --config vitest.integration.config.mts && npm run test:integration:teardown",
"test:integration:ci": "vitest run --config vitest.integration.config.mts",
"test:integration:setup": "docker compose -f docker-compose.test.yaml up -d && sleep 10",
"test:integration:teardown": "docker compose -f docker-compose.test.yaml down -v"
},
"types": "dist/index.d.ts"
}
Loading