-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path05-automation-script.sh
More file actions
147 lines (132 loc) · 5.23 KB
/
05-automation-script.sh
File metadata and controls
147 lines (132 loc) · 5.23 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
#!/bin/bash
# MiroFish — Full Simulation Automation Script
# Usage: ./05-automation-script.sh /path/to/seed.md "prediction requirement" [project_name]
#
# Prerequisites:
# - MiroFish running on localhost (docker compose up -d)
# - .env configured with LLM_API_KEY and ZEP_API_KEY
set -e
SEED_FILE="${1:?Usage: $0 <seed_file.md> <prediction_requirement> [project_name]}"
REQUIREMENT="${2:?Usage: $0 <seed_file.md> <prediction_requirement> [project_name]}"
PROJECT_NAME="${3:-Auto-$(date +%Y%m%d-%H%M)}"
API="http://localhost:5001/api"
echo "=========================================="
echo " MiroFish Simulation Runner"
echo " Seed: $SEED_FILE"
echo " Project: $PROJECT_NAME"
echo "=========================================="
# ─── STEP 1: Generate Ontology ───
echo ""
echo "[1/6] Generating ontology..."
ONTO=$(curl -s -X POST $API/graph/ontology/generate \
-F "files=@$SEED_FILE" \
-F "simulation_requirement=$REQUIREMENT" \
-F "project_name=$PROJECT_NAME")
PID=$(echo $ONTO | python3 -c 'import sys,json; print(json.load(sys.stdin)["data"]["project_id"])')
ENTS=$(echo $ONTO | python3 -c 'import sys,json; print(len(json.load(sys.stdin)["data"]["ontology"]["entity_types"]))')
echo " Project: $PID ($ENTS entity types)"
# ─── STEP 2: Build Knowledge Graph ───
echo ""
echo "[2/6] Building knowledge graph (Zep Cloud)..."
BUILD=$(curl -s -X POST $API/graph/build \
-H 'Content-Type: application/json' \
-d "{\"project_id\": \"$PID\"}")
TASK=$(echo $BUILD | python3 -c 'import sys,json; print(json.load(sys.stdin)["data"]["task_id"])')
while true; do
sleep 10
STATUS=$(curl -s $API/graph/task/$TASK | python3 -c '
import sys,json
d = json.load(sys.stdin)["data"]
print(d["status"], d["progress"], d["message"][:80])
')
echo " $STATUS"
echo $STATUS | grep -q "^completed" && break
echo $STATUS | grep -q "^failed" && echo "FAILED!" && exit 1
done
# ─── STEP 3: Create Simulation ───
echo ""
echo "[3/6] Creating simulation..."
SIM=$(curl -s -X POST $API/simulation/create \
-H 'Content-Type: application/json' \
-d "{\"project_id\": \"$PID\", \"enable_twitter\": true, \"enable_reddit\": true}")
SID=$(echo $SIM | python3 -c 'import sys,json; print(json.load(sys.stdin)["data"]["simulation_id"])')
echo " Simulation: $SID"
# ─── STEP 4: Prepare (Agent Profiles + Config) ───
echo ""
echo "[4/6] Preparing simulation (generating agent profiles)..."
PREP=$(curl -s -X POST $API/simulation/prepare \
-H 'Content-Type: application/json' \
-d "{\"simulation_id\": \"$SID\", \"use_llm_for_profiles\": true}")
ENTITY_COUNT=$(echo $PREP | python3 -c 'import sys,json; print(json.load(sys.stdin)["data"].get("expected_entities_count",0))')
echo " Generating profiles for $ENTITY_COUNT entities..."
while true; do
sleep 20
STATUS=$(curl -s -X POST $API/simulation/prepare/status \
-H 'Content-Type: application/json' \
-d "{\"simulation_id\": \"$SID\"}" | python3 -c '
import sys,json
d = json.load(sys.stdin)["data"]
t = d.get("task", {})
s = t.get("status", d.get("status", "?"))
p = t.get("progress", d.get("progress", 0))
m = t.get("message", d.get("message", ""))[:80]
print(f"{s} {p} {m}")
')
echo " $STATUS"
echo $STATUS | grep -qE "^completed|^ready" && break
echo $STATUS | grep -q "^failed" && echo "FAILED!" && exit 1
done
# ─── STEP 5: Start Simulation ───
echo ""
echo "[5/6] Starting OASIS simulation..."
START=$(curl -s -X POST $API/simulation/start \
-H 'Content-Type: application/json' \
-d "{\"simulation_id\": \"$SID\", \"platform\": \"parallel\", \"enable_graph_memory_update\": true}")
ROUNDS=$(echo $START | python3 -c 'import sys,json; print(json.load(sys.stdin)["data"]["total_rounds"])')
echo " Running $ROUNDS rounds..."
while true; do
sleep 30
STATUS=$(curl -s $API/simulation/$SID/run-status | python3 -c '
import sys,json
d = json.load(sys.stdin)["data"]
s = d["runner_status"]
r = d["current_round"]
t = d["total_rounds"]
a = d["total_actions_count"]
p = d["progress_percent"]
print(f"{s} round={r}/{t} actions={a} progress={p:.1f}%")
')
echo " $STATUS"
echo $STATUS | grep -q "^completed" && break
echo $STATUS | grep -q "^failed" && echo "FAILED!" && exit 1
echo $STATUS | grep -q "^stopped" && break
done
# ─── STEP 6: Generate Report ───
echo ""
echo "[6/6] Generating prediction report..."
REPORT=$(curl -s -X POST $API/report/generate \
-H 'Content-Type: application/json' \
-d "{\"simulation_id\": \"$SID\"}")
RTASK=$(echo $REPORT | python3 -c 'import sys,json; d=json.load(sys.stdin)["data"]; print(d.get("task_id","none"))')
if [ "$RTASK" != "none" ]; then
while true; do
sleep 15
STATUS=$(curl -s -X POST $API/report/generate/status \
-H 'Content-Type: application/json' \
-d "{\"task_id\": \"$RTASK\"}" | python3 -c '
import sys,json
d = json.load(sys.stdin)["data"]
print(d.get("status","?"), d.get("progress",0))
')
echo " $STATUS"
echo $STATUS | grep -q "^completed" && break
echo $STATUS | grep -q "^failed" && echo "Report generation failed" && break
done
fi
echo ""
echo "=========================================="
echo " SIMULATION COMPLETE"
echo " Project: $PID"
echo " Simulation: $SID"
echo " UI: http://localhost:3000/simulation/$SID/start"
echo "=========================================="