-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
170 lines (144 loc) · 6.46 KB
/
Copy pathmain.py
File metadata and controls
170 lines (144 loc) · 6.46 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
"""
Self_Optimizing_Holo_Half 主入口
Usage:
python main.py [--mode normal|evolution] [--config config.yaml]
"""
import asyncio
import argparse
import sys
from pathlib import Path
# 添加项目根目录到路径
sys.path.insert(0, str(Path(__file__).parent))
async def main():
"""主函数"""
parser = argparse.ArgumentParser(
description="Self_Optimizing_Holo_Half - AI Agent Self-Evolution Platform"
)
parser.add_argument(
"--mode",
choices=["normal", "evolution"],
default="normal",
help="运行模式: normal (生产) 或 evolution (进化)"
)
parser.add_argument(
"--config",
default="config.yaml",
help="配置文件路径"
)
parser.add_argument(
"--test",
action="store_true",
help="运行快速测试"
)
parser.add_argument(
"--auto",
action="store_true",
help="启动自动进化调度器(每天自动执行)"
)
args = parser.parse_args()
if args.test:
# 运行快速测试
print("🧪 Running quick tests...")
from quick_test import run_all_tests
success = run_all_tests()
sys.exit(0 if success else 1)
# 初始化数据库
print("📦 Initializing database...")
from user_scoring.database import init_db
init_db()
# 加载配置
print(f"⚙️ Loading configuration from {args.config}...")
try:
import yaml
with open(args.config, 'r', encoding='utf-8') as f:
config = yaml.safe_load(f)
except FileNotFoundError:
print(f"⚠️ Config file {args.config} not found, using defaults")
config = {}
# 设置模式
mode = args.mode or config.get('mode', 'normal')
print(f"🚀 Starting in '{mode}' mode")
# 初始化引擎
print("🔧 Initializing engine...")
try:
from core.engine import SelfOptimizingEngine
async with SelfOptimizingEngine(workspace=".") as engine:
print("✅ Engine initialized successfully!\n")
if mode == "evolution":
print("="*60)
print("🔄 Self-Evolution Mode")
print("="*60)
# Step 1: 启动时进化一次(优化系统)
print("\n📊 Phase 1: Pre-execution Evolution (Optimizing system...)")
pre_result = await engine.run_self_evolution_cycle()
print(f" Status: {pre_result.get('status', 'unknown')}")
if pre_result.get('suggestions'):
print(f" Suggestions generated: {len(pre_result['suggestions'])}")
if pre_result.get('applied'):
print(f" Optimizations applied: {len(pre_result['applied'])}")
# Step 2: 模拟用户交互/执行任务
print("\n✨ System optimized! Simulating task execution...")
await asyncio.sleep(2) # 模拟执行时间
print("\n📊 Phase 2: Post-execution Evolution (Learning from usage...)")
# Step 3: 结束时再进化一次(根据用户行为学习)
post_result = await engine.run_self_evolution_cycle()
print(f" Status: {post_result.get('status', 'unknown')}")
if post_result.get('suggestions'):
print(f" New suggestions: {len(post_result['suggestions'])}")
if post_result.get('applied'):
print(f" Improvements applied: {len(post_result['applied'])}")
# Step 4: 生成全息进化报告
print("\n📊 Generating Holo-Evolution Report...")
from evaluation.evaluator import CapabilityEvaluator
from evaluation.report_generator import HoloReportGenerator
evaluator = CapabilityEvaluator()
# 这里暂时使用模拟数据,后续接入真实执行历史
mock_history = [
{"result": {"success": True, "duration": 10}},
{"result": {"success": True, "duration": 12}},
]
scores = evaluator.evaluate(execution_history=mock_history)
reporter = HoloReportGenerator()
report_path = reporter.generate_holo_dashboard(scores, history=mock_history)
print(f"✅ Report generated: {report_path}")
print("💡 Open this file in your browser to see the dashboard!")
print("\n✅ Evolution complete! System is now smarter.")
elif args.auto:
print("="*60)
print("⚙️ Starting Auto-Evolution Scheduler")
print("="*60)
print("\n📅 The system will automatically run every day at 02:00")
print("🔄 Each cycle does 3 things:")
print(" 1. 📰 Fetch latest information (GitHub, RSS)")
print(" 2. 🧠 Analyze with LLM")
print(" 3. 📊 Make decisions (A/B test + 6-dim scoring)")
print("\n⏳ Running in background... Press Ctrl+C to stop\n")
from core.auto_scheduler import AutoEvolutionScheduler
scheduler = AutoEvolutionScheduler(engine=engine)
await scheduler.start()
else:
print("="*60)
print("✨ Normal Mode - Ready for Tasks")
print("="*60)
print("\n💡 Example usage:")
print(" result = await engine.execute('Your task here')")
print(" print(result)")
# 保持运行,等待用户交互
print("\n⏳ Press Ctrl+C to exit...\n")
try:
while True:
await asyncio.sleep(1)
except KeyboardInterrupt:
print("\n👋 Goodbye!")
except ImportError as e:
print(f"❌ Failed to import engine: {e}")
print("\n💡 Make sure all dependencies are installed:")
print(" pip install -r requirements.txt")
sys.exit(1)
except Exception as e:
print(f"❌ Error: {e}")
import traceback
traceback.print_exc()
sys.exit(1)
if __name__ == "__main__":
asyncio.run(main())