SuperAPI AI Directory

agentbay-monitor-skills

Data & analytics

View repository

Updated 10-15 19:51

About this skill

AgentBay Public Opinion Monitoring Skill

⚠️ Public opinion analysis = full workflow (required reading)

When the user says "run a public opinion analysis", "do a public opinion analysis", or "public opinion analysis, the topic is XXX", the complete three steps must be executed; you cannot just run the crawl and then stop.

Step Action Description
1. Crawl crawl.py or crawl_for_sentiment(...) obtain raw_output_path(crawl result JSON)
2. Sentiment analysis Read scripts/sentiment/sentiment_instruction.md → judge each entry in the crawl JSON one by one → write a small sentiment result JSON → run write_processed.py obtain processed JSON (e.g. output/processed.json)
3. Generate report report.py --input <processed 路径> or generate_report(...) obtain Markdown/JSON (and optional PDF)

Prohibited actions: only running crawl.py and then saying "crawl complete, sentiment analysis to be done by the main Agent" and stopping. This is incorrect usage—the main Agent is yourself, and you must continue to complete steps 2 and 3 until the final report file is produced.

When to use

When the user expresses any of the following intents,you mustuse this skill and execute the full workflow (crawl → sentiment analysis → generate report):

  • Asking "what is the public opinion on a certain event/topic", "what is the public opinion on XX", "I want to understand the public opinion on XX"
  • "Run a public opinion analysis", "do a public opinion analysis", "public opinion analysis, the topic is XXX"
  • Public opinion monitoring, sentiment analysis, public opinion reports, crawling by keyword/platform and generating reports (both Chinese and English scenarios)

If the intent is public opinion-related, this skill is used by default, and cannot be replaced by just using a web search.

Important convention: any mention of "public opinion analysis" (or equivalent expressions such as "run a public opinion analysis", "do a public opinion analysis", etc.) is deemed to mean executing thefull workflow—crawl → sentiment analysis → generate report. It must be executed according to this complete workflow; you cannot only do the crawl; the final output must include a Markdown/JSON (and optional PDF) report.

Prerequisites

The working directory is the skill directory (the directory where this SKILL is located); dependencies are installed; configured AGENTBAY_API_KEY。

Dependencies

pip install wuying-agentbay-sdk pandas numpy pyyaml markdown

Optional (PDF report):brew install cairo pango gdk-pixbuf after pip install weasyprint. If not installed, there is simply no PDF; .md/.json work normally.

API Key

Only need to configure AGENTBAY_API_KEY. Environment variable:export AGENTBAY_API_KEY=你的key(Windows PowerShell:$env:AGENTBAY_API_KEY="你的key"). Or write the file directly:mkdir -p ~/.config/agentbay && echo -n '你的key' > ~/.config/agentbay/api_key. Obtain:https://agentbay.console.aliyun.com/service-management . If not configured, running the script will report an error. The remaining parameters are passed in by the main Agent as arguments/command-line parameters.

Overall workflow

Public opinion analysis = full workflow: crawl → sentiment analysis → generate report (see "⚠️ Public opinion analysis = full workflow" above). When the user requests "public opinion analysis", all three steps must be executed; you cannot only do step 1.

  1. Crawl:crawl.py or crawl_for_sentiment(...) → obtain raw_output_path(crawl result JSON).
  2. Sentiment analysis: The main Agent reads the prompt scripts/sentiment/sentiment_instruction.md, determines the sentiment for each item in the crawl JSON, and produces a sentiment result small JSON; then runs write_processed.py to merge and obtain the processed JSON (e.g., output/processed.json). The prompt is customizable.
  3. Generate report:report.py --input <processed 路径> or generate_report(processed_results, ...) → Markdown/JSON (and optional PDF).

How to run

Step 0: Log in (non-search engines only) xhs/weibo/douyin/zhihu require login first; Baidu and Bing do not.python scripts/login.py --platform xhs [--context-name sentiment-analysis] → After logging in the browser, press Enter in the terminal; the state is persisted. When crawling with non-search engines, --context-name must match the login.

Step 1: Crawl

python scripts/crawl.py --keywords "关键词1,关键词2" [--platform baidu] [--max-results N] [--output-dir output]

Parameters:-k is required;-p defaults to baidu (options: xhs/weibo/douyin/zhihu/bing);--max-results、-o、--report-title、--context-name、--crawl-timeout. Baidu/Bing only scrape the news list page (without clicking into links); Baidu uses the news URL (tn=news).

Crawl timeout (must read): The execution environment (e.g., run_terminal_cmd)timeout must be ≥ 10 minutes(600 seconds or 600000 milliseconds), otherwise it will be interrupted. About 1 item/minute, 10 items take about 10 minutes; it is recommended that the timeout be slightly greater than the estimate (e.g., 15 minutes). In the script, --crawl-timeout is automatically calculated based on the number of items when not passed, so generally there is no need to pass it manually.

Step 2: Sentiment analysis The main Agent reads scripts/sentiment/sentiment_instruction.md, determines the sentiment for each item in the crawl JSON, and writes the processed JSON in the specified format (no need to configure an LLM in the skill).

Step 3: Generate report

python scripts/report.py --input <processed JSON 路径> [--output-dir output] [--title "报告标题"]

Output

Crawl → raw_output_path、crawl_results. Sentiment analysis → processed JSON (including sentiment_statistics, each item's sentiment, format see the prompt). Report → markdown_path、json_path, optional pdf_path。

Key points for Agent invocation

Public opinion analysis must run the full process: When the user says "public opinion analysis", "run public opinion analysis", or similar intent,mustcomplete "crawl → sentiment analysis → merge (write_processed.py) → generate report", producing the final report file.must notrun only the crawl and then say "sentiment analysis will be done by the main Agent" and end — the main Agent is the current Agent, and you must continue to complete the sentiment analysis and report.

  • Login: For non-search engines, first login.py --platform <平台>; Baidu/Bing require no login.
  • Crawl:crawl.py or crawl_for_sentiment(...), default platform baidu;execution timeout ≥ 10 minutes(see "Crawl timeout" above); for non-search engines, context_name must match the login.
  • Sentiment analysis: Read scripts/sentiment/sentiment_instruction.md; for the crawl JSON (raw_output_path) determine the sentiment for each item; write the sentiment result small JSON (e.g., output/sentiment_only.json); run python scripts/sentiment/write_processed.py --raw <爬取JSON> --sentiment <情感结果JSON> --output output/processed.json。
  • Report:report.py --input output/processed.json or generate_report(...)。
  • Failure: Key not configured, not logged in, or execution failed → success: False、error。

Code example

import asyncio, sys, json
from pathlib import Path
sys.path.insert(0, str(Path(__file__).resolve().parent / "scripts"))
from crawl import crawl_for_sentiment, generate_report

async def main():
    result = await crawl_for_sentiment(platform="baidu", keywords=["产品名"], max_results_per_keyword=10, output_dir="output")
    if not result.get("success"): return
    raw_path = result.get("raw_output_path")
    # 主 Agent:读 sentiment_instruction.md → 对 raw_path 做情感分析 → 写 output/processed.json(或先用 write_processed.py 合并)
    processed_path = Path("output") / "processed.json"
    with open(processed_path, "r", encoding="utf-8") as f:
        report = generate_report(json.load(f), output_dir="output", title="舆情报告")
    print("报告:", report.get("markdown_path"))
asyncio.run(main())

Common questions

  • What if only the crawl was run: If crawl.py has been run and produced raw_output_path, you must continue with sentiment analysis (read sentiment_instruction.md, write the sentiment result JSON, run write_processed.py) and then run report.py --input <processed路径>, until the report is produced.
  • processed JSON: title/content often contain unescaped double quotes, and manual writing can easily cause report.py JSON parsing failure. The main Agent only produces the small "sentiment result" JSON, then runs python scripts/sentiment/write_processed.py --raw <爬取JSON> --sentiment <情感结果JSON> --output <processed路径>. See sentiment_instruction.md Section 4.
  • Login expired: rerun python scripts/login.py --platform <平台> [--context-name ...]。
  • Crawl timeout: The execution environment timeout must be ≥ 10 minutes (see above); if a longer time is needed, explicitly pass --crawl-timeout(seconds).

File structure

SKILL.md · scripts/:crawl.py(crawl/report entry point),report.py、login.py、crawler/、sentiment/(sentiment_instruction.md、write_processed.py)、reporter/ · output/