agic expand_queries -> Text[]:
  recall = none
  tools = none

  Research question:
  {{ _ }}

  Turn this research question into 6 diverse web search queries.
  Return a JSON array containing exactly 6 query strings.

## Search the web for one query and return a compact evidence bundle.
agic search_web:
  recall = none
  tools = web/*

  Query:
  {{ _ }}

  Search the web for this query.
  Return a compact evidence bundle:
  - query
  - 3-5 useful results
  - title, url, date if available
  - one sentence on why it matters

agic extract_findings:
  recall = none
  tools = none

  Evidence bundle:
  {{ _ }}

  Extract durable findings from this evidence bundle.
  Prefer source-backed claims.
  Return concise bullets with URLs preserved.

agic synthesize_report(_, topic: Part[]):
  recall = none
  tools = none

  Research question:
  {{topic}}

  Findings:
  {{ _ }}

  Write a deep research brief from these findings.

  Structure:
  - Executive summary
  - Key findings
  - Conflicting or uncertain points
  - Source notes
  - Next search directions

# // [!region research]
flow research(_: Text):
  let topic =
    {{_}}

  ## Expand the research question into diverse search queries
  scatter 6 using expand_queries
  ## Search the web for each query
  map using search_web in 4 lanes
  ## Keep evidence bundles that answer the research task
  keep if is_relevant
  ## Prioritize the strongest evidence
  sort descending by relevance
  keep first 8
  ## Extract source-backed findings from each evidence bundle
  map using extract_findings in 4 lanes
  ## Synthesize the final research brief
  gather using synthesize_report
# // [!endregion research]

agic is_relevant(_, topic: Part[]) -> Boolean:
  recall = none
  tools = none

  Research question:
  {{topic}}

  Evidence bundle:
  {{ _ }}

  Decide whether this evidence bundle contains concrete, source-backed information that helps answer the research question.
  Return only true or false.

agic relevance(_, topic: Part[]) -> Number:
  recall = none
  tools = none

  Research question:
  {{topic}}

  Evidence bundle:
  {{_}}

  Return a numeric relevance score from 0 to 10. Higher is better.
