app:
  name: "全网竞品与行业研报分析 Agent"
  description: "基于 Dify 搭建的智能市场调研 Agent，实时检索网页、抓取财务与产品数据并自动输出 SWOT 分析报告"
  mode: "workflow"
  icon: "🔍"
  icon_background: "#059669"

workflow:
  graph:
    edges:
      - source: "start"
        target: "input_parser"
        sourceHandle: "source"
        targetHandle: "target"
      - source: "input_parser"
        target: "tavily_search"
        sourceHandle: "source"
        targetHandle: "target"
      - source: "tavily_search"
        target: "web_scraper"
        sourceHandle: "source"
        targetHandle: "target"
      - source: "web_scraper"
        target: "content_cleaner"
        sourceHandle: "source"
        targetHandle: "target"
      - source: "content_cleaner"
        target: "swot_analyzer"
        sourceHandle: "source"
        targetHandle: "target"
      - source: "swot_analyzer"
        target: "pdf_exporter"
        sourceHandle: "source"
        targetHandle: "target"
      - source: "pdf_exporter"
        target: "end"
        sourceHandle: "source"
        targetHandle: "target"

    nodes:
      - id: "start"
        type: "start"
        title: "开始"
        position:
          x: 80
          y: 150
        data:
          type: "start"
          variables:
            - variable: "research_topic"
              label: "调研主题"
              type: "text-input"
              required: true
              max_length: 200
              placeholder: "例如：2024年中国AI视频生成赛道竞争格局"
            - variable: "competitors"
              label: "目标竞品（逗号分隔）"
              type: "text-input"
              required: false
              max_length: 500
              placeholder: "例如：Runway, Pika, 可灵AI, 即梦"
            - variable: "research_depth"
              label: "调研深度"
              type: "select"
              required: true
              default: "standard"
              options:
                - value: "quick"
                  label: "快速扫描 (5-8 条结果)"
                - value: "standard"
                  label: "标准调研 (15-20 条结果)"
                - value: "deep"
                  label: "深度调研 (30+ 条结果)"

      - id: "input_parser"
        type: "code"
        title: "输入解析与搜索词构建"
        position:
          x: 320
          y: 150
        data:
          code_language: "python3"
          code: |
            import json

            def main(research_topic: str, competitors: str, research_depth: str) -> dict:
                # 构建多维度搜索查询
                queries = []

                # 行业概况查询
                queries.append(f"{research_topic} 市场分析 行业报告 2024 2025")

                # 竞品逐一查询
                if competitors:
                    for comp in competitors.split(","):
                        comp = comp.strip()
                        if comp:
                            queries.append(f"{comp} 产品分析 融资 用户评价")
                            queries.append(f"{comp} 竞品对比 优势 劣势")

                # 趋势查询
                queries.append(f"{research_topic} 发展趋势 未来预测")

                # 根据深度控制查询数量
                depth_map = {
                    "quick": 3,
                    "standard": 5,
                    "deep": 8
                }
                max_queries = depth_map.get(research_depth, 5)
                queries = queries[:max_queries]

                return {
                    "queries": queries,
                    "research_topic": research_topic,
                    "competitors": [c.strip() for c in competitors.split(",") if c.strip()],
                    "depth": research_depth
                }

      - id: "tavily_search"
        type: "tool"
        title: "Tavily 多源搜索"
        position:
          x: 560
          y: 150
        data:
          tool_name: "tavily_search"
          provider_type: "builtin"
          provider_name: "tavily"
          tool_configurations:
            tavily_api_key: "{{TAVILY_API_KEY}}"
          tool_parameters:
            - name: "query"
              type: "variable"
              value: "{{#input_parser.queries#}}"
            - name: "search_depth"
              type: "constant"
              value: "advanced"
            - name: "include_domains"
              type: "constant"
              value: []
            - name: "exclude_domains"
              type: "constant"
              value: []
            - name: "max_results"
              type: "variable"
              value: "{{#input_parser.depth == 'quick' ? 5 : (input_parser.depth == 'standard' ? 10 : 20)#}}"

      - id: "web_scraper"
        type: "tool"
        title: "网页内容抓取"
        position:
          x: 800
          y: 150
        data:
          tool_name: "web_scraper"
          provider_type: "builtin"
          provider_name: "firecrawl"
          tool_configurations:
            firecrawl_api_key: "{{FIRECRAWL_API_KEY}}"
          tool_parameters:
            - name: "urls"
              type: "variable"
              value: "{{#tavily_search.results[*].url#}}"
            - name: "mode"
              type: "constant"
              value: "scrape"
            - name: "formats"
              type: "constant"
              value: ["markdown"]

      - id: "content_cleaner"
        type: "llm"
        title: "内容清洗与信息提取"
        position:
          x: 1040
          y: 150
        data:
          model:
            provider: "anthropic"
            name: "claude-3-5-sonnet-20240620"
            mode: "chat"
            completion_params:
              temperature: 0.2
              max_tokens: 4096
          prompt_template:
            - role: "system"
              text: |
                你是一个专业的市场调研分析师。请从提供的网页内容中提取与调研主题相关的关键信息。

                提取规则：
                1. 剔除广告、导航栏、页脚等无关内容
                2. 提取产品规格、定价、融资信息、用户评价
                3. 标注信息来源（URL 和发布时间）
                4. 判断信息可信度（高/中/低）

                返回 JSON 格式：
                {
                  "extracted_insights": [
                    {
                      "source_url": "...",
                      "source_title": "...",
                      "publish_date": "...",
                      "credibility": "high|medium|low",
                      "category": "product|funding|market|user_review|other",
                      "key_findings": "...",
                      "relevant_data": "..."
                    }
                  ]
                }
            - role: "user"
              text: |
                调研主题：{{#input_parser.research_topic#}}

                抓取到的网页内容：
                {{#web_scraper.text#}}

                请提取与调研主题相关的关键信息。

      - id: "swot_analyzer"
        type: "llm"
        title: "SWOT 分析生成"
        position:
          x: 1280
          y: 150
        data:
          model:
            provider: "anthropic"
            name: "claude-3-5-sonnet-20240620"
            mode: "chat"
            completion_params:
              temperature: 0.3
              max_tokens: 4096
          prompt_template:
            - role: "system"
              text: |
                你是一个资深的战略咨询顾问。请基于提供的调研数据，生成一份专业的 SWOT 分析报告。

                要求：
                1. **Strengths（优势）**：分析竞品/行业的核心竞争力、技术壁垒、资源优势
                2. **Weaknesses（劣势）**：分析短板、用户痛点、资源限制
                3. **Opportunities（机会）**：分析市场空白、技术趋势、政策红利
                4. **Threats（威胁）**：分析竞争压力、替代品风险、监管风险

                输出格式：
                使用 Markdown 格式，包含：
                - 标题和摘要
                - 每个维度 3-5 个要点
                - 每个要点附上数据支撑
                - 结尾给出综合建议
            - role: "user"
              text: |
                调研主题：{{#input_parser.research_topic#}}
                目标竞品：{{#input_parser.competitors#}}

                提取的关键信息：
                {{#content_cleaner.text#}}

                请生成 SWOT 分析报告。

      - id: "pdf_exporter"
        type: "tool"
        title: "导出 PDF 报告"
        position:
          x: 1520
          y: 150
        data:
          tool_name: "pdf_exporter"
          provider_type: "builtin"
          provider_name: "pdf_generator"
          tool_parameters:
            - name: "content"
              type: "variable"
              value: "{{#swot_analyzer.text#}}"
            - name: "title"
              type: "variable"
              value: "{{#input_parser.research_topic#}} - SWOT 分析报告"
            - name: "format"
              type: "constant"
              value: "A4"
            - name: "include_toc"
              type: "constant"
              value: true

      - id: "end"
        type: "end"
        title: "输出结果"
        position:
          x: 1760
          y: 150
        data:
          type: "end"
          outputs:
            - variable: "swot_report"
              label: "SWOT 分析报告 (Markdown)"
              value: "{{#swot_analyzer.text#}}"
            - variable: "pdf_report"
              label: "PDF 报告下载"
              value: "{{#pdf_exporter.url#}}"
            - variable: "insights"
              label: "原始洞察数据"
              value: "{{#content_cleaner.json#}}"
            - variable: "search_results"
              label: "搜索来源"
              value: "{{#tavily_search.results#}}"

environment_variables:
  - key: "TAVILY_API_KEY"
    name: "Tavily API Key"
    type: "secret"
    required: true
    description: "Tavily Search API 密钥，用于多源网页搜索"
  - key: "FIRECRAWL_API_KEY"
    name: "Firecrawl API Key"
    type: "secret"
    required: true
    description: "Firecrawl API 密钥，用于网页内容抓取"
  - key: "ANTHROPIC_API_KEY"
    name: "Anthropic API Key"
    type: "secret"
    required: true
    description: "Anthropic API 密钥，用于 Claude 模型调用"

tags:
  - "Dify"
  - "Market Research"
  - "SWOT"
  - "Tavily"
  - "Claude"
  - "Automation"
  - "Business Analysis"

version: "1.0.0"
created_at: "2026-08-05"