mageagent-local 2.0.1

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.
@@ -0,0 +1,218 @@
1
+ #!/bin/bash
2
+ # MageAgent Server Launcher
3
+ # Multi-Model LLM Orchestrator for MLX
4
+
5
+ MAGEAGENT_DIR="$HOME/.claude/mageagent"
6
+ LOG_FILE="$HOME/.claude/debug/mageagent.log"
7
+ ERROR_LOG="$HOME/.claude/debug/mageagent.error.log"
8
+ PID_FILE="$MAGEAGENT_DIR/mageagent.pid"
9
+ PORT=3457
10
+
11
+ # Ensure directories exist
12
+ mkdir -p "$HOME/.claude/debug"
13
+ mkdir -p "$MAGEAGENT_DIR"
14
+
15
+ usage() {
16
+ echo "MageAgent Server - Multi-Model LLM Orchestrator"
17
+ echo ""
18
+ echo "Usage: $0 {start|stop|restart|status|logs|test}"
19
+ echo ""
20
+ echo "Commands:"
21
+ echo " start - Start the MageAgent server"
22
+ echo " stop - Stop the MageAgent server"
23
+ echo " restart - Restart the MageAgent server"
24
+ echo " status - Check if server is running"
25
+ echo " logs - Tail the server logs"
26
+ echo " test - Run a quick test against the server"
27
+ echo ""
28
+ echo "API Endpoints:"
29
+ echo " mageagent:auto - Intelligent task routing"
30
+ echo " mageagent:validated - Generate + validate pattern"
31
+ echo " mageagent:compete - Competing models with judge"
32
+ echo " mageagent:primary - Direct 72B model access"
33
+ echo " mageagent:validator - Direct 7B validator access"
34
+ echo " mageagent:competitor - Direct 32B model access"
35
+ }
36
+
37
+ is_running() {
38
+ if [ -f "$PID_FILE" ]; then
39
+ PID=$(cat "$PID_FILE")
40
+ if kill -0 "$PID" 2>/dev/null; then
41
+ return 0
42
+ fi
43
+ fi
44
+ return 1
45
+ }
46
+
47
+ start_server() {
48
+ if is_running; then
49
+ echo "MageAgent already running (PID: $(cat $PID_FILE))"
50
+ echo "API: http://localhost:$PORT"
51
+ return 0
52
+ fi
53
+
54
+ echo "Starting MageAgent server on port $PORT..."
55
+ echo "Log file: $LOG_FILE"
56
+
57
+ cd "$MAGEAGENT_DIR"
58
+
59
+ # Start with nohup to detach from terminal
60
+ nohup python3 -u server.py > "$LOG_FILE" 2> "$ERROR_LOG" &
61
+ echo $! > "$PID_FILE"
62
+
63
+ # Wait a moment for server to start
64
+ sleep 2
65
+
66
+ if is_running; then
67
+ echo "MageAgent started (PID: $(cat $PID_FILE))"
68
+ echo ""
69
+ echo "Waiting for server to be ready..."
70
+
71
+ # Wait up to 30 seconds for server to respond
72
+ for i in {1..30}; do
73
+ if curl -s "http://localhost:$PORT/health" > /dev/null 2>&1; then
74
+ echo "Server ready!"
75
+ echo "API: http://localhost:$PORT"
76
+ echo "Docs: http://localhost:$PORT/docs"
77
+ return 0
78
+ fi
79
+ sleep 1
80
+ echo -n "."
81
+ done
82
+
83
+ echo ""
84
+ echo "Warning: Server started but not responding yet."
85
+ echo "Check logs: tail -f $LOG_FILE"
86
+ else
87
+ echo "Failed to start MageAgent. Check error log:"
88
+ tail -20 "$ERROR_LOG"
89
+ return 1
90
+ fi
91
+ }
92
+
93
+ stop_server() {
94
+ if ! is_running; then
95
+ echo "MageAgent not running"
96
+ rm -f "$PID_FILE"
97
+ return 0
98
+ fi
99
+
100
+ PID=$(cat "$PID_FILE")
101
+ echo "Stopping MageAgent (PID: $PID)..."
102
+
103
+ kill "$PID" 2>/dev/null
104
+
105
+ # Wait for process to stop
106
+ for i in {1..10}; do
107
+ if ! kill -0 "$PID" 2>/dev/null; then
108
+ rm -f "$PID_FILE"
109
+ echo "MageAgent stopped"
110
+ return 0
111
+ fi
112
+ sleep 1
113
+ done
114
+
115
+ # Force kill if still running
116
+ echo "Force killing..."
117
+ kill -9 "$PID" 2>/dev/null
118
+ rm -f "$PID_FILE"
119
+ echo "MageAgent stopped (forced)"
120
+ }
121
+
122
+ show_status() {
123
+ if is_running; then
124
+ PID=$(cat "$PID_FILE")
125
+ echo "MageAgent: RUNNING (PID: $PID)"
126
+ echo "Port: $PORT"
127
+ echo ""
128
+
129
+ # Check health endpoint
130
+ HEALTH=$(curl -s "http://localhost:$PORT/health" 2>/dev/null)
131
+ if [ -n "$HEALTH" ]; then
132
+ echo "Health: $HEALTH"
133
+ else
134
+ echo "Health: Not responding"
135
+ fi
136
+
137
+ echo ""
138
+ echo "Loaded models:"
139
+ curl -s "http://localhost:$PORT/health" 2>/dev/null | python3 -c "import sys,json; d=json.load(sys.stdin); print(' ' + '\n '.join(d.get('loaded_models', [])))" 2>/dev/null || echo " Unable to query"
140
+ else
141
+ echo "MageAgent: STOPPED"
142
+
143
+ # Check if something else is using the port
144
+ if lsof -i:$PORT > /dev/null 2>&1; then
145
+ echo "Warning: Port $PORT is in use by another process"
146
+ lsof -i:$PORT
147
+ fi
148
+ fi
149
+ }
150
+
151
+ show_logs() {
152
+ echo "Showing MageAgent logs (Ctrl+C to exit)..."
153
+ echo "---"
154
+ tail -f "$LOG_FILE"
155
+ }
156
+
157
+ run_test() {
158
+ if ! is_running; then
159
+ echo "MageAgent not running. Start it first with: $0 start"
160
+ return 1
161
+ fi
162
+
163
+ echo "Testing MageAgent server..."
164
+ echo ""
165
+
166
+ echo "1. Testing health endpoint..."
167
+ curl -s "http://localhost:$PORT/health" | python3 -m json.tool
168
+ echo ""
169
+
170
+ echo "2. Testing models list..."
171
+ curl -s "http://localhost:$PORT/v1/models" | python3 -m json.tool
172
+ echo ""
173
+
174
+ echo "3. Testing simple completion (validator model)..."
175
+ echo "Request: Write a hello world in Python"
176
+
177
+ RESPONSE=$(curl -s -X POST "http://localhost:$PORT/v1/chat/completions" \
178
+ -H "Content-Type: application/json" \
179
+ -d '{
180
+ "model": "mageagent:validator",
181
+ "messages": [{"role": "user", "content": "Write a hello world in Python. Just the code, nothing else."}],
182
+ "max_tokens": 100,
183
+ "temperature": 0.3
184
+ }')
185
+
186
+ echo "Response:"
187
+ echo "$RESPONSE" | python3 -c "import sys,json; d=json.load(sys.stdin); print(d['choices'][0]['message']['content'])" 2>/dev/null || echo "$RESPONSE"
188
+ echo ""
189
+
190
+ echo "Test complete!"
191
+ }
192
+
193
+ case "$1" in
194
+ start)
195
+ start_server
196
+ ;;
197
+ stop)
198
+ stop_server
199
+ ;;
200
+ restart)
201
+ stop_server
202
+ sleep 2
203
+ start_server
204
+ ;;
205
+ status)
206
+ show_status
207
+ ;;
208
+ logs)
209
+ show_logs
210
+ ;;
211
+ test)
212
+ run_test
213
+ ;;
214
+ *)
215
+ usage
216
+ exit 1
217
+ ;;
218
+ esac