-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
166 lines (141 loc) · 5.07 KB
/
main.py
File metadata and controls
166 lines (141 loc) · 5.07 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
import argparse
import asyncio
from datetime import datetime
from typing import List
from mcp_agent.app import MCPApp
from workflows.exploration import load_checkpoint, run_exploration_cycle
from workflows.synthesis import run_synthesis_window
app = MCPApp(name="auto_llm_research_agent")
async def run_overnight(
seed_urls: List[str],
cycles: int,
synthesis_every: int,
) -> None:
"""Run multi-cycle overnight research with periodic synthesis.
Uses a checkpoint file to resume from previous runs and to avoid
re-processing URLs that have already been explored.
"""
checkpoint = load_checkpoint()
start_index = int(checkpoint.get("last_cycle_index", 0)) + 1
print(
"\nStarting overnight research run at "
+ datetime.utcnow().strftime("%Y-%m-%d %H:%M UTC")
)
print(f"Seed URLs ({len(seed_urls)}):")
for url in seed_urls:
print(f" - {url}")
print(
f"Requested cycles this run: {cycles}, synthesis_every: {synthesis_every}"
)
print(
f"Resuming from cycle index {start_index} (total_targets_explored so far: "
f"{checkpoint.get('total_targets_explored', 0)})\n"
)
async with app.run():
for offset in range(cycles):
cycle_idx = start_index + offset
cycle_label = f"cycle_{cycle_idx}"
print(f"==== {cycle_label} ====")
cycle_result = await run_exploration_cycle(
seed_urls,
cycle_label,
cycle_index=cycle_idx,
)
print(
"Exploration done: targets_explored="
+ str(cycle_result["targets_explored"])
+ ", high_interest="
+ str(len(cycle_result["high_interest_findings"]))
+ ", reports_written="
+ str(cycle_result["reports_written"])
+ ", skipped_previously_visited="
+ str(cycle_result["skipped_previously_visited"])
)
if cycle_idx % synthesis_every == 0:
synthesis_label = f"synth_after_{cycle_label}"
print(f"Running synthesis: {synthesis_label}")
synthesis_result = await run_synthesis_window(
label=synthesis_label,
lookback_hours=cycle_idx,
)
print(
"Synthesis preview (first 300 chars):\n"
+ synthesis_result["preview"][:300]
+ "\n"
)
if offset + 1 < cycles:
print("Sleeping 60s before next cycle...\n")
await asyncio.sleep(60)
print(
"\nOvernight research complete at "
+ datetime.utcnow().strftime("%Y-%m-%d %H:%M UTC")
)
async def run_single_explore(seed_urls: List[str]) -> None:
"""Run a single short exploration cycle (for testing/debug)."""
async with app.run():
result = await run_exploration_cycle(
seed_urls,
cycle_label="single_test",
cycle_index=None,
)
print("\nSingle exploration result:")
print(result)
async def run_single_synthesis(label: str, lookback_hours: int) -> None:
"""Run a one-off synthesis pass over recent data."""
async with app.run():
result = await run_synthesis_window(label=label, lookback_hours=lookback_hours)
print("\nSynthesis result metadata:")
print(result)
def main() -> None:
parser = argparse.ArgumentParser(description="Auto-LLM multi-agent research system")
parser.add_argument(
"mode",
choices=["overnight", "explore", "synthesize"],
help="Run full overnight loop, a single exploration, or a single synthesis run.",
)
parser.add_argument(
"--urls",
nargs="+",
default=[
"https://news.ycombinator.com/newest",
"https://github.com/trending",
"https://www.producthunt.com/",
],
help="Seed URLs to explore.",
)
parser.add_argument(
"--cycles",
type=int,
default=4,
help="Number of exploration cycles to run in overnight mode.",
)
parser.add_argument(
"--synthesis-every",
type=int,
default=2,
help="Run synthesis after this many cycles in overnight mode.",
)
parser.add_argument(
"--lookback-hours",
type=int,
default=24,
help="Lookback window in hours for a one-off synthesis run.",
)
args = parser.parse_args()
if args.mode == "overnight":
asyncio.run(
run_overnight(
seed_urls=args.urls,
cycles=args.cycles,
synthesis_every=args.synthesis_every,
)
)
elif args.mode == "explore":
asyncio.run(run_single_explore(seed_urls=args.urls))
elif args.mode == "synthesize":
label = f"one_off_synthesis_{datetime.utcnow().strftime('%Y%m%d_%H%M')}"
asyncio.run(
run_single_synthesis(label=label, lookback_hours=args.lookback_hours)
)
if __name__ == "__main__":
main()