Skip to content

Instantly share code, notes, and snippets.

@roninjin10
Created January 7, 2026 00:00
Show Gist options
  • Select an option

  • Save roninjin10/a666a89875edc5f3dcff55ef2f5b1e82 to your computer and use it in GitHub Desktop.

Select an option

Save roninjin10/a666a89875edc5f3dcff55ef2f5b1e82 to your computer and use it in GitHub Desktop.
def ResearchAgent(props):
phase, set_phase = use_state("research")
sources, set_sources = use_state([])
analyses, set_analyses = use_state({})
if phase == "research":
def on_done(r):
set_sources(r["sources"])
set_phase("analyze")
return h(Claude, {"tools": ["web"], "on_finished": on_done},
h(Phase, {"name": "research"},
h(Step, None, f"Search for recent articles about {props['topic']}"),
h(Step, None, "Find at least 5 credible sources"),
)
)
if phase == "analyze":
pending = [s for s in sources if s["id"] not in analyses]
def add_analysis(source, result):
next_analyses = {**analyses, source["id"]: result}
set_analyses(next_analyses)
if len(next_analyses) == len(sources):
set_phase("write")
return h(Fragment, None, *[
h(Subagent, {"key": s["id"], "name": f"analyzer-{s['id']}"},
h(Claude, {"on_finished": lambda r, s=s: add_analysis(s, r)},
f"Analyze: {s['url']}")
)
for s in pending
])
return h(Claude, None, f"Write report from: {list(analyses.values())}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment