name: research_brief
description: "Deep-research a business topic and produce an annotated brief with citations. Use before writing proposals, strategies, or market plans."
debug: true
model: power
sections:
  - agent
  - project
  - rag
  - message
  - instructions

steps:
  - type: think
    max_tokens: 600
    output_key: query_plan
    hint: |
      You are a professional business researcher. Your task is to produce a
      fully cited research brief on the following topic:

      TOPIC: {message}

      Plan your research. Generate exactly 4 search queries that together will
      cover the topic from multiple angles:
        Query 1: Market size, growth rate, and TAM
        Query 2: Key players, competitors, and pricing
        Query 3: Customer pain points, demand drivers, and trends
        Query 4: Case studies, success stories, or failure patterns

      Output ONLY a numbered list of 4 queries. No commentary.

  - type: think
    max_tokens: 100
    output_key: q1
    hint: |
      Extract only query 1 from the list above. Output ONLY the query text.

  - type: tool
    capability: Tool_WebSearcher
    input_from: last_text
    mode: research
    max_results: 6
    fetch_pages: 3
    optional: true
    output_key: research_market

  - type: think
    max_tokens: 100
    output_key: q2
    hint: |
      From the original query plan:
      {query_plan}

      Extract only query 2. Output ONLY the query text.

  - type: tool
    capability: Tool_WebSearcher
    input_from: last_text
    mode: research
    max_results: 5
    fetch_pages: 2
    optional: true
    output_key: research_competitors

  - type: think
    max_tokens: 100
    output_key: q3
    hint: |
      From the original query plan:
      {query_plan}

      Extract only query 3. Output ONLY the query text.

  - type: tool
    capability: Tool_WebSearcher
    input_from: last_text
    mode: research
    max_results: 5
    fetch_pages: 2
    optional: true
    output_key: research_trends

  - type: think
    max_tokens: 100
    output_key: q4
    hint: |
      From the original query plan:
      {query_plan}

      Extract only query 4. Output ONLY the query text.

  - type: tool
    capability: Tool_WebSearcher
    input_from: last_text
    mode: research
    max_results: 4
    fetch_pages: 2
    optional: true
    output_key: research_cases

  - type: think
    max_tokens: 6000
    output_key: research_document
    hint: |
      You are a professional business researcher. Write a comprehensive research brief.
      Use ALL of the research gathered below as your primary source material.
      Cite every factual claim using [Title](URL) inline markdown links.
      Do NOT invent statistics. If the research is thin on a topic, say so honestly.

      TOPIC: {message}

      === MARKET SIZE AND GROWTH RESEARCH ===
      {research_market}

      === COMPETITOR AND PRICING RESEARCH ===
      {research_competitors}

      === TRENDS AND DEMAND RESEARCH ===
      {research_trends}

      === CASE STUDIES AND PATTERNS ===
      {research_cases}

      Write the research brief with this structure:

      # Research Brief: [Topic Title]
      Date: [today]
      Prepared for: Crimson Leaf Holdings

      ## Executive Summary
      2-3 paragraph overview of the most important findings.
      What does this market look like? Is it a good opportunity?

      ## Market Size and Growth
      Specific numbers, growth rates, projections. Cite every figure.

      ## Competitive Landscape
      Who are the players? What do they charge? What is their moat?
      Where are the gaps? Cite sources.

      ## Demand Drivers and Customer Pain Points
      What is driving demand? What problems are unsolved?
      Who is the customer and what do they want? Cite sources.

      ## Case Studies and Evidence
      Real examples of success or failure in this space.
      What can Crimson Leaf learn from these? Cite sources.

      ## Strategic Assessment for Crimson Leaf
      Given everything above, is this a viable opportunity for CL?
      What is the entry strategy? What risks must be managed?
      What should happen next?

      ## Source Index
      List all sources cited in this document:
      - [Title](URL)

  - type: document
    source_step: 9
    dest_path: "deliverables/research/research-{task.id}.md"
    commit_msg: "research: brief for task={task.id}"

  - type: reply
    target: channel
    channel_name: "crimson_leaf:live-feed"
    hint: |
      Briefly announce that a research brief has been completed and saved.
      Include: topic, number of sources cited, path in Gitea.
      Keep to 2-3 lines.

adjudication:
  enabled: true
  pass_threshold: 80
  deliverable_type: research
  criteria:
    citation_quality:
      weight: 40
      description: "Every factual claim is backed by a real citation in [Title](URL) format -- no invented statistics"
    coverage_depth:
      weight: 30
      description: "All four research angles covered (market, competitors, trends, cases) with substantive findings"
    strategic_relevance:
      weight: 20
      description: "Strategic assessment is specific to Crimson Leaf and actionable"
    honest_gaps:
      weight: 10
      description: "Research gaps are acknowledged honestly rather than papered over with vague language"
