-
-
Notifications
You must be signed in to change notification settings - Fork 796
feat(mongodb): implement complete MongoDB memory adapter #1000
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
ee9c1ff
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,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 |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| node_modules | ||
| dist | ||
| .env |
| 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"> | ||||||
|
|
||||||
| [](https://www.npmjs.com/package/@voltagent/core) | ||||||
| [](CODE_OF_CONDUCT.md) | ||||||
|
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. Fix broken Line 30 links to Suggested fix-[](CODE_OF_CONDUCT.md)
+[](../../CODE_OF_CONDUCT.md)📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||
| [](https://s.voltagent.dev/discord) | ||||||
| [](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 | ||||||
| ``` | ||||||
| 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" | ||
| } |
| 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 }), | ||
| }); |
| 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
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. 🧩 Analysis chain🏁 Script executed: cat -n tsconfig.jsonRepository: VoltAgent/voltagent Length of output: 902 🏁 Script executed: cat -n packages/mongodb/package.json | head -50Repository: VoltAgent/voltagent Length of output: 1780 🏁 Script executed: cat -n examples/with-mongodb/tsconfig.jsonRepository: VoltAgent/voltagent Length of output: 507 Align ESM resolution with Line 8 uses Suggested fix "compilerOptions": {
"outDir": "./dist",
"rootDir": "./src",
"module": "ESNext",
"target": "ES2022",
- "moduleResolution": "node"
+ "moduleResolution": "NodeNext"
},🤖 Prompt for AI Agents |
||
| }, | ||
| "include": [ | ||
| "src/**/*" | ||
| ], | ||
| "exclude": [ | ||
| "dist", | ||
| "node_modules" | ||
| ] | ||
| } | ||
| 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 | |
| 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" | ||
| }, | ||
| "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.
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.
Can we also add minimal usage example?