Repository navigation
Expand file tree
/
Copy pathmain.py
More file actions
73 lines (60 loc) · 2.09 KB
/
Copy pathmain.py
File metadata and controls
73 lines (60 loc) · 2.09 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
"""
main.py - Main execution script for AI News Agent
"""
import asyncio
import json
import os
from pathlib import Path
from core.agent import AINewsAgent, AgentConfig
from core.agent import BrandTheme
def load_agent_config(config_path: str = "agent_config.json") -> AgentConfig:
"""Load agent configuration from JSON file"""
default_config = {
"name": "AI News Agent",
"personality": "professional",
"news_sources": ["gnews"],
"post_frequency": 3,
"max_news_age": 24,
"engagement_threshold": 0.5,
"memory_path": "agent_memory.json",
"output_dir": "./output",
"credentials": {
"GEMINI_API_KEY": os.getenv("GEMINI_API_KEY"),
"REPLICATE_API_TOKEN": os.getenv("REPLICATE_API_TOKEN"),
"OPENAI_API_KEY": os.getenv("OPENAI_API_KEY"),
"IG_USERNAME": os.getenv("IG_USERNAME"),
"IG_PASSWORD": os.getenv("IG_PASSWORD")
}
}
try:
if Path(config_path).exists():
with open(config_path, 'r') as f:
config_data = json.load(f)
default_config.update(config_data)
except Exception as e:
print(f"Error loading config file: {e}")
print("Using default configuration...")
default_config["memory_path"] = Path(default_config["memory_path"])
default_config["output_dir"] = Path(default_config["output_dir"])
return AgentConfig(**default_config)
async def main():
config = load_agent_config()
config.output_dir.mkdir(parents=True, exist_ok=True)
theme = BrandTheme(
primary_color="#2A5CAA",
secondary_color="#1A1A1A",
accent_color="#00FF88",
background_color="#0F0F0F",
text_color="#FFFFFF",
font_style="Roboto",
visual_style="cyberpunk",
)
agent = AINewsAgent(config, theme)
try:
await agent.run()
except KeyboardInterrupt:
print("\nShutting down agent gracefully...")
agent.memory.save(config.memory_path)
print("Agent state saved. Goodbye!")
if __name__ == "__main__":
asyncio.run(main())