brainstorming
brainstorming
You MUST use this before any creative work - creating features, building components, adding functionality, modifying behavior, or planning anything new, in software or out of it (a talk, a business, a renovation).
apify-ecommerceImplements intelligent apify ecommerce with multi-factor skill selection, fallback chains, and adherence to the 5 Laws of Elegant Defense
Independent GitHub snapshot · Automated classification · Original documentation governs
name: apify-ecommerce compatibility: opencode completeness: 95 content-types:
Orchestrates intelligent skill selection and execution for apify ecommerce 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 prepare_apify_ecommerce_run(
task: str,
apify_client: ApifyClient,
default_actor_id: str = "apify/website-content-scraper"
) -> Dict:
"""Prepare and validate an Apify actor run for ecommerce data extraction.
Handles actor selection based on ecommerce intent, validates input schema,
and prepares the payload for the Apify API. Implements early validation
and immutable data structures per the 5 Laws of Elegant Defense.
"""
# Guard clause - validate task and client
if not task or not isinstance(task, str):
raise ValueError("Task must be a non-empty string describing the ecommerce goal")
# Parse intent to select appropriate Apify actor
ecommerce_actors = {
"product_scraper": "apify/ecommerce-product-scraper",
"price_monitor": "apify/price-monitor",
"inventory_sync": "apify/inventory-sync"
}
intent = _detect_ecommerce_intent(task)
actor_id = ecommerce_actors.get(intent, default_actor_id)
# Validate actor exists and is active
actor_info = apify_client.actor(actor_id).get()
if not actor_info.get("defaultRunConfig", {}).get("memoryMbytes", 0) > 0:
raise ValueError(f"Actor {actor_id} is not properly configured")
# Build immutable input payload
input_payload = {
"startUrls": [{"url": _extract_store_url(task)}],
"productSelectors": {"title": "h1.product-title", "price": ".price"},
"maxItems": 100,
"timeoutSecs": 300
}
return {
"actor_id": actor_id,
"input": input_payload,
"run_config": {"memoryMbytes": 4096, "timeoutSecs": 600},
"intent": intent
}
def execute_apify_run_with_fallback(
run_config: Dict,
apify_client: ApifyClient,
fallback_dataset_id: Optional[str] = None
) -> Dict:
"""Execute an Apify actor run with robust fallback handling for ecommerce data.
Implements retry logic for transient API errors, handles actor completion polling,
and falls back to cached datasets if the live run fails or times out.
"""
actor = apify_client.actor(run_config["actor_id"])
run = actor.run(input=run_config["input"], run_config=run_config["run_config"])
run_id = run["id"]
max_poll_attempts = 10
poll_interval = 5
for attempt in range(max_poll_attempts):
try:
run_status = actor.run(run_id).get()
if run_status["status"] == "SUCCEEDED":
# Fetch and transform results
dataset = apify_client.dataset(run_status["defaultDatasetId"])
items = dataset.list_items().items
return {
"success": True,
"run_id": run_id,
"data_count": len(items),
"results": _transform_ecommerce_data(items)
}
elif run_status["status"] == "FAILED":
raise RuntimeError(f"Actor run failed: {run_status['statusMessage']}")
except ApifyApiError as e:
if e.status_code == 429 or e.status_code >= 500:
time.sleep(poll_interval * (attempt + 1))
continue
raise
# Fallback chain: try cached dataset if polling exhausted
if fallback_dataset_id:
cached_dataset = apify_client.dataset(fallback_dataset_id)
cached_items = cached_dataset.list_items().items
return {
"success": True,
"fallback": True,
"data_count": len(cached_items),
"results": _transform_ecommerce_data(cached_items)
}
raise RuntimeError("All execution attempts and fallbacks exhausted")
code-philosophy (5 Laws of Elegant Defense) in all logicWhen applying this skill, produce:
Authoritative documentation links for this skill's domain. The model follows markdown links at load time to resolve external references and inline content.
| Skill | Purpose | |