name: affiliate_intelligence
description: "Orion researches a specific Amazon affiliate / review site opportunity. Produces a content calendar and monthly revenue model. Spawned by opportunity_scan when an affiliate opportunity is identified."
debug: true
model: power
system: agent_prompt

agent_prompt:
  - "= identity.md"

sections:
  - agent
  - project
  - rag
  - message
  - instructions

steps:
  - type: think
    max_tokens: 200
    output_key: aff_search_1
    hint: |
      You are researching an Amazon affiliate opportunity in the niche described
      in the task message above.

      Formulate ONE search query to find:
      - Amazon Associates commission rates for this product category
      - Top-selling products in this category (by review count or bestseller rank)
      - Average selling price range

      Include "Amazon Associates commission rate" and the niche name in your query.
      Output ONLY the search query. Nothing else.

  - type: tool
    capability: Tool_WebSearcher
    input_from: aff_search_1
    mode: research
    max_results: 8
    fetch_pages: 3
    optional: true
    output_key: aff_data_1

  - type: think
    max_tokens: 200
    output_key: aff_search_2
    hint: |
      Pass 2 -- Existing review sites.
      Formulate ONE query to find who is already winning with review content
      in this niche. Look for:
      - Top-ranked review sites for this category
      - How much content they have, what their top pages cover
      - Signs of affiliate revenue (disclosure notices, "best of" pages)

      Output ONLY the search query. Nothing else.

  - type: tool
    capability: Tool_WebSearcher
    input_from: aff_search_2
    mode: research
    max_results: 8
    fetch_pages: 3
    optional: true
    output_key: aff_data_2

  - type: think
    max_tokens: 200
    output_key: aff_search_3
    hint: |
      Pass 3 -- Keyword and content opportunity.
      Formulate ONE query to find long-tail buying-intent keywords this niche:
      - "best [product type] under $X"
      - "[product type] vs [product type] comparison"
      - "[product type] for [specific use case] review [year]"

      Look for gaps: questions that get asked but have no great answer online.
      Output ONLY the search query. Nothing else.

  - type: tool
    capability: Tool_WebSearcher
    input_from: aff_search_3
    mode: research
    max_results: 6
    fetch_pages: 2
    optional: true
    output_key: aff_data_3

  - type: think
    max_tokens: 200
    output_key: aff_search_4
    hint: |
      Pass 4 -- Community pain points and buying signals.
      Formulate ONE query to find what buyers in this niche say on Reddit or forums:
      - What they cannot find good reviews for
      - What makes them distrust existing review sites
      - What would make a review site their go-to resource

      Append "site:reddit.com" to force community results.
      Output ONLY the search query. Nothing else.

  - type: tool
    capability: Tool_WebSearcher
    input_from: aff_search_4
    mode: research
    max_results: 6
    fetch_pages: 2
    optional: true
    output_key: aff_data_4

  - type: think
    max_tokens: 10000
    output_key: affiliate_brief_body
    hint: |
      You are Orion, Director of Research at Crimson Leaf Holdings.
      Produce a structured affiliate opportunity brief for the niche in the task message.

      === PASS 1: AMAZON COMMISSION AND PRODUCT DATA ===
      {aff_data_1}
      === END PASS 1 ===

      === PASS 2: EXISTING REVIEW SITES ===
      {aff_data_2}
      === END PASS 2 ===

      === PASS 3: KEYWORD AND CONTENT GAPS ===
      {aff_data_3}
      === END PASS 3 ===

      === PASS 4: COMMUNITY BUYING SIGNALS ===
      {aff_data_4}
      === END PASS 4 ===

      Cite every data point with [Title](URL). Label unverified estimates clearly.

      # Affiliate Intelligence Brief: [Niche Name]

      ---

      ## 1. Amazon Associates Overview
      - Product category: [exact Amazon category name]
      - Commission tier: [%] -- [cite Amazon Associates rate card if found]
      - Average product price range: $[X] to $[Y]
      - Top 5 products to review (by bestseller rank or review count):
        1. [Product name] -- ~$[price] -- [why this is a strong review target]
        2. [Product name] -- ~$[price] -- [why]
        3. [Product name] -- ~$[price] -- [why]
        4. [Product name] -- ~$[price] -- [why]
        5. [Product name] -- ~$[price] -- [why]

      ## 2. Competitive Landscape
      [Top 3-5 existing review sites in this niche.
       For each: name, URL, estimated content volume, what they do well, what they miss.
       Cite each site URL directly.]

      White space: [What the existing sites are NOT covering well.
       This is where Crimson Leaf enters.]

      ## 3. Content Opportunity Map
      Top 10 article templates for this niche (these are the articles to write first):
      1. "Best [product type] in [year] -- [N] Options Reviewed" -- [buying intent signal]
      2. "[Product A] vs [Product B] -- Which Is Worth It?" -- [head-to-head comparison]
      3. "Best [product type] Under $[price]" -- [budget segment]
      4. "Best [product type] for [specific use case]" -- [niche down]
      5. "[Product type] Buyer's Guide [year] -- What to Look For" -- [informational + conversion]
      6-10. [Additional article templates based on keyword gaps found in Pass 3]

      ## 4. Monthly Revenue Model
      Assumptions (state all -- these are estimates unless a source is cited):
      - Articles published per month: [N]
      - Months to meaningful traffic (SEO ramp): [N months]
      - Average monthly traffic per article at steady state: [X visits]
        Source: [cite if found, otherwise "(industry average estimate)"]
      - Affiliate conversion rate: [Y%]
        Source: [cite if found, otherwise "(Amazon Associates average: 1-3%)"]
      - Average order value: $[Z]
      - Commission rate: [P%]

      Revenue per article per month: X visits x Y% conversion x $Z AOV x P% commission = $[result]
      Monthly revenue at [N] articles: $[result per article] x N articles = $[total]

      Timeline:
      - Month 1-3: $0 (building content, no traffic yet)
      - Month 4-6: $[estimate] (first traffic, first conversions)
      - Month 7-12: $[estimate] (ramp toward steady state)
      - Month 13+: $[steady state] target (if [N] articles published)

      Break-even: [N articles needed at $[revenue per article] to cover $[monthly cost]]

      ## 5. Crimson Leaf Fit Assessment
      - What CL agents can do today: [write reviews, research products, publish to Gitea]
      - What needs to be built: [domain setup, WordPress or static site, affiliate tracking links]
      - David's required involvement: [minimal -- approve domain purchase, set up affiliate account]
      - Speed advantage: [CL can publish N articles per week vs a solo human writer's 1-2]

      ## 6. Recommendation
      **START NOW** / **RESEARCH FURTHER** / **PASS**

      Rationale: [2-3 sentences grounded in the data above.
       If START NOW: what makes this niche worth entering in the next 30 days?
       If RESEARCH FURTHER: what specific question must be answered?
       If PASS: what structural barrier makes the economics unviable?]

      ---

      ## Sources
      [All URLs cited above, numbered.
       Format: N. [Title](URL) -- domain.com]

      BUSINESS_PLAN_FLAG: [write "BUSINESS_PLAN_NEEDED: true" if recommendation is START NOW,
      otherwise "BUSINESS_PLAN_NEEDED: false"]

  - type: document
    source_step: affiliate_brief_body
    dest_path: "deliverables/affiliate-intelligence/affiliate-brief-{task.id}.md"
    commit_msg: "research: affiliate brief task={task.id}"

  - type: close
    rag_update: true

  - type: tool
    action: enqueue_strategy
    optional: true
    condition: "BUSINESS_PLAN_NEEDED: true"
    params:
      company_slug: "crimson_leaf"
      project_slug: "incubation"
      task_type: "business_plan"
      content: "Develop a full business plan for the affiliate/review site opportunity from affiliate intelligence brief {task.id}. The full brief is in the deliverables folder. Build on it -- do not repeat the affiliate research."
      agent_name: "orion"

  - type: reply
    target: channel
    channel_name: "crimson_leaf:live-feed"
    hint: |
      Write a 2-3 line summary of the affiliate intelligence brief just completed.
      Include: niche, recommendation (START NOW/RESEARCH FURTHER/PASS),
      the monthly revenue target at steady state,
      and the top article template to write first.
      Example: "Affiliate brief complete: [niche] -- START NOW.
      Steady-state target: $[X]/month at [N] articles.
      First article: [title template]."

adjudication:
  enabled: true
  pass_threshold: 70
  deliverable_type: analysis
  criteria:
    revenue_model:
      weight: 40
      description: "Monthly revenue model is present with stated assumptions. Break-even calculation shown. Numbers are labeled as estimates or cited."
    content_specificity:
      weight: 35
      description: "Top 10 article templates are specific and actionable -- not generic placeholders. Products are named."
    competitive_analysis:
      weight: 25
      description: "At least 3 existing review sites identified with actual URLs and gap analysis."
