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
67 changes: 67 additions & 0 deletions packages/mongodb/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
# @voltagent/mongodb

MongoDB storage adapter for VoltAgent memory.

## Installation

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

## Minimal Usage

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

const agent = new Agent({
name: "Assistant",
model: "openai/gpt-4o-mini",
memory: new Memory({
storage: new MongoDBMemoryAdapter({
connection: process.env.MONGODB_URI!,
database: process.env.MONGODB_DATABASE ?? "voltagent",
}),
}),
});
```

Example environment variables:

```bash
MONGODB_URI=mongodb://localhost:27017
MONGODB_DATABASE=voltagent
```

Customize collection names when you need to isolate multiple apps in the same database:

```typescript
const memory = new Memory({
storage: new MongoDBMemoryAdapter({
connection: process.env.MONGODB_URI!,
database: process.env.MONGODB_DATABASE ?? "voltagent",
collectionPrefix: "support_bot",
}),
});
```

## Features

- **Persistent Storage**: Stores messages, conversations, conversation steps, workflow states, and working memory 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 |

## Learn More

- Memory overview: https://voltagent.dev/docs/agents/memory/overview/
- MongoDB memory docs: https://voltagent.dev/docs/agents/memory/mongodb/
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:
Comment on lines +4 to +7
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

Avoid global container/port collisions in test compose setup.
Line 4 and Line 6 hardcode a shared container name and host port, which can break local/CI runs when MongoDB is already bound or jobs run concurrently.

Suggested adjustment
-    container_name: 'voltagent-mongodb-test'
     ports:
-      - '27017:27017'
+      - '${MONGODB_TEST_PORT:-27017}:27017'
📝 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
container_name: 'voltagent-mongodb-test'
ports:
- '27017:27017'
environment:
ports:
- '${MONGODB_TEST_PORT:-27017}:27017'
environment:
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/mongodb/docker-compose.test.yaml` around lines 4 - 7, The
docker-compose test file hardcodes container_name and host port mapping
(container_name: 'voltagent-mongodb-test' and ports: - '27017:27017'), causing
global collisions in concurrent/local CI runs; remove the fixed container_name
and avoid binding the container port to the host by either deleting the
container_name line and changing ports to expose only the container port (e.g.,
"27017" or no host mapping) or make the host port configurable using an env var
(e.g., replace '27017:27017' with "${MONGO_PORT:-27017}:27017" or use
project-scoped names like "${COMPOSE_PROJECT_NAME:-voltagent}-mongodb-test") so
tests can run in parallel without collisions.

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"
},
Comment on lines +49 to +53
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

Ensure integration teardown runs even when tests fail.
Line 49 currently skips teardown on test failure, leaving containers/volumes behind.

Suggested fix
-    "test:integration": "npm run test:integration:setup && vitest run --config vitest.integration.config.mts && npm run test:integration:teardown",
+    "test:integration": "sh -c 'npm run test:integration:setup; code=0; vitest run --config vitest.integration.config.mts || code=$?; npm run test:integration:teardown; exit $code'",
📝 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
"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"
},
"test:integration": "sh -c 'npm run test:integration:setup; code=0; vitest run --config vitest.integration.config.mts || code=$?; npm run test:integration:teardown; exit $code'",
"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"
},
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/mongodb/package.json` around lines 49 - 53, The integration script
currently uses "&&" so test:integration:teardown only runs on successful tests;
change test:integration to run test:integration:setup, run the vitest command
inside a shell that captures its exit code, always runs npm run
test:integration:teardown, then exits with the original vitest code. Update the
"test:integration" script (referencing test:integration, test:integration:setup,
and test:integration:teardown) to wrap the vitest invocation so teardown always
executes even when tests fail and the process returns the original test exit
status.

"types": "dist/index.d.ts"
}
Loading