SuperAPI AI Directory

agentbay-monitor-skill

Agents & models

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 public opinion analysis", "do public opinion analysis", or "public opinion analysis, topic is XXX", the complete three steps must be executed; you cannot just run crawling and then stop.

Step Action Description
1. Crawling crawl.py or crawl_for_sentiment(...) obtain raw_output_path(crawling result JSON)
2. Sentiment analysis Read scripts/sentiment/sentiment_instruction.md → determine each item in the crawling JSON one by one → write the sentiment result small JSON → run write_processed.py to 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 behavior: only running crawl.py and then saying "crawling complete, sentiment analysis is completed by the main Agent" and ending. 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

Public opinion monitoring,public opinion analysis, sentiment analysis, public opinion reports, crawling by keyword/platform and generating reports (both Chinese and English scenarios). If the intent is related to public opinion, use this skill by default.

Important convention: any mention of "public opinion analysis" (or equivalent expressions such as "run public opinion analysis" or "do public opinion analysis") is regarded as executing thefull workflow—crawling → sentiment analysis → report generation. It must be executed according to this complete workflow, and you cannot only do crawling; 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, then there is only no PDF, and .md/.json works normally.

API Key

Only needs to configure AGENTBAY_API_KEY. Environment variable:export AGENTBAY_API_KEY=你的key(Windows PowerShell:$env:AGENTBAY_API_KEY="你的key"). Or directly write the file: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 via parameters/command line.

Overall workflow

Public opinion analysis = full workflow: crawling → sentiment analysis → report generation (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. Crawling:crawl.py or crawl_for_sentiment(...) → obtain raw_output_path(crawling result JSON).
  2. Sentiment analysis: the main Agent reads the prompt scripts/sentiment/sentiment_instruction.md, determines the sentiment of each item in the crawling JSON one by one, and produces the sentiment result small JSON; then runs write_processed.py to merge and obtain processed JSON (e.g. output/processed.json). The prompt can be customized.
  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 in the browser, press Enter in the terminal; the state is persisted. When crawling non-search-engine sources, --context-name must match the login.

Step 1: Crawling

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

Parameters:-k required;-p defaults to baidu (options: xhs/weibo/douyin/zhihu/bing);--max-results、-o、--report-title、--context-name、--crawl-timeout. Baidu/Bing only crawl 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, so 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; 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 of each crawled JSON item one by one, 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 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 notonly run crawling and then say "sentiment analysis is completed 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: Before 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 crawled JSON (raw_output_path) determine the sentiment item by item; write a small sentiment result 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())

FAQ

  • What if only crawling was run: If crawl.py has already been run to obtain 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 writing them by hand can easily cause report.py JSON parsing failure. The main Agent only produces a small "sentiment result" JSON, then runs python scripts/sentiment/write_processed.py --raw <爬取JSON> --sentiment <情感结果JSON> --output <processed路径>. For details, 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),report.py、login.py、crawler/、sentiment/(sentiment_instruction.md、write_processed.py)、reporter/ · output/