-
-
Notifications
You must be signed in to change notification settings - Fork 715
feat(mongodb): add requested docs and minimal usage example #1127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
911d3be
d59ad0e
6185353
ef863b8
76dab7a
be1fd71
545a62a
7d0eb68
548468c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@voltagent/mongodb": minor | ||
| --- | ||
|
|
||
| Initial release of MongoDB memory storage adapter |
| 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/ |
| 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: | ||
| 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ensure integration teardown runs even when tests fail. 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
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||
| "types": "dist/index.d.ts" | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
📝 Committable suggestion
🤖 Prompt for AI Agents