mentedb-crewai 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- mentedb_crewai-0.1.0/.gitignore +9 -0
- mentedb_crewai-0.1.0/PKG-INFO +8 -0
- mentedb_crewai-0.1.0/README.md +102 -0
- mentedb_crewai-0.1.0/mentedb_crewai/__init__.py +4 -0
- mentedb_crewai-0.1.0/mentedb_crewai/memory.py +67 -0
- mentedb_crewai-0.1.0/mentedb_crewai/tool.py +35 -0
- mentedb_crewai-0.1.0/pyproject.toml +14 -0
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
# mentedb-crewai
|
|
2
|
+
|
|
3
|
+
MenteDB integration for CrewAI and AutoGen. Gives your multi agent teams persistent, cognitive memory that survives across sessions and tracks reasoning quality over time.
|
|
4
|
+
|
|
5
|
+
## Installation
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
pip install mentedb-crewai
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
## Components
|
|
12
|
+
|
|
13
|
+
### MenteDBCrewMemory
|
|
14
|
+
|
|
15
|
+
A memory backend for CrewAI agents that stores and retrieves memories through MenteDB. Each agent can have its own memory space, or agents on the same team can share a common space for collaborative recall.
|
|
16
|
+
|
|
17
|
+
```python
|
|
18
|
+
from crewai import Agent, Crew, Task
|
|
19
|
+
from mentedb_crewai import MenteDBCrewMemory
|
|
20
|
+
|
|
21
|
+
memory = MenteDBCrewMemory(
|
|
22
|
+
data_dir="./crew-memory",
|
|
23
|
+
space="research-team",
|
|
24
|
+
)
|
|
25
|
+
|
|
26
|
+
researcher = Agent(
|
|
27
|
+
role="Senior Researcher",
|
|
28
|
+
goal="Find comprehensive information on the topic",
|
|
29
|
+
memory=memory,
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
writer = Agent(
|
|
33
|
+
role="Technical Writer",
|
|
34
|
+
goal="Write clear documentation from research",
|
|
35
|
+
memory=MenteDBCrewMemory(
|
|
36
|
+
data_dir="./crew-memory",
|
|
37
|
+
space="research-team",
|
|
38
|
+
agent_name="writer",
|
|
39
|
+
),
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
task = Task(
|
|
43
|
+
description="Research and document the latest trends in vector databases",
|
|
44
|
+
agent=researcher,
|
|
45
|
+
)
|
|
46
|
+
|
|
47
|
+
crew = Crew(agents=[researcher, writer], tasks=[task])
|
|
48
|
+
crew.kickoff()
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Memory is stored persistently, so the next time the crew runs it can recall findings from previous sessions.
|
|
52
|
+
|
|
53
|
+
### MenteDBTool
|
|
54
|
+
|
|
55
|
+
A tool that lets agents query MenteDB directly using MQL (Mente Query Language). Attach it to any agent so the agent can search and retrieve from the team's knowledge base during task execution.
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
from crewai import Agent
|
|
59
|
+
from mentedb_crewai import MenteDBTool
|
|
60
|
+
|
|
61
|
+
memory_tool = MenteDBTool(data_dir="./crew-memory")
|
|
62
|
+
|
|
63
|
+
agent = Agent(
|
|
64
|
+
role="Analyst",
|
|
65
|
+
goal="Analyze data using historical context",
|
|
66
|
+
tools=[memory_tool],
|
|
67
|
+
)
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
The agent can then invoke the tool during its reasoning to recall past decisions, find related context, or check what the team already knows about a topic.
|
|
71
|
+
|
|
72
|
+
## Usage with AutoGen
|
|
73
|
+
|
|
74
|
+
MenteDB works with AutoGen agents through the same memory and tool interfaces. Use `MenteDBCrewMemory` to give AutoGen agents persistent memory, or `MenteDBTool` to let them query the knowledge base.
|
|
75
|
+
|
|
76
|
+
```python
|
|
77
|
+
from mentedb_crewai import MenteDBCrewMemory, MenteDBTool
|
|
78
|
+
|
|
79
|
+
memory = MenteDBCrewMemory(data_dir="./autogen-memory", space="dev-team")
|
|
80
|
+
tool = MenteDBTool(data_dir="./autogen-memory")
|
|
81
|
+
|
|
82
|
+
# Store context from agent work
|
|
83
|
+
memory.store("The team decided to use PostgreSQL for the main database.")
|
|
84
|
+
|
|
85
|
+
# Search for relevant memories
|
|
86
|
+
results = memory.search("database decision", k=5)
|
|
87
|
+
|
|
88
|
+
# Get assembled context within a token budget
|
|
89
|
+
context = memory.get_context("Plan the database migration", token_budget=2000)
|
|
90
|
+
```
|
|
91
|
+
|
|
92
|
+
## Configuration
|
|
93
|
+
|
|
94
|
+
| Parameter | Default | Description |
|
|
95
|
+
|---|---|---|
|
|
96
|
+
| `data_dir` | `./mentedb-data` | Path to the MenteDB data directory |
|
|
97
|
+
| `space` | `default` | Memory space name for agent isolation or sharing |
|
|
98
|
+
| `agent_name` | `None` | Optional agent name for per agent memory scoping |
|
|
99
|
+
|
|
100
|
+
## License
|
|
101
|
+
|
|
102
|
+
Apache 2.0
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
"""CrewAI memory backend powered by MenteDB."""
|
|
2
|
+
from typing import Any, Dict, List, Optional
|
|
3
|
+
|
|
4
|
+
from mentedb import MenteDB
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class MenteDBCrewMemory:
|
|
8
|
+
"""Drop-in memory backend for CrewAI agents.
|
|
9
|
+
|
|
10
|
+
Gives CrewAI agents persistent, cognitive memory with:
|
|
11
|
+
- Cross-session recall
|
|
12
|
+
- Multi-agent memory isolation via spaces
|
|
13
|
+
- Semantic search over past context
|
|
14
|
+
|
|
15
|
+
Usage:
|
|
16
|
+
from crewai import Agent
|
|
17
|
+
from mentedb_crewai import MenteDBCrewMemory
|
|
18
|
+
|
|
19
|
+
memory = MenteDBCrewMemory(
|
|
20
|
+
data_dir="./crew-memory",
|
|
21
|
+
space="research-team",
|
|
22
|
+
)
|
|
23
|
+
|
|
24
|
+
agent = Agent(
|
|
25
|
+
role="Researcher",
|
|
26
|
+
memory=memory,
|
|
27
|
+
)
|
|
28
|
+
"""
|
|
29
|
+
|
|
30
|
+
def __init__(self, data_dir: str = "./mentedb-data", space: str = "default",
|
|
31
|
+
agent_name: Optional[str] = None):
|
|
32
|
+
self.data_dir = data_dir
|
|
33
|
+
self.space = space
|
|
34
|
+
self.agent_name = agent_name
|
|
35
|
+
self._db = MenteDB(data_dir)
|
|
36
|
+
|
|
37
|
+
def store(self, content: str, metadata: Optional[Dict[str, Any]] = None) -> str:
|
|
38
|
+
"""Store a memory from the agent's work."""
|
|
39
|
+
tags = [self.space]
|
|
40
|
+
if self.agent_name:
|
|
41
|
+
tags.append(self.agent_name)
|
|
42
|
+
if metadata and "tags" in metadata:
|
|
43
|
+
tags.extend(metadata["tags"])
|
|
44
|
+
memory_type = (metadata or {}).get("memory_type", "episodic")
|
|
45
|
+
return self._db.store(content, memory_type=memory_type, tags=tags)
|
|
46
|
+
|
|
47
|
+
def search(self, query: str, k: int = 5) -> List[Dict[str, Any]]:
|
|
48
|
+
"""Search for relevant memories."""
|
|
49
|
+
results = self._db.search_text(query, k=k, tags=[self.space])
|
|
50
|
+
docs = []
|
|
51
|
+
for r in results:
|
|
52
|
+
mem = self._db.get_memory(r.id)
|
|
53
|
+
if mem:
|
|
54
|
+
docs.append({
|
|
55
|
+
"content": mem["content"],
|
|
56
|
+
"score": r.score,
|
|
57
|
+
"id": r.id,
|
|
58
|
+
"memory_type": mem.get("memory_type", ""),
|
|
59
|
+
})
|
|
60
|
+
return docs
|
|
61
|
+
|
|
62
|
+
def get_context(self, task_description: str, token_budget: int = 2000) -> str:
|
|
63
|
+
"""Get assembled context for a task using MQL recall."""
|
|
64
|
+
result = self._db.recall(
|
|
65
|
+
f"RECALL memories WHERE content ~> \"{task_description}\" LIMIT 10"
|
|
66
|
+
)
|
|
67
|
+
return result.text if result else ""
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
"""CrewAI tool for querying MenteDB with MQL."""
|
|
2
|
+
|
|
3
|
+
from mentedb import MenteDB
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class MenteDBTool:
|
|
7
|
+
"""A CrewAI tool that lets agents query their memory database directly.
|
|
8
|
+
|
|
9
|
+
Usage:
|
|
10
|
+
from crewai import Agent
|
|
11
|
+
from mentedb_crewai import MenteDBTool
|
|
12
|
+
|
|
13
|
+
memory_tool = MenteDBTool(data_dir="./crew-memory")
|
|
14
|
+
|
|
15
|
+
agent = Agent(
|
|
16
|
+
role="Researcher",
|
|
17
|
+
tools=[memory_tool],
|
|
18
|
+
)
|
|
19
|
+
"""
|
|
20
|
+
|
|
21
|
+
name: str = "mentedb_query"
|
|
22
|
+
description: str = (
|
|
23
|
+
"Query the team's knowledge database using MQL (Mente Query Language). "
|
|
24
|
+
"Use for recalling past decisions, finding related context, or checking "
|
|
25
|
+
"what the team knows about a topic."
|
|
26
|
+
)
|
|
27
|
+
|
|
28
|
+
def __init__(self, data_dir: str = "./mentedb-data"):
|
|
29
|
+
self.data_dir = data_dir
|
|
30
|
+
self._db = MenteDB(data_dir)
|
|
31
|
+
|
|
32
|
+
def run(self, query: str) -> str:
|
|
33
|
+
"""Execute an MQL query and return assembled context."""
|
|
34
|
+
result = self._db.recall(query)
|
|
35
|
+
return result.text if result else ""
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "mentedb-crewai"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "MenteDB integration for CrewAI and AutoGen"
|
|
5
|
+
license = "Apache-2.0"
|
|
6
|
+
requires-python = ">=3.9"
|
|
7
|
+
dependencies = [
|
|
8
|
+
"mentedb>=0.7.0",
|
|
9
|
+
"crewai>=0.30",
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
[build-system]
|
|
13
|
+
requires = ["hatchling"]
|
|
14
|
+
build-backend = "hatchling.build"
|