-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy-memory-system.sh
More file actions
363 lines (300 loc) · 11 KB
/
Copy pathdeploy-memory-system.sh
File metadata and controls
363 lines (300 loc) · 11 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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
#!/bin/bash
# Deploy Memory-Enhanced Agent System
# This script sets up the complete persistent memory system for FuzeAgent
set -e # Exit on any error
echo "🚀 Deploying FuzeAgent Memory-Enhanced Agent System"
echo "================================================="
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Check required environment variables
check_env_vars() {
echo -e "${BLUE}🔍 Checking environment variables...${NC}"
required_vars=("DATABASE_URL" "ANTHROPIC_API_KEY")
missing_vars=()
for var in "${required_vars[@]}"; do
if [ -z "${!var}" ]; then
missing_vars+=("$var")
fi
done
if [ ${#missing_vars[@]} -ne 0 ]; then
echo -e "${RED}❌ Missing required environment variables:${NC}"
for var in "${missing_vars[@]}"; do
echo -e "${RED} - $var${NC}"
done
echo ""
echo "Please set these variables and run the script again."
echo "Example:"
echo "export DATABASE_URL='postgresql://postgres:password@localhost:5434/ai_context'"
echo "export ANTHROPIC_API_KEY='your-api-key-here'"
exit 1
fi
echo -e "${GREEN}✅ All required environment variables are set${NC}"
}
# Check if database is accessible
check_database() {
echo -e "${BLUE}🔍 Checking database connection...${NC}"
python3 -c "
import asyncpg
import asyncio
import os
async def test_connection():
try:
conn = await asyncpg.connect(os.environ['DATABASE_URL'])
await conn.fetchval('SELECT 1')
await conn.close()
print('✅ Database connection successful')
except Exception as e:
print(f'❌ Database connection failed: {e}')
exit(1)
asyncio.run(test_connection())
" || {
echo -e "${RED}❌ Database connection failed. Please ensure the database is running and accessible.${NC}"
exit 1
}
}
# Run database migrations
run_migrations() {
echo -e "${BLUE}🗄️ Running database migrations...${NC}"
# Migration 003: Persistent agent memory schema
echo -e "${YELLOW} Running migration 003: Persistent agent memory schema${NC}"
python3 -c "
import asyncpg
import asyncio
import os
async def run_migration():
try:
conn = await asyncpg.connect(os.environ['DATABASE_URL'])
with open('services/orchestrator/migrations/003_add_persistent_agent_memory.sql', 'r') as f:
migration_sql = f.read()
await conn.execute(migration_sql)
await conn.close()
print('✅ Migration 003 completed successfully')
except Exception as e:
if 'already exists' in str(e):
print('✅ Migration 003 already applied')
else:
print(f'❌ Migration 003 failed: {e}')
exit(1)
asyncio.run(run_migration())
"
# Migration 004: Tasks table updates
echo -e "${YELLOW} Running migration 004: Tasks table updates${NC}"
python3 -c "
import asyncpg
import asyncio
import os
async def run_migration():
try:
conn = await asyncpg.connect(os.environ['DATABASE_URL'])
with open('services/orchestrator/migrations/004_update_tasks_for_memory_agents.sql', 'r') as f:
migration_sql = f.read()
await conn.execute(migration_sql)
await conn.close()
print('✅ Migration 004 completed successfully')
except Exception as e:
if 'already exists' in str(e):
print('✅ Migration 004 already applied')
else:
print(f'❌ Migration 004 failed: {e}')
exit(1)
asyncio.run(run_migration())
"
echo -e "${GREEN}✅ All database migrations completed${NC}"
}
# Build memory-enabled agent containers
build_containers() {
echo -e "${BLUE}🐳 Building memory-enabled agent containers...${NC}"
# Build base container
echo -e "${YELLOW} Building base development container${NC}"
docker build -t fuzeagent/dev-base:latest ./containers/templates/dev-base/ || {
echo -e "${RED}❌ Failed to build base container${NC}"
exit 1
}
# Build Python development container
echo -e "${YELLOW} Building Python development container${NC}"
docker build -t fuzeagent/dev-python:latest ./containers/templates/dev-python/ || {
echo -e "${RED}❌ Failed to build Python container${NC}"
exit 1
}
# Build TypeScript development container
echo -e "${YELLOW} Building TypeScript development container${NC}"
docker build -t fuzeagent/dev-typescript:latest ./containers/templates/dev-typescript/ || {
echo -e "${RED}❌ Failed to build TypeScript container${NC}"
exit 1
}
# Build React development container
echo -e "${YELLOW} Building React development container${NC}"
docker build -t fuzeagent/dev-react:latest ./containers/templates/dev-react/ || {
echo -e "${RED}❌ Failed to build React container${NC}"
exit 1
}
echo -e "${GREEN}✅ All agent containers built successfully${NC}"
}
# Install Python dependencies for memory system
install_dependencies() {
echo -e "${BLUE}📦 Installing memory system dependencies...${NC}"
# Check if requirements are satisfied
python3 -c "
import sys
try:
import asyncpg
import sentence_transformers
import numpy
import anthropic
print('✅ All memory system dependencies are installed')
except ImportError as e:
print(f'Installing missing dependency: {e.name}')
sys.exit(1)
" || {
echo -e "${YELLOW} Installing missing dependencies...${NC}"
pip3 install -r containers/templates/agent-process/requirements.txt
}
}
# Test memory system components
test_memory_system() {
echo -e "${BLUE}🧪 Testing memory system components...${NC}"
# Test AgentMemoryManager
echo -e "${YELLOW} Testing AgentMemoryManager...${NC}"
python3 -c "
import sys
import os
sys.path.append('containers/templates/agent-process')
try:
from agent_memory_manager import AgentMemoryManager, MemoryType
print('✅ AgentMemoryManager import successful')
except Exception as e:
print(f'❌ AgentMemoryManager test failed: {e}')
exit(1)
"
# Test ClaudeClientWithMemory
echo -e "${YELLOW} Testing ClaudeClientWithMemory...${NC}"
python3 -c "
import sys
import os
sys.path.append('containers/templates/agent-process')
try:
from claude_client_with_memory import ClaudeClientWithMemory
print('✅ ClaudeClientWithMemory import successful')
except Exception as e:
print(f'❌ ClaudeClientWithMemory test failed: {e}')
exit(1)
"
# Test autonomous agent
echo -e "${YELLOW} Testing AutonomousAgentWithMemory...${NC}"
python3 -c "
import sys
import os
sys.path.append('containers/templates/agent-process')
try:
from autonomous_agent_with_memory import AutonomousAgentWithMemory
print('✅ AutonomousAgentWithMemory import successful')
except Exception as e:
print(f'❌ AutonomousAgentWithMemory test failed: {e}')
exit(1)
"
echo -e "${GREEN}✅ All memory system components tested successfully${NC}"
}
# Create sample data for testing
create_sample_data() {
echo -e "${BLUE}📊 Creating sample data for testing...${NC}"
python3 -c "
import asyncpg
import asyncio
import os
import uuid
from datetime import datetime
async def create_sample_data():
try:
conn = await asyncpg.connect(os.environ['DATABASE_URL'])
# Create sample organization
org_id = str(uuid.uuid4())
await conn.execute('''
INSERT INTO organizations (id, name, description)
VALUES (\$1, 'Sample Development Team', 'Sample organization for testing memory-enabled agents')
ON CONFLICT (name) DO NOTHING
''', org_id)
# Get or create organization
org = await conn.fetchrow('SELECT id FROM organizations WHERE name = \$1', 'Sample Development Team')
org_id = org['id']
# Create sample team
team_id = str(uuid.uuid4())
await conn.execute('''
INSERT INTO teams (id, organization_id, name, description)
VALUES (\$1, \$2, 'Frontend Development', 'Sample frontend development team')
ON CONFLICT (organization_id, name) DO NOTHING
''', team_id, org_id)
# Get or create team
team = await conn.fetchrow('SELECT id FROM teams WHERE name = \$1 AND organization_id = \$2', 'Frontend Development', org_id)
team_id = team['id']
# Create sample agent
agent_id = str(uuid.uuid4())
await conn.execute('''
INSERT INTO agents (id, team_id, name, role, type, status, config)
VALUES (\$1, \$2, 'React Developer AI', 'Senior React Developer', 'developer', 'active', \$3)
ON CONFLICT (team_id, name) DO NOTHING
''', agent_id, team_id, {
'goal': 'Build responsive React applications with modern UI/UX',
'backstory': 'Expert React developer with persistent memory and learning capabilities',
'model': 'claude-3-5-sonnet-20241022',
'temperature': 0.3,
'memory_enabled': True
})
await conn.close()
print('✅ Sample data created successfully')
print(f' Organization ID: {org_id}')
print(f' Team ID: {team_id}')
# Get actual agent ID
conn = await asyncpg.connect(os.environ['DATABASE_URL'])
agent = await conn.fetchrow('SELECT id FROM agents WHERE name = \$1', 'React Developer AI')
if agent:
print(f' Agent ID: {agent[\"id\"]}')
await conn.close()
except Exception as e:
print(f'❌ Failed to create sample data: {e}')
asyncio.run(create_sample_data())
"
}
# Main deployment function
main() {
echo -e "${BLUE}Starting FuzeAgent Memory System Deployment${NC}"
echo ""
# Run all deployment steps
check_env_vars
echo ""
check_database
echo ""
install_dependencies
echo ""
run_migrations
echo ""
build_containers
echo ""
test_memory_system
echo ""
create_sample_data
echo ""
echo -e "${GREEN}🎉 FuzeAgent Memory System Deployment Complete!${NC}"
echo ""
echo -e "${BLUE}Next Steps:${NC}"
echo "1. Start the orchestrator service:"
echo " cd services/orchestrator && uvicorn main:app --host 0.0.0.0 --port 8000"
echo ""
echo "2. Deploy a memory-enabled agent:"
echo " curl -X POST http://localhost:8000/agents/{agent_id}/deploy-memory \\"
echo " -H 'Content-Type: application/json' \\"
echo " -d '{\"template_id\": \"python_developer\"}'"
echo ""
echo "3. View system expertise dashboard:"
echo " curl http://localhost:8000/system/expertise-dashboard"
echo ""
echo "4. Check agent memory status:"
echo " curl http://localhost:8000/agents/{agent_id}/memory-status"
echo ""
echo -e "${GREEN}The persistent memory system is now ready for AI agents!${NC}"
}
# Run main function
main