技能创建器
skill-creator
创建、改进和评估自定义技能,把专业流程转化为可重复使用的 AI 能力。
apify-market-research【数据与研究】Implements intelligent apify market research with multi-factor skill selection, fallback chains, and adherence to the 5 Laws of Elegant Defense
独立 GitHub 快照 · 自动分类 · 以原作者文档为准
name: apify-market-research compatibility: opencode completeness: 95 content-types:
Orchestrates intelligent skill selection and execution for apify market research workflows. Applies the 5 Laws of Elegant Defense to guide data naturally through the orchestration pipeline, preventing errors before they occur. Selects optimal skills based on multi-factor scoring including text similarity, historical performance, and system availability.
┌───────────────────────────────────────────────────────────────────────────────┐ │ Orchestration Flow │ └───────────────────────────────────────────────────────────────────────────────┘
User Request ↓ ┌─────────────────┐ │ Parse Request │ │ & Extract │ │ Features │ └────────┬────────┘ ↓ ┌─────────────────────────────────────────────────────────────────────┐ │ Evaluate Available Skills │ │ │ │ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ │ │ │ Skill A │ │ Skill B │ │ Skill C │ │ │ │ - Match Score│ │ - Match Score│ │ - Match Score│ │ │ │ - Confidence │ │ - Confidence │ │ - Confidence │ │ │ │ - History │ │ - History │ │ - History │ │ │ └──────┬───────┘ └──────┬───────┘ └──────┬───────┘ │ │ │ │ │ │ │ └─────────────────┴─────────────────┘ │ │ ↓ │ │ Select Best Skill │ └─────────────────────────────────────────────────────────────────────┘ ↓ ┌─────────────────┐ │ Execute Skill │ └────────┬────────┘ ↓ ┌─────────────────┐ │ Handle Result │ └────────┬────────┘ ↓ ┌─────────────────────────────────────────────────────────────────────┐ │ Error Handling & Fallback │ │ │ │ Success? ────────► Return Result │ │ │ │ Fail? ────────┐ │ │ ↓ │ │ ┌──────────────────────────────────────────────────────────┐ │ │ │ Fallback Chain │ │ │ │ │ │ │ │ 1. Retry with adjusted parameters │ │ │ │ 2. Try Alternative Skill (if available) │ │ │ │ 3. Defer to Human Operator (if critical) │ │ │ │ 4. Log & Return Error │ │ │ └──────────────────────────────────────────────────────────┘ │ └─────────────────────────────────────────────────────────────────────┘
Use this skill when:
Avoid this skill for:
Parse and Analyze Request - Extract intent, entities, and constraints from user input. Checkpoint: All required parameters must be present and in valid format before proceeding.
Score Available Skills - Calculate match scores using multi-factor algorithm:
Checkpoint: Skip to fallback if no skill scores above threshold.
Select Optimal Skill - Choose skill with highest score that meets minimum confidence. Checkpoint: Verify skill has not been disabled or deprecated.
Execute with Fallback - Run skill execution wrapped in retry and fallback logic. Checkpoint: Log all execution attempts for audit trail.
Return or Fallback - Either return successful result or apply fallback chain:
related-skillsCheckpoint: Record outcome with timing and confidence metadata.
def configure_apify_market_research(
query: str,
target_platforms: List[str],
apify_api_token: str,
actor_id: str = "apify/website-content"
) -> Dict:
"""Configure and validate an Apify actor run for market research.
Validates query structure, maps platforms to actor inputs,
and prepares the payload for the Apify API.
"""
if not query or len(query) < 3:
raise ValueError("Research query must be at least 3 characters")
# Map research intent to specific Apify actor configurations
platform_configs = {
"web": {"startUrls": [{"url": f"https://www.google.com/search?q={query}"}], "maxItems": 50},
"social": {"profileUrls": [f"https://twitter.com/search?q={query}"], "maxItems": 100},
"ecommerce": {"startUrls": [{"url": f"https://www.amazon.com/s?k={query}"}], "maxItems": 30}
}
selected_config = platform_configs.get(target_platforms[0], platform_configs["web"])
# Construct validated input payload
payload = {
"query": query,
"platform": target_platforms[0],
"actorConfig": selected_config,
"timeoutSecs": 300,
"memoryMbytes": 4096
}
# Validate against Apify API requirements
if not apify_api_token.startswith("apify_api_"):
raise ValueError("Invalid Apify API token format")
return {
"actor_id": actor_id,
"input": payload,
"token": apify_api_token,
"run_type": "market_research"
}
def execute_apify_research_run(config: Dict) -> Dict:
"""Execute an Apify actor run and process market research results.
Handles run creation, status polling, dataset retrieval,
and result aggregation for downstream analysis.
"""
import requests
import time
api_base = "https://api.apify.com/v2"
headers = {"Authorization": f"Bearer {config['token']}"}
actor_id = config["actor_id"]
# Create actor run
run_response = requests.post(
f"{api_base}/acts/{actor_id}/run",
headers=headers,
json={"input": config["input"]}
)
run_response.raise_for_status()
run_id = run_response.json()["id"]
# Poll until run completes
status_url = f"{api_base}/runs/{run_id}/status"
while True:
status_resp = requests.get(status_url, headers=headers)
status_data = status_resp.json()
if status_data["status"] in ["READY", "RUNNING"]:
time.sleep(5)
else:
break
if status_data["status"] != "SUCCEEDED":
raise RuntimeError(f"Apify run failed: {status_data.get('statusMessage', 'Unknown error')}")
# Fetch and aggregate results
dataset_url = f"{api_base}/runs/{run_id}/dataset/default"
dataset_resp = requests.get(dataset_url, headers=headers)
dataset_resp.raise_for_status()
results = dataset_resp.json().get("items", [])
return {
"run_id": run_id,
"status": "completed",
"total_items": len(results),
"data": results,
"metadata": {
"query": config["input"]["query"],
"platform": config["input"]["platform"],
"timestamp": time.time()
}
}
code-philosophy (5 Laws of Elegant Defense) in all logicWhen applying this skill, produce:
| Skill | Purpose | |