-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_agent.py
More file actions
64 lines (51 loc) · 2.09 KB
/
Copy pathrun_agent.py
File metadata and controls
64 lines (51 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
import os
import json
from dotenv import load_dotenv
from streamintel_agent import StreamIntelAgent
from pdf_utils import markdown_to_pdf
from email_utils import send_report_email
def main():
# Load environment variables (useful for local testing)
load_dotenv()
API_KEY = os.environ.get("GEMINI_API_KEY")
TAVILY_API_KEY = os.environ.get("TAVILY_API_KEY")
if not API_KEY:
print("[CRITICAL ERROR] GEMINI_API_KEY is missing. Aborting.")
return
print("[RUN_AGENT] Initializing Headless Automation Script...")
# Load configs
config_path = "config.json"
keywords = []
emails = []
if os.path.exists(config_path):
with open(config_path, "r") as f:
try:
cfg = json.load(f)
keywords = cfg.get("keywords", [])
emails = cfg.get("emails", [])
except Exception as e:
print(f"[WARNING] Failed to parse config.json: {e}")
else:
print("[WARNING] config.json not found, using default fallback vectors.")
print(f"[RUN_AGENT] Loaded {len(keywords)} Target Vectors and {len(emails)} Target Emails.")
# Run the agent
agent = StreamIntelAgent(api_key=API_KEY, tavily_api_key=TAVILY_API_KEY)
try:
report_md = agent.generate_report(keywords, engine="tavily")
print("[RUN_AGENT] Intelligence report successfully generated.")
# Generate PDF
pdf_path = markdown_to_pdf(report_md, is_manual=False)
print(f"[RUN_AGENT] PDF generated successfully at: {pdf_path}")
# Send Email
if emails:
success, msg = send_report_email(emails, pdf_path)
if success:
print(f"[RUN_AGENT] Success! Email dispatch complete: {msg}")
else:
print(f"[ERROR] Email dispatch failed: {msg}")
else:
print("[RUN_AGENT] No target emails configured. Skipping email dispatch.")
except Exception as e:
print(f"[CRITICAL ERROR] Pipeline failed: {e}")
if __name__ == "__main__":
main()