diff --git a/harbor/tasks/v3_depth3_net_revenue_usd_t14/environment/task.json b/harbor/tasks/v3_depth3_net_revenue_usd_t14/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..56c6b1e1dc14063ccdfb7baa75c956c7ae53faee --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t14/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_net_revenue_usd_t14", + "depth": 3, + "family": "net_revenue_usd", + "params": { + "region": "APAC", + "category": "C", + "month_start": 202602, + "month_end": 202606 + }, + "question": "For orders in region APAC, category C, months 202602-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_t14/instruction.md b/harbor/tasks/v3_depth3_net_revenue_usd_t14/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4544e2b38eee67681686bb00f767a86f01fc4a2f --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t14/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For orders in region APAC, category C, months 202602-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_t14/task.toml b/harbor/tasks/v3_depth3_net_revenue_usd_t14/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..130d1e8305f91bcd94de95edbf8751e3ca2b7b31 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t14/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_net_revenue_usd_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 = 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_t14/tests/check_output_shape.py b/harbor/tasks/v3_depth3_net_revenue_usd_t14/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t14/tests/test.sh b/harbor/tasks/v3_depth3_net_revenue_usd_t14/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t15/environment/Dockerfile b/harbor/tasks/v3_depth3_net_revenue_usd_t15/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t15/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_net_revenue_usd_t15/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t15/environment/task.json b/harbor/tasks/v3_depth3_net_revenue_usd_t15/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..f9614e6640f175e233209958a545c6f7de0cea33 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t15/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_net_revenue_usd_t15", + "depth": 3, + "family": "net_revenue_usd", + "params": { + "region": "LATAM", + "category": "D", + "month_start": 202601, + "month_end": 202605 + }, + "question": "For orders in region LATAM, category D, months 202601-202605: 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_t15/instruction.md b/harbor/tasks/v3_depth3_net_revenue_usd_t15/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0b8f80e84395a43d6c63a6cbf9d50f5ca4103fe9 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t15/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For orders in region LATAM, category D, months 202601-202605: 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_t15/task.toml b/harbor/tasks/v3_depth3_net_revenue_usd_t15/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..8d937f659470613621e47213d0853e3c31c43fd7 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t15/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_net_revenue_usd_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 = 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_t15/tests/check_output_shape.py b/harbor/tasks/v3_depth3_net_revenue_usd_t15/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t15/tests/test.sh b/harbor/tasks/v3_depth3_net_revenue_usd_t15/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t16/environment/Dockerfile b/harbor/tasks/v3_depth3_net_revenue_usd_t16/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t16/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_net_revenue_usd_t16/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t16/environment/task.json b/harbor/tasks/v3_depth3_net_revenue_usd_t16/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..ec79e3527c98186c556cbe716e77633c17077c0d --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t16/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_net_revenue_usd_t16", + "depth": 3, + "family": "net_revenue_usd", + "params": { + "region": "NA", + "category": "A", + "month_start": 202604, + "month_end": 202606 + }, + "question": "For orders in region NA, category A, 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_t16/instruction.md b/harbor/tasks/v3_depth3_net_revenue_usd_t16/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..80039cdf08fcfd15e9bb79d950f310da994aa41a --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t16/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For orders in region NA, category A, 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_t16/task.toml b/harbor/tasks/v3_depth3_net_revenue_usd_t16/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..ca160c42fb819c18bc4ebe425f98c18b10fda18e --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t16/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_net_revenue_usd_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 = 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_t16/tests/check_output_shape.py b/harbor/tasks/v3_depth3_net_revenue_usd_t16/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t16/tests/test.sh b/harbor/tasks/v3_depth3_net_revenue_usd_t16/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t17/environment/Dockerfile b/harbor/tasks/v3_depth3_net_revenue_usd_t17/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t17/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_net_revenue_usd_t17/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t17/environment/task.json b/harbor/tasks/v3_depth3_net_revenue_usd_t17/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..3cf6ce78a0df581ff8b5ad42a825084b607a5002 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t17/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_net_revenue_usd_t17", + "depth": 3, + "family": "net_revenue_usd", + "params": { + "region": "EU", + "category": "D", + "month_start": 202601, + "month_end": 202602 + }, + "question": "For orders in region EU, category D, months 202601-202602: 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_t17/instruction.md b/harbor/tasks/v3_depth3_net_revenue_usd_t17/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9aace038736dbbfdc79a48e896c883dd26815812 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t17/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For orders in region EU, category D, months 202601-202602: 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_t17/task.toml b/harbor/tasks/v3_depth3_net_revenue_usd_t17/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..0f3554375aaf1611409f8d9f9c22bafed44cebc0 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t17/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_net_revenue_usd_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 = 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_t17/tests/check_output_shape.py b/harbor/tasks/v3_depth3_net_revenue_usd_t17/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t17/tests/test.sh b/harbor/tasks/v3_depth3_net_revenue_usd_t17/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t18/environment/Dockerfile b/harbor/tasks/v3_depth3_net_revenue_usd_t18/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t18/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_net_revenue_usd_t18/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t18/environment/task.json b/harbor/tasks/v3_depth3_net_revenue_usd_t18/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..cb40d6147710c77869bed8a4e5509f1207294eef --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t18/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_net_revenue_usd_t18", + "depth": 3, + "family": "net_revenue_usd", + "params": { + "region": "APAC", + "category": "A", + "month_start": 202603, + "month_end": 202604 + }, + "question": "For orders in region APAC, category A, months 202603-202604: 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_t18/instruction.md b/harbor/tasks/v3_depth3_net_revenue_usd_t18/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..2b50a88775940c9341fdf0f732e7fbca2f1f6714 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t18/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For orders in region APAC, category A, months 202603-202604: 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_t18/task.toml b/harbor/tasks/v3_depth3_net_revenue_usd_t18/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..98b915279dc64930b184de8f2e993b8e6d366137 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t18/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_net_revenue_usd_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 = 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_t18/tests/check_output_shape.py b/harbor/tasks/v3_depth3_net_revenue_usd_t18/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t18/tests/test.sh b/harbor/tasks/v3_depth3_net_revenue_usd_t18/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t19/environment/Dockerfile b/harbor/tasks/v3_depth3_net_revenue_usd_t19/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t19/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_net_revenue_usd_t19/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t19/environment/task.json b/harbor/tasks/v3_depth3_net_revenue_usd_t19/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..ee1f44bfac348ebb89d4649094bf71dd854e7fa9 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t19/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_net_revenue_usd_t19", + "depth": 3, + "family": "net_revenue_usd", + "params": { + "region": "LATAM", + "category": "B", + "month_start": 202605, + "month_end": 202606 + }, + "question": "For orders in region LATAM, category B, months 202605-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_t19/instruction.md b/harbor/tasks/v3_depth3_net_revenue_usd_t19/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..6f121f357870f910b478d15e137ff8c4e2e68b90 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t19/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For orders in region LATAM, category B, months 202605-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_t19/task.toml b/harbor/tasks/v3_depth3_net_revenue_usd_t19/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..77c6b213b84841509945e4c20d233bfa322a3308 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t19/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_net_revenue_usd_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 = 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_t19/tests/check_output_shape.py b/harbor/tasks/v3_depth3_net_revenue_usd_t19/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t19/tests/test.sh b/harbor/tasks/v3_depth3_net_revenue_usd_t19/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t2/environment/Dockerfile b/harbor/tasks/v3_depth3_net_revenue_usd_t2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t2/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_net_revenue_usd_t2/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t2/environment/task.json b/harbor/tasks/v3_depth3_net_revenue_usd_t2/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..dec30d9135857f9587a4156e036e0be059049834 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t2/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_net_revenue_usd_t2", + "depth": 3, + "family": "net_revenue_usd", + "params": { + "region": "EU", + "category": "C", + "month_start": 202601, + "month_end": 202604 + }, + "question": "For orders in region EU, category C, months 202601-202604: 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_t2/instruction.md b/harbor/tasks/v3_depth3_net_revenue_usd_t2/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..e107933a1cfa559efa1a84c301e30b6d33b401c4 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t2/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For orders in region EU, category C, months 202601-202604: 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_t2/task.toml b/harbor/tasks/v3_depth3_net_revenue_usd_t2/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..5924ad63bd7db1bd3b6225663fb22a2eca55c1bc --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t2/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_net_revenue_usd_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 = 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_t2/tests/check_output_shape.py b/harbor/tasks/v3_depth3_net_revenue_usd_t2/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t2/tests/test.sh b/harbor/tasks/v3_depth3_net_revenue_usd_t2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t20/environment/Dockerfile b/harbor/tasks/v3_depth3_net_revenue_usd_t20/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t20/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_net_revenue_usd_t20/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t20/environment/task.json b/harbor/tasks/v3_depth3_net_revenue_usd_t20/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..d2a3c87d5e65b9aac0410529052039d8ba95b8e1 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t20/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_net_revenue_usd_t20", + "depth": 3, + "family": "net_revenue_usd", + "params": { + "region": "NA", + "category": "C", + "month_start": 202602, + "month_end": 202604 + }, + "question": "For orders in region NA, category C, months 202602-202604: 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_t20/instruction.md b/harbor/tasks/v3_depth3_net_revenue_usd_t20/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..792d6aebfe8d656151d0a525f48f1c31c6efd349 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t20/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For orders in region NA, category C, months 202602-202604: 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_t20/task.toml b/harbor/tasks/v3_depth3_net_revenue_usd_t20/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..fad16ca64380163a35f3c4712e1d57cd6ae8f70e --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t20/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_net_revenue_usd_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 = 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_t20/tests/check_output_shape.py b/harbor/tasks/v3_depth3_net_revenue_usd_t20/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t20/tests/test.sh b/harbor/tasks/v3_depth3_net_revenue_usd_t20/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t21/environment/Dockerfile b/harbor/tasks/v3_depth3_net_revenue_usd_t21/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t21/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_net_revenue_usd_t21/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t21/environment/task.json b/harbor/tasks/v3_depth3_net_revenue_usd_t21/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..c52b12547d002bf4b725f72f9bcbe15d1a7c501a --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t21/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_net_revenue_usd_t21", + "depth": 3, + "family": "net_revenue_usd", + "params": { + "region": "EU", + "category": "B", + "month_start": 202604, + "month_end": 202606 + }, + "question": "For orders in region EU, 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_t21/instruction.md b/harbor/tasks/v3_depth3_net_revenue_usd_t21/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..a882ce7eb09a68ebf84dd0eb4bed9d5b1c05c53c --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t21/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For orders in region EU, 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_t21/task.toml b/harbor/tasks/v3_depth3_net_revenue_usd_t21/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..4cdbc20efa4ee14c0a103efbc687cf986cf362fd --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t21/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_net_revenue_usd_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 = 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_t21/tests/check_output_shape.py b/harbor/tasks/v3_depth3_net_revenue_usd_t21/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t21/tests/test.sh b/harbor/tasks/v3_depth3_net_revenue_usd_t21/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t22/environment/Dockerfile b/harbor/tasks/v3_depth3_net_revenue_usd_t22/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t22/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_net_revenue_usd_t22/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t22/environment/task.json b/harbor/tasks/v3_depth3_net_revenue_usd_t22/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..e25017c5020040a01935bd700cfa44118ab8a77c --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t22/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_net_revenue_usd_t22", + "depth": 3, + "family": "net_revenue_usd", + "params": { + "region": "APAC", + "category": "D", + "month_start": 202603, + "month_end": 202605 + }, + "question": "For orders in region APAC, category D, months 202603-202605: 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_t22/instruction.md b/harbor/tasks/v3_depth3_net_revenue_usd_t22/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..420e3c42618377c4d259631effe1f2705bf86262 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t22/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For orders in region APAC, category D, months 202603-202605: 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_t22/task.toml b/harbor/tasks/v3_depth3_net_revenue_usd_t22/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..2b8d042f1a35b33ebb8a5e4b89ace20339280312 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t22/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_net_revenue_usd_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 = 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_t22/tests/check_output_shape.py b/harbor/tasks/v3_depth3_net_revenue_usd_t22/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t22/tests/test.sh b/harbor/tasks/v3_depth3_net_revenue_usd_t22/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t23/environment/Dockerfile b/harbor/tasks/v3_depth3_net_revenue_usd_t23/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t23/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_net_revenue_usd_t23/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t23/environment/task.json b/harbor/tasks/v3_depth3_net_revenue_usd_t23/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..618352997a05e86c7e9b9ed1b2194b0259ac48b7 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t23/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_net_revenue_usd_t23", + "depth": 3, + "family": "net_revenue_usd", + "params": { + "region": "LATAM", + "category": "C", + "month_start": 202601, + "month_end": 202602 + }, + "question": "For orders in region LATAM, category C, months 202601-202602: 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_t23/instruction.md b/harbor/tasks/v3_depth3_net_revenue_usd_t23/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..565e0d708da678e7f9b45079aa07283cb9fd7a0a --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t23/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For orders in region LATAM, category C, months 202601-202602: 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_t23/task.toml b/harbor/tasks/v3_depth3_net_revenue_usd_t23/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..1276ce8b0da91ad9f8b550e5dae369da1b2e4b27 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t23/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_net_revenue_usd_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 = 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_t23/tests/check_output_shape.py b/harbor/tasks/v3_depth3_net_revenue_usd_t23/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t23/tests/test.sh b/harbor/tasks/v3_depth3_net_revenue_usd_t23/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t24/environment/Dockerfile b/harbor/tasks/v3_depth3_net_revenue_usd_t24/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t24/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_net_revenue_usd_t24/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t24/environment/task.json b/harbor/tasks/v3_depth3_net_revenue_usd_t24/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..1950c844020162a361e99bf1f41baad108cea887 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t24/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_net_revenue_usd_t24", + "depth": 3, + "family": "net_revenue_usd", + "params": { + "region": "NA", + "category": "D", + "month_start": 202601, + "month_end": 202603 + }, + "question": "For orders in region NA, category D, 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_t24/instruction.md b/harbor/tasks/v3_depth3_net_revenue_usd_t24/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..a02c430a5b1f18a30191372d29da3828a812c955 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t24/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For orders in region NA, category D, 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_t24/task.toml b/harbor/tasks/v3_depth3_net_revenue_usd_t24/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..bab816ae91e9c12518c75080816f64e9cff99fa6 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t24/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_net_revenue_usd_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 = 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_t24/tests/check_output_shape.py b/harbor/tasks/v3_depth3_net_revenue_usd_t24/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t24/tests/test.sh b/harbor/tasks/v3_depth3_net_revenue_usd_t24/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t3/environment/Dockerfile b/harbor/tasks/v3_depth3_net_revenue_usd_t3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t3/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_net_revenue_usd_t3/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t3/environment/task.json b/harbor/tasks/v3_depth3_net_revenue_usd_t3/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..7346ee8f16acf1db056f6948bdeb441504611f71 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t3/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_net_revenue_usd_t3", + "depth": 3, + "family": "net_revenue_usd", + "params": { + "region": "EU", + "category": "D", + "month_start": 202603, + "month_end": 202606 + }, + "question": "For orders in region EU, category D, months 202603-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_t3/instruction.md b/harbor/tasks/v3_depth3_net_revenue_usd_t3/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..c93b3d3ec29b42a340bb674f59420e918bd50f87 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t3/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For orders in region EU, category D, months 202603-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_t3/task.toml b/harbor/tasks/v3_depth3_net_revenue_usd_t3/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..1e3352d9c0f6b8f361de01bb0f1199ded1103192 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t3/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_net_revenue_usd_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 = 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_t3/tests/check_output_shape.py b/harbor/tasks/v3_depth3_net_revenue_usd_t3/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t3/tests/test.sh b/harbor/tasks/v3_depth3_net_revenue_usd_t3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t4/environment/Dockerfile b/harbor/tasks/v3_depth3_net_revenue_usd_t4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t4/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_net_revenue_usd_t4/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t4/environment/task.json b/harbor/tasks/v3_depth3_net_revenue_usd_t4/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..1bd5b775a83af284655c783b090d94f5ae9fbe3a --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t4/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_net_revenue_usd_t4", + "depth": 3, + "family": "net_revenue_usd", + "params": { + "region": "APAC", + "category": "A", + "month_start": 202602, + "month_end": 202605 + }, + "question": "For orders in region APAC, category A, months 202602-202605: 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_t4/instruction.md b/harbor/tasks/v3_depth3_net_revenue_usd_t4/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..8928184d3e872cf728d97737cdb0897c52fb99dc --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t4/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For orders in region APAC, category A, months 202602-202605: 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_t4/task.toml b/harbor/tasks/v3_depth3_net_revenue_usd_t4/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..1f5e6ce55b48efc3824a0ae43d1e978a3485876c --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t4/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_net_revenue_usd_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 = 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_t4/tests/check_output_shape.py b/harbor/tasks/v3_depth3_net_revenue_usd_t4/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t4/tests/test.sh b/harbor/tasks/v3_depth3_net_revenue_usd_t4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t5/environment/Dockerfile b/harbor/tasks/v3_depth3_net_revenue_usd_t5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t5/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_net_revenue_usd_t5/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t5/environment/task.json b/harbor/tasks/v3_depth3_net_revenue_usd_t5/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..db6444c79e405be5b52f464016bf72d4ad2b8a77 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t5/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_net_revenue_usd_t5", + "depth": 3, + "family": "net_revenue_usd", + "params": { + "region": "APAC", + "category": "D", + "month_start": 202601, + "month_end": 202606 + }, + "question": "For orders in region APAC, category D, 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_t5/instruction.md b/harbor/tasks/v3_depth3_net_revenue_usd_t5/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..ff9cb316b6f35eff440e609b5a41efbad6f4e968 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t5/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For orders in region APAC, category D, 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_t5/task.toml b/harbor/tasks/v3_depth3_net_revenue_usd_t5/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..ea62e649b40a8fd3e32a360a0f583bbcb8dd9950 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t5/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_net_revenue_usd_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 = 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_t5/tests/check_output_shape.py b/harbor/tasks/v3_depth3_net_revenue_usd_t5/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t5/tests/test.sh b/harbor/tasks/v3_depth3_net_revenue_usd_t5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t6/environment/Dockerfile b/harbor/tasks/v3_depth3_net_revenue_usd_t6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t6/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_net_revenue_usd_t6/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t6/environment/task.json b/harbor/tasks/v3_depth3_net_revenue_usd_t6/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..9540de0bda7b53605a5426ac13936f5a5166c42b --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t6/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_net_revenue_usd_t6", + "depth": 3, + "family": "net_revenue_usd", + "params": { + "region": "LATAM", + "category": "B", + "month_start": 202601, + "month_end": 202604 + }, + "question": "For orders in region LATAM, category B, months 202601-202604: 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_t6/instruction.md b/harbor/tasks/v3_depth3_net_revenue_usd_t6/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..1f0664a9eb8f05ce9469dd23e63bb746f1ba291f --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t6/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For orders in region LATAM, category B, months 202601-202604: 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_t6/task.toml b/harbor/tasks/v3_depth3_net_revenue_usd_t6/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..4477b34847c8f8e34114518ae93bdb1b6c0b3ac1 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t6/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_net_revenue_usd_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 = 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_t6/tests/check_output_shape.py b/harbor/tasks/v3_depth3_net_revenue_usd_t6/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t6/tests/test.sh b/harbor/tasks/v3_depth3_net_revenue_usd_t6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t7/environment/Dockerfile b/harbor/tasks/v3_depth3_net_revenue_usd_t7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t7/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_net_revenue_usd_t7/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t7/environment/task.json b/harbor/tasks/v3_depth3_net_revenue_usd_t7/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..2e1846c6dc44bc9432beabc15c5b79ca11540ff4 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t7/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_net_revenue_usd_t7", + "depth": 3, + "family": "net_revenue_usd", + "params": { + "region": "LATAM", + "category": "C", + "month_start": 202603, + "month_end": 202606 + }, + "question": "For orders in region LATAM, category C, months 202603-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_t7/instruction.md b/harbor/tasks/v3_depth3_net_revenue_usd_t7/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..ae1f7929e350a8f14985ede73767f65ce122b6f5 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t7/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For orders in region LATAM, category C, months 202603-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_t7/task.toml b/harbor/tasks/v3_depth3_net_revenue_usd_t7/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..3e3fddc0073824d63ab7ec6ca1d095825b37b778 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t7/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_net_revenue_usd_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 = 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_t7/tests/check_output_shape.py b/harbor/tasks/v3_depth3_net_revenue_usd_t7/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t7/tests/test.sh b/harbor/tasks/v3_depth3_net_revenue_usd_t7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t8/environment/Dockerfile b/harbor/tasks/v3_depth3_net_revenue_usd_t8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t8/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_net_revenue_usd_t8/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t8/environment/task.json b/harbor/tasks/v3_depth3_net_revenue_usd_t8/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..578b25b36bcf85cb983657a6daa7a13b40c7084e --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t8/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_net_revenue_usd_t8", + "depth": 3, + "family": "net_revenue_usd", + "params": { + "region": "NA", + "category": "D", + "month_start": 202602, + "month_end": 202606 + }, + "question": "For orders in region NA, category D, months 202602-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_t8/instruction.md b/harbor/tasks/v3_depth3_net_revenue_usd_t8/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..d17fdf02036d3271ee884082c98605972f05c2d0 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t8/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For orders in region NA, category D, months 202602-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_t8/task.toml b/harbor/tasks/v3_depth3_net_revenue_usd_t8/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..979c2e5c932e024b450b5828d7ddc0f2204897d0 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t8/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_net_revenue_usd_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 = 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_t8/tests/check_output_shape.py b/harbor/tasks/v3_depth3_net_revenue_usd_t8/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t8/tests/test.sh b/harbor/tasks/v3_depth3_net_revenue_usd_t8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t9/environment/Dockerfile b/harbor/tasks/v3_depth3_net_revenue_usd_t9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t9/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_net_revenue_usd_t9/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t9/environment/task.json b/harbor/tasks/v3_depth3_net_revenue_usd_t9/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..b1541c895e29bc9f39c71ebf8d8602b0329b73c2 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t9/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_net_revenue_usd_t9", + "depth": 3, + "family": "net_revenue_usd", + "params": { + "region": "EU", + "category": "A", + "month_start": 202602, + "month_end": 202605 + }, + "question": "For orders in region EU, category A, months 202602-202605: 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_t9/instruction.md b/harbor/tasks/v3_depth3_net_revenue_usd_t9/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..ded2d5a45c00abadf99a4f21d878114cf1cf15d9 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t9/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For orders in region EU, category A, months 202602-202605: 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_t9/task.toml b/harbor/tasks/v3_depth3_net_revenue_usd_t9/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..5bdc80d8b0f8e996b138baf6e01f8daeb3e049bc --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_t9/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_net_revenue_usd_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 = 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_t9/tests/check_output_shape.py b/harbor/tasks/v3_depth3_net_revenue_usd_t9/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_depth3_net_revenue_usd_t9/tests/test.sh b/harbor/tasks/v3_depth3_net_revenue_usd_t9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_net_revenue_usd_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_refund_share_bp_t0/environment/Dockerfile b/harbor/tasks/v3_depth3_refund_share_bp_t0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_refund_share_bp_t0/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_refund_share_bp_t0/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_refund_share_bp_t0/environment/task.json b/harbor/tasks/v3_depth3_refund_share_bp_t0/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..ea26343b3ba9df21945c5738064a367847df837b --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t0/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_refund_share_bp_t0", + "depth": 3, + "family": "refund_share_bp", + "params": { + "region": "NA", + "category": "A", + "month_start": 202601, + "month_end": 202603 + }, + "question": "For orders in region NA, category A, months 202601-202603: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth3_refund_share_bp_t0/instruction.md b/harbor/tasks/v3_depth3_refund_share_bp_t0/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4355186ff732d0d6da11b83cc462568b2b23ce49 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero. + +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_refund_share_bp_t0/task.toml b/harbor/tasks/v3_depth3_refund_share_bp_t0/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..4bb1264daac32b4d04bc918e52ce4567093341b2 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t0/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_refund_share_bp_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_refund_share_bp_t0/tests/check_output_shape.py b/harbor/tasks/v3_depth3_refund_share_bp_t0/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_refund_share_bp_t0/tests/test.sh b/harbor/tasks/v3_depth3_refund_share_bp_t0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_refund_share_bp_t1/environment/Dockerfile b/harbor/tasks/v3_depth3_refund_share_bp_t1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_refund_share_bp_t1/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_refund_share_bp_t1/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_refund_share_bp_t1/environment/task.json b/harbor/tasks/v3_depth3_refund_share_bp_t1/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..9b283cb63d0f649ef41b50362f4a8de68fdfdb29 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t1/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_refund_share_bp_t1", + "depth": 3, + "family": "refund_share_bp", + "params": { + "region": "NA", + "category": "B", + "month_start": 202604, + "month_end": 202606 + }, + "question": "For orders in region NA, category B, months 202604-202606: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth3_refund_share_bp_t1/instruction.md b/harbor/tasks/v3_depth3_refund_share_bp_t1/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..107d8f21d2a484cd60592ea798a22b83576d84d9 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero. + +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_refund_share_bp_t1/task.toml b/harbor/tasks/v3_depth3_refund_share_bp_t1/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..fdba7a2817c06a50b1514ed0ac8a1a723c646cfa --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t1/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_refund_share_bp_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_refund_share_bp_t1/tests/check_output_shape.py b/harbor/tasks/v3_depth3_refund_share_bp_t1/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_refund_share_bp_t1/tests/test.sh b/harbor/tasks/v3_depth3_refund_share_bp_t1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_refund_share_bp_t10/environment/Dockerfile b/harbor/tasks/v3_depth3_refund_share_bp_t10/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_refund_share_bp_t10/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_refund_share_bp_t10/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_refund_share_bp_t10/environment/task.json b/harbor/tasks/v3_depth3_refund_share_bp_t10/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..21b422f7e54db346fc3326341f1861c4dfbb5698 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t10/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_refund_share_bp_t10", + "depth": 3, + "family": "refund_share_bp", + "params": { + "region": "APAC", + "category": "B", + "month_start": 202604, + "month_end": 202606 + }, + "question": "For orders in region APAC, category B, months 202604-202606: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth3_refund_share_bp_t10/instruction.md b/harbor/tasks/v3_depth3_refund_share_bp_t10/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..aa66fa49cc41dcd6752ec53d8094db933dfd2150 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero. + +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_refund_share_bp_t10/task.toml b/harbor/tasks/v3_depth3_refund_share_bp_t10/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..4567bc6efd86062aaf6db20135bb53eeb7e8a4e7 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t10/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_refund_share_bp_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_refund_share_bp_t10/tests/check_output_shape.py b/harbor/tasks/v3_depth3_refund_share_bp_t10/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_refund_share_bp_t10/tests/test.sh b/harbor/tasks/v3_depth3_refund_share_bp_t10/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_refund_share_bp_t11/environment/Dockerfile b/harbor/tasks/v3_depth3_refund_share_bp_t11/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_refund_share_bp_t11/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_refund_share_bp_t11/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_refund_share_bp_t11/environment/task.json b/harbor/tasks/v3_depth3_refund_share_bp_t11/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..1e5d318813eaa32071a79d46396d53c43dc84d66 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t11/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_refund_share_bp_t11", + "depth": 3, + "family": "refund_share_bp", + "params": { + "region": "LATAM", + "category": "A", + "month_start": 202601, + "month_end": 202603 + }, + "question": "For orders in region LATAM, category A, months 202601-202603: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth3_refund_share_bp_t11/instruction.md b/harbor/tasks/v3_depth3_refund_share_bp_t11/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..03c3155f8afbfba448fd5f3b672dff4b3224b720 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero. + +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_refund_share_bp_t11/task.toml b/harbor/tasks/v3_depth3_refund_share_bp_t11/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..0eb67dc653473aa6c1243cb823394d6b5cb20655 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t11/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_refund_share_bp_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_refund_share_bp_t11/tests/check_output_shape.py b/harbor/tasks/v3_depth3_refund_share_bp_t11/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_refund_share_bp_t11/tests/test.sh b/harbor/tasks/v3_depth3_refund_share_bp_t11/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_refund_share_bp_t12/environment/Dockerfile b/harbor/tasks/v3_depth3_refund_share_bp_t12/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_refund_share_bp_t12/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_refund_share_bp_t12/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_refund_share_bp_t12/environment/task.json b/harbor/tasks/v3_depth3_refund_share_bp_t12/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..a332a59a7b2aa9cc5e54f4faec1c35824e02b73e --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t12/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_refund_share_bp_t12", + "depth": 3, + "family": "refund_share_bp", + "params": { + "region": "NA", + "category": "C", + "month_start": 202601, + "month_end": 202606 + }, + "question": "For orders in region NA, category C, months 202601-202606: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth3_refund_share_bp_t12/instruction.md b/harbor/tasks/v3_depth3_refund_share_bp_t12/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..077af41506bfd375e5018a3b78547916ca32cda8 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero. + +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_refund_share_bp_t12/task.toml b/harbor/tasks/v3_depth3_refund_share_bp_t12/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..6d7aee12889bafe44065a97247c6e53a422737b5 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t12/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_refund_share_bp_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_refund_share_bp_t12/tests/check_output_shape.py b/harbor/tasks/v3_depth3_refund_share_bp_t12/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_refund_share_bp_t12/tests/test.sh b/harbor/tasks/v3_depth3_refund_share_bp_t12/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_refund_share_bp_t13/environment/Dockerfile b/harbor/tasks/v3_depth3_refund_share_bp_t13/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_refund_share_bp_t13/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_refund_share_bp_t13/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_refund_share_bp_t13/environment/task.json b/harbor/tasks/v3_depth3_refund_share_bp_t13/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..2eab7d80c510e4bed9983d02295d699098b3417a --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t13/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_refund_share_bp_t13", + "depth": 3, + "family": "refund_share_bp", + "params": { + "region": "EU", + "category": "B", + "month_start": 202601, + "month_end": 202603 + }, + "question": "For orders in region EU, category B, months 202601-202603: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth3_refund_share_bp_t13/instruction.md b/harbor/tasks/v3_depth3_refund_share_bp_t13/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..7c5e21e3cf911e754187e126f01cee14bdabc56a --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero. + +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_refund_share_bp_t13/task.toml b/harbor/tasks/v3_depth3_refund_share_bp_t13/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..67cf940b61d1b23373842bd523ec70ab96fb87a4 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t13/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_refund_share_bp_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_refund_share_bp_t13/tests/check_output_shape.py b/harbor/tasks/v3_depth3_refund_share_bp_t13/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_refund_share_bp_t13/tests/test.sh b/harbor/tasks/v3_depth3_refund_share_bp_t13/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_refund_share_bp_t14/environment/Dockerfile b/harbor/tasks/v3_depth3_refund_share_bp_t14/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_refund_share_bp_t14/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_refund_share_bp_t14/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t14/environment/task.json b/harbor/tasks/v3_depth3_refund_share_bp_t14/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..ec47b4d0fcb13403f14fbd41ac20e4918f40f396 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t14/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_refund_share_bp_t14", + "depth": 3, + "family": "refund_share_bp", + "params": { + "region": "APAC", + "category": "C", + "month_start": 202602, + "month_end": 202606 + }, + "question": "For orders in region APAC, category C, months 202602-202606: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth3_refund_share_bp_t14/instruction.md b/harbor/tasks/v3_depth3_refund_share_bp_t14/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..5b7ad9fe05e4c4abca2c10e714a1e172fb047d96 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t14/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For orders in region APAC, category C, months 202602-202606: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero. + +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_refund_share_bp_t14/task.toml b/harbor/tasks/v3_depth3_refund_share_bp_t14/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..66e5f3ce14e5ae7e6dd7b699465dd9aefd009233 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t14/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_refund_share_bp_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 = 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_refund_share_bp_t14/tests/check_output_shape.py b/harbor/tasks/v3_depth3_refund_share_bp_t14/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t14/tests/test.sh b/harbor/tasks/v3_depth3_refund_share_bp_t14/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t15/environment/Dockerfile b/harbor/tasks/v3_depth3_refund_share_bp_t15/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t15/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_refund_share_bp_t15/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t15/environment/task.json b/harbor/tasks/v3_depth3_refund_share_bp_t15/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..328565b282479976cdcc749549ff351987ff0e86 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t15/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_refund_share_bp_t15", + "depth": 3, + "family": "refund_share_bp", + "params": { + "region": "LATAM", + "category": "D", + "month_start": 202601, + "month_end": 202605 + }, + "question": "For orders in region LATAM, category D, months 202601-202605: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth3_refund_share_bp_t15/instruction.md b/harbor/tasks/v3_depth3_refund_share_bp_t15/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..41d42406f4e28e70863c73b54cea316499447a51 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t15/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For orders in region LATAM, category D, months 202601-202605: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero. + +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_refund_share_bp_t15/task.toml b/harbor/tasks/v3_depth3_refund_share_bp_t15/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..5ab988b4216908e8636ae2a5f5c2addc5802d5b9 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t15/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_refund_share_bp_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 = 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_refund_share_bp_t15/tests/check_output_shape.py b/harbor/tasks/v3_depth3_refund_share_bp_t15/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t15/tests/test.sh b/harbor/tasks/v3_depth3_refund_share_bp_t15/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t16/environment/Dockerfile b/harbor/tasks/v3_depth3_refund_share_bp_t16/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t16/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_refund_share_bp_t16/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t16/environment/task.json b/harbor/tasks/v3_depth3_refund_share_bp_t16/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..e84ecc52a8e6bc64cbc2e7b86ba4e7b187281635 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t16/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_refund_share_bp_t16", + "depth": 3, + "family": "refund_share_bp", + "params": { + "region": "NA", + "category": "A", + "month_start": 202604, + "month_end": 202606 + }, + "question": "For orders in region NA, category A, months 202604-202606: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth3_refund_share_bp_t16/instruction.md b/harbor/tasks/v3_depth3_refund_share_bp_t16/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..526f22feba91180b7e494d40f40675f3e3e9ad67 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t16/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For orders in region NA, category A, months 202604-202606: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero. + +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_refund_share_bp_t16/task.toml b/harbor/tasks/v3_depth3_refund_share_bp_t16/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..c56d981955579819900b518af436775ec0f5efba --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t16/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_refund_share_bp_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 = 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_refund_share_bp_t16/tests/check_output_shape.py b/harbor/tasks/v3_depth3_refund_share_bp_t16/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t16/tests/test.sh b/harbor/tasks/v3_depth3_refund_share_bp_t16/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t17/environment/Dockerfile b/harbor/tasks/v3_depth3_refund_share_bp_t17/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t17/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_refund_share_bp_t17/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t17/environment/task.json b/harbor/tasks/v3_depth3_refund_share_bp_t17/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..7ed16f376e0f4aa7b4b38735ceda165078fd9671 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t17/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_refund_share_bp_t17", + "depth": 3, + "family": "refund_share_bp", + "params": { + "region": "EU", + "category": "D", + "month_start": 202601, + "month_end": 202602 + }, + "question": "For orders in region EU, category D, months 202601-202602: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth3_refund_share_bp_t17/instruction.md b/harbor/tasks/v3_depth3_refund_share_bp_t17/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..2f2efa99eef66cb5efa9b36158e35c47cbf448f0 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t17/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For orders in region EU, category D, months 202601-202602: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero. + +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_refund_share_bp_t17/task.toml b/harbor/tasks/v3_depth3_refund_share_bp_t17/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..1950bb1355214c85ee8636c9d0b3f2331adebcb4 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t17/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_refund_share_bp_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 = 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_refund_share_bp_t17/tests/check_output_shape.py b/harbor/tasks/v3_depth3_refund_share_bp_t17/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t17/tests/test.sh b/harbor/tasks/v3_depth3_refund_share_bp_t17/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t18/environment/Dockerfile b/harbor/tasks/v3_depth3_refund_share_bp_t18/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t18/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_refund_share_bp_t18/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t18/environment/task.json b/harbor/tasks/v3_depth3_refund_share_bp_t18/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..979b0d86698ee6f8ae83d9b4ad94301d28001811 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t18/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_refund_share_bp_t18", + "depth": 3, + "family": "refund_share_bp", + "params": { + "region": "APAC", + "category": "A", + "month_start": 202603, + "month_end": 202604 + }, + "question": "For orders in region APAC, category A, months 202603-202604: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth3_refund_share_bp_t18/instruction.md b/harbor/tasks/v3_depth3_refund_share_bp_t18/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..7507c0cf0ee178697a3806a60bd963cf5f346c1e --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t18/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For orders in region APAC, category A, months 202603-202604: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero. + +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_refund_share_bp_t18/task.toml b/harbor/tasks/v3_depth3_refund_share_bp_t18/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..238e51f722f5932d8c39d0eaf5f219f18cdbf6ac --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t18/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_refund_share_bp_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 = 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_refund_share_bp_t18/tests/check_output_shape.py b/harbor/tasks/v3_depth3_refund_share_bp_t18/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t18/tests/test.sh b/harbor/tasks/v3_depth3_refund_share_bp_t18/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t19/environment/Dockerfile b/harbor/tasks/v3_depth3_refund_share_bp_t19/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t19/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_refund_share_bp_t19/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t19/environment/task.json b/harbor/tasks/v3_depth3_refund_share_bp_t19/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..37585c17a80799a82d1edda00ebed159f0414835 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t19/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_refund_share_bp_t19", + "depth": 3, + "family": "refund_share_bp", + "params": { + "region": "LATAM", + "category": "B", + "month_start": 202605, + "month_end": 202606 + }, + "question": "For orders in region LATAM, category B, months 202605-202606: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth3_refund_share_bp_t19/instruction.md b/harbor/tasks/v3_depth3_refund_share_bp_t19/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..e3ef18d7d80f0b55deffaa11613d62b9cb4e3442 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t19/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For orders in region LATAM, category B, months 202605-202606: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero. + +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_refund_share_bp_t19/task.toml b/harbor/tasks/v3_depth3_refund_share_bp_t19/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..541d1d617b2bf5a14f7dbe5d55c5e0d8ba011f5e --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t19/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_refund_share_bp_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 = 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_refund_share_bp_t19/tests/check_output_shape.py b/harbor/tasks/v3_depth3_refund_share_bp_t19/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t19/tests/test.sh b/harbor/tasks/v3_depth3_refund_share_bp_t19/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t2/environment/Dockerfile b/harbor/tasks/v3_depth3_refund_share_bp_t2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t2/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_refund_share_bp_t2/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t2/environment/task.json b/harbor/tasks/v3_depth3_refund_share_bp_t2/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..a7dbe22ee45685569bde1a6f5e9c1ad13b48a78f --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t2/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_refund_share_bp_t2", + "depth": 3, + "family": "refund_share_bp", + "params": { + "region": "EU", + "category": "C", + "month_start": 202601, + "month_end": 202604 + }, + "question": "For orders in region EU, category C, months 202601-202604: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth3_refund_share_bp_t2/instruction.md b/harbor/tasks/v3_depth3_refund_share_bp_t2/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..ceab9bd2e66ff00c24f0f3528c7e4c7118a555e5 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t2/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For orders in region EU, category C, months 202601-202604: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero. + +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_refund_share_bp_t2/task.toml b/harbor/tasks/v3_depth3_refund_share_bp_t2/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..19ec0185abab54496217b603403c93396ebf01b9 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t2/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_refund_share_bp_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 = 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_refund_share_bp_t2/tests/check_output_shape.py b/harbor/tasks/v3_depth3_refund_share_bp_t2/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t2/tests/test.sh b/harbor/tasks/v3_depth3_refund_share_bp_t2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t20/environment/Dockerfile b/harbor/tasks/v3_depth3_refund_share_bp_t20/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t20/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_refund_share_bp_t20/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t20/environment/task.json b/harbor/tasks/v3_depth3_refund_share_bp_t20/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..ece63e60387e718102552ac2ab489e606f46a218 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t20/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_refund_share_bp_t20", + "depth": 3, + "family": "refund_share_bp", + "params": { + "region": "NA", + "category": "C", + "month_start": 202602, + "month_end": 202604 + }, + "question": "For orders in region NA, category C, months 202602-202604: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth3_refund_share_bp_t20/instruction.md b/harbor/tasks/v3_depth3_refund_share_bp_t20/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..3adbd862a9dacd801604af1cbf2bcf2992b6eb1a --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t20/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For orders in region NA, category C, months 202602-202604: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero. + +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_refund_share_bp_t20/task.toml b/harbor/tasks/v3_depth3_refund_share_bp_t20/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..e58ee613689bb8e7ee2778937d4647c2dc42af38 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t20/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_refund_share_bp_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 = 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_refund_share_bp_t20/tests/check_output_shape.py b/harbor/tasks/v3_depth3_refund_share_bp_t20/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t20/tests/test.sh b/harbor/tasks/v3_depth3_refund_share_bp_t20/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t21/environment/Dockerfile b/harbor/tasks/v3_depth3_refund_share_bp_t21/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t21/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_refund_share_bp_t21/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t21/environment/task.json b/harbor/tasks/v3_depth3_refund_share_bp_t21/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..02f575bde4008cf0b892a2eafc7e7d5038359706 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t21/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_refund_share_bp_t21", + "depth": 3, + "family": "refund_share_bp", + "params": { + "region": "EU", + "category": "B", + "month_start": 202604, + "month_end": 202606 + }, + "question": "For orders in region EU, category B, months 202604-202606: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth3_refund_share_bp_t21/instruction.md b/harbor/tasks/v3_depth3_refund_share_bp_t21/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..385ea2655528569db121aba2fa6b432bb38cad46 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t21/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For orders in region EU, category B, months 202604-202606: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero. + +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_refund_share_bp_t21/task.toml b/harbor/tasks/v3_depth3_refund_share_bp_t21/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..45801c23c7f51b5c115bc6d33abf963d1e860962 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t21/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_refund_share_bp_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 = 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_refund_share_bp_t21/tests/check_output_shape.py b/harbor/tasks/v3_depth3_refund_share_bp_t21/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t21/tests/test.sh b/harbor/tasks/v3_depth3_refund_share_bp_t21/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t22/environment/Dockerfile b/harbor/tasks/v3_depth3_refund_share_bp_t22/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t22/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_refund_share_bp_t22/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t22/environment/task.json b/harbor/tasks/v3_depth3_refund_share_bp_t22/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..635cff9414e7dac88f9acf54b5f15907899ee7b4 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t22/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_refund_share_bp_t22", + "depth": 3, + "family": "refund_share_bp", + "params": { + "region": "APAC", + "category": "D", + "month_start": 202603, + "month_end": 202605 + }, + "question": "For orders in region APAC, category D, months 202603-202605: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth3_refund_share_bp_t22/instruction.md b/harbor/tasks/v3_depth3_refund_share_bp_t22/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..3ce9d44e13b28cc1008de27f884a95d450b14b5f --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t22/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For orders in region APAC, category D, months 202603-202605: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero. + +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_refund_share_bp_t22/task.toml b/harbor/tasks/v3_depth3_refund_share_bp_t22/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..21a023f3d6c1e1e1a5557f407b7947ef9d1bdc6a --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t22/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_refund_share_bp_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 = 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_refund_share_bp_t22/tests/check_output_shape.py b/harbor/tasks/v3_depth3_refund_share_bp_t22/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t22/tests/test.sh b/harbor/tasks/v3_depth3_refund_share_bp_t22/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t23/environment/Dockerfile b/harbor/tasks/v3_depth3_refund_share_bp_t23/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t23/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_refund_share_bp_t23/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t23/environment/task.json b/harbor/tasks/v3_depth3_refund_share_bp_t23/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..7272fd9343e1514b0d421994a71d7b42198f9826 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t23/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_refund_share_bp_t23", + "depth": 3, + "family": "refund_share_bp", + "params": { + "region": "LATAM", + "category": "C", + "month_start": 202601, + "month_end": 202602 + }, + "question": "For orders in region LATAM, category C, months 202601-202602: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth3_refund_share_bp_t23/instruction.md b/harbor/tasks/v3_depth3_refund_share_bp_t23/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..2df1cef968c2d00e4e92207be85337d891a11555 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t23/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For orders in region LATAM, category C, months 202601-202602: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero. + +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_refund_share_bp_t23/task.toml b/harbor/tasks/v3_depth3_refund_share_bp_t23/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..482ae871257e1cf36be5459b364051c22d3f39bb --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t23/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_refund_share_bp_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 = 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_refund_share_bp_t23/tests/check_output_shape.py b/harbor/tasks/v3_depth3_refund_share_bp_t23/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t23/tests/test.sh b/harbor/tasks/v3_depth3_refund_share_bp_t23/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t24/environment/Dockerfile b/harbor/tasks/v3_depth3_refund_share_bp_t24/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t24/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_refund_share_bp_t24/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t24/environment/task.json b/harbor/tasks/v3_depth3_refund_share_bp_t24/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..fb77b509453b5d4275738573957a729de98ab378 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t24/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_refund_share_bp_t24", + "depth": 3, + "family": "refund_share_bp", + "params": { + "region": "NA", + "category": "D", + "month_start": 202601, + "month_end": 202603 + }, + "question": "For orders in region NA, category D, months 202601-202603: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth3_refund_share_bp_t24/instruction.md b/harbor/tasks/v3_depth3_refund_share_bp_t24/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..cf0bd21b923df862117e666d3d9cee310ee5ac5d --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t24/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For orders in region NA, category D, months 202601-202603: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero. + +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_refund_share_bp_t24/task.toml b/harbor/tasks/v3_depth3_refund_share_bp_t24/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..5b0194d300690a2779339c11955d6f306f1ed1ca --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t24/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_refund_share_bp_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 = 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_refund_share_bp_t24/tests/check_output_shape.py b/harbor/tasks/v3_depth3_refund_share_bp_t24/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t24/tests/test.sh b/harbor/tasks/v3_depth3_refund_share_bp_t24/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t3/environment/Dockerfile b/harbor/tasks/v3_depth3_refund_share_bp_t3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t3/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_refund_share_bp_t3/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t3/environment/task.json b/harbor/tasks/v3_depth3_refund_share_bp_t3/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..135163b62c834f9dc9ed5a38f9558fcd1568d70c --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t3/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_refund_share_bp_t3", + "depth": 3, + "family": "refund_share_bp", + "params": { + "region": "EU", + "category": "D", + "month_start": 202603, + "month_end": 202606 + }, + "question": "For orders in region EU, category D, months 202603-202606: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth3_refund_share_bp_t3/instruction.md b/harbor/tasks/v3_depth3_refund_share_bp_t3/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..6592ca3fb877380c9787121d9e546dee74e39f6a --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t3/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For orders in region EU, category D, months 202603-202606: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero. + +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_refund_share_bp_t3/task.toml b/harbor/tasks/v3_depth3_refund_share_bp_t3/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..435cc73df129347903e35acbe49e2be0f2f20701 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t3/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_refund_share_bp_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 = 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_refund_share_bp_t3/tests/check_output_shape.py b/harbor/tasks/v3_depth3_refund_share_bp_t3/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t3/tests/test.sh b/harbor/tasks/v3_depth3_refund_share_bp_t3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t4/environment/Dockerfile b/harbor/tasks/v3_depth3_refund_share_bp_t4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t4/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_refund_share_bp_t4/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t4/environment/task.json b/harbor/tasks/v3_depth3_refund_share_bp_t4/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..b433bd984a36fea52b2630a11437965c12312e24 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t4/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_refund_share_bp_t4", + "depth": 3, + "family": "refund_share_bp", + "params": { + "region": "APAC", + "category": "A", + "month_start": 202602, + "month_end": 202605 + }, + "question": "For orders in region APAC, category A, months 202602-202605: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth3_refund_share_bp_t4/instruction.md b/harbor/tasks/v3_depth3_refund_share_bp_t4/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..725fd3c2be59e6ed7f4439b2450d8bc752667b29 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t4/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For orders in region APAC, category A, months 202602-202605: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero. + +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_refund_share_bp_t4/task.toml b/harbor/tasks/v3_depth3_refund_share_bp_t4/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..5e6604a83fb47d02bc475a553e4036bc10a89b5c --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t4/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_refund_share_bp_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 = 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_refund_share_bp_t4/tests/check_output_shape.py b/harbor/tasks/v3_depth3_refund_share_bp_t4/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t4/tests/test.sh b/harbor/tasks/v3_depth3_refund_share_bp_t4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t5/environment/Dockerfile b/harbor/tasks/v3_depth3_refund_share_bp_t5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t5/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_refund_share_bp_t5/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t5/environment/task.json b/harbor/tasks/v3_depth3_refund_share_bp_t5/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..e99fd41a7174f1f2353405aac585bdd88c7321ce --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t5/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_refund_share_bp_t5", + "depth": 3, + "family": "refund_share_bp", + "params": { + "region": "APAC", + "category": "D", + "month_start": 202601, + "month_end": 202606 + }, + "question": "For orders in region APAC, category D, months 202601-202606: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth3_refund_share_bp_t5/instruction.md b/harbor/tasks/v3_depth3_refund_share_bp_t5/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..8a290b2d87bce3f773b15fe755c39f522c77ed9a --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t5/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For orders in region APAC, category D, months 202601-202606: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero. + +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_refund_share_bp_t5/task.toml b/harbor/tasks/v3_depth3_refund_share_bp_t5/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..e9ad4d94148d93efd5858ca22592bf543b003fec --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t5/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_refund_share_bp_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 = 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_refund_share_bp_t5/tests/check_output_shape.py b/harbor/tasks/v3_depth3_refund_share_bp_t5/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t5/tests/test.sh b/harbor/tasks/v3_depth3_refund_share_bp_t5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t6/environment/Dockerfile b/harbor/tasks/v3_depth3_refund_share_bp_t6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t6/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_refund_share_bp_t6/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t6/environment/task.json b/harbor/tasks/v3_depth3_refund_share_bp_t6/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..fae986134ec36a23de72d5730e82e00731174ed9 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t6/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_refund_share_bp_t6", + "depth": 3, + "family": "refund_share_bp", + "params": { + "region": "LATAM", + "category": "B", + "month_start": 202601, + "month_end": 202604 + }, + "question": "For orders in region LATAM, category B, months 202601-202604: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth3_refund_share_bp_t6/instruction.md b/harbor/tasks/v3_depth3_refund_share_bp_t6/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..e7228d2f818b9e7f22f4192270d972b22c68c6f3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t6/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For orders in region LATAM, category B, months 202601-202604: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero. + +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_refund_share_bp_t6/task.toml b/harbor/tasks/v3_depth3_refund_share_bp_t6/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..e950b308444a4d9adeddac067b4fb40bd032ceea --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t6/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_refund_share_bp_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 = 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_refund_share_bp_t6/tests/check_output_shape.py b/harbor/tasks/v3_depth3_refund_share_bp_t6/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t6/tests/test.sh b/harbor/tasks/v3_depth3_refund_share_bp_t6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t7/environment/Dockerfile b/harbor/tasks/v3_depth3_refund_share_bp_t7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t7/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_refund_share_bp_t7/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t7/environment/task.json b/harbor/tasks/v3_depth3_refund_share_bp_t7/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..82624cd1f03fe25a2cf635d05ad530dbf290da5b --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t7/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_refund_share_bp_t7", + "depth": 3, + "family": "refund_share_bp", + "params": { + "region": "LATAM", + "category": "C", + "month_start": 202603, + "month_end": 202606 + }, + "question": "For orders in region LATAM, category C, months 202603-202606: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth3_refund_share_bp_t7/instruction.md b/harbor/tasks/v3_depth3_refund_share_bp_t7/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..3e7ff3197bc26de8732022693e283788f50e5005 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t7/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For orders in region LATAM, category C, months 202603-202606: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero. + +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_refund_share_bp_t7/task.toml b/harbor/tasks/v3_depth3_refund_share_bp_t7/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..5bfaeb7f787a6c3c97258245f7c097a986718da2 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t7/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_refund_share_bp_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 = 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_refund_share_bp_t7/tests/check_output_shape.py b/harbor/tasks/v3_depth3_refund_share_bp_t7/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t7/tests/test.sh b/harbor/tasks/v3_depth3_refund_share_bp_t7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t8/environment/Dockerfile b/harbor/tasks/v3_depth3_refund_share_bp_t8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t8/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_refund_share_bp_t8/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t8/environment/task.json b/harbor/tasks/v3_depth3_refund_share_bp_t8/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..efb57d08d64a80a4f55d9cd9a4aede56b85fdbd1 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t8/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_refund_share_bp_t8", + "depth": 3, + "family": "refund_share_bp", + "params": { + "region": "NA", + "category": "D", + "month_start": 202602, + "month_end": 202606 + }, + "question": "For orders in region NA, category D, months 202602-202606: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth3_refund_share_bp_t8/instruction.md b/harbor/tasks/v3_depth3_refund_share_bp_t8/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9945bc23c61332e9bccf969b05744b00b02f8f3b --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t8/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For orders in region NA, category D, months 202602-202606: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero. + +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_refund_share_bp_t8/task.toml b/harbor/tasks/v3_depth3_refund_share_bp_t8/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..eb5d836b660ec64474b01b6dc3b79be793e85a78 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t8/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_refund_share_bp_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 = 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_refund_share_bp_t8/tests/check_output_shape.py b/harbor/tasks/v3_depth3_refund_share_bp_t8/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t8/tests/test.sh b/harbor/tasks/v3_depth3_refund_share_bp_t8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t9/environment/Dockerfile b/harbor/tasks/v3_depth3_refund_share_bp_t9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t9/environment/flowbench_tools.py b/harbor/tasks/v3_depth3_refund_share_bp_t9/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t9/environment/task.json b/harbor/tasks/v3_depth3_refund_share_bp_t9/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..cbc9c5ee2f3d0d1b91943a1aa308c3c783fcf545 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t9/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth3_refund_share_bp_t9", + "depth": 3, + "family": "refund_share_bp", + "params": { + "region": "EU", + "category": "A", + "month_start": 202602, + "month_end": 202605 + }, + "question": "For orders in region EU, category A, months 202602-202605: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth3_refund_share_bp_t9/instruction.md b/harbor/tasks/v3_depth3_refund_share_bp_t9/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..8111d44f19c3c6ff745f2ea961f5420e5a59e704 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t9/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For orders in region EU, category A, months 202602-202605: sum gross USD revenue and refund USD amounts, then report the refund share in basis points as floor(refunds * 10000 / gross). Report 0 if gross is zero. + +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_refund_share_bp_t9/task.toml b/harbor/tasks/v3_depth3_refund_share_bp_t9/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..23cc2ad352b430d5dfb5d07d0e93bd4f5f8c3ae6 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_t9/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth3_refund_share_bp_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 = 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_refund_share_bp_t9/tests/check_output_shape.py b/harbor/tasks/v3_depth3_refund_share_bp_t9/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth3_refund_share_bp_t9/tests/test.sh b/harbor/tasks/v3_depth3_refund_share_bp_t9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth3_refund_share_bp_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_depth4_local_net_revenue_t0/environment/Dockerfile b/harbor/tasks/v3_depth4_local_net_revenue_t0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t0/environment/flowbench_tools.py b/harbor/tasks/v3_depth4_local_net_revenue_t0/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t0/environment/task.json b/harbor/tasks/v3_depth4_local_net_revenue_t0/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..206ca704e23481d469d5e0a57f971fcf13191671 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_t0/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth4_local_net_revenue_t0", + "depth": 4, + "family": "local_net_revenue", + "params": { + "region": "NA", + "category": "A", + "month_start": 202601, + "month_end": 202603 + }, + "question": "For orders in region NA, category A, months 202601-202603: sum net USD revenue after loyalty discounts and refunds, then convert the total into the region's local currency. Report the integer local-currency amount.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth4_local_net_revenue_t0/instruction.md b/harbor/tasks/v3_depth4_local_net_revenue_t0/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..c3d988005bcbc5eed497cced84a25574032155e1 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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: sum net USD revenue after loyalty discounts and refunds, then convert the total into the region's local currency. Report the integer local-currency amount. + +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_depth4_local_net_revenue_t0/task.toml b/harbor/tasks/v3_depth4_local_net_revenue_t0/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..434b2cb841625c377ce37c34df2fdcbdb3acaac6 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_t0/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth4_local_net_revenue_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 = 4 + +[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_depth4_local_net_revenue_t0/tests/check_output_shape.py b/harbor/tasks/v3_depth4_local_net_revenue_t0/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t0/tests/test.sh b/harbor/tasks/v3_depth4_local_net_revenue_t0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t1/environment/Dockerfile b/harbor/tasks/v3_depth4_local_net_revenue_t1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t1/environment/flowbench_tools.py b/harbor/tasks/v3_depth4_local_net_revenue_t1/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t1/environment/task.json b/harbor/tasks/v3_depth4_local_net_revenue_t1/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..1694e2acf56d0f0221553bfde95a264454b886db --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_t1/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth4_local_net_revenue_t1", + "depth": 4, + "family": "local_net_revenue", + "params": { + "region": "NA", + "category": "B", + "month_start": 202604, + "month_end": 202606 + }, + "question": "For orders in region NA, category B, months 202604-202606: sum net USD revenue after loyalty discounts and refunds, then convert the total into the region's local currency. Report the integer local-currency amount.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth4_local_net_revenue_t1/instruction.md b/harbor/tasks/v3_depth4_local_net_revenue_t1/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..eb1df3bd50e1916a731577f433e2325872a24bee --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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: sum net USD revenue after loyalty discounts and refunds, then convert the total into the region's local currency. Report the integer local-currency amount. + +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_depth4_local_net_revenue_t1/task.toml b/harbor/tasks/v3_depth4_local_net_revenue_t1/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..535b86d3d95ff71328b8558263a4218599c19ec0 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_t1/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth4_local_net_revenue_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 = 4 + +[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_depth4_local_net_revenue_t1/tests/check_output_shape.py b/harbor/tasks/v3_depth4_local_net_revenue_t1/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t1/tests/test.sh b/harbor/tasks/v3_depth4_local_net_revenue_t1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t10/environment/Dockerfile b/harbor/tasks/v3_depth4_local_net_revenue_t10/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t10/environment/flowbench_tools.py b/harbor/tasks/v3_depth4_local_net_revenue_t10/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t10/environment/task.json b/harbor/tasks/v3_depth4_local_net_revenue_t10/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..feded8cd60d6b948a34b0b85c16e8a44c41219d2 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_t10/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth4_local_net_revenue_t10", + "depth": 4, + "family": "local_net_revenue", + "params": { + "region": "APAC", + "category": "B", + "month_start": 202604, + "month_end": 202606 + }, + "question": "For orders in region APAC, category B, months 202604-202606: sum net USD revenue after loyalty discounts and refunds, then convert the total into the region's local currency. Report the integer local-currency amount.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth4_local_net_revenue_t10/instruction.md b/harbor/tasks/v3_depth4_local_net_revenue_t10/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4a4c00d89f40ab62daff17e17c4b3cbf7f52ce67 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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: sum net USD revenue after loyalty discounts and refunds, then convert the total into the region's local currency. Report the integer local-currency amount. + +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_depth4_local_net_revenue_t10/task.toml b/harbor/tasks/v3_depth4_local_net_revenue_t10/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..113c34ae2cd2db51159a3102522fb9ac28c76c04 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_t10/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth4_local_net_revenue_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 = 4 + +[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_depth4_local_net_revenue_t10/tests/check_output_shape.py b/harbor/tasks/v3_depth4_local_net_revenue_t10/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t10/tests/test.sh b/harbor/tasks/v3_depth4_local_net_revenue_t10/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t11/environment/Dockerfile b/harbor/tasks/v3_depth4_local_net_revenue_t11/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t11/environment/flowbench_tools.py b/harbor/tasks/v3_depth4_local_net_revenue_t11/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t11/environment/task.json b/harbor/tasks/v3_depth4_local_net_revenue_t11/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..35d919d26b501889690e4c88b4e2ab7e4c1a6b14 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_t11/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth4_local_net_revenue_t11", + "depth": 4, + "family": "local_net_revenue", + "params": { + "region": "LATAM", + "category": "A", + "month_start": 202601, + "month_end": 202603 + }, + "question": "For orders in region LATAM, category A, months 202601-202603: sum net USD revenue after loyalty discounts and refunds, then convert the total into the region's local currency. Report the integer local-currency amount.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth4_local_net_revenue_t11/instruction.md b/harbor/tasks/v3_depth4_local_net_revenue_t11/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..5f666cf8c89fcc2946b17742b102b6a415495655 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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: sum net USD revenue after loyalty discounts and refunds, then convert the total into the region's local currency. Report the integer local-currency amount. + +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_depth4_local_net_revenue_t11/task.toml b/harbor/tasks/v3_depth4_local_net_revenue_t11/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..2ff937c527afbad64682e96c647ccaed0862a6d3 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_t11/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth4_local_net_revenue_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 = 4 + +[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_depth4_local_net_revenue_t11/tests/check_output_shape.py b/harbor/tasks/v3_depth4_local_net_revenue_t11/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t11/tests/test.sh b/harbor/tasks/v3_depth4_local_net_revenue_t11/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t12/environment/Dockerfile b/harbor/tasks/v3_depth4_local_net_revenue_t12/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t12/environment/flowbench_tools.py b/harbor/tasks/v3_depth4_local_net_revenue_t12/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t12/environment/task.json b/harbor/tasks/v3_depth4_local_net_revenue_t12/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..fdcad84f0b76355c1b3bf0bd36796e5794a77bc2 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_t12/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth4_local_net_revenue_t12", + "depth": 4, + "family": "local_net_revenue", + "params": { + "region": "NA", + "category": "C", + "month_start": 202601, + "month_end": 202606 + }, + "question": "For orders in region NA, category C, months 202601-202606: sum net USD revenue after loyalty discounts and refunds, then convert the total into the region's local currency. Report the integer local-currency amount.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth4_local_net_revenue_t12/instruction.md b/harbor/tasks/v3_depth4_local_net_revenue_t12/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..e96e7bac38ba575d298579e8ab5f3d9e88042bd5 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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: sum net USD revenue after loyalty discounts and refunds, then convert the total into the region's local currency. Report the integer local-currency amount. + +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_depth4_local_net_revenue_t12/task.toml b/harbor/tasks/v3_depth4_local_net_revenue_t12/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..d69f9e96530263c3d5200bbcdff02c4b2f1303a9 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_t12/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth4_local_net_revenue_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 = 4 + +[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_depth4_local_net_revenue_t12/tests/check_output_shape.py b/harbor/tasks/v3_depth4_local_net_revenue_t12/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t12/tests/test.sh b/harbor/tasks/v3_depth4_local_net_revenue_t12/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t13/environment/Dockerfile b/harbor/tasks/v3_depth4_local_net_revenue_t13/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t13/environment/flowbench_tools.py b/harbor/tasks/v3_depth4_local_net_revenue_t13/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t13/environment/task.json b/harbor/tasks/v3_depth4_local_net_revenue_t13/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..de811a22df7828e01d69da279315254e237e8fb8 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_t13/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth4_local_net_revenue_t13", + "depth": 4, + "family": "local_net_revenue", + "params": { + "region": "EU", + "category": "B", + "month_start": 202601, + "month_end": 202603 + }, + "question": "For orders in region EU, category B, months 202601-202603: sum net USD revenue after loyalty discounts and refunds, then convert the total into the region's local currency. Report the integer local-currency amount.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth4_local_net_revenue_t13/instruction.md b/harbor/tasks/v3_depth4_local_net_revenue_t13/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4ea57cf8711892546e40b069ccd72e58af193597 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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: sum net USD revenue after loyalty discounts and refunds, then convert the total into the region's local currency. Report the integer local-currency amount. + +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_depth4_local_net_revenue_t13/task.toml b/harbor/tasks/v3_depth4_local_net_revenue_t13/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..4a3610a93bc96d142bcf712c66c1bd297474815a --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_t13/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth4_local_net_revenue_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 = 4 + +[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_depth4_local_net_revenue_t13/tests/check_output_shape.py b/harbor/tasks/v3_depth4_local_net_revenue_t13/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t13/tests/test.sh b/harbor/tasks/v3_depth4_local_net_revenue_t13/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t14/environment/Dockerfile b/harbor/tasks/v3_depth4_local_net_revenue_t14/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t14/environment/flowbench_tools.py b/harbor/tasks/v3_depth4_local_net_revenue_t14/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t14/environment/task.json b/harbor/tasks/v3_depth4_local_net_revenue_t14/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..6346b781d30e4c5f2824dd61431977d81f15ed75 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_t14/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth4_local_net_revenue_t14", + "depth": 4, + "family": "local_net_revenue", + "params": { + "region": "APAC", + "category": "C", + "month_start": 202602, + "month_end": 202606 + }, + "question": "For orders in region APAC, category C, months 202602-202606: sum net USD revenue after loyalty discounts and refunds, then convert the total into the region's local currency. Report the integer local-currency amount.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth4_local_net_revenue_t14/instruction.md b/harbor/tasks/v3_depth4_local_net_revenue_t14/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..44b33f4ed37f5346dbad05d9f76a2b796c8f46b6 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_t14/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For orders in region APAC, category C, months 202602-202606: sum net USD revenue after loyalty discounts and refunds, then convert the total into the region's local currency. Report the integer local-currency amount. + +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_depth4_local_net_revenue_t14/task.toml b/harbor/tasks/v3_depth4_local_net_revenue_t14/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..58678a90ba574b17cc7aa773a3c345c8322fa1ac --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_t14/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth4_local_net_revenue_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 = 4 + +[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_depth4_local_net_revenue_t14/tests/check_output_shape.py b/harbor/tasks/v3_depth4_local_net_revenue_t14/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t14/tests/test.sh b/harbor/tasks/v3_depth4_local_net_revenue_t14/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t15/environment/Dockerfile b/harbor/tasks/v3_depth4_local_net_revenue_t15/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t15/environment/flowbench_tools.py b/harbor/tasks/v3_depth4_local_net_revenue_t15/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t15/environment/task.json b/harbor/tasks/v3_depth4_local_net_revenue_t15/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..0524b48956de6539f9cafa656606de832657e233 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_t15/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth4_local_net_revenue_t15", + "depth": 4, + "family": "local_net_revenue", + "params": { + "region": "LATAM", + "category": "D", + "month_start": 202601, + "month_end": 202605 + }, + "question": "For orders in region LATAM, category D, months 202601-202605: sum net USD revenue after loyalty discounts and refunds, then convert the total into the region's local currency. Report the integer local-currency amount.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth4_local_net_revenue_t15/instruction.md b/harbor/tasks/v3_depth4_local_net_revenue_t15/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..56b2b32b9ce10c71239b5747c4c456e869542b7c --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_t15/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For orders in region LATAM, category D, months 202601-202605: sum net USD revenue after loyalty discounts and refunds, then convert the total into the region's local currency. Report the integer local-currency amount. + +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_depth4_local_net_revenue_t15/task.toml b/harbor/tasks/v3_depth4_local_net_revenue_t15/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..010662d34e6312500c9281a6481b7354cf8d5149 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_t15/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth4_local_net_revenue_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 = 4 + +[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_depth4_local_net_revenue_t15/tests/check_output_shape.py b/harbor/tasks/v3_depth4_local_net_revenue_t15/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t15/tests/test.sh b/harbor/tasks/v3_depth4_local_net_revenue_t15/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t16/environment/Dockerfile b/harbor/tasks/v3_depth4_local_net_revenue_t16/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t16/environment/flowbench_tools.py b/harbor/tasks/v3_depth4_local_net_revenue_t16/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t16/environment/task.json b/harbor/tasks/v3_depth4_local_net_revenue_t16/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..b2e6e6eeadbc571b3983a5066cd05f027fb43753 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_t16/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth4_local_net_revenue_t16", + "depth": 4, + "family": "local_net_revenue", + "params": { + "region": "NA", + "category": "A", + "month_start": 202604, + "month_end": 202606 + }, + "question": "For orders in region NA, category A, months 202604-202606: sum net USD revenue after loyalty discounts and refunds, then convert the total into the region's local currency. Report the integer local-currency amount.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth4_local_net_revenue_t16/instruction.md b/harbor/tasks/v3_depth4_local_net_revenue_t16/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..435d5558e35e7f57fdd93a5016d71d238226fbfc --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_t16/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For orders in region NA, category A, months 202604-202606: sum net USD revenue after loyalty discounts and refunds, then convert the total into the region's local currency. Report the integer local-currency amount. + +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_depth4_local_net_revenue_t16/task.toml b/harbor/tasks/v3_depth4_local_net_revenue_t16/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..fa4d2dcd482cac8aef1b95a9662dc6072f264a22 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_t16/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth4_local_net_revenue_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 = 4 + +[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_depth4_local_net_revenue_t16/tests/check_output_shape.py b/harbor/tasks/v3_depth4_local_net_revenue_t16/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t16/tests/test.sh b/harbor/tasks/v3_depth4_local_net_revenue_t16/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t17/environment/Dockerfile b/harbor/tasks/v3_depth4_local_net_revenue_t17/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t17/environment/flowbench_tools.py b/harbor/tasks/v3_depth4_local_net_revenue_t17/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t17/environment/task.json b/harbor/tasks/v3_depth4_local_net_revenue_t17/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..69ae9f09a033c2b7dd8753bb3cbcde3ee7905b4b --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_t17/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth4_local_net_revenue_t17", + "depth": 4, + "family": "local_net_revenue", + "params": { + "region": "EU", + "category": "D", + "month_start": 202601, + "month_end": 202602 + }, + "question": "For orders in region EU, category D, months 202601-202602: sum net USD revenue after loyalty discounts and refunds, then convert the total into the region's local currency. Report the integer local-currency amount.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth4_local_net_revenue_t17/instruction.md b/harbor/tasks/v3_depth4_local_net_revenue_t17/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..7a06082d89aab868cf10966765efa99f13ba0755 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_t17/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For orders in region EU, category D, months 202601-202602: sum net USD revenue after loyalty discounts and refunds, then convert the total into the region's local currency. Report the integer local-currency amount. + +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_depth4_local_net_revenue_t17/task.toml b/harbor/tasks/v3_depth4_local_net_revenue_t17/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..e56e4caafc615b470a6c2f7862dcb5509ea56f8c --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_t17/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth4_local_net_revenue_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 = 4 + +[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_depth4_local_net_revenue_t17/tests/check_output_shape.py b/harbor/tasks/v3_depth4_local_net_revenue_t17/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t17/tests/test.sh b/harbor/tasks/v3_depth4_local_net_revenue_t17/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t18/environment/Dockerfile b/harbor/tasks/v3_depth4_local_net_revenue_t18/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t18/environment/flowbench_tools.py b/harbor/tasks/v3_depth4_local_net_revenue_t18/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t18/environment/task.json b/harbor/tasks/v3_depth4_local_net_revenue_t18/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..3e2d56b91ebd5f8b981cad29451d5cc01fd19757 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_t18/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth4_local_net_revenue_t18", + "depth": 4, + "family": "local_net_revenue", + "params": { + "region": "APAC", + "category": "A", + "month_start": 202603, + "month_end": 202604 + }, + "question": "For orders in region APAC, category A, months 202603-202604: sum net USD revenue after loyalty discounts and refunds, then convert the total into the region's local currency. Report the integer local-currency amount.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth4_local_net_revenue_t18/instruction.md b/harbor/tasks/v3_depth4_local_net_revenue_t18/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9e27902ba9efdc81ab56c47525b9de7d4465940b --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_t18/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For orders in region APAC, category A, months 202603-202604: sum net USD revenue after loyalty discounts and refunds, then convert the total into the region's local currency. Report the integer local-currency amount. + +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_depth4_local_net_revenue_t18/task.toml b/harbor/tasks/v3_depth4_local_net_revenue_t18/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..d361e795d84c7bfcc92ff58fa835ebb0f4c64d3f --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_t18/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth4_local_net_revenue_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 = 4 + +[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_depth4_local_net_revenue_t18/tests/check_output_shape.py b/harbor/tasks/v3_depth4_local_net_revenue_t18/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t18/tests/test.sh b/harbor/tasks/v3_depth4_local_net_revenue_t18/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t19/environment/Dockerfile b/harbor/tasks/v3_depth4_local_net_revenue_t19/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t19/environment/flowbench_tools.py b/harbor/tasks/v3_depth4_local_net_revenue_t19/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t19/environment/task.json b/harbor/tasks/v3_depth4_local_net_revenue_t19/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..ddf38f88a08cb0065fca91954d14b6b77f0d33fe --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_t19/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth4_local_net_revenue_t19", + "depth": 4, + "family": "local_net_revenue", + "params": { + "region": "LATAM", + "category": "B", + "month_start": 202605, + "month_end": 202606 + }, + "question": "For orders in region LATAM, category B, months 202605-202606: sum net USD revenue after loyalty discounts and refunds, then convert the total into the region's local currency. Report the integer local-currency amount.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth4_local_net_revenue_t19/instruction.md b/harbor/tasks/v3_depth4_local_net_revenue_t19/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..d102c3a4f40a2d25978097a20dcbb661a5e7ca89 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_t19/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For orders in region LATAM, category B, months 202605-202606: sum net USD revenue after loyalty discounts and refunds, then convert the total into the region's local currency. Report the integer local-currency amount. + +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_depth4_local_net_revenue_t19/task.toml b/harbor/tasks/v3_depth4_local_net_revenue_t19/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..e5a9600ec1686bc451e59d8306c8b24937fce723 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_t19/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth4_local_net_revenue_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 = 4 + +[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_depth4_local_net_revenue_t19/tests/check_output_shape.py b/harbor/tasks/v3_depth4_local_net_revenue_t19/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t19/tests/test.sh b/harbor/tasks/v3_depth4_local_net_revenue_t19/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t2/environment/Dockerfile b/harbor/tasks/v3_depth4_local_net_revenue_t2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t2/environment/flowbench_tools.py b/harbor/tasks/v3_depth4_local_net_revenue_t2/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t2/environment/task.json b/harbor/tasks/v3_depth4_local_net_revenue_t2/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..f444f931a5c427fee71110900872f960853fb370 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_t2/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth4_local_net_revenue_t2", + "depth": 4, + "family": "local_net_revenue", + "params": { + "region": "EU", + "category": "C", + "month_start": 202601, + "month_end": 202604 + }, + "question": "For orders in region EU, category C, months 202601-202604: sum net USD revenue after loyalty discounts and refunds, then convert the total into the region's local currency. Report the integer local-currency amount.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth4_local_net_revenue_t2/instruction.md b/harbor/tasks/v3_depth4_local_net_revenue_t2/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..5544838cf4e54ac39abc0944d3ccf0828375ab3d --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_t2/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For orders in region EU, category C, months 202601-202604: sum net USD revenue after loyalty discounts and refunds, then convert the total into the region's local currency. Report the integer local-currency amount. + +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_depth4_local_net_revenue_t2/task.toml b/harbor/tasks/v3_depth4_local_net_revenue_t2/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..83e1019bd58d7ebda4c6ba133b4dab3f1b55632c --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_t2/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth4_local_net_revenue_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 = 4 + +[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_depth4_local_net_revenue_t2/tests/check_output_shape.py b/harbor/tasks/v3_depth4_local_net_revenue_t2/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t2/tests/test.sh b/harbor/tasks/v3_depth4_local_net_revenue_t2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t20/environment/Dockerfile b/harbor/tasks/v3_depth4_local_net_revenue_t20/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t20/environment/flowbench_tools.py b/harbor/tasks/v3_depth4_local_net_revenue_t20/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_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_depth4_local_net_revenue_t20/environment/task.json b/harbor/tasks/v3_depth4_local_net_revenue_t20/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..4b1c39ae92a4e0c2e435a3c6fc45476120d2400a --- /dev/null +++ b/harbor/tasks/v3_depth4_local_net_revenue_t20/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth4_local_net_revenue_t20", + "depth": 4, + "family": "local_net_revenue", + "params": { + "region": "NA", + "category": "C", + "month_start": 202602, + "month_end": 202604 + }, + "question": "For orders in region NA, category C, months 202602-202604: sum net USD revenue after loyalty discounts and refunds, then convert the total into the region's local currency. Report the integer local-currency amount.", + "answer_format": "exact integer" +}