Skip to content

Commit

Permalink
feat: add mem0 storage backend
Browse files Browse the repository at this point in the history
  • Loading branch information
phil65 committed Jan 29, 2025
1 parent e772348 commit 82c87dd
Show file tree
Hide file tree
Showing 6 changed files with 342 additions and 1 deletion.
23 changes: 23 additions & 0 deletions docs/concepts/storage.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,29 @@ storage:
```
Provides temporary storage without persistence, ideal for testing and development.
### Mem0 Storage
The mem0 provider offers semantic-powered conversation history with cloud persistence:
```yaml
storage:
providers:
- type: mem0
api_key: "your-mem0-api-key" # Required if no MEM0_API_KEY env var set
page_size: 100 # Results per page for queries
output_format: "v1.1" # API version format
```
Features:
- Semantic search capabilities
- Long-term memory persistence
- Cloud-hosted (no local setup)
- Automatic context management
- Advanced filtering options
- API version selection (v1.0/v1.1)
## Provider Capabilities
History Providers (SQL, File):
Expand Down
1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ markdown = ["markitdown"]
textual = ["textual>=1.0.0"]
litellm = ["litellm"]
remote = ["websockets>=14.2"]
mem0 = ["mem0ai>=0.1.48"]

[tool.uv]
default-groups = ["dev", "lint", "docs"]
Expand Down
95 changes: 95 additions & 0 deletions schema/config-schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -3487,6 +3487,97 @@
"title": "MarkItDownConfig",
"type": "object"
},
"Mem0Config": {
"additionalProperties": false,
"description": "Configuration for mem0 storage.",
"properties": {
"type": {
"const": "mem0",
"default": "mem0",
"description": "Type discriminator for storage config.",
"title": "Type",
"type": "string"
},
"log_messages": {
"default": true,
"description": "Whether to log messages",
"title": "Log Messages",
"type": "boolean"
},
"agents": {
"anyOf": [
{
"items": {
"type": "string"
},
"type": "array",
"uniqueItems": true
},
{
"type": "null"
}
],
"default": null,
"description": "Optional set of agent names to include. If None, logs all agents.",
"title": "Agents"
},
"log_conversations": {
"default": true,
"description": "Whether to log conversations",
"title": "Log Conversations",
"type": "boolean"
},
"log_tool_calls": {
"default": true,
"description": "Whether to log tool calls",
"title": "Log Tool Calls",
"type": "boolean"
},
"log_commands": {
"default": true,
"description": "Whether to log command executions",
"title": "Log Commands",
"type": "boolean"
},
"log_context": {
"default": true,
"description": "Whether to log context messages.",
"title": "Log Context",
"type": "boolean"
},
"api_key": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"description": "API key for mem0 service.",
"title": "Api Key"
},
"page_size": {
"default": 100,
"description": "Number of results per page when retrieving paginated data.",
"title": "Page Size",
"type": "integer"
},
"output_format": {
"default": "v1.1",
"description": "API output format version. 1.1 is recommended and provides enhanced details.",
"enum": [
"v1.0",
"v1.1"
],
"title": "Output Format",
"type": "string"
}
},
"title": "Mem0Config",
"type": "object"
},
"MemoryConfig": {
"additionalProperties": false,
"description": "Configuration for agent memory and history handling.",
Expand Down Expand Up @@ -5201,6 +5292,7 @@
"discriminator": {
"mapping": {
"file": "#/$defs/FileStorageConfig",
"mem0": "#/$defs/Mem0Config",
"memory": "#/$defs/MemoryStorageConfig",
"sql": "#/$defs/SQLStorageConfig",
"text_file": "#/$defs/TextLogConfig"
Expand All @@ -5219,6 +5311,9 @@
},
{
"$ref": "#/$defs/MemoryStorageConfig"
},
{
"$ref": "#/$defs/Mem0Config"
}
]
},
Expand Down
23 changes: 22 additions & 1 deletion src/llmling_agent/models/storage.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import os
from typing import Annotated, Final, Literal

from platformdirs import user_data_dir
Expand Down Expand Up @@ -101,8 +102,28 @@ class MemoryStorageConfig(BaseStorageProviderConfig):
type: Literal["memory"] = Field("memory", init=False)


class Mem0Config(BaseStorageProviderConfig):
"""Configuration for mem0 storage."""

type: Literal["mem0"] = Field("mem0", init=False)
"""Type discriminator for storage config."""

api_key: str | None = os.getenv("MEM0_API_KEY")
"""API key for mem0 service."""

page_size: int = 100
"""Number of results per page when retrieving paginated data."""

output_format: Literal["v1.0", "v1.1"] = "v1.1"
"""API output format version. 1.1 is recommended and provides enhanced details."""


StorageProviderConfig = Annotated[
SQLStorageConfig | FileStorageConfig | TextLogConfig | MemoryStorageConfig,
SQLStorageConfig
| FileStorageConfig
| TextLogConfig
| MemoryStorageConfig
| Mem0Config,
Field(discriminator="type"),
]

Expand Down
7 changes: 7 additions & 0 deletions src/llmling_agent/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from llmling_agent.models.storage import (
BaseStorageProviderConfig,
FileStorageConfig,
Mem0Config,
MemoryStorageConfig,
SQLStorageConfig,
TextLogConfig,
Expand Down Expand Up @@ -104,6 +105,12 @@ def _create_provider(self, config: BaseStorageProviderConfig) -> StorageProvider
from llmling_agent_storage.text_log_provider import TextLogProvider

return TextLogProvider(provider_config)

case Mem0Config():
from llmling_agent_storage.mem0 import Mem0StorageProvider

return Mem0StorageProvider(provider_config)

case MemoryStorageConfig():
from llmling_agent_storage.memory_provider import MemoryStorageProvider

Expand Down
Loading

0 comments on commit 82c87dd

Please sign in to comment.