diff --git a/harbor/tasks/v3_depth2_order_count_t5/task.toml b/harbor/tasks/v3_depth2_order_count_t5/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..e3f7e8af43f8863a64c3a6c5f7ebde8304f46c43 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t5/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_order_count_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 = 2 + +[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_depth2_order_count_t5/tests/check_output_shape.py b/harbor/tasks/v3_depth2_order_count_t5/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_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_depth2_order_count_t5/tests/test.sh b/harbor/tasks/v3_depth2_order_count_t5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_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_depth2_order_count_t6/environment/Dockerfile b/harbor/tasks/v3_depth2_order_count_t6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_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_depth2_order_count_t6/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_order_count_t6/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_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_depth2_order_count_t6/environment/task.json b/harbor/tasks/v3_depth2_order_count_t6/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..5e86385c072517310725aec84883887951e505f7 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t6/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_order_count_t6", + "depth": 2, + "family": "order_count", + "params": { + "region": "LATAM", + "category": "B", + "month_start": 202601, + "month_end": 202604 + }, + "question": "How many paid/refunded orders are in region LATAM, category B, from month 202601 through 202604? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_order_count_t6/instruction.md b/harbor/tasks/v3_depth2_order_count_t6/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..e9ddee7e838d1ae52485ff642ed905ab95d46b94 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_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: +How many paid/refunded orders are in region LATAM, category B, from month 202601 through 202604? Report the 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_depth2_order_count_t6/task.toml b/harbor/tasks/v3_depth2_order_count_t6/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..20d4143934509329c9929ae4aefb4e0905933839 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t6/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_order_count_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 = 2 + +[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_depth2_order_count_t6/tests/check_output_shape.py b/harbor/tasks/v3_depth2_order_count_t6/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_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_depth2_order_count_t6/tests/test.sh b/harbor/tasks/v3_depth2_order_count_t6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_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_depth2_order_count_t7/environment/Dockerfile b/harbor/tasks/v3_depth2_order_count_t7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_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_depth2_order_count_t7/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_order_count_t7/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_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_depth2_order_count_t7/environment/task.json b/harbor/tasks/v3_depth2_order_count_t7/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..38f9eb955c266595d8cc03ea4918014d571ba328 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t7/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_order_count_t7", + "depth": 2, + "family": "order_count", + "params": { + "region": "LATAM", + "category": "C", + "month_start": 202603, + "month_end": 202606 + }, + "question": "How many paid/refunded orders are in region LATAM, category C, from month 202603 through 202606? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_order_count_t7/instruction.md b/harbor/tasks/v3_depth2_order_count_t7/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..fbcbd3726d85ba2f555bb31aaa143e790f357a1d --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_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: +How many paid/refunded orders are in region LATAM, category C, from month 202603 through 202606? Report the 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_depth2_order_count_t7/task.toml b/harbor/tasks/v3_depth2_order_count_t7/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..28616e54dabedf812e2a4ad89d293c9b22995a07 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t7/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_order_count_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 = 2 + +[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_depth2_order_count_t7/tests/check_output_shape.py b/harbor/tasks/v3_depth2_order_count_t7/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_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_depth2_order_count_t7/tests/test.sh b/harbor/tasks/v3_depth2_order_count_t7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_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_depth2_order_count_t8/environment/Dockerfile b/harbor/tasks/v3_depth2_order_count_t8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_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_depth2_order_count_t8/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_order_count_t8/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_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_depth2_order_count_t8/environment/task.json b/harbor/tasks/v3_depth2_order_count_t8/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..aa99b96bd4b14a73c2af0c01973d4807de58b78a --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t8/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_order_count_t8", + "depth": 2, + "family": "order_count", + "params": { + "region": "NA", + "category": "D", + "month_start": 202602, + "month_end": 202606 + }, + "question": "How many paid/refunded orders are in region NA, category D, from month 202602 through 202606? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_order_count_t8/instruction.md b/harbor/tasks/v3_depth2_order_count_t8/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..97f563f7335446dc1058a229f413479a640f495e --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_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: +How many paid/refunded orders are in region NA, category D, from month 202602 through 202606? Report the 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_depth2_order_count_t8/task.toml b/harbor/tasks/v3_depth2_order_count_t8/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..d3af92af9812dfc668015fc9eb272a285a336a4f --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t8/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_order_count_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 = 2 + +[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_depth2_order_count_t8/tests/check_output_shape.py b/harbor/tasks/v3_depth2_order_count_t8/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_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_depth2_order_count_t8/tests/test.sh b/harbor/tasks/v3_depth2_order_count_t8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_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_depth2_order_count_t9/environment/Dockerfile b/harbor/tasks/v3_depth2_order_count_t9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_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_depth2_order_count_t9/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_order_count_t9/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_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_depth2_order_count_t9/environment/task.json b/harbor/tasks/v3_depth2_order_count_t9/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..da838a12f82c03347d0fb41f44b900922082f6ed --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t9/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_order_count_t9", + "depth": 2, + "family": "order_count", + "params": { + "region": "EU", + "category": "A", + "month_start": 202602, + "month_end": 202605 + }, + "question": "How many paid/refunded orders are in region EU, category A, from month 202602 through 202605? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_order_count_t9/instruction.md b/harbor/tasks/v3_depth2_order_count_t9/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..d1990503cf5272fb3f8752ce85db792b4b4e1f12 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_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: +How many paid/refunded orders are in region EU, category A, from month 202602 through 202605? Report the 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_depth2_order_count_t9/task.toml b/harbor/tasks/v3_depth2_order_count_t9/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..6574e13a746e247f2e074929ac4fcc2af3491178 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t9/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_order_count_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 = 2 + +[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_depth2_order_count_t9/tests/check_output_shape.py b/harbor/tasks/v3_depth2_order_count_t9/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_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_depth2_order_count_t9/tests/test.sh b/harbor/tasks/v3_depth2_order_count_t9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t9/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_depth2_unique_customer_count_t0/environment/Dockerfile b/harbor/tasks/v3_depth2_unique_customer_count_t0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t0/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_depth2_unique_customer_count_t0/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_unique_customer_count_t0/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t0/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_depth2_unique_customer_count_t0/environment/task.json b/harbor/tasks/v3_depth2_unique_customer_count_t0/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..af7bbbb11b178d66ff70162b645de106a768e17b --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t0/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_unique_customer_count_t0", + "depth": 2, + "family": "unique_customer_count", + "params": { + "region": "NA", + "category": "A", + "month_start": 202601, + "month_end": 202603 + }, + "question": "How many unique customers placed paid/refunded orders in region NA, category A, from month 202601 through 202603? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_unique_customer_count_t0/instruction.md b/harbor/tasks/v3_depth2_unique_customer_count_t0/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9cf408df7700d3ca682079155cb1f709ad999af8 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t0/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: +How many unique customers placed paid/refunded orders in region NA, category A, from month 202601 through 202603? Report the 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_depth2_unique_customer_count_t0/task.toml b/harbor/tasks/v3_depth2_unique_customer_count_t0/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..f381ecc3997430add1f867b4afd524c90211640e --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t0/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_unique_customer_count_t0" +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 = 2 + +[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_depth2_unique_customer_count_t0/tests/check_output_shape.py b/harbor/tasks/v3_depth2_unique_customer_count_t0/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t0/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_depth2_unique_customer_count_t0/tests/test.sh b/harbor/tasks/v3_depth2_unique_customer_count_t0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t0/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_depth2_unique_customer_count_t1/environment/Dockerfile b/harbor/tasks/v3_depth2_unique_customer_count_t1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t1/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_depth2_unique_customer_count_t1/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_unique_customer_count_t1/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t1/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_depth2_unique_customer_count_t1/environment/task.json b/harbor/tasks/v3_depth2_unique_customer_count_t1/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..8abc2048efef3a041776a633363526ccf955d9f7 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t1/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_unique_customer_count_t1", + "depth": 2, + "family": "unique_customer_count", + "params": { + "region": "NA", + "category": "B", + "month_start": 202604, + "month_end": 202606 + }, + "question": "How many unique customers placed paid/refunded orders in region NA, category B, from month 202604 through 202606? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_unique_customer_count_t1/instruction.md b/harbor/tasks/v3_depth2_unique_customer_count_t1/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..da922da06e3c966f5beb35cc1273d513636948a6 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t1/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: +How many unique customers placed paid/refunded orders in region NA, category B, from month 202604 through 202606? Report the 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_depth2_unique_customer_count_t1/task.toml b/harbor/tasks/v3_depth2_unique_customer_count_t1/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..a2009d274d27de388d383cd0d7322c502ac6ec7c --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t1/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_unique_customer_count_t1" +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 = 2 + +[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_depth2_unique_customer_count_t1/tests/check_output_shape.py b/harbor/tasks/v3_depth2_unique_customer_count_t1/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t1/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_depth2_unique_customer_count_t1/tests/test.sh b/harbor/tasks/v3_depth2_unique_customer_count_t1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t1/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_depth2_unique_customer_count_t10/environment/Dockerfile b/harbor/tasks/v3_depth2_unique_customer_count_t10/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t10/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_depth2_unique_customer_count_t10/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_unique_customer_count_t10/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t10/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_depth2_unique_customer_count_t10/environment/task.json b/harbor/tasks/v3_depth2_unique_customer_count_t10/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..b65fb2ed649418853dbfaec5b4d4811e56b9477f --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t10/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_unique_customer_count_t10", + "depth": 2, + "family": "unique_customer_count", + "params": { + "region": "APAC", + "category": "B", + "month_start": 202604, + "month_end": 202606 + }, + "question": "How many unique customers placed paid/refunded orders in region APAC, category B, from month 202604 through 202606? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_unique_customer_count_t10/instruction.md b/harbor/tasks/v3_depth2_unique_customer_count_t10/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..34920a5da0b55fb03d63a508bf9d0b00e60370a8 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t10/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: +How many unique customers placed paid/refunded orders in region APAC, category B, from month 202604 through 202606? Report the 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_depth2_unique_customer_count_t10/task.toml b/harbor/tasks/v3_depth2_unique_customer_count_t10/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..c62909660f6444ff5551a61f31fa9dab12755c30 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t10/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_unique_customer_count_t10" +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 = 2 + +[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_depth2_unique_customer_count_t10/tests/check_output_shape.py b/harbor/tasks/v3_depth2_unique_customer_count_t10/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t10/tests/test.sh b/harbor/tasks/v3_depth2_unique_customer_count_t10/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t11/environment/Dockerfile b/harbor/tasks/v3_depth2_unique_customer_count_t11/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t11/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_unique_customer_count_t11/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t11/environment/task.json b/harbor/tasks/v3_depth2_unique_customer_count_t11/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..d68d8e919840239812df3f5b26bf71fee45eb38c --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t11/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_unique_customer_count_t11", + "depth": 2, + "family": "unique_customer_count", + "params": { + "region": "LATAM", + "category": "A", + "month_start": 202601, + "month_end": 202603 + }, + "question": "How many unique customers placed paid/refunded orders in region LATAM, category A, from month 202601 through 202603? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_unique_customer_count_t11/instruction.md b/harbor/tasks/v3_depth2_unique_customer_count_t11/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..ceae8e9875ace8cb272bab2b937d02719a167da3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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: +How many unique customers placed paid/refunded orders in region LATAM, category A, from month 202601 through 202603? Report the 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_depth2_unique_customer_count_t11/task.toml b/harbor/tasks/v3_depth2_unique_customer_count_t11/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..21325d875c0032506fe6cc7dc6ea92be3d44ee61 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t11/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_unique_customer_count_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 = 2 + +[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_depth2_unique_customer_count_t11/tests/check_output_shape.py b/harbor/tasks/v3_depth2_unique_customer_count_t11/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t11/tests/test.sh b/harbor/tasks/v3_depth2_unique_customer_count_t11/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t12/environment/Dockerfile b/harbor/tasks/v3_depth2_unique_customer_count_t12/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t12/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_unique_customer_count_t12/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t12/environment/task.json b/harbor/tasks/v3_depth2_unique_customer_count_t12/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..7872bd32cec207e323defacd9cf7140f9c0e3c7b --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t12/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_unique_customer_count_t12", + "depth": 2, + "family": "unique_customer_count", + "params": { + "region": "NA", + "category": "C", + "month_start": 202601, + "month_end": 202606 + }, + "question": "How many unique customers placed paid/refunded orders in region NA, category C, from month 202601 through 202606? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_unique_customer_count_t12/instruction.md b/harbor/tasks/v3_depth2_unique_customer_count_t12/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..63a0b8247e1b771839a9772f4346a6cd8f32473e --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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: +How many unique customers placed paid/refunded orders in region NA, category C, from month 202601 through 202606? Report the 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_depth2_unique_customer_count_t12/task.toml b/harbor/tasks/v3_depth2_unique_customer_count_t12/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..0b9e5286048bb5fc9e86512793b4f723b0057272 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t12/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_unique_customer_count_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 = 2 + +[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_depth2_unique_customer_count_t12/tests/check_output_shape.py b/harbor/tasks/v3_depth2_unique_customer_count_t12/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t12/tests/test.sh b/harbor/tasks/v3_depth2_unique_customer_count_t12/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t13/environment/Dockerfile b/harbor/tasks/v3_depth2_unique_customer_count_t13/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t13/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_unique_customer_count_t13/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t13/environment/task.json b/harbor/tasks/v3_depth2_unique_customer_count_t13/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..2e9afb76ce12c1f53118977640582f1a38e24146 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t13/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_unique_customer_count_t13", + "depth": 2, + "family": "unique_customer_count", + "params": { + "region": "EU", + "category": "B", + "month_start": 202601, + "month_end": 202603 + }, + "question": "How many unique customers placed paid/refunded orders in region EU, category B, from month 202601 through 202603? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_unique_customer_count_t13/instruction.md b/harbor/tasks/v3_depth2_unique_customer_count_t13/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..199af558a046fc4574e77a6e1fb7a6345e5f6d01 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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: +How many unique customers placed paid/refunded orders in region EU, category B, from month 202601 through 202603? Report the 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_depth2_unique_customer_count_t13/task.toml b/harbor/tasks/v3_depth2_unique_customer_count_t13/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..bbea5875ddbff25392dd2e6ff6a18b88bb679e7f --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t13/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_unique_customer_count_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 = 2 + +[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_depth2_unique_customer_count_t13/tests/check_output_shape.py b/harbor/tasks/v3_depth2_unique_customer_count_t13/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t13/tests/test.sh b/harbor/tasks/v3_depth2_unique_customer_count_t13/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t14/environment/Dockerfile b/harbor/tasks/v3_depth2_unique_customer_count_t14/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t14/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_unique_customer_count_t14/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t14/environment/task.json b/harbor/tasks/v3_depth2_unique_customer_count_t14/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..c4152d3a2040e3471f957ee622ac3b765f823671 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t14/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_unique_customer_count_t14", + "depth": 2, + "family": "unique_customer_count", + "params": { + "region": "APAC", + "category": "C", + "month_start": 202602, + "month_end": 202606 + }, + "question": "How many unique customers placed paid/refunded orders in region APAC, category C, from month 202602 through 202606? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_unique_customer_count_t14/instruction.md b/harbor/tasks/v3_depth2_unique_customer_count_t14/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..13825ff085a0efdad12cdfaedace81b019c3781f --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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: +How many unique customers placed paid/refunded orders in region APAC, category C, from month 202602 through 202606? Report the 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_depth2_unique_customer_count_t14/task.toml b/harbor/tasks/v3_depth2_unique_customer_count_t14/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..b17863d557f1584570572ef723e8a7dcfc94d19a --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t14/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_unique_customer_count_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 = 2 + +[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_depth2_unique_customer_count_t14/tests/check_output_shape.py b/harbor/tasks/v3_depth2_unique_customer_count_t14/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t14/tests/test.sh b/harbor/tasks/v3_depth2_unique_customer_count_t14/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t15/environment/Dockerfile b/harbor/tasks/v3_depth2_unique_customer_count_t15/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t15/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_unique_customer_count_t15/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t15/environment/task.json b/harbor/tasks/v3_depth2_unique_customer_count_t15/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..a5f3ce016606fee03334fe8cad6c9b86eb78b4b9 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t15/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_unique_customer_count_t15", + "depth": 2, + "family": "unique_customer_count", + "params": { + "region": "LATAM", + "category": "D", + "month_start": 202601, + "month_end": 202605 + }, + "question": "How many unique customers placed paid/refunded orders in region LATAM, category D, from month 202601 through 202605? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_unique_customer_count_t15/instruction.md b/harbor/tasks/v3_depth2_unique_customer_count_t15/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..6f610741bb904a5579162f5fd4a54498ad49bd46 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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: +How many unique customers placed paid/refunded orders in region LATAM, category D, from month 202601 through 202605? Report the 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_depth2_unique_customer_count_t15/task.toml b/harbor/tasks/v3_depth2_unique_customer_count_t15/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..98900b54b4dcc4e56dbc5fd0d4532c336588d002 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t15/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_unique_customer_count_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 = 2 + +[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_depth2_unique_customer_count_t15/tests/check_output_shape.py b/harbor/tasks/v3_depth2_unique_customer_count_t15/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t15/tests/test.sh b/harbor/tasks/v3_depth2_unique_customer_count_t15/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t16/environment/Dockerfile b/harbor/tasks/v3_depth2_unique_customer_count_t16/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t16/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_unique_customer_count_t16/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t16/environment/task.json b/harbor/tasks/v3_depth2_unique_customer_count_t16/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..5a8af2c8ac5788f9199dc923532e7652835ace54 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t16/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_unique_customer_count_t16", + "depth": 2, + "family": "unique_customer_count", + "params": { + "region": "NA", + "category": "A", + "month_start": 202604, + "month_end": 202606 + }, + "question": "How many unique customers placed paid/refunded orders in region NA, category A, from month 202604 through 202606? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_unique_customer_count_t16/instruction.md b/harbor/tasks/v3_depth2_unique_customer_count_t16/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..356dbfa3221a5526531bf0d5464943fff68778ed --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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: +How many unique customers placed paid/refunded orders in region NA, category A, from month 202604 through 202606? Report the 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_depth2_unique_customer_count_t16/task.toml b/harbor/tasks/v3_depth2_unique_customer_count_t16/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..8f161bc2be0a8e6a94d84b845b64ba95c0fcb163 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t16/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_unique_customer_count_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 = 2 + +[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_depth2_unique_customer_count_t16/tests/check_output_shape.py b/harbor/tasks/v3_depth2_unique_customer_count_t16/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t16/tests/test.sh b/harbor/tasks/v3_depth2_unique_customer_count_t16/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t17/environment/Dockerfile b/harbor/tasks/v3_depth2_unique_customer_count_t17/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t17/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_unique_customer_count_t17/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t17/environment/task.json b/harbor/tasks/v3_depth2_unique_customer_count_t17/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..c96889685588bf92118897f1f29f4840009cf2e2 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t17/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_unique_customer_count_t17", + "depth": 2, + "family": "unique_customer_count", + "params": { + "region": "EU", + "category": "D", + "month_start": 202601, + "month_end": 202602 + }, + "question": "How many unique customers placed paid/refunded orders in region EU, category D, from month 202601 through 202602? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_unique_customer_count_t17/instruction.md b/harbor/tasks/v3_depth2_unique_customer_count_t17/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..61727a06b8dbaa1e0a424bdbfe0b177f31824bad --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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: +How many unique customers placed paid/refunded orders in region EU, category D, from month 202601 through 202602? Report the 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_depth2_unique_customer_count_t17/task.toml b/harbor/tasks/v3_depth2_unique_customer_count_t17/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..85f37f87e8a4658383f624db235a10cecc269fc3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t17/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_unique_customer_count_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 = 2 + +[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_depth2_unique_customer_count_t17/tests/check_output_shape.py b/harbor/tasks/v3_depth2_unique_customer_count_t17/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t17/tests/test.sh b/harbor/tasks/v3_depth2_unique_customer_count_t17/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t18/environment/Dockerfile b/harbor/tasks/v3_depth2_unique_customer_count_t18/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t18/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_unique_customer_count_t18/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t18/environment/task.json b/harbor/tasks/v3_depth2_unique_customer_count_t18/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..4e4e4595aca9ea1c79e2f7a02f1ad7dfb1081a5f --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t18/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_unique_customer_count_t18", + "depth": 2, + "family": "unique_customer_count", + "params": { + "region": "APAC", + "category": "A", + "month_start": 202603, + "month_end": 202604 + }, + "question": "How many unique customers placed paid/refunded orders in region APAC, category A, from month 202603 through 202604? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_unique_customer_count_t18/instruction.md b/harbor/tasks/v3_depth2_unique_customer_count_t18/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..27f95970a08c27e25dd3023e6204c4cc0963a670 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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: +How many unique customers placed paid/refunded orders in region APAC, category A, from month 202603 through 202604? Report the 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_depth2_unique_customer_count_t18/task.toml b/harbor/tasks/v3_depth2_unique_customer_count_t18/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..5e5c56e9a2c83635e4b16b5a5169cab21bdc68b1 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t18/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_unique_customer_count_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 = 2 + +[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_depth2_unique_customer_count_t18/tests/check_output_shape.py b/harbor/tasks/v3_depth2_unique_customer_count_t18/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t18/tests/test.sh b/harbor/tasks/v3_depth2_unique_customer_count_t18/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t19/environment/Dockerfile b/harbor/tasks/v3_depth2_unique_customer_count_t19/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t19/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_unique_customer_count_t19/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t19/environment/task.json b/harbor/tasks/v3_depth2_unique_customer_count_t19/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..75d3bd5e9110a74a49dc667c1b02c973a74a8ec6 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t19/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_unique_customer_count_t19", + "depth": 2, + "family": "unique_customer_count", + "params": { + "region": "LATAM", + "category": "B", + "month_start": 202605, + "month_end": 202606 + }, + "question": "How many unique customers placed paid/refunded orders in region LATAM, category B, from month 202605 through 202606? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_unique_customer_count_t19/instruction.md b/harbor/tasks/v3_depth2_unique_customer_count_t19/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..7ed5aae77293a91e7576f593375aa0859e2cb1bc --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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: +How many unique customers placed paid/refunded orders in region LATAM, category B, from month 202605 through 202606? Report the 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_depth2_unique_customer_count_t19/task.toml b/harbor/tasks/v3_depth2_unique_customer_count_t19/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..f02cabcd94382f3f9788a842b4425eb76354182e --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t19/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_unique_customer_count_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 = 2 + +[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_depth2_unique_customer_count_t19/tests/check_output_shape.py b/harbor/tasks/v3_depth2_unique_customer_count_t19/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t19/tests/test.sh b/harbor/tasks/v3_depth2_unique_customer_count_t19/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t2/environment/Dockerfile b/harbor/tasks/v3_depth2_unique_customer_count_t2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t2/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_unique_customer_count_t2/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t2/environment/task.json b/harbor/tasks/v3_depth2_unique_customer_count_t2/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..bc195a74b459913bb323f9cea8e293ba267be606 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t2/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_unique_customer_count_t2", + "depth": 2, + "family": "unique_customer_count", + "params": { + "region": "EU", + "category": "C", + "month_start": 202601, + "month_end": 202604 + }, + "question": "How many unique customers placed paid/refunded orders in region EU, category C, from month 202601 through 202604? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_unique_customer_count_t2/instruction.md b/harbor/tasks/v3_depth2_unique_customer_count_t2/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..b3d753dc2b9e89a9ba8ad4b704c4d1a3d9b57f5b --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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: +How many unique customers placed paid/refunded orders in region EU, category C, from month 202601 through 202604? Report the 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_depth2_unique_customer_count_t2/task.toml b/harbor/tasks/v3_depth2_unique_customer_count_t2/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..84cbe735b38d6201f0784bb7135b3eb594a1c180 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t2/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_unique_customer_count_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 = 2 + +[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_depth2_unique_customer_count_t2/tests/check_output_shape.py b/harbor/tasks/v3_depth2_unique_customer_count_t2/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t2/tests/test.sh b/harbor/tasks/v3_depth2_unique_customer_count_t2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t20/environment/Dockerfile b/harbor/tasks/v3_depth2_unique_customer_count_t20/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t20/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_unique_customer_count_t20/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t20/environment/task.json b/harbor/tasks/v3_depth2_unique_customer_count_t20/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..7e58fffaf8315e8fc66fc9f7b60a668b0f6d6240 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t20/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_unique_customer_count_t20", + "depth": 2, + "family": "unique_customer_count", + "params": { + "region": "NA", + "category": "C", + "month_start": 202602, + "month_end": 202604 + }, + "question": "How many unique customers placed paid/refunded orders in region NA, category C, from month 202602 through 202604? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_unique_customer_count_t20/instruction.md b/harbor/tasks/v3_depth2_unique_customer_count_t20/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..8a208b88c72635957f6384b745e0560ecd11321e --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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: +How many unique customers placed paid/refunded orders in region NA, category C, from month 202602 through 202604? Report the 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_depth2_unique_customer_count_t20/task.toml b/harbor/tasks/v3_depth2_unique_customer_count_t20/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..17c7039b33127750a01a8086188b24d32efa4fff --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t20/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_unique_customer_count_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 = 2 + +[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_depth2_unique_customer_count_t20/tests/check_output_shape.py b/harbor/tasks/v3_depth2_unique_customer_count_t20/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t20/tests/test.sh b/harbor/tasks/v3_depth2_unique_customer_count_t20/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t21/environment/Dockerfile b/harbor/tasks/v3_depth2_unique_customer_count_t21/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t21/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_unique_customer_count_t21/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t21/environment/task.json b/harbor/tasks/v3_depth2_unique_customer_count_t21/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..35fed1ef11e3d6802262ce0a53582258e939f97a --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t21/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_unique_customer_count_t21", + "depth": 2, + "family": "unique_customer_count", + "params": { + "region": "EU", + "category": "B", + "month_start": 202604, + "month_end": 202606 + }, + "question": "How many unique customers placed paid/refunded orders in region EU, category B, from month 202604 through 202606? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_unique_customer_count_t21/instruction.md b/harbor/tasks/v3_depth2_unique_customer_count_t21/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..1bee35077f2737c9ee1857211c32a2f66b20761b --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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: +How many unique customers placed paid/refunded orders in region EU, category B, from month 202604 through 202606? Report the 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_depth2_unique_customer_count_t21/task.toml b/harbor/tasks/v3_depth2_unique_customer_count_t21/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..436032a1ef9a8142b3a983323d0241c25a09df88 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t21/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_unique_customer_count_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 = 2 + +[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_depth2_unique_customer_count_t21/tests/check_output_shape.py b/harbor/tasks/v3_depth2_unique_customer_count_t21/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t21/tests/test.sh b/harbor/tasks/v3_depth2_unique_customer_count_t21/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t22/environment/Dockerfile b/harbor/tasks/v3_depth2_unique_customer_count_t22/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t22/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_unique_customer_count_t22/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t22/environment/task.json b/harbor/tasks/v3_depth2_unique_customer_count_t22/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..88953692ed52abbd8589e40823b9a22b638f670d --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t22/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_unique_customer_count_t22", + "depth": 2, + "family": "unique_customer_count", + "params": { + "region": "APAC", + "category": "D", + "month_start": 202603, + "month_end": 202605 + }, + "question": "How many unique customers placed paid/refunded orders in region APAC, category D, from month 202603 through 202605? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_unique_customer_count_t22/instruction.md b/harbor/tasks/v3_depth2_unique_customer_count_t22/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..c65af30eceeb1420c142c89968c4f604ea560bae --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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: +How many unique customers placed paid/refunded orders in region APAC, category D, from month 202603 through 202605? Report the 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_depth2_unique_customer_count_t22/task.toml b/harbor/tasks/v3_depth2_unique_customer_count_t22/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..9b8ff04b62b18de84cd4b95bb0dba8c4496d940c --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t22/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_unique_customer_count_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 = 2 + +[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_depth2_unique_customer_count_t22/tests/check_output_shape.py b/harbor/tasks/v3_depth2_unique_customer_count_t22/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t22/tests/test.sh b/harbor/tasks/v3_depth2_unique_customer_count_t22/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t23/environment/Dockerfile b/harbor/tasks/v3_depth2_unique_customer_count_t23/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t23/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_unique_customer_count_t23/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t23/environment/task.json b/harbor/tasks/v3_depth2_unique_customer_count_t23/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..5f202f4bb50123b86acae920339901d2ee696b8f --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t23/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_unique_customer_count_t23", + "depth": 2, + "family": "unique_customer_count", + "params": { + "region": "LATAM", + "category": "C", + "month_start": 202601, + "month_end": 202602 + }, + "question": "How many unique customers placed paid/refunded orders in region LATAM, category C, from month 202601 through 202602? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_unique_customer_count_t23/instruction.md b/harbor/tasks/v3_depth2_unique_customer_count_t23/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..f8c7b7992fa6ea89dcd676fe8891a93eaf54096d --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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: +How many unique customers placed paid/refunded orders in region LATAM, category C, from month 202601 through 202602? Report the 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_depth2_unique_customer_count_t23/task.toml b/harbor/tasks/v3_depth2_unique_customer_count_t23/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..b84122e2f31007dc2948527d515c506caf4a77a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t23/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_unique_customer_count_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 = 2 + +[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_depth2_unique_customer_count_t23/tests/check_output_shape.py b/harbor/tasks/v3_depth2_unique_customer_count_t23/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t23/tests/test.sh b/harbor/tasks/v3_depth2_unique_customer_count_t23/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t24/environment/Dockerfile b/harbor/tasks/v3_depth2_unique_customer_count_t24/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t24/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_unique_customer_count_t24/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t24/environment/task.json b/harbor/tasks/v3_depth2_unique_customer_count_t24/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..3a63f6bc5f1d0c816885eab49f00e5591153cdaa --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t24/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_unique_customer_count_t24", + "depth": 2, + "family": "unique_customer_count", + "params": { + "region": "NA", + "category": "D", + "month_start": 202601, + "month_end": 202603 + }, + "question": "How many unique customers placed paid/refunded orders in region NA, category D, from month 202601 through 202603? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_unique_customer_count_t24/instruction.md b/harbor/tasks/v3_depth2_unique_customer_count_t24/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..b001f7210a5b18ff5ebd52c3eb357c9f0a425800 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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: +How many unique customers placed paid/refunded orders in region NA, category D, from month 202601 through 202603? Report the 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_depth2_unique_customer_count_t24/task.toml b/harbor/tasks/v3_depth2_unique_customer_count_t24/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..af06f77a416f9c36f5140ac00d3db5876d901b6f --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t24/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_unique_customer_count_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 = 2 + +[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_depth2_unique_customer_count_t24/tests/check_output_shape.py b/harbor/tasks/v3_depth2_unique_customer_count_t24/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t24/tests/test.sh b/harbor/tasks/v3_depth2_unique_customer_count_t24/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t3/environment/Dockerfile b/harbor/tasks/v3_depth2_unique_customer_count_t3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t3/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_unique_customer_count_t3/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t3/environment/task.json b/harbor/tasks/v3_depth2_unique_customer_count_t3/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..5209f10924bb7d0c6573978e9aba2b7f83f88338 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t3/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_unique_customer_count_t3", + "depth": 2, + "family": "unique_customer_count", + "params": { + "region": "EU", + "category": "D", + "month_start": 202603, + "month_end": 202606 + }, + "question": "How many unique customers placed paid/refunded orders in region EU, category D, from month 202603 through 202606? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_unique_customer_count_t3/instruction.md b/harbor/tasks/v3_depth2_unique_customer_count_t3/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4fa2e6e0e774c2e63fdd53fdd0f6a6cef3529023 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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: +How many unique customers placed paid/refunded orders in region EU, category D, from month 202603 through 202606? Report the 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_depth2_unique_customer_count_t3/task.toml b/harbor/tasks/v3_depth2_unique_customer_count_t3/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..893c77246dc7eb38e01280c3538c0f3aae11ebf5 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t3/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_unique_customer_count_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 = 2 + +[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_depth2_unique_customer_count_t3/tests/check_output_shape.py b/harbor/tasks/v3_depth2_unique_customer_count_t3/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t3/tests/test.sh b/harbor/tasks/v3_depth2_unique_customer_count_t3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t4/environment/Dockerfile b/harbor/tasks/v3_depth2_unique_customer_count_t4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t4/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_unique_customer_count_t4/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t4/environment/task.json b/harbor/tasks/v3_depth2_unique_customer_count_t4/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..bf1586398f0eebf6d6a1ec1be29047b4798f1d4a --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t4/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_unique_customer_count_t4", + "depth": 2, + "family": "unique_customer_count", + "params": { + "region": "APAC", + "category": "A", + "month_start": 202602, + "month_end": 202605 + }, + "question": "How many unique customers placed paid/refunded orders in region APAC, category A, from month 202602 through 202605? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_unique_customer_count_t4/instruction.md b/harbor/tasks/v3_depth2_unique_customer_count_t4/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..62fe710de92a6ad41d0bf5b27d163decbba12e56 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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: +How many unique customers placed paid/refunded orders in region APAC, category A, from month 202602 through 202605? Report the 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_depth2_unique_customer_count_t4/task.toml b/harbor/tasks/v3_depth2_unique_customer_count_t4/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..1ecbe29aa10771db6e01fc85456553707fbd5e80 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t4/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_unique_customer_count_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 = 2 + +[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_depth2_unique_customer_count_t4/tests/check_output_shape.py b/harbor/tasks/v3_depth2_unique_customer_count_t4/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t4/tests/test.sh b/harbor/tasks/v3_depth2_unique_customer_count_t4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t5/environment/Dockerfile b/harbor/tasks/v3_depth2_unique_customer_count_t5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t5/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_unique_customer_count_t5/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t5/environment/task.json b/harbor/tasks/v3_depth2_unique_customer_count_t5/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..970e7598cdf67702d9589ce24af627bf4d8fcd27 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t5/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_unique_customer_count_t5", + "depth": 2, + "family": "unique_customer_count", + "params": { + "region": "APAC", + "category": "D", + "month_start": 202601, + "month_end": 202606 + }, + "question": "How many unique customers placed paid/refunded orders in region APAC, category D, from month 202601 through 202606? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_unique_customer_count_t5/instruction.md b/harbor/tasks/v3_depth2_unique_customer_count_t5/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..061a228bd34ac32943791c3b42ef052229c015f6 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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: +How many unique customers placed paid/refunded orders in region APAC, category D, from month 202601 through 202606? Report the 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_depth2_unique_customer_count_t5/task.toml b/harbor/tasks/v3_depth2_unique_customer_count_t5/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..7f756cf3b102554d44d723d0b6a50ab6f8e8a9f6 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t5/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_unique_customer_count_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 = 2 + +[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_depth2_unique_customer_count_t5/tests/check_output_shape.py b/harbor/tasks/v3_depth2_unique_customer_count_t5/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t5/tests/test.sh b/harbor/tasks/v3_depth2_unique_customer_count_t5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t6/environment/Dockerfile b/harbor/tasks/v3_depth2_unique_customer_count_t6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t6/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_unique_customer_count_t6/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t6/environment/task.json b/harbor/tasks/v3_depth2_unique_customer_count_t6/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..b0e6444bfa3bb7113e40197132e9d4d34fa1c876 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t6/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_unique_customer_count_t6", + "depth": 2, + "family": "unique_customer_count", + "params": { + "region": "LATAM", + "category": "B", + "month_start": 202601, + "month_end": 202604 + }, + "question": "How many unique customers placed paid/refunded orders in region LATAM, category B, from month 202601 through 202604? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_unique_customer_count_t6/instruction.md b/harbor/tasks/v3_depth2_unique_customer_count_t6/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..2bae6a8db9cd7f8bb2944d1be1a98a66c095a789 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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: +How many unique customers placed paid/refunded orders in region LATAM, category B, from month 202601 through 202604? Report the 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_depth2_unique_customer_count_t6/task.toml b/harbor/tasks/v3_depth2_unique_customer_count_t6/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..830da79eb6e9c37ff1327a54d36d0f56ba336663 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t6/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_unique_customer_count_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 = 2 + +[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_depth2_unique_customer_count_t6/tests/check_output_shape.py b/harbor/tasks/v3_depth2_unique_customer_count_t6/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t6/tests/test.sh b/harbor/tasks/v3_depth2_unique_customer_count_t6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t7/environment/Dockerfile b/harbor/tasks/v3_depth2_unique_customer_count_t7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t7/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_unique_customer_count_t7/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t7/environment/task.json b/harbor/tasks/v3_depth2_unique_customer_count_t7/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..95d018437f0d321e76ea3906879e6af7d33f8177 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t7/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_unique_customer_count_t7", + "depth": 2, + "family": "unique_customer_count", + "params": { + "region": "LATAM", + "category": "C", + "month_start": 202603, + "month_end": 202606 + }, + "question": "How many unique customers placed paid/refunded orders in region LATAM, category C, from month 202603 through 202606? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_unique_customer_count_t7/instruction.md b/harbor/tasks/v3_depth2_unique_customer_count_t7/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..7e69b028d452a5bca8f31a9bc2f6a0c97b50cd18 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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: +How many unique customers placed paid/refunded orders in region LATAM, category C, from month 202603 through 202606? Report the 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_depth2_unique_customer_count_t7/task.toml b/harbor/tasks/v3_depth2_unique_customer_count_t7/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..aa0062445910b17a02c45309a69e719a8fb3bc77 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t7/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_unique_customer_count_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 = 2 + +[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_depth2_unique_customer_count_t7/tests/check_output_shape.py b/harbor/tasks/v3_depth2_unique_customer_count_t7/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t7/tests/test.sh b/harbor/tasks/v3_depth2_unique_customer_count_t7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t8/environment/Dockerfile b/harbor/tasks/v3_depth2_unique_customer_count_t8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t8/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_unique_customer_count_t8/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t8/environment/task.json b/harbor/tasks/v3_depth2_unique_customer_count_t8/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..e4660e5b126741f7e54944c4b29852d1c1446a2f --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t8/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_unique_customer_count_t8", + "depth": 2, + "family": "unique_customer_count", + "params": { + "region": "NA", + "category": "D", + "month_start": 202602, + "month_end": 202606 + }, + "question": "How many unique customers placed paid/refunded orders in region NA, category D, from month 202602 through 202606? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_unique_customer_count_t8/instruction.md b/harbor/tasks/v3_depth2_unique_customer_count_t8/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..a8a65e3f589b78b8f90e27583f07981a27ddd6f9 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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: +How many unique customers placed paid/refunded orders in region NA, category D, from month 202602 through 202606? Report the 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_depth2_unique_customer_count_t8/task.toml b/harbor/tasks/v3_depth2_unique_customer_count_t8/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..b3ccc711b4ffb8a1c10f7a0f3b86834400e950c7 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t8/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_unique_customer_count_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 = 2 + +[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_depth2_unique_customer_count_t8/tests/check_output_shape.py b/harbor/tasks/v3_depth2_unique_customer_count_t8/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t8/tests/test.sh b/harbor/tasks/v3_depth2_unique_customer_count_t8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t9/environment/Dockerfile b/harbor/tasks/v3_depth2_unique_customer_count_t9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t9/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_unique_customer_count_t9/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t9/environment/task.json b/harbor/tasks/v3_depth2_unique_customer_count_t9/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..6c066b0eb47ecf1a1952abe57cc723b1167b153c --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t9/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_unique_customer_count_t9", + "depth": 2, + "family": "unique_customer_count", + "params": { + "region": "EU", + "category": "A", + "month_start": 202602, + "month_end": 202605 + }, + "question": "How many unique customers placed paid/refunded orders in region EU, category A, from month 202602 through 202605? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_unique_customer_count_t9/instruction.md b/harbor/tasks/v3_depth2_unique_customer_count_t9/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..c47301214c03955fdca3f39faff8051b9b0bd194 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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: +How many unique customers placed paid/refunded orders in region EU, category A, from month 202602 through 202605? Report the 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_depth2_unique_customer_count_t9/task.toml b/harbor/tasks/v3_depth2_unique_customer_count_t9/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..93923871f53f1bff2e58ee7256384a9da5803ee7 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t9/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_unique_customer_count_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 = 2 + +[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_depth2_unique_customer_count_t9/tests/check_output_shape.py b/harbor/tasks/v3_depth2_unique_customer_count_t9/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_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_depth2_unique_customer_count_t9/tests/test.sh b/harbor/tasks/v3_depth2_unique_customer_count_t9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_unique_customer_count_t9/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_depth3_net_revenue_usd_t0/environment/Dockerfile b/harbor/tasks/v3_depth3_net_revenue_usd_t0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t0/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_depth3_net_revenue_usd_t0/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_net_revenue_usd_t0/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t0/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_depth3_net_revenue_usd_t0/environment/task.json b/harbor/tasks/v3_depth3_net_revenue_usd_t0/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..acc3f682fb89c8b0a315bdcab10b57966d84bcd9 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t0/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_net_revenue_usd_t0", + "depth": 3, + "family": "net_revenue_usd", + "params": { + "region": "NA", + "category": "A", + "month_start": 202601, + "month_end": 202603 + }, + "question": "For orders in region NA, category A, months 202601-202603: compute each order's net USD revenue after loyalty discount and refunds, then report the total net revenue in USD.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth3_net_revenue_usd_t0/instruction.md b/harbor/tasks/v3_depth3_net_revenue_usd_t0/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..5242a8e30452bf34df4d41addbbe1ecf932e7fe3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t0/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 orders in region NA, category A, months 202601-202603: compute each order's net USD revenue after loyalty discount and refunds, then report the total net revenue in USD. + +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_depth3_net_revenue_usd_t0/task.toml b/harbor/tasks/v3_depth3_net_revenue_usd_t0/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..3db022894fc4983373a6b82241706ebafacb117d --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t0/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_net_revenue_usd_t0" +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 = 3 + +[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_depth3_net_revenue_usd_t0/tests/check_output_shape.py b/harbor/tasks/v3_depth3_net_revenue_usd_t0/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t0/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_depth3_net_revenue_usd_t0/tests/test.sh b/harbor/tasks/v3_depth3_net_revenue_usd_t0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t0/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_depth3_net_revenue_usd_t1/environment/Dockerfile b/harbor/tasks/v3_depth3_net_revenue_usd_t1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t1/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_depth3_net_revenue_usd_t1/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_net_revenue_usd_t1/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t1/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_depth3_net_revenue_usd_t1/environment/task.json b/harbor/tasks/v3_depth3_net_revenue_usd_t1/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..d5699728c9b99c4c731b65b2fd9bcadd10c9fc2b --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t1/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_net_revenue_usd_t1", + "depth": 3, + "family": "net_revenue_usd", + "params": { + "region": "NA", + "category": "B", + "month_start": 202604, + "month_end": 202606 + }, + "question": "For orders in region NA, category B, months 202604-202606: compute each order's net USD revenue after loyalty discount and refunds, then report the total net revenue in USD.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth3_net_revenue_usd_t1/instruction.md b/harbor/tasks/v3_depth3_net_revenue_usd_t1/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..338123e219349e9f8ec5465f4234a7a75ad5651f --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t1/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 orders in region NA, category B, months 202604-202606: compute each order's net USD revenue after loyalty discount and refunds, then report the total net revenue in USD. + +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_depth3_net_revenue_usd_t1/task.toml b/harbor/tasks/v3_depth3_net_revenue_usd_t1/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..58577d9573f8a601f86d0be222e7a8aca9adc5dc --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t1/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_net_revenue_usd_t1" +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 = 3 + +[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_depth3_net_revenue_usd_t1/tests/check_output_shape.py b/harbor/tasks/v3_depth3_net_revenue_usd_t1/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t1/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_depth3_net_revenue_usd_t1/tests/test.sh b/harbor/tasks/v3_depth3_net_revenue_usd_t1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t1/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_depth3_net_revenue_usd_t10/environment/Dockerfile b/harbor/tasks/v3_depth3_net_revenue_usd_t10/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t10/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_depth3_net_revenue_usd_t10/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_net_revenue_usd_t10/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t10/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_depth3_net_revenue_usd_t10/environment/task.json b/harbor/tasks/v3_depth3_net_revenue_usd_t10/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..3f8167866a26273b8cfbea5c35ea0223b4e9fb5e --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t10/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_net_revenue_usd_t10", + "depth": 3, + "family": "net_revenue_usd", + "params": { + "region": "APAC", + "category": "B", + "month_start": 202604, + "month_end": 202606 + }, + "question": "For orders in region APAC, category B, months 202604-202606: compute each order's net USD revenue after loyalty discount and refunds, then report the total net revenue in USD.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth3_net_revenue_usd_t10/instruction.md b/harbor/tasks/v3_depth3_net_revenue_usd_t10/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..2061acab1205bf020344de85409a3d6ff51e2302 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t10/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 orders in region APAC, category B, months 202604-202606: compute each order's net USD revenue after loyalty discount and refunds, then report the total net revenue in USD. + +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_depth3_net_revenue_usd_t10/task.toml b/harbor/tasks/v3_depth3_net_revenue_usd_t10/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..4a3ea1f4f632f810d13b4dec1664f0c85cc3a005 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t10/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_net_revenue_usd_t10" +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 = 3 + +[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_depth3_net_revenue_usd_t10/tests/check_output_shape.py b/harbor/tasks/v3_depth3_net_revenue_usd_t10/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t10/tests/test.sh b/harbor/tasks/v3_depth3_net_revenue_usd_t10/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t11/environment/Dockerfile b/harbor/tasks/v3_depth3_net_revenue_usd_t11/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t11/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_net_revenue_usd_t11/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t11/environment/task.json b/harbor/tasks/v3_depth3_net_revenue_usd_t11/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..33b4dad5cfbe0d06910bb1c9119f2b9f14bed009 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t11/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_net_revenue_usd_t11", + "depth": 3, + "family": "net_revenue_usd", + "params": { + "region": "LATAM", + "category": "A", + "month_start": 202601, + "month_end": 202603 + }, + "question": "For orders in region LATAM, category A, months 202601-202603: compute each order's net USD revenue after loyalty discount and refunds, then report the total net revenue in USD.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth3_net_revenue_usd_t11/instruction.md b/harbor/tasks/v3_depth3_net_revenue_usd_t11/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..66a6a1cf2a7283960e7763f9492aa58de9152b53 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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 orders in region LATAM, category A, months 202601-202603: compute each order's net USD revenue after loyalty discount and refunds, then report the total net revenue in USD. + +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_depth3_net_revenue_usd_t11/task.toml b/harbor/tasks/v3_depth3_net_revenue_usd_t11/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..4b7b1dc4edc736e67568cb2f7f17da3d1037c07a --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t11/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_net_revenue_usd_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 = 3 + +[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_depth3_net_revenue_usd_t11/tests/check_output_shape.py b/harbor/tasks/v3_depth3_net_revenue_usd_t11/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t11/tests/test.sh b/harbor/tasks/v3_depth3_net_revenue_usd_t11/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t12/environment/Dockerfile b/harbor/tasks/v3_depth3_net_revenue_usd_t12/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t12/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_net_revenue_usd_t12/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t12/environment/task.json b/harbor/tasks/v3_depth3_net_revenue_usd_t12/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..cb148de403a11fed173c7ec54a56a6a8137b0be5 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t12/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_net_revenue_usd_t12", + "depth": 3, + "family": "net_revenue_usd", + "params": { + "region": "NA", + "category": "C", + "month_start": 202601, + "month_end": 202606 + }, + "question": "For orders in region NA, category C, months 202601-202606: compute each order's net USD revenue after loyalty discount and refunds, then report the total net revenue in USD.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth3_net_revenue_usd_t12/instruction.md b/harbor/tasks/v3_depth3_net_revenue_usd_t12/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0b10821f08ff3004db9a95d075151d29117ebe8b --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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 orders in region NA, category C, months 202601-202606: compute each order's net USD revenue after loyalty discount and refunds, then report the total net revenue in USD. + +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_depth3_net_revenue_usd_t12/task.toml b/harbor/tasks/v3_depth3_net_revenue_usd_t12/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..e45998f8be0d28e9590f79ee75c16bffd4e3d7f3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t12/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_net_revenue_usd_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 = 3 + +[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_depth3_net_revenue_usd_t12/tests/check_output_shape.py b/harbor/tasks/v3_depth3_net_revenue_usd_t12/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t12/tests/test.sh b/harbor/tasks/v3_depth3_net_revenue_usd_t12/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t13/environment/Dockerfile b/harbor/tasks/v3_depth3_net_revenue_usd_t13/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t13/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_net_revenue_usd_t13/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t13/environment/task.json b/harbor/tasks/v3_depth3_net_revenue_usd_t13/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..493900126365bc1a0daf671a1f6993b3186e7e2f --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t13/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_net_revenue_usd_t13", + "depth": 3, + "family": "net_revenue_usd", + "params": { + "region": "EU", + "category": "B", + "month_start": 202601, + "month_end": 202603 + }, + "question": "For orders in region EU, category B, months 202601-202603: compute each order's net USD revenue after loyalty discount and refunds, then report the total net revenue in USD.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth3_net_revenue_usd_t13/instruction.md b/harbor/tasks/v3_depth3_net_revenue_usd_t13/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..e12e5b8b88465829048cbf59b45cb2e0419528d1 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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 orders in region EU, category B, months 202601-202603: compute each order's net USD revenue after loyalty discount and refunds, then report the total net revenue in USD. + +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_depth3_net_revenue_usd_t13/task.toml b/harbor/tasks/v3_depth3_net_revenue_usd_t13/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..f119f61d04b575d2beef19a6376c96b4568ada8b --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t13/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_net_revenue_usd_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 = 3 + +[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_depth3_net_revenue_usd_t13/tests/check_output_shape.py b/harbor/tasks/v3_depth3_net_revenue_usd_t13/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t13/tests/test.sh b/harbor/tasks/v3_depth3_net_revenue_usd_t13/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t14/environment/Dockerfile b/harbor/tasks/v3_depth3_net_revenue_usd_t14/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t14/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_net_revenue_usd_t14/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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']