diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t10/tests/check_output_shape.py b/harbor/tasks/v3_depth6_delay_sla_burden_t10/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t10/tests/check_output_shape.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import json +import os +import re +from pathlib import Path + + +def write_reward(score: float, diagnostic: str) -> None: + log_dir = Path(os.environ.get("LOG_DIR", "/logs/verifier")) + log_dir.mkdir(parents=True, exist_ok=True) + (log_dir / "reward.txt").write_text(f"{score:.6g}\n") + (log_dir / "reward.json").write_text( + json.dumps({"reward": score, "smoke_only": True}, indent=2) + "\n" + ) + (log_dir / "diagnostic.txt").write_text(diagnostic + "\n") + + +def main() -> int: + app_dir = Path(os.environ.get("APP_DIR", "/app")) + task = json.loads((app_dir / "task.json").read_text()) + answer_path = app_dir / "answer.txt" + if not answer_path.exists(): + write_reward(0.0, "missing /app/answer.txt") + return 1 + + got = answer_path.read_text().strip() + if task["answer_format"] == "exact integer": + ok = bool(re.fullmatch(r"-?\d+", got)) + diagnostic = "valid integer smoke output" if ok else f"not an exact integer: {got!r}" + else: + ok = bool(re.fullmatch(r"[A-Za-z]+", got)) + diagnostic = "valid code smoke output" if ok else f"not an exact code: {got!r}" + + # This is intentionally not official scoring; it only verifies I/O shape. + write_reward(1.0 if ok else 0.0, diagnostic) + return 0 if ok else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t10/tests/test.sh b/harbor/tasks/v3_depth6_delay_sla_burden_t10/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t10/tests/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -u +python /tests/check_output_shape.py diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t11/environment/Dockerfile b/harbor/tasks/v3_depth6_delay_sla_burden_t11/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t11/environment/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.12-slim +WORKDIR /app +COPY flowbench_tools.py /app/flowbench_tools.py +COPY task.json /app/task.json diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t11/environment/flowbench_tools.py b/harbor/tasks/v3_depth6_delay_sla_burden_t11/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t11/environment/flowbench_tools.py @@ -0,0 +1,311 @@ +"""Deterministic FlowBench v3 tools. This file contains no task answers.""" + + +REGIONS = ["NA", "EU", "APAC", "LATAM"] +CATEGORIES = ["A", "B", "C", "D"] +CURRENCIES = {"NA": "USD", "EU": "EUR", "APAC": "JPY", "LATAM": "BRL"} +FX_TO_USD_BP = {"USD": 10000, "EUR": 10900, "JPY": 67, "BRL": 1850} +TIERS = ["std", "gold", "plat"] +DISCOUNT_PCT = {"std": 0, "gold": 10, "plat": 20} +CHANNELS = ["web", "store", "partner"] +MONTHS = [202601, 202602, 202603, 202604, 202605, 202606] + +N_CUSTOMERS = 72 +N_PRODUCTS = 48 +N_ORDERS = 720 +N_TICKETS = 260 +N_RETURNS = 180 + + +def _h(*xs): + import hashlib + s = "|".join(str(x) for x in xs).encode() + return int.from_bytes(hashlib.sha256(s).digest()[:8], "big") & 0x7FFFFFFF + + +def build_data(): + customers = [] + for cid in range(N_CUSTOMERS): + region = REGIONS[_h("region", cid) % len(REGIONS)] + customers.append({ + "customer_id": cid, + "region": region, + "tier": TIERS[_h("tier", cid) % len(TIERS)], + "segment": ["consumer", "smb", "enterprise"][_h("segment", cid) % 3], + }) + + products = [] + for pid in range(N_PRODUCTS): + cat = CATEGORIES[_h("cat", pid) % len(CATEGORIES)] + unit_price = 12 + _h("price", pid) % 240 + cogs = unit_price * (45 + _h("margin", pid) % 35) // 100 + products.append({ + "product_id": pid, + "category": cat, + "unit_price_usd": unit_price, + "unit_cogs_usd": cogs, + "lead_time_days": 3 + _h("lead", pid) % 18, + }) + + inventory = [] + for pid in range(N_PRODUCTS): + for region in REGIONS: + inventory.append({ + "product_id": pid, + "region": region, + "on_hand": 10 + _h("onhand", pid, region) % 140, + "reserved": _h("reserved", pid, region) % 28, + "inbound": _h("inbound", pid, region) % 85, + }) + + orders = [] + for oid in range(N_ORDERS): + customer_id = _h("ocust", oid) % N_CUSTOMERS + product_id = _h("oprod", oid) % N_PRODUCTS + month = MONTHS[_h("month", oid) % len(MONTHS)] + qty = 1 + _h("qty", oid) % 9 + ship_days = 1 + _h("shipdays", oid) % 16 + promised_days = 3 + _h("promise", oid) % 9 + status = ["paid", "paid", "paid", "paid", "cancelled", "refunded"][ + _h("status", oid) % 6] + orders.append({ + "order_id": oid, + "customer_id": customer_id, + "product_id": product_id, + "month": month, + "qty": qty, + "status": status, + "channel": CHANNELS[_h("channel", oid) % len(CHANNELS)], + "ship_days": ship_days, + "promised_days": promised_days, + }) + + returns = [] + for rid in range(N_RETURNS): + oid = _h("roid", rid) % N_ORDERS + order = orders[oid] + if order["status"] == "cancelled": + continue + returned_qty = 1 + _h("rqty", rid) % max(1, order["qty"]) + reason = ["defect", "late", "changed_mind", "wrong_item"][_h("reason", rid) % 4] + returns.append({ + "return_id": rid, + "order_id": oid, + "month": MONTHS[_h("rmonth", rid) % len(MONTHS)], + "returned_qty": returned_qty, + "reason": reason, + }) + + tickets = [] + for tid in range(N_TICKETS): + oid = _h("toid", tid) % N_ORDERS + severity = ["low", "medium", "high", "critical"][_h("sev", tid) % 4] + opened = MONTHS[_h("tmonth", tid) % len(MONTHS)] + first_response_hours = 1 + _h("resp", tid) % 96 + resolution_hours = first_response_hours + _h("res", tid) % 240 + tickets.append({ + "ticket_id": tid, + "order_id": oid, + "opened_month": opened, + "severity": severity, + "first_response_hours": first_response_hours, + "resolution_hours": resolution_hours, + }) + + return { + "customers": customers, + "products": products, + "inventory": inventory, + "orders": orders, + "returns": returns, + "tickets": tickets, + "fx_to_usd_bp": FX_TO_USD_BP, + } + + +DATA = build_data() +CUSTOMERS = {c["customer_id"]: c for c in DATA["customers"]} +PRODUCTS = {p["product_id"]: p for p in DATA["products"]} +ORDERS = {o["order_id"]: o for o in DATA["orders"]} + + +def region_currency(region: str) -> str: + return CURRENCIES[region] + + +def get_orders(region: str, category: str, month_start: int, month_end: int) -> list: + """Paid/refunded order ids in a region/category/month window.""" + out = [] + for o in DATA["orders"]: + if o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + p = PRODUCTS[o["product_id"]] + if c["region"] == region and p["category"] == category and month_start <= o["month"] <= month_end: + out.append(o["order_id"]) + return sorted(out) + + +def order_gross_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * p["unit_price_usd"] + + +def order_margin_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * (p["unit_price_usd"] - p["unit_cogs_usd"]) + + +def refund_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + qty = sum(r["returned_qty"] for r in DATA["returns"] if r["order_id"] == order_id) + qty = min(qty, o["qty"]) + return qty * p["unit_price_usd"] + + +def customer_tier(order_id: int) -> str: + o = ORDERS[order_id] + return CUSTOMERS[o["customer_id"]]["tier"] + + +def apply_discount(amount_usd: int, tier: str) -> int: + return amount_usd * (100 - DISCOUNT_PCT[tier]) // 100 + + +def net_revenue_usd(order_id: int) -> int: + gross = apply_discount(order_gross_usd(order_id), customer_tier(order_id)) + return max(0, gross - refund_usd(order_id)) + + +def to_local(amount_usd: int, currency: str) -> int: + return amount_usd * 10000 // FX_TO_USD_BP[currency] + + +def inventory_position(product_id: int, region: str) -> int: + row = next(x for x in DATA["inventory"] + if x["product_id"] == product_id and x["region"] == region) + return row["on_hand"] - row["reserved"] + row["inbound"] + + +def product_lead_time(product_id: int) -> int: + return PRODUCTS[product_id]["lead_time_days"] + + +def product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int: + totals = {} + for oid in get_orders(region, category, month_start, month_end): + o = ORDERS[oid] + totals[o["product_id"]] = totals.get(o["product_id"], 0) + o["qty"] + if not totals: + return -1 + return min((-qty, pid) for pid, qty in totals.items())[1] + + +def units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int: + total = 0 + for o in DATA["orders"]: + if o["product_id"] != product_id or o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + if c["region"] == region and month_start <= o["month"] <= month_end: + total += o["qty"] + return total + + +def tickets_for_orders(order_ids: list, severity: str) -> list: + s = set(order_ids) + return sorted(t["ticket_id"] for t in DATA["tickets"] + if t["order_id"] in s and t["severity"] == severity) + + +def ticket_order_id(ticket_id: int) -> int: + return next(t["order_id"] for t in DATA["tickets"] if t["ticket_id"] == ticket_id) + + +def sla_breached(ticket_id: int, first_response_limit_hours: int, + resolution_limit_hours: int) -> bool: + t = next(x for x in DATA["tickets"] if x["ticket_id"] == ticket_id) + return (t["first_response_hours"] > first_response_limit_hours or + t["resolution_hours"] > resolution_limit_hours) + + +def delayed_orders(order_ids: list) -> list: + s = set(order_ids) + return sorted(o["order_id"] for o in DATA["orders"] + if o["order_id"] in s and o["ship_days"] > o["promised_days"]) + + +def unique_customers(order_ids: list) -> list: + return sorted({ORDERS[oid]["customer_id"] for oid in order_ids}) + + +def count_items(values: list) -> int: + return len(values) + + +def sum_values(values: list) -> int: + return sum(values) + + +def count_true(values: list) -> int: + return sum(1 for v in values if bool(v)) + + +def count_below(values: list, threshold: int) -> int: + return sum(1 for v in values if v < threshold) + + +TOOLS = { + "region_currency": ("region_currency(region: str) -> str", + "ISO currency code for a region.", region_currency), + "get_orders": ("get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]", + "Paid/refunded order ids for a region, product category, and inclusive month window.", + get_orders), + "order_gross_usd": ("order_gross_usd(order_id: int) -> int", + "Gross order revenue in USD before discounts/refunds.", order_gross_usd), + "order_margin_usd": ("order_margin_usd(order_id: int) -> int", + "Gross order margin in USD before discounts/refunds.", order_margin_usd), + "refund_usd": ("refund_usd(order_id: int) -> int", + "Refund amount in USD for returned quantity on an order.", refund_usd), + "customer_tier": ("customer_tier(order_id: int) -> str", + "Customer loyalty tier for an order.", customer_tier), + "apply_discount": ("apply_discount(amount_usd: int, tier: str) -> int", + "Apply the order customer's loyalty discount to a USD amount.", apply_discount), + "net_revenue_usd": ("net_revenue_usd(order_id: int) -> int", + "Net USD revenue after loyalty discount and refunds.", net_revenue_usd), + "to_local": ("to_local(amount_usd: int, currency: str) -> int", + "Convert a USD integer amount to a local-currency integer.", to_local), + "inventory_position": ("inventory_position(product_id: int, region: str) -> int", + "Available inventory position: on_hand - reserved + inbound.", + inventory_position), + "product_lead_time": ("product_lead_time(product_id: int) -> int", + "Supplier lead time in days for a product.", product_lead_time), + "product_id_for_top_seller": ( + "product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int", + "Product id with the highest units sold in a region/category/month window.", + product_id_for_top_seller), + "units_sold": ("units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int", + "Units sold for one product in a region and month window.", units_sold), + "tickets_for_orders": ("tickets_for_orders(order_ids: list[int], severity: str) -> list[int]", + "Support ticket ids for given orders and severity.", tickets_for_orders), + "ticket_order_id": ("ticket_order_id(ticket_id: int) -> int", + "Order id associated with a support ticket.", ticket_order_id), + "sla_breached": ( + "sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool", + "Whether a support ticket breaches first-response or resolution SLA.", + sla_breached), + "delayed_orders": ("delayed_orders(order_ids: list[int]) -> list[int]", + "Subset of order ids whose ship_days exceeded promised_days.", delayed_orders), + "unique_customers": ("unique_customers(order_ids: list[int]) -> list[int]", + "Unique customer ids among the given orders.", unique_customers), + "count_items": ("count_items(values: list) -> int", "Length of a list.", count_items), + "sum_values": ("sum_values(values: list[int]) -> int", "Sum a list of integers.", sum_values), + "count_true": ("count_true(values: list[bool]) -> int", "Count true values.", count_true), + "count_below": ("count_below(values: list[int], threshold: int) -> int", + "Count values below a threshold.", count_below), +} + +__all__ = [name for name in TOOLS.keys()] + ['TOOLS'] diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t11/environment/task.json b/harbor/tasks/v3_depth6_delay_sla_burden_t11/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..07fc30e95a67802318e2a4ea6f2150b6dba19750 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t11/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth6_delay_sla_burden_t11", + "depth": 6, + "family": "delay_sla_burden", + "params": { + "region": "LATAM", + "category": "A", + "month_start": 202601, + "month_end": 202603 + }, + "question": "For region LATAM, category A, months 202601-202603: get the orders, count delayed orders where ship_days exceeded promised_days, find high and critical support tickets for those orders, count tickets that breach a 24-hour first-response or 120-hour resolution SLA, and report delayed_order_count + breached_ticket_count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t11/instruction.md b/harbor/tasks/v3_depth6_delay_sla_burden_t11/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..1bdd10feca43e0f6626cf3a1ee5503f70dcafc40 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t11/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For region LATAM, category A, months 202601-202603: get the orders, count delayed orders where ship_days exceeded promised_days, find high and critical support tickets for those orders, count tickets that breach a 24-hour first-response or 120-hour resolution SLA, and report delayed_order_count + breached_ticket_count. + +Available tools: +- `region_currency(region: str) -> str`: ISO currency code for a region. +- `get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]`: Paid/refunded order ids for a region, product category, and inclusive month window. +- `order_gross_usd(order_id: int) -> int`: Gross order revenue in USD before discounts/refunds. +- `order_margin_usd(order_id: int) -> int`: Gross order margin in USD before discounts/refunds. +- `refund_usd(order_id: int) -> int`: Refund amount in USD for returned quantity on an order. +- `customer_tier(order_id: int) -> str`: Customer loyalty tier for an order. +- `apply_discount(amount_usd: int, tier: str) -> int`: Apply the order customer's loyalty discount to a USD amount. +- `net_revenue_usd(order_id: int) -> int`: Net USD revenue after loyalty discount and refunds. +- `to_local(amount_usd: int, currency: str) -> int`: Convert a USD integer amount to a local-currency integer. +- `inventory_position(product_id: int, region: str) -> int`: Available inventory position: on_hand - reserved + inbound. +- `product_lead_time(product_id: int) -> int`: Supplier lead time in days for a product. +- `product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int`: Product id with the highest units sold in a region/category/month window. +- `units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int`: Units sold for one product in a region and month window. +- `tickets_for_orders(order_ids: list[int], severity: str) -> list[int]`: Support ticket ids for given orders and severity. +- `ticket_order_id(ticket_id: int) -> int`: Order id associated with a support ticket. +- `sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool`: Whether a support ticket breaches first-response or resolution SLA. +- `delayed_orders(order_ids: list[int]) -> list[int]`: Subset of order ids whose ship_days exceeded promised_days. +- `unique_customers(order_ids: list[int]) -> list[int]`: Unique customer ids among the given orders. +- `count_items(values: list) -> int`: Length of a list. +- `sum_values(values: list[int]) -> int`: Sum a list of integers. +- `count_true(values: list[bool]) -> int`: Count true values. +- `count_below(values: list[int], threshold: int) -> int`: Count values below a threshold. diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t11/task.toml b/harbor/tasks/v3_depth6_delay_sla_burden_t11/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..6f017cec85727bf6e73d0cf92e452d09dfeb24d3 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t11/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth6_delay_sla_burden_t11" +description = "FlowBench v3 public task metadata. Public verifier is smoke-only." +authors = [{ name = "Mind Lab", email = "contact@mindlab.ltd" }] +keywords = ["flowbench", "tool-use", "data-orchestration", "operations"] + +[metadata] +benchmark = "FlowBench-v3" +split = "public-task-only" +category = "data-processing" +depth = 6 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +network_mode = "no-network" +build_timeout_sec = 600.0 +os = "linux" +cpus = 1 +memory_mb = 2048 +storage_mb = 2048 +gpus = 0 diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t11/tests/check_output_shape.py b/harbor/tasks/v3_depth6_delay_sla_burden_t11/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t11/tests/check_output_shape.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import json +import os +import re +from pathlib import Path + + +def write_reward(score: float, diagnostic: str) -> None: + log_dir = Path(os.environ.get("LOG_DIR", "/logs/verifier")) + log_dir.mkdir(parents=True, exist_ok=True) + (log_dir / "reward.txt").write_text(f"{score:.6g}\n") + (log_dir / "reward.json").write_text( + json.dumps({"reward": score, "smoke_only": True}, indent=2) + "\n" + ) + (log_dir / "diagnostic.txt").write_text(diagnostic + "\n") + + +def main() -> int: + app_dir = Path(os.environ.get("APP_DIR", "/app")) + task = json.loads((app_dir / "task.json").read_text()) + answer_path = app_dir / "answer.txt" + if not answer_path.exists(): + write_reward(0.0, "missing /app/answer.txt") + return 1 + + got = answer_path.read_text().strip() + if task["answer_format"] == "exact integer": + ok = bool(re.fullmatch(r"-?\d+", got)) + diagnostic = "valid integer smoke output" if ok else f"not an exact integer: {got!r}" + else: + ok = bool(re.fullmatch(r"[A-Za-z]+", got)) + diagnostic = "valid code smoke output" if ok else f"not an exact code: {got!r}" + + # This is intentionally not official scoring; it only verifies I/O shape. + write_reward(1.0 if ok else 0.0, diagnostic) + return 0 if ok else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t11/tests/test.sh b/harbor/tasks/v3_depth6_delay_sla_burden_t11/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t11/tests/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -u +python /tests/check_output_shape.py diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t12/environment/Dockerfile b/harbor/tasks/v3_depth6_delay_sla_burden_t12/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t12/environment/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.12-slim +WORKDIR /app +COPY flowbench_tools.py /app/flowbench_tools.py +COPY task.json /app/task.json diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t12/environment/flowbench_tools.py b/harbor/tasks/v3_depth6_delay_sla_burden_t12/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t12/environment/flowbench_tools.py @@ -0,0 +1,311 @@ +"""Deterministic FlowBench v3 tools. This file contains no task answers.""" + + +REGIONS = ["NA", "EU", "APAC", "LATAM"] +CATEGORIES = ["A", "B", "C", "D"] +CURRENCIES = {"NA": "USD", "EU": "EUR", "APAC": "JPY", "LATAM": "BRL"} +FX_TO_USD_BP = {"USD": 10000, "EUR": 10900, "JPY": 67, "BRL": 1850} +TIERS = ["std", "gold", "plat"] +DISCOUNT_PCT = {"std": 0, "gold": 10, "plat": 20} +CHANNELS = ["web", "store", "partner"] +MONTHS = [202601, 202602, 202603, 202604, 202605, 202606] + +N_CUSTOMERS = 72 +N_PRODUCTS = 48 +N_ORDERS = 720 +N_TICKETS = 260 +N_RETURNS = 180 + + +def _h(*xs): + import hashlib + s = "|".join(str(x) for x in xs).encode() + return int.from_bytes(hashlib.sha256(s).digest()[:8], "big") & 0x7FFFFFFF + + +def build_data(): + customers = [] + for cid in range(N_CUSTOMERS): + region = REGIONS[_h("region", cid) % len(REGIONS)] + customers.append({ + "customer_id": cid, + "region": region, + "tier": TIERS[_h("tier", cid) % len(TIERS)], + "segment": ["consumer", "smb", "enterprise"][_h("segment", cid) % 3], + }) + + products = [] + for pid in range(N_PRODUCTS): + cat = CATEGORIES[_h("cat", pid) % len(CATEGORIES)] + unit_price = 12 + _h("price", pid) % 240 + cogs = unit_price * (45 + _h("margin", pid) % 35) // 100 + products.append({ + "product_id": pid, + "category": cat, + "unit_price_usd": unit_price, + "unit_cogs_usd": cogs, + "lead_time_days": 3 + _h("lead", pid) % 18, + }) + + inventory = [] + for pid in range(N_PRODUCTS): + for region in REGIONS: + inventory.append({ + "product_id": pid, + "region": region, + "on_hand": 10 + _h("onhand", pid, region) % 140, + "reserved": _h("reserved", pid, region) % 28, + "inbound": _h("inbound", pid, region) % 85, + }) + + orders = [] + for oid in range(N_ORDERS): + customer_id = _h("ocust", oid) % N_CUSTOMERS + product_id = _h("oprod", oid) % N_PRODUCTS + month = MONTHS[_h("month", oid) % len(MONTHS)] + qty = 1 + _h("qty", oid) % 9 + ship_days = 1 + _h("shipdays", oid) % 16 + promised_days = 3 + _h("promise", oid) % 9 + status = ["paid", "paid", "paid", "paid", "cancelled", "refunded"][ + _h("status", oid) % 6] + orders.append({ + "order_id": oid, + "customer_id": customer_id, + "product_id": product_id, + "month": month, + "qty": qty, + "status": status, + "channel": CHANNELS[_h("channel", oid) % len(CHANNELS)], + "ship_days": ship_days, + "promised_days": promised_days, + }) + + returns = [] + for rid in range(N_RETURNS): + oid = _h("roid", rid) % N_ORDERS + order = orders[oid] + if order["status"] == "cancelled": + continue + returned_qty = 1 + _h("rqty", rid) % max(1, order["qty"]) + reason = ["defect", "late", "changed_mind", "wrong_item"][_h("reason", rid) % 4] + returns.append({ + "return_id": rid, + "order_id": oid, + "month": MONTHS[_h("rmonth", rid) % len(MONTHS)], + "returned_qty": returned_qty, + "reason": reason, + }) + + tickets = [] + for tid in range(N_TICKETS): + oid = _h("toid", tid) % N_ORDERS + severity = ["low", "medium", "high", "critical"][_h("sev", tid) % 4] + opened = MONTHS[_h("tmonth", tid) % len(MONTHS)] + first_response_hours = 1 + _h("resp", tid) % 96 + resolution_hours = first_response_hours + _h("res", tid) % 240 + tickets.append({ + "ticket_id": tid, + "order_id": oid, + "opened_month": opened, + "severity": severity, + "first_response_hours": first_response_hours, + "resolution_hours": resolution_hours, + }) + + return { + "customers": customers, + "products": products, + "inventory": inventory, + "orders": orders, + "returns": returns, + "tickets": tickets, + "fx_to_usd_bp": FX_TO_USD_BP, + } + + +DATA = build_data() +CUSTOMERS = {c["customer_id"]: c for c in DATA["customers"]} +PRODUCTS = {p["product_id"]: p for p in DATA["products"]} +ORDERS = {o["order_id"]: o for o in DATA["orders"]} + + +def region_currency(region: str) -> str: + return CURRENCIES[region] + + +def get_orders(region: str, category: str, month_start: int, month_end: int) -> list: + """Paid/refunded order ids in a region/category/month window.""" + out = [] + for o in DATA["orders"]: + if o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + p = PRODUCTS[o["product_id"]] + if c["region"] == region and p["category"] == category and month_start <= o["month"] <= month_end: + out.append(o["order_id"]) + return sorted(out) + + +def order_gross_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * p["unit_price_usd"] + + +def order_margin_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * (p["unit_price_usd"] - p["unit_cogs_usd"]) + + +def refund_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + qty = sum(r["returned_qty"] for r in DATA["returns"] if r["order_id"] == order_id) + qty = min(qty, o["qty"]) + return qty * p["unit_price_usd"] + + +def customer_tier(order_id: int) -> str: + o = ORDERS[order_id] + return CUSTOMERS[o["customer_id"]]["tier"] + + +def apply_discount(amount_usd: int, tier: str) -> int: + return amount_usd * (100 - DISCOUNT_PCT[tier]) // 100 + + +def net_revenue_usd(order_id: int) -> int: + gross = apply_discount(order_gross_usd(order_id), customer_tier(order_id)) + return max(0, gross - refund_usd(order_id)) + + +def to_local(amount_usd: int, currency: str) -> int: + return amount_usd * 10000 // FX_TO_USD_BP[currency] + + +def inventory_position(product_id: int, region: str) -> int: + row = next(x for x in DATA["inventory"] + if x["product_id"] == product_id and x["region"] == region) + return row["on_hand"] - row["reserved"] + row["inbound"] + + +def product_lead_time(product_id: int) -> int: + return PRODUCTS[product_id]["lead_time_days"] + + +def product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int: + totals = {} + for oid in get_orders(region, category, month_start, month_end): + o = ORDERS[oid] + totals[o["product_id"]] = totals.get(o["product_id"], 0) + o["qty"] + if not totals: + return -1 + return min((-qty, pid) for pid, qty in totals.items())[1] + + +def units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int: + total = 0 + for o in DATA["orders"]: + if o["product_id"] != product_id or o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + if c["region"] == region and month_start <= o["month"] <= month_end: + total += o["qty"] + return total + + +def tickets_for_orders(order_ids: list, severity: str) -> list: + s = set(order_ids) + return sorted(t["ticket_id"] for t in DATA["tickets"] + if t["order_id"] in s and t["severity"] == severity) + + +def ticket_order_id(ticket_id: int) -> int: + return next(t["order_id"] for t in DATA["tickets"] if t["ticket_id"] == ticket_id) + + +def sla_breached(ticket_id: int, first_response_limit_hours: int, + resolution_limit_hours: int) -> bool: + t = next(x for x in DATA["tickets"] if x["ticket_id"] == ticket_id) + return (t["first_response_hours"] > first_response_limit_hours or + t["resolution_hours"] > resolution_limit_hours) + + +def delayed_orders(order_ids: list) -> list: + s = set(order_ids) + return sorted(o["order_id"] for o in DATA["orders"] + if o["order_id"] in s and o["ship_days"] > o["promised_days"]) + + +def unique_customers(order_ids: list) -> list: + return sorted({ORDERS[oid]["customer_id"] for oid in order_ids}) + + +def count_items(values: list) -> int: + return len(values) + + +def sum_values(values: list) -> int: + return sum(values) + + +def count_true(values: list) -> int: + return sum(1 for v in values if bool(v)) + + +def count_below(values: list, threshold: int) -> int: + return sum(1 for v in values if v < threshold) + + +TOOLS = { + "region_currency": ("region_currency(region: str) -> str", + "ISO currency code for a region.", region_currency), + "get_orders": ("get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]", + "Paid/refunded order ids for a region, product category, and inclusive month window.", + get_orders), + "order_gross_usd": ("order_gross_usd(order_id: int) -> int", + "Gross order revenue in USD before discounts/refunds.", order_gross_usd), + "order_margin_usd": ("order_margin_usd(order_id: int) -> int", + "Gross order margin in USD before discounts/refunds.", order_margin_usd), + "refund_usd": ("refund_usd(order_id: int) -> int", + "Refund amount in USD for returned quantity on an order.", refund_usd), + "customer_tier": ("customer_tier(order_id: int) -> str", + "Customer loyalty tier for an order.", customer_tier), + "apply_discount": ("apply_discount(amount_usd: int, tier: str) -> int", + "Apply the order customer's loyalty discount to a USD amount.", apply_discount), + "net_revenue_usd": ("net_revenue_usd(order_id: int) -> int", + "Net USD revenue after loyalty discount and refunds.", net_revenue_usd), + "to_local": ("to_local(amount_usd: int, currency: str) -> int", + "Convert a USD integer amount to a local-currency integer.", to_local), + "inventory_position": ("inventory_position(product_id: int, region: str) -> int", + "Available inventory position: on_hand - reserved + inbound.", + inventory_position), + "product_lead_time": ("product_lead_time(product_id: int) -> int", + "Supplier lead time in days for a product.", product_lead_time), + "product_id_for_top_seller": ( + "product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int", + "Product id with the highest units sold in a region/category/month window.", + product_id_for_top_seller), + "units_sold": ("units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int", + "Units sold for one product in a region and month window.", units_sold), + "tickets_for_orders": ("tickets_for_orders(order_ids: list[int], severity: str) -> list[int]", + "Support ticket ids for given orders and severity.", tickets_for_orders), + "ticket_order_id": ("ticket_order_id(ticket_id: int) -> int", + "Order id associated with a support ticket.", ticket_order_id), + "sla_breached": ( + "sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool", + "Whether a support ticket breaches first-response or resolution SLA.", + sla_breached), + "delayed_orders": ("delayed_orders(order_ids: list[int]) -> list[int]", + "Subset of order ids whose ship_days exceeded promised_days.", delayed_orders), + "unique_customers": ("unique_customers(order_ids: list[int]) -> list[int]", + "Unique customer ids among the given orders.", unique_customers), + "count_items": ("count_items(values: list) -> int", "Length of a list.", count_items), + "sum_values": ("sum_values(values: list[int]) -> int", "Sum a list of integers.", sum_values), + "count_true": ("count_true(values: list[bool]) -> int", "Count true values.", count_true), + "count_below": ("count_below(values: list[int], threshold: int) -> int", + "Count values below a threshold.", count_below), +} + +__all__ = [name for name in TOOLS.keys()] + ['TOOLS'] diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t12/environment/task.json b/harbor/tasks/v3_depth6_delay_sla_burden_t12/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..4ee05547791e843ba29b776802f5b90e39742047 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t12/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth6_delay_sla_burden_t12", + "depth": 6, + "family": "delay_sla_burden", + "params": { + "region": "NA", + "category": "C", + "month_start": 202601, + "month_end": 202606 + }, + "question": "For region NA, category C, months 202601-202606: get the orders, count delayed orders where ship_days exceeded promised_days, find high and critical support tickets for those orders, count tickets that breach a 24-hour first-response or 120-hour resolution SLA, and report delayed_order_count + breached_ticket_count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t12/instruction.md b/harbor/tasks/v3_depth6_delay_sla_burden_t12/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..ba54ffe50e4a35f970d336b067e68ccca3a52806 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t12/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For region NA, category C, months 202601-202606: get the orders, count delayed orders where ship_days exceeded promised_days, find high and critical support tickets for those orders, count tickets that breach a 24-hour first-response or 120-hour resolution SLA, and report delayed_order_count + breached_ticket_count. + +Available tools: +- `region_currency(region: str) -> str`: ISO currency code for a region. +- `get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]`: Paid/refunded order ids for a region, product category, and inclusive month window. +- `order_gross_usd(order_id: int) -> int`: Gross order revenue in USD before discounts/refunds. +- `order_margin_usd(order_id: int) -> int`: Gross order margin in USD before discounts/refunds. +- `refund_usd(order_id: int) -> int`: Refund amount in USD for returned quantity on an order. +- `customer_tier(order_id: int) -> str`: Customer loyalty tier for an order. +- `apply_discount(amount_usd: int, tier: str) -> int`: Apply the order customer's loyalty discount to a USD amount. +- `net_revenue_usd(order_id: int) -> int`: Net USD revenue after loyalty discount and refunds. +- `to_local(amount_usd: int, currency: str) -> int`: Convert a USD integer amount to a local-currency integer. +- `inventory_position(product_id: int, region: str) -> int`: Available inventory position: on_hand - reserved + inbound. +- `product_lead_time(product_id: int) -> int`: Supplier lead time in days for a product. +- `product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int`: Product id with the highest units sold in a region/category/month window. +- `units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int`: Units sold for one product in a region and month window. +- `tickets_for_orders(order_ids: list[int], severity: str) -> list[int]`: Support ticket ids for given orders and severity. +- `ticket_order_id(ticket_id: int) -> int`: Order id associated with a support ticket. +- `sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool`: Whether a support ticket breaches first-response or resolution SLA. +- `delayed_orders(order_ids: list[int]) -> list[int]`: Subset of order ids whose ship_days exceeded promised_days. +- `unique_customers(order_ids: list[int]) -> list[int]`: Unique customer ids among the given orders. +- `count_items(values: list) -> int`: Length of a list. +- `sum_values(values: list[int]) -> int`: Sum a list of integers. +- `count_true(values: list[bool]) -> int`: Count true values. +- `count_below(values: list[int], threshold: int) -> int`: Count values below a threshold. diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t12/task.toml b/harbor/tasks/v3_depth6_delay_sla_burden_t12/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..3eebc527f50494c2fa27477599b5678781b0ecfb --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t12/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth6_delay_sla_burden_t12" +description = "FlowBench v3 public task metadata. Public verifier is smoke-only." +authors = [{ name = "Mind Lab", email = "contact@mindlab.ltd" }] +keywords = ["flowbench", "tool-use", "data-orchestration", "operations"] + +[metadata] +benchmark = "FlowBench-v3" +split = "public-task-only" +category = "data-processing" +depth = 6 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +network_mode = "no-network" +build_timeout_sec = 600.0 +os = "linux" +cpus = 1 +memory_mb = 2048 +storage_mb = 2048 +gpus = 0 diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t12/tests/check_output_shape.py b/harbor/tasks/v3_depth6_delay_sla_burden_t12/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t12/tests/check_output_shape.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import json +import os +import re +from pathlib import Path + + +def write_reward(score: float, diagnostic: str) -> None: + log_dir = Path(os.environ.get("LOG_DIR", "/logs/verifier")) + log_dir.mkdir(parents=True, exist_ok=True) + (log_dir / "reward.txt").write_text(f"{score:.6g}\n") + (log_dir / "reward.json").write_text( + json.dumps({"reward": score, "smoke_only": True}, indent=2) + "\n" + ) + (log_dir / "diagnostic.txt").write_text(diagnostic + "\n") + + +def main() -> int: + app_dir = Path(os.environ.get("APP_DIR", "/app")) + task = json.loads((app_dir / "task.json").read_text()) + answer_path = app_dir / "answer.txt" + if not answer_path.exists(): + write_reward(0.0, "missing /app/answer.txt") + return 1 + + got = answer_path.read_text().strip() + if task["answer_format"] == "exact integer": + ok = bool(re.fullmatch(r"-?\d+", got)) + diagnostic = "valid integer smoke output" if ok else f"not an exact integer: {got!r}" + else: + ok = bool(re.fullmatch(r"[A-Za-z]+", got)) + diagnostic = "valid code smoke output" if ok else f"not an exact code: {got!r}" + + # This is intentionally not official scoring; it only verifies I/O shape. + write_reward(1.0 if ok else 0.0, diagnostic) + return 0 if ok else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t12/tests/test.sh b/harbor/tasks/v3_depth6_delay_sla_burden_t12/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t12/tests/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -u +python /tests/check_output_shape.py diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t13/environment/Dockerfile b/harbor/tasks/v3_depth6_delay_sla_burden_t13/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t13/environment/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.12-slim +WORKDIR /app +COPY flowbench_tools.py /app/flowbench_tools.py +COPY task.json /app/task.json diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t13/environment/flowbench_tools.py b/harbor/tasks/v3_depth6_delay_sla_burden_t13/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t13/environment/flowbench_tools.py @@ -0,0 +1,311 @@ +"""Deterministic FlowBench v3 tools. This file contains no task answers.""" + + +REGIONS = ["NA", "EU", "APAC", "LATAM"] +CATEGORIES = ["A", "B", "C", "D"] +CURRENCIES = {"NA": "USD", "EU": "EUR", "APAC": "JPY", "LATAM": "BRL"} +FX_TO_USD_BP = {"USD": 10000, "EUR": 10900, "JPY": 67, "BRL": 1850} +TIERS = ["std", "gold", "plat"] +DISCOUNT_PCT = {"std": 0, "gold": 10, "plat": 20} +CHANNELS = ["web", "store", "partner"] +MONTHS = [202601, 202602, 202603, 202604, 202605, 202606] + +N_CUSTOMERS = 72 +N_PRODUCTS = 48 +N_ORDERS = 720 +N_TICKETS = 260 +N_RETURNS = 180 + + +def _h(*xs): + import hashlib + s = "|".join(str(x) for x in xs).encode() + return int.from_bytes(hashlib.sha256(s).digest()[:8], "big") & 0x7FFFFFFF + + +def build_data(): + customers = [] + for cid in range(N_CUSTOMERS): + region = REGIONS[_h("region", cid) % len(REGIONS)] + customers.append({ + "customer_id": cid, + "region": region, + "tier": TIERS[_h("tier", cid) % len(TIERS)], + "segment": ["consumer", "smb", "enterprise"][_h("segment", cid) % 3], + }) + + products = [] + for pid in range(N_PRODUCTS): + cat = CATEGORIES[_h("cat", pid) % len(CATEGORIES)] + unit_price = 12 + _h("price", pid) % 240 + cogs = unit_price * (45 + _h("margin", pid) % 35) // 100 + products.append({ + "product_id": pid, + "category": cat, + "unit_price_usd": unit_price, + "unit_cogs_usd": cogs, + "lead_time_days": 3 + _h("lead", pid) % 18, + }) + + inventory = [] + for pid in range(N_PRODUCTS): + for region in REGIONS: + inventory.append({ + "product_id": pid, + "region": region, + "on_hand": 10 + _h("onhand", pid, region) % 140, + "reserved": _h("reserved", pid, region) % 28, + "inbound": _h("inbound", pid, region) % 85, + }) + + orders = [] + for oid in range(N_ORDERS): + customer_id = _h("ocust", oid) % N_CUSTOMERS + product_id = _h("oprod", oid) % N_PRODUCTS + month = MONTHS[_h("month", oid) % len(MONTHS)] + qty = 1 + _h("qty", oid) % 9 + ship_days = 1 + _h("shipdays", oid) % 16 + promised_days = 3 + _h("promise", oid) % 9 + status = ["paid", "paid", "paid", "paid", "cancelled", "refunded"][ + _h("status", oid) % 6] + orders.append({ + "order_id": oid, + "customer_id": customer_id, + "product_id": product_id, + "month": month, + "qty": qty, + "status": status, + "channel": CHANNELS[_h("channel", oid) % len(CHANNELS)], + "ship_days": ship_days, + "promised_days": promised_days, + }) + + returns = [] + for rid in range(N_RETURNS): + oid = _h("roid", rid) % N_ORDERS + order = orders[oid] + if order["status"] == "cancelled": + continue + returned_qty = 1 + _h("rqty", rid) % max(1, order["qty"]) + reason = ["defect", "late", "changed_mind", "wrong_item"][_h("reason", rid) % 4] + returns.append({ + "return_id": rid, + "order_id": oid, + "month": MONTHS[_h("rmonth", rid) % len(MONTHS)], + "returned_qty": returned_qty, + "reason": reason, + }) + + tickets = [] + for tid in range(N_TICKETS): + oid = _h("toid", tid) % N_ORDERS + severity = ["low", "medium", "high", "critical"][_h("sev", tid) % 4] + opened = MONTHS[_h("tmonth", tid) % len(MONTHS)] + first_response_hours = 1 + _h("resp", tid) % 96 + resolution_hours = first_response_hours + _h("res", tid) % 240 + tickets.append({ + "ticket_id": tid, + "order_id": oid, + "opened_month": opened, + "severity": severity, + "first_response_hours": first_response_hours, + "resolution_hours": resolution_hours, + }) + + return { + "customers": customers, + "products": products, + "inventory": inventory, + "orders": orders, + "returns": returns, + "tickets": tickets, + "fx_to_usd_bp": FX_TO_USD_BP, + } + + +DATA = build_data() +CUSTOMERS = {c["customer_id"]: c for c in DATA["customers"]} +PRODUCTS = {p["product_id"]: p for p in DATA["products"]} +ORDERS = {o["order_id"]: o for o in DATA["orders"]} + + +def region_currency(region: str) -> str: + return CURRENCIES[region] + + +def get_orders(region: str, category: str, month_start: int, month_end: int) -> list: + """Paid/refunded order ids in a region/category/month window.""" + out = [] + for o in DATA["orders"]: + if o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + p = PRODUCTS[o["product_id"]] + if c["region"] == region and p["category"] == category and month_start <= o["month"] <= month_end: + out.append(o["order_id"]) + return sorted(out) + + +def order_gross_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * p["unit_price_usd"] + + +def order_margin_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * (p["unit_price_usd"] - p["unit_cogs_usd"]) + + +def refund_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + qty = sum(r["returned_qty"] for r in DATA["returns"] if r["order_id"] == order_id) + qty = min(qty, o["qty"]) + return qty * p["unit_price_usd"] + + +def customer_tier(order_id: int) -> str: + o = ORDERS[order_id] + return CUSTOMERS[o["customer_id"]]["tier"] + + +def apply_discount(amount_usd: int, tier: str) -> int: + return amount_usd * (100 - DISCOUNT_PCT[tier]) // 100 + + +def net_revenue_usd(order_id: int) -> int: + gross = apply_discount(order_gross_usd(order_id), customer_tier(order_id)) + return max(0, gross - refund_usd(order_id)) + + +def to_local(amount_usd: int, currency: str) -> int: + return amount_usd * 10000 // FX_TO_USD_BP[currency] + + +def inventory_position(product_id: int, region: str) -> int: + row = next(x for x in DATA["inventory"] + if x["product_id"] == product_id and x["region"] == region) + return row["on_hand"] - row["reserved"] + row["inbound"] + + +def product_lead_time(product_id: int) -> int: + return PRODUCTS[product_id]["lead_time_days"] + + +def product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int: + totals = {} + for oid in get_orders(region, category, month_start, month_end): + o = ORDERS[oid] + totals[o["product_id"]] = totals.get(o["product_id"], 0) + o["qty"] + if not totals: + return -1 + return min((-qty, pid) for pid, qty in totals.items())[1] + + +def units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int: + total = 0 + for o in DATA["orders"]: + if o["product_id"] != product_id or o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + if c["region"] == region and month_start <= o["month"] <= month_end: + total += o["qty"] + return total + + +def tickets_for_orders(order_ids: list, severity: str) -> list: + s = set(order_ids) + return sorted(t["ticket_id"] for t in DATA["tickets"] + if t["order_id"] in s and t["severity"] == severity) + + +def ticket_order_id(ticket_id: int) -> int: + return next(t["order_id"] for t in DATA["tickets"] if t["ticket_id"] == ticket_id) + + +def sla_breached(ticket_id: int, first_response_limit_hours: int, + resolution_limit_hours: int) -> bool: + t = next(x for x in DATA["tickets"] if x["ticket_id"] == ticket_id) + return (t["first_response_hours"] > first_response_limit_hours or + t["resolution_hours"] > resolution_limit_hours) + + +def delayed_orders(order_ids: list) -> list: + s = set(order_ids) + return sorted(o["order_id"] for o in DATA["orders"] + if o["order_id"] in s and o["ship_days"] > o["promised_days"]) + + +def unique_customers(order_ids: list) -> list: + return sorted({ORDERS[oid]["customer_id"] for oid in order_ids}) + + +def count_items(values: list) -> int: + return len(values) + + +def sum_values(values: list) -> int: + return sum(values) + + +def count_true(values: list) -> int: + return sum(1 for v in values if bool(v)) + + +def count_below(values: list, threshold: int) -> int: + return sum(1 for v in values if v < threshold) + + +TOOLS = { + "region_currency": ("region_currency(region: str) -> str", + "ISO currency code for a region.", region_currency), + "get_orders": ("get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]", + "Paid/refunded order ids for a region, product category, and inclusive month window.", + get_orders), + "order_gross_usd": ("order_gross_usd(order_id: int) -> int", + "Gross order revenue in USD before discounts/refunds.", order_gross_usd), + "order_margin_usd": ("order_margin_usd(order_id: int) -> int", + "Gross order margin in USD before discounts/refunds.", order_margin_usd), + "refund_usd": ("refund_usd(order_id: int) -> int", + "Refund amount in USD for returned quantity on an order.", refund_usd), + "customer_tier": ("customer_tier(order_id: int) -> str", + "Customer loyalty tier for an order.", customer_tier), + "apply_discount": ("apply_discount(amount_usd: int, tier: str) -> int", + "Apply the order customer's loyalty discount to a USD amount.", apply_discount), + "net_revenue_usd": ("net_revenue_usd(order_id: int) -> int", + "Net USD revenue after loyalty discount and refunds.", net_revenue_usd), + "to_local": ("to_local(amount_usd: int, currency: str) -> int", + "Convert a USD integer amount to a local-currency integer.", to_local), + "inventory_position": ("inventory_position(product_id: int, region: str) -> int", + "Available inventory position: on_hand - reserved + inbound.", + inventory_position), + "product_lead_time": ("product_lead_time(product_id: int) -> int", + "Supplier lead time in days for a product.", product_lead_time), + "product_id_for_top_seller": ( + "product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int", + "Product id with the highest units sold in a region/category/month window.", + product_id_for_top_seller), + "units_sold": ("units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int", + "Units sold for one product in a region and month window.", units_sold), + "tickets_for_orders": ("tickets_for_orders(order_ids: list[int], severity: str) -> list[int]", + "Support ticket ids for given orders and severity.", tickets_for_orders), + "ticket_order_id": ("ticket_order_id(ticket_id: int) -> int", + "Order id associated with a support ticket.", ticket_order_id), + "sla_breached": ( + "sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool", + "Whether a support ticket breaches first-response or resolution SLA.", + sla_breached), + "delayed_orders": ("delayed_orders(order_ids: list[int]) -> list[int]", + "Subset of order ids whose ship_days exceeded promised_days.", delayed_orders), + "unique_customers": ("unique_customers(order_ids: list[int]) -> list[int]", + "Unique customer ids among the given orders.", unique_customers), + "count_items": ("count_items(values: list) -> int", "Length of a list.", count_items), + "sum_values": ("sum_values(values: list[int]) -> int", "Sum a list of integers.", sum_values), + "count_true": ("count_true(values: list[bool]) -> int", "Count true values.", count_true), + "count_below": ("count_below(values: list[int], threshold: int) -> int", + "Count values below a threshold.", count_below), +} + +__all__ = [name for name in TOOLS.keys()] + ['TOOLS'] diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t13/environment/task.json b/harbor/tasks/v3_depth6_delay_sla_burden_t13/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..0a8dccdaf3cce9b71b84a2443476b4fc0bba13df --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t13/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth6_delay_sla_burden_t13", + "depth": 6, + "family": "delay_sla_burden", + "params": { + "region": "EU", + "category": "B", + "month_start": 202601, + "month_end": 202603 + }, + "question": "For region EU, category B, months 202601-202603: get the orders, count delayed orders where ship_days exceeded promised_days, find high and critical support tickets for those orders, count tickets that breach a 24-hour first-response or 120-hour resolution SLA, and report delayed_order_count + breached_ticket_count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t13/instruction.md b/harbor/tasks/v3_depth6_delay_sla_burden_t13/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0daa4b6690491069d55ad0d93b8ced29ede640af --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t13/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For region EU, category B, months 202601-202603: get the orders, count delayed orders where ship_days exceeded promised_days, find high and critical support tickets for those orders, count tickets that breach a 24-hour first-response or 120-hour resolution SLA, and report delayed_order_count + breached_ticket_count. + +Available tools: +- `region_currency(region: str) -> str`: ISO currency code for a region. +- `get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]`: Paid/refunded order ids for a region, product category, and inclusive month window. +- `order_gross_usd(order_id: int) -> int`: Gross order revenue in USD before discounts/refunds. +- `order_margin_usd(order_id: int) -> int`: Gross order margin in USD before discounts/refunds. +- `refund_usd(order_id: int) -> int`: Refund amount in USD for returned quantity on an order. +- `customer_tier(order_id: int) -> str`: Customer loyalty tier for an order. +- `apply_discount(amount_usd: int, tier: str) -> int`: Apply the order customer's loyalty discount to a USD amount. +- `net_revenue_usd(order_id: int) -> int`: Net USD revenue after loyalty discount and refunds. +- `to_local(amount_usd: int, currency: str) -> int`: Convert a USD integer amount to a local-currency integer. +- `inventory_position(product_id: int, region: str) -> int`: Available inventory position: on_hand - reserved + inbound. +- `product_lead_time(product_id: int) -> int`: Supplier lead time in days for a product. +- `product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int`: Product id with the highest units sold in a region/category/month window. +- `units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int`: Units sold for one product in a region and month window. +- `tickets_for_orders(order_ids: list[int], severity: str) -> list[int]`: Support ticket ids for given orders and severity. +- `ticket_order_id(ticket_id: int) -> int`: Order id associated with a support ticket. +- `sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool`: Whether a support ticket breaches first-response or resolution SLA. +- `delayed_orders(order_ids: list[int]) -> list[int]`: Subset of order ids whose ship_days exceeded promised_days. +- `unique_customers(order_ids: list[int]) -> list[int]`: Unique customer ids among the given orders. +- `count_items(values: list) -> int`: Length of a list. +- `sum_values(values: list[int]) -> int`: Sum a list of integers. +- `count_true(values: list[bool]) -> int`: Count true values. +- `count_below(values: list[int], threshold: int) -> int`: Count values below a threshold. diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t13/task.toml b/harbor/tasks/v3_depth6_delay_sla_burden_t13/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..c69ff2c951d7371a664522bf100e0a25ddd9917b --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t13/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth6_delay_sla_burden_t13" +description = "FlowBench v3 public task metadata. Public verifier is smoke-only." +authors = [{ name = "Mind Lab", email = "contact@mindlab.ltd" }] +keywords = ["flowbench", "tool-use", "data-orchestration", "operations"] + +[metadata] +benchmark = "FlowBench-v3" +split = "public-task-only" +category = "data-processing" +depth = 6 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +network_mode = "no-network" +build_timeout_sec = 600.0 +os = "linux" +cpus = 1 +memory_mb = 2048 +storage_mb = 2048 +gpus = 0 diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t13/tests/check_output_shape.py b/harbor/tasks/v3_depth6_delay_sla_burden_t13/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t13/tests/check_output_shape.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import json +import os +import re +from pathlib import Path + + +def write_reward(score: float, diagnostic: str) -> None: + log_dir = Path(os.environ.get("LOG_DIR", "/logs/verifier")) + log_dir.mkdir(parents=True, exist_ok=True) + (log_dir / "reward.txt").write_text(f"{score:.6g}\n") + (log_dir / "reward.json").write_text( + json.dumps({"reward": score, "smoke_only": True}, indent=2) + "\n" + ) + (log_dir / "diagnostic.txt").write_text(diagnostic + "\n") + + +def main() -> int: + app_dir = Path(os.environ.get("APP_DIR", "/app")) + task = json.loads((app_dir / "task.json").read_text()) + answer_path = app_dir / "answer.txt" + if not answer_path.exists(): + write_reward(0.0, "missing /app/answer.txt") + return 1 + + got = answer_path.read_text().strip() + if task["answer_format"] == "exact integer": + ok = bool(re.fullmatch(r"-?\d+", got)) + diagnostic = "valid integer smoke output" if ok else f"not an exact integer: {got!r}" + else: + ok = bool(re.fullmatch(r"[A-Za-z]+", got)) + diagnostic = "valid code smoke output" if ok else f"not an exact code: {got!r}" + + # This is intentionally not official scoring; it only verifies I/O shape. + write_reward(1.0 if ok else 0.0, diagnostic) + return 0 if ok else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t13/tests/test.sh b/harbor/tasks/v3_depth6_delay_sla_burden_t13/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t13/tests/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -u +python /tests/check_output_shape.py diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t14/environment/Dockerfile b/harbor/tasks/v3_depth6_delay_sla_burden_t14/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t14/environment/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.12-slim +WORKDIR /app +COPY flowbench_tools.py /app/flowbench_tools.py +COPY task.json /app/task.json diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t14/environment/flowbench_tools.py b/harbor/tasks/v3_depth6_delay_sla_burden_t14/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t14/environment/flowbench_tools.py @@ -0,0 +1,311 @@ +"""Deterministic FlowBench v3 tools. This file contains no task answers.""" + + +REGIONS = ["NA", "EU", "APAC", "LATAM"] +CATEGORIES = ["A", "B", "C", "D"] +CURRENCIES = {"NA": "USD", "EU": "EUR", "APAC": "JPY", "LATAM": "BRL"} +FX_TO_USD_BP = {"USD": 10000, "EUR": 10900, "JPY": 67, "BRL": 1850} +TIERS = ["std", "gold", "plat"] +DISCOUNT_PCT = {"std": 0, "gold": 10, "plat": 20} +CHANNELS = ["web", "store", "partner"] +MONTHS = [202601, 202602, 202603, 202604, 202605, 202606] + +N_CUSTOMERS = 72 +N_PRODUCTS = 48 +N_ORDERS = 720 +N_TICKETS = 260 +N_RETURNS = 180 + + +def _h(*xs): + import hashlib + s = "|".join(str(x) for x in xs).encode() + return int.from_bytes(hashlib.sha256(s).digest()[:8], "big") & 0x7FFFFFFF + + +def build_data(): + customers = [] + for cid in range(N_CUSTOMERS): + region = REGIONS[_h("region", cid) % len(REGIONS)] + customers.append({ + "customer_id": cid, + "region": region, + "tier": TIERS[_h("tier", cid) % len(TIERS)], + "segment": ["consumer", "smb", "enterprise"][_h("segment", cid) % 3], + }) + + products = [] + for pid in range(N_PRODUCTS): + cat = CATEGORIES[_h("cat", pid) % len(CATEGORIES)] + unit_price = 12 + _h("price", pid) % 240 + cogs = unit_price * (45 + _h("margin", pid) % 35) // 100 + products.append({ + "product_id": pid, + "category": cat, + "unit_price_usd": unit_price, + "unit_cogs_usd": cogs, + "lead_time_days": 3 + _h("lead", pid) % 18, + }) + + inventory = [] + for pid in range(N_PRODUCTS): + for region in REGIONS: + inventory.append({ + "product_id": pid, + "region": region, + "on_hand": 10 + _h("onhand", pid, region) % 140, + "reserved": _h("reserved", pid, region) % 28, + "inbound": _h("inbound", pid, region) % 85, + }) + + orders = [] + for oid in range(N_ORDERS): + customer_id = _h("ocust", oid) % N_CUSTOMERS + product_id = _h("oprod", oid) % N_PRODUCTS + month = MONTHS[_h("month", oid) % len(MONTHS)] + qty = 1 + _h("qty", oid) % 9 + ship_days = 1 + _h("shipdays", oid) % 16 + promised_days = 3 + _h("promise", oid) % 9 + status = ["paid", "paid", "paid", "paid", "cancelled", "refunded"][ + _h("status", oid) % 6] + orders.append({ + "order_id": oid, + "customer_id": customer_id, + "product_id": product_id, + "month": month, + "qty": qty, + "status": status, + "channel": CHANNELS[_h("channel", oid) % len(CHANNELS)], + "ship_days": ship_days, + "promised_days": promised_days, + }) + + returns = [] + for rid in range(N_RETURNS): + oid = _h("roid", rid) % N_ORDERS + order = orders[oid] + if order["status"] == "cancelled": + continue + returned_qty = 1 + _h("rqty", rid) % max(1, order["qty"]) + reason = ["defect", "late", "changed_mind", "wrong_item"][_h("reason", rid) % 4] + returns.append({ + "return_id": rid, + "order_id": oid, + "month": MONTHS[_h("rmonth", rid) % len(MONTHS)], + "returned_qty": returned_qty, + "reason": reason, + }) + + tickets = [] + for tid in range(N_TICKETS): + oid = _h("toid", tid) % N_ORDERS + severity = ["low", "medium", "high", "critical"][_h("sev", tid) % 4] + opened = MONTHS[_h("tmonth", tid) % len(MONTHS)] + first_response_hours = 1 + _h("resp", tid) % 96 + resolution_hours = first_response_hours + _h("res", tid) % 240 + tickets.append({ + "ticket_id": tid, + "order_id": oid, + "opened_month": opened, + "severity": severity, + "first_response_hours": first_response_hours, + "resolution_hours": resolution_hours, + }) + + return { + "customers": customers, + "products": products, + "inventory": inventory, + "orders": orders, + "returns": returns, + "tickets": tickets, + "fx_to_usd_bp": FX_TO_USD_BP, + } + + +DATA = build_data() +CUSTOMERS = {c["customer_id"]: c for c in DATA["customers"]} +PRODUCTS = {p["product_id"]: p for p in DATA["products"]} +ORDERS = {o["order_id"]: o for o in DATA["orders"]} + + +def region_currency(region: str) -> str: + return CURRENCIES[region] + + +def get_orders(region: str, category: str, month_start: int, month_end: int) -> list: + """Paid/refunded order ids in a region/category/month window.""" + out = [] + for o in DATA["orders"]: + if o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + p = PRODUCTS[o["product_id"]] + if c["region"] == region and p["category"] == category and month_start <= o["month"] <= month_end: + out.append(o["order_id"]) + return sorted(out) + + +def order_gross_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * p["unit_price_usd"] + + +def order_margin_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * (p["unit_price_usd"] - p["unit_cogs_usd"]) + + +def refund_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + qty = sum(r["returned_qty"] for r in DATA["returns"] if r["order_id"] == order_id) + qty = min(qty, o["qty"]) + return qty * p["unit_price_usd"] + + +def customer_tier(order_id: int) -> str: + o = ORDERS[order_id] + return CUSTOMERS[o["customer_id"]]["tier"] + + +def apply_discount(amount_usd: int, tier: str) -> int: + return amount_usd * (100 - DISCOUNT_PCT[tier]) // 100 + + +def net_revenue_usd(order_id: int) -> int: + gross = apply_discount(order_gross_usd(order_id), customer_tier(order_id)) + return max(0, gross - refund_usd(order_id)) + + +def to_local(amount_usd: int, currency: str) -> int: + return amount_usd * 10000 // FX_TO_USD_BP[currency] + + +def inventory_position(product_id: int, region: str) -> int: + row = next(x for x in DATA["inventory"] + if x["product_id"] == product_id and x["region"] == region) + return row["on_hand"] - row["reserved"] + row["inbound"] + + +def product_lead_time(product_id: int) -> int: + return PRODUCTS[product_id]["lead_time_days"] + + +def product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int: + totals = {} + for oid in get_orders(region, category, month_start, month_end): + o = ORDERS[oid] + totals[o["product_id"]] = totals.get(o["product_id"], 0) + o["qty"] + if not totals: + return -1 + return min((-qty, pid) for pid, qty in totals.items())[1] + + +def units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int: + total = 0 + for o in DATA["orders"]: + if o["product_id"] != product_id or o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + if c["region"] == region and month_start <= o["month"] <= month_end: + total += o["qty"] + return total + + +def tickets_for_orders(order_ids: list, severity: str) -> list: + s = set(order_ids) + return sorted(t["ticket_id"] for t in DATA["tickets"] + if t["order_id"] in s and t["severity"] == severity) + + +def ticket_order_id(ticket_id: int) -> int: + return next(t["order_id"] for t in DATA["tickets"] if t["ticket_id"] == ticket_id) + + +def sla_breached(ticket_id: int, first_response_limit_hours: int, + resolution_limit_hours: int) -> bool: + t = next(x for x in DATA["tickets"] if x["ticket_id"] == ticket_id) + return (t["first_response_hours"] > first_response_limit_hours or + t["resolution_hours"] > resolution_limit_hours) + + +def delayed_orders(order_ids: list) -> list: + s = set(order_ids) + return sorted(o["order_id"] for o in DATA["orders"] + if o["order_id"] in s and o["ship_days"] > o["promised_days"]) + + +def unique_customers(order_ids: list) -> list: + return sorted({ORDERS[oid]["customer_id"] for oid in order_ids}) + + +def count_items(values: list) -> int: + return len(values) + + +def sum_values(values: list) -> int: + return sum(values) + + +def count_true(values: list) -> int: + return sum(1 for v in values if bool(v)) + + +def count_below(values: list, threshold: int) -> int: + return sum(1 for v in values if v < threshold) + + +TOOLS = { + "region_currency": ("region_currency(region: str) -> str", + "ISO currency code for a region.", region_currency), + "get_orders": ("get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]", + "Paid/refunded order ids for a region, product category, and inclusive month window.", + get_orders), + "order_gross_usd": ("order_gross_usd(order_id: int) -> int", + "Gross order revenue in USD before discounts/refunds.", order_gross_usd), + "order_margin_usd": ("order_margin_usd(order_id: int) -> int", + "Gross order margin in USD before discounts/refunds.", order_margin_usd), + "refund_usd": ("refund_usd(order_id: int) -> int", + "Refund amount in USD for returned quantity on an order.", refund_usd), + "customer_tier": ("customer_tier(order_id: int) -> str", + "Customer loyalty tier for an order.", customer_tier), + "apply_discount": ("apply_discount(amount_usd: int, tier: str) -> int", + "Apply the order customer's loyalty discount to a USD amount.", apply_discount), + "net_revenue_usd": ("net_revenue_usd(order_id: int) -> int", + "Net USD revenue after loyalty discount and refunds.", net_revenue_usd), + "to_local": ("to_local(amount_usd: int, currency: str) -> int", + "Convert a USD integer amount to a local-currency integer.", to_local), + "inventory_position": ("inventory_position(product_id: int, region: str) -> int", + "Available inventory position: on_hand - reserved + inbound.", + inventory_position), + "product_lead_time": ("product_lead_time(product_id: int) -> int", + "Supplier lead time in days for a product.", product_lead_time), + "product_id_for_top_seller": ( + "product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int", + "Product id with the highest units sold in a region/category/month window.", + product_id_for_top_seller), + "units_sold": ("units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int", + "Units sold for one product in a region and month window.", units_sold), + "tickets_for_orders": ("tickets_for_orders(order_ids: list[int], severity: str) -> list[int]", + "Support ticket ids for given orders and severity.", tickets_for_orders), + "ticket_order_id": ("ticket_order_id(ticket_id: int) -> int", + "Order id associated with a support ticket.", ticket_order_id), + "sla_breached": ( + "sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool", + "Whether a support ticket breaches first-response or resolution SLA.", + sla_breached), + "delayed_orders": ("delayed_orders(order_ids: list[int]) -> list[int]", + "Subset of order ids whose ship_days exceeded promised_days.", delayed_orders), + "unique_customers": ("unique_customers(order_ids: list[int]) -> list[int]", + "Unique customer ids among the given orders.", unique_customers), + "count_items": ("count_items(values: list) -> int", "Length of a list.", count_items), + "sum_values": ("sum_values(values: list[int]) -> int", "Sum a list of integers.", sum_values), + "count_true": ("count_true(values: list[bool]) -> int", "Count true values.", count_true), + "count_below": ("count_below(values: list[int], threshold: int) -> int", + "Count values below a threshold.", count_below), +} + +__all__ = [name for name in TOOLS.keys()] + ['TOOLS'] diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t14/environment/task.json b/harbor/tasks/v3_depth6_delay_sla_burden_t14/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..e705d344d3370a6af072170143a685e3eccac88a --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t14/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth6_delay_sla_burden_t14", + "depth": 6, + "family": "delay_sla_burden", + "params": { + "region": "APAC", + "category": "C", + "month_start": 202602, + "month_end": 202606 + }, + "question": "For region APAC, category C, months 202602-202606: get the orders, count delayed orders where ship_days exceeded promised_days, find high and critical support tickets for those orders, count tickets that breach a 24-hour first-response or 120-hour resolution SLA, and report delayed_order_count + breached_ticket_count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t14/instruction.md b/harbor/tasks/v3_depth6_delay_sla_burden_t14/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..e6770aaff8cb2e9338d60f12167e6e416935f214 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t14/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For region APAC, category C, months 202602-202606: get the orders, count delayed orders where ship_days exceeded promised_days, find high and critical support tickets for those orders, count tickets that breach a 24-hour first-response or 120-hour resolution SLA, and report delayed_order_count + breached_ticket_count. + +Available tools: +- `region_currency(region: str) -> str`: ISO currency code for a region. +- `get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]`: Paid/refunded order ids for a region, product category, and inclusive month window. +- `order_gross_usd(order_id: int) -> int`: Gross order revenue in USD before discounts/refunds. +- `order_margin_usd(order_id: int) -> int`: Gross order margin in USD before discounts/refunds. +- `refund_usd(order_id: int) -> int`: Refund amount in USD for returned quantity on an order. +- `customer_tier(order_id: int) -> str`: Customer loyalty tier for an order. +- `apply_discount(amount_usd: int, tier: str) -> int`: Apply the order customer's loyalty discount to a USD amount. +- `net_revenue_usd(order_id: int) -> int`: Net USD revenue after loyalty discount and refunds. +- `to_local(amount_usd: int, currency: str) -> int`: Convert a USD integer amount to a local-currency integer. +- `inventory_position(product_id: int, region: str) -> int`: Available inventory position: on_hand - reserved + inbound. +- `product_lead_time(product_id: int) -> int`: Supplier lead time in days for a product. +- `product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int`: Product id with the highest units sold in a region/category/month window. +- `units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int`: Units sold for one product in a region and month window. +- `tickets_for_orders(order_ids: list[int], severity: str) -> list[int]`: Support ticket ids for given orders and severity. +- `ticket_order_id(ticket_id: int) -> int`: Order id associated with a support ticket. +- `sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool`: Whether a support ticket breaches first-response or resolution SLA. +- `delayed_orders(order_ids: list[int]) -> list[int]`: Subset of order ids whose ship_days exceeded promised_days. +- `unique_customers(order_ids: list[int]) -> list[int]`: Unique customer ids among the given orders. +- `count_items(values: list) -> int`: Length of a list. +- `sum_values(values: list[int]) -> int`: Sum a list of integers. +- `count_true(values: list[bool]) -> int`: Count true values. +- `count_below(values: list[int], threshold: int) -> int`: Count values below a threshold. diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t14/task.toml b/harbor/tasks/v3_depth6_delay_sla_burden_t14/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..71ce11e1ef3abce4a2a50a57a95df69311e301d2 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t14/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth6_delay_sla_burden_t14" +description = "FlowBench v3 public task metadata. Public verifier is smoke-only." +authors = [{ name = "Mind Lab", email = "contact@mindlab.ltd" }] +keywords = ["flowbench", "tool-use", "data-orchestration", "operations"] + +[metadata] +benchmark = "FlowBench-v3" +split = "public-task-only" +category = "data-processing" +depth = 6 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +network_mode = "no-network" +build_timeout_sec = 600.0 +os = "linux" +cpus = 1 +memory_mb = 2048 +storage_mb = 2048 +gpus = 0 diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t14/tests/check_output_shape.py b/harbor/tasks/v3_depth6_delay_sla_burden_t14/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t14/tests/check_output_shape.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import json +import os +import re +from pathlib import Path + + +def write_reward(score: float, diagnostic: str) -> None: + log_dir = Path(os.environ.get("LOG_DIR", "/logs/verifier")) + log_dir.mkdir(parents=True, exist_ok=True) + (log_dir / "reward.txt").write_text(f"{score:.6g}\n") + (log_dir / "reward.json").write_text( + json.dumps({"reward": score, "smoke_only": True}, indent=2) + "\n" + ) + (log_dir / "diagnostic.txt").write_text(diagnostic + "\n") + + +def main() -> int: + app_dir = Path(os.environ.get("APP_DIR", "/app")) + task = json.loads((app_dir / "task.json").read_text()) + answer_path = app_dir / "answer.txt" + if not answer_path.exists(): + write_reward(0.0, "missing /app/answer.txt") + return 1 + + got = answer_path.read_text().strip() + if task["answer_format"] == "exact integer": + ok = bool(re.fullmatch(r"-?\d+", got)) + diagnostic = "valid integer smoke output" if ok else f"not an exact integer: {got!r}" + else: + ok = bool(re.fullmatch(r"[A-Za-z]+", got)) + diagnostic = "valid code smoke output" if ok else f"not an exact code: {got!r}" + + # This is intentionally not official scoring; it only verifies I/O shape. + write_reward(1.0 if ok else 0.0, diagnostic) + return 0 if ok else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t14/tests/test.sh b/harbor/tasks/v3_depth6_delay_sla_burden_t14/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t14/tests/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -u +python /tests/check_output_shape.py diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t15/environment/Dockerfile b/harbor/tasks/v3_depth6_delay_sla_burden_t15/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t15/environment/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.12-slim +WORKDIR /app +COPY flowbench_tools.py /app/flowbench_tools.py +COPY task.json /app/task.json diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t15/environment/flowbench_tools.py b/harbor/tasks/v3_depth6_delay_sla_burden_t15/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t15/environment/flowbench_tools.py @@ -0,0 +1,311 @@ +"""Deterministic FlowBench v3 tools. This file contains no task answers.""" + + +REGIONS = ["NA", "EU", "APAC", "LATAM"] +CATEGORIES = ["A", "B", "C", "D"] +CURRENCIES = {"NA": "USD", "EU": "EUR", "APAC": "JPY", "LATAM": "BRL"} +FX_TO_USD_BP = {"USD": 10000, "EUR": 10900, "JPY": 67, "BRL": 1850} +TIERS = ["std", "gold", "plat"] +DISCOUNT_PCT = {"std": 0, "gold": 10, "plat": 20} +CHANNELS = ["web", "store", "partner"] +MONTHS = [202601, 202602, 202603, 202604, 202605, 202606] + +N_CUSTOMERS = 72 +N_PRODUCTS = 48 +N_ORDERS = 720 +N_TICKETS = 260 +N_RETURNS = 180 + + +def _h(*xs): + import hashlib + s = "|".join(str(x) for x in xs).encode() + return int.from_bytes(hashlib.sha256(s).digest()[:8], "big") & 0x7FFFFFFF + + +def build_data(): + customers = [] + for cid in range(N_CUSTOMERS): + region = REGIONS[_h("region", cid) % len(REGIONS)] + customers.append({ + "customer_id": cid, + "region": region, + "tier": TIERS[_h("tier", cid) % len(TIERS)], + "segment": ["consumer", "smb", "enterprise"][_h("segment", cid) % 3], + }) + + products = [] + for pid in range(N_PRODUCTS): + cat = CATEGORIES[_h("cat", pid) % len(CATEGORIES)] + unit_price = 12 + _h("price", pid) % 240 + cogs = unit_price * (45 + _h("margin", pid) % 35) // 100 + products.append({ + "product_id": pid, + "category": cat, + "unit_price_usd": unit_price, + "unit_cogs_usd": cogs, + "lead_time_days": 3 + _h("lead", pid) % 18, + }) + + inventory = [] + for pid in range(N_PRODUCTS): + for region in REGIONS: + inventory.append({ + "product_id": pid, + "region": region, + "on_hand": 10 + _h("onhand", pid, region) % 140, + "reserved": _h("reserved", pid, region) % 28, + "inbound": _h("inbound", pid, region) % 85, + }) + + orders = [] + for oid in range(N_ORDERS): + customer_id = _h("ocust", oid) % N_CUSTOMERS + product_id = _h("oprod", oid) % N_PRODUCTS + month = MONTHS[_h("month", oid) % len(MONTHS)] + qty = 1 + _h("qty", oid) % 9 + ship_days = 1 + _h("shipdays", oid) % 16 + promised_days = 3 + _h("promise", oid) % 9 + status = ["paid", "paid", "paid", "paid", "cancelled", "refunded"][ + _h("status", oid) % 6] + orders.append({ + "order_id": oid, + "customer_id": customer_id, + "product_id": product_id, + "month": month, + "qty": qty, + "status": status, + "channel": CHANNELS[_h("channel", oid) % len(CHANNELS)], + "ship_days": ship_days, + "promised_days": promised_days, + }) + + returns = [] + for rid in range(N_RETURNS): + oid = _h("roid", rid) % N_ORDERS + order = orders[oid] + if order["status"] == "cancelled": + continue + returned_qty = 1 + _h("rqty", rid) % max(1, order["qty"]) + reason = ["defect", "late", "changed_mind", "wrong_item"][_h("reason", rid) % 4] + returns.append({ + "return_id": rid, + "order_id": oid, + "month": MONTHS[_h("rmonth", rid) % len(MONTHS)], + "returned_qty": returned_qty, + "reason": reason, + }) + + tickets = [] + for tid in range(N_TICKETS): + oid = _h("toid", tid) % N_ORDERS + severity = ["low", "medium", "high", "critical"][_h("sev", tid) % 4] + opened = MONTHS[_h("tmonth", tid) % len(MONTHS)] + first_response_hours = 1 + _h("resp", tid) % 96 + resolution_hours = first_response_hours + _h("res", tid) % 240 + tickets.append({ + "ticket_id": tid, + "order_id": oid, + "opened_month": opened, + "severity": severity, + "first_response_hours": first_response_hours, + "resolution_hours": resolution_hours, + }) + + return { + "customers": customers, + "products": products, + "inventory": inventory, + "orders": orders, + "returns": returns, + "tickets": tickets, + "fx_to_usd_bp": FX_TO_USD_BP, + } + + +DATA = build_data() +CUSTOMERS = {c["customer_id"]: c for c in DATA["customers"]} +PRODUCTS = {p["product_id"]: p for p in DATA["products"]} +ORDERS = {o["order_id"]: o for o in DATA["orders"]} + + +def region_currency(region: str) -> str: + return CURRENCIES[region] + + +def get_orders(region: str, category: str, month_start: int, month_end: int) -> list: + """Paid/refunded order ids in a region/category/month window.""" + out = [] + for o in DATA["orders"]: + if o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + p = PRODUCTS[o["product_id"]] + if c["region"] == region and p["category"] == category and month_start <= o["month"] <= month_end: + out.append(o["order_id"]) + return sorted(out) + + +def order_gross_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * p["unit_price_usd"] + + +def order_margin_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * (p["unit_price_usd"] - p["unit_cogs_usd"]) + + +def refund_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + qty = sum(r["returned_qty"] for r in DATA["returns"] if r["order_id"] == order_id) + qty = min(qty, o["qty"]) + return qty * p["unit_price_usd"] + + +def customer_tier(order_id: int) -> str: + o = ORDERS[order_id] + return CUSTOMERS[o["customer_id"]]["tier"] + + +def apply_discount(amount_usd: int, tier: str) -> int: + return amount_usd * (100 - DISCOUNT_PCT[tier]) // 100 + + +def net_revenue_usd(order_id: int) -> int: + gross = apply_discount(order_gross_usd(order_id), customer_tier(order_id)) + return max(0, gross - refund_usd(order_id)) + + +def to_local(amount_usd: int, currency: str) -> int: + return amount_usd * 10000 // FX_TO_USD_BP[currency] + + +def inventory_position(product_id: int, region: str) -> int: + row = next(x for x in DATA["inventory"] + if x["product_id"] == product_id and x["region"] == region) + return row["on_hand"] - row["reserved"] + row["inbound"] + + +def product_lead_time(product_id: int) -> int: + return PRODUCTS[product_id]["lead_time_days"] + + +def product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int: + totals = {} + for oid in get_orders(region, category, month_start, month_end): + o = ORDERS[oid] + totals[o["product_id"]] = totals.get(o["product_id"], 0) + o["qty"] + if not totals: + return -1 + return min((-qty, pid) for pid, qty in totals.items())[1] + + +def units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int: + total = 0 + for o in DATA["orders"]: + if o["product_id"] != product_id or o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + if c["region"] == region and month_start <= o["month"] <= month_end: + total += o["qty"] + return total + + +def tickets_for_orders(order_ids: list, severity: str) -> list: + s = set(order_ids) + return sorted(t["ticket_id"] for t in DATA["tickets"] + if t["order_id"] in s and t["severity"] == severity) + + +def ticket_order_id(ticket_id: int) -> int: + return next(t["order_id"] for t in DATA["tickets"] if t["ticket_id"] == ticket_id) + + +def sla_breached(ticket_id: int, first_response_limit_hours: int, + resolution_limit_hours: int) -> bool: + t = next(x for x in DATA["tickets"] if x["ticket_id"] == ticket_id) + return (t["first_response_hours"] > first_response_limit_hours or + t["resolution_hours"] > resolution_limit_hours) + + +def delayed_orders(order_ids: list) -> list: + s = set(order_ids) + return sorted(o["order_id"] for o in DATA["orders"] + if o["order_id"] in s and o["ship_days"] > o["promised_days"]) + + +def unique_customers(order_ids: list) -> list: + return sorted({ORDERS[oid]["customer_id"] for oid in order_ids}) + + +def count_items(values: list) -> int: + return len(values) + + +def sum_values(values: list) -> int: + return sum(values) + + +def count_true(values: list) -> int: + return sum(1 for v in values if bool(v)) + + +def count_below(values: list, threshold: int) -> int: + return sum(1 for v in values if v < threshold) + + +TOOLS = { + "region_currency": ("region_currency(region: str) -> str", + "ISO currency code for a region.", region_currency), + "get_orders": ("get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]", + "Paid/refunded order ids for a region, product category, and inclusive month window.", + get_orders), + "order_gross_usd": ("order_gross_usd(order_id: int) -> int", + "Gross order revenue in USD before discounts/refunds.", order_gross_usd), + "order_margin_usd": ("order_margin_usd(order_id: int) -> int", + "Gross order margin in USD before discounts/refunds.", order_margin_usd), + "refund_usd": ("refund_usd(order_id: int) -> int", + "Refund amount in USD for returned quantity on an order.", refund_usd), + "customer_tier": ("customer_tier(order_id: int) -> str", + "Customer loyalty tier for an order.", customer_tier), + "apply_discount": ("apply_discount(amount_usd: int, tier: str) -> int", + "Apply the order customer's loyalty discount to a USD amount.", apply_discount), + "net_revenue_usd": ("net_revenue_usd(order_id: int) -> int", + "Net USD revenue after loyalty discount and refunds.", net_revenue_usd), + "to_local": ("to_local(amount_usd: int, currency: str) -> int", + "Convert a USD integer amount to a local-currency integer.", to_local), + "inventory_position": ("inventory_position(product_id: int, region: str) -> int", + "Available inventory position: on_hand - reserved + inbound.", + inventory_position), + "product_lead_time": ("product_lead_time(product_id: int) -> int", + "Supplier lead time in days for a product.", product_lead_time), + "product_id_for_top_seller": ( + "product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int", + "Product id with the highest units sold in a region/category/month window.", + product_id_for_top_seller), + "units_sold": ("units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int", + "Units sold for one product in a region and month window.", units_sold), + "tickets_for_orders": ("tickets_for_orders(order_ids: list[int], severity: str) -> list[int]", + "Support ticket ids for given orders and severity.", tickets_for_orders), + "ticket_order_id": ("ticket_order_id(ticket_id: int) -> int", + "Order id associated with a support ticket.", ticket_order_id), + "sla_breached": ( + "sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool", + "Whether a support ticket breaches first-response or resolution SLA.", + sla_breached), + "delayed_orders": ("delayed_orders(order_ids: list[int]) -> list[int]", + "Subset of order ids whose ship_days exceeded promised_days.", delayed_orders), + "unique_customers": ("unique_customers(order_ids: list[int]) -> list[int]", + "Unique customer ids among the given orders.", unique_customers), + "count_items": ("count_items(values: list) -> int", "Length of a list.", count_items), + "sum_values": ("sum_values(values: list[int]) -> int", "Sum a list of integers.", sum_values), + "count_true": ("count_true(values: list[bool]) -> int", "Count true values.", count_true), + "count_below": ("count_below(values: list[int], threshold: int) -> int", + "Count values below a threshold.", count_below), +} + +__all__ = [name for name in TOOLS.keys()] + ['TOOLS'] diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t15/environment/task.json b/harbor/tasks/v3_depth6_delay_sla_burden_t15/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..6af6acd0c89666d9c1fca8858972ef6aa21e94c6 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t15/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth6_delay_sla_burden_t15", + "depth": 6, + "family": "delay_sla_burden", + "params": { + "region": "LATAM", + "category": "D", + "month_start": 202601, + "month_end": 202605 + }, + "question": "For region LATAM, category D, months 202601-202605: get the orders, count delayed orders where ship_days exceeded promised_days, find high and critical support tickets for those orders, count tickets that breach a 24-hour first-response or 120-hour resolution SLA, and report delayed_order_count + breached_ticket_count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t15/instruction.md b/harbor/tasks/v3_depth6_delay_sla_burden_t15/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..84ede1dbcd23ccbab6cd8032101b88bf5f376b96 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t15/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For region LATAM, category D, months 202601-202605: get the orders, count delayed orders where ship_days exceeded promised_days, find high and critical support tickets for those orders, count tickets that breach a 24-hour first-response or 120-hour resolution SLA, and report delayed_order_count + breached_ticket_count. + +Available tools: +- `region_currency(region: str) -> str`: ISO currency code for a region. +- `get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]`: Paid/refunded order ids for a region, product category, and inclusive month window. +- `order_gross_usd(order_id: int) -> int`: Gross order revenue in USD before discounts/refunds. +- `order_margin_usd(order_id: int) -> int`: Gross order margin in USD before discounts/refunds. +- `refund_usd(order_id: int) -> int`: Refund amount in USD for returned quantity on an order. +- `customer_tier(order_id: int) -> str`: Customer loyalty tier for an order. +- `apply_discount(amount_usd: int, tier: str) -> int`: Apply the order customer's loyalty discount to a USD amount. +- `net_revenue_usd(order_id: int) -> int`: Net USD revenue after loyalty discount and refunds. +- `to_local(amount_usd: int, currency: str) -> int`: Convert a USD integer amount to a local-currency integer. +- `inventory_position(product_id: int, region: str) -> int`: Available inventory position: on_hand - reserved + inbound. +- `product_lead_time(product_id: int) -> int`: Supplier lead time in days for a product. +- `product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int`: Product id with the highest units sold in a region/category/month window. +- `units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int`: Units sold for one product in a region and month window. +- `tickets_for_orders(order_ids: list[int], severity: str) -> list[int]`: Support ticket ids for given orders and severity. +- `ticket_order_id(ticket_id: int) -> int`: Order id associated with a support ticket. +- `sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool`: Whether a support ticket breaches first-response or resolution SLA. +- `delayed_orders(order_ids: list[int]) -> list[int]`: Subset of order ids whose ship_days exceeded promised_days. +- `unique_customers(order_ids: list[int]) -> list[int]`: Unique customer ids among the given orders. +- `count_items(values: list) -> int`: Length of a list. +- `sum_values(values: list[int]) -> int`: Sum a list of integers. +- `count_true(values: list[bool]) -> int`: Count true values. +- `count_below(values: list[int], threshold: int) -> int`: Count values below a threshold. diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t15/task.toml b/harbor/tasks/v3_depth6_delay_sla_burden_t15/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..d6c72d33a784216d731ea906512096ba68f1c35a --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t15/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth6_delay_sla_burden_t15" +description = "FlowBench v3 public task metadata. Public verifier is smoke-only." +authors = [{ name = "Mind Lab", email = "contact@mindlab.ltd" }] +keywords = ["flowbench", "tool-use", "data-orchestration", "operations"] + +[metadata] +benchmark = "FlowBench-v3" +split = "public-task-only" +category = "data-processing" +depth = 6 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +network_mode = "no-network" +build_timeout_sec = 600.0 +os = "linux" +cpus = 1 +memory_mb = 2048 +storage_mb = 2048 +gpus = 0 diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t15/tests/check_output_shape.py b/harbor/tasks/v3_depth6_delay_sla_burden_t15/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t15/tests/check_output_shape.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import json +import os +import re +from pathlib import Path + + +def write_reward(score: float, diagnostic: str) -> None: + log_dir = Path(os.environ.get("LOG_DIR", "/logs/verifier")) + log_dir.mkdir(parents=True, exist_ok=True) + (log_dir / "reward.txt").write_text(f"{score:.6g}\n") + (log_dir / "reward.json").write_text( + json.dumps({"reward": score, "smoke_only": True}, indent=2) + "\n" + ) + (log_dir / "diagnostic.txt").write_text(diagnostic + "\n") + + +def main() -> int: + app_dir = Path(os.environ.get("APP_DIR", "/app")) + task = json.loads((app_dir / "task.json").read_text()) + answer_path = app_dir / "answer.txt" + if not answer_path.exists(): + write_reward(0.0, "missing /app/answer.txt") + return 1 + + got = answer_path.read_text().strip() + if task["answer_format"] == "exact integer": + ok = bool(re.fullmatch(r"-?\d+", got)) + diagnostic = "valid integer smoke output" if ok else f"not an exact integer: {got!r}" + else: + ok = bool(re.fullmatch(r"[A-Za-z]+", got)) + diagnostic = "valid code smoke output" if ok else f"not an exact code: {got!r}" + + # This is intentionally not official scoring; it only verifies I/O shape. + write_reward(1.0 if ok else 0.0, diagnostic) + return 0 if ok else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t15/tests/test.sh b/harbor/tasks/v3_depth6_delay_sla_burden_t15/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t15/tests/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -u +python /tests/check_output_shape.py diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t16/environment/Dockerfile b/harbor/tasks/v3_depth6_delay_sla_burden_t16/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t16/environment/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.12-slim +WORKDIR /app +COPY flowbench_tools.py /app/flowbench_tools.py +COPY task.json /app/task.json diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t16/environment/flowbench_tools.py b/harbor/tasks/v3_depth6_delay_sla_burden_t16/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t16/environment/flowbench_tools.py @@ -0,0 +1,311 @@ +"""Deterministic FlowBench v3 tools. This file contains no task answers.""" + + +REGIONS = ["NA", "EU", "APAC", "LATAM"] +CATEGORIES = ["A", "B", "C", "D"] +CURRENCIES = {"NA": "USD", "EU": "EUR", "APAC": "JPY", "LATAM": "BRL"} +FX_TO_USD_BP = {"USD": 10000, "EUR": 10900, "JPY": 67, "BRL": 1850} +TIERS = ["std", "gold", "plat"] +DISCOUNT_PCT = {"std": 0, "gold": 10, "plat": 20} +CHANNELS = ["web", "store", "partner"] +MONTHS = [202601, 202602, 202603, 202604, 202605, 202606] + +N_CUSTOMERS = 72 +N_PRODUCTS = 48 +N_ORDERS = 720 +N_TICKETS = 260 +N_RETURNS = 180 + + +def _h(*xs): + import hashlib + s = "|".join(str(x) for x in xs).encode() + return int.from_bytes(hashlib.sha256(s).digest()[:8], "big") & 0x7FFFFFFF + + +def build_data(): + customers = [] + for cid in range(N_CUSTOMERS): + region = REGIONS[_h("region", cid) % len(REGIONS)] + customers.append({ + "customer_id": cid, + "region": region, + "tier": TIERS[_h("tier", cid) % len(TIERS)], + "segment": ["consumer", "smb", "enterprise"][_h("segment", cid) % 3], + }) + + products = [] + for pid in range(N_PRODUCTS): + cat = CATEGORIES[_h("cat", pid) % len(CATEGORIES)] + unit_price = 12 + _h("price", pid) % 240 + cogs = unit_price * (45 + _h("margin", pid) % 35) // 100 + products.append({ + "product_id": pid, + "category": cat, + "unit_price_usd": unit_price, + "unit_cogs_usd": cogs, + "lead_time_days": 3 + _h("lead", pid) % 18, + }) + + inventory = [] + for pid in range(N_PRODUCTS): + for region in REGIONS: + inventory.append({ + "product_id": pid, + "region": region, + "on_hand": 10 + _h("onhand", pid, region) % 140, + "reserved": _h("reserved", pid, region) % 28, + "inbound": _h("inbound", pid, region) % 85, + }) + + orders = [] + for oid in range(N_ORDERS): + customer_id = _h("ocust", oid) % N_CUSTOMERS + product_id = _h("oprod", oid) % N_PRODUCTS + month = MONTHS[_h("month", oid) % len(MONTHS)] + qty = 1 + _h("qty", oid) % 9 + ship_days = 1 + _h("shipdays", oid) % 16 + promised_days = 3 + _h("promise", oid) % 9 + status = ["paid", "paid", "paid", "paid", "cancelled", "refunded"][ + _h("status", oid) % 6] + orders.append({ + "order_id": oid, + "customer_id": customer_id, + "product_id": product_id, + "month": month, + "qty": qty, + "status": status, + "channel": CHANNELS[_h("channel", oid) % len(CHANNELS)], + "ship_days": ship_days, + "promised_days": promised_days, + }) + + returns = [] + for rid in range(N_RETURNS): + oid = _h("roid", rid) % N_ORDERS + order = orders[oid] + if order["status"] == "cancelled": + continue + returned_qty = 1 + _h("rqty", rid) % max(1, order["qty"]) + reason = ["defect", "late", "changed_mind", "wrong_item"][_h("reason", rid) % 4] + returns.append({ + "return_id": rid, + "order_id": oid, + "month": MONTHS[_h("rmonth", rid) % len(MONTHS)], + "returned_qty": returned_qty, + "reason": reason, + }) + + tickets = [] + for tid in range(N_TICKETS): + oid = _h("toid", tid) % N_ORDERS + severity = ["low", "medium", "high", "critical"][_h("sev", tid) % 4] + opened = MONTHS[_h("tmonth", tid) % len(MONTHS)] + first_response_hours = 1 + _h("resp", tid) % 96 + resolution_hours = first_response_hours + _h("res", tid) % 240 + tickets.append({ + "ticket_id": tid, + "order_id": oid, + "opened_month": opened, + "severity": severity, + "first_response_hours": first_response_hours, + "resolution_hours": resolution_hours, + }) + + return { + "customers": customers, + "products": products, + "inventory": inventory, + "orders": orders, + "returns": returns, + "tickets": tickets, + "fx_to_usd_bp": FX_TO_USD_BP, + } + + +DATA = build_data() +CUSTOMERS = {c["customer_id"]: c for c in DATA["customers"]} +PRODUCTS = {p["product_id"]: p for p in DATA["products"]} +ORDERS = {o["order_id"]: o for o in DATA["orders"]} + + +def region_currency(region: str) -> str: + return CURRENCIES[region] + + +def get_orders(region: str, category: str, month_start: int, month_end: int) -> list: + """Paid/refunded order ids in a region/category/month window.""" + out = [] + for o in DATA["orders"]: + if o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + p = PRODUCTS[o["product_id"]] + if c["region"] == region and p["category"] == category and month_start <= o["month"] <= month_end: + out.append(o["order_id"]) + return sorted(out) + + +def order_gross_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * p["unit_price_usd"] + + +def order_margin_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * (p["unit_price_usd"] - p["unit_cogs_usd"]) + + +def refund_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + qty = sum(r["returned_qty"] for r in DATA["returns"] if r["order_id"] == order_id) + qty = min(qty, o["qty"]) + return qty * p["unit_price_usd"] + + +def customer_tier(order_id: int) -> str: + o = ORDERS[order_id] + return CUSTOMERS[o["customer_id"]]["tier"] + + +def apply_discount(amount_usd: int, tier: str) -> int: + return amount_usd * (100 - DISCOUNT_PCT[tier]) // 100 + + +def net_revenue_usd(order_id: int) -> int: + gross = apply_discount(order_gross_usd(order_id), customer_tier(order_id)) + return max(0, gross - refund_usd(order_id)) + + +def to_local(amount_usd: int, currency: str) -> int: + return amount_usd * 10000 // FX_TO_USD_BP[currency] + + +def inventory_position(product_id: int, region: str) -> int: + row = next(x for x in DATA["inventory"] + if x["product_id"] == product_id and x["region"] == region) + return row["on_hand"] - row["reserved"] + row["inbound"] + + +def product_lead_time(product_id: int) -> int: + return PRODUCTS[product_id]["lead_time_days"] + + +def product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int: + totals = {} + for oid in get_orders(region, category, month_start, month_end): + o = ORDERS[oid] + totals[o["product_id"]] = totals.get(o["product_id"], 0) + o["qty"] + if not totals: + return -1 + return min((-qty, pid) for pid, qty in totals.items())[1] + + +def units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int: + total = 0 + for o in DATA["orders"]: + if o["product_id"] != product_id or o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + if c["region"] == region and month_start <= o["month"] <= month_end: + total += o["qty"] + return total + + +def tickets_for_orders(order_ids: list, severity: str) -> list: + s = set(order_ids) + return sorted(t["ticket_id"] for t in DATA["tickets"] + if t["order_id"] in s and t["severity"] == severity) + + +def ticket_order_id(ticket_id: int) -> int: + return next(t["order_id"] for t in DATA["tickets"] if t["ticket_id"] == ticket_id) + + +def sla_breached(ticket_id: int, first_response_limit_hours: int, + resolution_limit_hours: int) -> bool: + t = next(x for x in DATA["tickets"] if x["ticket_id"] == ticket_id) + return (t["first_response_hours"] > first_response_limit_hours or + t["resolution_hours"] > resolution_limit_hours) + + +def delayed_orders(order_ids: list) -> list: + s = set(order_ids) + return sorted(o["order_id"] for o in DATA["orders"] + if o["order_id"] in s and o["ship_days"] > o["promised_days"]) + + +def unique_customers(order_ids: list) -> list: + return sorted({ORDERS[oid]["customer_id"] for oid in order_ids}) + + +def count_items(values: list) -> int: + return len(values) + + +def sum_values(values: list) -> int: + return sum(values) + + +def count_true(values: list) -> int: + return sum(1 for v in values if bool(v)) + + +def count_below(values: list, threshold: int) -> int: + return sum(1 for v in values if v < threshold) + + +TOOLS = { + "region_currency": ("region_currency(region: str) -> str", + "ISO currency code for a region.", region_currency), + "get_orders": ("get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]", + "Paid/refunded order ids for a region, product category, and inclusive month window.", + get_orders), + "order_gross_usd": ("order_gross_usd(order_id: int) -> int", + "Gross order revenue in USD before discounts/refunds.", order_gross_usd), + "order_margin_usd": ("order_margin_usd(order_id: int) -> int", + "Gross order margin in USD before discounts/refunds.", order_margin_usd), + "refund_usd": ("refund_usd(order_id: int) -> int", + "Refund amount in USD for returned quantity on an order.", refund_usd), + "customer_tier": ("customer_tier(order_id: int) -> str", + "Customer loyalty tier for an order.", customer_tier), + "apply_discount": ("apply_discount(amount_usd: int, tier: str) -> int", + "Apply the order customer's loyalty discount to a USD amount.", apply_discount), + "net_revenue_usd": ("net_revenue_usd(order_id: int) -> int", + "Net USD revenue after loyalty discount and refunds.", net_revenue_usd), + "to_local": ("to_local(amount_usd: int, currency: str) -> int", + "Convert a USD integer amount to a local-currency integer.", to_local), + "inventory_position": ("inventory_position(product_id: int, region: str) -> int", + "Available inventory position: on_hand - reserved + inbound.", + inventory_position), + "product_lead_time": ("product_lead_time(product_id: int) -> int", + "Supplier lead time in days for a product.", product_lead_time), + "product_id_for_top_seller": ( + "product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int", + "Product id with the highest units sold in a region/category/month window.", + product_id_for_top_seller), + "units_sold": ("units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int", + "Units sold for one product in a region and month window.", units_sold), + "tickets_for_orders": ("tickets_for_orders(order_ids: list[int], severity: str) -> list[int]", + "Support ticket ids for given orders and severity.", tickets_for_orders), + "ticket_order_id": ("ticket_order_id(ticket_id: int) -> int", + "Order id associated with a support ticket.", ticket_order_id), + "sla_breached": ( + "sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool", + "Whether a support ticket breaches first-response or resolution SLA.", + sla_breached), + "delayed_orders": ("delayed_orders(order_ids: list[int]) -> list[int]", + "Subset of order ids whose ship_days exceeded promised_days.", delayed_orders), + "unique_customers": ("unique_customers(order_ids: list[int]) -> list[int]", + "Unique customer ids among the given orders.", unique_customers), + "count_items": ("count_items(values: list) -> int", "Length of a list.", count_items), + "sum_values": ("sum_values(values: list[int]) -> int", "Sum a list of integers.", sum_values), + "count_true": ("count_true(values: list[bool]) -> int", "Count true values.", count_true), + "count_below": ("count_below(values: list[int], threshold: int) -> int", + "Count values below a threshold.", count_below), +} + +__all__ = [name for name in TOOLS.keys()] + ['TOOLS'] diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t16/environment/task.json b/harbor/tasks/v3_depth6_delay_sla_burden_t16/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..b243bfe5b829e33c8372192636a87fc18da4a68e --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t16/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth6_delay_sla_burden_t16", + "depth": 6, + "family": "delay_sla_burden", + "params": { + "region": "NA", + "category": "A", + "month_start": 202604, + "month_end": 202606 + }, + "question": "For region NA, category A, months 202604-202606: get the orders, count delayed orders where ship_days exceeded promised_days, find high and critical support tickets for those orders, count tickets that breach a 24-hour first-response or 120-hour resolution SLA, and report delayed_order_count + breached_ticket_count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t16/instruction.md b/harbor/tasks/v3_depth6_delay_sla_burden_t16/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..bc55a1649d3997030793e7edc5baddc6aab129c3 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t16/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For region NA, category A, months 202604-202606: get the orders, count delayed orders where ship_days exceeded promised_days, find high and critical support tickets for those orders, count tickets that breach a 24-hour first-response or 120-hour resolution SLA, and report delayed_order_count + breached_ticket_count. + +Available tools: +- `region_currency(region: str) -> str`: ISO currency code for a region. +- `get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]`: Paid/refunded order ids for a region, product category, and inclusive month window. +- `order_gross_usd(order_id: int) -> int`: Gross order revenue in USD before discounts/refunds. +- `order_margin_usd(order_id: int) -> int`: Gross order margin in USD before discounts/refunds. +- `refund_usd(order_id: int) -> int`: Refund amount in USD for returned quantity on an order. +- `customer_tier(order_id: int) -> str`: Customer loyalty tier for an order. +- `apply_discount(amount_usd: int, tier: str) -> int`: Apply the order customer's loyalty discount to a USD amount. +- `net_revenue_usd(order_id: int) -> int`: Net USD revenue after loyalty discount and refunds. +- `to_local(amount_usd: int, currency: str) -> int`: Convert a USD integer amount to a local-currency integer. +- `inventory_position(product_id: int, region: str) -> int`: Available inventory position: on_hand - reserved + inbound. +- `product_lead_time(product_id: int) -> int`: Supplier lead time in days for a product. +- `product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int`: Product id with the highest units sold in a region/category/month window. +- `units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int`: Units sold for one product in a region and month window. +- `tickets_for_orders(order_ids: list[int], severity: str) -> list[int]`: Support ticket ids for given orders and severity. +- `ticket_order_id(ticket_id: int) -> int`: Order id associated with a support ticket. +- `sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool`: Whether a support ticket breaches first-response or resolution SLA. +- `delayed_orders(order_ids: list[int]) -> list[int]`: Subset of order ids whose ship_days exceeded promised_days. +- `unique_customers(order_ids: list[int]) -> list[int]`: Unique customer ids among the given orders. +- `count_items(values: list) -> int`: Length of a list. +- `sum_values(values: list[int]) -> int`: Sum a list of integers. +- `count_true(values: list[bool]) -> int`: Count true values. +- `count_below(values: list[int], threshold: int) -> int`: Count values below a threshold. diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t16/task.toml b/harbor/tasks/v3_depth6_delay_sla_burden_t16/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..7bcca874aad7ea92b7b8f23afc9ee4e1e178e3bf --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t16/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth6_delay_sla_burden_t16" +description = "FlowBench v3 public task metadata. Public verifier is smoke-only." +authors = [{ name = "Mind Lab", email = "contact@mindlab.ltd" }] +keywords = ["flowbench", "tool-use", "data-orchestration", "operations"] + +[metadata] +benchmark = "FlowBench-v3" +split = "public-task-only" +category = "data-processing" +depth = 6 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +network_mode = "no-network" +build_timeout_sec = 600.0 +os = "linux" +cpus = 1 +memory_mb = 2048 +storage_mb = 2048 +gpus = 0 diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t16/tests/check_output_shape.py b/harbor/tasks/v3_depth6_delay_sla_burden_t16/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t16/tests/check_output_shape.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import json +import os +import re +from pathlib import Path + + +def write_reward(score: float, diagnostic: str) -> None: + log_dir = Path(os.environ.get("LOG_DIR", "/logs/verifier")) + log_dir.mkdir(parents=True, exist_ok=True) + (log_dir / "reward.txt").write_text(f"{score:.6g}\n") + (log_dir / "reward.json").write_text( + json.dumps({"reward": score, "smoke_only": True}, indent=2) + "\n" + ) + (log_dir / "diagnostic.txt").write_text(diagnostic + "\n") + + +def main() -> int: + app_dir = Path(os.environ.get("APP_DIR", "/app")) + task = json.loads((app_dir / "task.json").read_text()) + answer_path = app_dir / "answer.txt" + if not answer_path.exists(): + write_reward(0.0, "missing /app/answer.txt") + return 1 + + got = answer_path.read_text().strip() + if task["answer_format"] == "exact integer": + ok = bool(re.fullmatch(r"-?\d+", got)) + diagnostic = "valid integer smoke output" if ok else f"not an exact integer: {got!r}" + else: + ok = bool(re.fullmatch(r"[A-Za-z]+", got)) + diagnostic = "valid code smoke output" if ok else f"not an exact code: {got!r}" + + # This is intentionally not official scoring; it only verifies I/O shape. + write_reward(1.0 if ok else 0.0, diagnostic) + return 0 if ok else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t16/tests/test.sh b/harbor/tasks/v3_depth6_delay_sla_burden_t16/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t16/tests/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -u +python /tests/check_output_shape.py diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t17/environment/Dockerfile b/harbor/tasks/v3_depth6_delay_sla_burden_t17/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t17/environment/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.12-slim +WORKDIR /app +COPY flowbench_tools.py /app/flowbench_tools.py +COPY task.json /app/task.json diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t17/environment/flowbench_tools.py b/harbor/tasks/v3_depth6_delay_sla_burden_t17/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t17/environment/flowbench_tools.py @@ -0,0 +1,311 @@ +"""Deterministic FlowBench v3 tools. This file contains no task answers.""" + + +REGIONS = ["NA", "EU", "APAC", "LATAM"] +CATEGORIES = ["A", "B", "C", "D"] +CURRENCIES = {"NA": "USD", "EU": "EUR", "APAC": "JPY", "LATAM": "BRL"} +FX_TO_USD_BP = {"USD": 10000, "EUR": 10900, "JPY": 67, "BRL": 1850} +TIERS = ["std", "gold", "plat"] +DISCOUNT_PCT = {"std": 0, "gold": 10, "plat": 20} +CHANNELS = ["web", "store", "partner"] +MONTHS = [202601, 202602, 202603, 202604, 202605, 202606] + +N_CUSTOMERS = 72 +N_PRODUCTS = 48 +N_ORDERS = 720 +N_TICKETS = 260 +N_RETURNS = 180 + + +def _h(*xs): + import hashlib + s = "|".join(str(x) for x in xs).encode() + return int.from_bytes(hashlib.sha256(s).digest()[:8], "big") & 0x7FFFFFFF + + +def build_data(): + customers = [] + for cid in range(N_CUSTOMERS): + region = REGIONS[_h("region", cid) % len(REGIONS)] + customers.append({ + "customer_id": cid, + "region": region, + "tier": TIERS[_h("tier", cid) % len(TIERS)], + "segment": ["consumer", "smb", "enterprise"][_h("segment", cid) % 3], + }) + + products = [] + for pid in range(N_PRODUCTS): + cat = CATEGORIES[_h("cat", pid) % len(CATEGORIES)] + unit_price = 12 + _h("price", pid) % 240 + cogs = unit_price * (45 + _h("margin", pid) % 35) // 100 + products.append({ + "product_id": pid, + "category": cat, + "unit_price_usd": unit_price, + "unit_cogs_usd": cogs, + "lead_time_days": 3 + _h("lead", pid) % 18, + }) + + inventory = [] + for pid in range(N_PRODUCTS): + for region in REGIONS: + inventory.append({ + "product_id": pid, + "region": region, + "on_hand": 10 + _h("onhand", pid, region) % 140, + "reserved": _h("reserved", pid, region) % 28, + "inbound": _h("inbound", pid, region) % 85, + }) + + orders = [] + for oid in range(N_ORDERS): + customer_id = _h("ocust", oid) % N_CUSTOMERS + product_id = _h("oprod", oid) % N_PRODUCTS + month = MONTHS[_h("month", oid) % len(MONTHS)] + qty = 1 + _h("qty", oid) % 9 + ship_days = 1 + _h("shipdays", oid) % 16 + promised_days = 3 + _h("promise", oid) % 9 + status = ["paid", "paid", "paid", "paid", "cancelled", "refunded"][ + _h("status", oid) % 6] + orders.append({ + "order_id": oid, + "customer_id": customer_id, + "product_id": product_id, + "month": month, + "qty": qty, + "status": status, + "channel": CHANNELS[_h("channel", oid) % len(CHANNELS)], + "ship_days": ship_days, + "promised_days": promised_days, + }) + + returns = [] + for rid in range(N_RETURNS): + oid = _h("roid", rid) % N_ORDERS + order = orders[oid] + if order["status"] == "cancelled": + continue + returned_qty = 1 + _h("rqty", rid) % max(1, order["qty"]) + reason = ["defect", "late", "changed_mind", "wrong_item"][_h("reason", rid) % 4] + returns.append({ + "return_id": rid, + "order_id": oid, + "month": MONTHS[_h("rmonth", rid) % len(MONTHS)], + "returned_qty": returned_qty, + "reason": reason, + }) + + tickets = [] + for tid in range(N_TICKETS): + oid = _h("toid", tid) % N_ORDERS + severity = ["low", "medium", "high", "critical"][_h("sev", tid) % 4] + opened = MONTHS[_h("tmonth", tid) % len(MONTHS)] + first_response_hours = 1 + _h("resp", tid) % 96 + resolution_hours = first_response_hours + _h("res", tid) % 240 + tickets.append({ + "ticket_id": tid, + "order_id": oid, + "opened_month": opened, + "severity": severity, + "first_response_hours": first_response_hours, + "resolution_hours": resolution_hours, + }) + + return { + "customers": customers, + "products": products, + "inventory": inventory, + "orders": orders, + "returns": returns, + "tickets": tickets, + "fx_to_usd_bp": FX_TO_USD_BP, + } + + +DATA = build_data() +CUSTOMERS = {c["customer_id"]: c for c in DATA["customers"]} +PRODUCTS = {p["product_id"]: p for p in DATA["products"]} +ORDERS = {o["order_id"]: o for o in DATA["orders"]} + + +def region_currency(region: str) -> str: + return CURRENCIES[region] + + +def get_orders(region: str, category: str, month_start: int, month_end: int) -> list: + """Paid/refunded order ids in a region/category/month window.""" + out = [] + for o in DATA["orders"]: + if o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + p = PRODUCTS[o["product_id"]] + if c["region"] == region and p["category"] == category and month_start <= o["month"] <= month_end: + out.append(o["order_id"]) + return sorted(out) + + +def order_gross_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * p["unit_price_usd"] + + +def order_margin_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * (p["unit_price_usd"] - p["unit_cogs_usd"]) + + +def refund_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + qty = sum(r["returned_qty"] for r in DATA["returns"] if r["order_id"] == order_id) + qty = min(qty, o["qty"]) + return qty * p["unit_price_usd"] + + +def customer_tier(order_id: int) -> str: + o = ORDERS[order_id] + return CUSTOMERS[o["customer_id"]]["tier"] + + +def apply_discount(amount_usd: int, tier: str) -> int: + return amount_usd * (100 - DISCOUNT_PCT[tier]) // 100 + + +def net_revenue_usd(order_id: int) -> int: + gross = apply_discount(order_gross_usd(order_id), customer_tier(order_id)) + return max(0, gross - refund_usd(order_id)) + + +def to_local(amount_usd: int, currency: str) -> int: + return amount_usd * 10000 // FX_TO_USD_BP[currency] + + +def inventory_position(product_id: int, region: str) -> int: + row = next(x for x in DATA["inventory"] + if x["product_id"] == product_id and x["region"] == region) + return row["on_hand"] - row["reserved"] + row["inbound"] + + +def product_lead_time(product_id: int) -> int: + return PRODUCTS[product_id]["lead_time_days"] + + +def product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int: + totals = {} + for oid in get_orders(region, category, month_start, month_end): + o = ORDERS[oid] + totals[o["product_id"]] = totals.get(o["product_id"], 0) + o["qty"] + if not totals: + return -1 + return min((-qty, pid) for pid, qty in totals.items())[1] + + +def units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int: + total = 0 + for o in DATA["orders"]: + if o["product_id"] != product_id or o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + if c["region"] == region and month_start <= o["month"] <= month_end: + total += o["qty"] + return total + + +def tickets_for_orders(order_ids: list, severity: str) -> list: + s = set(order_ids) + return sorted(t["ticket_id"] for t in DATA["tickets"] + if t["order_id"] in s and t["severity"] == severity) + + +def ticket_order_id(ticket_id: int) -> int: + return next(t["order_id"] for t in DATA["tickets"] if t["ticket_id"] == ticket_id) + + +def sla_breached(ticket_id: int, first_response_limit_hours: int, + resolution_limit_hours: int) -> bool: + t = next(x for x in DATA["tickets"] if x["ticket_id"] == ticket_id) + return (t["first_response_hours"] > first_response_limit_hours or + t["resolution_hours"] > resolution_limit_hours) + + +def delayed_orders(order_ids: list) -> list: + s = set(order_ids) + return sorted(o["order_id"] for o in DATA["orders"] + if o["order_id"] in s and o["ship_days"] > o["promised_days"]) + + +def unique_customers(order_ids: list) -> list: + return sorted({ORDERS[oid]["customer_id"] for oid in order_ids}) + + +def count_items(values: list) -> int: + return len(values) + + +def sum_values(values: list) -> int: + return sum(values) + + +def count_true(values: list) -> int: + return sum(1 for v in values if bool(v)) + + +def count_below(values: list, threshold: int) -> int: + return sum(1 for v in values if v < threshold) + + +TOOLS = { + "region_currency": ("region_currency(region: str) -> str", + "ISO currency code for a region.", region_currency), + "get_orders": ("get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]", + "Paid/refunded order ids for a region, product category, and inclusive month window.", + get_orders), + "order_gross_usd": ("order_gross_usd(order_id: int) -> int", + "Gross order revenue in USD before discounts/refunds.", order_gross_usd), + "order_margin_usd": ("order_margin_usd(order_id: int) -> int", + "Gross order margin in USD before discounts/refunds.", order_margin_usd), + "refund_usd": ("refund_usd(order_id: int) -> int", + "Refund amount in USD for returned quantity on an order.", refund_usd), + "customer_tier": ("customer_tier(order_id: int) -> str", + "Customer loyalty tier for an order.", customer_tier), + "apply_discount": ("apply_discount(amount_usd: int, tier: str) -> int", + "Apply the order customer's loyalty discount to a USD amount.", apply_discount), + "net_revenue_usd": ("net_revenue_usd(order_id: int) -> int", + "Net USD revenue after loyalty discount and refunds.", net_revenue_usd), + "to_local": ("to_local(amount_usd: int, currency: str) -> int", + "Convert a USD integer amount to a local-currency integer.", to_local), + "inventory_position": ("inventory_position(product_id: int, region: str) -> int", + "Available inventory position: on_hand - reserved + inbound.", + inventory_position), + "product_lead_time": ("product_lead_time(product_id: int) -> int", + "Supplier lead time in days for a product.", product_lead_time), + "product_id_for_top_seller": ( + "product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int", + "Product id with the highest units sold in a region/category/month window.", + product_id_for_top_seller), + "units_sold": ("units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int", + "Units sold for one product in a region and month window.", units_sold), + "tickets_for_orders": ("tickets_for_orders(order_ids: list[int], severity: str) -> list[int]", + "Support ticket ids for given orders and severity.", tickets_for_orders), + "ticket_order_id": ("ticket_order_id(ticket_id: int) -> int", + "Order id associated with a support ticket.", ticket_order_id), + "sla_breached": ( + "sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool", + "Whether a support ticket breaches first-response or resolution SLA.", + sla_breached), + "delayed_orders": ("delayed_orders(order_ids: list[int]) -> list[int]", + "Subset of order ids whose ship_days exceeded promised_days.", delayed_orders), + "unique_customers": ("unique_customers(order_ids: list[int]) -> list[int]", + "Unique customer ids among the given orders.", unique_customers), + "count_items": ("count_items(values: list) -> int", "Length of a list.", count_items), + "sum_values": ("sum_values(values: list[int]) -> int", "Sum a list of integers.", sum_values), + "count_true": ("count_true(values: list[bool]) -> int", "Count true values.", count_true), + "count_below": ("count_below(values: list[int], threshold: int) -> int", + "Count values below a threshold.", count_below), +} + +__all__ = [name for name in TOOLS.keys()] + ['TOOLS'] diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t17/environment/task.json b/harbor/tasks/v3_depth6_delay_sla_burden_t17/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..c2c755cbaf36fe603ff75e567b218ef2f074f6f6 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t17/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth6_delay_sla_burden_t17", + "depth": 6, + "family": "delay_sla_burden", + "params": { + "region": "EU", + "category": "D", + "month_start": 202601, + "month_end": 202602 + }, + "question": "For region EU, category D, months 202601-202602: get the orders, count delayed orders where ship_days exceeded promised_days, find high and critical support tickets for those orders, count tickets that breach a 24-hour first-response or 120-hour resolution SLA, and report delayed_order_count + breached_ticket_count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t17/instruction.md b/harbor/tasks/v3_depth6_delay_sla_burden_t17/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..3df5903f1b20c48f19a71676c27c0bc00a471b04 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t17/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For region EU, category D, months 202601-202602: get the orders, count delayed orders where ship_days exceeded promised_days, find high and critical support tickets for those orders, count tickets that breach a 24-hour first-response or 120-hour resolution SLA, and report delayed_order_count + breached_ticket_count. + +Available tools: +- `region_currency(region: str) -> str`: ISO currency code for a region. +- `get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]`: Paid/refunded order ids for a region, product category, and inclusive month window. +- `order_gross_usd(order_id: int) -> int`: Gross order revenue in USD before discounts/refunds. +- `order_margin_usd(order_id: int) -> int`: Gross order margin in USD before discounts/refunds. +- `refund_usd(order_id: int) -> int`: Refund amount in USD for returned quantity on an order. +- `customer_tier(order_id: int) -> str`: Customer loyalty tier for an order. +- `apply_discount(amount_usd: int, tier: str) -> int`: Apply the order customer's loyalty discount to a USD amount. +- `net_revenue_usd(order_id: int) -> int`: Net USD revenue after loyalty discount and refunds. +- `to_local(amount_usd: int, currency: str) -> int`: Convert a USD integer amount to a local-currency integer. +- `inventory_position(product_id: int, region: str) -> int`: Available inventory position: on_hand - reserved + inbound. +- `product_lead_time(product_id: int) -> int`: Supplier lead time in days for a product. +- `product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int`: Product id with the highest units sold in a region/category/month window. +- `units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int`: Units sold for one product in a region and month window. +- `tickets_for_orders(order_ids: list[int], severity: str) -> list[int]`: Support ticket ids for given orders and severity. +- `ticket_order_id(ticket_id: int) -> int`: Order id associated with a support ticket. +- `sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool`: Whether a support ticket breaches first-response or resolution SLA. +- `delayed_orders(order_ids: list[int]) -> list[int]`: Subset of order ids whose ship_days exceeded promised_days. +- `unique_customers(order_ids: list[int]) -> list[int]`: Unique customer ids among the given orders. +- `count_items(values: list) -> int`: Length of a list. +- `sum_values(values: list[int]) -> int`: Sum a list of integers. +- `count_true(values: list[bool]) -> int`: Count true values. +- `count_below(values: list[int], threshold: int) -> int`: Count values below a threshold. diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t17/task.toml b/harbor/tasks/v3_depth6_delay_sla_burden_t17/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..8cc03ea075fc51a6a6dcbe21b62c338699adeeea --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t17/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth6_delay_sla_burden_t17" +description = "FlowBench v3 public task metadata. Public verifier is smoke-only." +authors = [{ name = "Mind Lab", email = "contact@mindlab.ltd" }] +keywords = ["flowbench", "tool-use", "data-orchestration", "operations"] + +[metadata] +benchmark = "FlowBench-v3" +split = "public-task-only" +category = "data-processing" +depth = 6 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +network_mode = "no-network" +build_timeout_sec = 600.0 +os = "linux" +cpus = 1 +memory_mb = 2048 +storage_mb = 2048 +gpus = 0 diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t17/tests/check_output_shape.py b/harbor/tasks/v3_depth6_delay_sla_burden_t17/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t17/tests/check_output_shape.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import json +import os +import re +from pathlib import Path + + +def write_reward(score: float, diagnostic: str) -> None: + log_dir = Path(os.environ.get("LOG_DIR", "/logs/verifier")) + log_dir.mkdir(parents=True, exist_ok=True) + (log_dir / "reward.txt").write_text(f"{score:.6g}\n") + (log_dir / "reward.json").write_text( + json.dumps({"reward": score, "smoke_only": True}, indent=2) + "\n" + ) + (log_dir / "diagnostic.txt").write_text(diagnostic + "\n") + + +def main() -> int: + app_dir = Path(os.environ.get("APP_DIR", "/app")) + task = json.loads((app_dir / "task.json").read_text()) + answer_path = app_dir / "answer.txt" + if not answer_path.exists(): + write_reward(0.0, "missing /app/answer.txt") + return 1 + + got = answer_path.read_text().strip() + if task["answer_format"] == "exact integer": + ok = bool(re.fullmatch(r"-?\d+", got)) + diagnostic = "valid integer smoke output" if ok else f"not an exact integer: {got!r}" + else: + ok = bool(re.fullmatch(r"[A-Za-z]+", got)) + diagnostic = "valid code smoke output" if ok else f"not an exact code: {got!r}" + + # This is intentionally not official scoring; it only verifies I/O shape. + write_reward(1.0 if ok else 0.0, diagnostic) + return 0 if ok else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t17/tests/test.sh b/harbor/tasks/v3_depth6_delay_sla_burden_t17/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t17/tests/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -u +python /tests/check_output_shape.py diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t18/environment/Dockerfile b/harbor/tasks/v3_depth6_delay_sla_burden_t18/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t18/environment/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.12-slim +WORKDIR /app +COPY flowbench_tools.py /app/flowbench_tools.py +COPY task.json /app/task.json diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t18/environment/flowbench_tools.py b/harbor/tasks/v3_depth6_delay_sla_burden_t18/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t18/environment/flowbench_tools.py @@ -0,0 +1,311 @@ +"""Deterministic FlowBench v3 tools. This file contains no task answers.""" + + +REGIONS = ["NA", "EU", "APAC", "LATAM"] +CATEGORIES = ["A", "B", "C", "D"] +CURRENCIES = {"NA": "USD", "EU": "EUR", "APAC": "JPY", "LATAM": "BRL"} +FX_TO_USD_BP = {"USD": 10000, "EUR": 10900, "JPY": 67, "BRL": 1850} +TIERS = ["std", "gold", "plat"] +DISCOUNT_PCT = {"std": 0, "gold": 10, "plat": 20} +CHANNELS = ["web", "store", "partner"] +MONTHS = [202601, 202602, 202603, 202604, 202605, 202606] + +N_CUSTOMERS = 72 +N_PRODUCTS = 48 +N_ORDERS = 720 +N_TICKETS = 260 +N_RETURNS = 180 + + +def _h(*xs): + import hashlib + s = "|".join(str(x) for x in xs).encode() + return int.from_bytes(hashlib.sha256(s).digest()[:8], "big") & 0x7FFFFFFF + + +def build_data(): + customers = [] + for cid in range(N_CUSTOMERS): + region = REGIONS[_h("region", cid) % len(REGIONS)] + customers.append({ + "customer_id": cid, + "region": region, + "tier": TIERS[_h("tier", cid) % len(TIERS)], + "segment": ["consumer", "smb", "enterprise"][_h("segment", cid) % 3], + }) + + products = [] + for pid in range(N_PRODUCTS): + cat = CATEGORIES[_h("cat", pid) % len(CATEGORIES)] + unit_price = 12 + _h("price", pid) % 240 + cogs = unit_price * (45 + _h("margin", pid) % 35) // 100 + products.append({ + "product_id": pid, + "category": cat, + "unit_price_usd": unit_price, + "unit_cogs_usd": cogs, + "lead_time_days": 3 + _h("lead", pid) % 18, + }) + + inventory = [] + for pid in range(N_PRODUCTS): + for region in REGIONS: + inventory.append({ + "product_id": pid, + "region": region, + "on_hand": 10 + _h("onhand", pid, region) % 140, + "reserved": _h("reserved", pid, region) % 28, + "inbound": _h("inbound", pid, region) % 85, + }) + + orders = [] + for oid in range(N_ORDERS): + customer_id = _h("ocust", oid) % N_CUSTOMERS + product_id = _h("oprod", oid) % N_PRODUCTS + month = MONTHS[_h("month", oid) % len(MONTHS)] + qty = 1 + _h("qty", oid) % 9 + ship_days = 1 + _h("shipdays", oid) % 16 + promised_days = 3 + _h("promise", oid) % 9 + status = ["paid", "paid", "paid", "paid", "cancelled", "refunded"][ + _h("status", oid) % 6] + orders.append({ + "order_id": oid, + "customer_id": customer_id, + "product_id": product_id, + "month": month, + "qty": qty, + "status": status, + "channel": CHANNELS[_h("channel", oid) % len(CHANNELS)], + "ship_days": ship_days, + "promised_days": promised_days, + }) + + returns = [] + for rid in range(N_RETURNS): + oid = _h("roid", rid) % N_ORDERS + order = orders[oid] + if order["status"] == "cancelled": + continue + returned_qty = 1 + _h("rqty", rid) % max(1, order["qty"]) + reason = ["defect", "late", "changed_mind", "wrong_item"][_h("reason", rid) % 4] + returns.append({ + "return_id": rid, + "order_id": oid, + "month": MONTHS[_h("rmonth", rid) % len(MONTHS)], + "returned_qty": returned_qty, + "reason": reason, + }) + + tickets = [] + for tid in range(N_TICKETS): + oid = _h("toid", tid) % N_ORDERS + severity = ["low", "medium", "high", "critical"][_h("sev", tid) % 4] + opened = MONTHS[_h("tmonth", tid) % len(MONTHS)] + first_response_hours = 1 + _h("resp", tid) % 96 + resolution_hours = first_response_hours + _h("res", tid) % 240 + tickets.append({ + "ticket_id": tid, + "order_id": oid, + "opened_month": opened, + "severity": severity, + "first_response_hours": first_response_hours, + "resolution_hours": resolution_hours, + }) + + return { + "customers": customers, + "products": products, + "inventory": inventory, + "orders": orders, + "returns": returns, + "tickets": tickets, + "fx_to_usd_bp": FX_TO_USD_BP, + } + + +DATA = build_data() +CUSTOMERS = {c["customer_id"]: c for c in DATA["customers"]} +PRODUCTS = {p["product_id"]: p for p in DATA["products"]} +ORDERS = {o["order_id"]: o for o in DATA["orders"]} + + +def region_currency(region: str) -> str: + return CURRENCIES[region] + + +def get_orders(region: str, category: str, month_start: int, month_end: int) -> list: + """Paid/refunded order ids in a region/category/month window.""" + out = [] + for o in DATA["orders"]: + if o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + p = PRODUCTS[o["product_id"]] + if c["region"] == region and p["category"] == category and month_start <= o["month"] <= month_end: + out.append(o["order_id"]) + return sorted(out) + + +def order_gross_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * p["unit_price_usd"] + + +def order_margin_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * (p["unit_price_usd"] - p["unit_cogs_usd"]) + + +def refund_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + qty = sum(r["returned_qty"] for r in DATA["returns"] if r["order_id"] == order_id) + qty = min(qty, o["qty"]) + return qty * p["unit_price_usd"] + + +def customer_tier(order_id: int) -> str: + o = ORDERS[order_id] + return CUSTOMERS[o["customer_id"]]["tier"] + + +def apply_discount(amount_usd: int, tier: str) -> int: + return amount_usd * (100 - DISCOUNT_PCT[tier]) // 100 + + +def net_revenue_usd(order_id: int) -> int: + gross = apply_discount(order_gross_usd(order_id), customer_tier(order_id)) + return max(0, gross - refund_usd(order_id)) + + +def to_local(amount_usd: int, currency: str) -> int: + return amount_usd * 10000 // FX_TO_USD_BP[currency] + + +def inventory_position(product_id: int, region: str) -> int: + row = next(x for x in DATA["inventory"] + if x["product_id"] == product_id and x["region"] == region) + return row["on_hand"] - row["reserved"] + row["inbound"] + + +def product_lead_time(product_id: int) -> int: + return PRODUCTS[product_id]["lead_time_days"] + + +def product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int: + totals = {} + for oid in get_orders(region, category, month_start, month_end): + o = ORDERS[oid] + totals[o["product_id"]] = totals.get(o["product_id"], 0) + o["qty"] + if not totals: + return -1 + return min((-qty, pid) for pid, qty in totals.items())[1] + + +def units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int: + total = 0 + for o in DATA["orders"]: + if o["product_id"] != product_id or o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + if c["region"] == region and month_start <= o["month"] <= month_end: + total += o["qty"] + return total + + +def tickets_for_orders(order_ids: list, severity: str) -> list: + s = set(order_ids) + return sorted(t["ticket_id"] for t in DATA["tickets"] + if t["order_id"] in s and t["severity"] == severity) + + +def ticket_order_id(ticket_id: int) -> int: + return next(t["order_id"] for t in DATA["tickets"] if t["ticket_id"] == ticket_id) + + +def sla_breached(ticket_id: int, first_response_limit_hours: int, + resolution_limit_hours: int) -> bool: + t = next(x for x in DATA["tickets"] if x["ticket_id"] == ticket_id) + return (t["first_response_hours"] > first_response_limit_hours or + t["resolution_hours"] > resolution_limit_hours) + + +def delayed_orders(order_ids: list) -> list: + s = set(order_ids) + return sorted(o["order_id"] for o in DATA["orders"] + if o["order_id"] in s and o["ship_days"] > o["promised_days"]) + + +def unique_customers(order_ids: list) -> list: + return sorted({ORDERS[oid]["customer_id"] for oid in order_ids}) + + +def count_items(values: list) -> int: + return len(values) + + +def sum_values(values: list) -> int: + return sum(values) + + +def count_true(values: list) -> int: + return sum(1 for v in values if bool(v)) + + +def count_below(values: list, threshold: int) -> int: + return sum(1 for v in values if v < threshold) + + +TOOLS = { + "region_currency": ("region_currency(region: str) -> str", + "ISO currency code for a region.", region_currency), + "get_orders": ("get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]", + "Paid/refunded order ids for a region, product category, and inclusive month window.", + get_orders), + "order_gross_usd": ("order_gross_usd(order_id: int) -> int", + "Gross order revenue in USD before discounts/refunds.", order_gross_usd), + "order_margin_usd": ("order_margin_usd(order_id: int) -> int", + "Gross order margin in USD before discounts/refunds.", order_margin_usd), + "refund_usd": ("refund_usd(order_id: int) -> int", + "Refund amount in USD for returned quantity on an order.", refund_usd), + "customer_tier": ("customer_tier(order_id: int) -> str", + "Customer loyalty tier for an order.", customer_tier), + "apply_discount": ("apply_discount(amount_usd: int, tier: str) -> int", + "Apply the order customer's loyalty discount to a USD amount.", apply_discount), + "net_revenue_usd": ("net_revenue_usd(order_id: int) -> int", + "Net USD revenue after loyalty discount and refunds.", net_revenue_usd), + "to_local": ("to_local(amount_usd: int, currency: str) -> int", + "Convert a USD integer amount to a local-currency integer.", to_local), + "inventory_position": ("inventory_position(product_id: int, region: str) -> int", + "Available inventory position: on_hand - reserved + inbound.", + inventory_position), + "product_lead_time": ("product_lead_time(product_id: int) -> int", + "Supplier lead time in days for a product.", product_lead_time), + "product_id_for_top_seller": ( + "product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int", + "Product id with the highest units sold in a region/category/month window.", + product_id_for_top_seller), + "units_sold": ("units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int", + "Units sold for one product in a region and month window.", units_sold), + "tickets_for_orders": ("tickets_for_orders(order_ids: list[int], severity: str) -> list[int]", + "Support ticket ids for given orders and severity.", tickets_for_orders), + "ticket_order_id": ("ticket_order_id(ticket_id: int) -> int", + "Order id associated with a support ticket.", ticket_order_id), + "sla_breached": ( + "sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool", + "Whether a support ticket breaches first-response or resolution SLA.", + sla_breached), + "delayed_orders": ("delayed_orders(order_ids: list[int]) -> list[int]", + "Subset of order ids whose ship_days exceeded promised_days.", delayed_orders), + "unique_customers": ("unique_customers(order_ids: list[int]) -> list[int]", + "Unique customer ids among the given orders.", unique_customers), + "count_items": ("count_items(values: list) -> int", "Length of a list.", count_items), + "sum_values": ("sum_values(values: list[int]) -> int", "Sum a list of integers.", sum_values), + "count_true": ("count_true(values: list[bool]) -> int", "Count true values.", count_true), + "count_below": ("count_below(values: list[int], threshold: int) -> int", + "Count values below a threshold.", count_below), +} + +__all__ = [name for name in TOOLS.keys()] + ['TOOLS'] diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t18/environment/task.json b/harbor/tasks/v3_depth6_delay_sla_burden_t18/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..5848bf82d85b969a9496396775a192c3e31165a1 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t18/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth6_delay_sla_burden_t18", + "depth": 6, + "family": "delay_sla_burden", + "params": { + "region": "APAC", + "category": "A", + "month_start": 202603, + "month_end": 202604 + }, + "question": "For region APAC, category A, months 202603-202604: get the orders, count delayed orders where ship_days exceeded promised_days, find high and critical support tickets for those orders, count tickets that breach a 24-hour first-response or 120-hour resolution SLA, and report delayed_order_count + breached_ticket_count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t18/instruction.md b/harbor/tasks/v3_depth6_delay_sla_burden_t18/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..e352eae0f3e07bd886746f7781ad3d4360f44eab --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t18/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For region APAC, category A, months 202603-202604: get the orders, count delayed orders where ship_days exceeded promised_days, find high and critical support tickets for those orders, count tickets that breach a 24-hour first-response or 120-hour resolution SLA, and report delayed_order_count + breached_ticket_count. + +Available tools: +- `region_currency(region: str) -> str`: ISO currency code for a region. +- `get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]`: Paid/refunded order ids for a region, product category, and inclusive month window. +- `order_gross_usd(order_id: int) -> int`: Gross order revenue in USD before discounts/refunds. +- `order_margin_usd(order_id: int) -> int`: Gross order margin in USD before discounts/refunds. +- `refund_usd(order_id: int) -> int`: Refund amount in USD for returned quantity on an order. +- `customer_tier(order_id: int) -> str`: Customer loyalty tier for an order. +- `apply_discount(amount_usd: int, tier: str) -> int`: Apply the order customer's loyalty discount to a USD amount. +- `net_revenue_usd(order_id: int) -> int`: Net USD revenue after loyalty discount and refunds. +- `to_local(amount_usd: int, currency: str) -> int`: Convert a USD integer amount to a local-currency integer. +- `inventory_position(product_id: int, region: str) -> int`: Available inventory position: on_hand - reserved + inbound. +- `product_lead_time(product_id: int) -> int`: Supplier lead time in days for a product. +- `product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int`: Product id with the highest units sold in a region/category/month window. +- `units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int`: Units sold for one product in a region and month window. +- `tickets_for_orders(order_ids: list[int], severity: str) -> list[int]`: Support ticket ids for given orders and severity. +- `ticket_order_id(ticket_id: int) -> int`: Order id associated with a support ticket. +- `sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool`: Whether a support ticket breaches first-response or resolution SLA. +- `delayed_orders(order_ids: list[int]) -> list[int]`: Subset of order ids whose ship_days exceeded promised_days. +- `unique_customers(order_ids: list[int]) -> list[int]`: Unique customer ids among the given orders. +- `count_items(values: list) -> int`: Length of a list. +- `sum_values(values: list[int]) -> int`: Sum a list of integers. +- `count_true(values: list[bool]) -> int`: Count true values. +- `count_below(values: list[int], threshold: int) -> int`: Count values below a threshold. diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t18/task.toml b/harbor/tasks/v3_depth6_delay_sla_burden_t18/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..56606362b6fcfe706839b121295558b3b2416a57 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t18/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth6_delay_sla_burden_t18" +description = "FlowBench v3 public task metadata. Public verifier is smoke-only." +authors = [{ name = "Mind Lab", email = "contact@mindlab.ltd" }] +keywords = ["flowbench", "tool-use", "data-orchestration", "operations"] + +[metadata] +benchmark = "FlowBench-v3" +split = "public-task-only" +category = "data-processing" +depth = 6 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +network_mode = "no-network" +build_timeout_sec = 600.0 +os = "linux" +cpus = 1 +memory_mb = 2048 +storage_mb = 2048 +gpus = 0 diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t18/tests/check_output_shape.py b/harbor/tasks/v3_depth6_delay_sla_burden_t18/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t18/tests/check_output_shape.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import json +import os +import re +from pathlib import Path + + +def write_reward(score: float, diagnostic: str) -> None: + log_dir = Path(os.environ.get("LOG_DIR", "/logs/verifier")) + log_dir.mkdir(parents=True, exist_ok=True) + (log_dir / "reward.txt").write_text(f"{score:.6g}\n") + (log_dir / "reward.json").write_text( + json.dumps({"reward": score, "smoke_only": True}, indent=2) + "\n" + ) + (log_dir / "diagnostic.txt").write_text(diagnostic + "\n") + + +def main() -> int: + app_dir = Path(os.environ.get("APP_DIR", "/app")) + task = json.loads((app_dir / "task.json").read_text()) + answer_path = app_dir / "answer.txt" + if not answer_path.exists(): + write_reward(0.0, "missing /app/answer.txt") + return 1 + + got = answer_path.read_text().strip() + if task["answer_format"] == "exact integer": + ok = bool(re.fullmatch(r"-?\d+", got)) + diagnostic = "valid integer smoke output" if ok else f"not an exact integer: {got!r}" + else: + ok = bool(re.fullmatch(r"[A-Za-z]+", got)) + diagnostic = "valid code smoke output" if ok else f"not an exact code: {got!r}" + + # This is intentionally not official scoring; it only verifies I/O shape. + write_reward(1.0 if ok else 0.0, diagnostic) + return 0 if ok else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t18/tests/test.sh b/harbor/tasks/v3_depth6_delay_sla_burden_t18/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t18/tests/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -u +python /tests/check_output_shape.py diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t19/environment/Dockerfile b/harbor/tasks/v3_depth6_delay_sla_burden_t19/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t19/environment/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.12-slim +WORKDIR /app +COPY flowbench_tools.py /app/flowbench_tools.py +COPY task.json /app/task.json diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t19/environment/flowbench_tools.py b/harbor/tasks/v3_depth6_delay_sla_burden_t19/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t19/environment/flowbench_tools.py @@ -0,0 +1,311 @@ +"""Deterministic FlowBench v3 tools. This file contains no task answers.""" + + +REGIONS = ["NA", "EU", "APAC", "LATAM"] +CATEGORIES = ["A", "B", "C", "D"] +CURRENCIES = {"NA": "USD", "EU": "EUR", "APAC": "JPY", "LATAM": "BRL"} +FX_TO_USD_BP = {"USD": 10000, "EUR": 10900, "JPY": 67, "BRL": 1850} +TIERS = ["std", "gold", "plat"] +DISCOUNT_PCT = {"std": 0, "gold": 10, "plat": 20} +CHANNELS = ["web", "store", "partner"] +MONTHS = [202601, 202602, 202603, 202604, 202605, 202606] + +N_CUSTOMERS = 72 +N_PRODUCTS = 48 +N_ORDERS = 720 +N_TICKETS = 260 +N_RETURNS = 180 + + +def _h(*xs): + import hashlib + s = "|".join(str(x) for x in xs).encode() + return int.from_bytes(hashlib.sha256(s).digest()[:8], "big") & 0x7FFFFFFF + + +def build_data(): + customers = [] + for cid in range(N_CUSTOMERS): + region = REGIONS[_h("region", cid) % len(REGIONS)] + customers.append({ + "customer_id": cid, + "region": region, + "tier": TIERS[_h("tier", cid) % len(TIERS)], + "segment": ["consumer", "smb", "enterprise"][_h("segment", cid) % 3], + }) + + products = [] + for pid in range(N_PRODUCTS): + cat = CATEGORIES[_h("cat", pid) % len(CATEGORIES)] + unit_price = 12 + _h("price", pid) % 240 + cogs = unit_price * (45 + _h("margin", pid) % 35) // 100 + products.append({ + "product_id": pid, + "category": cat, + "unit_price_usd": unit_price, + "unit_cogs_usd": cogs, + "lead_time_days": 3 + _h("lead", pid) % 18, + }) + + inventory = [] + for pid in range(N_PRODUCTS): + for region in REGIONS: + inventory.append({ + "product_id": pid, + "region": region, + "on_hand": 10 + _h("onhand", pid, region) % 140, + "reserved": _h("reserved", pid, region) % 28, + "inbound": _h("inbound", pid, region) % 85, + }) + + orders = [] + for oid in range(N_ORDERS): + customer_id = _h("ocust", oid) % N_CUSTOMERS + product_id = _h("oprod", oid) % N_PRODUCTS + month = MONTHS[_h("month", oid) % len(MONTHS)] + qty = 1 + _h("qty", oid) % 9 + ship_days = 1 + _h("shipdays", oid) % 16 + promised_days = 3 + _h("promise", oid) % 9 + status = ["paid", "paid", "paid", "paid", "cancelled", "refunded"][ + _h("status", oid) % 6] + orders.append({ + "order_id": oid, + "customer_id": customer_id, + "product_id": product_id, + "month": month, + "qty": qty, + "status": status, + "channel": CHANNELS[_h("channel", oid) % len(CHANNELS)], + "ship_days": ship_days, + "promised_days": promised_days, + }) + + returns = [] + for rid in range(N_RETURNS): + oid = _h("roid", rid) % N_ORDERS + order = orders[oid] + if order["status"] == "cancelled": + continue + returned_qty = 1 + _h("rqty", rid) % max(1, order["qty"]) + reason = ["defect", "late", "changed_mind", "wrong_item"][_h("reason", rid) % 4] + returns.append({ + "return_id": rid, + "order_id": oid, + "month": MONTHS[_h("rmonth", rid) % len(MONTHS)], + "returned_qty": returned_qty, + "reason": reason, + }) + + tickets = [] + for tid in range(N_TICKETS): + oid = _h("toid", tid) % N_ORDERS + severity = ["low", "medium", "high", "critical"][_h("sev", tid) % 4] + opened = MONTHS[_h("tmonth", tid) % len(MONTHS)] + first_response_hours = 1 + _h("resp", tid) % 96 + resolution_hours = first_response_hours + _h("res", tid) % 240 + tickets.append({ + "ticket_id": tid, + "order_id": oid, + "opened_month": opened, + "severity": severity, + "first_response_hours": first_response_hours, + "resolution_hours": resolution_hours, + }) + + return { + "customers": customers, + "products": products, + "inventory": inventory, + "orders": orders, + "returns": returns, + "tickets": tickets, + "fx_to_usd_bp": FX_TO_USD_BP, + } + + +DATA = build_data() +CUSTOMERS = {c["customer_id"]: c for c in DATA["customers"]} +PRODUCTS = {p["product_id"]: p for p in DATA["products"]} +ORDERS = {o["order_id"]: o for o in DATA["orders"]} + + +def region_currency(region: str) -> str: + return CURRENCIES[region] + + +def get_orders(region: str, category: str, month_start: int, month_end: int) -> list: + """Paid/refunded order ids in a region/category/month window.""" + out = [] + for o in DATA["orders"]: + if o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + p = PRODUCTS[o["product_id"]] + if c["region"] == region and p["category"] == category and month_start <= o["month"] <= month_end: + out.append(o["order_id"]) + return sorted(out) + + +def order_gross_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * p["unit_price_usd"] + + +def order_margin_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * (p["unit_price_usd"] - p["unit_cogs_usd"]) + + +def refund_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + qty = sum(r["returned_qty"] for r in DATA["returns"] if r["order_id"] == order_id) + qty = min(qty, o["qty"]) + return qty * p["unit_price_usd"] + + +def customer_tier(order_id: int) -> str: + o = ORDERS[order_id] + return CUSTOMERS[o["customer_id"]]["tier"] + + +def apply_discount(amount_usd: int, tier: str) -> int: + return amount_usd * (100 - DISCOUNT_PCT[tier]) // 100 + + +def net_revenue_usd(order_id: int) -> int: + gross = apply_discount(order_gross_usd(order_id), customer_tier(order_id)) + return max(0, gross - refund_usd(order_id)) + + +def to_local(amount_usd: int, currency: str) -> int: + return amount_usd * 10000 // FX_TO_USD_BP[currency] + + +def inventory_position(product_id: int, region: str) -> int: + row = next(x for x in DATA["inventory"] + if x["product_id"] == product_id and x["region"] == region) + return row["on_hand"] - row["reserved"] + row["inbound"] + + +def product_lead_time(product_id: int) -> int: + return PRODUCTS[product_id]["lead_time_days"] + + +def product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int: + totals = {} + for oid in get_orders(region, category, month_start, month_end): + o = ORDERS[oid] + totals[o["product_id"]] = totals.get(o["product_id"], 0) + o["qty"] + if not totals: + return -1 + return min((-qty, pid) for pid, qty in totals.items())[1] + + +def units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int: + total = 0 + for o in DATA["orders"]: + if o["product_id"] != product_id or o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + if c["region"] == region and month_start <= o["month"] <= month_end: + total += o["qty"] + return total + + +def tickets_for_orders(order_ids: list, severity: str) -> list: + s = set(order_ids) + return sorted(t["ticket_id"] for t in DATA["tickets"] + if t["order_id"] in s and t["severity"] == severity) + + +def ticket_order_id(ticket_id: int) -> int: + return next(t["order_id"] for t in DATA["tickets"] if t["ticket_id"] == ticket_id) + + +def sla_breached(ticket_id: int, first_response_limit_hours: int, + resolution_limit_hours: int) -> bool: + t = next(x for x in DATA["tickets"] if x["ticket_id"] == ticket_id) + return (t["first_response_hours"] > first_response_limit_hours or + t["resolution_hours"] > resolution_limit_hours) + + +def delayed_orders(order_ids: list) -> list: + s = set(order_ids) + return sorted(o["order_id"] for o in DATA["orders"] + if o["order_id"] in s and o["ship_days"] > o["promised_days"]) + + +def unique_customers(order_ids: list) -> list: + return sorted({ORDERS[oid]["customer_id"] for oid in order_ids}) + + +def count_items(values: list) -> int: + return len(values) + + +def sum_values(values: list) -> int: + return sum(values) + + +def count_true(values: list) -> int: + return sum(1 for v in values if bool(v)) + + +def count_below(values: list, threshold: int) -> int: + return sum(1 for v in values if v < threshold) + + +TOOLS = { + "region_currency": ("region_currency(region: str) -> str", + "ISO currency code for a region.", region_currency), + "get_orders": ("get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]", + "Paid/refunded order ids for a region, product category, and inclusive month window.", + get_orders), + "order_gross_usd": ("order_gross_usd(order_id: int) -> int", + "Gross order revenue in USD before discounts/refunds.", order_gross_usd), + "order_margin_usd": ("order_margin_usd(order_id: int) -> int", + "Gross order margin in USD before discounts/refunds.", order_margin_usd), + "refund_usd": ("refund_usd(order_id: int) -> int", + "Refund amount in USD for returned quantity on an order.", refund_usd), + "customer_tier": ("customer_tier(order_id: int) -> str", + "Customer loyalty tier for an order.", customer_tier), + "apply_discount": ("apply_discount(amount_usd: int, tier: str) -> int", + "Apply the order customer's loyalty discount to a USD amount.", apply_discount), + "net_revenue_usd": ("net_revenue_usd(order_id: int) -> int", + "Net USD revenue after loyalty discount and refunds.", net_revenue_usd), + "to_local": ("to_local(amount_usd: int, currency: str) -> int", + "Convert a USD integer amount to a local-currency integer.", to_local), + "inventory_position": ("inventory_position(product_id: int, region: str) -> int", + "Available inventory position: on_hand - reserved + inbound.", + inventory_position), + "product_lead_time": ("product_lead_time(product_id: int) -> int", + "Supplier lead time in days for a product.", product_lead_time), + "product_id_for_top_seller": ( + "product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int", + "Product id with the highest units sold in a region/category/month window.", + product_id_for_top_seller), + "units_sold": ("units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int", + "Units sold for one product in a region and month window.", units_sold), + "tickets_for_orders": ("tickets_for_orders(order_ids: list[int], severity: str) -> list[int]", + "Support ticket ids for given orders and severity.", tickets_for_orders), + "ticket_order_id": ("ticket_order_id(ticket_id: int) -> int", + "Order id associated with a support ticket.", ticket_order_id), + "sla_breached": ( + "sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool", + "Whether a support ticket breaches first-response or resolution SLA.", + sla_breached), + "delayed_orders": ("delayed_orders(order_ids: list[int]) -> list[int]", + "Subset of order ids whose ship_days exceeded promised_days.", delayed_orders), + "unique_customers": ("unique_customers(order_ids: list[int]) -> list[int]", + "Unique customer ids among the given orders.", unique_customers), + "count_items": ("count_items(values: list) -> int", "Length of a list.", count_items), + "sum_values": ("sum_values(values: list[int]) -> int", "Sum a list of integers.", sum_values), + "count_true": ("count_true(values: list[bool]) -> int", "Count true values.", count_true), + "count_below": ("count_below(values: list[int], threshold: int) -> int", + "Count values below a threshold.", count_below), +} + +__all__ = [name for name in TOOLS.keys()] + ['TOOLS'] diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t19/environment/task.json b/harbor/tasks/v3_depth6_delay_sla_burden_t19/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..0a99fc9892e472b39018fd30a103ab5c0df4f40e --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t19/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth6_delay_sla_burden_t19", + "depth": 6, + "family": "delay_sla_burden", + "params": { + "region": "LATAM", + "category": "B", + "month_start": 202605, + "month_end": 202606 + }, + "question": "For region LATAM, category B, months 202605-202606: get the orders, count delayed orders where ship_days exceeded promised_days, find high and critical support tickets for those orders, count tickets that breach a 24-hour first-response or 120-hour resolution SLA, and report delayed_order_count + breached_ticket_count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t19/instruction.md b/harbor/tasks/v3_depth6_delay_sla_burden_t19/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..38eadf19b0816d2e9f6f51c1d6501221b793ef43 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t19/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For region LATAM, category B, months 202605-202606: get the orders, count delayed orders where ship_days exceeded promised_days, find high and critical support tickets for those orders, count tickets that breach a 24-hour first-response or 120-hour resolution SLA, and report delayed_order_count + breached_ticket_count. + +Available tools: +- `region_currency(region: str) -> str`: ISO currency code for a region. +- `get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]`: Paid/refunded order ids for a region, product category, and inclusive month window. +- `order_gross_usd(order_id: int) -> int`: Gross order revenue in USD before discounts/refunds. +- `order_margin_usd(order_id: int) -> int`: Gross order margin in USD before discounts/refunds. +- `refund_usd(order_id: int) -> int`: Refund amount in USD for returned quantity on an order. +- `customer_tier(order_id: int) -> str`: Customer loyalty tier for an order. +- `apply_discount(amount_usd: int, tier: str) -> int`: Apply the order customer's loyalty discount to a USD amount. +- `net_revenue_usd(order_id: int) -> int`: Net USD revenue after loyalty discount and refunds. +- `to_local(amount_usd: int, currency: str) -> int`: Convert a USD integer amount to a local-currency integer. +- `inventory_position(product_id: int, region: str) -> int`: Available inventory position: on_hand - reserved + inbound. +- `product_lead_time(product_id: int) -> int`: Supplier lead time in days for a product. +- `product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int`: Product id with the highest units sold in a region/category/month window. +- `units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int`: Units sold for one product in a region and month window. +- `tickets_for_orders(order_ids: list[int], severity: str) -> list[int]`: Support ticket ids for given orders and severity. +- `ticket_order_id(ticket_id: int) -> int`: Order id associated with a support ticket. +- `sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool`: Whether a support ticket breaches first-response or resolution SLA. +- `delayed_orders(order_ids: list[int]) -> list[int]`: Subset of order ids whose ship_days exceeded promised_days. +- `unique_customers(order_ids: list[int]) -> list[int]`: Unique customer ids among the given orders. +- `count_items(values: list) -> int`: Length of a list. +- `sum_values(values: list[int]) -> int`: Sum a list of integers. +- `count_true(values: list[bool]) -> int`: Count true values. +- `count_below(values: list[int], threshold: int) -> int`: Count values below a threshold. diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t19/task.toml b/harbor/tasks/v3_depth6_delay_sla_burden_t19/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..f8d9bce724299f3b02d193b884eaa22d4a502b0d --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t19/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth6_delay_sla_burden_t19" +description = "FlowBench v3 public task metadata. Public verifier is smoke-only." +authors = [{ name = "Mind Lab", email = "contact@mindlab.ltd" }] +keywords = ["flowbench", "tool-use", "data-orchestration", "operations"] + +[metadata] +benchmark = "FlowBench-v3" +split = "public-task-only" +category = "data-processing" +depth = 6 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +network_mode = "no-network" +build_timeout_sec = 600.0 +os = "linux" +cpus = 1 +memory_mb = 2048 +storage_mb = 2048 +gpus = 0 diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t19/tests/check_output_shape.py b/harbor/tasks/v3_depth6_delay_sla_burden_t19/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t19/tests/check_output_shape.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import json +import os +import re +from pathlib import Path + + +def write_reward(score: float, diagnostic: str) -> None: + log_dir = Path(os.environ.get("LOG_DIR", "/logs/verifier")) + log_dir.mkdir(parents=True, exist_ok=True) + (log_dir / "reward.txt").write_text(f"{score:.6g}\n") + (log_dir / "reward.json").write_text( + json.dumps({"reward": score, "smoke_only": True}, indent=2) + "\n" + ) + (log_dir / "diagnostic.txt").write_text(diagnostic + "\n") + + +def main() -> int: + app_dir = Path(os.environ.get("APP_DIR", "/app")) + task = json.loads((app_dir / "task.json").read_text()) + answer_path = app_dir / "answer.txt" + if not answer_path.exists(): + write_reward(0.0, "missing /app/answer.txt") + return 1 + + got = answer_path.read_text().strip() + if task["answer_format"] == "exact integer": + ok = bool(re.fullmatch(r"-?\d+", got)) + diagnostic = "valid integer smoke output" if ok else f"not an exact integer: {got!r}" + else: + ok = bool(re.fullmatch(r"[A-Za-z]+", got)) + diagnostic = "valid code smoke output" if ok else f"not an exact code: {got!r}" + + # This is intentionally not official scoring; it only verifies I/O shape. + write_reward(1.0 if ok else 0.0, diagnostic) + return 0 if ok else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t19/tests/test.sh b/harbor/tasks/v3_depth6_delay_sla_burden_t19/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t19/tests/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -u +python /tests/check_output_shape.py diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t2/environment/Dockerfile b/harbor/tasks/v3_depth6_delay_sla_burden_t2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t2/environment/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.12-slim +WORKDIR /app +COPY flowbench_tools.py /app/flowbench_tools.py +COPY task.json /app/task.json diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t2/environment/flowbench_tools.py b/harbor/tasks/v3_depth6_delay_sla_burden_t2/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t2/environment/flowbench_tools.py @@ -0,0 +1,311 @@ +"""Deterministic FlowBench v3 tools. This file contains no task answers.""" + + +REGIONS = ["NA", "EU", "APAC", "LATAM"] +CATEGORIES = ["A", "B", "C", "D"] +CURRENCIES = {"NA": "USD", "EU": "EUR", "APAC": "JPY", "LATAM": "BRL"} +FX_TO_USD_BP = {"USD": 10000, "EUR": 10900, "JPY": 67, "BRL": 1850} +TIERS = ["std", "gold", "plat"] +DISCOUNT_PCT = {"std": 0, "gold": 10, "plat": 20} +CHANNELS = ["web", "store", "partner"] +MONTHS = [202601, 202602, 202603, 202604, 202605, 202606] + +N_CUSTOMERS = 72 +N_PRODUCTS = 48 +N_ORDERS = 720 +N_TICKETS = 260 +N_RETURNS = 180 + + +def _h(*xs): + import hashlib + s = "|".join(str(x) for x in xs).encode() + return int.from_bytes(hashlib.sha256(s).digest()[:8], "big") & 0x7FFFFFFF + + +def build_data(): + customers = [] + for cid in range(N_CUSTOMERS): + region = REGIONS[_h("region", cid) % len(REGIONS)] + customers.append({ + "customer_id": cid, + "region": region, + "tier": TIERS[_h("tier", cid) % len(TIERS)], + "segment": ["consumer", "smb", "enterprise"][_h("segment", cid) % 3], + }) + + products = [] + for pid in range(N_PRODUCTS): + cat = CATEGORIES[_h("cat", pid) % len(CATEGORIES)] + unit_price = 12 + _h("price", pid) % 240 + cogs = unit_price * (45 + _h("margin", pid) % 35) // 100 + products.append({ + "product_id": pid, + "category": cat, + "unit_price_usd": unit_price, + "unit_cogs_usd": cogs, + "lead_time_days": 3 + _h("lead", pid) % 18, + }) + + inventory = [] + for pid in range(N_PRODUCTS): + for region in REGIONS: + inventory.append({ + "product_id": pid, + "region": region, + "on_hand": 10 + _h("onhand", pid, region) % 140, + "reserved": _h("reserved", pid, region) % 28, + "inbound": _h("inbound", pid, region) % 85, + }) + + orders = [] + for oid in range(N_ORDERS): + customer_id = _h("ocust", oid) % N_CUSTOMERS + product_id = _h("oprod", oid) % N_PRODUCTS + month = MONTHS[_h("month", oid) % len(MONTHS)] + qty = 1 + _h("qty", oid) % 9 + ship_days = 1 + _h("shipdays", oid) % 16 + promised_days = 3 + _h("promise", oid) % 9 + status = ["paid", "paid", "paid", "paid", "cancelled", "refunded"][ + _h("status", oid) % 6] + orders.append({ + "order_id": oid, + "customer_id": customer_id, + "product_id": product_id, + "month": month, + "qty": qty, + "status": status, + "channel": CHANNELS[_h("channel", oid) % len(CHANNELS)], + "ship_days": ship_days, + "promised_days": promised_days, + }) + + returns = [] + for rid in range(N_RETURNS): + oid = _h("roid", rid) % N_ORDERS + order = orders[oid] + if order["status"] == "cancelled": + continue + returned_qty = 1 + _h("rqty", rid) % max(1, order["qty"]) + reason = ["defect", "late", "changed_mind", "wrong_item"][_h("reason", rid) % 4] + returns.append({ + "return_id": rid, + "order_id": oid, + "month": MONTHS[_h("rmonth", rid) % len(MONTHS)], + "returned_qty": returned_qty, + "reason": reason, + }) + + tickets = [] + for tid in range(N_TICKETS): + oid = _h("toid", tid) % N_ORDERS + severity = ["low", "medium", "high", "critical"][_h("sev", tid) % 4] + opened = MONTHS[_h("tmonth", tid) % len(MONTHS)] + first_response_hours = 1 + _h("resp", tid) % 96 + resolution_hours = first_response_hours + _h("res", tid) % 240 + tickets.append({ + "ticket_id": tid, + "order_id": oid, + "opened_month": opened, + "severity": severity, + "first_response_hours": first_response_hours, + "resolution_hours": resolution_hours, + }) + + return { + "customers": customers, + "products": products, + "inventory": inventory, + "orders": orders, + "returns": returns, + "tickets": tickets, + "fx_to_usd_bp": FX_TO_USD_BP, + } + + +DATA = build_data() +CUSTOMERS = {c["customer_id"]: c for c in DATA["customers"]} +PRODUCTS = {p["product_id"]: p for p in DATA["products"]} +ORDERS = {o["order_id"]: o for o in DATA["orders"]} + + +def region_currency(region: str) -> str: + return CURRENCIES[region] + + +def get_orders(region: str, category: str, month_start: int, month_end: int) -> list: + """Paid/refunded order ids in a region/category/month window.""" + out = [] + for o in DATA["orders"]: + if o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + p = PRODUCTS[o["product_id"]] + if c["region"] == region and p["category"] == category and month_start <= o["month"] <= month_end: + out.append(o["order_id"]) + return sorted(out) + + +def order_gross_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * p["unit_price_usd"] + + +def order_margin_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * (p["unit_price_usd"] - p["unit_cogs_usd"]) + + +def refund_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + qty = sum(r["returned_qty"] for r in DATA["returns"] if r["order_id"] == order_id) + qty = min(qty, o["qty"]) + return qty * p["unit_price_usd"] + + +def customer_tier(order_id: int) -> str: + o = ORDERS[order_id] + return CUSTOMERS[o["customer_id"]]["tier"] + + +def apply_discount(amount_usd: int, tier: str) -> int: + return amount_usd * (100 - DISCOUNT_PCT[tier]) // 100 + + +def net_revenue_usd(order_id: int) -> int: + gross = apply_discount(order_gross_usd(order_id), customer_tier(order_id)) + return max(0, gross - refund_usd(order_id)) + + +def to_local(amount_usd: int, currency: str) -> int: + return amount_usd * 10000 // FX_TO_USD_BP[currency] + + +def inventory_position(product_id: int, region: str) -> int: + row = next(x for x in DATA["inventory"] + if x["product_id"] == product_id and x["region"] == region) + return row["on_hand"] - row["reserved"] + row["inbound"] + + +def product_lead_time(product_id: int) -> int: + return PRODUCTS[product_id]["lead_time_days"] + + +def product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int: + totals = {} + for oid in get_orders(region, category, month_start, month_end): + o = ORDERS[oid] + totals[o["product_id"]] = totals.get(o["product_id"], 0) + o["qty"] + if not totals: + return -1 + return min((-qty, pid) for pid, qty in totals.items())[1] + + +def units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int: + total = 0 + for o in DATA["orders"]: + if o["product_id"] != product_id or o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + if c["region"] == region and month_start <= o["month"] <= month_end: + total += o["qty"] + return total + + +def tickets_for_orders(order_ids: list, severity: str) -> list: + s = set(order_ids) + return sorted(t["ticket_id"] for t in DATA["tickets"] + if t["order_id"] in s and t["severity"] == severity) + + +def ticket_order_id(ticket_id: int) -> int: + return next(t["order_id"] for t in DATA["tickets"] if t["ticket_id"] == ticket_id) + + +def sla_breached(ticket_id: int, first_response_limit_hours: int, + resolution_limit_hours: int) -> bool: + t = next(x for x in DATA["tickets"] if x["ticket_id"] == ticket_id) + return (t["first_response_hours"] > first_response_limit_hours or + t["resolution_hours"] > resolution_limit_hours) + + +def delayed_orders(order_ids: list) -> list: + s = set(order_ids) + return sorted(o["order_id"] for o in DATA["orders"] + if o["order_id"] in s and o["ship_days"] > o["promised_days"]) + + +def unique_customers(order_ids: list) -> list: + return sorted({ORDERS[oid]["customer_id"] for oid in order_ids}) + + +def count_items(values: list) -> int: + return len(values) + + +def sum_values(values: list) -> int: + return sum(values) + + +def count_true(values: list) -> int: + return sum(1 for v in values if bool(v)) + + +def count_below(values: list, threshold: int) -> int: + return sum(1 for v in values if v < threshold) + + +TOOLS = { + "region_currency": ("region_currency(region: str) -> str", + "ISO currency code for a region.", region_currency), + "get_orders": ("get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]", + "Paid/refunded order ids for a region, product category, and inclusive month window.", + get_orders), + "order_gross_usd": ("order_gross_usd(order_id: int) -> int", + "Gross order revenue in USD before discounts/refunds.", order_gross_usd), + "order_margin_usd": ("order_margin_usd(order_id: int) -> int", + "Gross order margin in USD before discounts/refunds.", order_margin_usd), + "refund_usd": ("refund_usd(order_id: int) -> int", + "Refund amount in USD for returned quantity on an order.", refund_usd), + "customer_tier": ("customer_tier(order_id: int) -> str", + "Customer loyalty tier for an order.", customer_tier), + "apply_discount": ("apply_discount(amount_usd: int, tier: str) -> int", + "Apply the order customer's loyalty discount to a USD amount.", apply_discount), + "net_revenue_usd": ("net_revenue_usd(order_id: int) -> int", + "Net USD revenue after loyalty discount and refunds.", net_revenue_usd), + "to_local": ("to_local(amount_usd: int, currency: str) -> int", + "Convert a USD integer amount to a local-currency integer.", to_local), + "inventory_position": ("inventory_position(product_id: int, region: str) -> int", + "Available inventory position: on_hand - reserved + inbound.", + inventory_position), + "product_lead_time": ("product_lead_time(product_id: int) -> int", + "Supplier lead time in days for a product.", product_lead_time), + "product_id_for_top_seller": ( + "product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int", + "Product id with the highest units sold in a region/category/month window.", + product_id_for_top_seller), + "units_sold": ("units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int", + "Units sold for one product in a region and month window.", units_sold), + "tickets_for_orders": ("tickets_for_orders(order_ids: list[int], severity: str) -> list[int]", + "Support ticket ids for given orders and severity.", tickets_for_orders), + "ticket_order_id": ("ticket_order_id(ticket_id: int) -> int", + "Order id associated with a support ticket.", ticket_order_id), + "sla_breached": ( + "sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool", + "Whether a support ticket breaches first-response or resolution SLA.", + sla_breached), + "delayed_orders": ("delayed_orders(order_ids: list[int]) -> list[int]", + "Subset of order ids whose ship_days exceeded promised_days.", delayed_orders), + "unique_customers": ("unique_customers(order_ids: list[int]) -> list[int]", + "Unique customer ids among the given orders.", unique_customers), + "count_items": ("count_items(values: list) -> int", "Length of a list.", count_items), + "sum_values": ("sum_values(values: list[int]) -> int", "Sum a list of integers.", sum_values), + "count_true": ("count_true(values: list[bool]) -> int", "Count true values.", count_true), + "count_below": ("count_below(values: list[int], threshold: int) -> int", + "Count values below a threshold.", count_below), +} + +__all__ = [name for name in TOOLS.keys()] + ['TOOLS'] diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t2/environment/task.json b/harbor/tasks/v3_depth6_delay_sla_burden_t2/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..9b9783d9e02ceda2752897923805871de44c6d84 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t2/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth6_delay_sla_burden_t2", + "depth": 6, + "family": "delay_sla_burden", + "params": { + "region": "EU", + "category": "C", + "month_start": 202601, + "month_end": 202604 + }, + "question": "For region EU, category C, months 202601-202604: get the orders, count delayed orders where ship_days exceeded promised_days, find high and critical support tickets for those orders, count tickets that breach a 24-hour first-response or 120-hour resolution SLA, and report delayed_order_count + breached_ticket_count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t2/instruction.md b/harbor/tasks/v3_depth6_delay_sla_burden_t2/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..b7a18ef5d579a3c622371f9975f4e7b6509d2f07 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t2/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For region EU, category C, months 202601-202604: get the orders, count delayed orders where ship_days exceeded promised_days, find high and critical support tickets for those orders, count tickets that breach a 24-hour first-response or 120-hour resolution SLA, and report delayed_order_count + breached_ticket_count. + +Available tools: +- `region_currency(region: str) -> str`: ISO currency code for a region. +- `get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]`: Paid/refunded order ids for a region, product category, and inclusive month window. +- `order_gross_usd(order_id: int) -> int`: Gross order revenue in USD before discounts/refunds. +- `order_margin_usd(order_id: int) -> int`: Gross order margin in USD before discounts/refunds. +- `refund_usd(order_id: int) -> int`: Refund amount in USD for returned quantity on an order. +- `customer_tier(order_id: int) -> str`: Customer loyalty tier for an order. +- `apply_discount(amount_usd: int, tier: str) -> int`: Apply the order customer's loyalty discount to a USD amount. +- `net_revenue_usd(order_id: int) -> int`: Net USD revenue after loyalty discount and refunds. +- `to_local(amount_usd: int, currency: str) -> int`: Convert a USD integer amount to a local-currency integer. +- `inventory_position(product_id: int, region: str) -> int`: Available inventory position: on_hand - reserved + inbound. +- `product_lead_time(product_id: int) -> int`: Supplier lead time in days for a product. +- `product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int`: Product id with the highest units sold in a region/category/month window. +- `units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int`: Units sold for one product in a region and month window. +- `tickets_for_orders(order_ids: list[int], severity: str) -> list[int]`: Support ticket ids for given orders and severity. +- `ticket_order_id(ticket_id: int) -> int`: Order id associated with a support ticket. +- `sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool`: Whether a support ticket breaches first-response or resolution SLA. +- `delayed_orders(order_ids: list[int]) -> list[int]`: Subset of order ids whose ship_days exceeded promised_days. +- `unique_customers(order_ids: list[int]) -> list[int]`: Unique customer ids among the given orders. +- `count_items(values: list) -> int`: Length of a list. +- `sum_values(values: list[int]) -> int`: Sum a list of integers. +- `count_true(values: list[bool]) -> int`: Count true values. +- `count_below(values: list[int], threshold: int) -> int`: Count values below a threshold. diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t2/task.toml b/harbor/tasks/v3_depth6_delay_sla_burden_t2/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..7bce73f10760daa991a2bba5c11789172ebf8c72 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t2/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth6_delay_sla_burden_t2" +description = "FlowBench v3 public task metadata. Public verifier is smoke-only." +authors = [{ name = "Mind Lab", email = "contact@mindlab.ltd" }] +keywords = ["flowbench", "tool-use", "data-orchestration", "operations"] + +[metadata] +benchmark = "FlowBench-v3" +split = "public-task-only" +category = "data-processing" +depth = 6 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +network_mode = "no-network" +build_timeout_sec = 600.0 +os = "linux" +cpus = 1 +memory_mb = 2048 +storage_mb = 2048 +gpus = 0 diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t2/tests/check_output_shape.py b/harbor/tasks/v3_depth6_delay_sla_burden_t2/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t2/tests/check_output_shape.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import json +import os +import re +from pathlib import Path + + +def write_reward(score: float, diagnostic: str) -> None: + log_dir = Path(os.environ.get("LOG_DIR", "/logs/verifier")) + log_dir.mkdir(parents=True, exist_ok=True) + (log_dir / "reward.txt").write_text(f"{score:.6g}\n") + (log_dir / "reward.json").write_text( + json.dumps({"reward": score, "smoke_only": True}, indent=2) + "\n" + ) + (log_dir / "diagnostic.txt").write_text(diagnostic + "\n") + + +def main() -> int: + app_dir = Path(os.environ.get("APP_DIR", "/app")) + task = json.loads((app_dir / "task.json").read_text()) + answer_path = app_dir / "answer.txt" + if not answer_path.exists(): + write_reward(0.0, "missing /app/answer.txt") + return 1 + + got = answer_path.read_text().strip() + if task["answer_format"] == "exact integer": + ok = bool(re.fullmatch(r"-?\d+", got)) + diagnostic = "valid integer smoke output" if ok else f"not an exact integer: {got!r}" + else: + ok = bool(re.fullmatch(r"[A-Za-z]+", got)) + diagnostic = "valid code smoke output" if ok else f"not an exact code: {got!r}" + + # This is intentionally not official scoring; it only verifies I/O shape. + write_reward(1.0 if ok else 0.0, diagnostic) + return 0 if ok else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t2/tests/test.sh b/harbor/tasks/v3_depth6_delay_sla_burden_t2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t2/tests/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -u +python /tests/check_output_shape.py diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t20/environment/Dockerfile b/harbor/tasks/v3_depth6_delay_sla_burden_t20/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t20/environment/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.12-slim +WORKDIR /app +COPY flowbench_tools.py /app/flowbench_tools.py +COPY task.json /app/task.json diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t20/environment/flowbench_tools.py b/harbor/tasks/v3_depth6_delay_sla_burden_t20/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t20/environment/flowbench_tools.py @@ -0,0 +1,311 @@ +"""Deterministic FlowBench v3 tools. This file contains no task answers.""" + + +REGIONS = ["NA", "EU", "APAC", "LATAM"] +CATEGORIES = ["A", "B", "C", "D"] +CURRENCIES = {"NA": "USD", "EU": "EUR", "APAC": "JPY", "LATAM": "BRL"} +FX_TO_USD_BP = {"USD": 10000, "EUR": 10900, "JPY": 67, "BRL": 1850} +TIERS = ["std", "gold", "plat"] +DISCOUNT_PCT = {"std": 0, "gold": 10, "plat": 20} +CHANNELS = ["web", "store", "partner"] +MONTHS = [202601, 202602, 202603, 202604, 202605, 202606] + +N_CUSTOMERS = 72 +N_PRODUCTS = 48 +N_ORDERS = 720 +N_TICKETS = 260 +N_RETURNS = 180 + + +def _h(*xs): + import hashlib + s = "|".join(str(x) for x in xs).encode() + return int.from_bytes(hashlib.sha256(s).digest()[:8], "big") & 0x7FFFFFFF + + +def build_data(): + customers = [] + for cid in range(N_CUSTOMERS): + region = REGIONS[_h("region", cid) % len(REGIONS)] + customers.append({ + "customer_id": cid, + "region": region, + "tier": TIERS[_h("tier", cid) % len(TIERS)], + "segment": ["consumer", "smb", "enterprise"][_h("segment", cid) % 3], + }) + + products = [] + for pid in range(N_PRODUCTS): + cat = CATEGORIES[_h("cat", pid) % len(CATEGORIES)] + unit_price = 12 + _h("price", pid) % 240 + cogs = unit_price * (45 + _h("margin", pid) % 35) // 100 + products.append({ + "product_id": pid, + "category": cat, + "unit_price_usd": unit_price, + "unit_cogs_usd": cogs, + "lead_time_days": 3 + _h("lead", pid) % 18, + }) + + inventory = [] + for pid in range(N_PRODUCTS): + for region in REGIONS: + inventory.append({ + "product_id": pid, + "region": region, + "on_hand": 10 + _h("onhand", pid, region) % 140, + "reserved": _h("reserved", pid, region) % 28, + "inbound": _h("inbound", pid, region) % 85, + }) + + orders = [] + for oid in range(N_ORDERS): + customer_id = _h("ocust", oid) % N_CUSTOMERS + product_id = _h("oprod", oid) % N_PRODUCTS + month = MONTHS[_h("month", oid) % len(MONTHS)] + qty = 1 + _h("qty", oid) % 9 + ship_days = 1 + _h("shipdays", oid) % 16 + promised_days = 3 + _h("promise", oid) % 9 + status = ["paid", "paid", "paid", "paid", "cancelled", "refunded"][ + _h("status", oid) % 6] + orders.append({ + "order_id": oid, + "customer_id": customer_id, + "product_id": product_id, + "month": month, + "qty": qty, + "status": status, + "channel": CHANNELS[_h("channel", oid) % len(CHANNELS)], + "ship_days": ship_days, + "promised_days": promised_days, + }) + + returns = [] + for rid in range(N_RETURNS): + oid = _h("roid", rid) % N_ORDERS + order = orders[oid] + if order["status"] == "cancelled": + continue + returned_qty = 1 + _h("rqty", rid) % max(1, order["qty"]) + reason = ["defect", "late", "changed_mind", "wrong_item"][_h("reason", rid) % 4] + returns.append({ + "return_id": rid, + "order_id": oid, + "month": MONTHS[_h("rmonth", rid) % len(MONTHS)], + "returned_qty": returned_qty, + "reason": reason, + }) + + tickets = [] + for tid in range(N_TICKETS): + oid = _h("toid", tid) % N_ORDERS + severity = ["low", "medium", "high", "critical"][_h("sev", tid) % 4] + opened = MONTHS[_h("tmonth", tid) % len(MONTHS)] + first_response_hours = 1 + _h("resp", tid) % 96 + resolution_hours = first_response_hours + _h("res", tid) % 240 + tickets.append({ + "ticket_id": tid, + "order_id": oid, + "opened_month": opened, + "severity": severity, + "first_response_hours": first_response_hours, + "resolution_hours": resolution_hours, + }) + + return { + "customers": customers, + "products": products, + "inventory": inventory, + "orders": orders, + "returns": returns, + "tickets": tickets, + "fx_to_usd_bp": FX_TO_USD_BP, + } + + +DATA = build_data() +CUSTOMERS = {c["customer_id"]: c for c in DATA["customers"]} +PRODUCTS = {p["product_id"]: p for p in DATA["products"]} +ORDERS = {o["order_id"]: o for o in DATA["orders"]} + + +def region_currency(region: str) -> str: + return CURRENCIES[region] + + +def get_orders(region: str, category: str, month_start: int, month_end: int) -> list: + """Paid/refunded order ids in a region/category/month window.""" + out = [] + for o in DATA["orders"]: + if o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + p = PRODUCTS[o["product_id"]] + if c["region"] == region and p["category"] == category and month_start <= o["month"] <= month_end: + out.append(o["order_id"]) + return sorted(out) + + +def order_gross_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * p["unit_price_usd"] + + +def order_margin_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * (p["unit_price_usd"] - p["unit_cogs_usd"]) + + +def refund_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + qty = sum(r["returned_qty"] for r in DATA["returns"] if r["order_id"] == order_id) + qty = min(qty, o["qty"]) + return qty * p["unit_price_usd"] + + +def customer_tier(order_id: int) -> str: + o = ORDERS[order_id] + return CUSTOMERS[o["customer_id"]]["tier"] + + +def apply_discount(amount_usd: int, tier: str) -> int: + return amount_usd * (100 - DISCOUNT_PCT[tier]) // 100 + + +def net_revenue_usd(order_id: int) -> int: + gross = apply_discount(order_gross_usd(order_id), customer_tier(order_id)) + return max(0, gross - refund_usd(order_id)) + + +def to_local(amount_usd: int, currency: str) -> int: + return amount_usd * 10000 // FX_TO_USD_BP[currency] + + +def inventory_position(product_id: int, region: str) -> int: + row = next(x for x in DATA["inventory"] + if x["product_id"] == product_id and x["region"] == region) + return row["on_hand"] - row["reserved"] + row["inbound"] + + +def product_lead_time(product_id: int) -> int: + return PRODUCTS[product_id]["lead_time_days"] + + +def product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int: + totals = {} + for oid in get_orders(region, category, month_start, month_end): + o = ORDERS[oid] + totals[o["product_id"]] = totals.get(o["product_id"], 0) + o["qty"] + if not totals: + return -1 + return min((-qty, pid) for pid, qty in totals.items())[1] + + +def units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int: + total = 0 + for o in DATA["orders"]: + if o["product_id"] != product_id or o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + if c["region"] == region and month_start <= o["month"] <= month_end: + total += o["qty"] + return total + + +def tickets_for_orders(order_ids: list, severity: str) -> list: + s = set(order_ids) + return sorted(t["ticket_id"] for t in DATA["tickets"] + if t["order_id"] in s and t["severity"] == severity) + + +def ticket_order_id(ticket_id: int) -> int: + return next(t["order_id"] for t in DATA["tickets"] if t["ticket_id"] == ticket_id) + + +def sla_breached(ticket_id: int, first_response_limit_hours: int, + resolution_limit_hours: int) -> bool: + t = next(x for x in DATA["tickets"] if x["ticket_id"] == ticket_id) + return (t["first_response_hours"] > first_response_limit_hours or + t["resolution_hours"] > resolution_limit_hours) + + +def delayed_orders(order_ids: list) -> list: + s = set(order_ids) + return sorted(o["order_id"] for o in DATA["orders"] + if o["order_id"] in s and o["ship_days"] > o["promised_days"]) + + +def unique_customers(order_ids: list) -> list: + return sorted({ORDERS[oid]["customer_id"] for oid in order_ids}) + + +def count_items(values: list) -> int: + return len(values) + + +def sum_values(values: list) -> int: + return sum(values) + + +def count_true(values: list) -> int: + return sum(1 for v in values if bool(v)) + + +def count_below(values: list, threshold: int) -> int: + return sum(1 for v in values if v < threshold) + + +TOOLS = { + "region_currency": ("region_currency(region: str) -> str", + "ISO currency code for a region.", region_currency), + "get_orders": ("get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]", + "Paid/refunded order ids for a region, product category, and inclusive month window.", + get_orders), + "order_gross_usd": ("order_gross_usd(order_id: int) -> int", + "Gross order revenue in USD before discounts/refunds.", order_gross_usd), + "order_margin_usd": ("order_margin_usd(order_id: int) -> int", + "Gross order margin in USD before discounts/refunds.", order_margin_usd), + "refund_usd": ("refund_usd(order_id: int) -> int", + "Refund amount in USD for returned quantity on an order.", refund_usd), + "customer_tier": ("customer_tier(order_id: int) -> str", + "Customer loyalty tier for an order.", customer_tier), + "apply_discount": ("apply_discount(amount_usd: int, tier: str) -> int", + "Apply the order customer's loyalty discount to a USD amount.", apply_discount), + "net_revenue_usd": ("net_revenue_usd(order_id: int) -> int", + "Net USD revenue after loyalty discount and refunds.", net_revenue_usd), + "to_local": ("to_local(amount_usd: int, currency: str) -> int", + "Convert a USD integer amount to a local-currency integer.", to_local), + "inventory_position": ("inventory_position(product_id: int, region: str) -> int", + "Available inventory position: on_hand - reserved + inbound.", + inventory_position), + "product_lead_time": ("product_lead_time(product_id: int) -> int", + "Supplier lead time in days for a product.", product_lead_time), + "product_id_for_top_seller": ( + "product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int", + "Product id with the highest units sold in a region/category/month window.", + product_id_for_top_seller), + "units_sold": ("units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int", + "Units sold for one product in a region and month window.", units_sold), + "tickets_for_orders": ("tickets_for_orders(order_ids: list[int], severity: str) -> list[int]", + "Support ticket ids for given orders and severity.", tickets_for_orders), + "ticket_order_id": ("ticket_order_id(ticket_id: int) -> int", + "Order id associated with a support ticket.", ticket_order_id), + "sla_breached": ( + "sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool", + "Whether a support ticket breaches first-response or resolution SLA.", + sla_breached), + "delayed_orders": ("delayed_orders(order_ids: list[int]) -> list[int]", + "Subset of order ids whose ship_days exceeded promised_days.", delayed_orders), + "unique_customers": ("unique_customers(order_ids: list[int]) -> list[int]", + "Unique customer ids among the given orders.", unique_customers), + "count_items": ("count_items(values: list) -> int", "Length of a list.", count_items), + "sum_values": ("sum_values(values: list[int]) -> int", "Sum a list of integers.", sum_values), + "count_true": ("count_true(values: list[bool]) -> int", "Count true values.", count_true), + "count_below": ("count_below(values: list[int], threshold: int) -> int", + "Count values below a threshold.", count_below), +} + +__all__ = [name for name in TOOLS.keys()] + ['TOOLS'] diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t20/environment/task.json b/harbor/tasks/v3_depth6_delay_sla_burden_t20/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..ba10b30d403dd601a52a37db3648017341e08991 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t20/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth6_delay_sla_burden_t20", + "depth": 6, + "family": "delay_sla_burden", + "params": { + "region": "NA", + "category": "C", + "month_start": 202602, + "month_end": 202604 + }, + "question": "For region NA, category C, months 202602-202604: get the orders, count delayed orders where ship_days exceeded promised_days, find high and critical support tickets for those orders, count tickets that breach a 24-hour first-response or 120-hour resolution SLA, and report delayed_order_count + breached_ticket_count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t20/instruction.md b/harbor/tasks/v3_depth6_delay_sla_burden_t20/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..8687b27948ee12897e79a639ebe58d5f5b0b48e3 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t20/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For region NA, category C, months 202602-202604: get the orders, count delayed orders where ship_days exceeded promised_days, find high and critical support tickets for those orders, count tickets that breach a 24-hour first-response or 120-hour resolution SLA, and report delayed_order_count + breached_ticket_count. + +Available tools: +- `region_currency(region: str) -> str`: ISO currency code for a region. +- `get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]`: Paid/refunded order ids for a region, product category, and inclusive month window. +- `order_gross_usd(order_id: int) -> int`: Gross order revenue in USD before discounts/refunds. +- `order_margin_usd(order_id: int) -> int`: Gross order margin in USD before discounts/refunds. +- `refund_usd(order_id: int) -> int`: Refund amount in USD for returned quantity on an order. +- `customer_tier(order_id: int) -> str`: Customer loyalty tier for an order. +- `apply_discount(amount_usd: int, tier: str) -> int`: Apply the order customer's loyalty discount to a USD amount. +- `net_revenue_usd(order_id: int) -> int`: Net USD revenue after loyalty discount and refunds. +- `to_local(amount_usd: int, currency: str) -> int`: Convert a USD integer amount to a local-currency integer. +- `inventory_position(product_id: int, region: str) -> int`: Available inventory position: on_hand - reserved + inbound. +- `product_lead_time(product_id: int) -> int`: Supplier lead time in days for a product. +- `product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int`: Product id with the highest units sold in a region/category/month window. +- `units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int`: Units sold for one product in a region and month window. +- `tickets_for_orders(order_ids: list[int], severity: str) -> list[int]`: Support ticket ids for given orders and severity. +- `ticket_order_id(ticket_id: int) -> int`: Order id associated with a support ticket. +- `sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool`: Whether a support ticket breaches first-response or resolution SLA. +- `delayed_orders(order_ids: list[int]) -> list[int]`: Subset of order ids whose ship_days exceeded promised_days. +- `unique_customers(order_ids: list[int]) -> list[int]`: Unique customer ids among the given orders. +- `count_items(values: list) -> int`: Length of a list. +- `sum_values(values: list[int]) -> int`: Sum a list of integers. +- `count_true(values: list[bool]) -> int`: Count true values. +- `count_below(values: list[int], threshold: int) -> int`: Count values below a threshold. diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t20/task.toml b/harbor/tasks/v3_depth6_delay_sla_burden_t20/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..7c0f1ba11e02f537a9374be94ef03507c5387a61 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t20/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth6_delay_sla_burden_t20" +description = "FlowBench v3 public task metadata. Public verifier is smoke-only." +authors = [{ name = "Mind Lab", email = "contact@mindlab.ltd" }] +keywords = ["flowbench", "tool-use", "data-orchestration", "operations"] + +[metadata] +benchmark = "FlowBench-v3" +split = "public-task-only" +category = "data-processing" +depth = 6 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +network_mode = "no-network" +build_timeout_sec = 600.0 +os = "linux" +cpus = 1 +memory_mb = 2048 +storage_mb = 2048 +gpus = 0 diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t20/tests/check_output_shape.py b/harbor/tasks/v3_depth6_delay_sla_burden_t20/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t20/tests/check_output_shape.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import json +import os +import re +from pathlib import Path + + +def write_reward(score: float, diagnostic: str) -> None: + log_dir = Path(os.environ.get("LOG_DIR", "/logs/verifier")) + log_dir.mkdir(parents=True, exist_ok=True) + (log_dir / "reward.txt").write_text(f"{score:.6g}\n") + (log_dir / "reward.json").write_text( + json.dumps({"reward": score, "smoke_only": True}, indent=2) + "\n" + ) + (log_dir / "diagnostic.txt").write_text(diagnostic + "\n") + + +def main() -> int: + app_dir = Path(os.environ.get("APP_DIR", "/app")) + task = json.loads((app_dir / "task.json").read_text()) + answer_path = app_dir / "answer.txt" + if not answer_path.exists(): + write_reward(0.0, "missing /app/answer.txt") + return 1 + + got = answer_path.read_text().strip() + if task["answer_format"] == "exact integer": + ok = bool(re.fullmatch(r"-?\d+", got)) + diagnostic = "valid integer smoke output" if ok else f"not an exact integer: {got!r}" + else: + ok = bool(re.fullmatch(r"[A-Za-z]+", got)) + diagnostic = "valid code smoke output" if ok else f"not an exact code: {got!r}" + + # This is intentionally not official scoring; it only verifies I/O shape. + write_reward(1.0 if ok else 0.0, diagnostic) + return 0 if ok else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t20/tests/test.sh b/harbor/tasks/v3_depth6_delay_sla_burden_t20/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t20/tests/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -u +python /tests/check_output_shape.py diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t21/environment/Dockerfile b/harbor/tasks/v3_depth6_delay_sla_burden_t21/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t21/environment/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.12-slim +WORKDIR /app +COPY flowbench_tools.py /app/flowbench_tools.py +COPY task.json /app/task.json diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t21/environment/flowbench_tools.py b/harbor/tasks/v3_depth6_delay_sla_burden_t21/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t21/environment/flowbench_tools.py @@ -0,0 +1,311 @@ +"""Deterministic FlowBench v3 tools. This file contains no task answers.""" + + +REGIONS = ["NA", "EU", "APAC", "LATAM"] +CATEGORIES = ["A", "B", "C", "D"] +CURRENCIES = {"NA": "USD", "EU": "EUR", "APAC": "JPY", "LATAM": "BRL"} +FX_TO_USD_BP = {"USD": 10000, "EUR": 10900, "JPY": 67, "BRL": 1850} +TIERS = ["std", "gold", "plat"] +DISCOUNT_PCT = {"std": 0, "gold": 10, "plat": 20} +CHANNELS = ["web", "store", "partner"] +MONTHS = [202601, 202602, 202603, 202604, 202605, 202606] + +N_CUSTOMERS = 72 +N_PRODUCTS = 48 +N_ORDERS = 720 +N_TICKETS = 260 +N_RETURNS = 180 + + +def _h(*xs): + import hashlib + s = "|".join(str(x) for x in xs).encode() + return int.from_bytes(hashlib.sha256(s).digest()[:8], "big") & 0x7FFFFFFF + + +def build_data(): + customers = [] + for cid in range(N_CUSTOMERS): + region = REGIONS[_h("region", cid) % len(REGIONS)] + customers.append({ + "customer_id": cid, + "region": region, + "tier": TIERS[_h("tier", cid) % len(TIERS)], + "segment": ["consumer", "smb", "enterprise"][_h("segment", cid) % 3], + }) + + products = [] + for pid in range(N_PRODUCTS): + cat = CATEGORIES[_h("cat", pid) % len(CATEGORIES)] + unit_price = 12 + _h("price", pid) % 240 + cogs = unit_price * (45 + _h("margin", pid) % 35) // 100 + products.append({ + "product_id": pid, + "category": cat, + "unit_price_usd": unit_price, + "unit_cogs_usd": cogs, + "lead_time_days": 3 + _h("lead", pid) % 18, + }) + + inventory = [] + for pid in range(N_PRODUCTS): + for region in REGIONS: + inventory.append({ + "product_id": pid, + "region": region, + "on_hand": 10 + _h("onhand", pid, region) % 140, + "reserved": _h("reserved", pid, region) % 28, + "inbound": _h("inbound", pid, region) % 85, + }) + + orders = [] + for oid in range(N_ORDERS): + customer_id = _h("ocust", oid) % N_CUSTOMERS + product_id = _h("oprod", oid) % N_PRODUCTS + month = MONTHS[_h("month", oid) % len(MONTHS)] + qty = 1 + _h("qty", oid) % 9 + ship_days = 1 + _h("shipdays", oid) % 16 + promised_days = 3 + _h("promise", oid) % 9 + status = ["paid", "paid", "paid", "paid", "cancelled", "refunded"][ + _h("status", oid) % 6] + orders.append({ + "order_id": oid, + "customer_id": customer_id, + "product_id": product_id, + "month": month, + "qty": qty, + "status": status, + "channel": CHANNELS[_h("channel", oid) % len(CHANNELS)], + "ship_days": ship_days, + "promised_days": promised_days, + }) + + returns = [] + for rid in range(N_RETURNS): + oid = _h("roid", rid) % N_ORDERS + order = orders[oid] + if order["status"] == "cancelled": + continue + returned_qty = 1 + _h("rqty", rid) % max(1, order["qty"]) + reason = ["defect", "late", "changed_mind", "wrong_item"][_h("reason", rid) % 4] + returns.append({ + "return_id": rid, + "order_id": oid, + "month": MONTHS[_h("rmonth", rid) % len(MONTHS)], + "returned_qty": returned_qty, + "reason": reason, + }) + + tickets = [] + for tid in range(N_TICKETS): + oid = _h("toid", tid) % N_ORDERS + severity = ["low", "medium", "high", "critical"][_h("sev", tid) % 4] + opened = MONTHS[_h("tmonth", tid) % len(MONTHS)] + first_response_hours = 1 + _h("resp", tid) % 96 + resolution_hours = first_response_hours + _h("res", tid) % 240 + tickets.append({ + "ticket_id": tid, + "order_id": oid, + "opened_month": opened, + "severity": severity, + "first_response_hours": first_response_hours, + "resolution_hours": resolution_hours, + }) + + return { + "customers": customers, + "products": products, + "inventory": inventory, + "orders": orders, + "returns": returns, + "tickets": tickets, + "fx_to_usd_bp": FX_TO_USD_BP, + } + + +DATA = build_data() +CUSTOMERS = {c["customer_id"]: c for c in DATA["customers"]} +PRODUCTS = {p["product_id"]: p for p in DATA["products"]} +ORDERS = {o["order_id"]: o for o in DATA["orders"]} + + +def region_currency(region: str) -> str: + return CURRENCIES[region] + + +def get_orders(region: str, category: str, month_start: int, month_end: int) -> list: + """Paid/refunded order ids in a region/category/month window.""" + out = [] + for o in DATA["orders"]: + if o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + p = PRODUCTS[o["product_id"]] + if c["region"] == region and p["category"] == category and month_start <= o["month"] <= month_end: + out.append(o["order_id"]) + return sorted(out) + + +def order_gross_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * p["unit_price_usd"] + + +def order_margin_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * (p["unit_price_usd"] - p["unit_cogs_usd"]) + + +def refund_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + qty = sum(r["returned_qty"] for r in DATA["returns"] if r["order_id"] == order_id) + qty = min(qty, o["qty"]) + return qty * p["unit_price_usd"] + + +def customer_tier(order_id: int) -> str: + o = ORDERS[order_id] + return CUSTOMERS[o["customer_id"]]["tier"] + + +def apply_discount(amount_usd: int, tier: str) -> int: + return amount_usd * (100 - DISCOUNT_PCT[tier]) // 100 + + +def net_revenue_usd(order_id: int) -> int: + gross = apply_discount(order_gross_usd(order_id), customer_tier(order_id)) + return max(0, gross - refund_usd(order_id)) + + +def to_local(amount_usd: int, currency: str) -> int: + return amount_usd * 10000 // FX_TO_USD_BP[currency] + + +def inventory_position(product_id: int, region: str) -> int: + row = next(x for x in DATA["inventory"] + if x["product_id"] == product_id and x["region"] == region) + return row["on_hand"] - row["reserved"] + row["inbound"] + + +def product_lead_time(product_id: int) -> int: + return PRODUCTS[product_id]["lead_time_days"] + + +def product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int: + totals = {} + for oid in get_orders(region, category, month_start, month_end): + o = ORDERS[oid] + totals[o["product_id"]] = totals.get(o["product_id"], 0) + o["qty"] + if not totals: + return -1 + return min((-qty, pid) for pid, qty in totals.items())[1] + + +def units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int: + total = 0 + for o in DATA["orders"]: + if o["product_id"] != product_id or o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + if c["region"] == region and month_start <= o["month"] <= month_end: + total += o["qty"] + return total + + +def tickets_for_orders(order_ids: list, severity: str) -> list: + s = set(order_ids) + return sorted(t["ticket_id"] for t in DATA["tickets"] + if t["order_id"] in s and t["severity"] == severity) + + +def ticket_order_id(ticket_id: int) -> int: + return next(t["order_id"] for t in DATA["tickets"] if t["ticket_id"] == ticket_id) + + +def sla_breached(ticket_id: int, first_response_limit_hours: int, + resolution_limit_hours: int) -> bool: + t = next(x for x in DATA["tickets"] if x["ticket_id"] == ticket_id) + return (t["first_response_hours"] > first_response_limit_hours or + t["resolution_hours"] > resolution_limit_hours) + + +def delayed_orders(order_ids: list) -> list: + s = set(order_ids) + return sorted(o["order_id"] for o in DATA["orders"] + if o["order_id"] in s and o["ship_days"] > o["promised_days"]) + + +def unique_customers(order_ids: list) -> list: + return sorted({ORDERS[oid]["customer_id"] for oid in order_ids}) + + +def count_items(values: list) -> int: + return len(values) + + +def sum_values(values: list) -> int: + return sum(values) + + +def count_true(values: list) -> int: + return sum(1 for v in values if bool(v)) + + +def count_below(values: list, threshold: int) -> int: + return sum(1 for v in values if v < threshold) + + +TOOLS = { + "region_currency": ("region_currency(region: str) -> str", + "ISO currency code for a region.", region_currency), + "get_orders": ("get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]", + "Paid/refunded order ids for a region, product category, and inclusive month window.", + get_orders), + "order_gross_usd": ("order_gross_usd(order_id: int) -> int", + "Gross order revenue in USD before discounts/refunds.", order_gross_usd), + "order_margin_usd": ("order_margin_usd(order_id: int) -> int", + "Gross order margin in USD before discounts/refunds.", order_margin_usd), + "refund_usd": ("refund_usd(order_id: int) -> int", + "Refund amount in USD for returned quantity on an order.", refund_usd), + "customer_tier": ("customer_tier(order_id: int) -> str", + "Customer loyalty tier for an order.", customer_tier), + "apply_discount": ("apply_discount(amount_usd: int, tier: str) -> int", + "Apply the order customer's loyalty discount to a USD amount.", apply_discount), + "net_revenue_usd": ("net_revenue_usd(order_id: int) -> int", + "Net USD revenue after loyalty discount and refunds.", net_revenue_usd), + "to_local": ("to_local(amount_usd: int, currency: str) -> int", + "Convert a USD integer amount to a local-currency integer.", to_local), + "inventory_position": ("inventory_position(product_id: int, region: str) -> int", + "Available inventory position: on_hand - reserved + inbound.", + inventory_position), + "product_lead_time": ("product_lead_time(product_id: int) -> int", + "Supplier lead time in days for a product.", product_lead_time), + "product_id_for_top_seller": ( + "product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int", + "Product id with the highest units sold in a region/category/month window.", + product_id_for_top_seller), + "units_sold": ("units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int", + "Units sold for one product in a region and month window.", units_sold), + "tickets_for_orders": ("tickets_for_orders(order_ids: list[int], severity: str) -> list[int]", + "Support ticket ids for given orders and severity.", tickets_for_orders), + "ticket_order_id": ("ticket_order_id(ticket_id: int) -> int", + "Order id associated with a support ticket.", ticket_order_id), + "sla_breached": ( + "sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool", + "Whether a support ticket breaches first-response or resolution SLA.", + sla_breached), + "delayed_orders": ("delayed_orders(order_ids: list[int]) -> list[int]", + "Subset of order ids whose ship_days exceeded promised_days.", delayed_orders), + "unique_customers": ("unique_customers(order_ids: list[int]) -> list[int]", + "Unique customer ids among the given orders.", unique_customers), + "count_items": ("count_items(values: list) -> int", "Length of a list.", count_items), + "sum_values": ("sum_values(values: list[int]) -> int", "Sum a list of integers.", sum_values), + "count_true": ("count_true(values: list[bool]) -> int", "Count true values.", count_true), + "count_below": ("count_below(values: list[int], threshold: int) -> int", + "Count values below a threshold.", count_below), +} + +__all__ = [name for name in TOOLS.keys()] + ['TOOLS'] diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t21/environment/task.json b/harbor/tasks/v3_depth6_delay_sla_burden_t21/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..a0bf595675b68182a510d626c13715b1027f7b97 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t21/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth6_delay_sla_burden_t21", + "depth": 6, + "family": "delay_sla_burden", + "params": { + "region": "EU", + "category": "B", + "month_start": 202604, + "month_end": 202606 + }, + "question": "For region EU, category B, months 202604-202606: get the orders, count delayed orders where ship_days exceeded promised_days, find high and critical support tickets for those orders, count tickets that breach a 24-hour first-response or 120-hour resolution SLA, and report delayed_order_count + breached_ticket_count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t21/instruction.md b/harbor/tasks/v3_depth6_delay_sla_burden_t21/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..015f6bb1dcb9ce175128807d635f1f7e976d4c92 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t21/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For region EU, category B, months 202604-202606: get the orders, count delayed orders where ship_days exceeded promised_days, find high and critical support tickets for those orders, count tickets that breach a 24-hour first-response or 120-hour resolution SLA, and report delayed_order_count + breached_ticket_count. + +Available tools: +- `region_currency(region: str) -> str`: ISO currency code for a region. +- `get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]`: Paid/refunded order ids for a region, product category, and inclusive month window. +- `order_gross_usd(order_id: int) -> int`: Gross order revenue in USD before discounts/refunds. +- `order_margin_usd(order_id: int) -> int`: Gross order margin in USD before discounts/refunds. +- `refund_usd(order_id: int) -> int`: Refund amount in USD for returned quantity on an order. +- `customer_tier(order_id: int) -> str`: Customer loyalty tier for an order. +- `apply_discount(amount_usd: int, tier: str) -> int`: Apply the order customer's loyalty discount to a USD amount. +- `net_revenue_usd(order_id: int) -> int`: Net USD revenue after loyalty discount and refunds. +- `to_local(amount_usd: int, currency: str) -> int`: Convert a USD integer amount to a local-currency integer. +- `inventory_position(product_id: int, region: str) -> int`: Available inventory position: on_hand - reserved + inbound. +- `product_lead_time(product_id: int) -> int`: Supplier lead time in days for a product. +- `product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int`: Product id with the highest units sold in a region/category/month window. +- `units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int`: Units sold for one product in a region and month window. +- `tickets_for_orders(order_ids: list[int], severity: str) -> list[int]`: Support ticket ids for given orders and severity. +- `ticket_order_id(ticket_id: int) -> int`: Order id associated with a support ticket. +- `sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool`: Whether a support ticket breaches first-response or resolution SLA. +- `delayed_orders(order_ids: list[int]) -> list[int]`: Subset of order ids whose ship_days exceeded promised_days. +- `unique_customers(order_ids: list[int]) -> list[int]`: Unique customer ids among the given orders. +- `count_items(values: list) -> int`: Length of a list. +- `sum_values(values: list[int]) -> int`: Sum a list of integers. +- `count_true(values: list[bool]) -> int`: Count true values. +- `count_below(values: list[int], threshold: int) -> int`: Count values below a threshold. diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t21/task.toml b/harbor/tasks/v3_depth6_delay_sla_burden_t21/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..1458d3a572507da450704a08fb3ac1fcfef26d27 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t21/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth6_delay_sla_burden_t21" +description = "FlowBench v3 public task metadata. Public verifier is smoke-only." +authors = [{ name = "Mind Lab", email = "contact@mindlab.ltd" }] +keywords = ["flowbench", "tool-use", "data-orchestration", "operations"] + +[metadata] +benchmark = "FlowBench-v3" +split = "public-task-only" +category = "data-processing" +depth = 6 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +network_mode = "no-network" +build_timeout_sec = 600.0 +os = "linux" +cpus = 1 +memory_mb = 2048 +storage_mb = 2048 +gpus = 0 diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t21/tests/check_output_shape.py b/harbor/tasks/v3_depth6_delay_sla_burden_t21/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t21/tests/check_output_shape.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import json +import os +import re +from pathlib import Path + + +def write_reward(score: float, diagnostic: str) -> None: + log_dir = Path(os.environ.get("LOG_DIR", "/logs/verifier")) + log_dir.mkdir(parents=True, exist_ok=True) + (log_dir / "reward.txt").write_text(f"{score:.6g}\n") + (log_dir / "reward.json").write_text( + json.dumps({"reward": score, "smoke_only": True}, indent=2) + "\n" + ) + (log_dir / "diagnostic.txt").write_text(diagnostic + "\n") + + +def main() -> int: + app_dir = Path(os.environ.get("APP_DIR", "/app")) + task = json.loads((app_dir / "task.json").read_text()) + answer_path = app_dir / "answer.txt" + if not answer_path.exists(): + write_reward(0.0, "missing /app/answer.txt") + return 1 + + got = answer_path.read_text().strip() + if task["answer_format"] == "exact integer": + ok = bool(re.fullmatch(r"-?\d+", got)) + diagnostic = "valid integer smoke output" if ok else f"not an exact integer: {got!r}" + else: + ok = bool(re.fullmatch(r"[A-Za-z]+", got)) + diagnostic = "valid code smoke output" if ok else f"not an exact code: {got!r}" + + # This is intentionally not official scoring; it only verifies I/O shape. + write_reward(1.0 if ok else 0.0, diagnostic) + return 0 if ok else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t21/tests/test.sh b/harbor/tasks/v3_depth6_delay_sla_burden_t21/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t21/tests/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -u +python /tests/check_output_shape.py diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t22/environment/Dockerfile b/harbor/tasks/v3_depth6_delay_sla_burden_t22/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t22/environment/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.12-slim +WORKDIR /app +COPY flowbench_tools.py /app/flowbench_tools.py +COPY task.json /app/task.json diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t22/environment/flowbench_tools.py b/harbor/tasks/v3_depth6_delay_sla_burden_t22/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t22/environment/flowbench_tools.py @@ -0,0 +1,311 @@ +"""Deterministic FlowBench v3 tools. This file contains no task answers.""" + + +REGIONS = ["NA", "EU", "APAC", "LATAM"] +CATEGORIES = ["A", "B", "C", "D"] +CURRENCIES = {"NA": "USD", "EU": "EUR", "APAC": "JPY", "LATAM": "BRL"} +FX_TO_USD_BP = {"USD": 10000, "EUR": 10900, "JPY": 67, "BRL": 1850} +TIERS = ["std", "gold", "plat"] +DISCOUNT_PCT = {"std": 0, "gold": 10, "plat": 20} +CHANNELS = ["web", "store", "partner"] +MONTHS = [202601, 202602, 202603, 202604, 202605, 202606] + +N_CUSTOMERS = 72 +N_PRODUCTS = 48 +N_ORDERS = 720 +N_TICKETS = 260 +N_RETURNS = 180 + + +def _h(*xs): + import hashlib + s = "|".join(str(x) for x in xs).encode() + return int.from_bytes(hashlib.sha256(s).digest()[:8], "big") & 0x7FFFFFFF + + +def build_data(): + customers = [] + for cid in range(N_CUSTOMERS): + region = REGIONS[_h("region", cid) % len(REGIONS)] + customers.append({ + "customer_id": cid, + "region": region, + "tier": TIERS[_h("tier", cid) % len(TIERS)], + "segment": ["consumer", "smb", "enterprise"][_h("segment", cid) % 3], + }) + + products = [] + for pid in range(N_PRODUCTS): + cat = CATEGORIES[_h("cat", pid) % len(CATEGORIES)] + unit_price = 12 + _h("price", pid) % 240 + cogs = unit_price * (45 + _h("margin", pid) % 35) // 100 + products.append({ + "product_id": pid, + "category": cat, + "unit_price_usd": unit_price, + "unit_cogs_usd": cogs, + "lead_time_days": 3 + _h("lead", pid) % 18, + }) + + inventory = [] + for pid in range(N_PRODUCTS): + for region in REGIONS: + inventory.append({ + "product_id": pid, + "region": region, + "on_hand": 10 + _h("onhand", pid, region) % 140, + "reserved": _h("reserved", pid, region) % 28, + "inbound": _h("inbound", pid, region) % 85, + }) + + orders = [] + for oid in range(N_ORDERS): + customer_id = _h("ocust", oid) % N_CUSTOMERS + product_id = _h("oprod", oid) % N_PRODUCTS + month = MONTHS[_h("month", oid) % len(MONTHS)] + qty = 1 + _h("qty", oid) % 9 + ship_days = 1 + _h("shipdays", oid) % 16 + promised_days = 3 + _h("promise", oid) % 9 + status = ["paid", "paid", "paid", "paid", "cancelled", "refunded"][ + _h("status", oid) % 6] + orders.append({ + "order_id": oid, + "customer_id": customer_id, + "product_id": product_id, + "month": month, + "qty": qty, + "status": status, + "channel": CHANNELS[_h("channel", oid) % len(CHANNELS)], + "ship_days": ship_days, + "promised_days": promised_days, + }) + + returns = [] + for rid in range(N_RETURNS): + oid = _h("roid", rid) % N_ORDERS + order = orders[oid] + if order["status"] == "cancelled": + continue + returned_qty = 1 + _h("rqty", rid) % max(1, order["qty"]) + reason = ["defect", "late", "changed_mind", "wrong_item"][_h("reason", rid) % 4] + returns.append({ + "return_id": rid, + "order_id": oid, + "month": MONTHS[_h("rmonth", rid) % len(MONTHS)], + "returned_qty": returned_qty, + "reason": reason, + }) + + tickets = [] + for tid in range(N_TICKETS): + oid = _h("toid", tid) % N_ORDERS + severity = ["low", "medium", "high", "critical"][_h("sev", tid) % 4] + opened = MONTHS[_h("tmonth", tid) % len(MONTHS)] + first_response_hours = 1 + _h("resp", tid) % 96 + resolution_hours = first_response_hours + _h("res", tid) % 240 + tickets.append({ + "ticket_id": tid, + "order_id": oid, + "opened_month": opened, + "severity": severity, + "first_response_hours": first_response_hours, + "resolution_hours": resolution_hours, + }) + + return { + "customers": customers, + "products": products, + "inventory": inventory, + "orders": orders, + "returns": returns, + "tickets": tickets, + "fx_to_usd_bp": FX_TO_USD_BP, + } + + +DATA = build_data() +CUSTOMERS = {c["customer_id"]: c for c in DATA["customers"]} +PRODUCTS = {p["product_id"]: p for p in DATA["products"]} +ORDERS = {o["order_id"]: o for o in DATA["orders"]} + + +def region_currency(region: str) -> str: + return CURRENCIES[region] + + +def get_orders(region: str, category: str, month_start: int, month_end: int) -> list: + """Paid/refunded order ids in a region/category/month window.""" + out = [] + for o in DATA["orders"]: + if o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + p = PRODUCTS[o["product_id"]] + if c["region"] == region and p["category"] == category and month_start <= o["month"] <= month_end: + out.append(o["order_id"]) + return sorted(out) + + +def order_gross_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * p["unit_price_usd"] + + +def order_margin_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * (p["unit_price_usd"] - p["unit_cogs_usd"]) + + +def refund_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + qty = sum(r["returned_qty"] for r in DATA["returns"] if r["order_id"] == order_id) + qty = min(qty, o["qty"]) + return qty * p["unit_price_usd"] + + +def customer_tier(order_id: int) -> str: + o = ORDERS[order_id] + return CUSTOMERS[o["customer_id"]]["tier"] + + +def apply_discount(amount_usd: int, tier: str) -> int: + return amount_usd * (100 - DISCOUNT_PCT[tier]) // 100 + + +def net_revenue_usd(order_id: int) -> int: + gross = apply_discount(order_gross_usd(order_id), customer_tier(order_id)) + return max(0, gross - refund_usd(order_id)) + + +def to_local(amount_usd: int, currency: str) -> int: + return amount_usd * 10000 // FX_TO_USD_BP[currency] + + +def inventory_position(product_id: int, region: str) -> int: + row = next(x for x in DATA["inventory"] + if x["product_id"] == product_id and x["region"] == region) + return row["on_hand"] - row["reserved"] + row["inbound"] + + +def product_lead_time(product_id: int) -> int: + return PRODUCTS[product_id]["lead_time_days"] + + +def product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int: + totals = {} + for oid in get_orders(region, category, month_start, month_end): + o = ORDERS[oid] + totals[o["product_id"]] = totals.get(o["product_id"], 0) + o["qty"] + if not totals: + return -1 + return min((-qty, pid) for pid, qty in totals.items())[1] + + +def units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int: + total = 0 + for o in DATA["orders"]: + if o["product_id"] != product_id or o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + if c["region"] == region and month_start <= o["month"] <= month_end: + total += o["qty"] + return total + + +def tickets_for_orders(order_ids: list, severity: str) -> list: + s = set(order_ids) + return sorted(t["ticket_id"] for t in DATA["tickets"] + if t["order_id"] in s and t["severity"] == severity) + + +def ticket_order_id(ticket_id: int) -> int: + return next(t["order_id"] for t in DATA["tickets"] if t["ticket_id"] == ticket_id) + + +def sla_breached(ticket_id: int, first_response_limit_hours: int, + resolution_limit_hours: int) -> bool: + t = next(x for x in DATA["tickets"] if x["ticket_id"] == ticket_id) + return (t["first_response_hours"] > first_response_limit_hours or + t["resolution_hours"] > resolution_limit_hours) + + +def delayed_orders(order_ids: list) -> list: + s = set(order_ids) + return sorted(o["order_id"] for o in DATA["orders"] + if o["order_id"] in s and o["ship_days"] > o["promised_days"]) + + +def unique_customers(order_ids: list) -> list: + return sorted({ORDERS[oid]["customer_id"] for oid in order_ids}) + + +def count_items(values: list) -> int: + return len(values) + + +def sum_values(values: list) -> int: + return sum(values) + + +def count_true(values: list) -> int: + return sum(1 for v in values if bool(v)) + + +def count_below(values: list, threshold: int) -> int: + return sum(1 for v in values if v < threshold) + + +TOOLS = { + "region_currency": ("region_currency(region: str) -> str", + "ISO currency code for a region.", region_currency), + "get_orders": ("get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]", + "Paid/refunded order ids for a region, product category, and inclusive month window.", + get_orders), + "order_gross_usd": ("order_gross_usd(order_id: int) -> int", + "Gross order revenue in USD before discounts/refunds.", order_gross_usd), + "order_margin_usd": ("order_margin_usd(order_id: int) -> int", + "Gross order margin in USD before discounts/refunds.", order_margin_usd), + "refund_usd": ("refund_usd(order_id: int) -> int", + "Refund amount in USD for returned quantity on an order.", refund_usd), + "customer_tier": ("customer_tier(order_id: int) -> str", + "Customer loyalty tier for an order.", customer_tier), + "apply_discount": ("apply_discount(amount_usd: int, tier: str) -> int", + "Apply the order customer's loyalty discount to a USD amount.", apply_discount), + "net_revenue_usd": ("net_revenue_usd(order_id: int) -> int", + "Net USD revenue after loyalty discount and refunds.", net_revenue_usd), + "to_local": ("to_local(amount_usd: int, currency: str) -> int", + "Convert a USD integer amount to a local-currency integer.", to_local), + "inventory_position": ("inventory_position(product_id: int, region: str) -> int", + "Available inventory position: on_hand - reserved + inbound.", + inventory_position), + "product_lead_time": ("product_lead_time(product_id: int) -> int", + "Supplier lead time in days for a product.", product_lead_time), + "product_id_for_top_seller": ( + "product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int", + "Product id with the highest units sold in a region/category/month window.", + product_id_for_top_seller), + "units_sold": ("units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int", + "Units sold for one product in a region and month window.", units_sold), + "tickets_for_orders": ("tickets_for_orders(order_ids: list[int], severity: str) -> list[int]", + "Support ticket ids for given orders and severity.", tickets_for_orders), + "ticket_order_id": ("ticket_order_id(ticket_id: int) -> int", + "Order id associated with a support ticket.", ticket_order_id), + "sla_breached": ( + "sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool", + "Whether a support ticket breaches first-response or resolution SLA.", + sla_breached), + "delayed_orders": ("delayed_orders(order_ids: list[int]) -> list[int]", + "Subset of order ids whose ship_days exceeded promised_days.", delayed_orders), + "unique_customers": ("unique_customers(order_ids: list[int]) -> list[int]", + "Unique customer ids among the given orders.", unique_customers), + "count_items": ("count_items(values: list) -> int", "Length of a list.", count_items), + "sum_values": ("sum_values(values: list[int]) -> int", "Sum a list of integers.", sum_values), + "count_true": ("count_true(values: list[bool]) -> int", "Count true values.", count_true), + "count_below": ("count_below(values: list[int], threshold: int) -> int", + "Count values below a threshold.", count_below), +} + +__all__ = [name for name in TOOLS.keys()] + ['TOOLS'] diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t22/environment/task.json b/harbor/tasks/v3_depth6_delay_sla_burden_t22/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..6af9d09614507b83f1c9fb077bb01583989cf5fe --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t22/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth6_delay_sla_burden_t22", + "depth": 6, + "family": "delay_sla_burden", + "params": { + "region": "APAC", + "category": "D", + "month_start": 202603, + "month_end": 202605 + }, + "question": "For region APAC, category D, months 202603-202605: get the orders, count delayed orders where ship_days exceeded promised_days, find high and critical support tickets for those orders, count tickets that breach a 24-hour first-response or 120-hour resolution SLA, and report delayed_order_count + breached_ticket_count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t22/instruction.md b/harbor/tasks/v3_depth6_delay_sla_burden_t22/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..3a8c3d3862e1287e161cfe7f101e6f68287290e7 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t22/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For region APAC, category D, months 202603-202605: get the orders, count delayed orders where ship_days exceeded promised_days, find high and critical support tickets for those orders, count tickets that breach a 24-hour first-response or 120-hour resolution SLA, and report delayed_order_count + breached_ticket_count. + +Available tools: +- `region_currency(region: str) -> str`: ISO currency code for a region. +- `get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]`: Paid/refunded order ids for a region, product category, and inclusive month window. +- `order_gross_usd(order_id: int) -> int`: Gross order revenue in USD before discounts/refunds. +- `order_margin_usd(order_id: int) -> int`: Gross order margin in USD before discounts/refunds. +- `refund_usd(order_id: int) -> int`: Refund amount in USD for returned quantity on an order. +- `customer_tier(order_id: int) -> str`: Customer loyalty tier for an order. +- `apply_discount(amount_usd: int, tier: str) -> int`: Apply the order customer's loyalty discount to a USD amount. +- `net_revenue_usd(order_id: int) -> int`: Net USD revenue after loyalty discount and refunds. +- `to_local(amount_usd: int, currency: str) -> int`: Convert a USD integer amount to a local-currency integer. +- `inventory_position(product_id: int, region: str) -> int`: Available inventory position: on_hand - reserved + inbound. +- `product_lead_time(product_id: int) -> int`: Supplier lead time in days for a product. +- `product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int`: Product id with the highest units sold in a region/category/month window. +- `units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int`: Units sold for one product in a region and month window. +- `tickets_for_orders(order_ids: list[int], severity: str) -> list[int]`: Support ticket ids for given orders and severity. +- `ticket_order_id(ticket_id: int) -> int`: Order id associated with a support ticket. +- `sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool`: Whether a support ticket breaches first-response or resolution SLA. +- `delayed_orders(order_ids: list[int]) -> list[int]`: Subset of order ids whose ship_days exceeded promised_days. +- `unique_customers(order_ids: list[int]) -> list[int]`: Unique customer ids among the given orders. +- `count_items(values: list) -> int`: Length of a list. +- `sum_values(values: list[int]) -> int`: Sum a list of integers. +- `count_true(values: list[bool]) -> int`: Count true values. +- `count_below(values: list[int], threshold: int) -> int`: Count values below a threshold. diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t22/task.toml b/harbor/tasks/v3_depth6_delay_sla_burden_t22/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..054b5eec082076e9fc0f555ecc0452438dd9a4c4 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t22/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth6_delay_sla_burden_t22" +description = "FlowBench v3 public task metadata. Public verifier is smoke-only." +authors = [{ name = "Mind Lab", email = "contact@mindlab.ltd" }] +keywords = ["flowbench", "tool-use", "data-orchestration", "operations"] + +[metadata] +benchmark = "FlowBench-v3" +split = "public-task-only" +category = "data-processing" +depth = 6 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +network_mode = "no-network" +build_timeout_sec = 600.0 +os = "linux" +cpus = 1 +memory_mb = 2048 +storage_mb = 2048 +gpus = 0 diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t22/tests/check_output_shape.py b/harbor/tasks/v3_depth6_delay_sla_burden_t22/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t22/tests/check_output_shape.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import json +import os +import re +from pathlib import Path + + +def write_reward(score: float, diagnostic: str) -> None: + log_dir = Path(os.environ.get("LOG_DIR", "/logs/verifier")) + log_dir.mkdir(parents=True, exist_ok=True) + (log_dir / "reward.txt").write_text(f"{score:.6g}\n") + (log_dir / "reward.json").write_text( + json.dumps({"reward": score, "smoke_only": True}, indent=2) + "\n" + ) + (log_dir / "diagnostic.txt").write_text(diagnostic + "\n") + + +def main() -> int: + app_dir = Path(os.environ.get("APP_DIR", "/app")) + task = json.loads((app_dir / "task.json").read_text()) + answer_path = app_dir / "answer.txt" + if not answer_path.exists(): + write_reward(0.0, "missing /app/answer.txt") + return 1 + + got = answer_path.read_text().strip() + if task["answer_format"] == "exact integer": + ok = bool(re.fullmatch(r"-?\d+", got)) + diagnostic = "valid integer smoke output" if ok else f"not an exact integer: {got!r}" + else: + ok = bool(re.fullmatch(r"[A-Za-z]+", got)) + diagnostic = "valid code smoke output" if ok else f"not an exact code: {got!r}" + + # This is intentionally not official scoring; it only verifies I/O shape. + write_reward(1.0 if ok else 0.0, diagnostic) + return 0 if ok else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t22/tests/test.sh b/harbor/tasks/v3_depth6_delay_sla_burden_t22/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t22/tests/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -u +python /tests/check_output_shape.py diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t23/environment/Dockerfile b/harbor/tasks/v3_depth6_delay_sla_burden_t23/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t23/environment/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.12-slim +WORKDIR /app +COPY flowbench_tools.py /app/flowbench_tools.py +COPY task.json /app/task.json diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t23/environment/flowbench_tools.py b/harbor/tasks/v3_depth6_delay_sla_burden_t23/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t23/environment/flowbench_tools.py @@ -0,0 +1,311 @@ +"""Deterministic FlowBench v3 tools. This file contains no task answers.""" + + +REGIONS = ["NA", "EU", "APAC", "LATAM"] +CATEGORIES = ["A", "B", "C", "D"] +CURRENCIES = {"NA": "USD", "EU": "EUR", "APAC": "JPY", "LATAM": "BRL"} +FX_TO_USD_BP = {"USD": 10000, "EUR": 10900, "JPY": 67, "BRL": 1850} +TIERS = ["std", "gold", "plat"] +DISCOUNT_PCT = {"std": 0, "gold": 10, "plat": 20} +CHANNELS = ["web", "store", "partner"] +MONTHS = [202601, 202602, 202603, 202604, 202605, 202606] + +N_CUSTOMERS = 72 +N_PRODUCTS = 48 +N_ORDERS = 720 +N_TICKETS = 260 +N_RETURNS = 180 + + +def _h(*xs): + import hashlib + s = "|".join(str(x) for x in xs).encode() + return int.from_bytes(hashlib.sha256(s).digest()[:8], "big") & 0x7FFFFFFF + + +def build_data(): + customers = [] + for cid in range(N_CUSTOMERS): + region = REGIONS[_h("region", cid) % len(REGIONS)] + customers.append({ + "customer_id": cid, + "region": region, + "tier": TIERS[_h("tier", cid) % len(TIERS)], + "segment": ["consumer", "smb", "enterprise"][_h("segment", cid) % 3], + }) + + products = [] + for pid in range(N_PRODUCTS): + cat = CATEGORIES[_h("cat", pid) % len(CATEGORIES)] + unit_price = 12 + _h("price", pid) % 240 + cogs = unit_price * (45 + _h("margin", pid) % 35) // 100 + products.append({ + "product_id": pid, + "category": cat, + "unit_price_usd": unit_price, + "unit_cogs_usd": cogs, + "lead_time_days": 3 + _h("lead", pid) % 18, + }) + + inventory = [] + for pid in range(N_PRODUCTS): + for region in REGIONS: + inventory.append({ + "product_id": pid, + "region": region, + "on_hand": 10 + _h("onhand", pid, region) % 140, + "reserved": _h("reserved", pid, region) % 28, + "inbound": _h("inbound", pid, region) % 85, + }) + + orders = [] + for oid in range(N_ORDERS): + customer_id = _h("ocust", oid) % N_CUSTOMERS + product_id = _h("oprod", oid) % N_PRODUCTS + month = MONTHS[_h("month", oid) % len(MONTHS)] + qty = 1 + _h("qty", oid) % 9 + ship_days = 1 + _h("shipdays", oid) % 16 + promised_days = 3 + _h("promise", oid) % 9 + status = ["paid", "paid", "paid", "paid", "cancelled", "refunded"][ + _h("status", oid) % 6] + orders.append({ + "order_id": oid, + "customer_id": customer_id, + "product_id": product_id, + "month": month, + "qty": qty, + "status": status, + "channel": CHANNELS[_h("channel", oid) % len(CHANNELS)], + "ship_days": ship_days, + "promised_days": promised_days, + }) + + returns = [] + for rid in range(N_RETURNS): + oid = _h("roid", rid) % N_ORDERS + order = orders[oid] + if order["status"] == "cancelled": + continue + returned_qty = 1 + _h("rqty", rid) % max(1, order["qty"]) + reason = ["defect", "late", "changed_mind", "wrong_item"][_h("reason", rid) % 4] + returns.append({ + "return_id": rid, + "order_id": oid, + "month": MONTHS[_h("rmonth", rid) % len(MONTHS)], + "returned_qty": returned_qty, + "reason": reason, + }) + + tickets = [] + for tid in range(N_TICKETS): + oid = _h("toid", tid) % N_ORDERS + severity = ["low", "medium", "high", "critical"][_h("sev", tid) % 4] + opened = MONTHS[_h("tmonth", tid) % len(MONTHS)] + first_response_hours = 1 + _h("resp", tid) % 96 + resolution_hours = first_response_hours + _h("res", tid) % 240 + tickets.append({ + "ticket_id": tid, + "order_id": oid, + "opened_month": opened, + "severity": severity, + "first_response_hours": first_response_hours, + "resolution_hours": resolution_hours, + }) + + return { + "customers": customers, + "products": products, + "inventory": inventory, + "orders": orders, + "returns": returns, + "tickets": tickets, + "fx_to_usd_bp": FX_TO_USD_BP, + } + + +DATA = build_data() +CUSTOMERS = {c["customer_id"]: c for c in DATA["customers"]} +PRODUCTS = {p["product_id"]: p for p in DATA["products"]} +ORDERS = {o["order_id"]: o for o in DATA["orders"]} + + +def region_currency(region: str) -> str: + return CURRENCIES[region] + + +def get_orders(region: str, category: str, month_start: int, month_end: int) -> list: + """Paid/refunded order ids in a region/category/month window.""" + out = [] + for o in DATA["orders"]: + if o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + p = PRODUCTS[o["product_id"]] + if c["region"] == region and p["category"] == category and month_start <= o["month"] <= month_end: + out.append(o["order_id"]) + return sorted(out) + + +def order_gross_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * p["unit_price_usd"] + + +def order_margin_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * (p["unit_price_usd"] - p["unit_cogs_usd"]) + + +def refund_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + qty = sum(r["returned_qty"] for r in DATA["returns"] if r["order_id"] == order_id) + qty = min(qty, o["qty"]) + return qty * p["unit_price_usd"] + + +def customer_tier(order_id: int) -> str: + o = ORDERS[order_id] + return CUSTOMERS[o["customer_id"]]["tier"] + + +def apply_discount(amount_usd: int, tier: str) -> int: + return amount_usd * (100 - DISCOUNT_PCT[tier]) // 100 + + +def net_revenue_usd(order_id: int) -> int: + gross = apply_discount(order_gross_usd(order_id), customer_tier(order_id)) + return max(0, gross - refund_usd(order_id)) + + +def to_local(amount_usd: int, currency: str) -> int: + return amount_usd * 10000 // FX_TO_USD_BP[currency] + + +def inventory_position(product_id: int, region: str) -> int: + row = next(x for x in DATA["inventory"] + if x["product_id"] == product_id and x["region"] == region) + return row["on_hand"] - row["reserved"] + row["inbound"] + + +def product_lead_time(product_id: int) -> int: + return PRODUCTS[product_id]["lead_time_days"] + + +def product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int: + totals = {} + for oid in get_orders(region, category, month_start, month_end): + o = ORDERS[oid] + totals[o["product_id"]] = totals.get(o["product_id"], 0) + o["qty"] + if not totals: + return -1 + return min((-qty, pid) for pid, qty in totals.items())[1] + + +def units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int: + total = 0 + for o in DATA["orders"]: + if o["product_id"] != product_id or o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + if c["region"] == region and month_start <= o["month"] <= month_end: + total += o["qty"] + return total + + +def tickets_for_orders(order_ids: list, severity: str) -> list: + s = set(order_ids) + return sorted(t["ticket_id"] for t in DATA["tickets"] + if t["order_id"] in s and t["severity"] == severity) + + +def ticket_order_id(ticket_id: int) -> int: + return next(t["order_id"] for t in DATA["tickets"] if t["ticket_id"] == ticket_id) + + +def sla_breached(ticket_id: int, first_response_limit_hours: int, + resolution_limit_hours: int) -> bool: + t = next(x for x in DATA["tickets"] if x["ticket_id"] == ticket_id) + return (t["first_response_hours"] > first_response_limit_hours or + t["resolution_hours"] > resolution_limit_hours) + + +def delayed_orders(order_ids: list) -> list: + s = set(order_ids) + return sorted(o["order_id"] for o in DATA["orders"] + if o["order_id"] in s and o["ship_days"] > o["promised_days"]) + + +def unique_customers(order_ids: list) -> list: + return sorted({ORDERS[oid]["customer_id"] for oid in order_ids}) + + +def count_items(values: list) -> int: + return len(values) + + +def sum_values(values: list) -> int: + return sum(values) + + +def count_true(values: list) -> int: + return sum(1 for v in values if bool(v)) + + +def count_below(values: list, threshold: int) -> int: + return sum(1 for v in values if v < threshold) + + +TOOLS = { + "region_currency": ("region_currency(region: str) -> str", + "ISO currency code for a region.", region_currency), + "get_orders": ("get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]", + "Paid/refunded order ids for a region, product category, and inclusive month window.", + get_orders), + "order_gross_usd": ("order_gross_usd(order_id: int) -> int", + "Gross order revenue in USD before discounts/refunds.", order_gross_usd), + "order_margin_usd": ("order_margin_usd(order_id: int) -> int", + "Gross order margin in USD before discounts/refunds.", order_margin_usd), + "refund_usd": ("refund_usd(order_id: int) -> int", + "Refund amount in USD for returned quantity on an order.", refund_usd), + "customer_tier": ("customer_tier(order_id: int) -> str", + "Customer loyalty tier for an order.", customer_tier), + "apply_discount": ("apply_discount(amount_usd: int, tier: str) -> int", + "Apply the order customer's loyalty discount to a USD amount.", apply_discount), + "net_revenue_usd": ("net_revenue_usd(order_id: int) -> int", + "Net USD revenue after loyalty discount and refunds.", net_revenue_usd), + "to_local": ("to_local(amount_usd: int, currency: str) -> int", + "Convert a USD integer amount to a local-currency integer.", to_local), + "inventory_position": ("inventory_position(product_id: int, region: str) -> int", + "Available inventory position: on_hand - reserved + inbound.", + inventory_position), + "product_lead_time": ("product_lead_time(product_id: int) -> int", + "Supplier lead time in days for a product.", product_lead_time), + "product_id_for_top_seller": ( + "product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int", + "Product id with the highest units sold in a region/category/month window.", + product_id_for_top_seller), + "units_sold": ("units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int", + "Units sold for one product in a region and month window.", units_sold), + "tickets_for_orders": ("tickets_for_orders(order_ids: list[int], severity: str) -> list[int]", + "Support ticket ids for given orders and severity.", tickets_for_orders), + "ticket_order_id": ("ticket_order_id(ticket_id: int) -> int", + "Order id associated with a support ticket.", ticket_order_id), + "sla_breached": ( + "sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool", + "Whether a support ticket breaches first-response or resolution SLA.", + sla_breached), + "delayed_orders": ("delayed_orders(order_ids: list[int]) -> list[int]", + "Subset of order ids whose ship_days exceeded promised_days.", delayed_orders), + "unique_customers": ("unique_customers(order_ids: list[int]) -> list[int]", + "Unique customer ids among the given orders.", unique_customers), + "count_items": ("count_items(values: list) -> int", "Length of a list.", count_items), + "sum_values": ("sum_values(values: list[int]) -> int", "Sum a list of integers.", sum_values), + "count_true": ("count_true(values: list[bool]) -> int", "Count true values.", count_true), + "count_below": ("count_below(values: list[int], threshold: int) -> int", + "Count values below a threshold.", count_below), +} + +__all__ = [name for name in TOOLS.keys()] + ['TOOLS'] diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t23/environment/task.json b/harbor/tasks/v3_depth6_delay_sla_burden_t23/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..8b6e4feb141a66161b4b826bd198628ea0eeaba1 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t23/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth6_delay_sla_burden_t23", + "depth": 6, + "family": "delay_sla_burden", + "params": { + "region": "LATAM", + "category": "C", + "month_start": 202601, + "month_end": 202602 + }, + "question": "For region LATAM, category C, months 202601-202602: get the orders, count delayed orders where ship_days exceeded promised_days, find high and critical support tickets for those orders, count tickets that breach a 24-hour first-response or 120-hour resolution SLA, and report delayed_order_count + breached_ticket_count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t23/instruction.md b/harbor/tasks/v3_depth6_delay_sla_burden_t23/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..a88ef630e64da3cee69b386b22d9d192b6afa274 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t23/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For region LATAM, category C, months 202601-202602: get the orders, count delayed orders where ship_days exceeded promised_days, find high and critical support tickets for those orders, count tickets that breach a 24-hour first-response or 120-hour resolution SLA, and report delayed_order_count + breached_ticket_count. + +Available tools: +- `region_currency(region: str) -> str`: ISO currency code for a region. +- `get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]`: Paid/refunded order ids for a region, product category, and inclusive month window. +- `order_gross_usd(order_id: int) -> int`: Gross order revenue in USD before discounts/refunds. +- `order_margin_usd(order_id: int) -> int`: Gross order margin in USD before discounts/refunds. +- `refund_usd(order_id: int) -> int`: Refund amount in USD for returned quantity on an order. +- `customer_tier(order_id: int) -> str`: Customer loyalty tier for an order. +- `apply_discount(amount_usd: int, tier: str) -> int`: Apply the order customer's loyalty discount to a USD amount. +- `net_revenue_usd(order_id: int) -> int`: Net USD revenue after loyalty discount and refunds. +- `to_local(amount_usd: int, currency: str) -> int`: Convert a USD integer amount to a local-currency integer. +- `inventory_position(product_id: int, region: str) -> int`: Available inventory position: on_hand - reserved + inbound. +- `product_lead_time(product_id: int) -> int`: Supplier lead time in days for a product. +- `product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int`: Product id with the highest units sold in a region/category/month window. +- `units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int`: Units sold for one product in a region and month window. +- `tickets_for_orders(order_ids: list[int], severity: str) -> list[int]`: Support ticket ids for given orders and severity. +- `ticket_order_id(ticket_id: int) -> int`: Order id associated with a support ticket. +- `sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool`: Whether a support ticket breaches first-response or resolution SLA. +- `delayed_orders(order_ids: list[int]) -> list[int]`: Subset of order ids whose ship_days exceeded promised_days. +- `unique_customers(order_ids: list[int]) -> list[int]`: Unique customer ids among the given orders. +- `count_items(values: list) -> int`: Length of a list. +- `sum_values(values: list[int]) -> int`: Sum a list of integers. +- `count_true(values: list[bool]) -> int`: Count true values. +- `count_below(values: list[int], threshold: int) -> int`: Count values below a threshold. diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t23/task.toml b/harbor/tasks/v3_depth6_delay_sla_burden_t23/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..8aa988abeaad473d0050c8ba56770d2ce510991a --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t23/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth6_delay_sla_burden_t23" +description = "FlowBench v3 public task metadata. Public verifier is smoke-only." +authors = [{ name = "Mind Lab", email = "contact@mindlab.ltd" }] +keywords = ["flowbench", "tool-use", "data-orchestration", "operations"] + +[metadata] +benchmark = "FlowBench-v3" +split = "public-task-only" +category = "data-processing" +depth = 6 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +network_mode = "no-network" +build_timeout_sec = 600.0 +os = "linux" +cpus = 1 +memory_mb = 2048 +storage_mb = 2048 +gpus = 0 diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t23/tests/check_output_shape.py b/harbor/tasks/v3_depth6_delay_sla_burden_t23/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t23/tests/check_output_shape.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import json +import os +import re +from pathlib import Path + + +def write_reward(score: float, diagnostic: str) -> None: + log_dir = Path(os.environ.get("LOG_DIR", "/logs/verifier")) + log_dir.mkdir(parents=True, exist_ok=True) + (log_dir / "reward.txt").write_text(f"{score:.6g}\n") + (log_dir / "reward.json").write_text( + json.dumps({"reward": score, "smoke_only": True}, indent=2) + "\n" + ) + (log_dir / "diagnostic.txt").write_text(diagnostic + "\n") + + +def main() -> int: + app_dir = Path(os.environ.get("APP_DIR", "/app")) + task = json.loads((app_dir / "task.json").read_text()) + answer_path = app_dir / "answer.txt" + if not answer_path.exists(): + write_reward(0.0, "missing /app/answer.txt") + return 1 + + got = answer_path.read_text().strip() + if task["answer_format"] == "exact integer": + ok = bool(re.fullmatch(r"-?\d+", got)) + diagnostic = "valid integer smoke output" if ok else f"not an exact integer: {got!r}" + else: + ok = bool(re.fullmatch(r"[A-Za-z]+", got)) + diagnostic = "valid code smoke output" if ok else f"not an exact code: {got!r}" + + # This is intentionally not official scoring; it only verifies I/O shape. + write_reward(1.0 if ok else 0.0, diagnostic) + return 0 if ok else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t23/tests/test.sh b/harbor/tasks/v3_depth6_delay_sla_burden_t23/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t23/tests/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -u +python /tests/check_output_shape.py diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t24/environment/Dockerfile b/harbor/tasks/v3_depth6_delay_sla_burden_t24/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t24/environment/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.12-slim +WORKDIR /app +COPY flowbench_tools.py /app/flowbench_tools.py +COPY task.json /app/task.json diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t24/environment/flowbench_tools.py b/harbor/tasks/v3_depth6_delay_sla_burden_t24/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t24/environment/flowbench_tools.py @@ -0,0 +1,311 @@ +"""Deterministic FlowBench v3 tools. This file contains no task answers.""" + + +REGIONS = ["NA", "EU", "APAC", "LATAM"] +CATEGORIES = ["A", "B", "C", "D"] +CURRENCIES = {"NA": "USD", "EU": "EUR", "APAC": "JPY", "LATAM": "BRL"} +FX_TO_USD_BP = {"USD": 10000, "EUR": 10900, "JPY": 67, "BRL": 1850} +TIERS = ["std", "gold", "plat"] +DISCOUNT_PCT = {"std": 0, "gold": 10, "plat": 20} +CHANNELS = ["web", "store", "partner"] +MONTHS = [202601, 202602, 202603, 202604, 202605, 202606] + +N_CUSTOMERS = 72 +N_PRODUCTS = 48 +N_ORDERS = 720 +N_TICKETS = 260 +N_RETURNS = 180 + + +def _h(*xs): + import hashlib + s = "|".join(str(x) for x in xs).encode() + return int.from_bytes(hashlib.sha256(s).digest()[:8], "big") & 0x7FFFFFFF + + +def build_data(): + customers = [] + for cid in range(N_CUSTOMERS): + region = REGIONS[_h("region", cid) % len(REGIONS)] + customers.append({ + "customer_id": cid, + "region": region, + "tier": TIERS[_h("tier", cid) % len(TIERS)], + "segment": ["consumer", "smb", "enterprise"][_h("segment", cid) % 3], + }) + + products = [] + for pid in range(N_PRODUCTS): + cat = CATEGORIES[_h("cat", pid) % len(CATEGORIES)] + unit_price = 12 + _h("price", pid) % 240 + cogs = unit_price * (45 + _h("margin", pid) % 35) // 100 + products.append({ + "product_id": pid, + "category": cat, + "unit_price_usd": unit_price, + "unit_cogs_usd": cogs, + "lead_time_days": 3 + _h("lead", pid) % 18, + }) + + inventory = [] + for pid in range(N_PRODUCTS): + for region in REGIONS: + inventory.append({ + "product_id": pid, + "region": region, + "on_hand": 10 + _h("onhand", pid, region) % 140, + "reserved": _h("reserved", pid, region) % 28, + "inbound": _h("inbound", pid, region) % 85, + }) + + orders = [] + for oid in range(N_ORDERS): + customer_id = _h("ocust", oid) % N_CUSTOMERS + product_id = _h("oprod", oid) % N_PRODUCTS + month = MONTHS[_h("month", oid) % len(MONTHS)] + qty = 1 + _h("qty", oid) % 9 + ship_days = 1 + _h("shipdays", oid) % 16 + promised_days = 3 + _h("promise", oid) % 9 + status = ["paid", "paid", "paid", "paid", "cancelled", "refunded"][ + _h("status", oid) % 6] + orders.append({ + "order_id": oid, + "customer_id": customer_id, + "product_id": product_id, + "month": month, + "qty": qty, + "status": status, + "channel": CHANNELS[_h("channel", oid) % len(CHANNELS)], + "ship_days": ship_days, + "promised_days": promised_days, + }) + + returns = [] + for rid in range(N_RETURNS): + oid = _h("roid", rid) % N_ORDERS + order = orders[oid] + if order["status"] == "cancelled": + continue + returned_qty = 1 + _h("rqty", rid) % max(1, order["qty"]) + reason = ["defect", "late", "changed_mind", "wrong_item"][_h("reason", rid) % 4] + returns.append({ + "return_id": rid, + "order_id": oid, + "month": MONTHS[_h("rmonth", rid) % len(MONTHS)], + "returned_qty": returned_qty, + "reason": reason, + }) + + tickets = [] + for tid in range(N_TICKETS): + oid = _h("toid", tid) % N_ORDERS + severity = ["low", "medium", "high", "critical"][_h("sev", tid) % 4] + opened = MONTHS[_h("tmonth", tid) % len(MONTHS)] + first_response_hours = 1 + _h("resp", tid) % 96 + resolution_hours = first_response_hours + _h("res", tid) % 240 + tickets.append({ + "ticket_id": tid, + "order_id": oid, + "opened_month": opened, + "severity": severity, + "first_response_hours": first_response_hours, + "resolution_hours": resolution_hours, + }) + + return { + "customers": customers, + "products": products, + "inventory": inventory, + "orders": orders, + "returns": returns, + "tickets": tickets, + "fx_to_usd_bp": FX_TO_USD_BP, + } + + +DATA = build_data() +CUSTOMERS = {c["customer_id"]: c for c in DATA["customers"]} +PRODUCTS = {p["product_id"]: p for p in DATA["products"]} +ORDERS = {o["order_id"]: o for o in DATA["orders"]} + + +def region_currency(region: str) -> str: + return CURRENCIES[region] + + +def get_orders(region: str, category: str, month_start: int, month_end: int) -> list: + """Paid/refunded order ids in a region/category/month window.""" + out = [] + for o in DATA["orders"]: + if o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + p = PRODUCTS[o["product_id"]] + if c["region"] == region and p["category"] == category and month_start <= o["month"] <= month_end: + out.append(o["order_id"]) + return sorted(out) + + +def order_gross_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * p["unit_price_usd"] + + +def order_margin_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * (p["unit_price_usd"] - p["unit_cogs_usd"]) + + +def refund_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + qty = sum(r["returned_qty"] for r in DATA["returns"] if r["order_id"] == order_id) + qty = min(qty, o["qty"]) + return qty * p["unit_price_usd"] + + +def customer_tier(order_id: int) -> str: + o = ORDERS[order_id] + return CUSTOMERS[o["customer_id"]]["tier"] + + +def apply_discount(amount_usd: int, tier: str) -> int: + return amount_usd * (100 - DISCOUNT_PCT[tier]) // 100 + + +def net_revenue_usd(order_id: int) -> int: + gross = apply_discount(order_gross_usd(order_id), customer_tier(order_id)) + return max(0, gross - refund_usd(order_id)) + + +def to_local(amount_usd: int, currency: str) -> int: + return amount_usd * 10000 // FX_TO_USD_BP[currency] + + +def inventory_position(product_id: int, region: str) -> int: + row = next(x for x in DATA["inventory"] + if x["product_id"] == product_id and x["region"] == region) + return row["on_hand"] - row["reserved"] + row["inbound"] + + +def product_lead_time(product_id: int) -> int: + return PRODUCTS[product_id]["lead_time_days"] + + +def product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int: + totals = {} + for oid in get_orders(region, category, month_start, month_end): + o = ORDERS[oid] + totals[o["product_id"]] = totals.get(o["product_id"], 0) + o["qty"] + if not totals: + return -1 + return min((-qty, pid) for pid, qty in totals.items())[1] + + +def units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int: + total = 0 + for o in DATA["orders"]: + if o["product_id"] != product_id or o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + if c["region"] == region and month_start <= o["month"] <= month_end: + total += o["qty"] + return total + + +def tickets_for_orders(order_ids: list, severity: str) -> list: + s = set(order_ids) + return sorted(t["ticket_id"] for t in DATA["tickets"] + if t["order_id"] in s and t["severity"] == severity) + + +def ticket_order_id(ticket_id: int) -> int: + return next(t["order_id"] for t in DATA["tickets"] if t["ticket_id"] == ticket_id) + + +def sla_breached(ticket_id: int, first_response_limit_hours: int, + resolution_limit_hours: int) -> bool: + t = next(x for x in DATA["tickets"] if x["ticket_id"] == ticket_id) + return (t["first_response_hours"] > first_response_limit_hours or + t["resolution_hours"] > resolution_limit_hours) + + +def delayed_orders(order_ids: list) -> list: + s = set(order_ids) + return sorted(o["order_id"] for o in DATA["orders"] + if o["order_id"] in s and o["ship_days"] > o["promised_days"]) + + +def unique_customers(order_ids: list) -> list: + return sorted({ORDERS[oid]["customer_id"] for oid in order_ids}) + + +def count_items(values: list) -> int: + return len(values) + + +def sum_values(values: list) -> int: + return sum(values) + + +def count_true(values: list) -> int: + return sum(1 for v in values if bool(v)) + + +def count_below(values: list, threshold: int) -> int: + return sum(1 for v in values if v < threshold) + + +TOOLS = { + "region_currency": ("region_currency(region: str) -> str", + "ISO currency code for a region.", region_currency), + "get_orders": ("get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]", + "Paid/refunded order ids for a region, product category, and inclusive month window.", + get_orders), + "order_gross_usd": ("order_gross_usd(order_id: int) -> int", + "Gross order revenue in USD before discounts/refunds.", order_gross_usd), + "order_margin_usd": ("order_margin_usd(order_id: int) -> int", + "Gross order margin in USD before discounts/refunds.", order_margin_usd), + "refund_usd": ("refund_usd(order_id: int) -> int", + "Refund amount in USD for returned quantity on an order.", refund_usd), + "customer_tier": ("customer_tier(order_id: int) -> str", + "Customer loyalty tier for an order.", customer_tier), + "apply_discount": ("apply_discount(amount_usd: int, tier: str) -> int", + "Apply the order customer's loyalty discount to a USD amount.", apply_discount), + "net_revenue_usd": ("net_revenue_usd(order_id: int) -> int", + "Net USD revenue after loyalty discount and refunds.", net_revenue_usd), + "to_local": ("to_local(amount_usd: int, currency: str) -> int", + "Convert a USD integer amount to a local-currency integer.", to_local), + "inventory_position": ("inventory_position(product_id: int, region: str) -> int", + "Available inventory position: on_hand - reserved + inbound.", + inventory_position), + "product_lead_time": ("product_lead_time(product_id: int) -> int", + "Supplier lead time in days for a product.", product_lead_time), + "product_id_for_top_seller": ( + "product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int", + "Product id with the highest units sold in a region/category/month window.", + product_id_for_top_seller), + "units_sold": ("units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int", + "Units sold for one product in a region and month window.", units_sold), + "tickets_for_orders": ("tickets_for_orders(order_ids: list[int], severity: str) -> list[int]", + "Support ticket ids for given orders and severity.", tickets_for_orders), + "ticket_order_id": ("ticket_order_id(ticket_id: int) -> int", + "Order id associated with a support ticket.", ticket_order_id), + "sla_breached": ( + "sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool", + "Whether a support ticket breaches first-response or resolution SLA.", + sla_breached), + "delayed_orders": ("delayed_orders(order_ids: list[int]) -> list[int]", + "Subset of order ids whose ship_days exceeded promised_days.", delayed_orders), + "unique_customers": ("unique_customers(order_ids: list[int]) -> list[int]", + "Unique customer ids among the given orders.", unique_customers), + "count_items": ("count_items(values: list) -> int", "Length of a list.", count_items), + "sum_values": ("sum_values(values: list[int]) -> int", "Sum a list of integers.", sum_values), + "count_true": ("count_true(values: list[bool]) -> int", "Count true values.", count_true), + "count_below": ("count_below(values: list[int], threshold: int) -> int", + "Count values below a threshold.", count_below), +} + +__all__ = [name for name in TOOLS.keys()] + ['TOOLS'] diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t24/environment/task.json b/harbor/tasks/v3_depth6_delay_sla_burden_t24/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..a45ea8cbac773fc2c16fbc18f505328ceae73597 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t24/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth6_delay_sla_burden_t24", + "depth": 6, + "family": "delay_sla_burden", + "params": { + "region": "NA", + "category": "D", + "month_start": 202601, + "month_end": 202603 + }, + "question": "For region NA, category D, months 202601-202603: get the orders, count delayed orders where ship_days exceeded promised_days, find high and critical support tickets for those orders, count tickets that breach a 24-hour first-response or 120-hour resolution SLA, and report delayed_order_count + breached_ticket_count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t24/instruction.md b/harbor/tasks/v3_depth6_delay_sla_burden_t24/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..843d8ae93f33d9666221563bbd66ff8781ea6875 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t24/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For region NA, category D, months 202601-202603: get the orders, count delayed orders where ship_days exceeded promised_days, find high and critical support tickets for those orders, count tickets that breach a 24-hour first-response or 120-hour resolution SLA, and report delayed_order_count + breached_ticket_count. + +Available tools: +- `region_currency(region: str) -> str`: ISO currency code for a region. +- `get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]`: Paid/refunded order ids for a region, product category, and inclusive month window. +- `order_gross_usd(order_id: int) -> int`: Gross order revenue in USD before discounts/refunds. +- `order_margin_usd(order_id: int) -> int`: Gross order margin in USD before discounts/refunds. +- `refund_usd(order_id: int) -> int`: Refund amount in USD for returned quantity on an order. +- `customer_tier(order_id: int) -> str`: Customer loyalty tier for an order. +- `apply_discount(amount_usd: int, tier: str) -> int`: Apply the order customer's loyalty discount to a USD amount. +- `net_revenue_usd(order_id: int) -> int`: Net USD revenue after loyalty discount and refunds. +- `to_local(amount_usd: int, currency: str) -> int`: Convert a USD integer amount to a local-currency integer. +- `inventory_position(product_id: int, region: str) -> int`: Available inventory position: on_hand - reserved + inbound. +- `product_lead_time(product_id: int) -> int`: Supplier lead time in days for a product. +- `product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int`: Product id with the highest units sold in a region/category/month window. +- `units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int`: Units sold for one product in a region and month window. +- `tickets_for_orders(order_ids: list[int], severity: str) -> list[int]`: Support ticket ids for given orders and severity. +- `ticket_order_id(ticket_id: int) -> int`: Order id associated with a support ticket. +- `sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool`: Whether a support ticket breaches first-response or resolution SLA. +- `delayed_orders(order_ids: list[int]) -> list[int]`: Subset of order ids whose ship_days exceeded promised_days. +- `unique_customers(order_ids: list[int]) -> list[int]`: Unique customer ids among the given orders. +- `count_items(values: list) -> int`: Length of a list. +- `sum_values(values: list[int]) -> int`: Sum a list of integers. +- `count_true(values: list[bool]) -> int`: Count true values. +- `count_below(values: list[int], threshold: int) -> int`: Count values below a threshold. diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t24/task.toml b/harbor/tasks/v3_depth6_delay_sla_burden_t24/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..71c41614d3ef5a48618833e9919b6d18cc4b33c6 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t24/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth6_delay_sla_burden_t24" +description = "FlowBench v3 public task metadata. Public verifier is smoke-only." +authors = [{ name = "Mind Lab", email = "contact@mindlab.ltd" }] +keywords = ["flowbench", "tool-use", "data-orchestration", "operations"] + +[metadata] +benchmark = "FlowBench-v3" +split = "public-task-only" +category = "data-processing" +depth = 6 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +network_mode = "no-network" +build_timeout_sec = 600.0 +os = "linux" +cpus = 1 +memory_mb = 2048 +storage_mb = 2048 +gpus = 0 diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t24/tests/check_output_shape.py b/harbor/tasks/v3_depth6_delay_sla_burden_t24/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t24/tests/check_output_shape.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import json +import os +import re +from pathlib import Path + + +def write_reward(score: float, diagnostic: str) -> None: + log_dir = Path(os.environ.get("LOG_DIR", "/logs/verifier")) + log_dir.mkdir(parents=True, exist_ok=True) + (log_dir / "reward.txt").write_text(f"{score:.6g}\n") + (log_dir / "reward.json").write_text( + json.dumps({"reward": score, "smoke_only": True}, indent=2) + "\n" + ) + (log_dir / "diagnostic.txt").write_text(diagnostic + "\n") + + +def main() -> int: + app_dir = Path(os.environ.get("APP_DIR", "/app")) + task = json.loads((app_dir / "task.json").read_text()) + answer_path = app_dir / "answer.txt" + if not answer_path.exists(): + write_reward(0.0, "missing /app/answer.txt") + return 1 + + got = answer_path.read_text().strip() + if task["answer_format"] == "exact integer": + ok = bool(re.fullmatch(r"-?\d+", got)) + diagnostic = "valid integer smoke output" if ok else f"not an exact integer: {got!r}" + else: + ok = bool(re.fullmatch(r"[A-Za-z]+", got)) + diagnostic = "valid code smoke output" if ok else f"not an exact code: {got!r}" + + # This is intentionally not official scoring; it only verifies I/O shape. + write_reward(1.0 if ok else 0.0, diagnostic) + return 0 if ok else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t24/tests/test.sh b/harbor/tasks/v3_depth6_delay_sla_burden_t24/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t24/tests/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -u +python /tests/check_output_shape.py diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t3/environment/Dockerfile b/harbor/tasks/v3_depth6_delay_sla_burden_t3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t3/environment/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.12-slim +WORKDIR /app +COPY flowbench_tools.py /app/flowbench_tools.py +COPY task.json /app/task.json diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t3/environment/flowbench_tools.py b/harbor/tasks/v3_depth6_delay_sla_burden_t3/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t3/environment/flowbench_tools.py @@ -0,0 +1,311 @@ +"""Deterministic FlowBench v3 tools. This file contains no task answers.""" + + +REGIONS = ["NA", "EU", "APAC", "LATAM"] +CATEGORIES = ["A", "B", "C", "D"] +CURRENCIES = {"NA": "USD", "EU": "EUR", "APAC": "JPY", "LATAM": "BRL"} +FX_TO_USD_BP = {"USD": 10000, "EUR": 10900, "JPY": 67, "BRL": 1850} +TIERS = ["std", "gold", "plat"] +DISCOUNT_PCT = {"std": 0, "gold": 10, "plat": 20} +CHANNELS = ["web", "store", "partner"] +MONTHS = [202601, 202602, 202603, 202604, 202605, 202606] + +N_CUSTOMERS = 72 +N_PRODUCTS = 48 +N_ORDERS = 720 +N_TICKETS = 260 +N_RETURNS = 180 + + +def _h(*xs): + import hashlib + s = "|".join(str(x) for x in xs).encode() + return int.from_bytes(hashlib.sha256(s).digest()[:8], "big") & 0x7FFFFFFF + + +def build_data(): + customers = [] + for cid in range(N_CUSTOMERS): + region = REGIONS[_h("region", cid) % len(REGIONS)] + customers.append({ + "customer_id": cid, + "region": region, + "tier": TIERS[_h("tier", cid) % len(TIERS)], + "segment": ["consumer", "smb", "enterprise"][_h("segment", cid) % 3], + }) + + products = [] + for pid in range(N_PRODUCTS): + cat = CATEGORIES[_h("cat", pid) % len(CATEGORIES)] + unit_price = 12 + _h("price", pid) % 240 + cogs = unit_price * (45 + _h("margin", pid) % 35) // 100 + products.append({ + "product_id": pid, + "category": cat, + "unit_price_usd": unit_price, + "unit_cogs_usd": cogs, + "lead_time_days": 3 + _h("lead", pid) % 18, + }) + + inventory = [] + for pid in range(N_PRODUCTS): + for region in REGIONS: + inventory.append({ + "product_id": pid, + "region": region, + "on_hand": 10 + _h("onhand", pid, region) % 140, + "reserved": _h("reserved", pid, region) % 28, + "inbound": _h("inbound", pid, region) % 85, + }) + + orders = [] + for oid in range(N_ORDERS): + customer_id = _h("ocust", oid) % N_CUSTOMERS + product_id = _h("oprod", oid) % N_PRODUCTS + month = MONTHS[_h("month", oid) % len(MONTHS)] + qty = 1 + _h("qty", oid) % 9 + ship_days = 1 + _h("shipdays", oid) % 16 + promised_days = 3 + _h("promise", oid) % 9 + status = ["paid", "paid", "paid", "paid", "cancelled", "refunded"][ + _h("status", oid) % 6] + orders.append({ + "order_id": oid, + "customer_id": customer_id, + "product_id": product_id, + "month": month, + "qty": qty, + "status": status, + "channel": CHANNELS[_h("channel", oid) % len(CHANNELS)], + "ship_days": ship_days, + "promised_days": promised_days, + }) + + returns = [] + for rid in range(N_RETURNS): + oid = _h("roid", rid) % N_ORDERS + order = orders[oid] + if order["status"] == "cancelled": + continue + returned_qty = 1 + _h("rqty", rid) % max(1, order["qty"]) + reason = ["defect", "late", "changed_mind", "wrong_item"][_h("reason", rid) % 4] + returns.append({ + "return_id": rid, + "order_id": oid, + "month": MONTHS[_h("rmonth", rid) % len(MONTHS)], + "returned_qty": returned_qty, + "reason": reason, + }) + + tickets = [] + for tid in range(N_TICKETS): + oid = _h("toid", tid) % N_ORDERS + severity = ["low", "medium", "high", "critical"][_h("sev", tid) % 4] + opened = MONTHS[_h("tmonth", tid) % len(MONTHS)] + first_response_hours = 1 + _h("resp", tid) % 96 + resolution_hours = first_response_hours + _h("res", tid) % 240 + tickets.append({ + "ticket_id": tid, + "order_id": oid, + "opened_month": opened, + "severity": severity, + "first_response_hours": first_response_hours, + "resolution_hours": resolution_hours, + }) + + return { + "customers": customers, + "products": products, + "inventory": inventory, + "orders": orders, + "returns": returns, + "tickets": tickets, + "fx_to_usd_bp": FX_TO_USD_BP, + } + + +DATA = build_data() +CUSTOMERS = {c["customer_id"]: c for c in DATA["customers"]} +PRODUCTS = {p["product_id"]: p for p in DATA["products"]} +ORDERS = {o["order_id"]: o for o in DATA["orders"]} + + +def region_currency(region: str) -> str: + return CURRENCIES[region] + + +def get_orders(region: str, category: str, month_start: int, month_end: int) -> list: + """Paid/refunded order ids in a region/category/month window.""" + out = [] + for o in DATA["orders"]: + if o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + p = PRODUCTS[o["product_id"]] + if c["region"] == region and p["category"] == category and month_start <= o["month"] <= month_end: + out.append(o["order_id"]) + return sorted(out) + + +def order_gross_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * p["unit_price_usd"] + + +def order_margin_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * (p["unit_price_usd"] - p["unit_cogs_usd"]) + + +def refund_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + qty = sum(r["returned_qty"] for r in DATA["returns"] if r["order_id"] == order_id) + qty = min(qty, o["qty"]) + return qty * p["unit_price_usd"] + + +def customer_tier(order_id: int) -> str: + o = ORDERS[order_id] + return CUSTOMERS[o["customer_id"]]["tier"] + + +def apply_discount(amount_usd: int, tier: str) -> int: + return amount_usd * (100 - DISCOUNT_PCT[tier]) // 100 + + +def net_revenue_usd(order_id: int) -> int: + gross = apply_discount(order_gross_usd(order_id), customer_tier(order_id)) + return max(0, gross - refund_usd(order_id)) + + +def to_local(amount_usd: int, currency: str) -> int: + return amount_usd * 10000 // FX_TO_USD_BP[currency] + + +def inventory_position(product_id: int, region: str) -> int: + row = next(x for x in DATA["inventory"] + if x["product_id"] == product_id and x["region"] == region) + return row["on_hand"] - row["reserved"] + row["inbound"] + + +def product_lead_time(product_id: int) -> int: + return PRODUCTS[product_id]["lead_time_days"] + + +def product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int: + totals = {} + for oid in get_orders(region, category, month_start, month_end): + o = ORDERS[oid] + totals[o["product_id"]] = totals.get(o["product_id"], 0) + o["qty"] + if not totals: + return -1 + return min((-qty, pid) for pid, qty in totals.items())[1] + + +def units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int: + total = 0 + for o in DATA["orders"]: + if o["product_id"] != product_id or o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + if c["region"] == region and month_start <= o["month"] <= month_end: + total += o["qty"] + return total + + +def tickets_for_orders(order_ids: list, severity: str) -> list: + s = set(order_ids) + return sorted(t["ticket_id"] for t in DATA["tickets"] + if t["order_id"] in s and t["severity"] == severity) + + +def ticket_order_id(ticket_id: int) -> int: + return next(t["order_id"] for t in DATA["tickets"] if t["ticket_id"] == ticket_id) + + +def sla_breached(ticket_id: int, first_response_limit_hours: int, + resolution_limit_hours: int) -> bool: + t = next(x for x in DATA["tickets"] if x["ticket_id"] == ticket_id) + return (t["first_response_hours"] > first_response_limit_hours or + t["resolution_hours"] > resolution_limit_hours) + + +def delayed_orders(order_ids: list) -> list: + s = set(order_ids) + return sorted(o["order_id"] for o in DATA["orders"] + if o["order_id"] in s and o["ship_days"] > o["promised_days"]) + + +def unique_customers(order_ids: list) -> list: + return sorted({ORDERS[oid]["customer_id"] for oid in order_ids}) + + +def count_items(values: list) -> int: + return len(values) + + +def sum_values(values: list) -> int: + return sum(values) + + +def count_true(values: list) -> int: + return sum(1 for v in values if bool(v)) + + +def count_below(values: list, threshold: int) -> int: + return sum(1 for v in values if v < threshold) + + +TOOLS = { + "region_currency": ("region_currency(region: str) -> str", + "ISO currency code for a region.", region_currency), + "get_orders": ("get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]", + "Paid/refunded order ids for a region, product category, and inclusive month window.", + get_orders), + "order_gross_usd": ("order_gross_usd(order_id: int) -> int", + "Gross order revenue in USD before discounts/refunds.", order_gross_usd), + "order_margin_usd": ("order_margin_usd(order_id: int) -> int", + "Gross order margin in USD before discounts/refunds.", order_margin_usd), + "refund_usd": ("refund_usd(order_id: int) -> int", + "Refund amount in USD for returned quantity on an order.", refund_usd), + "customer_tier": ("customer_tier(order_id: int) -> str", + "Customer loyalty tier for an order.", customer_tier), + "apply_discount": ("apply_discount(amount_usd: int, tier: str) -> int", + "Apply the order customer's loyalty discount to a USD amount.", apply_discount), + "net_revenue_usd": ("net_revenue_usd(order_id: int) -> int", + "Net USD revenue after loyalty discount and refunds.", net_revenue_usd), + "to_local": ("to_local(amount_usd: int, currency: str) -> int", + "Convert a USD integer amount to a local-currency integer.", to_local), + "inventory_position": ("inventory_position(product_id: int, region: str) -> int", + "Available inventory position: on_hand - reserved + inbound.", + inventory_position), + "product_lead_time": ("product_lead_time(product_id: int) -> int", + "Supplier lead time in days for a product.", product_lead_time), + "product_id_for_top_seller": ( + "product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int", + "Product id with the highest units sold in a region/category/month window.", + product_id_for_top_seller), + "units_sold": ("units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int", + "Units sold for one product in a region and month window.", units_sold), + "tickets_for_orders": ("tickets_for_orders(order_ids: list[int], severity: str) -> list[int]", + "Support ticket ids for given orders and severity.", tickets_for_orders), + "ticket_order_id": ("ticket_order_id(ticket_id: int) -> int", + "Order id associated with a support ticket.", ticket_order_id), + "sla_breached": ( + "sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool", + "Whether a support ticket breaches first-response or resolution SLA.", + sla_breached), + "delayed_orders": ("delayed_orders(order_ids: list[int]) -> list[int]", + "Subset of order ids whose ship_days exceeded promised_days.", delayed_orders), + "unique_customers": ("unique_customers(order_ids: list[int]) -> list[int]", + "Unique customer ids among the given orders.", unique_customers), + "count_items": ("count_items(values: list) -> int", "Length of a list.", count_items), + "sum_values": ("sum_values(values: list[int]) -> int", "Sum a list of integers.", sum_values), + "count_true": ("count_true(values: list[bool]) -> int", "Count true values.", count_true), + "count_below": ("count_below(values: list[int], threshold: int) -> int", + "Count values below a threshold.", count_below), +} + +__all__ = [name for name in TOOLS.keys()] + ['TOOLS'] diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t3/environment/task.json b/harbor/tasks/v3_depth6_delay_sla_burden_t3/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..439e7388f5ed54fecefe1856f8ae9f055249e6da --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t3/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth6_delay_sla_burden_t3", + "depth": 6, + "family": "delay_sla_burden", + "params": { + "region": "EU", + "category": "D", + "month_start": 202603, + "month_end": 202606 + }, + "question": "For region EU, category D, months 202603-202606: get the orders, count delayed orders where ship_days exceeded promised_days, find high and critical support tickets for those orders, count tickets that breach a 24-hour first-response or 120-hour resolution SLA, and report delayed_order_count + breached_ticket_count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t3/instruction.md b/harbor/tasks/v3_depth6_delay_sla_burden_t3/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..5493d015017bd6d0ff376e854be60f4999abc340 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t3/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For region EU, category D, months 202603-202606: get the orders, count delayed orders where ship_days exceeded promised_days, find high and critical support tickets for those orders, count tickets that breach a 24-hour first-response or 120-hour resolution SLA, and report delayed_order_count + breached_ticket_count. + +Available tools: +- `region_currency(region: str) -> str`: ISO currency code for a region. +- `get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]`: Paid/refunded order ids for a region, product category, and inclusive month window. +- `order_gross_usd(order_id: int) -> int`: Gross order revenue in USD before discounts/refunds. +- `order_margin_usd(order_id: int) -> int`: Gross order margin in USD before discounts/refunds. +- `refund_usd(order_id: int) -> int`: Refund amount in USD for returned quantity on an order. +- `customer_tier(order_id: int) -> str`: Customer loyalty tier for an order. +- `apply_discount(amount_usd: int, tier: str) -> int`: Apply the order customer's loyalty discount to a USD amount. +- `net_revenue_usd(order_id: int) -> int`: Net USD revenue after loyalty discount and refunds. +- `to_local(amount_usd: int, currency: str) -> int`: Convert a USD integer amount to a local-currency integer. +- `inventory_position(product_id: int, region: str) -> int`: Available inventory position: on_hand - reserved + inbound. +- `product_lead_time(product_id: int) -> int`: Supplier lead time in days for a product. +- `product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int`: Product id with the highest units sold in a region/category/month window. +- `units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int`: Units sold for one product in a region and month window. +- `tickets_for_orders(order_ids: list[int], severity: str) -> list[int]`: Support ticket ids for given orders and severity. +- `ticket_order_id(ticket_id: int) -> int`: Order id associated with a support ticket. +- `sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool`: Whether a support ticket breaches first-response or resolution SLA. +- `delayed_orders(order_ids: list[int]) -> list[int]`: Subset of order ids whose ship_days exceeded promised_days. +- `unique_customers(order_ids: list[int]) -> list[int]`: Unique customer ids among the given orders. +- `count_items(values: list) -> int`: Length of a list. +- `sum_values(values: list[int]) -> int`: Sum a list of integers. +- `count_true(values: list[bool]) -> int`: Count true values. +- `count_below(values: list[int], threshold: int) -> int`: Count values below a threshold. diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t3/task.toml b/harbor/tasks/v3_depth6_delay_sla_burden_t3/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..baabf0fb067cef698d1498b5b4b97a931e91bedf --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t3/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth6_delay_sla_burden_t3" +description = "FlowBench v3 public task metadata. Public verifier is smoke-only." +authors = [{ name = "Mind Lab", email = "contact@mindlab.ltd" }] +keywords = ["flowbench", "tool-use", "data-orchestration", "operations"] + +[metadata] +benchmark = "FlowBench-v3" +split = "public-task-only" +category = "data-processing" +depth = 6 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +network_mode = "no-network" +build_timeout_sec = 600.0 +os = "linux" +cpus = 1 +memory_mb = 2048 +storage_mb = 2048 +gpus = 0 diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t3/tests/check_output_shape.py b/harbor/tasks/v3_depth6_delay_sla_burden_t3/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t3/tests/check_output_shape.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import json +import os +import re +from pathlib import Path + + +def write_reward(score: float, diagnostic: str) -> None: + log_dir = Path(os.environ.get("LOG_DIR", "/logs/verifier")) + log_dir.mkdir(parents=True, exist_ok=True) + (log_dir / "reward.txt").write_text(f"{score:.6g}\n") + (log_dir / "reward.json").write_text( + json.dumps({"reward": score, "smoke_only": True}, indent=2) + "\n" + ) + (log_dir / "diagnostic.txt").write_text(diagnostic + "\n") + + +def main() -> int: + app_dir = Path(os.environ.get("APP_DIR", "/app")) + task = json.loads((app_dir / "task.json").read_text()) + answer_path = app_dir / "answer.txt" + if not answer_path.exists(): + write_reward(0.0, "missing /app/answer.txt") + return 1 + + got = answer_path.read_text().strip() + if task["answer_format"] == "exact integer": + ok = bool(re.fullmatch(r"-?\d+", got)) + diagnostic = "valid integer smoke output" if ok else f"not an exact integer: {got!r}" + else: + ok = bool(re.fullmatch(r"[A-Za-z]+", got)) + diagnostic = "valid code smoke output" if ok else f"not an exact code: {got!r}" + + # This is intentionally not official scoring; it only verifies I/O shape. + write_reward(1.0 if ok else 0.0, diagnostic) + return 0 if ok else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t3/tests/test.sh b/harbor/tasks/v3_depth6_delay_sla_burden_t3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t3/tests/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -u +python /tests/check_output_shape.py diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t4/environment/Dockerfile b/harbor/tasks/v3_depth6_delay_sla_burden_t4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t4/environment/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.12-slim +WORKDIR /app +COPY flowbench_tools.py /app/flowbench_tools.py +COPY task.json /app/task.json diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t4/environment/flowbench_tools.py b/harbor/tasks/v3_depth6_delay_sla_burden_t4/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t4/environment/flowbench_tools.py @@ -0,0 +1,311 @@ +"""Deterministic FlowBench v3 tools. This file contains no task answers.""" + + +REGIONS = ["NA", "EU", "APAC", "LATAM"] +CATEGORIES = ["A", "B", "C", "D"] +CURRENCIES = {"NA": "USD", "EU": "EUR", "APAC": "JPY", "LATAM": "BRL"} +FX_TO_USD_BP = {"USD": 10000, "EUR": 10900, "JPY": 67, "BRL": 1850} +TIERS = ["std", "gold", "plat"] +DISCOUNT_PCT = {"std": 0, "gold": 10, "plat": 20} +CHANNELS = ["web", "store", "partner"] +MONTHS = [202601, 202602, 202603, 202604, 202605, 202606] + +N_CUSTOMERS = 72 +N_PRODUCTS = 48 +N_ORDERS = 720 +N_TICKETS = 260 +N_RETURNS = 180 + + +def _h(*xs): + import hashlib + s = "|".join(str(x) for x in xs).encode() + return int.from_bytes(hashlib.sha256(s).digest()[:8], "big") & 0x7FFFFFFF + + +def build_data(): + customers = [] + for cid in range(N_CUSTOMERS): + region = REGIONS[_h("region", cid) % len(REGIONS)] + customers.append({ + "customer_id": cid, + "region": region, + "tier": TIERS[_h("tier", cid) % len(TIERS)], + "segment": ["consumer", "smb", "enterprise"][_h("segment", cid) % 3], + }) + + products = [] + for pid in range(N_PRODUCTS): + cat = CATEGORIES[_h("cat", pid) % len(CATEGORIES)] + unit_price = 12 + _h("price", pid) % 240 + cogs = unit_price * (45 + _h("margin", pid) % 35) // 100 + products.append({ + "product_id": pid, + "category": cat, + "unit_price_usd": unit_price, + "unit_cogs_usd": cogs, + "lead_time_days": 3 + _h("lead", pid) % 18, + }) + + inventory = [] + for pid in range(N_PRODUCTS): + for region in REGIONS: + inventory.append({ + "product_id": pid, + "region": region, + "on_hand": 10 + _h("onhand", pid, region) % 140, + "reserved": _h("reserved", pid, region) % 28, + "inbound": _h("inbound", pid, region) % 85, + }) + + orders = [] + for oid in range(N_ORDERS): + customer_id = _h("ocust", oid) % N_CUSTOMERS + product_id = _h("oprod", oid) % N_PRODUCTS + month = MONTHS[_h("month", oid) % len(MONTHS)] + qty = 1 + _h("qty", oid) % 9 + ship_days = 1 + _h("shipdays", oid) % 16 + promised_days = 3 + _h("promise", oid) % 9 + status = ["paid", "paid", "paid", "paid", "cancelled", "refunded"][ + _h("status", oid) % 6] + orders.append({ + "order_id": oid, + "customer_id": customer_id, + "product_id": product_id, + "month": month, + "qty": qty, + "status": status, + "channel": CHANNELS[_h("channel", oid) % len(CHANNELS)], + "ship_days": ship_days, + "promised_days": promised_days, + }) + + returns = [] + for rid in range(N_RETURNS): + oid = _h("roid", rid) % N_ORDERS + order = orders[oid] + if order["status"] == "cancelled": + continue + returned_qty = 1 + _h("rqty", rid) % max(1, order["qty"]) + reason = ["defect", "late", "changed_mind", "wrong_item"][_h("reason", rid) % 4] + returns.append({ + "return_id": rid, + "order_id": oid, + "month": MONTHS[_h("rmonth", rid) % len(MONTHS)], + "returned_qty": returned_qty, + "reason": reason, + }) + + tickets = [] + for tid in range(N_TICKETS): + oid = _h("toid", tid) % N_ORDERS + severity = ["low", "medium", "high", "critical"][_h("sev", tid) % 4] + opened = MONTHS[_h("tmonth", tid) % len(MONTHS)] + first_response_hours = 1 + _h("resp", tid) % 96 + resolution_hours = first_response_hours + _h("res", tid) % 240 + tickets.append({ + "ticket_id": tid, + "order_id": oid, + "opened_month": opened, + "severity": severity, + "first_response_hours": first_response_hours, + "resolution_hours": resolution_hours, + }) + + return { + "customers": customers, + "products": products, + "inventory": inventory, + "orders": orders, + "returns": returns, + "tickets": tickets, + "fx_to_usd_bp": FX_TO_USD_BP, + } + + +DATA = build_data() +CUSTOMERS = {c["customer_id"]: c for c in DATA["customers"]} +PRODUCTS = {p["product_id"]: p for p in DATA["products"]} +ORDERS = {o["order_id"]: o for o in DATA["orders"]} + + +def region_currency(region: str) -> str: + return CURRENCIES[region] + + +def get_orders(region: str, category: str, month_start: int, month_end: int) -> list: + """Paid/refunded order ids in a region/category/month window.""" + out = [] + for o in DATA["orders"]: + if o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + p = PRODUCTS[o["product_id"]] + if c["region"] == region and p["category"] == category and month_start <= o["month"] <= month_end: + out.append(o["order_id"]) + return sorted(out) + + +def order_gross_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * p["unit_price_usd"] + + +def order_margin_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * (p["unit_price_usd"] - p["unit_cogs_usd"]) + + +def refund_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + qty = sum(r["returned_qty"] for r in DATA["returns"] if r["order_id"] == order_id) + qty = min(qty, o["qty"]) + return qty * p["unit_price_usd"] + + +def customer_tier(order_id: int) -> str: + o = ORDERS[order_id] + return CUSTOMERS[o["customer_id"]]["tier"] + + +def apply_discount(amount_usd: int, tier: str) -> int: + return amount_usd * (100 - DISCOUNT_PCT[tier]) // 100 + + +def net_revenue_usd(order_id: int) -> int: + gross = apply_discount(order_gross_usd(order_id), customer_tier(order_id)) + return max(0, gross - refund_usd(order_id)) + + +def to_local(amount_usd: int, currency: str) -> int: + return amount_usd * 10000 // FX_TO_USD_BP[currency] + + +def inventory_position(product_id: int, region: str) -> int: + row = next(x for x in DATA["inventory"] + if x["product_id"] == product_id and x["region"] == region) + return row["on_hand"] - row["reserved"] + row["inbound"] + + +def product_lead_time(product_id: int) -> int: + return PRODUCTS[product_id]["lead_time_days"] + + +def product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int: + totals = {} + for oid in get_orders(region, category, month_start, month_end): + o = ORDERS[oid] + totals[o["product_id"]] = totals.get(o["product_id"], 0) + o["qty"] + if not totals: + return -1 + return min((-qty, pid) for pid, qty in totals.items())[1] + + +def units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int: + total = 0 + for o in DATA["orders"]: + if o["product_id"] != product_id or o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + if c["region"] == region and month_start <= o["month"] <= month_end: + total += o["qty"] + return total + + +def tickets_for_orders(order_ids: list, severity: str) -> list: + s = set(order_ids) + return sorted(t["ticket_id"] for t in DATA["tickets"] + if t["order_id"] in s and t["severity"] == severity) + + +def ticket_order_id(ticket_id: int) -> int: + return next(t["order_id"] for t in DATA["tickets"] if t["ticket_id"] == ticket_id) + + +def sla_breached(ticket_id: int, first_response_limit_hours: int, + resolution_limit_hours: int) -> bool: + t = next(x for x in DATA["tickets"] if x["ticket_id"] == ticket_id) + return (t["first_response_hours"] > first_response_limit_hours or + t["resolution_hours"] > resolution_limit_hours) + + +def delayed_orders(order_ids: list) -> list: + s = set(order_ids) + return sorted(o["order_id"] for o in DATA["orders"] + if o["order_id"] in s and o["ship_days"] > o["promised_days"]) + + +def unique_customers(order_ids: list) -> list: + return sorted({ORDERS[oid]["customer_id"] for oid in order_ids}) + + +def count_items(values: list) -> int: + return len(values) + + +def sum_values(values: list) -> int: + return sum(values) + + +def count_true(values: list) -> int: + return sum(1 for v in values if bool(v)) + + +def count_below(values: list, threshold: int) -> int: + return sum(1 for v in values if v < threshold) + + +TOOLS = { + "region_currency": ("region_currency(region: str) -> str", + "ISO currency code for a region.", region_currency), + "get_orders": ("get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]", + "Paid/refunded order ids for a region, product category, and inclusive month window.", + get_orders), + "order_gross_usd": ("order_gross_usd(order_id: int) -> int", + "Gross order revenue in USD before discounts/refunds.", order_gross_usd), + "order_margin_usd": ("order_margin_usd(order_id: int) -> int", + "Gross order margin in USD before discounts/refunds.", order_margin_usd), + "refund_usd": ("refund_usd(order_id: int) -> int", + "Refund amount in USD for returned quantity on an order.", refund_usd), + "customer_tier": ("customer_tier(order_id: int) -> str", + "Customer loyalty tier for an order.", customer_tier), + "apply_discount": ("apply_discount(amount_usd: int, tier: str) -> int", + "Apply the order customer's loyalty discount to a USD amount.", apply_discount), + "net_revenue_usd": ("net_revenue_usd(order_id: int) -> int", + "Net USD revenue after loyalty discount and refunds.", net_revenue_usd), + "to_local": ("to_local(amount_usd: int, currency: str) -> int", + "Convert a USD integer amount to a local-currency integer.", to_local), + "inventory_position": ("inventory_position(product_id: int, region: str) -> int", + "Available inventory position: on_hand - reserved + inbound.", + inventory_position), + "product_lead_time": ("product_lead_time(product_id: int) -> int", + "Supplier lead time in days for a product.", product_lead_time), + "product_id_for_top_seller": ( + "product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int", + "Product id with the highest units sold in a region/category/month window.", + product_id_for_top_seller), + "units_sold": ("units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int", + "Units sold for one product in a region and month window.", units_sold), + "tickets_for_orders": ("tickets_for_orders(order_ids: list[int], severity: str) -> list[int]", + "Support ticket ids for given orders and severity.", tickets_for_orders), + "ticket_order_id": ("ticket_order_id(ticket_id: int) -> int", + "Order id associated with a support ticket.", ticket_order_id), + "sla_breached": ( + "sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool", + "Whether a support ticket breaches first-response or resolution SLA.", + sla_breached), + "delayed_orders": ("delayed_orders(order_ids: list[int]) -> list[int]", + "Subset of order ids whose ship_days exceeded promised_days.", delayed_orders), + "unique_customers": ("unique_customers(order_ids: list[int]) -> list[int]", + "Unique customer ids among the given orders.", unique_customers), + "count_items": ("count_items(values: list) -> int", "Length of a list.", count_items), + "sum_values": ("sum_values(values: list[int]) -> int", "Sum a list of integers.", sum_values), + "count_true": ("count_true(values: list[bool]) -> int", "Count true values.", count_true), + "count_below": ("count_below(values: list[int], threshold: int) -> int", + "Count values below a threshold.", count_below), +} + +__all__ = [name for name in TOOLS.keys()] + ['TOOLS'] diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t4/environment/task.json b/harbor/tasks/v3_depth6_delay_sla_burden_t4/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..44e70d6f9a9b68697101f1fbed9cda6c73b32172 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t4/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth6_delay_sla_burden_t4", + "depth": 6, + "family": "delay_sla_burden", + "params": { + "region": "APAC", + "category": "A", + "month_start": 202602, + "month_end": 202605 + }, + "question": "For region APAC, category A, months 202602-202605: get the orders, count delayed orders where ship_days exceeded promised_days, find high and critical support tickets for those orders, count tickets that breach a 24-hour first-response or 120-hour resolution SLA, and report delayed_order_count + breached_ticket_count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t4/instruction.md b/harbor/tasks/v3_depth6_delay_sla_burden_t4/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..f01a9adca5fba80e88fbe9fb920e689e4e1d2a46 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t4/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For region APAC, category A, months 202602-202605: get the orders, count delayed orders where ship_days exceeded promised_days, find high and critical support tickets for those orders, count tickets that breach a 24-hour first-response or 120-hour resolution SLA, and report delayed_order_count + breached_ticket_count. + +Available tools: +- `region_currency(region: str) -> str`: ISO currency code for a region. +- `get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]`: Paid/refunded order ids for a region, product category, and inclusive month window. +- `order_gross_usd(order_id: int) -> int`: Gross order revenue in USD before discounts/refunds. +- `order_margin_usd(order_id: int) -> int`: Gross order margin in USD before discounts/refunds. +- `refund_usd(order_id: int) -> int`: Refund amount in USD for returned quantity on an order. +- `customer_tier(order_id: int) -> str`: Customer loyalty tier for an order. +- `apply_discount(amount_usd: int, tier: str) -> int`: Apply the order customer's loyalty discount to a USD amount. +- `net_revenue_usd(order_id: int) -> int`: Net USD revenue after loyalty discount and refunds. +- `to_local(amount_usd: int, currency: str) -> int`: Convert a USD integer amount to a local-currency integer. +- `inventory_position(product_id: int, region: str) -> int`: Available inventory position: on_hand - reserved + inbound. +- `product_lead_time(product_id: int) -> int`: Supplier lead time in days for a product. +- `product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int`: Product id with the highest units sold in a region/category/month window. +- `units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int`: Units sold for one product in a region and month window. +- `tickets_for_orders(order_ids: list[int], severity: str) -> list[int]`: Support ticket ids for given orders and severity. +- `ticket_order_id(ticket_id: int) -> int`: Order id associated with a support ticket. +- `sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool`: Whether a support ticket breaches first-response or resolution SLA. +- `delayed_orders(order_ids: list[int]) -> list[int]`: Subset of order ids whose ship_days exceeded promised_days. +- `unique_customers(order_ids: list[int]) -> list[int]`: Unique customer ids among the given orders. +- `count_items(values: list) -> int`: Length of a list. +- `sum_values(values: list[int]) -> int`: Sum a list of integers. +- `count_true(values: list[bool]) -> int`: Count true values. +- `count_below(values: list[int], threshold: int) -> int`: Count values below a threshold. diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t4/task.toml b/harbor/tasks/v3_depth6_delay_sla_burden_t4/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..6c438b60e5c1e089681136646130aaaaccfc672f --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t4/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth6_delay_sla_burden_t4" +description = "FlowBench v3 public task metadata. Public verifier is smoke-only." +authors = [{ name = "Mind Lab", email = "contact@mindlab.ltd" }] +keywords = ["flowbench", "tool-use", "data-orchestration", "operations"] + +[metadata] +benchmark = "FlowBench-v3" +split = "public-task-only" +category = "data-processing" +depth = 6 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +network_mode = "no-network" +build_timeout_sec = 600.0 +os = "linux" +cpus = 1 +memory_mb = 2048 +storage_mb = 2048 +gpus = 0 diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t4/tests/check_output_shape.py b/harbor/tasks/v3_depth6_delay_sla_burden_t4/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t4/tests/check_output_shape.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import json +import os +import re +from pathlib import Path + + +def write_reward(score: float, diagnostic: str) -> None: + log_dir = Path(os.environ.get("LOG_DIR", "/logs/verifier")) + log_dir.mkdir(parents=True, exist_ok=True) + (log_dir / "reward.txt").write_text(f"{score:.6g}\n") + (log_dir / "reward.json").write_text( + json.dumps({"reward": score, "smoke_only": True}, indent=2) + "\n" + ) + (log_dir / "diagnostic.txt").write_text(diagnostic + "\n") + + +def main() -> int: + app_dir = Path(os.environ.get("APP_DIR", "/app")) + task = json.loads((app_dir / "task.json").read_text()) + answer_path = app_dir / "answer.txt" + if not answer_path.exists(): + write_reward(0.0, "missing /app/answer.txt") + return 1 + + got = answer_path.read_text().strip() + if task["answer_format"] == "exact integer": + ok = bool(re.fullmatch(r"-?\d+", got)) + diagnostic = "valid integer smoke output" if ok else f"not an exact integer: {got!r}" + else: + ok = bool(re.fullmatch(r"[A-Za-z]+", got)) + diagnostic = "valid code smoke output" if ok else f"not an exact code: {got!r}" + + # This is intentionally not official scoring; it only verifies I/O shape. + write_reward(1.0 if ok else 0.0, diagnostic) + return 0 if ok else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t4/tests/test.sh b/harbor/tasks/v3_depth6_delay_sla_burden_t4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t4/tests/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -u +python /tests/check_output_shape.py diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t5/environment/Dockerfile b/harbor/tasks/v3_depth6_delay_sla_burden_t5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t5/environment/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.12-slim +WORKDIR /app +COPY flowbench_tools.py /app/flowbench_tools.py +COPY task.json /app/task.json diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t5/environment/flowbench_tools.py b/harbor/tasks/v3_depth6_delay_sla_burden_t5/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t5/environment/flowbench_tools.py @@ -0,0 +1,311 @@ +"""Deterministic FlowBench v3 tools. This file contains no task answers.""" + + +REGIONS = ["NA", "EU", "APAC", "LATAM"] +CATEGORIES = ["A", "B", "C", "D"] +CURRENCIES = {"NA": "USD", "EU": "EUR", "APAC": "JPY", "LATAM": "BRL"} +FX_TO_USD_BP = {"USD": 10000, "EUR": 10900, "JPY": 67, "BRL": 1850} +TIERS = ["std", "gold", "plat"] +DISCOUNT_PCT = {"std": 0, "gold": 10, "plat": 20} +CHANNELS = ["web", "store", "partner"] +MONTHS = [202601, 202602, 202603, 202604, 202605, 202606] + +N_CUSTOMERS = 72 +N_PRODUCTS = 48 +N_ORDERS = 720 +N_TICKETS = 260 +N_RETURNS = 180 + + +def _h(*xs): + import hashlib + s = "|".join(str(x) for x in xs).encode() + return int.from_bytes(hashlib.sha256(s).digest()[:8], "big") & 0x7FFFFFFF + + +def build_data(): + customers = [] + for cid in range(N_CUSTOMERS): + region = REGIONS[_h("region", cid) % len(REGIONS)] + customers.append({ + "customer_id": cid, + "region": region, + "tier": TIERS[_h("tier", cid) % len(TIERS)], + "segment": ["consumer", "smb", "enterprise"][_h("segment", cid) % 3], + }) + + products = [] + for pid in range(N_PRODUCTS): + cat = CATEGORIES[_h("cat", pid) % len(CATEGORIES)] + unit_price = 12 + _h("price", pid) % 240 + cogs = unit_price * (45 + _h("margin", pid) % 35) // 100 + products.append({ + "product_id": pid, + "category": cat, + "unit_price_usd": unit_price, + "unit_cogs_usd": cogs, + "lead_time_days": 3 + _h("lead", pid) % 18, + }) + + inventory = [] + for pid in range(N_PRODUCTS): + for region in REGIONS: + inventory.append({ + "product_id": pid, + "region": region, + "on_hand": 10 + _h("onhand", pid, region) % 140, + "reserved": _h("reserved", pid, region) % 28, + "inbound": _h("inbound", pid, region) % 85, + }) + + orders = [] + for oid in range(N_ORDERS): + customer_id = _h("ocust", oid) % N_CUSTOMERS + product_id = _h("oprod", oid) % N_PRODUCTS + month = MONTHS[_h("month", oid) % len(MONTHS)] + qty = 1 + _h("qty", oid) % 9 + ship_days = 1 + _h("shipdays", oid) % 16 + promised_days = 3 + _h("promise", oid) % 9 + status = ["paid", "paid", "paid", "paid", "cancelled", "refunded"][ + _h("status", oid) % 6] + orders.append({ + "order_id": oid, + "customer_id": customer_id, + "product_id": product_id, + "month": month, + "qty": qty, + "status": status, + "channel": CHANNELS[_h("channel", oid) % len(CHANNELS)], + "ship_days": ship_days, + "promised_days": promised_days, + }) + + returns = [] + for rid in range(N_RETURNS): + oid = _h("roid", rid) % N_ORDERS + order = orders[oid] + if order["status"] == "cancelled": + continue + returned_qty = 1 + _h("rqty", rid) % max(1, order["qty"]) + reason = ["defect", "late", "changed_mind", "wrong_item"][_h("reason", rid) % 4] + returns.append({ + "return_id": rid, + "order_id": oid, + "month": MONTHS[_h("rmonth", rid) % len(MONTHS)], + "returned_qty": returned_qty, + "reason": reason, + }) + + tickets = [] + for tid in range(N_TICKETS): + oid = _h("toid", tid) % N_ORDERS + severity = ["low", "medium", "high", "critical"][_h("sev", tid) % 4] + opened = MONTHS[_h("tmonth", tid) % len(MONTHS)] + first_response_hours = 1 + _h("resp", tid) % 96 + resolution_hours = first_response_hours + _h("res", tid) % 240 + tickets.append({ + "ticket_id": tid, + "order_id": oid, + "opened_month": opened, + "severity": severity, + "first_response_hours": first_response_hours, + "resolution_hours": resolution_hours, + }) + + return { + "customers": customers, + "products": products, + "inventory": inventory, + "orders": orders, + "returns": returns, + "tickets": tickets, + "fx_to_usd_bp": FX_TO_USD_BP, + } + + +DATA = build_data() +CUSTOMERS = {c["customer_id"]: c for c in DATA["customers"]} +PRODUCTS = {p["product_id"]: p for p in DATA["products"]} +ORDERS = {o["order_id"]: o for o in DATA["orders"]} + + +def region_currency(region: str) -> str: + return CURRENCIES[region] + + +def get_orders(region: str, category: str, month_start: int, month_end: int) -> list: + """Paid/refunded order ids in a region/category/month window.""" + out = [] + for o in DATA["orders"]: + if o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + p = PRODUCTS[o["product_id"]] + if c["region"] == region and p["category"] == category and month_start <= o["month"] <= month_end: + out.append(o["order_id"]) + return sorted(out) + + +def order_gross_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * p["unit_price_usd"] + + +def order_margin_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * (p["unit_price_usd"] - p["unit_cogs_usd"]) + + +def refund_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + qty = sum(r["returned_qty"] for r in DATA["returns"] if r["order_id"] == order_id) + qty = min(qty, o["qty"]) + return qty * p["unit_price_usd"] + + +def customer_tier(order_id: int) -> str: + o = ORDERS[order_id] + return CUSTOMERS[o["customer_id"]]["tier"] + + +def apply_discount(amount_usd: int, tier: str) -> int: + return amount_usd * (100 - DISCOUNT_PCT[tier]) // 100 + + +def net_revenue_usd(order_id: int) -> int: + gross = apply_discount(order_gross_usd(order_id), customer_tier(order_id)) + return max(0, gross - refund_usd(order_id)) + + +def to_local(amount_usd: int, currency: str) -> int: + return amount_usd * 10000 // FX_TO_USD_BP[currency] + + +def inventory_position(product_id: int, region: str) -> int: + row = next(x for x in DATA["inventory"] + if x["product_id"] == product_id and x["region"] == region) + return row["on_hand"] - row["reserved"] + row["inbound"] + + +def product_lead_time(product_id: int) -> int: + return PRODUCTS[product_id]["lead_time_days"] + + +def product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int: + totals = {} + for oid in get_orders(region, category, month_start, month_end): + o = ORDERS[oid] + totals[o["product_id"]] = totals.get(o["product_id"], 0) + o["qty"] + if not totals: + return -1 + return min((-qty, pid) for pid, qty in totals.items())[1] + + +def units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int: + total = 0 + for o in DATA["orders"]: + if o["product_id"] != product_id or o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + if c["region"] == region and month_start <= o["month"] <= month_end: + total += o["qty"] + return total + + +def tickets_for_orders(order_ids: list, severity: str) -> list: + s = set(order_ids) + return sorted(t["ticket_id"] for t in DATA["tickets"] + if t["order_id"] in s and t["severity"] == severity) + + +def ticket_order_id(ticket_id: int) -> int: + return next(t["order_id"] for t in DATA["tickets"] if t["ticket_id"] == ticket_id) + + +def sla_breached(ticket_id: int, first_response_limit_hours: int, + resolution_limit_hours: int) -> bool: + t = next(x for x in DATA["tickets"] if x["ticket_id"] == ticket_id) + return (t["first_response_hours"] > first_response_limit_hours or + t["resolution_hours"] > resolution_limit_hours) + + +def delayed_orders(order_ids: list) -> list: + s = set(order_ids) + return sorted(o["order_id"] for o in DATA["orders"] + if o["order_id"] in s and o["ship_days"] > o["promised_days"]) + + +def unique_customers(order_ids: list) -> list: + return sorted({ORDERS[oid]["customer_id"] for oid in order_ids}) + + +def count_items(values: list) -> int: + return len(values) + + +def sum_values(values: list) -> int: + return sum(values) + + +def count_true(values: list) -> int: + return sum(1 for v in values if bool(v)) + + +def count_below(values: list, threshold: int) -> int: + return sum(1 for v in values if v < threshold) + + +TOOLS = { + "region_currency": ("region_currency(region: str) -> str", + "ISO currency code for a region.", region_currency), + "get_orders": ("get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]", + "Paid/refunded order ids for a region, product category, and inclusive month window.", + get_orders), + "order_gross_usd": ("order_gross_usd(order_id: int) -> int", + "Gross order revenue in USD before discounts/refunds.", order_gross_usd), + "order_margin_usd": ("order_margin_usd(order_id: int) -> int", + "Gross order margin in USD before discounts/refunds.", order_margin_usd), + "refund_usd": ("refund_usd(order_id: int) -> int", + "Refund amount in USD for returned quantity on an order.", refund_usd), + "customer_tier": ("customer_tier(order_id: int) -> str", + "Customer loyalty tier for an order.", customer_tier), + "apply_discount": ("apply_discount(amount_usd: int, tier: str) -> int", + "Apply the order customer's loyalty discount to a USD amount.", apply_discount), + "net_revenue_usd": ("net_revenue_usd(order_id: int) -> int", + "Net USD revenue after loyalty discount and refunds.", net_revenue_usd), + "to_local": ("to_local(amount_usd: int, currency: str) -> int", + "Convert a USD integer amount to a local-currency integer.", to_local), + "inventory_position": ("inventory_position(product_id: int, region: str) -> int", + "Available inventory position: on_hand - reserved + inbound.", + inventory_position), + "product_lead_time": ("product_lead_time(product_id: int) -> int", + "Supplier lead time in days for a product.", product_lead_time), + "product_id_for_top_seller": ( + "product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int", + "Product id with the highest units sold in a region/category/month window.", + product_id_for_top_seller), + "units_sold": ("units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int", + "Units sold for one product in a region and month window.", units_sold), + "tickets_for_orders": ("tickets_for_orders(order_ids: list[int], severity: str) -> list[int]", + "Support ticket ids for given orders and severity.", tickets_for_orders), + "ticket_order_id": ("ticket_order_id(ticket_id: int) -> int", + "Order id associated with a support ticket.", ticket_order_id), + "sla_breached": ( + "sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool", + "Whether a support ticket breaches first-response or resolution SLA.", + sla_breached), + "delayed_orders": ("delayed_orders(order_ids: list[int]) -> list[int]", + "Subset of order ids whose ship_days exceeded promised_days.", delayed_orders), + "unique_customers": ("unique_customers(order_ids: list[int]) -> list[int]", + "Unique customer ids among the given orders.", unique_customers), + "count_items": ("count_items(values: list) -> int", "Length of a list.", count_items), + "sum_values": ("sum_values(values: list[int]) -> int", "Sum a list of integers.", sum_values), + "count_true": ("count_true(values: list[bool]) -> int", "Count true values.", count_true), + "count_below": ("count_below(values: list[int], threshold: int) -> int", + "Count values below a threshold.", count_below), +} + +__all__ = [name for name in TOOLS.keys()] + ['TOOLS'] diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t5/environment/task.json b/harbor/tasks/v3_depth6_delay_sla_burden_t5/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..63dc67682458a5ea6f8251a9757831092c2d9518 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t5/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth6_delay_sla_burden_t5", + "depth": 6, + "family": "delay_sla_burden", + "params": { + "region": "APAC", + "category": "D", + "month_start": 202601, + "month_end": 202606 + }, + "question": "For region APAC, category D, months 202601-202606: get the orders, count delayed orders where ship_days exceeded promised_days, find high and critical support tickets for those orders, count tickets that breach a 24-hour first-response or 120-hour resolution SLA, and report delayed_order_count + breached_ticket_count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t5/instruction.md b/harbor/tasks/v3_depth6_delay_sla_burden_t5/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..8db3b592a684838fabdd16a9f8b6b248a2839d37 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t5/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For region APAC, category D, months 202601-202606: get the orders, count delayed orders where ship_days exceeded promised_days, find high and critical support tickets for those orders, count tickets that breach a 24-hour first-response or 120-hour resolution SLA, and report delayed_order_count + breached_ticket_count. + +Available tools: +- `region_currency(region: str) -> str`: ISO currency code for a region. +- `get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]`: Paid/refunded order ids for a region, product category, and inclusive month window. +- `order_gross_usd(order_id: int) -> int`: Gross order revenue in USD before discounts/refunds. +- `order_margin_usd(order_id: int) -> int`: Gross order margin in USD before discounts/refunds. +- `refund_usd(order_id: int) -> int`: Refund amount in USD for returned quantity on an order. +- `customer_tier(order_id: int) -> str`: Customer loyalty tier for an order. +- `apply_discount(amount_usd: int, tier: str) -> int`: Apply the order customer's loyalty discount to a USD amount. +- `net_revenue_usd(order_id: int) -> int`: Net USD revenue after loyalty discount and refunds. +- `to_local(amount_usd: int, currency: str) -> int`: Convert a USD integer amount to a local-currency integer. +- `inventory_position(product_id: int, region: str) -> int`: Available inventory position: on_hand - reserved + inbound. +- `product_lead_time(product_id: int) -> int`: Supplier lead time in days for a product. +- `product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int`: Product id with the highest units sold in a region/category/month window. +- `units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int`: Units sold for one product in a region and month window. +- `tickets_for_orders(order_ids: list[int], severity: str) -> list[int]`: Support ticket ids for given orders and severity. +- `ticket_order_id(ticket_id: int) -> int`: Order id associated with a support ticket. +- `sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool`: Whether a support ticket breaches first-response or resolution SLA. +- `delayed_orders(order_ids: list[int]) -> list[int]`: Subset of order ids whose ship_days exceeded promised_days. +- `unique_customers(order_ids: list[int]) -> list[int]`: Unique customer ids among the given orders. +- `count_items(values: list) -> int`: Length of a list. +- `sum_values(values: list[int]) -> int`: Sum a list of integers. +- `count_true(values: list[bool]) -> int`: Count true values. +- `count_below(values: list[int], threshold: int) -> int`: Count values below a threshold. diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t5/task.toml b/harbor/tasks/v3_depth6_delay_sla_burden_t5/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..9c13373ae8364311f2040f460a6de406bf5fd169 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t5/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth6_delay_sla_burden_t5" +description = "FlowBench v3 public task metadata. Public verifier is smoke-only." +authors = [{ name = "Mind Lab", email = "contact@mindlab.ltd" }] +keywords = ["flowbench", "tool-use", "data-orchestration", "operations"] + +[metadata] +benchmark = "FlowBench-v3" +split = "public-task-only" +category = "data-processing" +depth = 6 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +network_mode = "no-network" +build_timeout_sec = 600.0 +os = "linux" +cpus = 1 +memory_mb = 2048 +storage_mb = 2048 +gpus = 0 diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t5/tests/check_output_shape.py b/harbor/tasks/v3_depth6_delay_sla_burden_t5/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t5/tests/check_output_shape.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import json +import os +import re +from pathlib import Path + + +def write_reward(score: float, diagnostic: str) -> None: + log_dir = Path(os.environ.get("LOG_DIR", "/logs/verifier")) + log_dir.mkdir(parents=True, exist_ok=True) + (log_dir / "reward.txt").write_text(f"{score:.6g}\n") + (log_dir / "reward.json").write_text( + json.dumps({"reward": score, "smoke_only": True}, indent=2) + "\n" + ) + (log_dir / "diagnostic.txt").write_text(diagnostic + "\n") + + +def main() -> int: + app_dir = Path(os.environ.get("APP_DIR", "/app")) + task = json.loads((app_dir / "task.json").read_text()) + answer_path = app_dir / "answer.txt" + if not answer_path.exists(): + write_reward(0.0, "missing /app/answer.txt") + return 1 + + got = answer_path.read_text().strip() + if task["answer_format"] == "exact integer": + ok = bool(re.fullmatch(r"-?\d+", got)) + diagnostic = "valid integer smoke output" if ok else f"not an exact integer: {got!r}" + else: + ok = bool(re.fullmatch(r"[A-Za-z]+", got)) + diagnostic = "valid code smoke output" if ok else f"not an exact code: {got!r}" + + # This is intentionally not official scoring; it only verifies I/O shape. + write_reward(1.0 if ok else 0.0, diagnostic) + return 0 if ok else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t5/tests/test.sh b/harbor/tasks/v3_depth6_delay_sla_burden_t5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t5/tests/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -u +python /tests/check_output_shape.py diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t6/environment/Dockerfile b/harbor/tasks/v3_depth6_delay_sla_burden_t6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t6/environment/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.12-slim +WORKDIR /app +COPY flowbench_tools.py /app/flowbench_tools.py +COPY task.json /app/task.json diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t6/environment/flowbench_tools.py b/harbor/tasks/v3_depth6_delay_sla_burden_t6/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t6/environment/flowbench_tools.py @@ -0,0 +1,311 @@ +"""Deterministic FlowBench v3 tools. This file contains no task answers.""" + + +REGIONS = ["NA", "EU", "APAC", "LATAM"] +CATEGORIES = ["A", "B", "C", "D"] +CURRENCIES = {"NA": "USD", "EU": "EUR", "APAC": "JPY", "LATAM": "BRL"} +FX_TO_USD_BP = {"USD": 10000, "EUR": 10900, "JPY": 67, "BRL": 1850} +TIERS = ["std", "gold", "plat"] +DISCOUNT_PCT = {"std": 0, "gold": 10, "plat": 20} +CHANNELS = ["web", "store", "partner"] +MONTHS = [202601, 202602, 202603, 202604, 202605, 202606] + +N_CUSTOMERS = 72 +N_PRODUCTS = 48 +N_ORDERS = 720 +N_TICKETS = 260 +N_RETURNS = 180 + + +def _h(*xs): + import hashlib + s = "|".join(str(x) for x in xs).encode() + return int.from_bytes(hashlib.sha256(s).digest()[:8], "big") & 0x7FFFFFFF + + +def build_data(): + customers = [] + for cid in range(N_CUSTOMERS): + region = REGIONS[_h("region", cid) % len(REGIONS)] + customers.append({ + "customer_id": cid, + "region": region, + "tier": TIERS[_h("tier", cid) % len(TIERS)], + "segment": ["consumer", "smb", "enterprise"][_h("segment", cid) % 3], + }) + + products = [] + for pid in range(N_PRODUCTS): + cat = CATEGORIES[_h("cat", pid) % len(CATEGORIES)] + unit_price = 12 + _h("price", pid) % 240 + cogs = unit_price * (45 + _h("margin", pid) % 35) // 100 + products.append({ + "product_id": pid, + "category": cat, + "unit_price_usd": unit_price, + "unit_cogs_usd": cogs, + "lead_time_days": 3 + _h("lead", pid) % 18, + }) + + inventory = [] + for pid in range(N_PRODUCTS): + for region in REGIONS: + inventory.append({ + "product_id": pid, + "region": region, + "on_hand": 10 + _h("onhand", pid, region) % 140, + "reserved": _h("reserved", pid, region) % 28, + "inbound": _h("inbound", pid, region) % 85, + }) + + orders = [] + for oid in range(N_ORDERS): + customer_id = _h("ocust", oid) % N_CUSTOMERS + product_id = _h("oprod", oid) % N_PRODUCTS + month = MONTHS[_h("month", oid) % len(MONTHS)] + qty = 1 + _h("qty", oid) % 9 + ship_days = 1 + _h("shipdays", oid) % 16 + promised_days = 3 + _h("promise", oid) % 9 + status = ["paid", "paid", "paid", "paid", "cancelled", "refunded"][ + _h("status", oid) % 6] + orders.append({ + "order_id": oid, + "customer_id": customer_id, + "product_id": product_id, + "month": month, + "qty": qty, + "status": status, + "channel": CHANNELS[_h("channel", oid) % len(CHANNELS)], + "ship_days": ship_days, + "promised_days": promised_days, + }) + + returns = [] + for rid in range(N_RETURNS): + oid = _h("roid", rid) % N_ORDERS + order = orders[oid] + if order["status"] == "cancelled": + continue + returned_qty = 1 + _h("rqty", rid) % max(1, order["qty"]) + reason = ["defect", "late", "changed_mind", "wrong_item"][_h("reason", rid) % 4] + returns.append({ + "return_id": rid, + "order_id": oid, + "month": MONTHS[_h("rmonth", rid) % len(MONTHS)], + "returned_qty": returned_qty, + "reason": reason, + }) + + tickets = [] + for tid in range(N_TICKETS): + oid = _h("toid", tid) % N_ORDERS + severity = ["low", "medium", "high", "critical"][_h("sev", tid) % 4] + opened = MONTHS[_h("tmonth", tid) % len(MONTHS)] + first_response_hours = 1 + _h("resp", tid) % 96 + resolution_hours = first_response_hours + _h("res", tid) % 240 + tickets.append({ + "ticket_id": tid, + "order_id": oid, + "opened_month": opened, + "severity": severity, + "first_response_hours": first_response_hours, + "resolution_hours": resolution_hours, + }) + + return { + "customers": customers, + "products": products, + "inventory": inventory, + "orders": orders, + "returns": returns, + "tickets": tickets, + "fx_to_usd_bp": FX_TO_USD_BP, + } + + +DATA = build_data() +CUSTOMERS = {c["customer_id"]: c for c in DATA["customers"]} +PRODUCTS = {p["product_id"]: p for p in DATA["products"]} +ORDERS = {o["order_id"]: o for o in DATA["orders"]} + + +def region_currency(region: str) -> str: + return CURRENCIES[region] + + +def get_orders(region: str, category: str, month_start: int, month_end: int) -> list: + """Paid/refunded order ids in a region/category/month window.""" + out = [] + for o in DATA["orders"]: + if o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + p = PRODUCTS[o["product_id"]] + if c["region"] == region and p["category"] == category and month_start <= o["month"] <= month_end: + out.append(o["order_id"]) + return sorted(out) + + +def order_gross_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * p["unit_price_usd"] + + +def order_margin_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * (p["unit_price_usd"] - p["unit_cogs_usd"]) + + +def refund_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + qty = sum(r["returned_qty"] for r in DATA["returns"] if r["order_id"] == order_id) + qty = min(qty, o["qty"]) + return qty * p["unit_price_usd"] + + +def customer_tier(order_id: int) -> str: + o = ORDERS[order_id] + return CUSTOMERS[o["customer_id"]]["tier"] + + +def apply_discount(amount_usd: int, tier: str) -> int: + return amount_usd * (100 - DISCOUNT_PCT[tier]) // 100 + + +def net_revenue_usd(order_id: int) -> int: + gross = apply_discount(order_gross_usd(order_id), customer_tier(order_id)) + return max(0, gross - refund_usd(order_id)) + + +def to_local(amount_usd: int, currency: str) -> int: + return amount_usd * 10000 // FX_TO_USD_BP[currency] + + +def inventory_position(product_id: int, region: str) -> int: + row = next(x for x in DATA["inventory"] + if x["product_id"] == product_id and x["region"] == region) + return row["on_hand"] - row["reserved"] + row["inbound"] + + +def product_lead_time(product_id: int) -> int: + return PRODUCTS[product_id]["lead_time_days"] + + +def product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int: + totals = {} + for oid in get_orders(region, category, month_start, month_end): + o = ORDERS[oid] + totals[o["product_id"]] = totals.get(o["product_id"], 0) + o["qty"] + if not totals: + return -1 + return min((-qty, pid) for pid, qty in totals.items())[1] + + +def units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int: + total = 0 + for o in DATA["orders"]: + if o["product_id"] != product_id or o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + if c["region"] == region and month_start <= o["month"] <= month_end: + total += o["qty"] + return total + + +def tickets_for_orders(order_ids: list, severity: str) -> list: + s = set(order_ids) + return sorted(t["ticket_id"] for t in DATA["tickets"] + if t["order_id"] in s and t["severity"] == severity) + + +def ticket_order_id(ticket_id: int) -> int: + return next(t["order_id"] for t in DATA["tickets"] if t["ticket_id"] == ticket_id) + + +def sla_breached(ticket_id: int, first_response_limit_hours: int, + resolution_limit_hours: int) -> bool: + t = next(x for x in DATA["tickets"] if x["ticket_id"] == ticket_id) + return (t["first_response_hours"] > first_response_limit_hours or + t["resolution_hours"] > resolution_limit_hours) + + +def delayed_orders(order_ids: list) -> list: + s = set(order_ids) + return sorted(o["order_id"] for o in DATA["orders"] + if o["order_id"] in s and o["ship_days"] > o["promised_days"]) + + +def unique_customers(order_ids: list) -> list: + return sorted({ORDERS[oid]["customer_id"] for oid in order_ids}) + + +def count_items(values: list) -> int: + return len(values) + + +def sum_values(values: list) -> int: + return sum(values) + + +def count_true(values: list) -> int: + return sum(1 for v in values if bool(v)) + + +def count_below(values: list, threshold: int) -> int: + return sum(1 for v in values if v < threshold) + + +TOOLS = { + "region_currency": ("region_currency(region: str) -> str", + "ISO currency code for a region.", region_currency), + "get_orders": ("get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]", + "Paid/refunded order ids for a region, product category, and inclusive month window.", + get_orders), + "order_gross_usd": ("order_gross_usd(order_id: int) -> int", + "Gross order revenue in USD before discounts/refunds.", order_gross_usd), + "order_margin_usd": ("order_margin_usd(order_id: int) -> int", + "Gross order margin in USD before discounts/refunds.", order_margin_usd), + "refund_usd": ("refund_usd(order_id: int) -> int", + "Refund amount in USD for returned quantity on an order.", refund_usd), + "customer_tier": ("customer_tier(order_id: int) -> str", + "Customer loyalty tier for an order.", customer_tier), + "apply_discount": ("apply_discount(amount_usd: int, tier: str) -> int", + "Apply the order customer's loyalty discount to a USD amount.", apply_discount), + "net_revenue_usd": ("net_revenue_usd(order_id: int) -> int", + "Net USD revenue after loyalty discount and refunds.", net_revenue_usd), + "to_local": ("to_local(amount_usd: int, currency: str) -> int", + "Convert a USD integer amount to a local-currency integer.", to_local), + "inventory_position": ("inventory_position(product_id: int, region: str) -> int", + "Available inventory position: on_hand - reserved + inbound.", + inventory_position), + "product_lead_time": ("product_lead_time(product_id: int) -> int", + "Supplier lead time in days for a product.", product_lead_time), + "product_id_for_top_seller": ( + "product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int", + "Product id with the highest units sold in a region/category/month window.", + product_id_for_top_seller), + "units_sold": ("units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int", + "Units sold for one product in a region and month window.", units_sold), + "tickets_for_orders": ("tickets_for_orders(order_ids: list[int], severity: str) -> list[int]", + "Support ticket ids for given orders and severity.", tickets_for_orders), + "ticket_order_id": ("ticket_order_id(ticket_id: int) -> int", + "Order id associated with a support ticket.", ticket_order_id), + "sla_breached": ( + "sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool", + "Whether a support ticket breaches first-response or resolution SLA.", + sla_breached), + "delayed_orders": ("delayed_orders(order_ids: list[int]) -> list[int]", + "Subset of order ids whose ship_days exceeded promised_days.", delayed_orders), + "unique_customers": ("unique_customers(order_ids: list[int]) -> list[int]", + "Unique customer ids among the given orders.", unique_customers), + "count_items": ("count_items(values: list) -> int", "Length of a list.", count_items), + "sum_values": ("sum_values(values: list[int]) -> int", "Sum a list of integers.", sum_values), + "count_true": ("count_true(values: list[bool]) -> int", "Count true values.", count_true), + "count_below": ("count_below(values: list[int], threshold: int) -> int", + "Count values below a threshold.", count_below), +} + +__all__ = [name for name in TOOLS.keys()] + ['TOOLS'] diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t6/environment/task.json b/harbor/tasks/v3_depth6_delay_sla_burden_t6/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..428e92440c8767a0dd73cecf37409e7f830778b2 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t6/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth6_delay_sla_burden_t6", + "depth": 6, + "family": "delay_sla_burden", + "params": { + "region": "LATAM", + "category": "B", + "month_start": 202601, + "month_end": 202604 + }, + "question": "For region LATAM, category B, months 202601-202604: get the orders, count delayed orders where ship_days exceeded promised_days, find high and critical support tickets for those orders, count tickets that breach a 24-hour first-response or 120-hour resolution SLA, and report delayed_order_count + breached_ticket_count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t6/instruction.md b/harbor/tasks/v3_depth6_delay_sla_burden_t6/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..40518168f1675f5dc88a7ea3fbb352f387b45518 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t6/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For region LATAM, category B, months 202601-202604: get the orders, count delayed orders where ship_days exceeded promised_days, find high and critical support tickets for those orders, count tickets that breach a 24-hour first-response or 120-hour resolution SLA, and report delayed_order_count + breached_ticket_count. + +Available tools: +- `region_currency(region: str) -> str`: ISO currency code for a region. +- `get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]`: Paid/refunded order ids for a region, product category, and inclusive month window. +- `order_gross_usd(order_id: int) -> int`: Gross order revenue in USD before discounts/refunds. +- `order_margin_usd(order_id: int) -> int`: Gross order margin in USD before discounts/refunds. +- `refund_usd(order_id: int) -> int`: Refund amount in USD for returned quantity on an order. +- `customer_tier(order_id: int) -> str`: Customer loyalty tier for an order. +- `apply_discount(amount_usd: int, tier: str) -> int`: Apply the order customer's loyalty discount to a USD amount. +- `net_revenue_usd(order_id: int) -> int`: Net USD revenue after loyalty discount and refunds. +- `to_local(amount_usd: int, currency: str) -> int`: Convert a USD integer amount to a local-currency integer. +- `inventory_position(product_id: int, region: str) -> int`: Available inventory position: on_hand - reserved + inbound. +- `product_lead_time(product_id: int) -> int`: Supplier lead time in days for a product. +- `product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int`: Product id with the highest units sold in a region/category/month window. +- `units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int`: Units sold for one product in a region and month window. +- `tickets_for_orders(order_ids: list[int], severity: str) -> list[int]`: Support ticket ids for given orders and severity. +- `ticket_order_id(ticket_id: int) -> int`: Order id associated with a support ticket. +- `sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool`: Whether a support ticket breaches first-response or resolution SLA. +- `delayed_orders(order_ids: list[int]) -> list[int]`: Subset of order ids whose ship_days exceeded promised_days. +- `unique_customers(order_ids: list[int]) -> list[int]`: Unique customer ids among the given orders. +- `count_items(values: list) -> int`: Length of a list. +- `sum_values(values: list[int]) -> int`: Sum a list of integers. +- `count_true(values: list[bool]) -> int`: Count true values. +- `count_below(values: list[int], threshold: int) -> int`: Count values below a threshold. diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t6/task.toml b/harbor/tasks/v3_depth6_delay_sla_burden_t6/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..6d4062127ce1861be446196f78a09ca493570147 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t6/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth6_delay_sla_burden_t6" +description = "FlowBench v3 public task metadata. Public verifier is smoke-only." +authors = [{ name = "Mind Lab", email = "contact@mindlab.ltd" }] +keywords = ["flowbench", "tool-use", "data-orchestration", "operations"] + +[metadata] +benchmark = "FlowBench-v3" +split = "public-task-only" +category = "data-processing" +depth = 6 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +network_mode = "no-network" +build_timeout_sec = 600.0 +os = "linux" +cpus = 1 +memory_mb = 2048 +storage_mb = 2048 +gpus = 0 diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t6/tests/check_output_shape.py b/harbor/tasks/v3_depth6_delay_sla_burden_t6/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t6/tests/check_output_shape.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import json +import os +import re +from pathlib import Path + + +def write_reward(score: float, diagnostic: str) -> None: + log_dir = Path(os.environ.get("LOG_DIR", "/logs/verifier")) + log_dir.mkdir(parents=True, exist_ok=True) + (log_dir / "reward.txt").write_text(f"{score:.6g}\n") + (log_dir / "reward.json").write_text( + json.dumps({"reward": score, "smoke_only": True}, indent=2) + "\n" + ) + (log_dir / "diagnostic.txt").write_text(diagnostic + "\n") + + +def main() -> int: + app_dir = Path(os.environ.get("APP_DIR", "/app")) + task = json.loads((app_dir / "task.json").read_text()) + answer_path = app_dir / "answer.txt" + if not answer_path.exists(): + write_reward(0.0, "missing /app/answer.txt") + return 1 + + got = answer_path.read_text().strip() + if task["answer_format"] == "exact integer": + ok = bool(re.fullmatch(r"-?\d+", got)) + diagnostic = "valid integer smoke output" if ok else f"not an exact integer: {got!r}" + else: + ok = bool(re.fullmatch(r"[A-Za-z]+", got)) + diagnostic = "valid code smoke output" if ok else f"not an exact code: {got!r}" + + # This is intentionally not official scoring; it only verifies I/O shape. + write_reward(1.0 if ok else 0.0, diagnostic) + return 0 if ok else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t6/tests/test.sh b/harbor/tasks/v3_depth6_delay_sla_burden_t6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t6/tests/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -u +python /tests/check_output_shape.py diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t7/environment/Dockerfile b/harbor/tasks/v3_depth6_delay_sla_burden_t7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t7/environment/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.12-slim +WORKDIR /app +COPY flowbench_tools.py /app/flowbench_tools.py +COPY task.json /app/task.json diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t7/environment/flowbench_tools.py b/harbor/tasks/v3_depth6_delay_sla_burden_t7/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t7/environment/flowbench_tools.py @@ -0,0 +1,311 @@ +"""Deterministic FlowBench v3 tools. This file contains no task answers.""" + + +REGIONS = ["NA", "EU", "APAC", "LATAM"] +CATEGORIES = ["A", "B", "C", "D"] +CURRENCIES = {"NA": "USD", "EU": "EUR", "APAC": "JPY", "LATAM": "BRL"} +FX_TO_USD_BP = {"USD": 10000, "EUR": 10900, "JPY": 67, "BRL": 1850} +TIERS = ["std", "gold", "plat"] +DISCOUNT_PCT = {"std": 0, "gold": 10, "plat": 20} +CHANNELS = ["web", "store", "partner"] +MONTHS = [202601, 202602, 202603, 202604, 202605, 202606] + +N_CUSTOMERS = 72 +N_PRODUCTS = 48 +N_ORDERS = 720 +N_TICKETS = 260 +N_RETURNS = 180 + + +def _h(*xs): + import hashlib + s = "|".join(str(x) for x in xs).encode() + return int.from_bytes(hashlib.sha256(s).digest()[:8], "big") & 0x7FFFFFFF + + +def build_data(): + customers = [] + for cid in range(N_CUSTOMERS): + region = REGIONS[_h("region", cid) % len(REGIONS)] + customers.append({ + "customer_id": cid, + "region": region, + "tier": TIERS[_h("tier", cid) % len(TIERS)], + "segment": ["consumer", "smb", "enterprise"][_h("segment", cid) % 3], + }) + + products = [] + for pid in range(N_PRODUCTS): + cat = CATEGORIES[_h("cat", pid) % len(CATEGORIES)] + unit_price = 12 + _h("price", pid) % 240 + cogs = unit_price * (45 + _h("margin", pid) % 35) // 100 + products.append({ + "product_id": pid, + "category": cat, + "unit_price_usd": unit_price, + "unit_cogs_usd": cogs, + "lead_time_days": 3 + _h("lead", pid) % 18, + }) + + inventory = [] + for pid in range(N_PRODUCTS): + for region in REGIONS: + inventory.append({ + "product_id": pid, + "region": region, + "on_hand": 10 + _h("onhand", pid, region) % 140, + "reserved": _h("reserved", pid, region) % 28, + "inbound": _h("inbound", pid, region) % 85, + }) + + orders = [] + for oid in range(N_ORDERS): + customer_id = _h("ocust", oid) % N_CUSTOMERS + product_id = _h("oprod", oid) % N_PRODUCTS + month = MONTHS[_h("month", oid) % len(MONTHS)] + qty = 1 + _h("qty", oid) % 9 + ship_days = 1 + _h("shipdays", oid) % 16 + promised_days = 3 + _h("promise", oid) % 9 + status = ["paid", "paid", "paid", "paid", "cancelled", "refunded"][ + _h("status", oid) % 6] + orders.append({ + "order_id": oid, + "customer_id": customer_id, + "product_id": product_id, + "month": month, + "qty": qty, + "status": status, + "channel": CHANNELS[_h("channel", oid) % len(CHANNELS)], + "ship_days": ship_days, + "promised_days": promised_days, + }) + + returns = [] + for rid in range(N_RETURNS): + oid = _h("roid", rid) % N_ORDERS + order = orders[oid] + if order["status"] == "cancelled": + continue + returned_qty = 1 + _h("rqty", rid) % max(1, order["qty"]) + reason = ["defect", "late", "changed_mind", "wrong_item"][_h("reason", rid) % 4] + returns.append({ + "return_id": rid, + "order_id": oid, + "month": MONTHS[_h("rmonth", rid) % len(MONTHS)], + "returned_qty": returned_qty, + "reason": reason, + }) + + tickets = [] + for tid in range(N_TICKETS): + oid = _h("toid", tid) % N_ORDERS + severity = ["low", "medium", "high", "critical"][_h("sev", tid) % 4] + opened = MONTHS[_h("tmonth", tid) % len(MONTHS)] + first_response_hours = 1 + _h("resp", tid) % 96 + resolution_hours = first_response_hours + _h("res", tid) % 240 + tickets.append({ + "ticket_id": tid, + "order_id": oid, + "opened_month": opened, + "severity": severity, + "first_response_hours": first_response_hours, + "resolution_hours": resolution_hours, + }) + + return { + "customers": customers, + "products": products, + "inventory": inventory, + "orders": orders, + "returns": returns, + "tickets": tickets, + "fx_to_usd_bp": FX_TO_USD_BP, + } + + +DATA = build_data() +CUSTOMERS = {c["customer_id"]: c for c in DATA["customers"]} +PRODUCTS = {p["product_id"]: p for p in DATA["products"]} +ORDERS = {o["order_id"]: o for o in DATA["orders"]} + + +def region_currency(region: str) -> str: + return CURRENCIES[region] + + +def get_orders(region: str, category: str, month_start: int, month_end: int) -> list: + """Paid/refunded order ids in a region/category/month window.""" + out = [] + for o in DATA["orders"]: + if o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + p = PRODUCTS[o["product_id"]] + if c["region"] == region and p["category"] == category and month_start <= o["month"] <= month_end: + out.append(o["order_id"]) + return sorted(out) + + +def order_gross_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * p["unit_price_usd"] + + +def order_margin_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * (p["unit_price_usd"] - p["unit_cogs_usd"]) + + +def refund_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + qty = sum(r["returned_qty"] for r in DATA["returns"] if r["order_id"] == order_id) + qty = min(qty, o["qty"]) + return qty * p["unit_price_usd"] + + +def customer_tier(order_id: int) -> str: + o = ORDERS[order_id] + return CUSTOMERS[o["customer_id"]]["tier"] + + +def apply_discount(amount_usd: int, tier: str) -> int: + return amount_usd * (100 - DISCOUNT_PCT[tier]) // 100 + + +def net_revenue_usd(order_id: int) -> int: + gross = apply_discount(order_gross_usd(order_id), customer_tier(order_id)) + return max(0, gross - refund_usd(order_id)) + + +def to_local(amount_usd: int, currency: str) -> int: + return amount_usd * 10000 // FX_TO_USD_BP[currency] + + +def inventory_position(product_id: int, region: str) -> int: + row = next(x for x in DATA["inventory"] + if x["product_id"] == product_id and x["region"] == region) + return row["on_hand"] - row["reserved"] + row["inbound"] + + +def product_lead_time(product_id: int) -> int: + return PRODUCTS[product_id]["lead_time_days"] + + +def product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int: + totals = {} + for oid in get_orders(region, category, month_start, month_end): + o = ORDERS[oid] + totals[o["product_id"]] = totals.get(o["product_id"], 0) + o["qty"] + if not totals: + return -1 + return min((-qty, pid) for pid, qty in totals.items())[1] + + +def units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int: + total = 0 + for o in DATA["orders"]: + if o["product_id"] != product_id or o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + if c["region"] == region and month_start <= o["month"] <= month_end: + total += o["qty"] + return total + + +def tickets_for_orders(order_ids: list, severity: str) -> list: + s = set(order_ids) + return sorted(t["ticket_id"] for t in DATA["tickets"] + if t["order_id"] in s and t["severity"] == severity) + + +def ticket_order_id(ticket_id: int) -> int: + return next(t["order_id"] for t in DATA["tickets"] if t["ticket_id"] == ticket_id) + + +def sla_breached(ticket_id: int, first_response_limit_hours: int, + resolution_limit_hours: int) -> bool: + t = next(x for x in DATA["tickets"] if x["ticket_id"] == ticket_id) + return (t["first_response_hours"] > first_response_limit_hours or + t["resolution_hours"] > resolution_limit_hours) + + +def delayed_orders(order_ids: list) -> list: + s = set(order_ids) + return sorted(o["order_id"] for o in DATA["orders"] + if o["order_id"] in s and o["ship_days"] > o["promised_days"]) + + +def unique_customers(order_ids: list) -> list: + return sorted({ORDERS[oid]["customer_id"] for oid in order_ids}) + + +def count_items(values: list) -> int: + return len(values) + + +def sum_values(values: list) -> int: + return sum(values) + + +def count_true(values: list) -> int: + return sum(1 for v in values if bool(v)) + + +def count_below(values: list, threshold: int) -> int: + return sum(1 for v in values if v < threshold) + + +TOOLS = { + "region_currency": ("region_currency(region: str) -> str", + "ISO currency code for a region.", region_currency), + "get_orders": ("get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]", + "Paid/refunded order ids for a region, product category, and inclusive month window.", + get_orders), + "order_gross_usd": ("order_gross_usd(order_id: int) -> int", + "Gross order revenue in USD before discounts/refunds.", order_gross_usd), + "order_margin_usd": ("order_margin_usd(order_id: int) -> int", + "Gross order margin in USD before discounts/refunds.", order_margin_usd), + "refund_usd": ("refund_usd(order_id: int) -> int", + "Refund amount in USD for returned quantity on an order.", refund_usd), + "customer_tier": ("customer_tier(order_id: int) -> str", + "Customer loyalty tier for an order.", customer_tier), + "apply_discount": ("apply_discount(amount_usd: int, tier: str) -> int", + "Apply the order customer's loyalty discount to a USD amount.", apply_discount), + "net_revenue_usd": ("net_revenue_usd(order_id: int) -> int", + "Net USD revenue after loyalty discount and refunds.", net_revenue_usd), + "to_local": ("to_local(amount_usd: int, currency: str) -> int", + "Convert a USD integer amount to a local-currency integer.", to_local), + "inventory_position": ("inventory_position(product_id: int, region: str) -> int", + "Available inventory position: on_hand - reserved + inbound.", + inventory_position), + "product_lead_time": ("product_lead_time(product_id: int) -> int", + "Supplier lead time in days for a product.", product_lead_time), + "product_id_for_top_seller": ( + "product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int", + "Product id with the highest units sold in a region/category/month window.", + product_id_for_top_seller), + "units_sold": ("units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int", + "Units sold for one product in a region and month window.", units_sold), + "tickets_for_orders": ("tickets_for_orders(order_ids: list[int], severity: str) -> list[int]", + "Support ticket ids for given orders and severity.", tickets_for_orders), + "ticket_order_id": ("ticket_order_id(ticket_id: int) -> int", + "Order id associated with a support ticket.", ticket_order_id), + "sla_breached": ( + "sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool", + "Whether a support ticket breaches first-response or resolution SLA.", + sla_breached), + "delayed_orders": ("delayed_orders(order_ids: list[int]) -> list[int]", + "Subset of order ids whose ship_days exceeded promised_days.", delayed_orders), + "unique_customers": ("unique_customers(order_ids: list[int]) -> list[int]", + "Unique customer ids among the given orders.", unique_customers), + "count_items": ("count_items(values: list) -> int", "Length of a list.", count_items), + "sum_values": ("sum_values(values: list[int]) -> int", "Sum a list of integers.", sum_values), + "count_true": ("count_true(values: list[bool]) -> int", "Count true values.", count_true), + "count_below": ("count_below(values: list[int], threshold: int) -> int", + "Count values below a threshold.", count_below), +} + +__all__ = [name for name in TOOLS.keys()] + ['TOOLS'] diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t7/environment/task.json b/harbor/tasks/v3_depth6_delay_sla_burden_t7/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..bc96bde05f3150d366e32f944c09f21ea375f778 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t7/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth6_delay_sla_burden_t7", + "depth": 6, + "family": "delay_sla_burden", + "params": { + "region": "LATAM", + "category": "C", + "month_start": 202603, + "month_end": 202606 + }, + "question": "For region LATAM, category C, months 202603-202606: get the orders, count delayed orders where ship_days exceeded promised_days, find high and critical support tickets for those orders, count tickets that breach a 24-hour first-response or 120-hour resolution SLA, and report delayed_order_count + breached_ticket_count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t7/instruction.md b/harbor/tasks/v3_depth6_delay_sla_burden_t7/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..f7d53ff7f362a40e18b7238782e80faa94857ecc --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t7/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For region LATAM, category C, months 202603-202606: get the orders, count delayed orders where ship_days exceeded promised_days, find high and critical support tickets for those orders, count tickets that breach a 24-hour first-response or 120-hour resolution SLA, and report delayed_order_count + breached_ticket_count. + +Available tools: +- `region_currency(region: str) -> str`: ISO currency code for a region. +- `get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]`: Paid/refunded order ids for a region, product category, and inclusive month window. +- `order_gross_usd(order_id: int) -> int`: Gross order revenue in USD before discounts/refunds. +- `order_margin_usd(order_id: int) -> int`: Gross order margin in USD before discounts/refunds. +- `refund_usd(order_id: int) -> int`: Refund amount in USD for returned quantity on an order. +- `customer_tier(order_id: int) -> str`: Customer loyalty tier for an order. +- `apply_discount(amount_usd: int, tier: str) -> int`: Apply the order customer's loyalty discount to a USD amount. +- `net_revenue_usd(order_id: int) -> int`: Net USD revenue after loyalty discount and refunds. +- `to_local(amount_usd: int, currency: str) -> int`: Convert a USD integer amount to a local-currency integer. +- `inventory_position(product_id: int, region: str) -> int`: Available inventory position: on_hand - reserved + inbound. +- `product_lead_time(product_id: int) -> int`: Supplier lead time in days for a product. +- `product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int`: Product id with the highest units sold in a region/category/month window. +- `units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int`: Units sold for one product in a region and month window. +- `tickets_for_orders(order_ids: list[int], severity: str) -> list[int]`: Support ticket ids for given orders and severity. +- `ticket_order_id(ticket_id: int) -> int`: Order id associated with a support ticket. +- `sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool`: Whether a support ticket breaches first-response or resolution SLA. +- `delayed_orders(order_ids: list[int]) -> list[int]`: Subset of order ids whose ship_days exceeded promised_days. +- `unique_customers(order_ids: list[int]) -> list[int]`: Unique customer ids among the given orders. +- `count_items(values: list) -> int`: Length of a list. +- `sum_values(values: list[int]) -> int`: Sum a list of integers. +- `count_true(values: list[bool]) -> int`: Count true values. +- `count_below(values: list[int], threshold: int) -> int`: Count values below a threshold. diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t7/task.toml b/harbor/tasks/v3_depth6_delay_sla_burden_t7/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..c308d438ff2f36b898bcb3aef16a872df2ad8e34 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t7/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth6_delay_sla_burden_t7" +description = "FlowBench v3 public task metadata. Public verifier is smoke-only." +authors = [{ name = "Mind Lab", email = "contact@mindlab.ltd" }] +keywords = ["flowbench", "tool-use", "data-orchestration", "operations"] + +[metadata] +benchmark = "FlowBench-v3" +split = "public-task-only" +category = "data-processing" +depth = 6 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +network_mode = "no-network" +build_timeout_sec = 600.0 +os = "linux" +cpus = 1 +memory_mb = 2048 +storage_mb = 2048 +gpus = 0 diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t7/tests/check_output_shape.py b/harbor/tasks/v3_depth6_delay_sla_burden_t7/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t7/tests/check_output_shape.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import json +import os +import re +from pathlib import Path + + +def write_reward(score: float, diagnostic: str) -> None: + log_dir = Path(os.environ.get("LOG_DIR", "/logs/verifier")) + log_dir.mkdir(parents=True, exist_ok=True) + (log_dir / "reward.txt").write_text(f"{score:.6g}\n") + (log_dir / "reward.json").write_text( + json.dumps({"reward": score, "smoke_only": True}, indent=2) + "\n" + ) + (log_dir / "diagnostic.txt").write_text(diagnostic + "\n") + + +def main() -> int: + app_dir = Path(os.environ.get("APP_DIR", "/app")) + task = json.loads((app_dir / "task.json").read_text()) + answer_path = app_dir / "answer.txt" + if not answer_path.exists(): + write_reward(0.0, "missing /app/answer.txt") + return 1 + + got = answer_path.read_text().strip() + if task["answer_format"] == "exact integer": + ok = bool(re.fullmatch(r"-?\d+", got)) + diagnostic = "valid integer smoke output" if ok else f"not an exact integer: {got!r}" + else: + ok = bool(re.fullmatch(r"[A-Za-z]+", got)) + diagnostic = "valid code smoke output" if ok else f"not an exact code: {got!r}" + + # This is intentionally not official scoring; it only verifies I/O shape. + write_reward(1.0 if ok else 0.0, diagnostic) + return 0 if ok else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t7/tests/test.sh b/harbor/tasks/v3_depth6_delay_sla_burden_t7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t7/tests/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -u +python /tests/check_output_shape.py diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t8/environment/Dockerfile b/harbor/tasks/v3_depth6_delay_sla_burden_t8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t8/environment/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.12-slim +WORKDIR /app +COPY flowbench_tools.py /app/flowbench_tools.py +COPY task.json /app/task.json diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t8/environment/flowbench_tools.py b/harbor/tasks/v3_depth6_delay_sla_burden_t8/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t8/environment/flowbench_tools.py @@ -0,0 +1,311 @@ +"""Deterministic FlowBench v3 tools. This file contains no task answers.""" + + +REGIONS = ["NA", "EU", "APAC", "LATAM"] +CATEGORIES = ["A", "B", "C", "D"] +CURRENCIES = {"NA": "USD", "EU": "EUR", "APAC": "JPY", "LATAM": "BRL"} +FX_TO_USD_BP = {"USD": 10000, "EUR": 10900, "JPY": 67, "BRL": 1850} +TIERS = ["std", "gold", "plat"] +DISCOUNT_PCT = {"std": 0, "gold": 10, "plat": 20} +CHANNELS = ["web", "store", "partner"] +MONTHS = [202601, 202602, 202603, 202604, 202605, 202606] + +N_CUSTOMERS = 72 +N_PRODUCTS = 48 +N_ORDERS = 720 +N_TICKETS = 260 +N_RETURNS = 180 + + +def _h(*xs): + import hashlib + s = "|".join(str(x) for x in xs).encode() + return int.from_bytes(hashlib.sha256(s).digest()[:8], "big") & 0x7FFFFFFF + + +def build_data(): + customers = [] + for cid in range(N_CUSTOMERS): + region = REGIONS[_h("region", cid) % len(REGIONS)] + customers.append({ + "customer_id": cid, + "region": region, + "tier": TIERS[_h("tier", cid) % len(TIERS)], + "segment": ["consumer", "smb", "enterprise"][_h("segment", cid) % 3], + }) + + products = [] + for pid in range(N_PRODUCTS): + cat = CATEGORIES[_h("cat", pid) % len(CATEGORIES)] + unit_price = 12 + _h("price", pid) % 240 + cogs = unit_price * (45 + _h("margin", pid) % 35) // 100 + products.append({ + "product_id": pid, + "category": cat, + "unit_price_usd": unit_price, + "unit_cogs_usd": cogs, + "lead_time_days": 3 + _h("lead", pid) % 18, + }) + + inventory = [] + for pid in range(N_PRODUCTS): + for region in REGIONS: + inventory.append({ + "product_id": pid, + "region": region, + "on_hand": 10 + _h("onhand", pid, region) % 140, + "reserved": _h("reserved", pid, region) % 28, + "inbound": _h("inbound", pid, region) % 85, + }) + + orders = [] + for oid in range(N_ORDERS): + customer_id = _h("ocust", oid) % N_CUSTOMERS + product_id = _h("oprod", oid) % N_PRODUCTS + month = MONTHS[_h("month", oid) % len(MONTHS)] + qty = 1 + _h("qty", oid) % 9 + ship_days = 1 + _h("shipdays", oid) % 16 + promised_days = 3 + _h("promise", oid) % 9 + status = ["paid", "paid", "paid", "paid", "cancelled", "refunded"][ + _h("status", oid) % 6] + orders.append({ + "order_id": oid, + "customer_id": customer_id, + "product_id": product_id, + "month": month, + "qty": qty, + "status": status, + "channel": CHANNELS[_h("channel", oid) % len(CHANNELS)], + "ship_days": ship_days, + "promised_days": promised_days, + }) + + returns = [] + for rid in range(N_RETURNS): + oid = _h("roid", rid) % N_ORDERS + order = orders[oid] + if order["status"] == "cancelled": + continue + returned_qty = 1 + _h("rqty", rid) % max(1, order["qty"]) + reason = ["defect", "late", "changed_mind", "wrong_item"][_h("reason", rid) % 4] + returns.append({ + "return_id": rid, + "order_id": oid, + "month": MONTHS[_h("rmonth", rid) % len(MONTHS)], + "returned_qty": returned_qty, + "reason": reason, + }) + + tickets = [] + for tid in range(N_TICKETS): + oid = _h("toid", tid) % N_ORDERS + severity = ["low", "medium", "high", "critical"][_h("sev", tid) % 4] + opened = MONTHS[_h("tmonth", tid) % len(MONTHS)] + first_response_hours = 1 + _h("resp", tid) % 96 + resolution_hours = first_response_hours + _h("res", tid) % 240 + tickets.append({ + "ticket_id": tid, + "order_id": oid, + "opened_month": opened, + "severity": severity, + "first_response_hours": first_response_hours, + "resolution_hours": resolution_hours, + }) + + return { + "customers": customers, + "products": products, + "inventory": inventory, + "orders": orders, + "returns": returns, + "tickets": tickets, + "fx_to_usd_bp": FX_TO_USD_BP, + } + + +DATA = build_data() +CUSTOMERS = {c["customer_id"]: c for c in DATA["customers"]} +PRODUCTS = {p["product_id"]: p for p in DATA["products"]} +ORDERS = {o["order_id"]: o for o in DATA["orders"]} + + +def region_currency(region: str) -> str: + return CURRENCIES[region] + + +def get_orders(region: str, category: str, month_start: int, month_end: int) -> list: + """Paid/refunded order ids in a region/category/month window.""" + out = [] + for o in DATA["orders"]: + if o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + p = PRODUCTS[o["product_id"]] + if c["region"] == region and p["category"] == category and month_start <= o["month"] <= month_end: + out.append(o["order_id"]) + return sorted(out) + + +def order_gross_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * p["unit_price_usd"] + + +def order_margin_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * (p["unit_price_usd"] - p["unit_cogs_usd"]) + + +def refund_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + qty = sum(r["returned_qty"] for r in DATA["returns"] if r["order_id"] == order_id) + qty = min(qty, o["qty"]) + return qty * p["unit_price_usd"] + + +def customer_tier(order_id: int) -> str: + o = ORDERS[order_id] + return CUSTOMERS[o["customer_id"]]["tier"] + + +def apply_discount(amount_usd: int, tier: str) -> int: + return amount_usd * (100 - DISCOUNT_PCT[tier]) // 100 + + +def net_revenue_usd(order_id: int) -> int: + gross = apply_discount(order_gross_usd(order_id), customer_tier(order_id)) + return max(0, gross - refund_usd(order_id)) + + +def to_local(amount_usd: int, currency: str) -> int: + return amount_usd * 10000 // FX_TO_USD_BP[currency] + + +def inventory_position(product_id: int, region: str) -> int: + row = next(x for x in DATA["inventory"] + if x["product_id"] == product_id and x["region"] == region) + return row["on_hand"] - row["reserved"] + row["inbound"] + + +def product_lead_time(product_id: int) -> int: + return PRODUCTS[product_id]["lead_time_days"] + + +def product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int: + totals = {} + for oid in get_orders(region, category, month_start, month_end): + o = ORDERS[oid] + totals[o["product_id"]] = totals.get(o["product_id"], 0) + o["qty"] + if not totals: + return -1 + return min((-qty, pid) for pid, qty in totals.items())[1] + + +def units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int: + total = 0 + for o in DATA["orders"]: + if o["product_id"] != product_id or o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + if c["region"] == region and month_start <= o["month"] <= month_end: + total += o["qty"] + return total + + +def tickets_for_orders(order_ids: list, severity: str) -> list: + s = set(order_ids) + return sorted(t["ticket_id"] for t in DATA["tickets"] + if t["order_id"] in s and t["severity"] == severity) + + +def ticket_order_id(ticket_id: int) -> int: + return next(t["order_id"] for t in DATA["tickets"] if t["ticket_id"] == ticket_id) + + +def sla_breached(ticket_id: int, first_response_limit_hours: int, + resolution_limit_hours: int) -> bool: + t = next(x for x in DATA["tickets"] if x["ticket_id"] == ticket_id) + return (t["first_response_hours"] > first_response_limit_hours or + t["resolution_hours"] > resolution_limit_hours) + + +def delayed_orders(order_ids: list) -> list: + s = set(order_ids) + return sorted(o["order_id"] for o in DATA["orders"] + if o["order_id"] in s and o["ship_days"] > o["promised_days"]) + + +def unique_customers(order_ids: list) -> list: + return sorted({ORDERS[oid]["customer_id"] for oid in order_ids}) + + +def count_items(values: list) -> int: + return len(values) + + +def sum_values(values: list) -> int: + return sum(values) + + +def count_true(values: list) -> int: + return sum(1 for v in values if bool(v)) + + +def count_below(values: list, threshold: int) -> int: + return sum(1 for v in values if v < threshold) + + +TOOLS = { + "region_currency": ("region_currency(region: str) -> str", + "ISO currency code for a region.", region_currency), + "get_orders": ("get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]", + "Paid/refunded order ids for a region, product category, and inclusive month window.", + get_orders), + "order_gross_usd": ("order_gross_usd(order_id: int) -> int", + "Gross order revenue in USD before discounts/refunds.", order_gross_usd), + "order_margin_usd": ("order_margin_usd(order_id: int) -> int", + "Gross order margin in USD before discounts/refunds.", order_margin_usd), + "refund_usd": ("refund_usd(order_id: int) -> int", + "Refund amount in USD for returned quantity on an order.", refund_usd), + "customer_tier": ("customer_tier(order_id: int) -> str", + "Customer loyalty tier for an order.", customer_tier), + "apply_discount": ("apply_discount(amount_usd: int, tier: str) -> int", + "Apply the order customer's loyalty discount to a USD amount.", apply_discount), + "net_revenue_usd": ("net_revenue_usd(order_id: int) -> int", + "Net USD revenue after loyalty discount and refunds.", net_revenue_usd), + "to_local": ("to_local(amount_usd: int, currency: str) -> int", + "Convert a USD integer amount to a local-currency integer.", to_local), + "inventory_position": ("inventory_position(product_id: int, region: str) -> int", + "Available inventory position: on_hand - reserved + inbound.", + inventory_position), + "product_lead_time": ("product_lead_time(product_id: int) -> int", + "Supplier lead time in days for a product.", product_lead_time), + "product_id_for_top_seller": ( + "product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int", + "Product id with the highest units sold in a region/category/month window.", + product_id_for_top_seller), + "units_sold": ("units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int", + "Units sold for one product in a region and month window.", units_sold), + "tickets_for_orders": ("tickets_for_orders(order_ids: list[int], severity: str) -> list[int]", + "Support ticket ids for given orders and severity.", tickets_for_orders), + "ticket_order_id": ("ticket_order_id(ticket_id: int) -> int", + "Order id associated with a support ticket.", ticket_order_id), + "sla_breached": ( + "sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool", + "Whether a support ticket breaches first-response or resolution SLA.", + sla_breached), + "delayed_orders": ("delayed_orders(order_ids: list[int]) -> list[int]", + "Subset of order ids whose ship_days exceeded promised_days.", delayed_orders), + "unique_customers": ("unique_customers(order_ids: list[int]) -> list[int]", + "Unique customer ids among the given orders.", unique_customers), + "count_items": ("count_items(values: list) -> int", "Length of a list.", count_items), + "sum_values": ("sum_values(values: list[int]) -> int", "Sum a list of integers.", sum_values), + "count_true": ("count_true(values: list[bool]) -> int", "Count true values.", count_true), + "count_below": ("count_below(values: list[int], threshold: int) -> int", + "Count values below a threshold.", count_below), +} + +__all__ = [name for name in TOOLS.keys()] + ['TOOLS'] diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t8/environment/task.json b/harbor/tasks/v3_depth6_delay_sla_burden_t8/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..2aaf5743a68b52156b6bd80941c8426fb1fd14ee --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t8/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth6_delay_sla_burden_t8", + "depth": 6, + "family": "delay_sla_burden", + "params": { + "region": "NA", + "category": "D", + "month_start": 202602, + "month_end": 202606 + }, + "question": "For region NA, category D, months 202602-202606: get the orders, count delayed orders where ship_days exceeded promised_days, find high and critical support tickets for those orders, count tickets that breach a 24-hour first-response or 120-hour resolution SLA, and report delayed_order_count + breached_ticket_count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t8/instruction.md b/harbor/tasks/v3_depth6_delay_sla_burden_t8/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..e507507bc32f040d2199f7c2e7d1b4a38bb3ed3b --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t8/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For region NA, category D, months 202602-202606: get the orders, count delayed orders where ship_days exceeded promised_days, find high and critical support tickets for those orders, count tickets that breach a 24-hour first-response or 120-hour resolution SLA, and report delayed_order_count + breached_ticket_count. + +Available tools: +- `region_currency(region: str) -> str`: ISO currency code for a region. +- `get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]`: Paid/refunded order ids for a region, product category, and inclusive month window. +- `order_gross_usd(order_id: int) -> int`: Gross order revenue in USD before discounts/refunds. +- `order_margin_usd(order_id: int) -> int`: Gross order margin in USD before discounts/refunds. +- `refund_usd(order_id: int) -> int`: Refund amount in USD for returned quantity on an order. +- `customer_tier(order_id: int) -> str`: Customer loyalty tier for an order. +- `apply_discount(amount_usd: int, tier: str) -> int`: Apply the order customer's loyalty discount to a USD amount. +- `net_revenue_usd(order_id: int) -> int`: Net USD revenue after loyalty discount and refunds. +- `to_local(amount_usd: int, currency: str) -> int`: Convert a USD integer amount to a local-currency integer. +- `inventory_position(product_id: int, region: str) -> int`: Available inventory position: on_hand - reserved + inbound. +- `product_lead_time(product_id: int) -> int`: Supplier lead time in days for a product. +- `product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int`: Product id with the highest units sold in a region/category/month window. +- `units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int`: Units sold for one product in a region and month window. +- `tickets_for_orders(order_ids: list[int], severity: str) -> list[int]`: Support ticket ids for given orders and severity. +- `ticket_order_id(ticket_id: int) -> int`: Order id associated with a support ticket. +- `sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool`: Whether a support ticket breaches first-response or resolution SLA. +- `delayed_orders(order_ids: list[int]) -> list[int]`: Subset of order ids whose ship_days exceeded promised_days. +- `unique_customers(order_ids: list[int]) -> list[int]`: Unique customer ids among the given orders. +- `count_items(values: list) -> int`: Length of a list. +- `sum_values(values: list[int]) -> int`: Sum a list of integers. +- `count_true(values: list[bool]) -> int`: Count true values. +- `count_below(values: list[int], threshold: int) -> int`: Count values below a threshold. diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t8/task.toml b/harbor/tasks/v3_depth6_delay_sla_burden_t8/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..da091590ba6803afae94bf0f0bf5f54236bcdc27 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t8/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth6_delay_sla_burden_t8" +description = "FlowBench v3 public task metadata. Public verifier is smoke-only." +authors = [{ name = "Mind Lab", email = "contact@mindlab.ltd" }] +keywords = ["flowbench", "tool-use", "data-orchestration", "operations"] + +[metadata] +benchmark = "FlowBench-v3" +split = "public-task-only" +category = "data-processing" +depth = 6 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +network_mode = "no-network" +build_timeout_sec = 600.0 +os = "linux" +cpus = 1 +memory_mb = 2048 +storage_mb = 2048 +gpus = 0 diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t8/tests/check_output_shape.py b/harbor/tasks/v3_depth6_delay_sla_burden_t8/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t8/tests/check_output_shape.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import json +import os +import re +from pathlib import Path + + +def write_reward(score: float, diagnostic: str) -> None: + log_dir = Path(os.environ.get("LOG_DIR", "/logs/verifier")) + log_dir.mkdir(parents=True, exist_ok=True) + (log_dir / "reward.txt").write_text(f"{score:.6g}\n") + (log_dir / "reward.json").write_text( + json.dumps({"reward": score, "smoke_only": True}, indent=2) + "\n" + ) + (log_dir / "diagnostic.txt").write_text(diagnostic + "\n") + + +def main() -> int: + app_dir = Path(os.environ.get("APP_DIR", "/app")) + task = json.loads((app_dir / "task.json").read_text()) + answer_path = app_dir / "answer.txt" + if not answer_path.exists(): + write_reward(0.0, "missing /app/answer.txt") + return 1 + + got = answer_path.read_text().strip() + if task["answer_format"] == "exact integer": + ok = bool(re.fullmatch(r"-?\d+", got)) + diagnostic = "valid integer smoke output" if ok else f"not an exact integer: {got!r}" + else: + ok = bool(re.fullmatch(r"[A-Za-z]+", got)) + diagnostic = "valid code smoke output" if ok else f"not an exact code: {got!r}" + + # This is intentionally not official scoring; it only verifies I/O shape. + write_reward(1.0 if ok else 0.0, diagnostic) + return 0 if ok else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t8/tests/test.sh b/harbor/tasks/v3_depth6_delay_sla_burden_t8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t8/tests/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -u +python /tests/check_output_shape.py diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t9/environment/Dockerfile b/harbor/tasks/v3_depth6_delay_sla_burden_t9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t9/environment/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.12-slim +WORKDIR /app +COPY flowbench_tools.py /app/flowbench_tools.py +COPY task.json /app/task.json diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t9/environment/flowbench_tools.py b/harbor/tasks/v3_depth6_delay_sla_burden_t9/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t9/environment/flowbench_tools.py @@ -0,0 +1,311 @@ +"""Deterministic FlowBench v3 tools. This file contains no task answers.""" + + +REGIONS = ["NA", "EU", "APAC", "LATAM"] +CATEGORIES = ["A", "B", "C", "D"] +CURRENCIES = {"NA": "USD", "EU": "EUR", "APAC": "JPY", "LATAM": "BRL"} +FX_TO_USD_BP = {"USD": 10000, "EUR": 10900, "JPY": 67, "BRL": 1850} +TIERS = ["std", "gold", "plat"] +DISCOUNT_PCT = {"std": 0, "gold": 10, "plat": 20} +CHANNELS = ["web", "store", "partner"] +MONTHS = [202601, 202602, 202603, 202604, 202605, 202606] + +N_CUSTOMERS = 72 +N_PRODUCTS = 48 +N_ORDERS = 720 +N_TICKETS = 260 +N_RETURNS = 180 + + +def _h(*xs): + import hashlib + s = "|".join(str(x) for x in xs).encode() + return int.from_bytes(hashlib.sha256(s).digest()[:8], "big") & 0x7FFFFFFF + + +def build_data(): + customers = [] + for cid in range(N_CUSTOMERS): + region = REGIONS[_h("region", cid) % len(REGIONS)] + customers.append({ + "customer_id": cid, + "region": region, + "tier": TIERS[_h("tier", cid) % len(TIERS)], + "segment": ["consumer", "smb", "enterprise"][_h("segment", cid) % 3], + }) + + products = [] + for pid in range(N_PRODUCTS): + cat = CATEGORIES[_h("cat", pid) % len(CATEGORIES)] + unit_price = 12 + _h("price", pid) % 240 + cogs = unit_price * (45 + _h("margin", pid) % 35) // 100 + products.append({ + "product_id": pid, + "category": cat, + "unit_price_usd": unit_price, + "unit_cogs_usd": cogs, + "lead_time_days": 3 + _h("lead", pid) % 18, + }) + + inventory = [] + for pid in range(N_PRODUCTS): + for region in REGIONS: + inventory.append({ + "product_id": pid, + "region": region, + "on_hand": 10 + _h("onhand", pid, region) % 140, + "reserved": _h("reserved", pid, region) % 28, + "inbound": _h("inbound", pid, region) % 85, + }) + + orders = [] + for oid in range(N_ORDERS): + customer_id = _h("ocust", oid) % N_CUSTOMERS + product_id = _h("oprod", oid) % N_PRODUCTS + month = MONTHS[_h("month", oid) % len(MONTHS)] + qty = 1 + _h("qty", oid) % 9 + ship_days = 1 + _h("shipdays", oid) % 16 + promised_days = 3 + _h("promise", oid) % 9 + status = ["paid", "paid", "paid", "paid", "cancelled", "refunded"][ + _h("status", oid) % 6] + orders.append({ + "order_id": oid, + "customer_id": customer_id, + "product_id": product_id, + "month": month, + "qty": qty, + "status": status, + "channel": CHANNELS[_h("channel", oid) % len(CHANNELS)], + "ship_days": ship_days, + "promised_days": promised_days, + }) + + returns = [] + for rid in range(N_RETURNS): + oid = _h("roid", rid) % N_ORDERS + order = orders[oid] + if order["status"] == "cancelled": + continue + returned_qty = 1 + _h("rqty", rid) % max(1, order["qty"]) + reason = ["defect", "late", "changed_mind", "wrong_item"][_h("reason", rid) % 4] + returns.append({ + "return_id": rid, + "order_id": oid, + "month": MONTHS[_h("rmonth", rid) % len(MONTHS)], + "returned_qty": returned_qty, + "reason": reason, + }) + + tickets = [] + for tid in range(N_TICKETS): + oid = _h("toid", tid) % N_ORDERS + severity = ["low", "medium", "high", "critical"][_h("sev", tid) % 4] + opened = MONTHS[_h("tmonth", tid) % len(MONTHS)] + first_response_hours = 1 + _h("resp", tid) % 96 + resolution_hours = first_response_hours + _h("res", tid) % 240 + tickets.append({ + "ticket_id": tid, + "order_id": oid, + "opened_month": opened, + "severity": severity, + "first_response_hours": first_response_hours, + "resolution_hours": resolution_hours, + }) + + return { + "customers": customers, + "products": products, + "inventory": inventory, + "orders": orders, + "returns": returns, + "tickets": tickets, + "fx_to_usd_bp": FX_TO_USD_BP, + } + + +DATA = build_data() +CUSTOMERS = {c["customer_id"]: c for c in DATA["customers"]} +PRODUCTS = {p["product_id"]: p for p in DATA["products"]} +ORDERS = {o["order_id"]: o for o in DATA["orders"]} + + +def region_currency(region: str) -> str: + return CURRENCIES[region] + + +def get_orders(region: str, category: str, month_start: int, month_end: int) -> list: + """Paid/refunded order ids in a region/category/month window.""" + out = [] + for o in DATA["orders"]: + if o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + p = PRODUCTS[o["product_id"]] + if c["region"] == region and p["category"] == category and month_start <= o["month"] <= month_end: + out.append(o["order_id"]) + return sorted(out) + + +def order_gross_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * p["unit_price_usd"] + + +def order_margin_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * (p["unit_price_usd"] - p["unit_cogs_usd"]) + + +def refund_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + qty = sum(r["returned_qty"] for r in DATA["returns"] if r["order_id"] == order_id) + qty = min(qty, o["qty"]) + return qty * p["unit_price_usd"] + + +def customer_tier(order_id: int) -> str: + o = ORDERS[order_id] + return CUSTOMERS[o["customer_id"]]["tier"] + + +def apply_discount(amount_usd: int, tier: str) -> int: + return amount_usd * (100 - DISCOUNT_PCT[tier]) // 100 + + +def net_revenue_usd(order_id: int) -> int: + gross = apply_discount(order_gross_usd(order_id), customer_tier(order_id)) + return max(0, gross - refund_usd(order_id)) + + +def to_local(amount_usd: int, currency: str) -> int: + return amount_usd * 10000 // FX_TO_USD_BP[currency] + + +def inventory_position(product_id: int, region: str) -> int: + row = next(x for x in DATA["inventory"] + if x["product_id"] == product_id and x["region"] == region) + return row["on_hand"] - row["reserved"] + row["inbound"] + + +def product_lead_time(product_id: int) -> int: + return PRODUCTS[product_id]["lead_time_days"] + + +def product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int: + totals = {} + for oid in get_orders(region, category, month_start, month_end): + o = ORDERS[oid] + totals[o["product_id"]] = totals.get(o["product_id"], 0) + o["qty"] + if not totals: + return -1 + return min((-qty, pid) for pid, qty in totals.items())[1] + + +def units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int: + total = 0 + for o in DATA["orders"]: + if o["product_id"] != product_id or o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + if c["region"] == region and month_start <= o["month"] <= month_end: + total += o["qty"] + return total + + +def tickets_for_orders(order_ids: list, severity: str) -> list: + s = set(order_ids) + return sorted(t["ticket_id"] for t in DATA["tickets"] + if t["order_id"] in s and t["severity"] == severity) + + +def ticket_order_id(ticket_id: int) -> int: + return next(t["order_id"] for t in DATA["tickets"] if t["ticket_id"] == ticket_id) + + +def sla_breached(ticket_id: int, first_response_limit_hours: int, + resolution_limit_hours: int) -> bool: + t = next(x for x in DATA["tickets"] if x["ticket_id"] == ticket_id) + return (t["first_response_hours"] > first_response_limit_hours or + t["resolution_hours"] > resolution_limit_hours) + + +def delayed_orders(order_ids: list) -> list: + s = set(order_ids) + return sorted(o["order_id"] for o in DATA["orders"] + if o["order_id"] in s and o["ship_days"] > o["promised_days"]) + + +def unique_customers(order_ids: list) -> list: + return sorted({ORDERS[oid]["customer_id"] for oid in order_ids}) + + +def count_items(values: list) -> int: + return len(values) + + +def sum_values(values: list) -> int: + return sum(values) + + +def count_true(values: list) -> int: + return sum(1 for v in values if bool(v)) + + +def count_below(values: list, threshold: int) -> int: + return sum(1 for v in values if v < threshold) + + +TOOLS = { + "region_currency": ("region_currency(region: str) -> str", + "ISO currency code for a region.", region_currency), + "get_orders": ("get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]", + "Paid/refunded order ids for a region, product category, and inclusive month window.", + get_orders), + "order_gross_usd": ("order_gross_usd(order_id: int) -> int", + "Gross order revenue in USD before discounts/refunds.", order_gross_usd), + "order_margin_usd": ("order_margin_usd(order_id: int) -> int", + "Gross order margin in USD before discounts/refunds.", order_margin_usd), + "refund_usd": ("refund_usd(order_id: int) -> int", + "Refund amount in USD for returned quantity on an order.", refund_usd), + "customer_tier": ("customer_tier(order_id: int) -> str", + "Customer loyalty tier for an order.", customer_tier), + "apply_discount": ("apply_discount(amount_usd: int, tier: str) -> int", + "Apply the order customer's loyalty discount to a USD amount.", apply_discount), + "net_revenue_usd": ("net_revenue_usd(order_id: int) -> int", + "Net USD revenue after loyalty discount and refunds.", net_revenue_usd), + "to_local": ("to_local(amount_usd: int, currency: str) -> int", + "Convert a USD integer amount to a local-currency integer.", to_local), + "inventory_position": ("inventory_position(product_id: int, region: str) -> int", + "Available inventory position: on_hand - reserved + inbound.", + inventory_position), + "product_lead_time": ("product_lead_time(product_id: int) -> int", + "Supplier lead time in days for a product.", product_lead_time), + "product_id_for_top_seller": ( + "product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int", + "Product id with the highest units sold in a region/category/month window.", + product_id_for_top_seller), + "units_sold": ("units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int", + "Units sold for one product in a region and month window.", units_sold), + "tickets_for_orders": ("tickets_for_orders(order_ids: list[int], severity: str) -> list[int]", + "Support ticket ids for given orders and severity.", tickets_for_orders), + "ticket_order_id": ("ticket_order_id(ticket_id: int) -> int", + "Order id associated with a support ticket.", ticket_order_id), + "sla_breached": ( + "sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool", + "Whether a support ticket breaches first-response or resolution SLA.", + sla_breached), + "delayed_orders": ("delayed_orders(order_ids: list[int]) -> list[int]", + "Subset of order ids whose ship_days exceeded promised_days.", delayed_orders), + "unique_customers": ("unique_customers(order_ids: list[int]) -> list[int]", + "Unique customer ids among the given orders.", unique_customers), + "count_items": ("count_items(values: list) -> int", "Length of a list.", count_items), + "sum_values": ("sum_values(values: list[int]) -> int", "Sum a list of integers.", sum_values), + "count_true": ("count_true(values: list[bool]) -> int", "Count true values.", count_true), + "count_below": ("count_below(values: list[int], threshold: int) -> int", + "Count values below a threshold.", count_below), +} + +__all__ = [name for name in TOOLS.keys()] + ['TOOLS'] diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t9/environment/task.json b/harbor/tasks/v3_depth6_delay_sla_burden_t9/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..b5ab9185632a62d7b571c178c1ac800e63296f2e --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t9/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth6_delay_sla_burden_t9", + "depth": 6, + "family": "delay_sla_burden", + "params": { + "region": "EU", + "category": "A", + "month_start": 202602, + "month_end": 202605 + }, + "question": "For region EU, category A, months 202602-202605: get the orders, count delayed orders where ship_days exceeded promised_days, find high and critical support tickets for those orders, count tickets that breach a 24-hour first-response or 120-hour resolution SLA, and report delayed_order_count + breached_ticket_count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t9/instruction.md b/harbor/tasks/v3_depth6_delay_sla_burden_t9/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..efed97e6a037707a259804d477a7d022f4c687ce --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t9/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For region EU, category A, months 202602-202605: get the orders, count delayed orders where ship_days exceeded promised_days, find high and critical support tickets for those orders, count tickets that breach a 24-hour first-response or 120-hour resolution SLA, and report delayed_order_count + breached_ticket_count. + +Available tools: +- `region_currency(region: str) -> str`: ISO currency code for a region. +- `get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]`: Paid/refunded order ids for a region, product category, and inclusive month window. +- `order_gross_usd(order_id: int) -> int`: Gross order revenue in USD before discounts/refunds. +- `order_margin_usd(order_id: int) -> int`: Gross order margin in USD before discounts/refunds. +- `refund_usd(order_id: int) -> int`: Refund amount in USD for returned quantity on an order. +- `customer_tier(order_id: int) -> str`: Customer loyalty tier for an order. +- `apply_discount(amount_usd: int, tier: str) -> int`: Apply the order customer's loyalty discount to a USD amount. +- `net_revenue_usd(order_id: int) -> int`: Net USD revenue after loyalty discount and refunds. +- `to_local(amount_usd: int, currency: str) -> int`: Convert a USD integer amount to a local-currency integer. +- `inventory_position(product_id: int, region: str) -> int`: Available inventory position: on_hand - reserved + inbound. +- `product_lead_time(product_id: int) -> int`: Supplier lead time in days for a product. +- `product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int`: Product id with the highest units sold in a region/category/month window. +- `units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int`: Units sold for one product in a region and month window. +- `tickets_for_orders(order_ids: list[int], severity: str) -> list[int]`: Support ticket ids for given orders and severity. +- `ticket_order_id(ticket_id: int) -> int`: Order id associated with a support ticket. +- `sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool`: Whether a support ticket breaches first-response or resolution SLA. +- `delayed_orders(order_ids: list[int]) -> list[int]`: Subset of order ids whose ship_days exceeded promised_days. +- `unique_customers(order_ids: list[int]) -> list[int]`: Unique customer ids among the given orders. +- `count_items(values: list) -> int`: Length of a list. +- `sum_values(values: list[int]) -> int`: Sum a list of integers. +- `count_true(values: list[bool]) -> int`: Count true values. +- `count_below(values: list[int], threshold: int) -> int`: Count values below a threshold. diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t9/task.toml b/harbor/tasks/v3_depth6_delay_sla_burden_t9/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..30ccc5afb8e811f6fc7cab57ada35978ed7a9f9a --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t9/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth6_delay_sla_burden_t9" +description = "FlowBench v3 public task metadata. Public verifier is smoke-only." +authors = [{ name = "Mind Lab", email = "contact@mindlab.ltd" }] +keywords = ["flowbench", "tool-use", "data-orchestration", "operations"] + +[metadata] +benchmark = "FlowBench-v3" +split = "public-task-only" +category = "data-processing" +depth = 6 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +network_mode = "no-network" +build_timeout_sec = 600.0 +os = "linux" +cpus = 1 +memory_mb = 2048 +storage_mb = 2048 +gpus = 0 diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t9/tests/check_output_shape.py b/harbor/tasks/v3_depth6_delay_sla_burden_t9/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t9/tests/check_output_shape.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import json +import os +import re +from pathlib import Path + + +def write_reward(score: float, diagnostic: str) -> None: + log_dir = Path(os.environ.get("LOG_DIR", "/logs/verifier")) + log_dir.mkdir(parents=True, exist_ok=True) + (log_dir / "reward.txt").write_text(f"{score:.6g}\n") + (log_dir / "reward.json").write_text( + json.dumps({"reward": score, "smoke_only": True}, indent=2) + "\n" + ) + (log_dir / "diagnostic.txt").write_text(diagnostic + "\n") + + +def main() -> int: + app_dir = Path(os.environ.get("APP_DIR", "/app")) + task = json.loads((app_dir / "task.json").read_text()) + answer_path = app_dir / "answer.txt" + if not answer_path.exists(): + write_reward(0.0, "missing /app/answer.txt") + return 1 + + got = answer_path.read_text().strip() + if task["answer_format"] == "exact integer": + ok = bool(re.fullmatch(r"-?\d+", got)) + diagnostic = "valid integer smoke output" if ok else f"not an exact integer: {got!r}" + else: + ok = bool(re.fullmatch(r"[A-Za-z]+", got)) + diagnostic = "valid code smoke output" if ok else f"not an exact code: {got!r}" + + # This is intentionally not official scoring; it only verifies I/O shape. + write_reward(1.0 if ok else 0.0, diagnostic) + return 0 if ok else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/harbor/tasks/v3_depth6_delay_sla_burden_t9/tests/test.sh b/harbor/tasks/v3_depth6_delay_sla_burden_t9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth6_delay_sla_burden_t9/tests/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -u +python /tests/check_output_shape.py diff --git a/tools/flowbench_tools_v3.py b/tools/flowbench_tools_v3.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/tools/flowbench_tools_v3.py @@ -0,0 +1,311 @@ +"""Deterministic FlowBench v3 tools. This file contains no task answers.""" + + +REGIONS = ["NA", "EU", "APAC", "LATAM"] +CATEGORIES = ["A", "B", "C", "D"] +CURRENCIES = {"NA": "USD", "EU": "EUR", "APAC": "JPY", "LATAM": "BRL"} +FX_TO_USD_BP = {"USD": 10000, "EUR": 10900, "JPY": 67, "BRL": 1850} +TIERS = ["std", "gold", "plat"] +DISCOUNT_PCT = {"std": 0, "gold": 10, "plat": 20} +CHANNELS = ["web", "store", "partner"] +MONTHS = [202601, 202602, 202603, 202604, 202605, 202606] + +N_CUSTOMERS = 72 +N_PRODUCTS = 48 +N_ORDERS = 720 +N_TICKETS = 260 +N_RETURNS = 180 + + +def _h(*xs): + import hashlib + s = "|".join(str(x) for x in xs).encode() + return int.from_bytes(hashlib.sha256(s).digest()[:8], "big") & 0x7FFFFFFF + + +def build_data(): + customers = [] + for cid in range(N_CUSTOMERS): + region = REGIONS[_h("region", cid) % len(REGIONS)] + customers.append({ + "customer_id": cid, + "region": region, + "tier": TIERS[_h("tier", cid) % len(TIERS)], + "segment": ["consumer", "smb", "enterprise"][_h("segment", cid) % 3], + }) + + products = [] + for pid in range(N_PRODUCTS): + cat = CATEGORIES[_h("cat", pid) % len(CATEGORIES)] + unit_price = 12 + _h("price", pid) % 240 + cogs = unit_price * (45 + _h("margin", pid) % 35) // 100 + products.append({ + "product_id": pid, + "category": cat, + "unit_price_usd": unit_price, + "unit_cogs_usd": cogs, + "lead_time_days": 3 + _h("lead", pid) % 18, + }) + + inventory = [] + for pid in range(N_PRODUCTS): + for region in REGIONS: + inventory.append({ + "product_id": pid, + "region": region, + "on_hand": 10 + _h("onhand", pid, region) % 140, + "reserved": _h("reserved", pid, region) % 28, + "inbound": _h("inbound", pid, region) % 85, + }) + + orders = [] + for oid in range(N_ORDERS): + customer_id = _h("ocust", oid) % N_CUSTOMERS + product_id = _h("oprod", oid) % N_PRODUCTS + month = MONTHS[_h("month", oid) % len(MONTHS)] + qty = 1 + _h("qty", oid) % 9 + ship_days = 1 + _h("shipdays", oid) % 16 + promised_days = 3 + _h("promise", oid) % 9 + status = ["paid", "paid", "paid", "paid", "cancelled", "refunded"][ + _h("status", oid) % 6] + orders.append({ + "order_id": oid, + "customer_id": customer_id, + "product_id": product_id, + "month": month, + "qty": qty, + "status": status, + "channel": CHANNELS[_h("channel", oid) % len(CHANNELS)], + "ship_days": ship_days, + "promised_days": promised_days, + }) + + returns = [] + for rid in range(N_RETURNS): + oid = _h("roid", rid) % N_ORDERS + order = orders[oid] + if order["status"] == "cancelled": + continue + returned_qty = 1 + _h("rqty", rid) % max(1, order["qty"]) + reason = ["defect", "late", "changed_mind", "wrong_item"][_h("reason", rid) % 4] + returns.append({ + "return_id": rid, + "order_id": oid, + "month": MONTHS[_h("rmonth", rid) % len(MONTHS)], + "returned_qty": returned_qty, + "reason": reason, + }) + + tickets = [] + for tid in range(N_TICKETS): + oid = _h("toid", tid) % N_ORDERS + severity = ["low", "medium", "high", "critical"][_h("sev", tid) % 4] + opened = MONTHS[_h("tmonth", tid) % len(MONTHS)] + first_response_hours = 1 + _h("resp", tid) % 96 + resolution_hours = first_response_hours + _h("res", tid) % 240 + tickets.append({ + "ticket_id": tid, + "order_id": oid, + "opened_month": opened, + "severity": severity, + "first_response_hours": first_response_hours, + "resolution_hours": resolution_hours, + }) + + return { + "customers": customers, + "products": products, + "inventory": inventory, + "orders": orders, + "returns": returns, + "tickets": tickets, + "fx_to_usd_bp": FX_TO_USD_BP, + } + + +DATA = build_data() +CUSTOMERS = {c["customer_id"]: c for c in DATA["customers"]} +PRODUCTS = {p["product_id"]: p for p in DATA["products"]} +ORDERS = {o["order_id"]: o for o in DATA["orders"]} + + +def region_currency(region: str) -> str: + return CURRENCIES[region] + + +def get_orders(region: str, category: str, month_start: int, month_end: int) -> list: + """Paid/refunded order ids in a region/category/month window.""" + out = [] + for o in DATA["orders"]: + if o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + p = PRODUCTS[o["product_id"]] + if c["region"] == region and p["category"] == category and month_start <= o["month"] <= month_end: + out.append(o["order_id"]) + return sorted(out) + + +def order_gross_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * p["unit_price_usd"] + + +def order_margin_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * (p["unit_price_usd"] - p["unit_cogs_usd"]) + + +def refund_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + qty = sum(r["returned_qty"] for r in DATA["returns"] if r["order_id"] == order_id) + qty = min(qty, o["qty"]) + return qty * p["unit_price_usd"] + + +def customer_tier(order_id: int) -> str: + o = ORDERS[order_id] + return CUSTOMERS[o["customer_id"]]["tier"] + + +def apply_discount(amount_usd: int, tier: str) -> int: + return amount_usd * (100 - DISCOUNT_PCT[tier]) // 100 + + +def net_revenue_usd(order_id: int) -> int: + gross = apply_discount(order_gross_usd(order_id), customer_tier(order_id)) + return max(0, gross - refund_usd(order_id)) + + +def to_local(amount_usd: int, currency: str) -> int: + return amount_usd * 10000 // FX_TO_USD_BP[currency] + + +def inventory_position(product_id: int, region: str) -> int: + row = next(x for x in DATA["inventory"] + if x["product_id"] == product_id and x["region"] == region) + return row["on_hand"] - row["reserved"] + row["inbound"] + + +def product_lead_time(product_id: int) -> int: + return PRODUCTS[product_id]["lead_time_days"] + + +def product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int: + totals = {} + for oid in get_orders(region, category, month_start, month_end): + o = ORDERS[oid] + totals[o["product_id"]] = totals.get(o["product_id"], 0) + o["qty"] + if not totals: + return -1 + return min((-qty, pid) for pid, qty in totals.items())[1] + + +def units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int: + total = 0 + for o in DATA["orders"]: + if o["product_id"] != product_id or o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + if c["region"] == region and month_start <= o["month"] <= month_end: + total += o["qty"] + return total + + +def tickets_for_orders(order_ids: list, severity: str) -> list: + s = set(order_ids) + return sorted(t["ticket_id"] for t in DATA["tickets"] + if t["order_id"] in s and t["severity"] == severity) + + +def ticket_order_id(ticket_id: int) -> int: + return next(t["order_id"] for t in DATA["tickets"] if t["ticket_id"] == ticket_id) + + +def sla_breached(ticket_id: int, first_response_limit_hours: int, + resolution_limit_hours: int) -> bool: + t = next(x for x in DATA["tickets"] if x["ticket_id"] == ticket_id) + return (t["first_response_hours"] > first_response_limit_hours or + t["resolution_hours"] > resolution_limit_hours) + + +def delayed_orders(order_ids: list) -> list: + s = set(order_ids) + return sorted(o["order_id"] for o in DATA["orders"] + if o["order_id"] in s and o["ship_days"] > o["promised_days"]) + + +def unique_customers(order_ids: list) -> list: + return sorted({ORDERS[oid]["customer_id"] for oid in order_ids}) + + +def count_items(values: list) -> int: + return len(values) + + +def sum_values(values: list) -> int: + return sum(values) + + +def count_true(values: list) -> int: + return sum(1 for v in values if bool(v)) + + +def count_below(values: list, threshold: int) -> int: + return sum(1 for v in values if v < threshold) + + +TOOLS = { + "region_currency": ("region_currency(region: str) -> str", + "ISO currency code for a region.", region_currency), + "get_orders": ("get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]", + "Paid/refunded order ids for a region, product category, and inclusive month window.", + get_orders), + "order_gross_usd": ("order_gross_usd(order_id: int) -> int", + "Gross order revenue in USD before discounts/refunds.", order_gross_usd), + "order_margin_usd": ("order_margin_usd(order_id: int) -> int", + "Gross order margin in USD before discounts/refunds.", order_margin_usd), + "refund_usd": ("refund_usd(order_id: int) -> int", + "Refund amount in USD for returned quantity on an order.", refund_usd), + "customer_tier": ("customer_tier(order_id: int) -> str", + "Customer loyalty tier for an order.", customer_tier), + "apply_discount": ("apply_discount(amount_usd: int, tier: str) -> int", + "Apply the order customer's loyalty discount to a USD amount.", apply_discount), + "net_revenue_usd": ("net_revenue_usd(order_id: int) -> int", + "Net USD revenue after loyalty discount and refunds.", net_revenue_usd), + "to_local": ("to_local(amount_usd: int, currency: str) -> int", + "Convert a USD integer amount to a local-currency integer.", to_local), + "inventory_position": ("inventory_position(product_id: int, region: str) -> int", + "Available inventory position: on_hand - reserved + inbound.", + inventory_position), + "product_lead_time": ("product_lead_time(product_id: int) -> int", + "Supplier lead time in days for a product.", product_lead_time), + "product_id_for_top_seller": ( + "product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int", + "Product id with the highest units sold in a region/category/month window.", + product_id_for_top_seller), + "units_sold": ("units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int", + "Units sold for one product in a region and month window.", units_sold), + "tickets_for_orders": ("tickets_for_orders(order_ids: list[int], severity: str) -> list[int]", + "Support ticket ids for given orders and severity.", tickets_for_orders), + "ticket_order_id": ("ticket_order_id(ticket_id: int) -> int", + "Order id associated with a support ticket.", ticket_order_id), + "sla_breached": ( + "sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool", + "Whether a support ticket breaches first-response or resolution SLA.", + sla_breached), + "delayed_orders": ("delayed_orders(order_ids: list[int]) -> list[int]", + "Subset of order ids whose ship_days exceeded promised_days.", delayed_orders), + "unique_customers": ("unique_customers(order_ids: list[int]) -> list[int]", + "Unique customer ids among the given orders.", unique_customers), + "count_items": ("count_items(values: list) -> int", "Length of a list.", count_items), + "sum_values": ("sum_values(values: list[int]) -> int", "Sum a list of integers.", sum_values), + "count_true": ("count_true(values: list[bool]) -> int", "Count true values.", count_true), + "count_below": ("count_below(values: list[int], threshold: int) -> int", + "Count values below a threshold.", count_below), +} + +__all__ = [name for name in TOOLS.keys()] + ['TOOLS']