File size: 8,150 Bytes
4abc17c
 
3b3daa9
4abc17c
 
3b3daa9
 
 
 
4abc17c
 
3b3daa9
4abc17c
 
 
 
 
3b3daa9
 
 
4abc17c
 
 
 
 
3b3daa9
 
 
4abc17c
 
 
 
 
3b3daa9
 
 
4abc17c
 
 
 
 
3b3daa9
 
 
4abc17c
 
 
 
 
3b3daa9
 
 
4abc17c
 
 
 
 
3b3daa9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4abc17c
 
 
3b3daa9
4abc17c
3b3daa9
 
 
 
 
4abc17c
 
3b3daa9
4abc17c
3b3daa9
 
4abc17c
 
 
3b3daa9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
LifeFlow AI - Configuration
整合 Agno Agent 系統配置
"""

import os
from pathlib import Path

# ===== 應用配置 =====
APP_TITLE = "LifeFlow AI - Intelligent Daily Trip Planner"

# ===== Agent 資訊配置 (前端顯示用) =====
AGENTS_INFO = {
    'planner': {
        'name': 'Planner',
        'role': 'Task Analyzer',
        'icon': '📋',
        'avatar': '📋',
        'color': '#f093fb',
        'glow': 'rgba(240, 147, 251, 0.3)'
    },
    'scout': {
        'name': 'Scout',
        'role': 'POI Searcher',
        'icon': '🗺️',
        'avatar': '🗺️',
        'color': '#4facfe',
        'glow': 'rgba(79, 172, 254, 0.3)'
    },
    'optimizer': {
        'name': 'Optimizer',
        'role': 'Route Optimizer',
        'icon': '⚡',
        'avatar': '⚡',
        'color': '#43e97b',
        'glow': 'rgba(67, 233, 123, 0.3)'
    },
    'validator': {
        'name': 'Validator',
        'role': 'Feasibility Checker',
        'icon': '✅',
        'avatar': '✅',
        'color': '#fa709a',
        'glow': 'rgba(250, 112, 154, 0.3)'
    },
    'weather': {
        'name': 'Weather',
        'role': 'Weather Advisor',
        'icon': '🌤️',
        'avatar': '🌤️',
        'color': '#feca57',
        'glow': 'rgba(254, 202, 87, 0.3)'
    },
    'traffic': {
        'name': 'Traffic',
        'role': 'Traffic Analyzer',
        'icon': '🚗',
        'avatar': '🚗',
        'color': '#ff6348',
        'glow': 'rgba(255, 99, 72, 0.3)'
    },
    'navigator': {
        'name': 'Navigator',
        'role': 'Route Navigator',
        'icon': '🧭',
        'avatar': '🧭',
        'color': '#5f27cd',
        'glow': 'rgba(95, 39, 205, 0.3)'
    },
    'weatherman': {
        'name': 'Weatherman',
        'role': 'Weather Forecaster',
        'icon': '⛅',
        'avatar': '⛅',
        'color': '#00d2d3',
        'glow': 'rgba(0, 210, 211, 0.3)'
    },
    'presenter': {
        'name': 'Presenter',
        'role': 'Report Generator',
        'icon': '📊',
        'avatar': '📊',
        'color': '#ee5a6f',
        'glow': 'rgba(238, 90, 111, 0.3)'
    },
    'team': {
        'name': 'Team Leader',
        'role': 'Orchestrator',
        'icon': '👨‍✈️',
        'avatar': '👨‍✈️',
        'color': '#0abde3',
        'glow': 'rgba(10, 189, 227, 0.3)'
    }
}

# ===== API Keys (從環境變數讀取) =====
DEFAULT_SETTINGS = {
    'google_maps_api_key': os.getenv('GOOGLE_MAPS_API_KEY', ''),
    'openweather_api_key': os.getenv('OPENWEATHER_API_KEY', ''),
    'anthropic_api_key': os.getenv('ANTHROPIC_API_KEY', ''),
    'gemini_api_key': os.getenv('GEMINI_API_KEY', ''),
    'model': 'gemini-2.5-flash'
}

# ===== LLM 模型選擇 =====
MODEL_CHOICES = [
    'gemini-2.5-flash',
    'gemini-2.5-flash-lite',
    'claude-sonnet-4-20250514',
    'claude-sonnet-3-5-20241022',
    'gpt-4-turbo',
    'gpt-4o'
]

# ===== Agno Agent 配置 =====
AGENT_CONFIG = {
    # Planner Agent 配置
    'planner': {
        'model': 'gemini-2.5-flash',
        'thinking_budget': 2048,
        'temperature': 0.7,
        'debug_mode': False
    },

    # Core Team 配置
    'team': {
        'model': 'gemini-2.5-flash',
        'thinking_budget': 1024,
        'temperature': 0.7,
        'debug_mode': False,
        'debug_level': 1
    },

    # Member Agents 配置
    'scout': {
        'model': 'gemini-2.5-flash',
        'temperature': 0.5
    },

    'optimizer': {
        'model': 'gemini-2.5-flash-lite',
        'temperature': 0.3
    },

    'navigator': {
        'model': 'gemini-2.5-flash-lite',
        'temperature': 0.3
    },

    'weatherman': {
        'model': 'gemini-2.5-flash-lite',
        'temperature': 0.5
    },

    'presenter': {
        'model': 'gemini-2.5-flash',
        'temperature': 0.7
    }
}

# ===== 資料庫配置 =====
DATABASE_CONFIG = {
    'planner_db': 'tmp/planner.db',
    'team_db': 'tmp/team.db',
    'poi_db': 'storage/lifeflow_payloads.db',
    'offload_db': 'storage/offloaded_data.db'
}

# ===== 路徑配置 =====
BASE_DIR = Path(__file__).parent
STORAGE_DIR = BASE_DIR / 'storage'
TMP_DIR = BASE_DIR / 'tmp'
LOGS_DIR = BASE_DIR / 'logs'

# 確保目錄存在
for dir_path in [STORAGE_DIR, TMP_DIR, LOGS_DIR]:
    dir_path.mkdir(parents=True, exist_ok=True)

# ===== 日誌配置 =====
LOGGING_CONFIG = {
    'version': 1,
    'disable_existing_loggers': False,
    'formatters': {
        'default': {
            'format': '%(asctime)s - %(name)s - %(levelname)s - %(message)s'
        },
        'detailed': {
            'format': '%(asctime)s - %(name)s - %(levelname)s - [%(filename)s:%(lineno)d] - %(message)s'
        }
    },
    'handlers': {
        'console': {
            'class': 'logging.StreamHandler',
            'level': 'INFO',
            'formatter': 'default',
            'stream': 'ext://sys.stdout'
        },
        'file': {
            'class': 'logging.handlers.RotatingFileHandler',
            'level': 'DEBUG',
            'formatter': 'detailed',
            'filename': str(LOGS_DIR / 'lifeflow.log'),
            'maxBytes': 10485760,  # 10MB
            'backupCount': 5
        }
    },
    'root': {
        'level': 'INFO',
        'handlers': ['console', 'file']
    }
}

# ===== Gradio UI 配置 =====
GRADIO_CONFIG = {
    'server_name': '0.0.0.0',
    'server_port': 7860,
    'share': False,
    'show_error': True,
    'quiet': False
}

# ===== 預設位置 (台北101) =====
DEFAULT_LOCATION = {
    'lat': 25.033,
    'lng': 121.565,
    'name': 'Taipei 101'
}

# ===== Tool 配置 =====
TOOL_CONFIG = {
    'scout': {
        'search_radius': 5000,  # 米
        'max_results': 10,
        'min_rating': 3.5
    },
    'optimizer': {
        'algorithm': 'ortools_tsptw',
        'max_iterations': 1000,
        'time_limit_seconds': 30
    },
    'navigator': {
        'travel_mode': 'driving',
        'avoid_highways': False,
        'avoid_tolls': False
    },
    'weather': {
        'forecast_hours': 24,
        'update_interval_minutes': 60
    }
}

# ===== 功能開關 =====
FEATURE_FLAGS = {
    'enable_weather': True,
    'enable_traffic': True,
    'enable_chat': True,
    'enable_map_visualization': True,
    'enable_reasoning_display': True,
    'enable_celebration_animation': True,
    'enable_stream_output': True
}

# ===== 性能配置 =====
PERFORMANCE_CONFIG = {
    'max_concurrent_requests': 10,
    'request_timeout_seconds': 120,
    'cache_ttl_seconds': 3600,
    'enable_caching': True
}

# ===== 安全配置 =====
SECURITY_CONFIG = {
    'max_input_length': 1000,
    'max_tasks_per_request': 20,
    'rate_limit_per_minute': 60,
    'enable_input_validation': True
}


# ===== 導出配置函數 =====
def get_agent_config(agent_name: str) -> dict:
    """獲取指定 Agent 的配置"""
    return AGENT_CONFIG.get(agent_name, {})


def get_tool_config(tool_name: str) -> dict:
    """獲取指定 Tool 的配置"""
    return TOOL_CONFIG.get(tool_name, {})


def is_feature_enabled(feature_name: str) -> bool:
    """檢查功能是否啟用"""
    return FEATURE_FLAGS.get(feature_name, False)


def get_database_path(db_name: str) -> str:
    """獲取資料庫路徑"""
    return DATABASE_CONFIG.get(db_name, '')


# ===== 環境檢查 =====
def check_environment():
    """檢查環境配置是否完整"""
    missing_keys = []

    required_keys = ['GEMINI_API_KEY', 'GOOGLE_MAPS_API_KEY']

    for key in required_keys:
        if not os.getenv(key):
            missing_keys.append(key)

    if missing_keys:
        print(f"⚠️  Warning: Missing environment variables: {', '.join(missing_keys)}")
        print("Please set them in your .env file or environment")
        return False

    return True


# ===== 初始化配置 =====
def initialize_config():
    """初始化配置"""
    # 檢查環境
    check_environment()

    # 創建必要的目錄
    for dir_path in [STORAGE_DIR, TMP_DIR, LOGS_DIR]:
        dir_path.mkdir(parents=True, exist_ok=True)

    print("✅ Configuration initialized successfully")


# 自動初始化
if __name__ != "__main__":
    initialize_config()