-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-agent.sh
More file actions
executable file
Β·149 lines (123 loc) Β· 4.29 KB
/
Copy pathrun-agent.sh
File metadata and controls
executable file
Β·149 lines (123 loc) Β· 4.29 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
#!/bin/bash
# GPT20 Agent Runner - Convenience script to start portfolio-db and run the agent
set -e # Exit on any error
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
echo -e "${BLUE}π GPT20 Agent Runner${NC}"
echo "=================================="
# Check if we're in the right directory
if [ ! -f "README.md" ] || [ ! -d "agent" ] || [ ! -d "services/portfolio-db" ]; then
echo -e "${RED}β Error: Must run from the claude-20 project root directory${NC}"
exit 1
fi
# Function to check if port is in use
check_port() {
local port=$1
if lsof -Pi :$port -sTCP:LISTEN -t >/dev/null 2>&1; then
return 0 # Port is in use
else
return 1 # Port is free
fi
}
# Step 1: Check/Start Portfolio Database Server
echo -e "${YELLOW}π Checking portfolio database server...${NC}"
if check_port 8080; then
echo -e "${GREEN}β
Portfolio-db server already running on port 8080${NC}"
else
echo -e "${YELLOW}π Starting portfolio-db server...${NC}"
# Navigate to portfolio-db directory
cd services/portfolio-db
# Check if binary exists, build if needed
if [ ! -f "portfolio-db" ]; then
echo -e "${YELLOW}π¨ Building portfolio-db server...${NC}"
go build -o portfolio-db || {
echo -e "${RED}β Failed to build portfolio-db server${NC}"
exit 1
}
fi
# Start the server in background
nohup ./portfolio-db > server.log 2>&1 &
SERVER_PID=$!
# Wait for server to start
echo -e "${YELLOW}β³ Waiting for server to start...${NC}"
sleep 3
# Check if server is running
if check_port 8080; then
echo -e "${GREEN}β
Portfolio-db server started successfully (PID: $SERVER_PID)${NC}"
else
echo -e "${RED}β Failed to start portfolio-db server${NC}"
echo "Check server.log for details:"
tail -10 server.log
exit 1
fi
# Return to project root
cd ../..
fi
# Step 2: Health check
echo -e "${YELLOW}π₯ Performing health check...${NC}"
if curl -f -s http://localhost:8080/health > /dev/null; then
echo -e "${GREEN}β
Health check passed${NC}"
else
echo -e "${RED}β Health check failed - server may not be ready${NC}"
exit 1
fi
# Step 3: Check Python environment
echo -e "${YELLOW}π Checking Python environment...${NC}"
# Check if we're in a virtual environment
if [ -z "$VIRTUAL_ENV" ]; then
echo -e "${YELLOW}β οΈ Not in a virtual environment${NC}"
echo -e "${YELLOW}π‘ Consider activating your venv: source venv/bin/activate${NC}"
fi
# Check for required packages
if ! python3 -c "import strands, yfinance, requests" 2>/dev/null; then
echo -e "${RED}β Missing required Python packages${NC}"
echo "Install with: pip install strands yfinance requests"
exit 1
fi
# Check for OpenAI API key
if [ -z "$OPENAI_API_KEY" ]; then
echo -e "${RED}β OPENAI_API_KEY environment variable not set${NC}"
echo "Set it with: export OPENAI_API_KEY='your-key-here'"
exit 1
fi
echo -e "${GREEN}β
Python environment ready${NC}"
# Step 4: Run the agent
echo ""
echo -e "${BLUE}π€ Starting GPT20 Agent...${NC}"
echo "=================================="
# Navigate to agent directory and run
cd agent
python3 -m src.main
echo ""
echo -e "${GREEN}β
Agent execution completed!${NC}"
# Step 5: Show results
echo ""
echo -e "${BLUE}π Portfolio Summary${NC}"
echo "=================================="
# Try to get portfolio summary via API
echo "Current portfolio status:"
curl -s -X POST http://localhost:8080/mcp \
-H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "id": 1, "method": "tools/call", "params": {"name": "get_portfolio_summary", "arguments": {}}}' | \
python3 -c "
import json, sys
try:
data = json.load(sys.stdin)
if 'result' in data and 'content' in data['result']:
print(data['result']['content'][0]['text'])
else:
print('No portfolio data available')
except:
print('Could not retrieve portfolio summary')
"
echo ""
echo -e "${GREEN}π Done! Check the updated portfolio at:${NC}"
echo -e "${BLUE} π agent/md/indices/GPT20.md${NC}"
echo -e "${BLUE} π https://hunterjsb.github.io/gpt-500/${NC}"
echo ""
echo -e "${YELLOW}π‘ To stop the portfolio-db server:${NC}"
echo " pkill -f portfolio-db"