-
Notifications
You must be signed in to change notification settings - Fork 91
Expand file tree
/
Copy pathmain.py
More file actions
87 lines (66 loc) · 2.42 KB
/
Copy pathmain.py
File metadata and controls
87 lines (66 loc) · 2.42 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
import logging
import os
import threading
import dotenv
from agents.core_agent import CoreAgent
from interfaces.api import FlaskAgent
from interfaces.telegram import TelegramAgent
from interfaces.twitter_post import TwitterAgent
# Set up logging
logging.basicConfig(level=logging.INFO, format="%(asctime)s - %(name)s - %(levelname)s - %(message)s")
logger = logging.getLogger(__name__)
def run_flask(flask_agent):
"""Runs the (blocking) Flask API agent in a separate thread."""
try:
logger.info("Starting Flask API agent...")
flask_agent.run(host="0.0.0.0", port=5005)
except Exception as e:
logger.error(f"Flask API agent error: {str(e)}")
def run_telegram(telegram_agent):
"""Run the Telegram agent"""
try:
logger.info("Starting Telegram agent...")
telegram_agent.run()
except Exception as e:
logger.error(f"Telegram agent error: {str(e)}")
def run_twitter(twitter_agent):
"""Run the Twitter agent"""
try:
logger.info("Starting Twitter agent...")
twitter_agent.run()
except Exception as e:
logger.error(f"Twitter agent error: {str(e)}")
def reload_environment():
"""Reload environment variables"""
os.environ.clear()
dotenv.load_dotenv(override=True)
logger.info("Environment variables reloaded")
def main():
"""Main entry point"""
try:
# Initial load of environment variables
reload_environment()
# Create shared core agent and interfaces
core_agent = CoreAgent()
flask_agent = FlaskAgent(core_agent)
telegram_agent = TelegramAgent(core_agent)
twitter_agent = TwitterAgent(core_agent)
# farcaster_agent = FarcasterAgent(core_agent) # noqa: F841
# Start Flask in a separate thread
flask_thread = threading.Thread(target=run_flask, args=(flask_agent,), daemon=True)
flask_thread.start()
# Start Twitter in a separate thread
twitter_thread = threading.Thread(target=run_twitter, args=(twitter_agent,), daemon=True)
twitter_thread.start()
# Run Telegram in the main thread
run_telegram(telegram_agent)
# Wait for other threads
flask_thread.join()
twitter_thread.join()
except KeyboardInterrupt:
logger.info("Application stopped by user")
except Exception as e:
logger.error(f"Fatal error: {str(e)}")
raise
if __name__ == "__main__":
main()