-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomplete_setup_example.py
More file actions
134 lines (103 loc) Β· 4.18 KB
/
complete_setup_example.py
File metadata and controls
134 lines (103 loc) Β· 4.18 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
131
132
133
134
#!/usr/bin/env python3
"""
Complete Eion Setup and Usage Example
This example demonstrates the full Eion workflow:
1. Setup server infrastructure
2. Run the server
3. Use cluster management features
4. Clean up
IMPORTANT: This will download ~3GB of dependencies on first run!
"""
import os
import time
from eiondb import EionClient, EionError
def main():
"""Complete Eion example"""
print("π Eion Complete Setup and Usage Example")
print("=" * 50)
client = EionClient(
cluster_api_key=os.getenv("EION_CLUSTER_API_KEY", "my-secret-api-key-123")
)
try:
# Step 1: Setup infrastructure (one-time, downloads ~3GB)
print("\nπ¦ Setting up Eion infrastructure...")
print(" This will download Docker images, Python packages, and AI models")
print(" (This may take several minutes on first run)")
client.setup()
# Step 2: Run server in background
print("\nπ Starting Eion server in background...")
client.run(detached=True)
# Wait a moment for server to be ready
print(" Waiting for server to be ready...")
time.sleep(5)
# Step 3: Verify server is healthy
if client.server_health():
print("β
Server is healthy and ready!")
else:
print("β Server not responding - check setup")
return 1
# Step 4: Use cluster management features
print("\nπ’ Demonstrating cluster management...")
# Create a user
print(" Creating user...")
user = client.create_user(
user_id="demo_user",
name="Demo User"
)
print(f" β
Created user: {user['user_id']}")
# Register an agent
print(" Registering agent...")
agent = client.register_agent(
agent_id="demo_agent",
name="Demo Assistant Agent",
permission="crud",
description="A demo agent for testing multi-agent memory"
)
print(f" β
Registered agent: {agent['agent_id']}")
# Create a session
print(" Creating session...")
session = client.create_session(
session_id="demo_session",
user_id="demo_user"
)
print(f" β
Created session: {session['session_id']}")
# Show how agents would use HTTP directly for memory operations
print("\nπ€ Agent memory operations (via HTTP):")
print(" Agents can now use these endpoints:")
print(" POST http://localhost:8080/sessions/v1/demo_session/memories?agent_id=demo_agent&user_id=demo_user")
print(" GET http://localhost:8080/sessions/v1/demo_session/memories?agent_id=demo_agent&user_id=demo_user")
print(" GET http://localhost:8080/sessions/v1/demo_session/memories/search?agent_id=demo_agent&user_id=demo_user&query=pizza")
print("\nβ
Example completed successfully!")
print("\nπ Server is running in background")
print(" - Use client.stop() to stop the server")
print(" - Use client.reset() to clean everything")
print(" - Server URL: http://localhost:8080")
return 0
except EionError as e:
print(f"\nβ Example failed: {e}")
return 1
def cleanup_example():
"""Example of how to clean up Eion"""
print("\nπ§Ή Cleanup Example")
print("=" * 20)
client = EionClient()
try:
# Stop the server
print("π Stopping server...")
client.stop()
# Reset everything to clean state
print("π Resetting to clean state...")
client.reset()
print("β
Cleanup complete!")
except EionError as e:
print(f"β Cleanup failed: {e}")
if __name__ == "__main__":
import sys
if len(sys.argv) > 1 and sys.argv[1] == "cleanup":
cleanup_example()
else:
exit_code = main()
if exit_code == 0:
print("\n" + "=" * 50)
print("π‘ To clean up, run: python complete_setup_example.py cleanup")
sys.exit(exit_code)