forked from MemMachine/MemMachine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_integration.py
More file actions
executable file
·130 lines (104 loc) · 3.31 KB
/
test_integration.py
File metadata and controls
executable file
·130 lines (104 loc) · 3.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#!/usr/bin/env python3
"""
Quick test script for CrewAI + MemMachine integration.
This script tests the basic functionality without requiring a full CrewAI setup.
"""
import sys
from .tool import MemMachineTools, create_memmachine_tools
def test_memmachine_tools() -> None:
"""Test MemMachineTools class."""
print("=" * 60)
print("Test 1: MemMachineTools Class")
print("=" * 60)
# Create tools instance
tools = MemMachineTools(
base_url="http://localhost:8080",
org_id="test_org",
project_id="test_project",
user_id="test_user",
)
print("✓ Tools instance created")
print(f" - org_id: {tools.org_id}")
print(f" - project_id: {tools.project_id}")
print(f" - user_id: {tools.user_id}")
print()
def test_create_tools() -> None:
"""Test create_memmachine_tools function."""
print("=" * 60)
print("Test 2: create_memmachine_tools Function")
print("=" * 60)
try:
tools = create_memmachine_tools(
base_url="http://localhost:8080",
org_id="test_org",
project_id="test_project",
user_id="test_user",
)
print(f"✓ Created {len(tools)} tools")
for i, tool in enumerate(tools, 1):
tool_name = getattr(tool, "name", getattr(tool, "__name__", "Unknown"))
print(f" {i}. {tool_name}")
print()
except Exception as e:
print(f"⚠ Tool creation test skipped: {e}")
print(" (This is expected if CrewAI is not installed)")
print()
def test_playground_mode() -> None:
"""Test with playground mode."""
print("=" * 60)
print("Test 3: Playground Mode")
print("=" * 60)
from memmachine_client import MemMachineClient
# Create client with playground mode
client = MemMachineClient(
base_url="http://localhost:8080",
is_playground=True,
)
# Create tools with playground client
tools = MemMachineTools(
client=client,
org_id="playground_org",
project_id="playground_project",
)
# Test add memory (should work in playground mode)
try:
result = tools.add_memory(
content="Test memory in playground mode",
role="user",
)
print(f"✓ Add memory test: {result['status']}")
print(f" Message: {result.get('message', 'N/A')}")
except Exception as e:
print(f"⚠ Add memory test skipped: {e}")
# Test search memory
try:
result = tools.search_memory(
query="test",
limit=5,
)
print(f"✓ Search memory test: {result['status']}")
print(f" Summary: {result.get('summary', 'N/A')[:100]}...")
except Exception as e:
print(f"⚠ Search memory test skipped: {e}")
print()
def main() -> int:
"""Run all tests."""
print("\n" + "=" * 60)
print("CrewAI + MemMachine Integration Tests")
print("=" * 60 + "\n")
try:
test_memmachine_tools()
test_create_tools()
test_playground_mode()
print("=" * 60)
print(" All tests completed!")
print("=" * 60)
except Exception as e:
print(f"\n✗ Error: {e}")
import traceback
traceback.print_exc()
return 1
else:
return 0
if __name__ == "__main__":
sys.exit(main())