diff --git a/harbor/tasks/v3_depth1_top_product_lookup_t17/tests/test.sh b/harbor/tasks/v3_depth1_top_product_lookup_t17/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t18/environment/Dockerfile b/harbor/tasks/v3_depth1_top_product_lookup_t18/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t18/environment/flowbench_tools.py b/harbor/tasks/v3_depth1_top_product_lookup_t18/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t18/environment/task.json b/harbor/tasks/v3_depth1_top_product_lookup_t18/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..bb2d3dd10bfe91f2f5f6be8887f70d00884673a9 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_t18/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth1_top_product_lookup_t18", + "depth": 1, + "family": "top_product_lookup", + "params": { + "region": "APAC", + "category": "A", + "month_start": 202603, + "month_end": 202604 + }, + "question": "For region APAC, category A, months 202603-202604, identify the product id with the highest units sold. Report only the product id; report -1 if no product has paid/refunded orders.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth1_top_product_lookup_t18/instruction.md b/harbor/tasks/v3_depth1_top_product_lookup_t18/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9782a2fca3dd2bc8a9c1fd2b9f6e1ea221fd2b35 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_t18/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For region APAC, category A, months 202603-202604, identify the product id with the highest units sold. Report only the product id; report -1 if no product has paid/refunded orders. + +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_depth1_top_product_lookup_t18/task.toml b/harbor/tasks/v3_depth1_top_product_lookup_t18/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..41e9b597508742490bc113982d89add02311e636 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_t18/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth1_top_product_lookup_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 = 1 + +[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_depth1_top_product_lookup_t18/tests/check_output_shape.py b/harbor/tasks/v3_depth1_top_product_lookup_t18/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t18/tests/test.sh b/harbor/tasks/v3_depth1_top_product_lookup_t18/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t19/environment/Dockerfile b/harbor/tasks/v3_depth1_top_product_lookup_t19/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t19/environment/flowbench_tools.py b/harbor/tasks/v3_depth1_top_product_lookup_t19/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t19/environment/task.json b/harbor/tasks/v3_depth1_top_product_lookup_t19/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..3d486032e2eae582b78e6e7bdd3f93cd4d23aa86 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_t19/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth1_top_product_lookup_t19", + "depth": 1, + "family": "top_product_lookup", + "params": { + "region": "LATAM", + "category": "B", + "month_start": 202605, + "month_end": 202606 + }, + "question": "For region LATAM, category B, months 202605-202606, identify the product id with the highest units sold. Report only the product id; report -1 if no product has paid/refunded orders.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth1_top_product_lookup_t19/instruction.md b/harbor/tasks/v3_depth1_top_product_lookup_t19/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..4ef8e353c9c37c922d0b4528a1741514a4c35745 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_t19/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For region LATAM, category B, months 202605-202606, identify the product id with the highest units sold. Report only the product id; report -1 if no product has paid/refunded orders. + +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_depth1_top_product_lookup_t19/task.toml b/harbor/tasks/v3_depth1_top_product_lookup_t19/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..5094440e15984cd06fd884d89258ff6e126f513d --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_t19/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth1_top_product_lookup_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 = 1 + +[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_depth1_top_product_lookup_t19/tests/check_output_shape.py b/harbor/tasks/v3_depth1_top_product_lookup_t19/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t19/tests/test.sh b/harbor/tasks/v3_depth1_top_product_lookup_t19/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t2/environment/Dockerfile b/harbor/tasks/v3_depth1_top_product_lookup_t2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t2/environment/flowbench_tools.py b/harbor/tasks/v3_depth1_top_product_lookup_t2/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t2/environment/task.json b/harbor/tasks/v3_depth1_top_product_lookup_t2/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..13229393378b5f90f0c1d8b934c8f0b0c7714f18 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_t2/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth1_top_product_lookup_t2", + "depth": 1, + "family": "top_product_lookup", + "params": { + "region": "EU", + "category": "C", + "month_start": 202601, + "month_end": 202604 + }, + "question": "For region EU, category C, months 202601-202604, identify the product id with the highest units sold. Report only the product id; report -1 if no product has paid/refunded orders.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth1_top_product_lookup_t2/instruction.md b/harbor/tasks/v3_depth1_top_product_lookup_t2/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..ad1ceaa02b17f5dca7797d74bc38eeb43e7a5b36 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_t2/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For region EU, category C, months 202601-202604, identify the product id with the highest units sold. Report only the product id; report -1 if no product has paid/refunded orders. + +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_depth1_top_product_lookup_t2/task.toml b/harbor/tasks/v3_depth1_top_product_lookup_t2/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..ca5a988395409a4033383197af430b6a882e4156 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_t2/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth1_top_product_lookup_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 = 1 + +[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_depth1_top_product_lookup_t2/tests/check_output_shape.py b/harbor/tasks/v3_depth1_top_product_lookup_t2/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t2/tests/test.sh b/harbor/tasks/v3_depth1_top_product_lookup_t2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t20/environment/Dockerfile b/harbor/tasks/v3_depth1_top_product_lookup_t20/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t20/environment/flowbench_tools.py b/harbor/tasks/v3_depth1_top_product_lookup_t20/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t20/environment/task.json b/harbor/tasks/v3_depth1_top_product_lookup_t20/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..4f8a12ee23f2e7c4c1989260fcc87d3d3ba43a06 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_t20/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth1_top_product_lookup_t20", + "depth": 1, + "family": "top_product_lookup", + "params": { + "region": "NA", + "category": "C", + "month_start": 202602, + "month_end": 202604 + }, + "question": "For region NA, category C, months 202602-202604, identify the product id with the highest units sold. Report only the product id; report -1 if no product has paid/refunded orders.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth1_top_product_lookup_t20/instruction.md b/harbor/tasks/v3_depth1_top_product_lookup_t20/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..44e9b242e44d4439381986cdf2bce8a73590024b --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_t20/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For region NA, category C, months 202602-202604, identify the product id with the highest units sold. Report only the product id; report -1 if no product has paid/refunded orders. + +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_depth1_top_product_lookup_t20/task.toml b/harbor/tasks/v3_depth1_top_product_lookup_t20/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..667ae1e0fbba7c48832869ca6d971cefce9f868c --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_t20/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth1_top_product_lookup_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 = 1 + +[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_depth1_top_product_lookup_t20/tests/check_output_shape.py b/harbor/tasks/v3_depth1_top_product_lookup_t20/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t20/tests/test.sh b/harbor/tasks/v3_depth1_top_product_lookup_t20/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t21/environment/Dockerfile b/harbor/tasks/v3_depth1_top_product_lookup_t21/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t21/environment/flowbench_tools.py b/harbor/tasks/v3_depth1_top_product_lookup_t21/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t21/environment/task.json b/harbor/tasks/v3_depth1_top_product_lookup_t21/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..9928e97cc8e62b8f8374a2f41efd481ee91b333d --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_t21/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth1_top_product_lookup_t21", + "depth": 1, + "family": "top_product_lookup", + "params": { + "region": "EU", + "category": "B", + "month_start": 202604, + "month_end": 202606 + }, + "question": "For region EU, category B, months 202604-202606, identify the product id with the highest units sold. Report only the product id; report -1 if no product has paid/refunded orders.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth1_top_product_lookup_t21/instruction.md b/harbor/tasks/v3_depth1_top_product_lookup_t21/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..8294d36159d0f0ea405e85b90e87c1321070d1a1 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_t21/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For region EU, category B, months 202604-202606, identify the product id with the highest units sold. Report only the product id; report -1 if no product has paid/refunded orders. + +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_depth1_top_product_lookup_t21/task.toml b/harbor/tasks/v3_depth1_top_product_lookup_t21/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..b8ce2d5cc896cddf372a5a197d5be5ed72bd88df --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_t21/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth1_top_product_lookup_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 = 1 + +[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_depth1_top_product_lookup_t21/tests/check_output_shape.py b/harbor/tasks/v3_depth1_top_product_lookup_t21/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t21/tests/test.sh b/harbor/tasks/v3_depth1_top_product_lookup_t21/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t22/environment/Dockerfile b/harbor/tasks/v3_depth1_top_product_lookup_t22/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t22/environment/flowbench_tools.py b/harbor/tasks/v3_depth1_top_product_lookup_t22/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t22/environment/task.json b/harbor/tasks/v3_depth1_top_product_lookup_t22/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..692c4a1d9889cfdd6556f1c6150445b895986716 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_t22/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth1_top_product_lookup_t22", + "depth": 1, + "family": "top_product_lookup", + "params": { + "region": "APAC", + "category": "D", + "month_start": 202603, + "month_end": 202605 + }, + "question": "For region APAC, category D, months 202603-202605, identify the product id with the highest units sold. Report only the product id; report -1 if no product has paid/refunded orders.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth1_top_product_lookup_t22/instruction.md b/harbor/tasks/v3_depth1_top_product_lookup_t22/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..1e44eb70fb304e66df8e967b3838b4299eef4a33 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_t22/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For region APAC, category D, months 202603-202605, identify the product id with the highest units sold. Report only the product id; report -1 if no product has paid/refunded orders. + +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_depth1_top_product_lookup_t22/task.toml b/harbor/tasks/v3_depth1_top_product_lookup_t22/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..16717277f73de952def6efe17b2e9d813459eaa0 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_t22/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth1_top_product_lookup_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 = 1 + +[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_depth1_top_product_lookup_t22/tests/check_output_shape.py b/harbor/tasks/v3_depth1_top_product_lookup_t22/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t22/tests/test.sh b/harbor/tasks/v3_depth1_top_product_lookup_t22/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t23/environment/Dockerfile b/harbor/tasks/v3_depth1_top_product_lookup_t23/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t23/environment/flowbench_tools.py b/harbor/tasks/v3_depth1_top_product_lookup_t23/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t23/environment/task.json b/harbor/tasks/v3_depth1_top_product_lookup_t23/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..978340db1916b59654ecc04f1e2d03c303624dd3 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_t23/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth1_top_product_lookup_t23", + "depth": 1, + "family": "top_product_lookup", + "params": { + "region": "LATAM", + "category": "C", + "month_start": 202601, + "month_end": 202602 + }, + "question": "For region LATAM, category C, months 202601-202602, identify the product id with the highest units sold. Report only the product id; report -1 if no product has paid/refunded orders.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth1_top_product_lookup_t23/instruction.md b/harbor/tasks/v3_depth1_top_product_lookup_t23/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..3eb9ca287617161adad1204edaa95857af093ce8 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_t23/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For region LATAM, category C, months 202601-202602, identify the product id with the highest units sold. Report only the product id; report -1 if no product has paid/refunded orders. + +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_depth1_top_product_lookup_t23/task.toml b/harbor/tasks/v3_depth1_top_product_lookup_t23/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..ea23acbe512b349e626292281fe7a8c4c4bfe09e --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_t23/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth1_top_product_lookup_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 = 1 + +[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_depth1_top_product_lookup_t23/tests/check_output_shape.py b/harbor/tasks/v3_depth1_top_product_lookup_t23/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t23/tests/test.sh b/harbor/tasks/v3_depth1_top_product_lookup_t23/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t24/environment/Dockerfile b/harbor/tasks/v3_depth1_top_product_lookup_t24/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t24/environment/flowbench_tools.py b/harbor/tasks/v3_depth1_top_product_lookup_t24/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t24/environment/task.json b/harbor/tasks/v3_depth1_top_product_lookup_t24/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..473a961299aee979842085ca55a97f0c75afa023 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_t24/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth1_top_product_lookup_t24", + "depth": 1, + "family": "top_product_lookup", + "params": { + "region": "NA", + "category": "D", + "month_start": 202601, + "month_end": 202603 + }, + "question": "For region NA, category D, months 202601-202603, identify the product id with the highest units sold. Report only the product id; report -1 if no product has paid/refunded orders.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth1_top_product_lookup_t24/instruction.md b/harbor/tasks/v3_depth1_top_product_lookup_t24/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..f43fd4c439923750912eb9182d31d5eb65fcdd2c --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_t24/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For region NA, category D, months 202601-202603, identify the product id with the highest units sold. Report only the product id; report -1 if no product has paid/refunded orders. + +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_depth1_top_product_lookup_t24/task.toml b/harbor/tasks/v3_depth1_top_product_lookup_t24/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..c6544c3704b2f08c7aef114771f9b73afdc6c5a5 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_t24/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth1_top_product_lookup_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 = 1 + +[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_depth1_top_product_lookup_t24/tests/check_output_shape.py b/harbor/tasks/v3_depth1_top_product_lookup_t24/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t24/tests/test.sh b/harbor/tasks/v3_depth1_top_product_lookup_t24/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t3/environment/Dockerfile b/harbor/tasks/v3_depth1_top_product_lookup_t3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t3/environment/flowbench_tools.py b/harbor/tasks/v3_depth1_top_product_lookup_t3/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t3/environment/task.json b/harbor/tasks/v3_depth1_top_product_lookup_t3/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..27becfcf1e4049dbd21bfb1f8f001889e39c0ffe --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_t3/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth1_top_product_lookup_t3", + "depth": 1, + "family": "top_product_lookup", + "params": { + "region": "EU", + "category": "D", + "month_start": 202603, + "month_end": 202606 + }, + "question": "For region EU, category D, months 202603-202606, identify the product id with the highest units sold. Report only the product id; report -1 if no product has paid/refunded orders.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth1_top_product_lookup_t3/instruction.md b/harbor/tasks/v3_depth1_top_product_lookup_t3/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..520601396cd3c2038d0fd18c2132c384a195eebe --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_t3/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For region EU, category D, months 202603-202606, identify the product id with the highest units sold. Report only the product id; report -1 if no product has paid/refunded orders. + +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_depth1_top_product_lookup_t3/task.toml b/harbor/tasks/v3_depth1_top_product_lookup_t3/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..4644e898f2a89bfa5ddd0ed934612a88986dd793 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_t3/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth1_top_product_lookup_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 = 1 + +[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_depth1_top_product_lookup_t3/tests/check_output_shape.py b/harbor/tasks/v3_depth1_top_product_lookup_t3/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t3/tests/test.sh b/harbor/tasks/v3_depth1_top_product_lookup_t3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t4/environment/Dockerfile b/harbor/tasks/v3_depth1_top_product_lookup_t4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t4/environment/flowbench_tools.py b/harbor/tasks/v3_depth1_top_product_lookup_t4/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t4/environment/task.json b/harbor/tasks/v3_depth1_top_product_lookup_t4/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..1777c595cca817d77d6c4c20334c00052fd52749 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_t4/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth1_top_product_lookup_t4", + "depth": 1, + "family": "top_product_lookup", + "params": { + "region": "APAC", + "category": "A", + "month_start": 202602, + "month_end": 202605 + }, + "question": "For region APAC, category A, months 202602-202605, identify the product id with the highest units sold. Report only the product id; report -1 if no product has paid/refunded orders.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth1_top_product_lookup_t4/instruction.md b/harbor/tasks/v3_depth1_top_product_lookup_t4/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..dec635ba74891d006a77a28ba43bd0a23291d926 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_t4/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For region APAC, category A, months 202602-202605, identify the product id with the highest units sold. Report only the product id; report -1 if no product has paid/refunded orders. + +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_depth1_top_product_lookup_t4/task.toml b/harbor/tasks/v3_depth1_top_product_lookup_t4/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..04d292965e7a4d7b2a216055174fea3b59c637f4 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_t4/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth1_top_product_lookup_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 = 1 + +[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_depth1_top_product_lookup_t4/tests/check_output_shape.py b/harbor/tasks/v3_depth1_top_product_lookup_t4/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t4/tests/test.sh b/harbor/tasks/v3_depth1_top_product_lookup_t4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t5/environment/Dockerfile b/harbor/tasks/v3_depth1_top_product_lookup_t5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t5/environment/flowbench_tools.py b/harbor/tasks/v3_depth1_top_product_lookup_t5/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t5/environment/task.json b/harbor/tasks/v3_depth1_top_product_lookup_t5/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..c559628ed9263794ce93b5b45be8d325a067f6f7 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_t5/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth1_top_product_lookup_t5", + "depth": 1, + "family": "top_product_lookup", + "params": { + "region": "APAC", + "category": "D", + "month_start": 202601, + "month_end": 202606 + }, + "question": "For region APAC, category D, months 202601-202606, identify the product id with the highest units sold. Report only the product id; report -1 if no product has paid/refunded orders.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth1_top_product_lookup_t5/instruction.md b/harbor/tasks/v3_depth1_top_product_lookup_t5/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..21583a5495c126311b586e844f7197054f4ad576 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_t5/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For region APAC, category D, months 202601-202606, identify the product id with the highest units sold. Report only the product id; report -1 if no product has paid/refunded orders. + +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_depth1_top_product_lookup_t5/task.toml b/harbor/tasks/v3_depth1_top_product_lookup_t5/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..b455cc481432e277c0eedca83660052cfd719664 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_t5/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth1_top_product_lookup_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 = 1 + +[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_depth1_top_product_lookup_t5/tests/check_output_shape.py b/harbor/tasks/v3_depth1_top_product_lookup_t5/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t5/tests/test.sh b/harbor/tasks/v3_depth1_top_product_lookup_t5/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t6/environment/Dockerfile b/harbor/tasks/v3_depth1_top_product_lookup_t6/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t6/environment/flowbench_tools.py b/harbor/tasks/v3_depth1_top_product_lookup_t6/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t6/environment/task.json b/harbor/tasks/v3_depth1_top_product_lookup_t6/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..ed0eb4121bcf86242ba6e8abc6ff4c9e50a8fcd3 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_t6/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth1_top_product_lookup_t6", + "depth": 1, + "family": "top_product_lookup", + "params": { + "region": "LATAM", + "category": "B", + "month_start": 202601, + "month_end": 202604 + }, + "question": "For region LATAM, category B, months 202601-202604, identify the product id with the highest units sold. Report only the product id; report -1 if no product has paid/refunded orders.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth1_top_product_lookup_t6/instruction.md b/harbor/tasks/v3_depth1_top_product_lookup_t6/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..3f21ed8933f4d60437095b99214a1f16285c0320 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_t6/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For region LATAM, category B, months 202601-202604, identify the product id with the highest units sold. Report only the product id; report -1 if no product has paid/refunded orders. + +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_depth1_top_product_lookup_t6/task.toml b/harbor/tasks/v3_depth1_top_product_lookup_t6/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..ce35d99b2cf459beb944caebb2814d295aff72f4 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_t6/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth1_top_product_lookup_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 = 1 + +[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_depth1_top_product_lookup_t6/tests/check_output_shape.py b/harbor/tasks/v3_depth1_top_product_lookup_t6/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t6/tests/test.sh b/harbor/tasks/v3_depth1_top_product_lookup_t6/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t7/environment/Dockerfile b/harbor/tasks/v3_depth1_top_product_lookup_t7/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t7/environment/flowbench_tools.py b/harbor/tasks/v3_depth1_top_product_lookup_t7/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t7/environment/task.json b/harbor/tasks/v3_depth1_top_product_lookup_t7/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..73e2623d3ff908d1aeb0595c681131d2106d0465 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_t7/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth1_top_product_lookup_t7", + "depth": 1, + "family": "top_product_lookup", + "params": { + "region": "LATAM", + "category": "C", + "month_start": 202603, + "month_end": 202606 + }, + "question": "For region LATAM, category C, months 202603-202606, identify the product id with the highest units sold. Report only the product id; report -1 if no product has paid/refunded orders.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth1_top_product_lookup_t7/instruction.md b/harbor/tasks/v3_depth1_top_product_lookup_t7/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..a1756a048972d2a53ed2927d1b9df09c3eaacfde --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_t7/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For region LATAM, category C, months 202603-202606, identify the product id with the highest units sold. Report only the product id; report -1 if no product has paid/refunded orders. + +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_depth1_top_product_lookup_t7/task.toml b/harbor/tasks/v3_depth1_top_product_lookup_t7/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..08decbd4c2084b659b3e5a8ac79657a83968c520 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_t7/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth1_top_product_lookup_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 = 1 + +[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_depth1_top_product_lookup_t7/tests/check_output_shape.py b/harbor/tasks/v3_depth1_top_product_lookup_t7/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t7/tests/test.sh b/harbor/tasks/v3_depth1_top_product_lookup_t7/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t8/environment/Dockerfile b/harbor/tasks/v3_depth1_top_product_lookup_t8/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t8/environment/flowbench_tools.py b/harbor/tasks/v3_depth1_top_product_lookup_t8/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t8/environment/task.json b/harbor/tasks/v3_depth1_top_product_lookup_t8/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..e541bd9c43d0583cff188baabcb6b827d34bcf7b --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_t8/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth1_top_product_lookup_t8", + "depth": 1, + "family": "top_product_lookup", + "params": { + "region": "NA", + "category": "D", + "month_start": 202602, + "month_end": 202606 + }, + "question": "For region NA, category D, months 202602-202606, identify the product id with the highest units sold. Report only the product id; report -1 if no product has paid/refunded orders.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth1_top_product_lookup_t8/instruction.md b/harbor/tasks/v3_depth1_top_product_lookup_t8/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..c4222c3e544404f678e5cd977f9cb6e39e9940fd --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_t8/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For region NA, category D, months 202602-202606, identify the product id with the highest units sold. Report only the product id; report -1 if no product has paid/refunded orders. + +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_depth1_top_product_lookup_t8/task.toml b/harbor/tasks/v3_depth1_top_product_lookup_t8/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..527cffeb56197c278d10c660f63e5861bf92450a --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_t8/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth1_top_product_lookup_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 = 1 + +[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_depth1_top_product_lookup_t8/tests/check_output_shape.py b/harbor/tasks/v3_depth1_top_product_lookup_t8/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t8/tests/test.sh b/harbor/tasks/v3_depth1_top_product_lookup_t8/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t9/environment/Dockerfile b/harbor/tasks/v3_depth1_top_product_lookup_t9/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t9/environment/flowbench_tools.py b/harbor/tasks/v3_depth1_top_product_lookup_t9/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t9/environment/task.json b/harbor/tasks/v3_depth1_top_product_lookup_t9/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..2f5880375e8753be50c78cefd361b1064285f595 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_t9/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth1_top_product_lookup_t9", + "depth": 1, + "family": "top_product_lookup", + "params": { + "region": "EU", + "category": "A", + "month_start": 202602, + "month_end": 202605 + }, + "question": "For region EU, category A, months 202602-202605, identify the product id with the highest units sold. Report only the product id; report -1 if no product has paid/refunded orders.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth1_top_product_lookup_t9/instruction.md b/harbor/tasks/v3_depth1_top_product_lookup_t9/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..54636f2f135ee1a9edff1a25d106c0d9213bed80 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_t9/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +For region EU, category A, months 202602-202605, identify the product id with the highest units sold. Report only the product id; report -1 if no product has paid/refunded orders. + +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_depth1_top_product_lookup_t9/task.toml b/harbor/tasks/v3_depth1_top_product_lookup_t9/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..a1d627ff6d5cf197cb90cc701180cf01a8e04f17 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_t9/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth1_top_product_lookup_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 = 1 + +[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_depth1_top_product_lookup_t9/tests/check_output_shape.py b/harbor/tasks/v3_depth1_top_product_lookup_t9/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_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_depth1_top_product_lookup_t9/tests/test.sh b/harbor/tasks/v3_depth1_top_product_lookup_t9/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth1_top_product_lookup_t9/tests/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -u +python /tests/check_output_shape.py diff --git a/harbor/tasks/v3_depth2_order_count_t0/environment/Dockerfile b/harbor/tasks/v3_depth2_order_count_t0/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t0/environment/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.12-slim +WORKDIR /app +COPY flowbench_tools.py /app/flowbench_tools.py +COPY task.json /app/task.json diff --git a/harbor/tasks/v3_depth2_order_count_t0/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_order_count_t0/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t0/environment/flowbench_tools.py @@ -0,0 +1,311 @@ +"""Deterministic FlowBench v3 tools. This file contains no task answers.""" + + +REGIONS = ["NA", "EU", "APAC", "LATAM"] +CATEGORIES = ["A", "B", "C", "D"] +CURRENCIES = {"NA": "USD", "EU": "EUR", "APAC": "JPY", "LATAM": "BRL"} +FX_TO_USD_BP = {"USD": 10000, "EUR": 10900, "JPY": 67, "BRL": 1850} +TIERS = ["std", "gold", "plat"] +DISCOUNT_PCT = {"std": 0, "gold": 10, "plat": 20} +CHANNELS = ["web", "store", "partner"] +MONTHS = [202601, 202602, 202603, 202604, 202605, 202606] + +N_CUSTOMERS = 72 +N_PRODUCTS = 48 +N_ORDERS = 720 +N_TICKETS = 260 +N_RETURNS = 180 + + +def _h(*xs): + import hashlib + s = "|".join(str(x) for x in xs).encode() + return int.from_bytes(hashlib.sha256(s).digest()[:8], "big") & 0x7FFFFFFF + + +def build_data(): + customers = [] + for cid in range(N_CUSTOMERS): + region = REGIONS[_h("region", cid) % len(REGIONS)] + customers.append({ + "customer_id": cid, + "region": region, + "tier": TIERS[_h("tier", cid) % len(TIERS)], + "segment": ["consumer", "smb", "enterprise"][_h("segment", cid) % 3], + }) + + products = [] + for pid in range(N_PRODUCTS): + cat = CATEGORIES[_h("cat", pid) % len(CATEGORIES)] + unit_price = 12 + _h("price", pid) % 240 + cogs = unit_price * (45 + _h("margin", pid) % 35) // 100 + products.append({ + "product_id": pid, + "category": cat, + "unit_price_usd": unit_price, + "unit_cogs_usd": cogs, + "lead_time_days": 3 + _h("lead", pid) % 18, + }) + + inventory = [] + for pid in range(N_PRODUCTS): + for region in REGIONS: + inventory.append({ + "product_id": pid, + "region": region, + "on_hand": 10 + _h("onhand", pid, region) % 140, + "reserved": _h("reserved", pid, region) % 28, + "inbound": _h("inbound", pid, region) % 85, + }) + + orders = [] + for oid in range(N_ORDERS): + customer_id = _h("ocust", oid) % N_CUSTOMERS + product_id = _h("oprod", oid) % N_PRODUCTS + month = MONTHS[_h("month", oid) % len(MONTHS)] + qty = 1 + _h("qty", oid) % 9 + ship_days = 1 + _h("shipdays", oid) % 16 + promised_days = 3 + _h("promise", oid) % 9 + status = ["paid", "paid", "paid", "paid", "cancelled", "refunded"][ + _h("status", oid) % 6] + orders.append({ + "order_id": oid, + "customer_id": customer_id, + "product_id": product_id, + "month": month, + "qty": qty, + "status": status, + "channel": CHANNELS[_h("channel", oid) % len(CHANNELS)], + "ship_days": ship_days, + "promised_days": promised_days, + }) + + returns = [] + for rid in range(N_RETURNS): + oid = _h("roid", rid) % N_ORDERS + order = orders[oid] + if order["status"] == "cancelled": + continue + returned_qty = 1 + _h("rqty", rid) % max(1, order["qty"]) + reason = ["defect", "late", "changed_mind", "wrong_item"][_h("reason", rid) % 4] + returns.append({ + "return_id": rid, + "order_id": oid, + "month": MONTHS[_h("rmonth", rid) % len(MONTHS)], + "returned_qty": returned_qty, + "reason": reason, + }) + + tickets = [] + for tid in range(N_TICKETS): + oid = _h("toid", tid) % N_ORDERS + severity = ["low", "medium", "high", "critical"][_h("sev", tid) % 4] + opened = MONTHS[_h("tmonth", tid) % len(MONTHS)] + first_response_hours = 1 + _h("resp", tid) % 96 + resolution_hours = first_response_hours + _h("res", tid) % 240 + tickets.append({ + "ticket_id": tid, + "order_id": oid, + "opened_month": opened, + "severity": severity, + "first_response_hours": first_response_hours, + "resolution_hours": resolution_hours, + }) + + return { + "customers": customers, + "products": products, + "inventory": inventory, + "orders": orders, + "returns": returns, + "tickets": tickets, + "fx_to_usd_bp": FX_TO_USD_BP, + } + + +DATA = build_data() +CUSTOMERS = {c["customer_id"]: c for c in DATA["customers"]} +PRODUCTS = {p["product_id"]: p for p in DATA["products"]} +ORDERS = {o["order_id"]: o for o in DATA["orders"]} + + +def region_currency(region: str) -> str: + return CURRENCIES[region] + + +def get_orders(region: str, category: str, month_start: int, month_end: int) -> list: + """Paid/refunded order ids in a region/category/month window.""" + out = [] + for o in DATA["orders"]: + if o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + p = PRODUCTS[o["product_id"]] + if c["region"] == region and p["category"] == category and month_start <= o["month"] <= month_end: + out.append(o["order_id"]) + return sorted(out) + + +def order_gross_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * p["unit_price_usd"] + + +def order_margin_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * (p["unit_price_usd"] - p["unit_cogs_usd"]) + + +def refund_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + qty = sum(r["returned_qty"] for r in DATA["returns"] if r["order_id"] == order_id) + qty = min(qty, o["qty"]) + return qty * p["unit_price_usd"] + + +def customer_tier(order_id: int) -> str: + o = ORDERS[order_id] + return CUSTOMERS[o["customer_id"]]["tier"] + + +def apply_discount(amount_usd: int, tier: str) -> int: + return amount_usd * (100 - DISCOUNT_PCT[tier]) // 100 + + +def net_revenue_usd(order_id: int) -> int: + gross = apply_discount(order_gross_usd(order_id), customer_tier(order_id)) + return max(0, gross - refund_usd(order_id)) + + +def to_local(amount_usd: int, currency: str) -> int: + return amount_usd * 10000 // FX_TO_USD_BP[currency] + + +def inventory_position(product_id: int, region: str) -> int: + row = next(x for x in DATA["inventory"] + if x["product_id"] == product_id and x["region"] == region) + return row["on_hand"] - row["reserved"] + row["inbound"] + + +def product_lead_time(product_id: int) -> int: + return PRODUCTS[product_id]["lead_time_days"] + + +def product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int: + totals = {} + for oid in get_orders(region, category, month_start, month_end): + o = ORDERS[oid] + totals[o["product_id"]] = totals.get(o["product_id"], 0) + o["qty"] + if not totals: + return -1 + return min((-qty, pid) for pid, qty in totals.items())[1] + + +def units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int: + total = 0 + for o in DATA["orders"]: + if o["product_id"] != product_id or o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + if c["region"] == region and month_start <= o["month"] <= month_end: + total += o["qty"] + return total + + +def tickets_for_orders(order_ids: list, severity: str) -> list: + s = set(order_ids) + return sorted(t["ticket_id"] for t in DATA["tickets"] + if t["order_id"] in s and t["severity"] == severity) + + +def ticket_order_id(ticket_id: int) -> int: + return next(t["order_id"] for t in DATA["tickets"] if t["ticket_id"] == ticket_id) + + +def sla_breached(ticket_id: int, first_response_limit_hours: int, + resolution_limit_hours: int) -> bool: + t = next(x for x in DATA["tickets"] if x["ticket_id"] == ticket_id) + return (t["first_response_hours"] > first_response_limit_hours or + t["resolution_hours"] > resolution_limit_hours) + + +def delayed_orders(order_ids: list) -> list: + s = set(order_ids) + return sorted(o["order_id"] for o in DATA["orders"] + if o["order_id"] in s and o["ship_days"] > o["promised_days"]) + + +def unique_customers(order_ids: list) -> list: + return sorted({ORDERS[oid]["customer_id"] for oid in order_ids}) + + +def count_items(values: list) -> int: + return len(values) + + +def sum_values(values: list) -> int: + return sum(values) + + +def count_true(values: list) -> int: + return sum(1 for v in values if bool(v)) + + +def count_below(values: list, threshold: int) -> int: + return sum(1 for v in values if v < threshold) + + +TOOLS = { + "region_currency": ("region_currency(region: str) -> str", + "ISO currency code for a region.", region_currency), + "get_orders": ("get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]", + "Paid/refunded order ids for a region, product category, and inclusive month window.", + get_orders), + "order_gross_usd": ("order_gross_usd(order_id: int) -> int", + "Gross order revenue in USD before discounts/refunds.", order_gross_usd), + "order_margin_usd": ("order_margin_usd(order_id: int) -> int", + "Gross order margin in USD before discounts/refunds.", order_margin_usd), + "refund_usd": ("refund_usd(order_id: int) -> int", + "Refund amount in USD for returned quantity on an order.", refund_usd), + "customer_tier": ("customer_tier(order_id: int) -> str", + "Customer loyalty tier for an order.", customer_tier), + "apply_discount": ("apply_discount(amount_usd: int, tier: str) -> int", + "Apply the order customer's loyalty discount to a USD amount.", apply_discount), + "net_revenue_usd": ("net_revenue_usd(order_id: int) -> int", + "Net USD revenue after loyalty discount and refunds.", net_revenue_usd), + "to_local": ("to_local(amount_usd: int, currency: str) -> int", + "Convert a USD integer amount to a local-currency integer.", to_local), + "inventory_position": ("inventory_position(product_id: int, region: str) -> int", + "Available inventory position: on_hand - reserved + inbound.", + inventory_position), + "product_lead_time": ("product_lead_time(product_id: int) -> int", + "Supplier lead time in days for a product.", product_lead_time), + "product_id_for_top_seller": ( + "product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int", + "Product id with the highest units sold in a region/category/month window.", + product_id_for_top_seller), + "units_sold": ("units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int", + "Units sold for one product in a region and month window.", units_sold), + "tickets_for_orders": ("tickets_for_orders(order_ids: list[int], severity: str) -> list[int]", + "Support ticket ids for given orders and severity.", tickets_for_orders), + "ticket_order_id": ("ticket_order_id(ticket_id: int) -> int", + "Order id associated with a support ticket.", ticket_order_id), + "sla_breached": ( + "sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool", + "Whether a support ticket breaches first-response or resolution SLA.", + sla_breached), + "delayed_orders": ("delayed_orders(order_ids: list[int]) -> list[int]", + "Subset of order ids whose ship_days exceeded promised_days.", delayed_orders), + "unique_customers": ("unique_customers(order_ids: list[int]) -> list[int]", + "Unique customer ids among the given orders.", unique_customers), + "count_items": ("count_items(values: list) -> int", "Length of a list.", count_items), + "sum_values": ("sum_values(values: list[int]) -> int", "Sum a list of integers.", sum_values), + "count_true": ("count_true(values: list[bool]) -> int", "Count true values.", count_true), + "count_below": ("count_below(values: list[int], threshold: int) -> int", + "Count values below a threshold.", count_below), +} + +__all__ = [name for name in TOOLS.keys()] + ['TOOLS'] diff --git a/harbor/tasks/v3_depth2_order_count_t0/environment/task.json b/harbor/tasks/v3_depth2_order_count_t0/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..27537ac5045cd46b8c56dc86e6d33a5a7090bb9c --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t0/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_order_count_t0", + "depth": 2, + "family": "order_count", + "params": { + "region": "NA", + "category": "A", + "month_start": 202601, + "month_end": 202603 + }, + "question": "How many paid/refunded orders are in region NA, category A, from month 202601 through 202603? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_order_count_t0/instruction.md b/harbor/tasks/v3_depth2_order_count_t0/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9bef82dea236bd6c869f3e2fe4e37c2afbaa73a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t0/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +How many paid/refunded orders are in region NA, category A, from month 202601 through 202603? Report the count. + +Available tools: +- `region_currency(region: str) -> str`: ISO currency code for a region. +- `get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]`: Paid/refunded order ids for a region, product category, and inclusive month window. +- `order_gross_usd(order_id: int) -> int`: Gross order revenue in USD before discounts/refunds. +- `order_margin_usd(order_id: int) -> int`: Gross order margin in USD before discounts/refunds. +- `refund_usd(order_id: int) -> int`: Refund amount in USD for returned quantity on an order. +- `customer_tier(order_id: int) -> str`: Customer loyalty tier for an order. +- `apply_discount(amount_usd: int, tier: str) -> int`: Apply the order customer's loyalty discount to a USD amount. +- `net_revenue_usd(order_id: int) -> int`: Net USD revenue after loyalty discount and refunds. +- `to_local(amount_usd: int, currency: str) -> int`: Convert a USD integer amount to a local-currency integer. +- `inventory_position(product_id: int, region: str) -> int`: Available inventory position: on_hand - reserved + inbound. +- `product_lead_time(product_id: int) -> int`: Supplier lead time in days for a product. +- `product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int`: Product id with the highest units sold in a region/category/month window. +- `units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int`: Units sold for one product in a region and month window. +- `tickets_for_orders(order_ids: list[int], severity: str) -> list[int]`: Support ticket ids for given orders and severity. +- `ticket_order_id(ticket_id: int) -> int`: Order id associated with a support ticket. +- `sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool`: Whether a support ticket breaches first-response or resolution SLA. +- `delayed_orders(order_ids: list[int]) -> list[int]`: Subset of order ids whose ship_days exceeded promised_days. +- `unique_customers(order_ids: list[int]) -> list[int]`: Unique customer ids among the given orders. +- `count_items(values: list) -> int`: Length of a list. +- `sum_values(values: list[int]) -> int`: Sum a list of integers. +- `count_true(values: list[bool]) -> int`: Count true values. +- `count_below(values: list[int], threshold: int) -> int`: Count values below a threshold. diff --git a/harbor/tasks/v3_depth2_order_count_t0/task.toml b/harbor/tasks/v3_depth2_order_count_t0/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..cfef5e0f138f0952560d69093bdbba86010d2935 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t0/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_order_count_t0" +description = "FlowBench v3 public task metadata. Public verifier is smoke-only." +authors = [{ name = "Mind Lab", email = "contact@mindlab.ltd" }] +keywords = ["flowbench", "tool-use", "data-orchestration", "operations"] + +[metadata] +benchmark = "FlowBench-v3" +split = "public-task-only" +category = "data-processing" +depth = 2 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +network_mode = "no-network" +build_timeout_sec = 600.0 +os = "linux" +cpus = 1 +memory_mb = 2048 +storage_mb = 2048 +gpus = 0 diff --git a/harbor/tasks/v3_depth2_order_count_t0/tests/check_output_shape.py b/harbor/tasks/v3_depth2_order_count_t0/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t0/tests/check_output_shape.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import json +import os +import re +from pathlib import Path + + +def write_reward(score: float, diagnostic: str) -> None: + log_dir = Path(os.environ.get("LOG_DIR", "/logs/verifier")) + log_dir.mkdir(parents=True, exist_ok=True) + (log_dir / "reward.txt").write_text(f"{score:.6g}\n") + (log_dir / "reward.json").write_text( + json.dumps({"reward": score, "smoke_only": True}, indent=2) + "\n" + ) + (log_dir / "diagnostic.txt").write_text(diagnostic + "\n") + + +def main() -> int: + app_dir = Path(os.environ.get("APP_DIR", "/app")) + task = json.loads((app_dir / "task.json").read_text()) + answer_path = app_dir / "answer.txt" + if not answer_path.exists(): + write_reward(0.0, "missing /app/answer.txt") + return 1 + + got = answer_path.read_text().strip() + if task["answer_format"] == "exact integer": + ok = bool(re.fullmatch(r"-?\d+", got)) + diagnostic = "valid integer smoke output" if ok else f"not an exact integer: {got!r}" + else: + ok = bool(re.fullmatch(r"[A-Za-z]+", got)) + diagnostic = "valid code smoke output" if ok else f"not an exact code: {got!r}" + + # This is intentionally not official scoring; it only verifies I/O shape. + write_reward(1.0 if ok else 0.0, diagnostic) + return 0 if ok else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/harbor/tasks/v3_depth2_order_count_t0/tests/test.sh b/harbor/tasks/v3_depth2_order_count_t0/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t0/tests/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -u +python /tests/check_output_shape.py diff --git a/harbor/tasks/v3_depth2_order_count_t1/environment/Dockerfile b/harbor/tasks/v3_depth2_order_count_t1/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t1/environment/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.12-slim +WORKDIR /app +COPY flowbench_tools.py /app/flowbench_tools.py +COPY task.json /app/task.json diff --git a/harbor/tasks/v3_depth2_order_count_t1/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_order_count_t1/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t1/environment/flowbench_tools.py @@ -0,0 +1,311 @@ +"""Deterministic FlowBench v3 tools. This file contains no task answers.""" + + +REGIONS = ["NA", "EU", "APAC", "LATAM"] +CATEGORIES = ["A", "B", "C", "D"] +CURRENCIES = {"NA": "USD", "EU": "EUR", "APAC": "JPY", "LATAM": "BRL"} +FX_TO_USD_BP = {"USD": 10000, "EUR": 10900, "JPY": 67, "BRL": 1850} +TIERS = ["std", "gold", "plat"] +DISCOUNT_PCT = {"std": 0, "gold": 10, "plat": 20} +CHANNELS = ["web", "store", "partner"] +MONTHS = [202601, 202602, 202603, 202604, 202605, 202606] + +N_CUSTOMERS = 72 +N_PRODUCTS = 48 +N_ORDERS = 720 +N_TICKETS = 260 +N_RETURNS = 180 + + +def _h(*xs): + import hashlib + s = "|".join(str(x) for x in xs).encode() + return int.from_bytes(hashlib.sha256(s).digest()[:8], "big") & 0x7FFFFFFF + + +def build_data(): + customers = [] + for cid in range(N_CUSTOMERS): + region = REGIONS[_h("region", cid) % len(REGIONS)] + customers.append({ + "customer_id": cid, + "region": region, + "tier": TIERS[_h("tier", cid) % len(TIERS)], + "segment": ["consumer", "smb", "enterprise"][_h("segment", cid) % 3], + }) + + products = [] + for pid in range(N_PRODUCTS): + cat = CATEGORIES[_h("cat", pid) % len(CATEGORIES)] + unit_price = 12 + _h("price", pid) % 240 + cogs = unit_price * (45 + _h("margin", pid) % 35) // 100 + products.append({ + "product_id": pid, + "category": cat, + "unit_price_usd": unit_price, + "unit_cogs_usd": cogs, + "lead_time_days": 3 + _h("lead", pid) % 18, + }) + + inventory = [] + for pid in range(N_PRODUCTS): + for region in REGIONS: + inventory.append({ + "product_id": pid, + "region": region, + "on_hand": 10 + _h("onhand", pid, region) % 140, + "reserved": _h("reserved", pid, region) % 28, + "inbound": _h("inbound", pid, region) % 85, + }) + + orders = [] + for oid in range(N_ORDERS): + customer_id = _h("ocust", oid) % N_CUSTOMERS + product_id = _h("oprod", oid) % N_PRODUCTS + month = MONTHS[_h("month", oid) % len(MONTHS)] + qty = 1 + _h("qty", oid) % 9 + ship_days = 1 + _h("shipdays", oid) % 16 + promised_days = 3 + _h("promise", oid) % 9 + status = ["paid", "paid", "paid", "paid", "cancelled", "refunded"][ + _h("status", oid) % 6] + orders.append({ + "order_id": oid, + "customer_id": customer_id, + "product_id": product_id, + "month": month, + "qty": qty, + "status": status, + "channel": CHANNELS[_h("channel", oid) % len(CHANNELS)], + "ship_days": ship_days, + "promised_days": promised_days, + }) + + returns = [] + for rid in range(N_RETURNS): + oid = _h("roid", rid) % N_ORDERS + order = orders[oid] + if order["status"] == "cancelled": + continue + returned_qty = 1 + _h("rqty", rid) % max(1, order["qty"]) + reason = ["defect", "late", "changed_mind", "wrong_item"][_h("reason", rid) % 4] + returns.append({ + "return_id": rid, + "order_id": oid, + "month": MONTHS[_h("rmonth", rid) % len(MONTHS)], + "returned_qty": returned_qty, + "reason": reason, + }) + + tickets = [] + for tid in range(N_TICKETS): + oid = _h("toid", tid) % N_ORDERS + severity = ["low", "medium", "high", "critical"][_h("sev", tid) % 4] + opened = MONTHS[_h("tmonth", tid) % len(MONTHS)] + first_response_hours = 1 + _h("resp", tid) % 96 + resolution_hours = first_response_hours + _h("res", tid) % 240 + tickets.append({ + "ticket_id": tid, + "order_id": oid, + "opened_month": opened, + "severity": severity, + "first_response_hours": first_response_hours, + "resolution_hours": resolution_hours, + }) + + return { + "customers": customers, + "products": products, + "inventory": inventory, + "orders": orders, + "returns": returns, + "tickets": tickets, + "fx_to_usd_bp": FX_TO_USD_BP, + } + + +DATA = build_data() +CUSTOMERS = {c["customer_id"]: c for c in DATA["customers"]} +PRODUCTS = {p["product_id"]: p for p in DATA["products"]} +ORDERS = {o["order_id"]: o for o in DATA["orders"]} + + +def region_currency(region: str) -> str: + return CURRENCIES[region] + + +def get_orders(region: str, category: str, month_start: int, month_end: int) -> list: + """Paid/refunded order ids in a region/category/month window.""" + out = [] + for o in DATA["orders"]: + if o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + p = PRODUCTS[o["product_id"]] + if c["region"] == region and p["category"] == category and month_start <= o["month"] <= month_end: + out.append(o["order_id"]) + return sorted(out) + + +def order_gross_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * p["unit_price_usd"] + + +def order_margin_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * (p["unit_price_usd"] - p["unit_cogs_usd"]) + + +def refund_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + qty = sum(r["returned_qty"] for r in DATA["returns"] if r["order_id"] == order_id) + qty = min(qty, o["qty"]) + return qty * p["unit_price_usd"] + + +def customer_tier(order_id: int) -> str: + o = ORDERS[order_id] + return CUSTOMERS[o["customer_id"]]["tier"] + + +def apply_discount(amount_usd: int, tier: str) -> int: + return amount_usd * (100 - DISCOUNT_PCT[tier]) // 100 + + +def net_revenue_usd(order_id: int) -> int: + gross = apply_discount(order_gross_usd(order_id), customer_tier(order_id)) + return max(0, gross - refund_usd(order_id)) + + +def to_local(amount_usd: int, currency: str) -> int: + return amount_usd * 10000 // FX_TO_USD_BP[currency] + + +def inventory_position(product_id: int, region: str) -> int: + row = next(x for x in DATA["inventory"] + if x["product_id"] == product_id and x["region"] == region) + return row["on_hand"] - row["reserved"] + row["inbound"] + + +def product_lead_time(product_id: int) -> int: + return PRODUCTS[product_id]["lead_time_days"] + + +def product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int: + totals = {} + for oid in get_orders(region, category, month_start, month_end): + o = ORDERS[oid] + totals[o["product_id"]] = totals.get(o["product_id"], 0) + o["qty"] + if not totals: + return -1 + return min((-qty, pid) for pid, qty in totals.items())[1] + + +def units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int: + total = 0 + for o in DATA["orders"]: + if o["product_id"] != product_id or o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + if c["region"] == region and month_start <= o["month"] <= month_end: + total += o["qty"] + return total + + +def tickets_for_orders(order_ids: list, severity: str) -> list: + s = set(order_ids) + return sorted(t["ticket_id"] for t in DATA["tickets"] + if t["order_id"] in s and t["severity"] == severity) + + +def ticket_order_id(ticket_id: int) -> int: + return next(t["order_id"] for t in DATA["tickets"] if t["ticket_id"] == ticket_id) + + +def sla_breached(ticket_id: int, first_response_limit_hours: int, + resolution_limit_hours: int) -> bool: + t = next(x for x in DATA["tickets"] if x["ticket_id"] == ticket_id) + return (t["first_response_hours"] > first_response_limit_hours or + t["resolution_hours"] > resolution_limit_hours) + + +def delayed_orders(order_ids: list) -> list: + s = set(order_ids) + return sorted(o["order_id"] for o in DATA["orders"] + if o["order_id"] in s and o["ship_days"] > o["promised_days"]) + + +def unique_customers(order_ids: list) -> list: + return sorted({ORDERS[oid]["customer_id"] for oid in order_ids}) + + +def count_items(values: list) -> int: + return len(values) + + +def sum_values(values: list) -> int: + return sum(values) + + +def count_true(values: list) -> int: + return sum(1 for v in values if bool(v)) + + +def count_below(values: list, threshold: int) -> int: + return sum(1 for v in values if v < threshold) + + +TOOLS = { + "region_currency": ("region_currency(region: str) -> str", + "ISO currency code for a region.", region_currency), + "get_orders": ("get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]", + "Paid/refunded order ids for a region, product category, and inclusive month window.", + get_orders), + "order_gross_usd": ("order_gross_usd(order_id: int) -> int", + "Gross order revenue in USD before discounts/refunds.", order_gross_usd), + "order_margin_usd": ("order_margin_usd(order_id: int) -> int", + "Gross order margin in USD before discounts/refunds.", order_margin_usd), + "refund_usd": ("refund_usd(order_id: int) -> int", + "Refund amount in USD for returned quantity on an order.", refund_usd), + "customer_tier": ("customer_tier(order_id: int) -> str", + "Customer loyalty tier for an order.", customer_tier), + "apply_discount": ("apply_discount(amount_usd: int, tier: str) -> int", + "Apply the order customer's loyalty discount to a USD amount.", apply_discount), + "net_revenue_usd": ("net_revenue_usd(order_id: int) -> int", + "Net USD revenue after loyalty discount and refunds.", net_revenue_usd), + "to_local": ("to_local(amount_usd: int, currency: str) -> int", + "Convert a USD integer amount to a local-currency integer.", to_local), + "inventory_position": ("inventory_position(product_id: int, region: str) -> int", + "Available inventory position: on_hand - reserved + inbound.", + inventory_position), + "product_lead_time": ("product_lead_time(product_id: int) -> int", + "Supplier lead time in days for a product.", product_lead_time), + "product_id_for_top_seller": ( + "product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int", + "Product id with the highest units sold in a region/category/month window.", + product_id_for_top_seller), + "units_sold": ("units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int", + "Units sold for one product in a region and month window.", units_sold), + "tickets_for_orders": ("tickets_for_orders(order_ids: list[int], severity: str) -> list[int]", + "Support ticket ids for given orders and severity.", tickets_for_orders), + "ticket_order_id": ("ticket_order_id(ticket_id: int) -> int", + "Order id associated with a support ticket.", ticket_order_id), + "sla_breached": ( + "sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool", + "Whether a support ticket breaches first-response or resolution SLA.", + sla_breached), + "delayed_orders": ("delayed_orders(order_ids: list[int]) -> list[int]", + "Subset of order ids whose ship_days exceeded promised_days.", delayed_orders), + "unique_customers": ("unique_customers(order_ids: list[int]) -> list[int]", + "Unique customer ids among the given orders.", unique_customers), + "count_items": ("count_items(values: list) -> int", "Length of a list.", count_items), + "sum_values": ("sum_values(values: list[int]) -> int", "Sum a list of integers.", sum_values), + "count_true": ("count_true(values: list[bool]) -> int", "Count true values.", count_true), + "count_below": ("count_below(values: list[int], threshold: int) -> int", + "Count values below a threshold.", count_below), +} + +__all__ = [name for name in TOOLS.keys()] + ['TOOLS'] diff --git a/harbor/tasks/v3_depth2_order_count_t1/environment/task.json b/harbor/tasks/v3_depth2_order_count_t1/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..dba9a940054ee6eaa1705fb68c231a3b30a491ff --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t1/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_order_count_t1", + "depth": 2, + "family": "order_count", + "params": { + "region": "NA", + "category": "B", + "month_start": 202604, + "month_end": 202606 + }, + "question": "How many paid/refunded orders are in region NA, category B, from month 202604 through 202606? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_order_count_t1/instruction.md b/harbor/tasks/v3_depth2_order_count_t1/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..b935a5605954c4df188a0898987496b7add6411d --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t1/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +How many paid/refunded orders are in region NA, category B, from month 202604 through 202606? Report the count. + +Available tools: +- `region_currency(region: str) -> str`: ISO currency code for a region. +- `get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]`: Paid/refunded order ids for a region, product category, and inclusive month window. +- `order_gross_usd(order_id: int) -> int`: Gross order revenue in USD before discounts/refunds. +- `order_margin_usd(order_id: int) -> int`: Gross order margin in USD before discounts/refunds. +- `refund_usd(order_id: int) -> int`: Refund amount in USD for returned quantity on an order. +- `customer_tier(order_id: int) -> str`: Customer loyalty tier for an order. +- `apply_discount(amount_usd: int, tier: str) -> int`: Apply the order customer's loyalty discount to a USD amount. +- `net_revenue_usd(order_id: int) -> int`: Net USD revenue after loyalty discount and refunds. +- `to_local(amount_usd: int, currency: str) -> int`: Convert a USD integer amount to a local-currency integer. +- `inventory_position(product_id: int, region: str) -> int`: Available inventory position: on_hand - reserved + inbound. +- `product_lead_time(product_id: int) -> int`: Supplier lead time in days for a product. +- `product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int`: Product id with the highest units sold in a region/category/month window. +- `units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int`: Units sold for one product in a region and month window. +- `tickets_for_orders(order_ids: list[int], severity: str) -> list[int]`: Support ticket ids for given orders and severity. +- `ticket_order_id(ticket_id: int) -> int`: Order id associated with a support ticket. +- `sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool`: Whether a support ticket breaches first-response or resolution SLA. +- `delayed_orders(order_ids: list[int]) -> list[int]`: Subset of order ids whose ship_days exceeded promised_days. +- `unique_customers(order_ids: list[int]) -> list[int]`: Unique customer ids among the given orders. +- `count_items(values: list) -> int`: Length of a list. +- `sum_values(values: list[int]) -> int`: Sum a list of integers. +- `count_true(values: list[bool]) -> int`: Count true values. +- `count_below(values: list[int], threshold: int) -> int`: Count values below a threshold. diff --git a/harbor/tasks/v3_depth2_order_count_t1/task.toml b/harbor/tasks/v3_depth2_order_count_t1/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..f641a75075e0e8ac897c0ff1d8b36ea5d43aaae3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t1/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_order_count_t1" +description = "FlowBench v3 public task metadata. Public verifier is smoke-only." +authors = [{ name = "Mind Lab", email = "contact@mindlab.ltd" }] +keywords = ["flowbench", "tool-use", "data-orchestration", "operations"] + +[metadata] +benchmark = "FlowBench-v3" +split = "public-task-only" +category = "data-processing" +depth = 2 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +network_mode = "no-network" +build_timeout_sec = 600.0 +os = "linux" +cpus = 1 +memory_mb = 2048 +storage_mb = 2048 +gpus = 0 diff --git a/harbor/tasks/v3_depth2_order_count_t1/tests/check_output_shape.py b/harbor/tasks/v3_depth2_order_count_t1/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t1/tests/check_output_shape.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import json +import os +import re +from pathlib import Path + + +def write_reward(score: float, diagnostic: str) -> None: + log_dir = Path(os.environ.get("LOG_DIR", "/logs/verifier")) + log_dir.mkdir(parents=True, exist_ok=True) + (log_dir / "reward.txt").write_text(f"{score:.6g}\n") + (log_dir / "reward.json").write_text( + json.dumps({"reward": score, "smoke_only": True}, indent=2) + "\n" + ) + (log_dir / "diagnostic.txt").write_text(diagnostic + "\n") + + +def main() -> int: + app_dir = Path(os.environ.get("APP_DIR", "/app")) + task = json.loads((app_dir / "task.json").read_text()) + answer_path = app_dir / "answer.txt" + if not answer_path.exists(): + write_reward(0.0, "missing /app/answer.txt") + return 1 + + got = answer_path.read_text().strip() + if task["answer_format"] == "exact integer": + ok = bool(re.fullmatch(r"-?\d+", got)) + diagnostic = "valid integer smoke output" if ok else f"not an exact integer: {got!r}" + else: + ok = bool(re.fullmatch(r"[A-Za-z]+", got)) + diagnostic = "valid code smoke output" if ok else f"not an exact code: {got!r}" + + # This is intentionally not official scoring; it only verifies I/O shape. + write_reward(1.0 if ok else 0.0, diagnostic) + return 0 if ok else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/harbor/tasks/v3_depth2_order_count_t1/tests/test.sh b/harbor/tasks/v3_depth2_order_count_t1/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t1/tests/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -u +python /tests/check_output_shape.py diff --git a/harbor/tasks/v3_depth2_order_count_t10/environment/Dockerfile b/harbor/tasks/v3_depth2_order_count_t10/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t10/environment/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.12-slim +WORKDIR /app +COPY flowbench_tools.py /app/flowbench_tools.py +COPY task.json /app/task.json diff --git a/harbor/tasks/v3_depth2_order_count_t10/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_order_count_t10/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t10/environment/flowbench_tools.py @@ -0,0 +1,311 @@ +"""Deterministic FlowBench v3 tools. This file contains no task answers.""" + + +REGIONS = ["NA", "EU", "APAC", "LATAM"] +CATEGORIES = ["A", "B", "C", "D"] +CURRENCIES = {"NA": "USD", "EU": "EUR", "APAC": "JPY", "LATAM": "BRL"} +FX_TO_USD_BP = {"USD": 10000, "EUR": 10900, "JPY": 67, "BRL": 1850} +TIERS = ["std", "gold", "plat"] +DISCOUNT_PCT = {"std": 0, "gold": 10, "plat": 20} +CHANNELS = ["web", "store", "partner"] +MONTHS = [202601, 202602, 202603, 202604, 202605, 202606] + +N_CUSTOMERS = 72 +N_PRODUCTS = 48 +N_ORDERS = 720 +N_TICKETS = 260 +N_RETURNS = 180 + + +def _h(*xs): + import hashlib + s = "|".join(str(x) for x in xs).encode() + return int.from_bytes(hashlib.sha256(s).digest()[:8], "big") & 0x7FFFFFFF + + +def build_data(): + customers = [] + for cid in range(N_CUSTOMERS): + region = REGIONS[_h("region", cid) % len(REGIONS)] + customers.append({ + "customer_id": cid, + "region": region, + "tier": TIERS[_h("tier", cid) % len(TIERS)], + "segment": ["consumer", "smb", "enterprise"][_h("segment", cid) % 3], + }) + + products = [] + for pid in range(N_PRODUCTS): + cat = CATEGORIES[_h("cat", pid) % len(CATEGORIES)] + unit_price = 12 + _h("price", pid) % 240 + cogs = unit_price * (45 + _h("margin", pid) % 35) // 100 + products.append({ + "product_id": pid, + "category": cat, + "unit_price_usd": unit_price, + "unit_cogs_usd": cogs, + "lead_time_days": 3 + _h("lead", pid) % 18, + }) + + inventory = [] + for pid in range(N_PRODUCTS): + for region in REGIONS: + inventory.append({ + "product_id": pid, + "region": region, + "on_hand": 10 + _h("onhand", pid, region) % 140, + "reserved": _h("reserved", pid, region) % 28, + "inbound": _h("inbound", pid, region) % 85, + }) + + orders = [] + for oid in range(N_ORDERS): + customer_id = _h("ocust", oid) % N_CUSTOMERS + product_id = _h("oprod", oid) % N_PRODUCTS + month = MONTHS[_h("month", oid) % len(MONTHS)] + qty = 1 + _h("qty", oid) % 9 + ship_days = 1 + _h("shipdays", oid) % 16 + promised_days = 3 + _h("promise", oid) % 9 + status = ["paid", "paid", "paid", "paid", "cancelled", "refunded"][ + _h("status", oid) % 6] + orders.append({ + "order_id": oid, + "customer_id": customer_id, + "product_id": product_id, + "month": month, + "qty": qty, + "status": status, + "channel": CHANNELS[_h("channel", oid) % len(CHANNELS)], + "ship_days": ship_days, + "promised_days": promised_days, + }) + + returns = [] + for rid in range(N_RETURNS): + oid = _h("roid", rid) % N_ORDERS + order = orders[oid] + if order["status"] == "cancelled": + continue + returned_qty = 1 + _h("rqty", rid) % max(1, order["qty"]) + reason = ["defect", "late", "changed_mind", "wrong_item"][_h("reason", rid) % 4] + returns.append({ + "return_id": rid, + "order_id": oid, + "month": MONTHS[_h("rmonth", rid) % len(MONTHS)], + "returned_qty": returned_qty, + "reason": reason, + }) + + tickets = [] + for tid in range(N_TICKETS): + oid = _h("toid", tid) % N_ORDERS + severity = ["low", "medium", "high", "critical"][_h("sev", tid) % 4] + opened = MONTHS[_h("tmonth", tid) % len(MONTHS)] + first_response_hours = 1 + _h("resp", tid) % 96 + resolution_hours = first_response_hours + _h("res", tid) % 240 + tickets.append({ + "ticket_id": tid, + "order_id": oid, + "opened_month": opened, + "severity": severity, + "first_response_hours": first_response_hours, + "resolution_hours": resolution_hours, + }) + + return { + "customers": customers, + "products": products, + "inventory": inventory, + "orders": orders, + "returns": returns, + "tickets": tickets, + "fx_to_usd_bp": FX_TO_USD_BP, + } + + +DATA = build_data() +CUSTOMERS = {c["customer_id"]: c for c in DATA["customers"]} +PRODUCTS = {p["product_id"]: p for p in DATA["products"]} +ORDERS = {o["order_id"]: o for o in DATA["orders"]} + + +def region_currency(region: str) -> str: + return CURRENCIES[region] + + +def get_orders(region: str, category: str, month_start: int, month_end: int) -> list: + """Paid/refunded order ids in a region/category/month window.""" + out = [] + for o in DATA["orders"]: + if o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + p = PRODUCTS[o["product_id"]] + if c["region"] == region and p["category"] == category and month_start <= o["month"] <= month_end: + out.append(o["order_id"]) + return sorted(out) + + +def order_gross_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * p["unit_price_usd"] + + +def order_margin_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * (p["unit_price_usd"] - p["unit_cogs_usd"]) + + +def refund_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + qty = sum(r["returned_qty"] for r in DATA["returns"] if r["order_id"] == order_id) + qty = min(qty, o["qty"]) + return qty * p["unit_price_usd"] + + +def customer_tier(order_id: int) -> str: + o = ORDERS[order_id] + return CUSTOMERS[o["customer_id"]]["tier"] + + +def apply_discount(amount_usd: int, tier: str) -> int: + return amount_usd * (100 - DISCOUNT_PCT[tier]) // 100 + + +def net_revenue_usd(order_id: int) -> int: + gross = apply_discount(order_gross_usd(order_id), customer_tier(order_id)) + return max(0, gross - refund_usd(order_id)) + + +def to_local(amount_usd: int, currency: str) -> int: + return amount_usd * 10000 // FX_TO_USD_BP[currency] + + +def inventory_position(product_id: int, region: str) -> int: + row = next(x for x in DATA["inventory"] + if x["product_id"] == product_id and x["region"] == region) + return row["on_hand"] - row["reserved"] + row["inbound"] + + +def product_lead_time(product_id: int) -> int: + return PRODUCTS[product_id]["lead_time_days"] + + +def product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int: + totals = {} + for oid in get_orders(region, category, month_start, month_end): + o = ORDERS[oid] + totals[o["product_id"]] = totals.get(o["product_id"], 0) + o["qty"] + if not totals: + return -1 + return min((-qty, pid) for pid, qty in totals.items())[1] + + +def units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int: + total = 0 + for o in DATA["orders"]: + if o["product_id"] != product_id or o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + if c["region"] == region and month_start <= o["month"] <= month_end: + total += o["qty"] + return total + + +def tickets_for_orders(order_ids: list, severity: str) -> list: + s = set(order_ids) + return sorted(t["ticket_id"] for t in DATA["tickets"] + if t["order_id"] in s and t["severity"] == severity) + + +def ticket_order_id(ticket_id: int) -> int: + return next(t["order_id"] for t in DATA["tickets"] if t["ticket_id"] == ticket_id) + + +def sla_breached(ticket_id: int, first_response_limit_hours: int, + resolution_limit_hours: int) -> bool: + t = next(x for x in DATA["tickets"] if x["ticket_id"] == ticket_id) + return (t["first_response_hours"] > first_response_limit_hours or + t["resolution_hours"] > resolution_limit_hours) + + +def delayed_orders(order_ids: list) -> list: + s = set(order_ids) + return sorted(o["order_id"] for o in DATA["orders"] + if o["order_id"] in s and o["ship_days"] > o["promised_days"]) + + +def unique_customers(order_ids: list) -> list: + return sorted({ORDERS[oid]["customer_id"] for oid in order_ids}) + + +def count_items(values: list) -> int: + return len(values) + + +def sum_values(values: list) -> int: + return sum(values) + + +def count_true(values: list) -> int: + return sum(1 for v in values if bool(v)) + + +def count_below(values: list, threshold: int) -> int: + return sum(1 for v in values if v < threshold) + + +TOOLS = { + "region_currency": ("region_currency(region: str) -> str", + "ISO currency code for a region.", region_currency), + "get_orders": ("get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]", + "Paid/refunded order ids for a region, product category, and inclusive month window.", + get_orders), + "order_gross_usd": ("order_gross_usd(order_id: int) -> int", + "Gross order revenue in USD before discounts/refunds.", order_gross_usd), + "order_margin_usd": ("order_margin_usd(order_id: int) -> int", + "Gross order margin in USD before discounts/refunds.", order_margin_usd), + "refund_usd": ("refund_usd(order_id: int) -> int", + "Refund amount in USD for returned quantity on an order.", refund_usd), + "customer_tier": ("customer_tier(order_id: int) -> str", + "Customer loyalty tier for an order.", customer_tier), + "apply_discount": ("apply_discount(amount_usd: int, tier: str) -> int", + "Apply the order customer's loyalty discount to a USD amount.", apply_discount), + "net_revenue_usd": ("net_revenue_usd(order_id: int) -> int", + "Net USD revenue after loyalty discount and refunds.", net_revenue_usd), + "to_local": ("to_local(amount_usd: int, currency: str) -> int", + "Convert a USD integer amount to a local-currency integer.", to_local), + "inventory_position": ("inventory_position(product_id: int, region: str) -> int", + "Available inventory position: on_hand - reserved + inbound.", + inventory_position), + "product_lead_time": ("product_lead_time(product_id: int) -> int", + "Supplier lead time in days for a product.", product_lead_time), + "product_id_for_top_seller": ( + "product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int", + "Product id with the highest units sold in a region/category/month window.", + product_id_for_top_seller), + "units_sold": ("units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int", + "Units sold for one product in a region and month window.", units_sold), + "tickets_for_orders": ("tickets_for_orders(order_ids: list[int], severity: str) -> list[int]", + "Support ticket ids for given orders and severity.", tickets_for_orders), + "ticket_order_id": ("ticket_order_id(ticket_id: int) -> int", + "Order id associated with a support ticket.", ticket_order_id), + "sla_breached": ( + "sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool", + "Whether a support ticket breaches first-response or resolution SLA.", + sla_breached), + "delayed_orders": ("delayed_orders(order_ids: list[int]) -> list[int]", + "Subset of order ids whose ship_days exceeded promised_days.", delayed_orders), + "unique_customers": ("unique_customers(order_ids: list[int]) -> list[int]", + "Unique customer ids among the given orders.", unique_customers), + "count_items": ("count_items(values: list) -> int", "Length of a list.", count_items), + "sum_values": ("sum_values(values: list[int]) -> int", "Sum a list of integers.", sum_values), + "count_true": ("count_true(values: list[bool]) -> int", "Count true values.", count_true), + "count_below": ("count_below(values: list[int], threshold: int) -> int", + "Count values below a threshold.", count_below), +} + +__all__ = [name for name in TOOLS.keys()] + ['TOOLS'] diff --git a/harbor/tasks/v3_depth2_order_count_t10/environment/task.json b/harbor/tasks/v3_depth2_order_count_t10/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..3b9ea04a025d0ffa79fa4eaf59d623d0295fe745 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t10/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_order_count_t10", + "depth": 2, + "family": "order_count", + "params": { + "region": "APAC", + "category": "B", + "month_start": 202604, + "month_end": 202606 + }, + "question": "How many paid/refunded orders are in region APAC, category B, from month 202604 through 202606? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_order_count_t10/instruction.md b/harbor/tasks/v3_depth2_order_count_t10/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..1ca01134aebecf65c404b9499bfb547d304eea3e --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t10/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +How many paid/refunded orders are in region APAC, category B, from month 202604 through 202606? Report the count. + +Available tools: +- `region_currency(region: str) -> str`: ISO currency code for a region. +- `get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]`: Paid/refunded order ids for a region, product category, and inclusive month window. +- `order_gross_usd(order_id: int) -> int`: Gross order revenue in USD before discounts/refunds. +- `order_margin_usd(order_id: int) -> int`: Gross order margin in USD before discounts/refunds. +- `refund_usd(order_id: int) -> int`: Refund amount in USD for returned quantity on an order. +- `customer_tier(order_id: int) -> str`: Customer loyalty tier for an order. +- `apply_discount(amount_usd: int, tier: str) -> int`: Apply the order customer's loyalty discount to a USD amount. +- `net_revenue_usd(order_id: int) -> int`: Net USD revenue after loyalty discount and refunds. +- `to_local(amount_usd: int, currency: str) -> int`: Convert a USD integer amount to a local-currency integer. +- `inventory_position(product_id: int, region: str) -> int`: Available inventory position: on_hand - reserved + inbound. +- `product_lead_time(product_id: int) -> int`: Supplier lead time in days for a product. +- `product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int`: Product id with the highest units sold in a region/category/month window. +- `units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int`: Units sold for one product in a region and month window. +- `tickets_for_orders(order_ids: list[int], severity: str) -> list[int]`: Support ticket ids for given orders and severity. +- `ticket_order_id(ticket_id: int) -> int`: Order id associated with a support ticket. +- `sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool`: Whether a support ticket breaches first-response or resolution SLA. +- `delayed_orders(order_ids: list[int]) -> list[int]`: Subset of order ids whose ship_days exceeded promised_days. +- `unique_customers(order_ids: list[int]) -> list[int]`: Unique customer ids among the given orders. +- `count_items(values: list) -> int`: Length of a list. +- `sum_values(values: list[int]) -> int`: Sum a list of integers. +- `count_true(values: list[bool]) -> int`: Count true values. +- `count_below(values: list[int], threshold: int) -> int`: Count values below a threshold. diff --git a/harbor/tasks/v3_depth2_order_count_t10/task.toml b/harbor/tasks/v3_depth2_order_count_t10/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..26b318f6ab001397459d6c39f7d0133e12136238 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t10/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_order_count_t10" +description = "FlowBench v3 public task metadata. Public verifier is smoke-only." +authors = [{ name = "Mind Lab", email = "contact@mindlab.ltd" }] +keywords = ["flowbench", "tool-use", "data-orchestration", "operations"] + +[metadata] +benchmark = "FlowBench-v3" +split = "public-task-only" +category = "data-processing" +depth = 2 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +network_mode = "no-network" +build_timeout_sec = 600.0 +os = "linux" +cpus = 1 +memory_mb = 2048 +storage_mb = 2048 +gpus = 0 diff --git a/harbor/tasks/v3_depth2_order_count_t10/tests/check_output_shape.py b/harbor/tasks/v3_depth2_order_count_t10/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t10/tests/check_output_shape.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import json +import os +import re +from pathlib import Path + + +def write_reward(score: float, diagnostic: str) -> None: + log_dir = Path(os.environ.get("LOG_DIR", "/logs/verifier")) + log_dir.mkdir(parents=True, exist_ok=True) + (log_dir / "reward.txt").write_text(f"{score:.6g}\n") + (log_dir / "reward.json").write_text( + json.dumps({"reward": score, "smoke_only": True}, indent=2) + "\n" + ) + (log_dir / "diagnostic.txt").write_text(diagnostic + "\n") + + +def main() -> int: + app_dir = Path(os.environ.get("APP_DIR", "/app")) + task = json.loads((app_dir / "task.json").read_text()) + answer_path = app_dir / "answer.txt" + if not answer_path.exists(): + write_reward(0.0, "missing /app/answer.txt") + return 1 + + got = answer_path.read_text().strip() + if task["answer_format"] == "exact integer": + ok = bool(re.fullmatch(r"-?\d+", got)) + diagnostic = "valid integer smoke output" if ok else f"not an exact integer: {got!r}" + else: + ok = bool(re.fullmatch(r"[A-Za-z]+", got)) + diagnostic = "valid code smoke output" if ok else f"not an exact code: {got!r}" + + # This is intentionally not official scoring; it only verifies I/O shape. + write_reward(1.0 if ok else 0.0, diagnostic) + return 0 if ok else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/harbor/tasks/v3_depth2_order_count_t10/tests/test.sh b/harbor/tasks/v3_depth2_order_count_t10/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t10/tests/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -u +python /tests/check_output_shape.py diff --git a/harbor/tasks/v3_depth2_order_count_t11/environment/Dockerfile b/harbor/tasks/v3_depth2_order_count_t11/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t11/environment/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.12-slim +WORKDIR /app +COPY flowbench_tools.py /app/flowbench_tools.py +COPY task.json /app/task.json diff --git a/harbor/tasks/v3_depth2_order_count_t11/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_order_count_t11/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t11/environment/flowbench_tools.py @@ -0,0 +1,311 @@ +"""Deterministic FlowBench v3 tools. This file contains no task answers.""" + + +REGIONS = ["NA", "EU", "APAC", "LATAM"] +CATEGORIES = ["A", "B", "C", "D"] +CURRENCIES = {"NA": "USD", "EU": "EUR", "APAC": "JPY", "LATAM": "BRL"} +FX_TO_USD_BP = {"USD": 10000, "EUR": 10900, "JPY": 67, "BRL": 1850} +TIERS = ["std", "gold", "plat"] +DISCOUNT_PCT = {"std": 0, "gold": 10, "plat": 20} +CHANNELS = ["web", "store", "partner"] +MONTHS = [202601, 202602, 202603, 202604, 202605, 202606] + +N_CUSTOMERS = 72 +N_PRODUCTS = 48 +N_ORDERS = 720 +N_TICKETS = 260 +N_RETURNS = 180 + + +def _h(*xs): + import hashlib + s = "|".join(str(x) for x in xs).encode() + return int.from_bytes(hashlib.sha256(s).digest()[:8], "big") & 0x7FFFFFFF + + +def build_data(): + customers = [] + for cid in range(N_CUSTOMERS): + region = REGIONS[_h("region", cid) % len(REGIONS)] + customers.append({ + "customer_id": cid, + "region": region, + "tier": TIERS[_h("tier", cid) % len(TIERS)], + "segment": ["consumer", "smb", "enterprise"][_h("segment", cid) % 3], + }) + + products = [] + for pid in range(N_PRODUCTS): + cat = CATEGORIES[_h("cat", pid) % len(CATEGORIES)] + unit_price = 12 + _h("price", pid) % 240 + cogs = unit_price * (45 + _h("margin", pid) % 35) // 100 + products.append({ + "product_id": pid, + "category": cat, + "unit_price_usd": unit_price, + "unit_cogs_usd": cogs, + "lead_time_days": 3 + _h("lead", pid) % 18, + }) + + inventory = [] + for pid in range(N_PRODUCTS): + for region in REGIONS: + inventory.append({ + "product_id": pid, + "region": region, + "on_hand": 10 + _h("onhand", pid, region) % 140, + "reserved": _h("reserved", pid, region) % 28, + "inbound": _h("inbound", pid, region) % 85, + }) + + orders = [] + for oid in range(N_ORDERS): + customer_id = _h("ocust", oid) % N_CUSTOMERS + product_id = _h("oprod", oid) % N_PRODUCTS + month = MONTHS[_h("month", oid) % len(MONTHS)] + qty = 1 + _h("qty", oid) % 9 + ship_days = 1 + _h("shipdays", oid) % 16 + promised_days = 3 + _h("promise", oid) % 9 + status = ["paid", "paid", "paid", "paid", "cancelled", "refunded"][ + _h("status", oid) % 6] + orders.append({ + "order_id": oid, + "customer_id": customer_id, + "product_id": product_id, + "month": month, + "qty": qty, + "status": status, + "channel": CHANNELS[_h("channel", oid) % len(CHANNELS)], + "ship_days": ship_days, + "promised_days": promised_days, + }) + + returns = [] + for rid in range(N_RETURNS): + oid = _h("roid", rid) % N_ORDERS + order = orders[oid] + if order["status"] == "cancelled": + continue + returned_qty = 1 + _h("rqty", rid) % max(1, order["qty"]) + reason = ["defect", "late", "changed_mind", "wrong_item"][_h("reason", rid) % 4] + returns.append({ + "return_id": rid, + "order_id": oid, + "month": MONTHS[_h("rmonth", rid) % len(MONTHS)], + "returned_qty": returned_qty, + "reason": reason, + }) + + tickets = [] + for tid in range(N_TICKETS): + oid = _h("toid", tid) % N_ORDERS + severity = ["low", "medium", "high", "critical"][_h("sev", tid) % 4] + opened = MONTHS[_h("tmonth", tid) % len(MONTHS)] + first_response_hours = 1 + _h("resp", tid) % 96 + resolution_hours = first_response_hours + _h("res", tid) % 240 + tickets.append({ + "ticket_id": tid, + "order_id": oid, + "opened_month": opened, + "severity": severity, + "first_response_hours": first_response_hours, + "resolution_hours": resolution_hours, + }) + + return { + "customers": customers, + "products": products, + "inventory": inventory, + "orders": orders, + "returns": returns, + "tickets": tickets, + "fx_to_usd_bp": FX_TO_USD_BP, + } + + +DATA = build_data() +CUSTOMERS = {c["customer_id"]: c for c in DATA["customers"]} +PRODUCTS = {p["product_id"]: p for p in DATA["products"]} +ORDERS = {o["order_id"]: o for o in DATA["orders"]} + + +def region_currency(region: str) -> str: + return CURRENCIES[region] + + +def get_orders(region: str, category: str, month_start: int, month_end: int) -> list: + """Paid/refunded order ids in a region/category/month window.""" + out = [] + for o in DATA["orders"]: + if o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + p = PRODUCTS[o["product_id"]] + if c["region"] == region and p["category"] == category and month_start <= o["month"] <= month_end: + out.append(o["order_id"]) + return sorted(out) + + +def order_gross_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * p["unit_price_usd"] + + +def order_margin_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * (p["unit_price_usd"] - p["unit_cogs_usd"]) + + +def refund_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + qty = sum(r["returned_qty"] for r in DATA["returns"] if r["order_id"] == order_id) + qty = min(qty, o["qty"]) + return qty * p["unit_price_usd"] + + +def customer_tier(order_id: int) -> str: + o = ORDERS[order_id] + return CUSTOMERS[o["customer_id"]]["tier"] + + +def apply_discount(amount_usd: int, tier: str) -> int: + return amount_usd * (100 - DISCOUNT_PCT[tier]) // 100 + + +def net_revenue_usd(order_id: int) -> int: + gross = apply_discount(order_gross_usd(order_id), customer_tier(order_id)) + return max(0, gross - refund_usd(order_id)) + + +def to_local(amount_usd: int, currency: str) -> int: + return amount_usd * 10000 // FX_TO_USD_BP[currency] + + +def inventory_position(product_id: int, region: str) -> int: + row = next(x for x in DATA["inventory"] + if x["product_id"] == product_id and x["region"] == region) + return row["on_hand"] - row["reserved"] + row["inbound"] + + +def product_lead_time(product_id: int) -> int: + return PRODUCTS[product_id]["lead_time_days"] + + +def product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int: + totals = {} + for oid in get_orders(region, category, month_start, month_end): + o = ORDERS[oid] + totals[o["product_id"]] = totals.get(o["product_id"], 0) + o["qty"] + if not totals: + return -1 + return min((-qty, pid) for pid, qty in totals.items())[1] + + +def units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int: + total = 0 + for o in DATA["orders"]: + if o["product_id"] != product_id or o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + if c["region"] == region and month_start <= o["month"] <= month_end: + total += o["qty"] + return total + + +def tickets_for_orders(order_ids: list, severity: str) -> list: + s = set(order_ids) + return sorted(t["ticket_id"] for t in DATA["tickets"] + if t["order_id"] in s and t["severity"] == severity) + + +def ticket_order_id(ticket_id: int) -> int: + return next(t["order_id"] for t in DATA["tickets"] if t["ticket_id"] == ticket_id) + + +def sla_breached(ticket_id: int, first_response_limit_hours: int, + resolution_limit_hours: int) -> bool: + t = next(x for x in DATA["tickets"] if x["ticket_id"] == ticket_id) + return (t["first_response_hours"] > first_response_limit_hours or + t["resolution_hours"] > resolution_limit_hours) + + +def delayed_orders(order_ids: list) -> list: + s = set(order_ids) + return sorted(o["order_id"] for o in DATA["orders"] + if o["order_id"] in s and o["ship_days"] > o["promised_days"]) + + +def unique_customers(order_ids: list) -> list: + return sorted({ORDERS[oid]["customer_id"] for oid in order_ids}) + + +def count_items(values: list) -> int: + return len(values) + + +def sum_values(values: list) -> int: + return sum(values) + + +def count_true(values: list) -> int: + return sum(1 for v in values if bool(v)) + + +def count_below(values: list, threshold: int) -> int: + return sum(1 for v in values if v < threshold) + + +TOOLS = { + "region_currency": ("region_currency(region: str) -> str", + "ISO currency code for a region.", region_currency), + "get_orders": ("get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]", + "Paid/refunded order ids for a region, product category, and inclusive month window.", + get_orders), + "order_gross_usd": ("order_gross_usd(order_id: int) -> int", + "Gross order revenue in USD before discounts/refunds.", order_gross_usd), + "order_margin_usd": ("order_margin_usd(order_id: int) -> int", + "Gross order margin in USD before discounts/refunds.", order_margin_usd), + "refund_usd": ("refund_usd(order_id: int) -> int", + "Refund amount in USD for returned quantity on an order.", refund_usd), + "customer_tier": ("customer_tier(order_id: int) -> str", + "Customer loyalty tier for an order.", customer_tier), + "apply_discount": ("apply_discount(amount_usd: int, tier: str) -> int", + "Apply the order customer's loyalty discount to a USD amount.", apply_discount), + "net_revenue_usd": ("net_revenue_usd(order_id: int) -> int", + "Net USD revenue after loyalty discount and refunds.", net_revenue_usd), + "to_local": ("to_local(amount_usd: int, currency: str) -> int", + "Convert a USD integer amount to a local-currency integer.", to_local), + "inventory_position": ("inventory_position(product_id: int, region: str) -> int", + "Available inventory position: on_hand - reserved + inbound.", + inventory_position), + "product_lead_time": ("product_lead_time(product_id: int) -> int", + "Supplier lead time in days for a product.", product_lead_time), + "product_id_for_top_seller": ( + "product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int", + "Product id with the highest units sold in a region/category/month window.", + product_id_for_top_seller), + "units_sold": ("units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int", + "Units sold for one product in a region and month window.", units_sold), + "tickets_for_orders": ("tickets_for_orders(order_ids: list[int], severity: str) -> list[int]", + "Support ticket ids for given orders and severity.", tickets_for_orders), + "ticket_order_id": ("ticket_order_id(ticket_id: int) -> int", + "Order id associated with a support ticket.", ticket_order_id), + "sla_breached": ( + "sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool", + "Whether a support ticket breaches first-response or resolution SLA.", + sla_breached), + "delayed_orders": ("delayed_orders(order_ids: list[int]) -> list[int]", + "Subset of order ids whose ship_days exceeded promised_days.", delayed_orders), + "unique_customers": ("unique_customers(order_ids: list[int]) -> list[int]", + "Unique customer ids among the given orders.", unique_customers), + "count_items": ("count_items(values: list) -> int", "Length of a list.", count_items), + "sum_values": ("sum_values(values: list[int]) -> int", "Sum a list of integers.", sum_values), + "count_true": ("count_true(values: list[bool]) -> int", "Count true values.", count_true), + "count_below": ("count_below(values: list[int], threshold: int) -> int", + "Count values below a threshold.", count_below), +} + +__all__ = [name for name in TOOLS.keys()] + ['TOOLS'] diff --git a/harbor/tasks/v3_depth2_order_count_t11/environment/task.json b/harbor/tasks/v3_depth2_order_count_t11/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..0d842f0f8bf998b0499ca0badb0711e42d35770e --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t11/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_order_count_t11", + "depth": 2, + "family": "order_count", + "params": { + "region": "LATAM", + "category": "A", + "month_start": 202601, + "month_end": 202603 + }, + "question": "How many paid/refunded orders are in region LATAM, category A, from month 202601 through 202603? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_order_count_t11/instruction.md b/harbor/tasks/v3_depth2_order_count_t11/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..036f7d3c9669a3a89550f2da64717ba897ff5312 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t11/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +How many paid/refunded orders are in region LATAM, category A, from month 202601 through 202603? Report the count. + +Available tools: +- `region_currency(region: str) -> str`: ISO currency code for a region. +- `get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]`: Paid/refunded order ids for a region, product category, and inclusive month window. +- `order_gross_usd(order_id: int) -> int`: Gross order revenue in USD before discounts/refunds. +- `order_margin_usd(order_id: int) -> int`: Gross order margin in USD before discounts/refunds. +- `refund_usd(order_id: int) -> int`: Refund amount in USD for returned quantity on an order. +- `customer_tier(order_id: int) -> str`: Customer loyalty tier for an order. +- `apply_discount(amount_usd: int, tier: str) -> int`: Apply the order customer's loyalty discount to a USD amount. +- `net_revenue_usd(order_id: int) -> int`: Net USD revenue after loyalty discount and refunds. +- `to_local(amount_usd: int, currency: str) -> int`: Convert a USD integer amount to a local-currency integer. +- `inventory_position(product_id: int, region: str) -> int`: Available inventory position: on_hand - reserved + inbound. +- `product_lead_time(product_id: int) -> int`: Supplier lead time in days for a product. +- `product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int`: Product id with the highest units sold in a region/category/month window. +- `units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int`: Units sold for one product in a region and month window. +- `tickets_for_orders(order_ids: list[int], severity: str) -> list[int]`: Support ticket ids for given orders and severity. +- `ticket_order_id(ticket_id: int) -> int`: Order id associated with a support ticket. +- `sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool`: Whether a support ticket breaches first-response or resolution SLA. +- `delayed_orders(order_ids: list[int]) -> list[int]`: Subset of order ids whose ship_days exceeded promised_days. +- `unique_customers(order_ids: list[int]) -> list[int]`: Unique customer ids among the given orders. +- `count_items(values: list) -> int`: Length of a list. +- `sum_values(values: list[int]) -> int`: Sum a list of integers. +- `count_true(values: list[bool]) -> int`: Count true values. +- `count_below(values: list[int], threshold: int) -> int`: Count values below a threshold. diff --git a/harbor/tasks/v3_depth2_order_count_t11/task.toml b/harbor/tasks/v3_depth2_order_count_t11/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..76445835de2abd9d6cc8ebb1e7e0ad6a5247f90f --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t11/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_order_count_t11" +description = "FlowBench v3 public task metadata. Public verifier is smoke-only." +authors = [{ name = "Mind Lab", email = "contact@mindlab.ltd" }] +keywords = ["flowbench", "tool-use", "data-orchestration", "operations"] + +[metadata] +benchmark = "FlowBench-v3" +split = "public-task-only" +category = "data-processing" +depth = 2 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +network_mode = "no-network" +build_timeout_sec = 600.0 +os = "linux" +cpus = 1 +memory_mb = 2048 +storage_mb = 2048 +gpus = 0 diff --git a/harbor/tasks/v3_depth2_order_count_t11/tests/check_output_shape.py b/harbor/tasks/v3_depth2_order_count_t11/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t11/tests/check_output_shape.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import json +import os +import re +from pathlib import Path + + +def write_reward(score: float, diagnostic: str) -> None: + log_dir = Path(os.environ.get("LOG_DIR", "/logs/verifier")) + log_dir.mkdir(parents=True, exist_ok=True) + (log_dir / "reward.txt").write_text(f"{score:.6g}\n") + (log_dir / "reward.json").write_text( + json.dumps({"reward": score, "smoke_only": True}, indent=2) + "\n" + ) + (log_dir / "diagnostic.txt").write_text(diagnostic + "\n") + + +def main() -> int: + app_dir = Path(os.environ.get("APP_DIR", "/app")) + task = json.loads((app_dir / "task.json").read_text()) + answer_path = app_dir / "answer.txt" + if not answer_path.exists(): + write_reward(0.0, "missing /app/answer.txt") + return 1 + + got = answer_path.read_text().strip() + if task["answer_format"] == "exact integer": + ok = bool(re.fullmatch(r"-?\d+", got)) + diagnostic = "valid integer smoke output" if ok else f"not an exact integer: {got!r}" + else: + ok = bool(re.fullmatch(r"[A-Za-z]+", got)) + diagnostic = "valid code smoke output" if ok else f"not an exact code: {got!r}" + + # This is intentionally not official scoring; it only verifies I/O shape. + write_reward(1.0 if ok else 0.0, diagnostic) + return 0 if ok else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/harbor/tasks/v3_depth2_order_count_t11/tests/test.sh b/harbor/tasks/v3_depth2_order_count_t11/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t11/tests/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -u +python /tests/check_output_shape.py diff --git a/harbor/tasks/v3_depth2_order_count_t12/environment/Dockerfile b/harbor/tasks/v3_depth2_order_count_t12/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t12/environment/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.12-slim +WORKDIR /app +COPY flowbench_tools.py /app/flowbench_tools.py +COPY task.json /app/task.json diff --git a/harbor/tasks/v3_depth2_order_count_t12/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_order_count_t12/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t12/environment/flowbench_tools.py @@ -0,0 +1,311 @@ +"""Deterministic FlowBench v3 tools. This file contains no task answers.""" + + +REGIONS = ["NA", "EU", "APAC", "LATAM"] +CATEGORIES = ["A", "B", "C", "D"] +CURRENCIES = {"NA": "USD", "EU": "EUR", "APAC": "JPY", "LATAM": "BRL"} +FX_TO_USD_BP = {"USD": 10000, "EUR": 10900, "JPY": 67, "BRL": 1850} +TIERS = ["std", "gold", "plat"] +DISCOUNT_PCT = {"std": 0, "gold": 10, "plat": 20} +CHANNELS = ["web", "store", "partner"] +MONTHS = [202601, 202602, 202603, 202604, 202605, 202606] + +N_CUSTOMERS = 72 +N_PRODUCTS = 48 +N_ORDERS = 720 +N_TICKETS = 260 +N_RETURNS = 180 + + +def _h(*xs): + import hashlib + s = "|".join(str(x) for x in xs).encode() + return int.from_bytes(hashlib.sha256(s).digest()[:8], "big") & 0x7FFFFFFF + + +def build_data(): + customers = [] + for cid in range(N_CUSTOMERS): + region = REGIONS[_h("region", cid) % len(REGIONS)] + customers.append({ + "customer_id": cid, + "region": region, + "tier": TIERS[_h("tier", cid) % len(TIERS)], + "segment": ["consumer", "smb", "enterprise"][_h("segment", cid) % 3], + }) + + products = [] + for pid in range(N_PRODUCTS): + cat = CATEGORIES[_h("cat", pid) % len(CATEGORIES)] + unit_price = 12 + _h("price", pid) % 240 + cogs = unit_price * (45 + _h("margin", pid) % 35) // 100 + products.append({ + "product_id": pid, + "category": cat, + "unit_price_usd": unit_price, + "unit_cogs_usd": cogs, + "lead_time_days": 3 + _h("lead", pid) % 18, + }) + + inventory = [] + for pid in range(N_PRODUCTS): + for region in REGIONS: + inventory.append({ + "product_id": pid, + "region": region, + "on_hand": 10 + _h("onhand", pid, region) % 140, + "reserved": _h("reserved", pid, region) % 28, + "inbound": _h("inbound", pid, region) % 85, + }) + + orders = [] + for oid in range(N_ORDERS): + customer_id = _h("ocust", oid) % N_CUSTOMERS + product_id = _h("oprod", oid) % N_PRODUCTS + month = MONTHS[_h("month", oid) % len(MONTHS)] + qty = 1 + _h("qty", oid) % 9 + ship_days = 1 + _h("shipdays", oid) % 16 + promised_days = 3 + _h("promise", oid) % 9 + status = ["paid", "paid", "paid", "paid", "cancelled", "refunded"][ + _h("status", oid) % 6] + orders.append({ + "order_id": oid, + "customer_id": customer_id, + "product_id": product_id, + "month": month, + "qty": qty, + "status": status, + "channel": CHANNELS[_h("channel", oid) % len(CHANNELS)], + "ship_days": ship_days, + "promised_days": promised_days, + }) + + returns = [] + for rid in range(N_RETURNS): + oid = _h("roid", rid) % N_ORDERS + order = orders[oid] + if order["status"] == "cancelled": + continue + returned_qty = 1 + _h("rqty", rid) % max(1, order["qty"]) + reason = ["defect", "late", "changed_mind", "wrong_item"][_h("reason", rid) % 4] + returns.append({ + "return_id": rid, + "order_id": oid, + "month": MONTHS[_h("rmonth", rid) % len(MONTHS)], + "returned_qty": returned_qty, + "reason": reason, + }) + + tickets = [] + for tid in range(N_TICKETS): + oid = _h("toid", tid) % N_ORDERS + severity = ["low", "medium", "high", "critical"][_h("sev", tid) % 4] + opened = MONTHS[_h("tmonth", tid) % len(MONTHS)] + first_response_hours = 1 + _h("resp", tid) % 96 + resolution_hours = first_response_hours + _h("res", tid) % 240 + tickets.append({ + "ticket_id": tid, + "order_id": oid, + "opened_month": opened, + "severity": severity, + "first_response_hours": first_response_hours, + "resolution_hours": resolution_hours, + }) + + return { + "customers": customers, + "products": products, + "inventory": inventory, + "orders": orders, + "returns": returns, + "tickets": tickets, + "fx_to_usd_bp": FX_TO_USD_BP, + } + + +DATA = build_data() +CUSTOMERS = {c["customer_id"]: c for c in DATA["customers"]} +PRODUCTS = {p["product_id"]: p for p in DATA["products"]} +ORDERS = {o["order_id"]: o for o in DATA["orders"]} + + +def region_currency(region: str) -> str: + return CURRENCIES[region] + + +def get_orders(region: str, category: str, month_start: int, month_end: int) -> list: + """Paid/refunded order ids in a region/category/month window.""" + out = [] + for o in DATA["orders"]: + if o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + p = PRODUCTS[o["product_id"]] + if c["region"] == region and p["category"] == category and month_start <= o["month"] <= month_end: + out.append(o["order_id"]) + return sorted(out) + + +def order_gross_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * p["unit_price_usd"] + + +def order_margin_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * (p["unit_price_usd"] - p["unit_cogs_usd"]) + + +def refund_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + qty = sum(r["returned_qty"] for r in DATA["returns"] if r["order_id"] == order_id) + qty = min(qty, o["qty"]) + return qty * p["unit_price_usd"] + + +def customer_tier(order_id: int) -> str: + o = ORDERS[order_id] + return CUSTOMERS[o["customer_id"]]["tier"] + + +def apply_discount(amount_usd: int, tier: str) -> int: + return amount_usd * (100 - DISCOUNT_PCT[tier]) // 100 + + +def net_revenue_usd(order_id: int) -> int: + gross = apply_discount(order_gross_usd(order_id), customer_tier(order_id)) + return max(0, gross - refund_usd(order_id)) + + +def to_local(amount_usd: int, currency: str) -> int: + return amount_usd * 10000 // FX_TO_USD_BP[currency] + + +def inventory_position(product_id: int, region: str) -> int: + row = next(x for x in DATA["inventory"] + if x["product_id"] == product_id and x["region"] == region) + return row["on_hand"] - row["reserved"] + row["inbound"] + + +def product_lead_time(product_id: int) -> int: + return PRODUCTS[product_id]["lead_time_days"] + + +def product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int: + totals = {} + for oid in get_orders(region, category, month_start, month_end): + o = ORDERS[oid] + totals[o["product_id"]] = totals.get(o["product_id"], 0) + o["qty"] + if not totals: + return -1 + return min((-qty, pid) for pid, qty in totals.items())[1] + + +def units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int: + total = 0 + for o in DATA["orders"]: + if o["product_id"] != product_id or o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + if c["region"] == region and month_start <= o["month"] <= month_end: + total += o["qty"] + return total + + +def tickets_for_orders(order_ids: list, severity: str) -> list: + s = set(order_ids) + return sorted(t["ticket_id"] for t in DATA["tickets"] + if t["order_id"] in s and t["severity"] == severity) + + +def ticket_order_id(ticket_id: int) -> int: + return next(t["order_id"] for t in DATA["tickets"] if t["ticket_id"] == ticket_id) + + +def sla_breached(ticket_id: int, first_response_limit_hours: int, + resolution_limit_hours: int) -> bool: + t = next(x for x in DATA["tickets"] if x["ticket_id"] == ticket_id) + return (t["first_response_hours"] > first_response_limit_hours or + t["resolution_hours"] > resolution_limit_hours) + + +def delayed_orders(order_ids: list) -> list: + s = set(order_ids) + return sorted(o["order_id"] for o in DATA["orders"] + if o["order_id"] in s and o["ship_days"] > o["promised_days"]) + + +def unique_customers(order_ids: list) -> list: + return sorted({ORDERS[oid]["customer_id"] for oid in order_ids}) + + +def count_items(values: list) -> int: + return len(values) + + +def sum_values(values: list) -> int: + return sum(values) + + +def count_true(values: list) -> int: + return sum(1 for v in values if bool(v)) + + +def count_below(values: list, threshold: int) -> int: + return sum(1 for v in values if v < threshold) + + +TOOLS = { + "region_currency": ("region_currency(region: str) -> str", + "ISO currency code for a region.", region_currency), + "get_orders": ("get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]", + "Paid/refunded order ids for a region, product category, and inclusive month window.", + get_orders), + "order_gross_usd": ("order_gross_usd(order_id: int) -> int", + "Gross order revenue in USD before discounts/refunds.", order_gross_usd), + "order_margin_usd": ("order_margin_usd(order_id: int) -> int", + "Gross order margin in USD before discounts/refunds.", order_margin_usd), + "refund_usd": ("refund_usd(order_id: int) -> int", + "Refund amount in USD for returned quantity on an order.", refund_usd), + "customer_tier": ("customer_tier(order_id: int) -> str", + "Customer loyalty tier for an order.", customer_tier), + "apply_discount": ("apply_discount(amount_usd: int, tier: str) -> int", + "Apply the order customer's loyalty discount to a USD amount.", apply_discount), + "net_revenue_usd": ("net_revenue_usd(order_id: int) -> int", + "Net USD revenue after loyalty discount and refunds.", net_revenue_usd), + "to_local": ("to_local(amount_usd: int, currency: str) -> int", + "Convert a USD integer amount to a local-currency integer.", to_local), + "inventory_position": ("inventory_position(product_id: int, region: str) -> int", + "Available inventory position: on_hand - reserved + inbound.", + inventory_position), + "product_lead_time": ("product_lead_time(product_id: int) -> int", + "Supplier lead time in days for a product.", product_lead_time), + "product_id_for_top_seller": ( + "product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int", + "Product id with the highest units sold in a region/category/month window.", + product_id_for_top_seller), + "units_sold": ("units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int", + "Units sold for one product in a region and month window.", units_sold), + "tickets_for_orders": ("tickets_for_orders(order_ids: list[int], severity: str) -> list[int]", + "Support ticket ids for given orders and severity.", tickets_for_orders), + "ticket_order_id": ("ticket_order_id(ticket_id: int) -> int", + "Order id associated with a support ticket.", ticket_order_id), + "sla_breached": ( + "sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool", + "Whether a support ticket breaches first-response or resolution SLA.", + sla_breached), + "delayed_orders": ("delayed_orders(order_ids: list[int]) -> list[int]", + "Subset of order ids whose ship_days exceeded promised_days.", delayed_orders), + "unique_customers": ("unique_customers(order_ids: list[int]) -> list[int]", + "Unique customer ids among the given orders.", unique_customers), + "count_items": ("count_items(values: list) -> int", "Length of a list.", count_items), + "sum_values": ("sum_values(values: list[int]) -> int", "Sum a list of integers.", sum_values), + "count_true": ("count_true(values: list[bool]) -> int", "Count true values.", count_true), + "count_below": ("count_below(values: list[int], threshold: int) -> int", + "Count values below a threshold.", count_below), +} + +__all__ = [name for name in TOOLS.keys()] + ['TOOLS'] diff --git a/harbor/tasks/v3_depth2_order_count_t12/environment/task.json b/harbor/tasks/v3_depth2_order_count_t12/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..ea01539b6a4e27e9db523c6fa4044df2b9d639d6 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t12/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_order_count_t12", + "depth": 2, + "family": "order_count", + "params": { + "region": "NA", + "category": "C", + "month_start": 202601, + "month_end": 202606 + }, + "question": "How many paid/refunded orders are in region NA, category C, from month 202601 through 202606? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_order_count_t12/instruction.md b/harbor/tasks/v3_depth2_order_count_t12/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..65f7fc1229a6f8b11bd15f02b9b22205f77935ab --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t12/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +How many paid/refunded orders are in region NA, category C, from month 202601 through 202606? Report the count. + +Available tools: +- `region_currency(region: str) -> str`: ISO currency code for a region. +- `get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]`: Paid/refunded order ids for a region, product category, and inclusive month window. +- `order_gross_usd(order_id: int) -> int`: Gross order revenue in USD before discounts/refunds. +- `order_margin_usd(order_id: int) -> int`: Gross order margin in USD before discounts/refunds. +- `refund_usd(order_id: int) -> int`: Refund amount in USD for returned quantity on an order. +- `customer_tier(order_id: int) -> str`: Customer loyalty tier for an order. +- `apply_discount(amount_usd: int, tier: str) -> int`: Apply the order customer's loyalty discount to a USD amount. +- `net_revenue_usd(order_id: int) -> int`: Net USD revenue after loyalty discount and refunds. +- `to_local(amount_usd: int, currency: str) -> int`: Convert a USD integer amount to a local-currency integer. +- `inventory_position(product_id: int, region: str) -> int`: Available inventory position: on_hand - reserved + inbound. +- `product_lead_time(product_id: int) -> int`: Supplier lead time in days for a product. +- `product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int`: Product id with the highest units sold in a region/category/month window. +- `units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int`: Units sold for one product in a region and month window. +- `tickets_for_orders(order_ids: list[int], severity: str) -> list[int]`: Support ticket ids for given orders and severity. +- `ticket_order_id(ticket_id: int) -> int`: Order id associated with a support ticket. +- `sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool`: Whether a support ticket breaches first-response or resolution SLA. +- `delayed_orders(order_ids: list[int]) -> list[int]`: Subset of order ids whose ship_days exceeded promised_days. +- `unique_customers(order_ids: list[int]) -> list[int]`: Unique customer ids among the given orders. +- `count_items(values: list) -> int`: Length of a list. +- `sum_values(values: list[int]) -> int`: Sum a list of integers. +- `count_true(values: list[bool]) -> int`: Count true values. +- `count_below(values: list[int], threshold: int) -> int`: Count values below a threshold. diff --git a/harbor/tasks/v3_depth2_order_count_t12/task.toml b/harbor/tasks/v3_depth2_order_count_t12/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..f920b2899b0d1a9d678f11ba4ed97a6947a83a34 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t12/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_order_count_t12" +description = "FlowBench v3 public task metadata. Public verifier is smoke-only." +authors = [{ name = "Mind Lab", email = "contact@mindlab.ltd" }] +keywords = ["flowbench", "tool-use", "data-orchestration", "operations"] + +[metadata] +benchmark = "FlowBench-v3" +split = "public-task-only" +category = "data-processing" +depth = 2 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +network_mode = "no-network" +build_timeout_sec = 600.0 +os = "linux" +cpus = 1 +memory_mb = 2048 +storage_mb = 2048 +gpus = 0 diff --git a/harbor/tasks/v3_depth2_order_count_t12/tests/check_output_shape.py b/harbor/tasks/v3_depth2_order_count_t12/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t12/tests/check_output_shape.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import json +import os +import re +from pathlib import Path + + +def write_reward(score: float, diagnostic: str) -> None: + log_dir = Path(os.environ.get("LOG_DIR", "/logs/verifier")) + log_dir.mkdir(parents=True, exist_ok=True) + (log_dir / "reward.txt").write_text(f"{score:.6g}\n") + (log_dir / "reward.json").write_text( + json.dumps({"reward": score, "smoke_only": True}, indent=2) + "\n" + ) + (log_dir / "diagnostic.txt").write_text(diagnostic + "\n") + + +def main() -> int: + app_dir = Path(os.environ.get("APP_DIR", "/app")) + task = json.loads((app_dir / "task.json").read_text()) + answer_path = app_dir / "answer.txt" + if not answer_path.exists(): + write_reward(0.0, "missing /app/answer.txt") + return 1 + + got = answer_path.read_text().strip() + if task["answer_format"] == "exact integer": + ok = bool(re.fullmatch(r"-?\d+", got)) + diagnostic = "valid integer smoke output" if ok else f"not an exact integer: {got!r}" + else: + ok = bool(re.fullmatch(r"[A-Za-z]+", got)) + diagnostic = "valid code smoke output" if ok else f"not an exact code: {got!r}" + + # This is intentionally not official scoring; it only verifies I/O shape. + write_reward(1.0 if ok else 0.0, diagnostic) + return 0 if ok else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/harbor/tasks/v3_depth2_order_count_t12/tests/test.sh b/harbor/tasks/v3_depth2_order_count_t12/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t12/tests/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -u +python /tests/check_output_shape.py diff --git a/harbor/tasks/v3_depth2_order_count_t13/environment/Dockerfile b/harbor/tasks/v3_depth2_order_count_t13/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t13/environment/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.12-slim +WORKDIR /app +COPY flowbench_tools.py /app/flowbench_tools.py +COPY task.json /app/task.json diff --git a/harbor/tasks/v3_depth2_order_count_t13/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_order_count_t13/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t13/environment/flowbench_tools.py @@ -0,0 +1,311 @@ +"""Deterministic FlowBench v3 tools. This file contains no task answers.""" + + +REGIONS = ["NA", "EU", "APAC", "LATAM"] +CATEGORIES = ["A", "B", "C", "D"] +CURRENCIES = {"NA": "USD", "EU": "EUR", "APAC": "JPY", "LATAM": "BRL"} +FX_TO_USD_BP = {"USD": 10000, "EUR": 10900, "JPY": 67, "BRL": 1850} +TIERS = ["std", "gold", "plat"] +DISCOUNT_PCT = {"std": 0, "gold": 10, "plat": 20} +CHANNELS = ["web", "store", "partner"] +MONTHS = [202601, 202602, 202603, 202604, 202605, 202606] + +N_CUSTOMERS = 72 +N_PRODUCTS = 48 +N_ORDERS = 720 +N_TICKETS = 260 +N_RETURNS = 180 + + +def _h(*xs): + import hashlib + s = "|".join(str(x) for x in xs).encode() + return int.from_bytes(hashlib.sha256(s).digest()[:8], "big") & 0x7FFFFFFF + + +def build_data(): + customers = [] + for cid in range(N_CUSTOMERS): + region = REGIONS[_h("region", cid) % len(REGIONS)] + customers.append({ + "customer_id": cid, + "region": region, + "tier": TIERS[_h("tier", cid) % len(TIERS)], + "segment": ["consumer", "smb", "enterprise"][_h("segment", cid) % 3], + }) + + products = [] + for pid in range(N_PRODUCTS): + cat = CATEGORIES[_h("cat", pid) % len(CATEGORIES)] + unit_price = 12 + _h("price", pid) % 240 + cogs = unit_price * (45 + _h("margin", pid) % 35) // 100 + products.append({ + "product_id": pid, + "category": cat, + "unit_price_usd": unit_price, + "unit_cogs_usd": cogs, + "lead_time_days": 3 + _h("lead", pid) % 18, + }) + + inventory = [] + for pid in range(N_PRODUCTS): + for region in REGIONS: + inventory.append({ + "product_id": pid, + "region": region, + "on_hand": 10 + _h("onhand", pid, region) % 140, + "reserved": _h("reserved", pid, region) % 28, + "inbound": _h("inbound", pid, region) % 85, + }) + + orders = [] + for oid in range(N_ORDERS): + customer_id = _h("ocust", oid) % N_CUSTOMERS + product_id = _h("oprod", oid) % N_PRODUCTS + month = MONTHS[_h("month", oid) % len(MONTHS)] + qty = 1 + _h("qty", oid) % 9 + ship_days = 1 + _h("shipdays", oid) % 16 + promised_days = 3 + _h("promise", oid) % 9 + status = ["paid", "paid", "paid", "paid", "cancelled", "refunded"][ + _h("status", oid) % 6] + orders.append({ + "order_id": oid, + "customer_id": customer_id, + "product_id": product_id, + "month": month, + "qty": qty, + "status": status, + "channel": CHANNELS[_h("channel", oid) % len(CHANNELS)], + "ship_days": ship_days, + "promised_days": promised_days, + }) + + returns = [] + for rid in range(N_RETURNS): + oid = _h("roid", rid) % N_ORDERS + order = orders[oid] + if order["status"] == "cancelled": + continue + returned_qty = 1 + _h("rqty", rid) % max(1, order["qty"]) + reason = ["defect", "late", "changed_mind", "wrong_item"][_h("reason", rid) % 4] + returns.append({ + "return_id": rid, + "order_id": oid, + "month": MONTHS[_h("rmonth", rid) % len(MONTHS)], + "returned_qty": returned_qty, + "reason": reason, + }) + + tickets = [] + for tid in range(N_TICKETS): + oid = _h("toid", tid) % N_ORDERS + severity = ["low", "medium", "high", "critical"][_h("sev", tid) % 4] + opened = MONTHS[_h("tmonth", tid) % len(MONTHS)] + first_response_hours = 1 + _h("resp", tid) % 96 + resolution_hours = first_response_hours + _h("res", tid) % 240 + tickets.append({ + "ticket_id": tid, + "order_id": oid, + "opened_month": opened, + "severity": severity, + "first_response_hours": first_response_hours, + "resolution_hours": resolution_hours, + }) + + return { + "customers": customers, + "products": products, + "inventory": inventory, + "orders": orders, + "returns": returns, + "tickets": tickets, + "fx_to_usd_bp": FX_TO_USD_BP, + } + + +DATA = build_data() +CUSTOMERS = {c["customer_id"]: c for c in DATA["customers"]} +PRODUCTS = {p["product_id"]: p for p in DATA["products"]} +ORDERS = {o["order_id"]: o for o in DATA["orders"]} + + +def region_currency(region: str) -> str: + return CURRENCIES[region] + + +def get_orders(region: str, category: str, month_start: int, month_end: int) -> list: + """Paid/refunded order ids in a region/category/month window.""" + out = [] + for o in DATA["orders"]: + if o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + p = PRODUCTS[o["product_id"]] + if c["region"] == region and p["category"] == category and month_start <= o["month"] <= month_end: + out.append(o["order_id"]) + return sorted(out) + + +def order_gross_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * p["unit_price_usd"] + + +def order_margin_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * (p["unit_price_usd"] - p["unit_cogs_usd"]) + + +def refund_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + qty = sum(r["returned_qty"] for r in DATA["returns"] if r["order_id"] == order_id) + qty = min(qty, o["qty"]) + return qty * p["unit_price_usd"] + + +def customer_tier(order_id: int) -> str: + o = ORDERS[order_id] + return CUSTOMERS[o["customer_id"]]["tier"] + + +def apply_discount(amount_usd: int, tier: str) -> int: + return amount_usd * (100 - DISCOUNT_PCT[tier]) // 100 + + +def net_revenue_usd(order_id: int) -> int: + gross = apply_discount(order_gross_usd(order_id), customer_tier(order_id)) + return max(0, gross - refund_usd(order_id)) + + +def to_local(amount_usd: int, currency: str) -> int: + return amount_usd * 10000 // FX_TO_USD_BP[currency] + + +def inventory_position(product_id: int, region: str) -> int: + row = next(x for x in DATA["inventory"] + if x["product_id"] == product_id and x["region"] == region) + return row["on_hand"] - row["reserved"] + row["inbound"] + + +def product_lead_time(product_id: int) -> int: + return PRODUCTS[product_id]["lead_time_days"] + + +def product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int: + totals = {} + for oid in get_orders(region, category, month_start, month_end): + o = ORDERS[oid] + totals[o["product_id"]] = totals.get(o["product_id"], 0) + o["qty"] + if not totals: + return -1 + return min((-qty, pid) for pid, qty in totals.items())[1] + + +def units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int: + total = 0 + for o in DATA["orders"]: + if o["product_id"] != product_id or o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + if c["region"] == region and month_start <= o["month"] <= month_end: + total += o["qty"] + return total + + +def tickets_for_orders(order_ids: list, severity: str) -> list: + s = set(order_ids) + return sorted(t["ticket_id"] for t in DATA["tickets"] + if t["order_id"] in s and t["severity"] == severity) + + +def ticket_order_id(ticket_id: int) -> int: + return next(t["order_id"] for t in DATA["tickets"] if t["ticket_id"] == ticket_id) + + +def sla_breached(ticket_id: int, first_response_limit_hours: int, + resolution_limit_hours: int) -> bool: + t = next(x for x in DATA["tickets"] if x["ticket_id"] == ticket_id) + return (t["first_response_hours"] > first_response_limit_hours or + t["resolution_hours"] > resolution_limit_hours) + + +def delayed_orders(order_ids: list) -> list: + s = set(order_ids) + return sorted(o["order_id"] for o in DATA["orders"] + if o["order_id"] in s and o["ship_days"] > o["promised_days"]) + + +def unique_customers(order_ids: list) -> list: + return sorted({ORDERS[oid]["customer_id"] for oid in order_ids}) + + +def count_items(values: list) -> int: + return len(values) + + +def sum_values(values: list) -> int: + return sum(values) + + +def count_true(values: list) -> int: + return sum(1 for v in values if bool(v)) + + +def count_below(values: list, threshold: int) -> int: + return sum(1 for v in values if v < threshold) + + +TOOLS = { + "region_currency": ("region_currency(region: str) -> str", + "ISO currency code for a region.", region_currency), + "get_orders": ("get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]", + "Paid/refunded order ids for a region, product category, and inclusive month window.", + get_orders), + "order_gross_usd": ("order_gross_usd(order_id: int) -> int", + "Gross order revenue in USD before discounts/refunds.", order_gross_usd), + "order_margin_usd": ("order_margin_usd(order_id: int) -> int", + "Gross order margin in USD before discounts/refunds.", order_margin_usd), + "refund_usd": ("refund_usd(order_id: int) -> int", + "Refund amount in USD for returned quantity on an order.", refund_usd), + "customer_tier": ("customer_tier(order_id: int) -> str", + "Customer loyalty tier for an order.", customer_tier), + "apply_discount": ("apply_discount(amount_usd: int, tier: str) -> int", + "Apply the order customer's loyalty discount to a USD amount.", apply_discount), + "net_revenue_usd": ("net_revenue_usd(order_id: int) -> int", + "Net USD revenue after loyalty discount and refunds.", net_revenue_usd), + "to_local": ("to_local(amount_usd: int, currency: str) -> int", + "Convert a USD integer amount to a local-currency integer.", to_local), + "inventory_position": ("inventory_position(product_id: int, region: str) -> int", + "Available inventory position: on_hand - reserved + inbound.", + inventory_position), + "product_lead_time": ("product_lead_time(product_id: int) -> int", + "Supplier lead time in days for a product.", product_lead_time), + "product_id_for_top_seller": ( + "product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int", + "Product id with the highest units sold in a region/category/month window.", + product_id_for_top_seller), + "units_sold": ("units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int", + "Units sold for one product in a region and month window.", units_sold), + "tickets_for_orders": ("tickets_for_orders(order_ids: list[int], severity: str) -> list[int]", + "Support ticket ids for given orders and severity.", tickets_for_orders), + "ticket_order_id": ("ticket_order_id(ticket_id: int) -> int", + "Order id associated with a support ticket.", ticket_order_id), + "sla_breached": ( + "sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool", + "Whether a support ticket breaches first-response or resolution SLA.", + sla_breached), + "delayed_orders": ("delayed_orders(order_ids: list[int]) -> list[int]", + "Subset of order ids whose ship_days exceeded promised_days.", delayed_orders), + "unique_customers": ("unique_customers(order_ids: list[int]) -> list[int]", + "Unique customer ids among the given orders.", unique_customers), + "count_items": ("count_items(values: list) -> int", "Length of a list.", count_items), + "sum_values": ("sum_values(values: list[int]) -> int", "Sum a list of integers.", sum_values), + "count_true": ("count_true(values: list[bool]) -> int", "Count true values.", count_true), + "count_below": ("count_below(values: list[int], threshold: int) -> int", + "Count values below a threshold.", count_below), +} + +__all__ = [name for name in TOOLS.keys()] + ['TOOLS'] diff --git a/harbor/tasks/v3_depth2_order_count_t13/environment/task.json b/harbor/tasks/v3_depth2_order_count_t13/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..5c08fa7adf3b10c85586ccecf0cb124f332b99ca --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t13/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_order_count_t13", + "depth": 2, + "family": "order_count", + "params": { + "region": "EU", + "category": "B", + "month_start": 202601, + "month_end": 202603 + }, + "question": "How many paid/refunded orders are in region EU, category B, from month 202601 through 202603? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_order_count_t13/instruction.md b/harbor/tasks/v3_depth2_order_count_t13/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..826c10ff3542fe2cee04027794fd721a68318cca --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t13/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +How many paid/refunded orders are in region EU, category B, from month 202601 through 202603? Report the count. + +Available tools: +- `region_currency(region: str) -> str`: ISO currency code for a region. +- `get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]`: Paid/refunded order ids for a region, product category, and inclusive month window. +- `order_gross_usd(order_id: int) -> int`: Gross order revenue in USD before discounts/refunds. +- `order_margin_usd(order_id: int) -> int`: Gross order margin in USD before discounts/refunds. +- `refund_usd(order_id: int) -> int`: Refund amount in USD for returned quantity on an order. +- `customer_tier(order_id: int) -> str`: Customer loyalty tier for an order. +- `apply_discount(amount_usd: int, tier: str) -> int`: Apply the order customer's loyalty discount to a USD amount. +- `net_revenue_usd(order_id: int) -> int`: Net USD revenue after loyalty discount and refunds. +- `to_local(amount_usd: int, currency: str) -> int`: Convert a USD integer amount to a local-currency integer. +- `inventory_position(product_id: int, region: str) -> int`: Available inventory position: on_hand - reserved + inbound. +- `product_lead_time(product_id: int) -> int`: Supplier lead time in days for a product. +- `product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int`: Product id with the highest units sold in a region/category/month window. +- `units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int`: Units sold for one product in a region and month window. +- `tickets_for_orders(order_ids: list[int], severity: str) -> list[int]`: Support ticket ids for given orders and severity. +- `ticket_order_id(ticket_id: int) -> int`: Order id associated with a support ticket. +- `sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool`: Whether a support ticket breaches first-response or resolution SLA. +- `delayed_orders(order_ids: list[int]) -> list[int]`: Subset of order ids whose ship_days exceeded promised_days. +- `unique_customers(order_ids: list[int]) -> list[int]`: Unique customer ids among the given orders. +- `count_items(values: list) -> int`: Length of a list. +- `sum_values(values: list[int]) -> int`: Sum a list of integers. +- `count_true(values: list[bool]) -> int`: Count true values. +- `count_below(values: list[int], threshold: int) -> int`: Count values below a threshold. diff --git a/harbor/tasks/v3_depth2_order_count_t13/task.toml b/harbor/tasks/v3_depth2_order_count_t13/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..7db170da614a15fb14f25a3384e0b46867176d2c --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t13/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_order_count_t13" +description = "FlowBench v3 public task metadata. Public verifier is smoke-only." +authors = [{ name = "Mind Lab", email = "contact@mindlab.ltd" }] +keywords = ["flowbench", "tool-use", "data-orchestration", "operations"] + +[metadata] +benchmark = "FlowBench-v3" +split = "public-task-only" +category = "data-processing" +depth = 2 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +network_mode = "no-network" +build_timeout_sec = 600.0 +os = "linux" +cpus = 1 +memory_mb = 2048 +storage_mb = 2048 +gpus = 0 diff --git a/harbor/tasks/v3_depth2_order_count_t13/tests/check_output_shape.py b/harbor/tasks/v3_depth2_order_count_t13/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t13/tests/check_output_shape.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import json +import os +import re +from pathlib import Path + + +def write_reward(score: float, diagnostic: str) -> None: + log_dir = Path(os.environ.get("LOG_DIR", "/logs/verifier")) + log_dir.mkdir(parents=True, exist_ok=True) + (log_dir / "reward.txt").write_text(f"{score:.6g}\n") + (log_dir / "reward.json").write_text( + json.dumps({"reward": score, "smoke_only": True}, indent=2) + "\n" + ) + (log_dir / "diagnostic.txt").write_text(diagnostic + "\n") + + +def main() -> int: + app_dir = Path(os.environ.get("APP_DIR", "/app")) + task = json.loads((app_dir / "task.json").read_text()) + answer_path = app_dir / "answer.txt" + if not answer_path.exists(): + write_reward(0.0, "missing /app/answer.txt") + return 1 + + got = answer_path.read_text().strip() + if task["answer_format"] == "exact integer": + ok = bool(re.fullmatch(r"-?\d+", got)) + diagnostic = "valid integer smoke output" if ok else f"not an exact integer: {got!r}" + else: + ok = bool(re.fullmatch(r"[A-Za-z]+", got)) + diagnostic = "valid code smoke output" if ok else f"not an exact code: {got!r}" + + # This is intentionally not official scoring; it only verifies I/O shape. + write_reward(1.0 if ok else 0.0, diagnostic) + return 0 if ok else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/harbor/tasks/v3_depth2_order_count_t13/tests/test.sh b/harbor/tasks/v3_depth2_order_count_t13/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t13/tests/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -u +python /tests/check_output_shape.py diff --git a/harbor/tasks/v3_depth2_order_count_t14/environment/Dockerfile b/harbor/tasks/v3_depth2_order_count_t14/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t14/environment/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.12-slim +WORKDIR /app +COPY flowbench_tools.py /app/flowbench_tools.py +COPY task.json /app/task.json diff --git a/harbor/tasks/v3_depth2_order_count_t14/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_order_count_t14/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t14/environment/flowbench_tools.py @@ -0,0 +1,311 @@ +"""Deterministic FlowBench v3 tools. This file contains no task answers.""" + + +REGIONS = ["NA", "EU", "APAC", "LATAM"] +CATEGORIES = ["A", "B", "C", "D"] +CURRENCIES = {"NA": "USD", "EU": "EUR", "APAC": "JPY", "LATAM": "BRL"} +FX_TO_USD_BP = {"USD": 10000, "EUR": 10900, "JPY": 67, "BRL": 1850} +TIERS = ["std", "gold", "plat"] +DISCOUNT_PCT = {"std": 0, "gold": 10, "plat": 20} +CHANNELS = ["web", "store", "partner"] +MONTHS = [202601, 202602, 202603, 202604, 202605, 202606] + +N_CUSTOMERS = 72 +N_PRODUCTS = 48 +N_ORDERS = 720 +N_TICKETS = 260 +N_RETURNS = 180 + + +def _h(*xs): + import hashlib + s = "|".join(str(x) for x in xs).encode() + return int.from_bytes(hashlib.sha256(s).digest()[:8], "big") & 0x7FFFFFFF + + +def build_data(): + customers = [] + for cid in range(N_CUSTOMERS): + region = REGIONS[_h("region", cid) % len(REGIONS)] + customers.append({ + "customer_id": cid, + "region": region, + "tier": TIERS[_h("tier", cid) % len(TIERS)], + "segment": ["consumer", "smb", "enterprise"][_h("segment", cid) % 3], + }) + + products = [] + for pid in range(N_PRODUCTS): + cat = CATEGORIES[_h("cat", pid) % len(CATEGORIES)] + unit_price = 12 + _h("price", pid) % 240 + cogs = unit_price * (45 + _h("margin", pid) % 35) // 100 + products.append({ + "product_id": pid, + "category": cat, + "unit_price_usd": unit_price, + "unit_cogs_usd": cogs, + "lead_time_days": 3 + _h("lead", pid) % 18, + }) + + inventory = [] + for pid in range(N_PRODUCTS): + for region in REGIONS: + inventory.append({ + "product_id": pid, + "region": region, + "on_hand": 10 + _h("onhand", pid, region) % 140, + "reserved": _h("reserved", pid, region) % 28, + "inbound": _h("inbound", pid, region) % 85, + }) + + orders = [] + for oid in range(N_ORDERS): + customer_id = _h("ocust", oid) % N_CUSTOMERS + product_id = _h("oprod", oid) % N_PRODUCTS + month = MONTHS[_h("month", oid) % len(MONTHS)] + qty = 1 + _h("qty", oid) % 9 + ship_days = 1 + _h("shipdays", oid) % 16 + promised_days = 3 + _h("promise", oid) % 9 + status = ["paid", "paid", "paid", "paid", "cancelled", "refunded"][ + _h("status", oid) % 6] + orders.append({ + "order_id": oid, + "customer_id": customer_id, + "product_id": product_id, + "month": month, + "qty": qty, + "status": status, + "channel": CHANNELS[_h("channel", oid) % len(CHANNELS)], + "ship_days": ship_days, + "promised_days": promised_days, + }) + + returns = [] + for rid in range(N_RETURNS): + oid = _h("roid", rid) % N_ORDERS + order = orders[oid] + if order["status"] == "cancelled": + continue + returned_qty = 1 + _h("rqty", rid) % max(1, order["qty"]) + reason = ["defect", "late", "changed_mind", "wrong_item"][_h("reason", rid) % 4] + returns.append({ + "return_id": rid, + "order_id": oid, + "month": MONTHS[_h("rmonth", rid) % len(MONTHS)], + "returned_qty": returned_qty, + "reason": reason, + }) + + tickets = [] + for tid in range(N_TICKETS): + oid = _h("toid", tid) % N_ORDERS + severity = ["low", "medium", "high", "critical"][_h("sev", tid) % 4] + opened = MONTHS[_h("tmonth", tid) % len(MONTHS)] + first_response_hours = 1 + _h("resp", tid) % 96 + resolution_hours = first_response_hours + _h("res", tid) % 240 + tickets.append({ + "ticket_id": tid, + "order_id": oid, + "opened_month": opened, + "severity": severity, + "first_response_hours": first_response_hours, + "resolution_hours": resolution_hours, + }) + + return { + "customers": customers, + "products": products, + "inventory": inventory, + "orders": orders, + "returns": returns, + "tickets": tickets, + "fx_to_usd_bp": FX_TO_USD_BP, + } + + +DATA = build_data() +CUSTOMERS = {c["customer_id"]: c for c in DATA["customers"]} +PRODUCTS = {p["product_id"]: p for p in DATA["products"]} +ORDERS = {o["order_id"]: o for o in DATA["orders"]} + + +def region_currency(region: str) -> str: + return CURRENCIES[region] + + +def get_orders(region: str, category: str, month_start: int, month_end: int) -> list: + """Paid/refunded order ids in a region/category/month window.""" + out = [] + for o in DATA["orders"]: + if o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + p = PRODUCTS[o["product_id"]] + if c["region"] == region and p["category"] == category and month_start <= o["month"] <= month_end: + out.append(o["order_id"]) + return sorted(out) + + +def order_gross_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * p["unit_price_usd"] + + +def order_margin_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * (p["unit_price_usd"] - p["unit_cogs_usd"]) + + +def refund_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + qty = sum(r["returned_qty"] for r in DATA["returns"] if r["order_id"] == order_id) + qty = min(qty, o["qty"]) + return qty * p["unit_price_usd"] + + +def customer_tier(order_id: int) -> str: + o = ORDERS[order_id] + return CUSTOMERS[o["customer_id"]]["tier"] + + +def apply_discount(amount_usd: int, tier: str) -> int: + return amount_usd * (100 - DISCOUNT_PCT[tier]) // 100 + + +def net_revenue_usd(order_id: int) -> int: + gross = apply_discount(order_gross_usd(order_id), customer_tier(order_id)) + return max(0, gross - refund_usd(order_id)) + + +def to_local(amount_usd: int, currency: str) -> int: + return amount_usd * 10000 // FX_TO_USD_BP[currency] + + +def inventory_position(product_id: int, region: str) -> int: + row = next(x for x in DATA["inventory"] + if x["product_id"] == product_id and x["region"] == region) + return row["on_hand"] - row["reserved"] + row["inbound"] + + +def product_lead_time(product_id: int) -> int: + return PRODUCTS[product_id]["lead_time_days"] + + +def product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int: + totals = {} + for oid in get_orders(region, category, month_start, month_end): + o = ORDERS[oid] + totals[o["product_id"]] = totals.get(o["product_id"], 0) + o["qty"] + if not totals: + return -1 + return min((-qty, pid) for pid, qty in totals.items())[1] + + +def units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int: + total = 0 + for o in DATA["orders"]: + if o["product_id"] != product_id or o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + if c["region"] == region and month_start <= o["month"] <= month_end: + total += o["qty"] + return total + + +def tickets_for_orders(order_ids: list, severity: str) -> list: + s = set(order_ids) + return sorted(t["ticket_id"] for t in DATA["tickets"] + if t["order_id"] in s and t["severity"] == severity) + + +def ticket_order_id(ticket_id: int) -> int: + return next(t["order_id"] for t in DATA["tickets"] if t["ticket_id"] == ticket_id) + + +def sla_breached(ticket_id: int, first_response_limit_hours: int, + resolution_limit_hours: int) -> bool: + t = next(x for x in DATA["tickets"] if x["ticket_id"] == ticket_id) + return (t["first_response_hours"] > first_response_limit_hours or + t["resolution_hours"] > resolution_limit_hours) + + +def delayed_orders(order_ids: list) -> list: + s = set(order_ids) + return sorted(o["order_id"] for o in DATA["orders"] + if o["order_id"] in s and o["ship_days"] > o["promised_days"]) + + +def unique_customers(order_ids: list) -> list: + return sorted({ORDERS[oid]["customer_id"] for oid in order_ids}) + + +def count_items(values: list) -> int: + return len(values) + + +def sum_values(values: list) -> int: + return sum(values) + + +def count_true(values: list) -> int: + return sum(1 for v in values if bool(v)) + + +def count_below(values: list, threshold: int) -> int: + return sum(1 for v in values if v < threshold) + + +TOOLS = { + "region_currency": ("region_currency(region: str) -> str", + "ISO currency code for a region.", region_currency), + "get_orders": ("get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]", + "Paid/refunded order ids for a region, product category, and inclusive month window.", + get_orders), + "order_gross_usd": ("order_gross_usd(order_id: int) -> int", + "Gross order revenue in USD before discounts/refunds.", order_gross_usd), + "order_margin_usd": ("order_margin_usd(order_id: int) -> int", + "Gross order margin in USD before discounts/refunds.", order_margin_usd), + "refund_usd": ("refund_usd(order_id: int) -> int", + "Refund amount in USD for returned quantity on an order.", refund_usd), + "customer_tier": ("customer_tier(order_id: int) -> str", + "Customer loyalty tier for an order.", customer_tier), + "apply_discount": ("apply_discount(amount_usd: int, tier: str) -> int", + "Apply the order customer's loyalty discount to a USD amount.", apply_discount), + "net_revenue_usd": ("net_revenue_usd(order_id: int) -> int", + "Net USD revenue after loyalty discount and refunds.", net_revenue_usd), + "to_local": ("to_local(amount_usd: int, currency: str) -> int", + "Convert a USD integer amount to a local-currency integer.", to_local), + "inventory_position": ("inventory_position(product_id: int, region: str) -> int", + "Available inventory position: on_hand - reserved + inbound.", + inventory_position), + "product_lead_time": ("product_lead_time(product_id: int) -> int", + "Supplier lead time in days for a product.", product_lead_time), + "product_id_for_top_seller": ( + "product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int", + "Product id with the highest units sold in a region/category/month window.", + product_id_for_top_seller), + "units_sold": ("units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int", + "Units sold for one product in a region and month window.", units_sold), + "tickets_for_orders": ("tickets_for_orders(order_ids: list[int], severity: str) -> list[int]", + "Support ticket ids for given orders and severity.", tickets_for_orders), + "ticket_order_id": ("ticket_order_id(ticket_id: int) -> int", + "Order id associated with a support ticket.", ticket_order_id), + "sla_breached": ( + "sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool", + "Whether a support ticket breaches first-response or resolution SLA.", + sla_breached), + "delayed_orders": ("delayed_orders(order_ids: list[int]) -> list[int]", + "Subset of order ids whose ship_days exceeded promised_days.", delayed_orders), + "unique_customers": ("unique_customers(order_ids: list[int]) -> list[int]", + "Unique customer ids among the given orders.", unique_customers), + "count_items": ("count_items(values: list) -> int", "Length of a list.", count_items), + "sum_values": ("sum_values(values: list[int]) -> int", "Sum a list of integers.", sum_values), + "count_true": ("count_true(values: list[bool]) -> int", "Count true values.", count_true), + "count_below": ("count_below(values: list[int], threshold: int) -> int", + "Count values below a threshold.", count_below), +} + +__all__ = [name for name in TOOLS.keys()] + ['TOOLS'] diff --git a/harbor/tasks/v3_depth2_order_count_t14/environment/task.json b/harbor/tasks/v3_depth2_order_count_t14/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..fa22687551e94e18fb0edcce3afc754d6d2a20cc --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t14/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_order_count_t14", + "depth": 2, + "family": "order_count", + "params": { + "region": "APAC", + "category": "C", + "month_start": 202602, + "month_end": 202606 + }, + "question": "How many paid/refunded orders are in region APAC, category C, from month 202602 through 202606? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_order_count_t14/instruction.md b/harbor/tasks/v3_depth2_order_count_t14/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..b66c81bac41f04142032e794d639fdfee8c9cd42 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t14/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +How many paid/refunded orders are in region APAC, category C, from month 202602 through 202606? Report the count. + +Available tools: +- `region_currency(region: str) -> str`: ISO currency code for a region. +- `get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]`: Paid/refunded order ids for a region, product category, and inclusive month window. +- `order_gross_usd(order_id: int) -> int`: Gross order revenue in USD before discounts/refunds. +- `order_margin_usd(order_id: int) -> int`: Gross order margin in USD before discounts/refunds. +- `refund_usd(order_id: int) -> int`: Refund amount in USD for returned quantity on an order. +- `customer_tier(order_id: int) -> str`: Customer loyalty tier for an order. +- `apply_discount(amount_usd: int, tier: str) -> int`: Apply the order customer's loyalty discount to a USD amount. +- `net_revenue_usd(order_id: int) -> int`: Net USD revenue after loyalty discount and refunds. +- `to_local(amount_usd: int, currency: str) -> int`: Convert a USD integer amount to a local-currency integer. +- `inventory_position(product_id: int, region: str) -> int`: Available inventory position: on_hand - reserved + inbound. +- `product_lead_time(product_id: int) -> int`: Supplier lead time in days for a product. +- `product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int`: Product id with the highest units sold in a region/category/month window. +- `units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int`: Units sold for one product in a region and month window. +- `tickets_for_orders(order_ids: list[int], severity: str) -> list[int]`: Support ticket ids for given orders and severity. +- `ticket_order_id(ticket_id: int) -> int`: Order id associated with a support ticket. +- `sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool`: Whether a support ticket breaches first-response or resolution SLA. +- `delayed_orders(order_ids: list[int]) -> list[int]`: Subset of order ids whose ship_days exceeded promised_days. +- `unique_customers(order_ids: list[int]) -> list[int]`: Unique customer ids among the given orders. +- `count_items(values: list) -> int`: Length of a list. +- `sum_values(values: list[int]) -> int`: Sum a list of integers. +- `count_true(values: list[bool]) -> int`: Count true values. +- `count_below(values: list[int], threshold: int) -> int`: Count values below a threshold. diff --git a/harbor/tasks/v3_depth2_order_count_t14/task.toml b/harbor/tasks/v3_depth2_order_count_t14/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..165fc225d193a3b93e4fb5cc3920c7878bb2638f --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t14/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_order_count_t14" +description = "FlowBench v3 public task metadata. Public verifier is smoke-only." +authors = [{ name = "Mind Lab", email = "contact@mindlab.ltd" }] +keywords = ["flowbench", "tool-use", "data-orchestration", "operations"] + +[metadata] +benchmark = "FlowBench-v3" +split = "public-task-only" +category = "data-processing" +depth = 2 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +network_mode = "no-network" +build_timeout_sec = 600.0 +os = "linux" +cpus = 1 +memory_mb = 2048 +storage_mb = 2048 +gpus = 0 diff --git a/harbor/tasks/v3_depth2_order_count_t14/tests/check_output_shape.py b/harbor/tasks/v3_depth2_order_count_t14/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t14/tests/check_output_shape.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import json +import os +import re +from pathlib import Path + + +def write_reward(score: float, diagnostic: str) -> None: + log_dir = Path(os.environ.get("LOG_DIR", "/logs/verifier")) + log_dir.mkdir(parents=True, exist_ok=True) + (log_dir / "reward.txt").write_text(f"{score:.6g}\n") + (log_dir / "reward.json").write_text( + json.dumps({"reward": score, "smoke_only": True}, indent=2) + "\n" + ) + (log_dir / "diagnostic.txt").write_text(diagnostic + "\n") + + +def main() -> int: + app_dir = Path(os.environ.get("APP_DIR", "/app")) + task = json.loads((app_dir / "task.json").read_text()) + answer_path = app_dir / "answer.txt" + if not answer_path.exists(): + write_reward(0.0, "missing /app/answer.txt") + return 1 + + got = answer_path.read_text().strip() + if task["answer_format"] == "exact integer": + ok = bool(re.fullmatch(r"-?\d+", got)) + diagnostic = "valid integer smoke output" if ok else f"not an exact integer: {got!r}" + else: + ok = bool(re.fullmatch(r"[A-Za-z]+", got)) + diagnostic = "valid code smoke output" if ok else f"not an exact code: {got!r}" + + # This is intentionally not official scoring; it only verifies I/O shape. + write_reward(1.0 if ok else 0.0, diagnostic) + return 0 if ok else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/harbor/tasks/v3_depth2_order_count_t14/tests/test.sh b/harbor/tasks/v3_depth2_order_count_t14/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t14/tests/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -u +python /tests/check_output_shape.py diff --git a/harbor/tasks/v3_depth2_order_count_t15/environment/Dockerfile b/harbor/tasks/v3_depth2_order_count_t15/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t15/environment/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.12-slim +WORKDIR /app +COPY flowbench_tools.py /app/flowbench_tools.py +COPY task.json /app/task.json diff --git a/harbor/tasks/v3_depth2_order_count_t15/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_order_count_t15/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t15/environment/flowbench_tools.py @@ -0,0 +1,311 @@ +"""Deterministic FlowBench v3 tools. This file contains no task answers.""" + + +REGIONS = ["NA", "EU", "APAC", "LATAM"] +CATEGORIES = ["A", "B", "C", "D"] +CURRENCIES = {"NA": "USD", "EU": "EUR", "APAC": "JPY", "LATAM": "BRL"} +FX_TO_USD_BP = {"USD": 10000, "EUR": 10900, "JPY": 67, "BRL": 1850} +TIERS = ["std", "gold", "plat"] +DISCOUNT_PCT = {"std": 0, "gold": 10, "plat": 20} +CHANNELS = ["web", "store", "partner"] +MONTHS = [202601, 202602, 202603, 202604, 202605, 202606] + +N_CUSTOMERS = 72 +N_PRODUCTS = 48 +N_ORDERS = 720 +N_TICKETS = 260 +N_RETURNS = 180 + + +def _h(*xs): + import hashlib + s = "|".join(str(x) for x in xs).encode() + return int.from_bytes(hashlib.sha256(s).digest()[:8], "big") & 0x7FFFFFFF + + +def build_data(): + customers = [] + for cid in range(N_CUSTOMERS): + region = REGIONS[_h("region", cid) % len(REGIONS)] + customers.append({ + "customer_id": cid, + "region": region, + "tier": TIERS[_h("tier", cid) % len(TIERS)], + "segment": ["consumer", "smb", "enterprise"][_h("segment", cid) % 3], + }) + + products = [] + for pid in range(N_PRODUCTS): + cat = CATEGORIES[_h("cat", pid) % len(CATEGORIES)] + unit_price = 12 + _h("price", pid) % 240 + cogs = unit_price * (45 + _h("margin", pid) % 35) // 100 + products.append({ + "product_id": pid, + "category": cat, + "unit_price_usd": unit_price, + "unit_cogs_usd": cogs, + "lead_time_days": 3 + _h("lead", pid) % 18, + }) + + inventory = [] + for pid in range(N_PRODUCTS): + for region in REGIONS: + inventory.append({ + "product_id": pid, + "region": region, + "on_hand": 10 + _h("onhand", pid, region) % 140, + "reserved": _h("reserved", pid, region) % 28, + "inbound": _h("inbound", pid, region) % 85, + }) + + orders = [] + for oid in range(N_ORDERS): + customer_id = _h("ocust", oid) % N_CUSTOMERS + product_id = _h("oprod", oid) % N_PRODUCTS + month = MONTHS[_h("month", oid) % len(MONTHS)] + qty = 1 + _h("qty", oid) % 9 + ship_days = 1 + _h("shipdays", oid) % 16 + promised_days = 3 + _h("promise", oid) % 9 + status = ["paid", "paid", "paid", "paid", "cancelled", "refunded"][ + _h("status", oid) % 6] + orders.append({ + "order_id": oid, + "customer_id": customer_id, + "product_id": product_id, + "month": month, + "qty": qty, + "status": status, + "channel": CHANNELS[_h("channel", oid) % len(CHANNELS)], + "ship_days": ship_days, + "promised_days": promised_days, + }) + + returns = [] + for rid in range(N_RETURNS): + oid = _h("roid", rid) % N_ORDERS + order = orders[oid] + if order["status"] == "cancelled": + continue + returned_qty = 1 + _h("rqty", rid) % max(1, order["qty"]) + reason = ["defect", "late", "changed_mind", "wrong_item"][_h("reason", rid) % 4] + returns.append({ + "return_id": rid, + "order_id": oid, + "month": MONTHS[_h("rmonth", rid) % len(MONTHS)], + "returned_qty": returned_qty, + "reason": reason, + }) + + tickets = [] + for tid in range(N_TICKETS): + oid = _h("toid", tid) % N_ORDERS + severity = ["low", "medium", "high", "critical"][_h("sev", tid) % 4] + opened = MONTHS[_h("tmonth", tid) % len(MONTHS)] + first_response_hours = 1 + _h("resp", tid) % 96 + resolution_hours = first_response_hours + _h("res", tid) % 240 + tickets.append({ + "ticket_id": tid, + "order_id": oid, + "opened_month": opened, + "severity": severity, + "first_response_hours": first_response_hours, + "resolution_hours": resolution_hours, + }) + + return { + "customers": customers, + "products": products, + "inventory": inventory, + "orders": orders, + "returns": returns, + "tickets": tickets, + "fx_to_usd_bp": FX_TO_USD_BP, + } + + +DATA = build_data() +CUSTOMERS = {c["customer_id"]: c for c in DATA["customers"]} +PRODUCTS = {p["product_id"]: p for p in DATA["products"]} +ORDERS = {o["order_id"]: o for o in DATA["orders"]} + + +def region_currency(region: str) -> str: + return CURRENCIES[region] + + +def get_orders(region: str, category: str, month_start: int, month_end: int) -> list: + """Paid/refunded order ids in a region/category/month window.""" + out = [] + for o in DATA["orders"]: + if o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + p = PRODUCTS[o["product_id"]] + if c["region"] == region and p["category"] == category and month_start <= o["month"] <= month_end: + out.append(o["order_id"]) + return sorted(out) + + +def order_gross_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * p["unit_price_usd"] + + +def order_margin_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * (p["unit_price_usd"] - p["unit_cogs_usd"]) + + +def refund_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + qty = sum(r["returned_qty"] for r in DATA["returns"] if r["order_id"] == order_id) + qty = min(qty, o["qty"]) + return qty * p["unit_price_usd"] + + +def customer_tier(order_id: int) -> str: + o = ORDERS[order_id] + return CUSTOMERS[o["customer_id"]]["tier"] + + +def apply_discount(amount_usd: int, tier: str) -> int: + return amount_usd * (100 - DISCOUNT_PCT[tier]) // 100 + + +def net_revenue_usd(order_id: int) -> int: + gross = apply_discount(order_gross_usd(order_id), customer_tier(order_id)) + return max(0, gross - refund_usd(order_id)) + + +def to_local(amount_usd: int, currency: str) -> int: + return amount_usd * 10000 // FX_TO_USD_BP[currency] + + +def inventory_position(product_id: int, region: str) -> int: + row = next(x for x in DATA["inventory"] + if x["product_id"] == product_id and x["region"] == region) + return row["on_hand"] - row["reserved"] + row["inbound"] + + +def product_lead_time(product_id: int) -> int: + return PRODUCTS[product_id]["lead_time_days"] + + +def product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int: + totals = {} + for oid in get_orders(region, category, month_start, month_end): + o = ORDERS[oid] + totals[o["product_id"]] = totals.get(o["product_id"], 0) + o["qty"] + if not totals: + return -1 + return min((-qty, pid) for pid, qty in totals.items())[1] + + +def units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int: + total = 0 + for o in DATA["orders"]: + if o["product_id"] != product_id or o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + if c["region"] == region and month_start <= o["month"] <= month_end: + total += o["qty"] + return total + + +def tickets_for_orders(order_ids: list, severity: str) -> list: + s = set(order_ids) + return sorted(t["ticket_id"] for t in DATA["tickets"] + if t["order_id"] in s and t["severity"] == severity) + + +def ticket_order_id(ticket_id: int) -> int: + return next(t["order_id"] for t in DATA["tickets"] if t["ticket_id"] == ticket_id) + + +def sla_breached(ticket_id: int, first_response_limit_hours: int, + resolution_limit_hours: int) -> bool: + t = next(x for x in DATA["tickets"] if x["ticket_id"] == ticket_id) + return (t["first_response_hours"] > first_response_limit_hours or + t["resolution_hours"] > resolution_limit_hours) + + +def delayed_orders(order_ids: list) -> list: + s = set(order_ids) + return sorted(o["order_id"] for o in DATA["orders"] + if o["order_id"] in s and o["ship_days"] > o["promised_days"]) + + +def unique_customers(order_ids: list) -> list: + return sorted({ORDERS[oid]["customer_id"] for oid in order_ids}) + + +def count_items(values: list) -> int: + return len(values) + + +def sum_values(values: list) -> int: + return sum(values) + + +def count_true(values: list) -> int: + return sum(1 for v in values if bool(v)) + + +def count_below(values: list, threshold: int) -> int: + return sum(1 for v in values if v < threshold) + + +TOOLS = { + "region_currency": ("region_currency(region: str) -> str", + "ISO currency code for a region.", region_currency), + "get_orders": ("get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]", + "Paid/refunded order ids for a region, product category, and inclusive month window.", + get_orders), + "order_gross_usd": ("order_gross_usd(order_id: int) -> int", + "Gross order revenue in USD before discounts/refunds.", order_gross_usd), + "order_margin_usd": ("order_margin_usd(order_id: int) -> int", + "Gross order margin in USD before discounts/refunds.", order_margin_usd), + "refund_usd": ("refund_usd(order_id: int) -> int", + "Refund amount in USD for returned quantity on an order.", refund_usd), + "customer_tier": ("customer_tier(order_id: int) -> str", + "Customer loyalty tier for an order.", customer_tier), + "apply_discount": ("apply_discount(amount_usd: int, tier: str) -> int", + "Apply the order customer's loyalty discount to a USD amount.", apply_discount), + "net_revenue_usd": ("net_revenue_usd(order_id: int) -> int", + "Net USD revenue after loyalty discount and refunds.", net_revenue_usd), + "to_local": ("to_local(amount_usd: int, currency: str) -> int", + "Convert a USD integer amount to a local-currency integer.", to_local), + "inventory_position": ("inventory_position(product_id: int, region: str) -> int", + "Available inventory position: on_hand - reserved + inbound.", + inventory_position), + "product_lead_time": ("product_lead_time(product_id: int) -> int", + "Supplier lead time in days for a product.", product_lead_time), + "product_id_for_top_seller": ( + "product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int", + "Product id with the highest units sold in a region/category/month window.", + product_id_for_top_seller), + "units_sold": ("units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int", + "Units sold for one product in a region and month window.", units_sold), + "tickets_for_orders": ("tickets_for_orders(order_ids: list[int], severity: str) -> list[int]", + "Support ticket ids for given orders and severity.", tickets_for_orders), + "ticket_order_id": ("ticket_order_id(ticket_id: int) -> int", + "Order id associated with a support ticket.", ticket_order_id), + "sla_breached": ( + "sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool", + "Whether a support ticket breaches first-response or resolution SLA.", + sla_breached), + "delayed_orders": ("delayed_orders(order_ids: list[int]) -> list[int]", + "Subset of order ids whose ship_days exceeded promised_days.", delayed_orders), + "unique_customers": ("unique_customers(order_ids: list[int]) -> list[int]", + "Unique customer ids among the given orders.", unique_customers), + "count_items": ("count_items(values: list) -> int", "Length of a list.", count_items), + "sum_values": ("sum_values(values: list[int]) -> int", "Sum a list of integers.", sum_values), + "count_true": ("count_true(values: list[bool]) -> int", "Count true values.", count_true), + "count_below": ("count_below(values: list[int], threshold: int) -> int", + "Count values below a threshold.", count_below), +} + +__all__ = [name for name in TOOLS.keys()] + ['TOOLS'] diff --git a/harbor/tasks/v3_depth2_order_count_t15/environment/task.json b/harbor/tasks/v3_depth2_order_count_t15/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..7582a6cb9dc19ce19bb6ec5c4758967f05251666 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t15/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_order_count_t15", + "depth": 2, + "family": "order_count", + "params": { + "region": "LATAM", + "category": "D", + "month_start": 202601, + "month_end": 202605 + }, + "question": "How many paid/refunded orders are in region LATAM, category D, from month 202601 through 202605? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_order_count_t15/instruction.md b/harbor/tasks/v3_depth2_order_count_t15/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..c8ccaf0f256489a4e141e7ddba8b94aeec3ee87b --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t15/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +How many paid/refunded orders are in region LATAM, category D, from month 202601 through 202605? Report the count. + +Available tools: +- `region_currency(region: str) -> str`: ISO currency code for a region. +- `get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]`: Paid/refunded order ids for a region, product category, and inclusive month window. +- `order_gross_usd(order_id: int) -> int`: Gross order revenue in USD before discounts/refunds. +- `order_margin_usd(order_id: int) -> int`: Gross order margin in USD before discounts/refunds. +- `refund_usd(order_id: int) -> int`: Refund amount in USD for returned quantity on an order. +- `customer_tier(order_id: int) -> str`: Customer loyalty tier for an order. +- `apply_discount(amount_usd: int, tier: str) -> int`: Apply the order customer's loyalty discount to a USD amount. +- `net_revenue_usd(order_id: int) -> int`: Net USD revenue after loyalty discount and refunds. +- `to_local(amount_usd: int, currency: str) -> int`: Convert a USD integer amount to a local-currency integer. +- `inventory_position(product_id: int, region: str) -> int`: Available inventory position: on_hand - reserved + inbound. +- `product_lead_time(product_id: int) -> int`: Supplier lead time in days for a product. +- `product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int`: Product id with the highest units sold in a region/category/month window. +- `units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int`: Units sold for one product in a region and month window. +- `tickets_for_orders(order_ids: list[int], severity: str) -> list[int]`: Support ticket ids for given orders and severity. +- `ticket_order_id(ticket_id: int) -> int`: Order id associated with a support ticket. +- `sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool`: Whether a support ticket breaches first-response or resolution SLA. +- `delayed_orders(order_ids: list[int]) -> list[int]`: Subset of order ids whose ship_days exceeded promised_days. +- `unique_customers(order_ids: list[int]) -> list[int]`: Unique customer ids among the given orders. +- `count_items(values: list) -> int`: Length of a list. +- `sum_values(values: list[int]) -> int`: Sum a list of integers. +- `count_true(values: list[bool]) -> int`: Count true values. +- `count_below(values: list[int], threshold: int) -> int`: Count values below a threshold. diff --git a/harbor/tasks/v3_depth2_order_count_t15/task.toml b/harbor/tasks/v3_depth2_order_count_t15/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..487bb7d25f9a8006648ac4070ca54fc53785a124 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t15/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_order_count_t15" +description = "FlowBench v3 public task metadata. Public verifier is smoke-only." +authors = [{ name = "Mind Lab", email = "contact@mindlab.ltd" }] +keywords = ["flowbench", "tool-use", "data-orchestration", "operations"] + +[metadata] +benchmark = "FlowBench-v3" +split = "public-task-only" +category = "data-processing" +depth = 2 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +network_mode = "no-network" +build_timeout_sec = 600.0 +os = "linux" +cpus = 1 +memory_mb = 2048 +storage_mb = 2048 +gpus = 0 diff --git a/harbor/tasks/v3_depth2_order_count_t15/tests/check_output_shape.py b/harbor/tasks/v3_depth2_order_count_t15/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t15/tests/check_output_shape.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import json +import os +import re +from pathlib import Path + + +def write_reward(score: float, diagnostic: str) -> None: + log_dir = Path(os.environ.get("LOG_DIR", "/logs/verifier")) + log_dir.mkdir(parents=True, exist_ok=True) + (log_dir / "reward.txt").write_text(f"{score:.6g}\n") + (log_dir / "reward.json").write_text( + json.dumps({"reward": score, "smoke_only": True}, indent=2) + "\n" + ) + (log_dir / "diagnostic.txt").write_text(diagnostic + "\n") + + +def main() -> int: + app_dir = Path(os.environ.get("APP_DIR", "/app")) + task = json.loads((app_dir / "task.json").read_text()) + answer_path = app_dir / "answer.txt" + if not answer_path.exists(): + write_reward(0.0, "missing /app/answer.txt") + return 1 + + got = answer_path.read_text().strip() + if task["answer_format"] == "exact integer": + ok = bool(re.fullmatch(r"-?\d+", got)) + diagnostic = "valid integer smoke output" if ok else f"not an exact integer: {got!r}" + else: + ok = bool(re.fullmatch(r"[A-Za-z]+", got)) + diagnostic = "valid code smoke output" if ok else f"not an exact code: {got!r}" + + # This is intentionally not official scoring; it only verifies I/O shape. + write_reward(1.0 if ok else 0.0, diagnostic) + return 0 if ok else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/harbor/tasks/v3_depth2_order_count_t15/tests/test.sh b/harbor/tasks/v3_depth2_order_count_t15/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t15/tests/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -u +python /tests/check_output_shape.py diff --git a/harbor/tasks/v3_depth2_order_count_t16/environment/Dockerfile b/harbor/tasks/v3_depth2_order_count_t16/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t16/environment/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.12-slim +WORKDIR /app +COPY flowbench_tools.py /app/flowbench_tools.py +COPY task.json /app/task.json diff --git a/harbor/tasks/v3_depth2_order_count_t16/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_order_count_t16/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t16/environment/flowbench_tools.py @@ -0,0 +1,311 @@ +"""Deterministic FlowBench v3 tools. This file contains no task answers.""" + + +REGIONS = ["NA", "EU", "APAC", "LATAM"] +CATEGORIES = ["A", "B", "C", "D"] +CURRENCIES = {"NA": "USD", "EU": "EUR", "APAC": "JPY", "LATAM": "BRL"} +FX_TO_USD_BP = {"USD": 10000, "EUR": 10900, "JPY": 67, "BRL": 1850} +TIERS = ["std", "gold", "plat"] +DISCOUNT_PCT = {"std": 0, "gold": 10, "plat": 20} +CHANNELS = ["web", "store", "partner"] +MONTHS = [202601, 202602, 202603, 202604, 202605, 202606] + +N_CUSTOMERS = 72 +N_PRODUCTS = 48 +N_ORDERS = 720 +N_TICKETS = 260 +N_RETURNS = 180 + + +def _h(*xs): + import hashlib + s = "|".join(str(x) for x in xs).encode() + return int.from_bytes(hashlib.sha256(s).digest()[:8], "big") & 0x7FFFFFFF + + +def build_data(): + customers = [] + for cid in range(N_CUSTOMERS): + region = REGIONS[_h("region", cid) % len(REGIONS)] + customers.append({ + "customer_id": cid, + "region": region, + "tier": TIERS[_h("tier", cid) % len(TIERS)], + "segment": ["consumer", "smb", "enterprise"][_h("segment", cid) % 3], + }) + + products = [] + for pid in range(N_PRODUCTS): + cat = CATEGORIES[_h("cat", pid) % len(CATEGORIES)] + unit_price = 12 + _h("price", pid) % 240 + cogs = unit_price * (45 + _h("margin", pid) % 35) // 100 + products.append({ + "product_id": pid, + "category": cat, + "unit_price_usd": unit_price, + "unit_cogs_usd": cogs, + "lead_time_days": 3 + _h("lead", pid) % 18, + }) + + inventory = [] + for pid in range(N_PRODUCTS): + for region in REGIONS: + inventory.append({ + "product_id": pid, + "region": region, + "on_hand": 10 + _h("onhand", pid, region) % 140, + "reserved": _h("reserved", pid, region) % 28, + "inbound": _h("inbound", pid, region) % 85, + }) + + orders = [] + for oid in range(N_ORDERS): + customer_id = _h("ocust", oid) % N_CUSTOMERS + product_id = _h("oprod", oid) % N_PRODUCTS + month = MONTHS[_h("month", oid) % len(MONTHS)] + qty = 1 + _h("qty", oid) % 9 + ship_days = 1 + _h("shipdays", oid) % 16 + promised_days = 3 + _h("promise", oid) % 9 + status = ["paid", "paid", "paid", "paid", "cancelled", "refunded"][ + _h("status", oid) % 6] + orders.append({ + "order_id": oid, + "customer_id": customer_id, + "product_id": product_id, + "month": month, + "qty": qty, + "status": status, + "channel": CHANNELS[_h("channel", oid) % len(CHANNELS)], + "ship_days": ship_days, + "promised_days": promised_days, + }) + + returns = [] + for rid in range(N_RETURNS): + oid = _h("roid", rid) % N_ORDERS + order = orders[oid] + if order["status"] == "cancelled": + continue + returned_qty = 1 + _h("rqty", rid) % max(1, order["qty"]) + reason = ["defect", "late", "changed_mind", "wrong_item"][_h("reason", rid) % 4] + returns.append({ + "return_id": rid, + "order_id": oid, + "month": MONTHS[_h("rmonth", rid) % len(MONTHS)], + "returned_qty": returned_qty, + "reason": reason, + }) + + tickets = [] + for tid in range(N_TICKETS): + oid = _h("toid", tid) % N_ORDERS + severity = ["low", "medium", "high", "critical"][_h("sev", tid) % 4] + opened = MONTHS[_h("tmonth", tid) % len(MONTHS)] + first_response_hours = 1 + _h("resp", tid) % 96 + resolution_hours = first_response_hours + _h("res", tid) % 240 + tickets.append({ + "ticket_id": tid, + "order_id": oid, + "opened_month": opened, + "severity": severity, + "first_response_hours": first_response_hours, + "resolution_hours": resolution_hours, + }) + + return { + "customers": customers, + "products": products, + "inventory": inventory, + "orders": orders, + "returns": returns, + "tickets": tickets, + "fx_to_usd_bp": FX_TO_USD_BP, + } + + +DATA = build_data() +CUSTOMERS = {c["customer_id"]: c for c in DATA["customers"]} +PRODUCTS = {p["product_id"]: p for p in DATA["products"]} +ORDERS = {o["order_id"]: o for o in DATA["orders"]} + + +def region_currency(region: str) -> str: + return CURRENCIES[region] + + +def get_orders(region: str, category: str, month_start: int, month_end: int) -> list: + """Paid/refunded order ids in a region/category/month window.""" + out = [] + for o in DATA["orders"]: + if o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + p = PRODUCTS[o["product_id"]] + if c["region"] == region and p["category"] == category and month_start <= o["month"] <= month_end: + out.append(o["order_id"]) + return sorted(out) + + +def order_gross_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * p["unit_price_usd"] + + +def order_margin_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * (p["unit_price_usd"] - p["unit_cogs_usd"]) + + +def refund_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + qty = sum(r["returned_qty"] for r in DATA["returns"] if r["order_id"] == order_id) + qty = min(qty, o["qty"]) + return qty * p["unit_price_usd"] + + +def customer_tier(order_id: int) -> str: + o = ORDERS[order_id] + return CUSTOMERS[o["customer_id"]]["tier"] + + +def apply_discount(amount_usd: int, tier: str) -> int: + return amount_usd * (100 - DISCOUNT_PCT[tier]) // 100 + + +def net_revenue_usd(order_id: int) -> int: + gross = apply_discount(order_gross_usd(order_id), customer_tier(order_id)) + return max(0, gross - refund_usd(order_id)) + + +def to_local(amount_usd: int, currency: str) -> int: + return amount_usd * 10000 // FX_TO_USD_BP[currency] + + +def inventory_position(product_id: int, region: str) -> int: + row = next(x for x in DATA["inventory"] + if x["product_id"] == product_id and x["region"] == region) + return row["on_hand"] - row["reserved"] + row["inbound"] + + +def product_lead_time(product_id: int) -> int: + return PRODUCTS[product_id]["lead_time_days"] + + +def product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int: + totals = {} + for oid in get_orders(region, category, month_start, month_end): + o = ORDERS[oid] + totals[o["product_id"]] = totals.get(o["product_id"], 0) + o["qty"] + if not totals: + return -1 + return min((-qty, pid) for pid, qty in totals.items())[1] + + +def units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int: + total = 0 + for o in DATA["orders"]: + if o["product_id"] != product_id or o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + if c["region"] == region and month_start <= o["month"] <= month_end: + total += o["qty"] + return total + + +def tickets_for_orders(order_ids: list, severity: str) -> list: + s = set(order_ids) + return sorted(t["ticket_id"] for t in DATA["tickets"] + if t["order_id"] in s and t["severity"] == severity) + + +def ticket_order_id(ticket_id: int) -> int: + return next(t["order_id"] for t in DATA["tickets"] if t["ticket_id"] == ticket_id) + + +def sla_breached(ticket_id: int, first_response_limit_hours: int, + resolution_limit_hours: int) -> bool: + t = next(x for x in DATA["tickets"] if x["ticket_id"] == ticket_id) + return (t["first_response_hours"] > first_response_limit_hours or + t["resolution_hours"] > resolution_limit_hours) + + +def delayed_orders(order_ids: list) -> list: + s = set(order_ids) + return sorted(o["order_id"] for o in DATA["orders"] + if o["order_id"] in s and o["ship_days"] > o["promised_days"]) + + +def unique_customers(order_ids: list) -> list: + return sorted({ORDERS[oid]["customer_id"] for oid in order_ids}) + + +def count_items(values: list) -> int: + return len(values) + + +def sum_values(values: list) -> int: + return sum(values) + + +def count_true(values: list) -> int: + return sum(1 for v in values if bool(v)) + + +def count_below(values: list, threshold: int) -> int: + return sum(1 for v in values if v < threshold) + + +TOOLS = { + "region_currency": ("region_currency(region: str) -> str", + "ISO currency code for a region.", region_currency), + "get_orders": ("get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]", + "Paid/refunded order ids for a region, product category, and inclusive month window.", + get_orders), + "order_gross_usd": ("order_gross_usd(order_id: int) -> int", + "Gross order revenue in USD before discounts/refunds.", order_gross_usd), + "order_margin_usd": ("order_margin_usd(order_id: int) -> int", + "Gross order margin in USD before discounts/refunds.", order_margin_usd), + "refund_usd": ("refund_usd(order_id: int) -> int", + "Refund amount in USD for returned quantity on an order.", refund_usd), + "customer_tier": ("customer_tier(order_id: int) -> str", + "Customer loyalty tier for an order.", customer_tier), + "apply_discount": ("apply_discount(amount_usd: int, tier: str) -> int", + "Apply the order customer's loyalty discount to a USD amount.", apply_discount), + "net_revenue_usd": ("net_revenue_usd(order_id: int) -> int", + "Net USD revenue after loyalty discount and refunds.", net_revenue_usd), + "to_local": ("to_local(amount_usd: int, currency: str) -> int", + "Convert a USD integer amount to a local-currency integer.", to_local), + "inventory_position": ("inventory_position(product_id: int, region: str) -> int", + "Available inventory position: on_hand - reserved + inbound.", + inventory_position), + "product_lead_time": ("product_lead_time(product_id: int) -> int", + "Supplier lead time in days for a product.", product_lead_time), + "product_id_for_top_seller": ( + "product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int", + "Product id with the highest units sold in a region/category/month window.", + product_id_for_top_seller), + "units_sold": ("units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int", + "Units sold for one product in a region and month window.", units_sold), + "tickets_for_orders": ("tickets_for_orders(order_ids: list[int], severity: str) -> list[int]", + "Support ticket ids for given orders and severity.", tickets_for_orders), + "ticket_order_id": ("ticket_order_id(ticket_id: int) -> int", + "Order id associated with a support ticket.", ticket_order_id), + "sla_breached": ( + "sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool", + "Whether a support ticket breaches first-response or resolution SLA.", + sla_breached), + "delayed_orders": ("delayed_orders(order_ids: list[int]) -> list[int]", + "Subset of order ids whose ship_days exceeded promised_days.", delayed_orders), + "unique_customers": ("unique_customers(order_ids: list[int]) -> list[int]", + "Unique customer ids among the given orders.", unique_customers), + "count_items": ("count_items(values: list) -> int", "Length of a list.", count_items), + "sum_values": ("sum_values(values: list[int]) -> int", "Sum a list of integers.", sum_values), + "count_true": ("count_true(values: list[bool]) -> int", "Count true values.", count_true), + "count_below": ("count_below(values: list[int], threshold: int) -> int", + "Count values below a threshold.", count_below), +} + +__all__ = [name for name in TOOLS.keys()] + ['TOOLS'] diff --git a/harbor/tasks/v3_depth2_order_count_t16/environment/task.json b/harbor/tasks/v3_depth2_order_count_t16/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..3b077d04a3104fd774cc1619f6e85a3b21660153 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t16/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_order_count_t16", + "depth": 2, + "family": "order_count", + "params": { + "region": "NA", + "category": "A", + "month_start": 202604, + "month_end": 202606 + }, + "question": "How many paid/refunded orders are in region NA, category A, from month 202604 through 202606? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_order_count_t16/instruction.md b/harbor/tasks/v3_depth2_order_count_t16/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..539f3ed79a5e971f58e75483123b07e1b3e0000c --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t16/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +How many paid/refunded orders are in region NA, category A, from month 202604 through 202606? Report the count. + +Available tools: +- `region_currency(region: str) -> str`: ISO currency code for a region. +- `get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]`: Paid/refunded order ids for a region, product category, and inclusive month window. +- `order_gross_usd(order_id: int) -> int`: Gross order revenue in USD before discounts/refunds. +- `order_margin_usd(order_id: int) -> int`: Gross order margin in USD before discounts/refunds. +- `refund_usd(order_id: int) -> int`: Refund amount in USD for returned quantity on an order. +- `customer_tier(order_id: int) -> str`: Customer loyalty tier for an order. +- `apply_discount(amount_usd: int, tier: str) -> int`: Apply the order customer's loyalty discount to a USD amount. +- `net_revenue_usd(order_id: int) -> int`: Net USD revenue after loyalty discount and refunds. +- `to_local(amount_usd: int, currency: str) -> int`: Convert a USD integer amount to a local-currency integer. +- `inventory_position(product_id: int, region: str) -> int`: Available inventory position: on_hand - reserved + inbound. +- `product_lead_time(product_id: int) -> int`: Supplier lead time in days for a product. +- `product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int`: Product id with the highest units sold in a region/category/month window. +- `units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int`: Units sold for one product in a region and month window. +- `tickets_for_orders(order_ids: list[int], severity: str) -> list[int]`: Support ticket ids for given orders and severity. +- `ticket_order_id(ticket_id: int) -> int`: Order id associated with a support ticket. +- `sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool`: Whether a support ticket breaches first-response or resolution SLA. +- `delayed_orders(order_ids: list[int]) -> list[int]`: Subset of order ids whose ship_days exceeded promised_days. +- `unique_customers(order_ids: list[int]) -> list[int]`: Unique customer ids among the given orders. +- `count_items(values: list) -> int`: Length of a list. +- `sum_values(values: list[int]) -> int`: Sum a list of integers. +- `count_true(values: list[bool]) -> int`: Count true values. +- `count_below(values: list[int], threshold: int) -> int`: Count values below a threshold. diff --git a/harbor/tasks/v3_depth2_order_count_t16/task.toml b/harbor/tasks/v3_depth2_order_count_t16/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..60019aa9dd1fe092927576b31fb8b3b3f8c36860 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t16/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_order_count_t16" +description = "FlowBench v3 public task metadata. Public verifier is smoke-only." +authors = [{ name = "Mind Lab", email = "contact@mindlab.ltd" }] +keywords = ["flowbench", "tool-use", "data-orchestration", "operations"] + +[metadata] +benchmark = "FlowBench-v3" +split = "public-task-only" +category = "data-processing" +depth = 2 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +network_mode = "no-network" +build_timeout_sec = 600.0 +os = "linux" +cpus = 1 +memory_mb = 2048 +storage_mb = 2048 +gpus = 0 diff --git a/harbor/tasks/v3_depth2_order_count_t16/tests/check_output_shape.py b/harbor/tasks/v3_depth2_order_count_t16/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t16/tests/check_output_shape.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import json +import os +import re +from pathlib import Path + + +def write_reward(score: float, diagnostic: str) -> None: + log_dir = Path(os.environ.get("LOG_DIR", "/logs/verifier")) + log_dir.mkdir(parents=True, exist_ok=True) + (log_dir / "reward.txt").write_text(f"{score:.6g}\n") + (log_dir / "reward.json").write_text( + json.dumps({"reward": score, "smoke_only": True}, indent=2) + "\n" + ) + (log_dir / "diagnostic.txt").write_text(diagnostic + "\n") + + +def main() -> int: + app_dir = Path(os.environ.get("APP_DIR", "/app")) + task = json.loads((app_dir / "task.json").read_text()) + answer_path = app_dir / "answer.txt" + if not answer_path.exists(): + write_reward(0.0, "missing /app/answer.txt") + return 1 + + got = answer_path.read_text().strip() + if task["answer_format"] == "exact integer": + ok = bool(re.fullmatch(r"-?\d+", got)) + diagnostic = "valid integer smoke output" if ok else f"not an exact integer: {got!r}" + else: + ok = bool(re.fullmatch(r"[A-Za-z]+", got)) + diagnostic = "valid code smoke output" if ok else f"not an exact code: {got!r}" + + # This is intentionally not official scoring; it only verifies I/O shape. + write_reward(1.0 if ok else 0.0, diagnostic) + return 0 if ok else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/harbor/tasks/v3_depth2_order_count_t16/tests/test.sh b/harbor/tasks/v3_depth2_order_count_t16/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t16/tests/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -u +python /tests/check_output_shape.py diff --git a/harbor/tasks/v3_depth2_order_count_t17/environment/Dockerfile b/harbor/tasks/v3_depth2_order_count_t17/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t17/environment/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.12-slim +WORKDIR /app +COPY flowbench_tools.py /app/flowbench_tools.py +COPY task.json /app/task.json diff --git a/harbor/tasks/v3_depth2_order_count_t17/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_order_count_t17/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t17/environment/flowbench_tools.py @@ -0,0 +1,311 @@ +"""Deterministic FlowBench v3 tools. This file contains no task answers.""" + + +REGIONS = ["NA", "EU", "APAC", "LATAM"] +CATEGORIES = ["A", "B", "C", "D"] +CURRENCIES = {"NA": "USD", "EU": "EUR", "APAC": "JPY", "LATAM": "BRL"} +FX_TO_USD_BP = {"USD": 10000, "EUR": 10900, "JPY": 67, "BRL": 1850} +TIERS = ["std", "gold", "plat"] +DISCOUNT_PCT = {"std": 0, "gold": 10, "plat": 20} +CHANNELS = ["web", "store", "partner"] +MONTHS = [202601, 202602, 202603, 202604, 202605, 202606] + +N_CUSTOMERS = 72 +N_PRODUCTS = 48 +N_ORDERS = 720 +N_TICKETS = 260 +N_RETURNS = 180 + + +def _h(*xs): + import hashlib + s = "|".join(str(x) for x in xs).encode() + return int.from_bytes(hashlib.sha256(s).digest()[:8], "big") & 0x7FFFFFFF + + +def build_data(): + customers = [] + for cid in range(N_CUSTOMERS): + region = REGIONS[_h("region", cid) % len(REGIONS)] + customers.append({ + "customer_id": cid, + "region": region, + "tier": TIERS[_h("tier", cid) % len(TIERS)], + "segment": ["consumer", "smb", "enterprise"][_h("segment", cid) % 3], + }) + + products = [] + for pid in range(N_PRODUCTS): + cat = CATEGORIES[_h("cat", pid) % len(CATEGORIES)] + unit_price = 12 + _h("price", pid) % 240 + cogs = unit_price * (45 + _h("margin", pid) % 35) // 100 + products.append({ + "product_id": pid, + "category": cat, + "unit_price_usd": unit_price, + "unit_cogs_usd": cogs, + "lead_time_days": 3 + _h("lead", pid) % 18, + }) + + inventory = [] + for pid in range(N_PRODUCTS): + for region in REGIONS: + inventory.append({ + "product_id": pid, + "region": region, + "on_hand": 10 + _h("onhand", pid, region) % 140, + "reserved": _h("reserved", pid, region) % 28, + "inbound": _h("inbound", pid, region) % 85, + }) + + orders = [] + for oid in range(N_ORDERS): + customer_id = _h("ocust", oid) % N_CUSTOMERS + product_id = _h("oprod", oid) % N_PRODUCTS + month = MONTHS[_h("month", oid) % len(MONTHS)] + qty = 1 + _h("qty", oid) % 9 + ship_days = 1 + _h("shipdays", oid) % 16 + promised_days = 3 + _h("promise", oid) % 9 + status = ["paid", "paid", "paid", "paid", "cancelled", "refunded"][ + _h("status", oid) % 6] + orders.append({ + "order_id": oid, + "customer_id": customer_id, + "product_id": product_id, + "month": month, + "qty": qty, + "status": status, + "channel": CHANNELS[_h("channel", oid) % len(CHANNELS)], + "ship_days": ship_days, + "promised_days": promised_days, + }) + + returns = [] + for rid in range(N_RETURNS): + oid = _h("roid", rid) % N_ORDERS + order = orders[oid] + if order["status"] == "cancelled": + continue + returned_qty = 1 + _h("rqty", rid) % max(1, order["qty"]) + reason = ["defect", "late", "changed_mind", "wrong_item"][_h("reason", rid) % 4] + returns.append({ + "return_id": rid, + "order_id": oid, + "month": MONTHS[_h("rmonth", rid) % len(MONTHS)], + "returned_qty": returned_qty, + "reason": reason, + }) + + tickets = [] + for tid in range(N_TICKETS): + oid = _h("toid", tid) % N_ORDERS + severity = ["low", "medium", "high", "critical"][_h("sev", tid) % 4] + opened = MONTHS[_h("tmonth", tid) % len(MONTHS)] + first_response_hours = 1 + _h("resp", tid) % 96 + resolution_hours = first_response_hours + _h("res", tid) % 240 + tickets.append({ + "ticket_id": tid, + "order_id": oid, + "opened_month": opened, + "severity": severity, + "first_response_hours": first_response_hours, + "resolution_hours": resolution_hours, + }) + + return { + "customers": customers, + "products": products, + "inventory": inventory, + "orders": orders, + "returns": returns, + "tickets": tickets, + "fx_to_usd_bp": FX_TO_USD_BP, + } + + +DATA = build_data() +CUSTOMERS = {c["customer_id"]: c for c in DATA["customers"]} +PRODUCTS = {p["product_id"]: p for p in DATA["products"]} +ORDERS = {o["order_id"]: o for o in DATA["orders"]} + + +def region_currency(region: str) -> str: + return CURRENCIES[region] + + +def get_orders(region: str, category: str, month_start: int, month_end: int) -> list: + """Paid/refunded order ids in a region/category/month window.""" + out = [] + for o in DATA["orders"]: + if o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + p = PRODUCTS[o["product_id"]] + if c["region"] == region and p["category"] == category and month_start <= o["month"] <= month_end: + out.append(o["order_id"]) + return sorted(out) + + +def order_gross_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * p["unit_price_usd"] + + +def order_margin_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * (p["unit_price_usd"] - p["unit_cogs_usd"]) + + +def refund_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + qty = sum(r["returned_qty"] for r in DATA["returns"] if r["order_id"] == order_id) + qty = min(qty, o["qty"]) + return qty * p["unit_price_usd"] + + +def customer_tier(order_id: int) -> str: + o = ORDERS[order_id] + return CUSTOMERS[o["customer_id"]]["tier"] + + +def apply_discount(amount_usd: int, tier: str) -> int: + return amount_usd * (100 - DISCOUNT_PCT[tier]) // 100 + + +def net_revenue_usd(order_id: int) -> int: + gross = apply_discount(order_gross_usd(order_id), customer_tier(order_id)) + return max(0, gross - refund_usd(order_id)) + + +def to_local(amount_usd: int, currency: str) -> int: + return amount_usd * 10000 // FX_TO_USD_BP[currency] + + +def inventory_position(product_id: int, region: str) -> int: + row = next(x for x in DATA["inventory"] + if x["product_id"] == product_id and x["region"] == region) + return row["on_hand"] - row["reserved"] + row["inbound"] + + +def product_lead_time(product_id: int) -> int: + return PRODUCTS[product_id]["lead_time_days"] + + +def product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int: + totals = {} + for oid in get_orders(region, category, month_start, month_end): + o = ORDERS[oid] + totals[o["product_id"]] = totals.get(o["product_id"], 0) + o["qty"] + if not totals: + return -1 + return min((-qty, pid) for pid, qty in totals.items())[1] + + +def units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int: + total = 0 + for o in DATA["orders"]: + if o["product_id"] != product_id or o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + if c["region"] == region and month_start <= o["month"] <= month_end: + total += o["qty"] + return total + + +def tickets_for_orders(order_ids: list, severity: str) -> list: + s = set(order_ids) + return sorted(t["ticket_id"] for t in DATA["tickets"] + if t["order_id"] in s and t["severity"] == severity) + + +def ticket_order_id(ticket_id: int) -> int: + return next(t["order_id"] for t in DATA["tickets"] if t["ticket_id"] == ticket_id) + + +def sla_breached(ticket_id: int, first_response_limit_hours: int, + resolution_limit_hours: int) -> bool: + t = next(x for x in DATA["tickets"] if x["ticket_id"] == ticket_id) + return (t["first_response_hours"] > first_response_limit_hours or + t["resolution_hours"] > resolution_limit_hours) + + +def delayed_orders(order_ids: list) -> list: + s = set(order_ids) + return sorted(o["order_id"] for o in DATA["orders"] + if o["order_id"] in s and o["ship_days"] > o["promised_days"]) + + +def unique_customers(order_ids: list) -> list: + return sorted({ORDERS[oid]["customer_id"] for oid in order_ids}) + + +def count_items(values: list) -> int: + return len(values) + + +def sum_values(values: list) -> int: + return sum(values) + + +def count_true(values: list) -> int: + return sum(1 for v in values if bool(v)) + + +def count_below(values: list, threshold: int) -> int: + return sum(1 for v in values if v < threshold) + + +TOOLS = { + "region_currency": ("region_currency(region: str) -> str", + "ISO currency code for a region.", region_currency), + "get_orders": ("get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]", + "Paid/refunded order ids for a region, product category, and inclusive month window.", + get_orders), + "order_gross_usd": ("order_gross_usd(order_id: int) -> int", + "Gross order revenue in USD before discounts/refunds.", order_gross_usd), + "order_margin_usd": ("order_margin_usd(order_id: int) -> int", + "Gross order margin in USD before discounts/refunds.", order_margin_usd), + "refund_usd": ("refund_usd(order_id: int) -> int", + "Refund amount in USD for returned quantity on an order.", refund_usd), + "customer_tier": ("customer_tier(order_id: int) -> str", + "Customer loyalty tier for an order.", customer_tier), + "apply_discount": ("apply_discount(amount_usd: int, tier: str) -> int", + "Apply the order customer's loyalty discount to a USD amount.", apply_discount), + "net_revenue_usd": ("net_revenue_usd(order_id: int) -> int", + "Net USD revenue after loyalty discount and refunds.", net_revenue_usd), + "to_local": ("to_local(amount_usd: int, currency: str) -> int", + "Convert a USD integer amount to a local-currency integer.", to_local), + "inventory_position": ("inventory_position(product_id: int, region: str) -> int", + "Available inventory position: on_hand - reserved + inbound.", + inventory_position), + "product_lead_time": ("product_lead_time(product_id: int) -> int", + "Supplier lead time in days for a product.", product_lead_time), + "product_id_for_top_seller": ( + "product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int", + "Product id with the highest units sold in a region/category/month window.", + product_id_for_top_seller), + "units_sold": ("units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int", + "Units sold for one product in a region and month window.", units_sold), + "tickets_for_orders": ("tickets_for_orders(order_ids: list[int], severity: str) -> list[int]", + "Support ticket ids for given orders and severity.", tickets_for_orders), + "ticket_order_id": ("ticket_order_id(ticket_id: int) -> int", + "Order id associated with a support ticket.", ticket_order_id), + "sla_breached": ( + "sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool", + "Whether a support ticket breaches first-response or resolution SLA.", + sla_breached), + "delayed_orders": ("delayed_orders(order_ids: list[int]) -> list[int]", + "Subset of order ids whose ship_days exceeded promised_days.", delayed_orders), + "unique_customers": ("unique_customers(order_ids: list[int]) -> list[int]", + "Unique customer ids among the given orders.", unique_customers), + "count_items": ("count_items(values: list) -> int", "Length of a list.", count_items), + "sum_values": ("sum_values(values: list[int]) -> int", "Sum a list of integers.", sum_values), + "count_true": ("count_true(values: list[bool]) -> int", "Count true values.", count_true), + "count_below": ("count_below(values: list[int], threshold: int) -> int", + "Count values below a threshold.", count_below), +} + +__all__ = [name for name in TOOLS.keys()] + ['TOOLS'] diff --git a/harbor/tasks/v3_depth2_order_count_t17/environment/task.json b/harbor/tasks/v3_depth2_order_count_t17/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..37ff947b9490c33b6621d951d32598596f4e2807 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t17/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_order_count_t17", + "depth": 2, + "family": "order_count", + "params": { + "region": "EU", + "category": "D", + "month_start": 202601, + "month_end": 202602 + }, + "question": "How many paid/refunded orders are in region EU, category D, from month 202601 through 202602? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_order_count_t17/instruction.md b/harbor/tasks/v3_depth2_order_count_t17/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..13a904336c82555541be4e05c4b4ca688c7a15ac --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t17/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +How many paid/refunded orders are in region EU, category D, from month 202601 through 202602? Report the count. + +Available tools: +- `region_currency(region: str) -> str`: ISO currency code for a region. +- `get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]`: Paid/refunded order ids for a region, product category, and inclusive month window. +- `order_gross_usd(order_id: int) -> int`: Gross order revenue in USD before discounts/refunds. +- `order_margin_usd(order_id: int) -> int`: Gross order margin in USD before discounts/refunds. +- `refund_usd(order_id: int) -> int`: Refund amount in USD for returned quantity on an order. +- `customer_tier(order_id: int) -> str`: Customer loyalty tier for an order. +- `apply_discount(amount_usd: int, tier: str) -> int`: Apply the order customer's loyalty discount to a USD amount. +- `net_revenue_usd(order_id: int) -> int`: Net USD revenue after loyalty discount and refunds. +- `to_local(amount_usd: int, currency: str) -> int`: Convert a USD integer amount to a local-currency integer. +- `inventory_position(product_id: int, region: str) -> int`: Available inventory position: on_hand - reserved + inbound. +- `product_lead_time(product_id: int) -> int`: Supplier lead time in days for a product. +- `product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int`: Product id with the highest units sold in a region/category/month window. +- `units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int`: Units sold for one product in a region and month window. +- `tickets_for_orders(order_ids: list[int], severity: str) -> list[int]`: Support ticket ids for given orders and severity. +- `ticket_order_id(ticket_id: int) -> int`: Order id associated with a support ticket. +- `sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool`: Whether a support ticket breaches first-response or resolution SLA. +- `delayed_orders(order_ids: list[int]) -> list[int]`: Subset of order ids whose ship_days exceeded promised_days. +- `unique_customers(order_ids: list[int]) -> list[int]`: Unique customer ids among the given orders. +- `count_items(values: list) -> int`: Length of a list. +- `sum_values(values: list[int]) -> int`: Sum a list of integers. +- `count_true(values: list[bool]) -> int`: Count true values. +- `count_below(values: list[int], threshold: int) -> int`: Count values below a threshold. diff --git a/harbor/tasks/v3_depth2_order_count_t17/task.toml b/harbor/tasks/v3_depth2_order_count_t17/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..b66537d33757499daf17c9a99ff8c4c5b6574353 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t17/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_order_count_t17" +description = "FlowBench v3 public task metadata. Public verifier is smoke-only." +authors = [{ name = "Mind Lab", email = "contact@mindlab.ltd" }] +keywords = ["flowbench", "tool-use", "data-orchestration", "operations"] + +[metadata] +benchmark = "FlowBench-v3" +split = "public-task-only" +category = "data-processing" +depth = 2 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +network_mode = "no-network" +build_timeout_sec = 600.0 +os = "linux" +cpus = 1 +memory_mb = 2048 +storage_mb = 2048 +gpus = 0 diff --git a/harbor/tasks/v3_depth2_order_count_t17/tests/check_output_shape.py b/harbor/tasks/v3_depth2_order_count_t17/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t17/tests/check_output_shape.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import json +import os +import re +from pathlib import Path + + +def write_reward(score: float, diagnostic: str) -> None: + log_dir = Path(os.environ.get("LOG_DIR", "/logs/verifier")) + log_dir.mkdir(parents=True, exist_ok=True) + (log_dir / "reward.txt").write_text(f"{score:.6g}\n") + (log_dir / "reward.json").write_text( + json.dumps({"reward": score, "smoke_only": True}, indent=2) + "\n" + ) + (log_dir / "diagnostic.txt").write_text(diagnostic + "\n") + + +def main() -> int: + app_dir = Path(os.environ.get("APP_DIR", "/app")) + task = json.loads((app_dir / "task.json").read_text()) + answer_path = app_dir / "answer.txt" + if not answer_path.exists(): + write_reward(0.0, "missing /app/answer.txt") + return 1 + + got = answer_path.read_text().strip() + if task["answer_format"] == "exact integer": + ok = bool(re.fullmatch(r"-?\d+", got)) + diagnostic = "valid integer smoke output" if ok else f"not an exact integer: {got!r}" + else: + ok = bool(re.fullmatch(r"[A-Za-z]+", got)) + diagnostic = "valid code smoke output" if ok else f"not an exact code: {got!r}" + + # This is intentionally not official scoring; it only verifies I/O shape. + write_reward(1.0 if ok else 0.0, diagnostic) + return 0 if ok else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/harbor/tasks/v3_depth2_order_count_t17/tests/test.sh b/harbor/tasks/v3_depth2_order_count_t17/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t17/tests/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -u +python /tests/check_output_shape.py diff --git a/harbor/tasks/v3_depth2_order_count_t18/environment/Dockerfile b/harbor/tasks/v3_depth2_order_count_t18/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t18/environment/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.12-slim +WORKDIR /app +COPY flowbench_tools.py /app/flowbench_tools.py +COPY task.json /app/task.json diff --git a/harbor/tasks/v3_depth2_order_count_t18/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_order_count_t18/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t18/environment/flowbench_tools.py @@ -0,0 +1,311 @@ +"""Deterministic FlowBench v3 tools. This file contains no task answers.""" + + +REGIONS = ["NA", "EU", "APAC", "LATAM"] +CATEGORIES = ["A", "B", "C", "D"] +CURRENCIES = {"NA": "USD", "EU": "EUR", "APAC": "JPY", "LATAM": "BRL"} +FX_TO_USD_BP = {"USD": 10000, "EUR": 10900, "JPY": 67, "BRL": 1850} +TIERS = ["std", "gold", "plat"] +DISCOUNT_PCT = {"std": 0, "gold": 10, "plat": 20} +CHANNELS = ["web", "store", "partner"] +MONTHS = [202601, 202602, 202603, 202604, 202605, 202606] + +N_CUSTOMERS = 72 +N_PRODUCTS = 48 +N_ORDERS = 720 +N_TICKETS = 260 +N_RETURNS = 180 + + +def _h(*xs): + import hashlib + s = "|".join(str(x) for x in xs).encode() + return int.from_bytes(hashlib.sha256(s).digest()[:8], "big") & 0x7FFFFFFF + + +def build_data(): + customers = [] + for cid in range(N_CUSTOMERS): + region = REGIONS[_h("region", cid) % len(REGIONS)] + customers.append({ + "customer_id": cid, + "region": region, + "tier": TIERS[_h("tier", cid) % len(TIERS)], + "segment": ["consumer", "smb", "enterprise"][_h("segment", cid) % 3], + }) + + products = [] + for pid in range(N_PRODUCTS): + cat = CATEGORIES[_h("cat", pid) % len(CATEGORIES)] + unit_price = 12 + _h("price", pid) % 240 + cogs = unit_price * (45 + _h("margin", pid) % 35) // 100 + products.append({ + "product_id": pid, + "category": cat, + "unit_price_usd": unit_price, + "unit_cogs_usd": cogs, + "lead_time_days": 3 + _h("lead", pid) % 18, + }) + + inventory = [] + for pid in range(N_PRODUCTS): + for region in REGIONS: + inventory.append({ + "product_id": pid, + "region": region, + "on_hand": 10 + _h("onhand", pid, region) % 140, + "reserved": _h("reserved", pid, region) % 28, + "inbound": _h("inbound", pid, region) % 85, + }) + + orders = [] + for oid in range(N_ORDERS): + customer_id = _h("ocust", oid) % N_CUSTOMERS + product_id = _h("oprod", oid) % N_PRODUCTS + month = MONTHS[_h("month", oid) % len(MONTHS)] + qty = 1 + _h("qty", oid) % 9 + ship_days = 1 + _h("shipdays", oid) % 16 + promised_days = 3 + _h("promise", oid) % 9 + status = ["paid", "paid", "paid", "paid", "cancelled", "refunded"][ + _h("status", oid) % 6] + orders.append({ + "order_id": oid, + "customer_id": customer_id, + "product_id": product_id, + "month": month, + "qty": qty, + "status": status, + "channel": CHANNELS[_h("channel", oid) % len(CHANNELS)], + "ship_days": ship_days, + "promised_days": promised_days, + }) + + returns = [] + for rid in range(N_RETURNS): + oid = _h("roid", rid) % N_ORDERS + order = orders[oid] + if order["status"] == "cancelled": + continue + returned_qty = 1 + _h("rqty", rid) % max(1, order["qty"]) + reason = ["defect", "late", "changed_mind", "wrong_item"][_h("reason", rid) % 4] + returns.append({ + "return_id": rid, + "order_id": oid, + "month": MONTHS[_h("rmonth", rid) % len(MONTHS)], + "returned_qty": returned_qty, + "reason": reason, + }) + + tickets = [] + for tid in range(N_TICKETS): + oid = _h("toid", tid) % N_ORDERS + severity = ["low", "medium", "high", "critical"][_h("sev", tid) % 4] + opened = MONTHS[_h("tmonth", tid) % len(MONTHS)] + first_response_hours = 1 + _h("resp", tid) % 96 + resolution_hours = first_response_hours + _h("res", tid) % 240 + tickets.append({ + "ticket_id": tid, + "order_id": oid, + "opened_month": opened, + "severity": severity, + "first_response_hours": first_response_hours, + "resolution_hours": resolution_hours, + }) + + return { + "customers": customers, + "products": products, + "inventory": inventory, + "orders": orders, + "returns": returns, + "tickets": tickets, + "fx_to_usd_bp": FX_TO_USD_BP, + } + + +DATA = build_data() +CUSTOMERS = {c["customer_id"]: c for c in DATA["customers"]} +PRODUCTS = {p["product_id"]: p for p in DATA["products"]} +ORDERS = {o["order_id"]: o for o in DATA["orders"]} + + +def region_currency(region: str) -> str: + return CURRENCIES[region] + + +def get_orders(region: str, category: str, month_start: int, month_end: int) -> list: + """Paid/refunded order ids in a region/category/month window.""" + out = [] + for o in DATA["orders"]: + if o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + p = PRODUCTS[o["product_id"]] + if c["region"] == region and p["category"] == category and month_start <= o["month"] <= month_end: + out.append(o["order_id"]) + return sorted(out) + + +def order_gross_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * p["unit_price_usd"] + + +def order_margin_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * (p["unit_price_usd"] - p["unit_cogs_usd"]) + + +def refund_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + qty = sum(r["returned_qty"] for r in DATA["returns"] if r["order_id"] == order_id) + qty = min(qty, o["qty"]) + return qty * p["unit_price_usd"] + + +def customer_tier(order_id: int) -> str: + o = ORDERS[order_id] + return CUSTOMERS[o["customer_id"]]["tier"] + + +def apply_discount(amount_usd: int, tier: str) -> int: + return amount_usd * (100 - DISCOUNT_PCT[tier]) // 100 + + +def net_revenue_usd(order_id: int) -> int: + gross = apply_discount(order_gross_usd(order_id), customer_tier(order_id)) + return max(0, gross - refund_usd(order_id)) + + +def to_local(amount_usd: int, currency: str) -> int: + return amount_usd * 10000 // FX_TO_USD_BP[currency] + + +def inventory_position(product_id: int, region: str) -> int: + row = next(x for x in DATA["inventory"] + if x["product_id"] == product_id and x["region"] == region) + return row["on_hand"] - row["reserved"] + row["inbound"] + + +def product_lead_time(product_id: int) -> int: + return PRODUCTS[product_id]["lead_time_days"] + + +def product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int: + totals = {} + for oid in get_orders(region, category, month_start, month_end): + o = ORDERS[oid] + totals[o["product_id"]] = totals.get(o["product_id"], 0) + o["qty"] + if not totals: + return -1 + return min((-qty, pid) for pid, qty in totals.items())[1] + + +def units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int: + total = 0 + for o in DATA["orders"]: + if o["product_id"] != product_id or o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + if c["region"] == region and month_start <= o["month"] <= month_end: + total += o["qty"] + return total + + +def tickets_for_orders(order_ids: list, severity: str) -> list: + s = set(order_ids) + return sorted(t["ticket_id"] for t in DATA["tickets"] + if t["order_id"] in s and t["severity"] == severity) + + +def ticket_order_id(ticket_id: int) -> int: + return next(t["order_id"] for t in DATA["tickets"] if t["ticket_id"] == ticket_id) + + +def sla_breached(ticket_id: int, first_response_limit_hours: int, + resolution_limit_hours: int) -> bool: + t = next(x for x in DATA["tickets"] if x["ticket_id"] == ticket_id) + return (t["first_response_hours"] > first_response_limit_hours or + t["resolution_hours"] > resolution_limit_hours) + + +def delayed_orders(order_ids: list) -> list: + s = set(order_ids) + return sorted(o["order_id"] for o in DATA["orders"] + if o["order_id"] in s and o["ship_days"] > o["promised_days"]) + + +def unique_customers(order_ids: list) -> list: + return sorted({ORDERS[oid]["customer_id"] for oid in order_ids}) + + +def count_items(values: list) -> int: + return len(values) + + +def sum_values(values: list) -> int: + return sum(values) + + +def count_true(values: list) -> int: + return sum(1 for v in values if bool(v)) + + +def count_below(values: list, threshold: int) -> int: + return sum(1 for v in values if v < threshold) + + +TOOLS = { + "region_currency": ("region_currency(region: str) -> str", + "ISO currency code for a region.", region_currency), + "get_orders": ("get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]", + "Paid/refunded order ids for a region, product category, and inclusive month window.", + get_orders), + "order_gross_usd": ("order_gross_usd(order_id: int) -> int", + "Gross order revenue in USD before discounts/refunds.", order_gross_usd), + "order_margin_usd": ("order_margin_usd(order_id: int) -> int", + "Gross order margin in USD before discounts/refunds.", order_margin_usd), + "refund_usd": ("refund_usd(order_id: int) -> int", + "Refund amount in USD for returned quantity on an order.", refund_usd), + "customer_tier": ("customer_tier(order_id: int) -> str", + "Customer loyalty tier for an order.", customer_tier), + "apply_discount": ("apply_discount(amount_usd: int, tier: str) -> int", + "Apply the order customer's loyalty discount to a USD amount.", apply_discount), + "net_revenue_usd": ("net_revenue_usd(order_id: int) -> int", + "Net USD revenue after loyalty discount and refunds.", net_revenue_usd), + "to_local": ("to_local(amount_usd: int, currency: str) -> int", + "Convert a USD integer amount to a local-currency integer.", to_local), + "inventory_position": ("inventory_position(product_id: int, region: str) -> int", + "Available inventory position: on_hand - reserved + inbound.", + inventory_position), + "product_lead_time": ("product_lead_time(product_id: int) -> int", + "Supplier lead time in days for a product.", product_lead_time), + "product_id_for_top_seller": ( + "product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int", + "Product id with the highest units sold in a region/category/month window.", + product_id_for_top_seller), + "units_sold": ("units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int", + "Units sold for one product in a region and month window.", units_sold), + "tickets_for_orders": ("tickets_for_orders(order_ids: list[int], severity: str) -> list[int]", + "Support ticket ids for given orders and severity.", tickets_for_orders), + "ticket_order_id": ("ticket_order_id(ticket_id: int) -> int", + "Order id associated with a support ticket.", ticket_order_id), + "sla_breached": ( + "sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool", + "Whether a support ticket breaches first-response or resolution SLA.", + sla_breached), + "delayed_orders": ("delayed_orders(order_ids: list[int]) -> list[int]", + "Subset of order ids whose ship_days exceeded promised_days.", delayed_orders), + "unique_customers": ("unique_customers(order_ids: list[int]) -> list[int]", + "Unique customer ids among the given orders.", unique_customers), + "count_items": ("count_items(values: list) -> int", "Length of a list.", count_items), + "sum_values": ("sum_values(values: list[int]) -> int", "Sum a list of integers.", sum_values), + "count_true": ("count_true(values: list[bool]) -> int", "Count true values.", count_true), + "count_below": ("count_below(values: list[int], threshold: int) -> int", + "Count values below a threshold.", count_below), +} + +__all__ = [name for name in TOOLS.keys()] + ['TOOLS'] diff --git a/harbor/tasks/v3_depth2_order_count_t18/environment/task.json b/harbor/tasks/v3_depth2_order_count_t18/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..b26b9c4e55d6f631f3612d6365070bcf2ef506d6 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t18/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_order_count_t18", + "depth": 2, + "family": "order_count", + "params": { + "region": "APAC", + "category": "A", + "month_start": 202603, + "month_end": 202604 + }, + "question": "How many paid/refunded orders are in region APAC, category A, from month 202603 through 202604? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_order_count_t18/instruction.md b/harbor/tasks/v3_depth2_order_count_t18/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..a2575945dfea03737d3a2c616d226177421376d4 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t18/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +How many paid/refunded orders are in region APAC, category A, from month 202603 through 202604? Report the count. + +Available tools: +- `region_currency(region: str) -> str`: ISO currency code for a region. +- `get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]`: Paid/refunded order ids for a region, product category, and inclusive month window. +- `order_gross_usd(order_id: int) -> int`: Gross order revenue in USD before discounts/refunds. +- `order_margin_usd(order_id: int) -> int`: Gross order margin in USD before discounts/refunds. +- `refund_usd(order_id: int) -> int`: Refund amount in USD for returned quantity on an order. +- `customer_tier(order_id: int) -> str`: Customer loyalty tier for an order. +- `apply_discount(amount_usd: int, tier: str) -> int`: Apply the order customer's loyalty discount to a USD amount. +- `net_revenue_usd(order_id: int) -> int`: Net USD revenue after loyalty discount and refunds. +- `to_local(amount_usd: int, currency: str) -> int`: Convert a USD integer amount to a local-currency integer. +- `inventory_position(product_id: int, region: str) -> int`: Available inventory position: on_hand - reserved + inbound. +- `product_lead_time(product_id: int) -> int`: Supplier lead time in days for a product. +- `product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int`: Product id with the highest units sold in a region/category/month window. +- `units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int`: Units sold for one product in a region and month window. +- `tickets_for_orders(order_ids: list[int], severity: str) -> list[int]`: Support ticket ids for given orders and severity. +- `ticket_order_id(ticket_id: int) -> int`: Order id associated with a support ticket. +- `sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool`: Whether a support ticket breaches first-response or resolution SLA. +- `delayed_orders(order_ids: list[int]) -> list[int]`: Subset of order ids whose ship_days exceeded promised_days. +- `unique_customers(order_ids: list[int]) -> list[int]`: Unique customer ids among the given orders. +- `count_items(values: list) -> int`: Length of a list. +- `sum_values(values: list[int]) -> int`: Sum a list of integers. +- `count_true(values: list[bool]) -> int`: Count true values. +- `count_below(values: list[int], threshold: int) -> int`: Count values below a threshold. diff --git a/harbor/tasks/v3_depth2_order_count_t18/task.toml b/harbor/tasks/v3_depth2_order_count_t18/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..dcacdfeff9699173e7b297ffe23ef0c8cd244ab1 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t18/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_order_count_t18" +description = "FlowBench v3 public task metadata. Public verifier is smoke-only." +authors = [{ name = "Mind Lab", email = "contact@mindlab.ltd" }] +keywords = ["flowbench", "tool-use", "data-orchestration", "operations"] + +[metadata] +benchmark = "FlowBench-v3" +split = "public-task-only" +category = "data-processing" +depth = 2 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +network_mode = "no-network" +build_timeout_sec = 600.0 +os = "linux" +cpus = 1 +memory_mb = 2048 +storage_mb = 2048 +gpus = 0 diff --git a/harbor/tasks/v3_depth2_order_count_t18/tests/check_output_shape.py b/harbor/tasks/v3_depth2_order_count_t18/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t18/tests/check_output_shape.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import json +import os +import re +from pathlib import Path + + +def write_reward(score: float, diagnostic: str) -> None: + log_dir = Path(os.environ.get("LOG_DIR", "/logs/verifier")) + log_dir.mkdir(parents=True, exist_ok=True) + (log_dir / "reward.txt").write_text(f"{score:.6g}\n") + (log_dir / "reward.json").write_text( + json.dumps({"reward": score, "smoke_only": True}, indent=2) + "\n" + ) + (log_dir / "diagnostic.txt").write_text(diagnostic + "\n") + + +def main() -> int: + app_dir = Path(os.environ.get("APP_DIR", "/app")) + task = json.loads((app_dir / "task.json").read_text()) + answer_path = app_dir / "answer.txt" + if not answer_path.exists(): + write_reward(0.0, "missing /app/answer.txt") + return 1 + + got = answer_path.read_text().strip() + if task["answer_format"] == "exact integer": + ok = bool(re.fullmatch(r"-?\d+", got)) + diagnostic = "valid integer smoke output" if ok else f"not an exact integer: {got!r}" + else: + ok = bool(re.fullmatch(r"[A-Za-z]+", got)) + diagnostic = "valid code smoke output" if ok else f"not an exact code: {got!r}" + + # This is intentionally not official scoring; it only verifies I/O shape. + write_reward(1.0 if ok else 0.0, diagnostic) + return 0 if ok else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/harbor/tasks/v3_depth2_order_count_t18/tests/test.sh b/harbor/tasks/v3_depth2_order_count_t18/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t18/tests/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -u +python /tests/check_output_shape.py diff --git a/harbor/tasks/v3_depth2_order_count_t19/environment/Dockerfile b/harbor/tasks/v3_depth2_order_count_t19/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t19/environment/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.12-slim +WORKDIR /app +COPY flowbench_tools.py /app/flowbench_tools.py +COPY task.json /app/task.json diff --git a/harbor/tasks/v3_depth2_order_count_t19/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_order_count_t19/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t19/environment/flowbench_tools.py @@ -0,0 +1,311 @@ +"""Deterministic FlowBench v3 tools. This file contains no task answers.""" + + +REGIONS = ["NA", "EU", "APAC", "LATAM"] +CATEGORIES = ["A", "B", "C", "D"] +CURRENCIES = {"NA": "USD", "EU": "EUR", "APAC": "JPY", "LATAM": "BRL"} +FX_TO_USD_BP = {"USD": 10000, "EUR": 10900, "JPY": 67, "BRL": 1850} +TIERS = ["std", "gold", "plat"] +DISCOUNT_PCT = {"std": 0, "gold": 10, "plat": 20} +CHANNELS = ["web", "store", "partner"] +MONTHS = [202601, 202602, 202603, 202604, 202605, 202606] + +N_CUSTOMERS = 72 +N_PRODUCTS = 48 +N_ORDERS = 720 +N_TICKETS = 260 +N_RETURNS = 180 + + +def _h(*xs): + import hashlib + s = "|".join(str(x) for x in xs).encode() + return int.from_bytes(hashlib.sha256(s).digest()[:8], "big") & 0x7FFFFFFF + + +def build_data(): + customers = [] + for cid in range(N_CUSTOMERS): + region = REGIONS[_h("region", cid) % len(REGIONS)] + customers.append({ + "customer_id": cid, + "region": region, + "tier": TIERS[_h("tier", cid) % len(TIERS)], + "segment": ["consumer", "smb", "enterprise"][_h("segment", cid) % 3], + }) + + products = [] + for pid in range(N_PRODUCTS): + cat = CATEGORIES[_h("cat", pid) % len(CATEGORIES)] + unit_price = 12 + _h("price", pid) % 240 + cogs = unit_price * (45 + _h("margin", pid) % 35) // 100 + products.append({ + "product_id": pid, + "category": cat, + "unit_price_usd": unit_price, + "unit_cogs_usd": cogs, + "lead_time_days": 3 + _h("lead", pid) % 18, + }) + + inventory = [] + for pid in range(N_PRODUCTS): + for region in REGIONS: + inventory.append({ + "product_id": pid, + "region": region, + "on_hand": 10 + _h("onhand", pid, region) % 140, + "reserved": _h("reserved", pid, region) % 28, + "inbound": _h("inbound", pid, region) % 85, + }) + + orders = [] + for oid in range(N_ORDERS): + customer_id = _h("ocust", oid) % N_CUSTOMERS + product_id = _h("oprod", oid) % N_PRODUCTS + month = MONTHS[_h("month", oid) % len(MONTHS)] + qty = 1 + _h("qty", oid) % 9 + ship_days = 1 + _h("shipdays", oid) % 16 + promised_days = 3 + _h("promise", oid) % 9 + status = ["paid", "paid", "paid", "paid", "cancelled", "refunded"][ + _h("status", oid) % 6] + orders.append({ + "order_id": oid, + "customer_id": customer_id, + "product_id": product_id, + "month": month, + "qty": qty, + "status": status, + "channel": CHANNELS[_h("channel", oid) % len(CHANNELS)], + "ship_days": ship_days, + "promised_days": promised_days, + }) + + returns = [] + for rid in range(N_RETURNS): + oid = _h("roid", rid) % N_ORDERS + order = orders[oid] + if order["status"] == "cancelled": + continue + returned_qty = 1 + _h("rqty", rid) % max(1, order["qty"]) + reason = ["defect", "late", "changed_mind", "wrong_item"][_h("reason", rid) % 4] + returns.append({ + "return_id": rid, + "order_id": oid, + "month": MONTHS[_h("rmonth", rid) % len(MONTHS)], + "returned_qty": returned_qty, + "reason": reason, + }) + + tickets = [] + for tid in range(N_TICKETS): + oid = _h("toid", tid) % N_ORDERS + severity = ["low", "medium", "high", "critical"][_h("sev", tid) % 4] + opened = MONTHS[_h("tmonth", tid) % len(MONTHS)] + first_response_hours = 1 + _h("resp", tid) % 96 + resolution_hours = first_response_hours + _h("res", tid) % 240 + tickets.append({ + "ticket_id": tid, + "order_id": oid, + "opened_month": opened, + "severity": severity, + "first_response_hours": first_response_hours, + "resolution_hours": resolution_hours, + }) + + return { + "customers": customers, + "products": products, + "inventory": inventory, + "orders": orders, + "returns": returns, + "tickets": tickets, + "fx_to_usd_bp": FX_TO_USD_BP, + } + + +DATA = build_data() +CUSTOMERS = {c["customer_id"]: c for c in DATA["customers"]} +PRODUCTS = {p["product_id"]: p for p in DATA["products"]} +ORDERS = {o["order_id"]: o for o in DATA["orders"]} + + +def region_currency(region: str) -> str: + return CURRENCIES[region] + + +def get_orders(region: str, category: str, month_start: int, month_end: int) -> list: + """Paid/refunded order ids in a region/category/month window.""" + out = [] + for o in DATA["orders"]: + if o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + p = PRODUCTS[o["product_id"]] + if c["region"] == region and p["category"] == category and month_start <= o["month"] <= month_end: + out.append(o["order_id"]) + return sorted(out) + + +def order_gross_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * p["unit_price_usd"] + + +def order_margin_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * (p["unit_price_usd"] - p["unit_cogs_usd"]) + + +def refund_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + qty = sum(r["returned_qty"] for r in DATA["returns"] if r["order_id"] == order_id) + qty = min(qty, o["qty"]) + return qty * p["unit_price_usd"] + + +def customer_tier(order_id: int) -> str: + o = ORDERS[order_id] + return CUSTOMERS[o["customer_id"]]["tier"] + + +def apply_discount(amount_usd: int, tier: str) -> int: + return amount_usd * (100 - DISCOUNT_PCT[tier]) // 100 + + +def net_revenue_usd(order_id: int) -> int: + gross = apply_discount(order_gross_usd(order_id), customer_tier(order_id)) + return max(0, gross - refund_usd(order_id)) + + +def to_local(amount_usd: int, currency: str) -> int: + return amount_usd * 10000 // FX_TO_USD_BP[currency] + + +def inventory_position(product_id: int, region: str) -> int: + row = next(x for x in DATA["inventory"] + if x["product_id"] == product_id and x["region"] == region) + return row["on_hand"] - row["reserved"] + row["inbound"] + + +def product_lead_time(product_id: int) -> int: + return PRODUCTS[product_id]["lead_time_days"] + + +def product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int: + totals = {} + for oid in get_orders(region, category, month_start, month_end): + o = ORDERS[oid] + totals[o["product_id"]] = totals.get(o["product_id"], 0) + o["qty"] + if not totals: + return -1 + return min((-qty, pid) for pid, qty in totals.items())[1] + + +def units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int: + total = 0 + for o in DATA["orders"]: + if o["product_id"] != product_id or o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + if c["region"] == region and month_start <= o["month"] <= month_end: + total += o["qty"] + return total + + +def tickets_for_orders(order_ids: list, severity: str) -> list: + s = set(order_ids) + return sorted(t["ticket_id"] for t in DATA["tickets"] + if t["order_id"] in s and t["severity"] == severity) + + +def ticket_order_id(ticket_id: int) -> int: + return next(t["order_id"] for t in DATA["tickets"] if t["ticket_id"] == ticket_id) + + +def sla_breached(ticket_id: int, first_response_limit_hours: int, + resolution_limit_hours: int) -> bool: + t = next(x for x in DATA["tickets"] if x["ticket_id"] == ticket_id) + return (t["first_response_hours"] > first_response_limit_hours or + t["resolution_hours"] > resolution_limit_hours) + + +def delayed_orders(order_ids: list) -> list: + s = set(order_ids) + return sorted(o["order_id"] for o in DATA["orders"] + if o["order_id"] in s and o["ship_days"] > o["promised_days"]) + + +def unique_customers(order_ids: list) -> list: + return sorted({ORDERS[oid]["customer_id"] for oid in order_ids}) + + +def count_items(values: list) -> int: + return len(values) + + +def sum_values(values: list) -> int: + return sum(values) + + +def count_true(values: list) -> int: + return sum(1 for v in values if bool(v)) + + +def count_below(values: list, threshold: int) -> int: + return sum(1 for v in values if v < threshold) + + +TOOLS = { + "region_currency": ("region_currency(region: str) -> str", + "ISO currency code for a region.", region_currency), + "get_orders": ("get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]", + "Paid/refunded order ids for a region, product category, and inclusive month window.", + get_orders), + "order_gross_usd": ("order_gross_usd(order_id: int) -> int", + "Gross order revenue in USD before discounts/refunds.", order_gross_usd), + "order_margin_usd": ("order_margin_usd(order_id: int) -> int", + "Gross order margin in USD before discounts/refunds.", order_margin_usd), + "refund_usd": ("refund_usd(order_id: int) -> int", + "Refund amount in USD for returned quantity on an order.", refund_usd), + "customer_tier": ("customer_tier(order_id: int) -> str", + "Customer loyalty tier for an order.", customer_tier), + "apply_discount": ("apply_discount(amount_usd: int, tier: str) -> int", + "Apply the order customer's loyalty discount to a USD amount.", apply_discount), + "net_revenue_usd": ("net_revenue_usd(order_id: int) -> int", + "Net USD revenue after loyalty discount and refunds.", net_revenue_usd), + "to_local": ("to_local(amount_usd: int, currency: str) -> int", + "Convert a USD integer amount to a local-currency integer.", to_local), + "inventory_position": ("inventory_position(product_id: int, region: str) -> int", + "Available inventory position: on_hand - reserved + inbound.", + inventory_position), + "product_lead_time": ("product_lead_time(product_id: int) -> int", + "Supplier lead time in days for a product.", product_lead_time), + "product_id_for_top_seller": ( + "product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int", + "Product id with the highest units sold in a region/category/month window.", + product_id_for_top_seller), + "units_sold": ("units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int", + "Units sold for one product in a region and month window.", units_sold), + "tickets_for_orders": ("tickets_for_orders(order_ids: list[int], severity: str) -> list[int]", + "Support ticket ids for given orders and severity.", tickets_for_orders), + "ticket_order_id": ("ticket_order_id(ticket_id: int) -> int", + "Order id associated with a support ticket.", ticket_order_id), + "sla_breached": ( + "sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool", + "Whether a support ticket breaches first-response or resolution SLA.", + sla_breached), + "delayed_orders": ("delayed_orders(order_ids: list[int]) -> list[int]", + "Subset of order ids whose ship_days exceeded promised_days.", delayed_orders), + "unique_customers": ("unique_customers(order_ids: list[int]) -> list[int]", + "Unique customer ids among the given orders.", unique_customers), + "count_items": ("count_items(values: list) -> int", "Length of a list.", count_items), + "sum_values": ("sum_values(values: list[int]) -> int", "Sum a list of integers.", sum_values), + "count_true": ("count_true(values: list[bool]) -> int", "Count true values.", count_true), + "count_below": ("count_below(values: list[int], threshold: int) -> int", + "Count values below a threshold.", count_below), +} + +__all__ = [name for name in TOOLS.keys()] + ['TOOLS'] diff --git a/harbor/tasks/v3_depth2_order_count_t19/environment/task.json b/harbor/tasks/v3_depth2_order_count_t19/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..10b36d0894adbe30d8cfa47e37097067db53ee98 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t19/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_order_count_t19", + "depth": 2, + "family": "order_count", + "params": { + "region": "LATAM", + "category": "B", + "month_start": 202605, + "month_end": 202606 + }, + "question": "How many paid/refunded orders are in region LATAM, category B, from month 202605 through 202606? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_order_count_t19/instruction.md b/harbor/tasks/v3_depth2_order_count_t19/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..47934d61a0ad579512e6902ad3a1273227d77406 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t19/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +How many paid/refunded orders are in region LATAM, category B, from month 202605 through 202606? Report the count. + +Available tools: +- `region_currency(region: str) -> str`: ISO currency code for a region. +- `get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]`: Paid/refunded order ids for a region, product category, and inclusive month window. +- `order_gross_usd(order_id: int) -> int`: Gross order revenue in USD before discounts/refunds. +- `order_margin_usd(order_id: int) -> int`: Gross order margin in USD before discounts/refunds. +- `refund_usd(order_id: int) -> int`: Refund amount in USD for returned quantity on an order. +- `customer_tier(order_id: int) -> str`: Customer loyalty tier for an order. +- `apply_discount(amount_usd: int, tier: str) -> int`: Apply the order customer's loyalty discount to a USD amount. +- `net_revenue_usd(order_id: int) -> int`: Net USD revenue after loyalty discount and refunds. +- `to_local(amount_usd: int, currency: str) -> int`: Convert a USD integer amount to a local-currency integer. +- `inventory_position(product_id: int, region: str) -> int`: Available inventory position: on_hand - reserved + inbound. +- `product_lead_time(product_id: int) -> int`: Supplier lead time in days for a product. +- `product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int`: Product id with the highest units sold in a region/category/month window. +- `units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int`: Units sold for one product in a region and month window. +- `tickets_for_orders(order_ids: list[int], severity: str) -> list[int]`: Support ticket ids for given orders and severity. +- `ticket_order_id(ticket_id: int) -> int`: Order id associated with a support ticket. +- `sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool`: Whether a support ticket breaches first-response or resolution SLA. +- `delayed_orders(order_ids: list[int]) -> list[int]`: Subset of order ids whose ship_days exceeded promised_days. +- `unique_customers(order_ids: list[int]) -> list[int]`: Unique customer ids among the given orders. +- `count_items(values: list) -> int`: Length of a list. +- `sum_values(values: list[int]) -> int`: Sum a list of integers. +- `count_true(values: list[bool]) -> int`: Count true values. +- `count_below(values: list[int], threshold: int) -> int`: Count values below a threshold. diff --git a/harbor/tasks/v3_depth2_order_count_t19/task.toml b/harbor/tasks/v3_depth2_order_count_t19/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..28842c518f4e8f9eba1e3361aec41262a5e38185 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t19/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_order_count_t19" +description = "FlowBench v3 public task metadata. Public verifier is smoke-only." +authors = [{ name = "Mind Lab", email = "contact@mindlab.ltd" }] +keywords = ["flowbench", "tool-use", "data-orchestration", "operations"] + +[metadata] +benchmark = "FlowBench-v3" +split = "public-task-only" +category = "data-processing" +depth = 2 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +network_mode = "no-network" +build_timeout_sec = 600.0 +os = "linux" +cpus = 1 +memory_mb = 2048 +storage_mb = 2048 +gpus = 0 diff --git a/harbor/tasks/v3_depth2_order_count_t19/tests/check_output_shape.py b/harbor/tasks/v3_depth2_order_count_t19/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t19/tests/check_output_shape.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import json +import os +import re +from pathlib import Path + + +def write_reward(score: float, diagnostic: str) -> None: + log_dir = Path(os.environ.get("LOG_DIR", "/logs/verifier")) + log_dir.mkdir(parents=True, exist_ok=True) + (log_dir / "reward.txt").write_text(f"{score:.6g}\n") + (log_dir / "reward.json").write_text( + json.dumps({"reward": score, "smoke_only": True}, indent=2) + "\n" + ) + (log_dir / "diagnostic.txt").write_text(diagnostic + "\n") + + +def main() -> int: + app_dir = Path(os.environ.get("APP_DIR", "/app")) + task = json.loads((app_dir / "task.json").read_text()) + answer_path = app_dir / "answer.txt" + if not answer_path.exists(): + write_reward(0.0, "missing /app/answer.txt") + return 1 + + got = answer_path.read_text().strip() + if task["answer_format"] == "exact integer": + ok = bool(re.fullmatch(r"-?\d+", got)) + diagnostic = "valid integer smoke output" if ok else f"not an exact integer: {got!r}" + else: + ok = bool(re.fullmatch(r"[A-Za-z]+", got)) + diagnostic = "valid code smoke output" if ok else f"not an exact code: {got!r}" + + # This is intentionally not official scoring; it only verifies I/O shape. + write_reward(1.0 if ok else 0.0, diagnostic) + return 0 if ok else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/harbor/tasks/v3_depth2_order_count_t19/tests/test.sh b/harbor/tasks/v3_depth2_order_count_t19/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t19/tests/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -u +python /tests/check_output_shape.py diff --git a/harbor/tasks/v3_depth2_order_count_t2/environment/Dockerfile b/harbor/tasks/v3_depth2_order_count_t2/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t2/environment/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.12-slim +WORKDIR /app +COPY flowbench_tools.py /app/flowbench_tools.py +COPY task.json /app/task.json diff --git a/harbor/tasks/v3_depth2_order_count_t2/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_order_count_t2/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t2/environment/flowbench_tools.py @@ -0,0 +1,311 @@ +"""Deterministic FlowBench v3 tools. This file contains no task answers.""" + + +REGIONS = ["NA", "EU", "APAC", "LATAM"] +CATEGORIES = ["A", "B", "C", "D"] +CURRENCIES = {"NA": "USD", "EU": "EUR", "APAC": "JPY", "LATAM": "BRL"} +FX_TO_USD_BP = {"USD": 10000, "EUR": 10900, "JPY": 67, "BRL": 1850} +TIERS = ["std", "gold", "plat"] +DISCOUNT_PCT = {"std": 0, "gold": 10, "plat": 20} +CHANNELS = ["web", "store", "partner"] +MONTHS = [202601, 202602, 202603, 202604, 202605, 202606] + +N_CUSTOMERS = 72 +N_PRODUCTS = 48 +N_ORDERS = 720 +N_TICKETS = 260 +N_RETURNS = 180 + + +def _h(*xs): + import hashlib + s = "|".join(str(x) for x in xs).encode() + return int.from_bytes(hashlib.sha256(s).digest()[:8], "big") & 0x7FFFFFFF + + +def build_data(): + customers = [] + for cid in range(N_CUSTOMERS): + region = REGIONS[_h("region", cid) % len(REGIONS)] + customers.append({ + "customer_id": cid, + "region": region, + "tier": TIERS[_h("tier", cid) % len(TIERS)], + "segment": ["consumer", "smb", "enterprise"][_h("segment", cid) % 3], + }) + + products = [] + for pid in range(N_PRODUCTS): + cat = CATEGORIES[_h("cat", pid) % len(CATEGORIES)] + unit_price = 12 + _h("price", pid) % 240 + cogs = unit_price * (45 + _h("margin", pid) % 35) // 100 + products.append({ + "product_id": pid, + "category": cat, + "unit_price_usd": unit_price, + "unit_cogs_usd": cogs, + "lead_time_days": 3 + _h("lead", pid) % 18, + }) + + inventory = [] + for pid in range(N_PRODUCTS): + for region in REGIONS: + inventory.append({ + "product_id": pid, + "region": region, + "on_hand": 10 + _h("onhand", pid, region) % 140, + "reserved": _h("reserved", pid, region) % 28, + "inbound": _h("inbound", pid, region) % 85, + }) + + orders = [] + for oid in range(N_ORDERS): + customer_id = _h("ocust", oid) % N_CUSTOMERS + product_id = _h("oprod", oid) % N_PRODUCTS + month = MONTHS[_h("month", oid) % len(MONTHS)] + qty = 1 + _h("qty", oid) % 9 + ship_days = 1 + _h("shipdays", oid) % 16 + promised_days = 3 + _h("promise", oid) % 9 + status = ["paid", "paid", "paid", "paid", "cancelled", "refunded"][ + _h("status", oid) % 6] + orders.append({ + "order_id": oid, + "customer_id": customer_id, + "product_id": product_id, + "month": month, + "qty": qty, + "status": status, + "channel": CHANNELS[_h("channel", oid) % len(CHANNELS)], + "ship_days": ship_days, + "promised_days": promised_days, + }) + + returns = [] + for rid in range(N_RETURNS): + oid = _h("roid", rid) % N_ORDERS + order = orders[oid] + if order["status"] == "cancelled": + continue + returned_qty = 1 + _h("rqty", rid) % max(1, order["qty"]) + reason = ["defect", "late", "changed_mind", "wrong_item"][_h("reason", rid) % 4] + returns.append({ + "return_id": rid, + "order_id": oid, + "month": MONTHS[_h("rmonth", rid) % len(MONTHS)], + "returned_qty": returned_qty, + "reason": reason, + }) + + tickets = [] + for tid in range(N_TICKETS): + oid = _h("toid", tid) % N_ORDERS + severity = ["low", "medium", "high", "critical"][_h("sev", tid) % 4] + opened = MONTHS[_h("tmonth", tid) % len(MONTHS)] + first_response_hours = 1 + _h("resp", tid) % 96 + resolution_hours = first_response_hours + _h("res", tid) % 240 + tickets.append({ + "ticket_id": tid, + "order_id": oid, + "opened_month": opened, + "severity": severity, + "first_response_hours": first_response_hours, + "resolution_hours": resolution_hours, + }) + + return { + "customers": customers, + "products": products, + "inventory": inventory, + "orders": orders, + "returns": returns, + "tickets": tickets, + "fx_to_usd_bp": FX_TO_USD_BP, + } + + +DATA = build_data() +CUSTOMERS = {c["customer_id"]: c for c in DATA["customers"]} +PRODUCTS = {p["product_id"]: p for p in DATA["products"]} +ORDERS = {o["order_id"]: o for o in DATA["orders"]} + + +def region_currency(region: str) -> str: + return CURRENCIES[region] + + +def get_orders(region: str, category: str, month_start: int, month_end: int) -> list: + """Paid/refunded order ids in a region/category/month window.""" + out = [] + for o in DATA["orders"]: + if o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + p = PRODUCTS[o["product_id"]] + if c["region"] == region and p["category"] == category and month_start <= o["month"] <= month_end: + out.append(o["order_id"]) + return sorted(out) + + +def order_gross_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * p["unit_price_usd"] + + +def order_margin_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * (p["unit_price_usd"] - p["unit_cogs_usd"]) + + +def refund_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + qty = sum(r["returned_qty"] for r in DATA["returns"] if r["order_id"] == order_id) + qty = min(qty, o["qty"]) + return qty * p["unit_price_usd"] + + +def customer_tier(order_id: int) -> str: + o = ORDERS[order_id] + return CUSTOMERS[o["customer_id"]]["tier"] + + +def apply_discount(amount_usd: int, tier: str) -> int: + return amount_usd * (100 - DISCOUNT_PCT[tier]) // 100 + + +def net_revenue_usd(order_id: int) -> int: + gross = apply_discount(order_gross_usd(order_id), customer_tier(order_id)) + return max(0, gross - refund_usd(order_id)) + + +def to_local(amount_usd: int, currency: str) -> int: + return amount_usd * 10000 // FX_TO_USD_BP[currency] + + +def inventory_position(product_id: int, region: str) -> int: + row = next(x for x in DATA["inventory"] + if x["product_id"] == product_id and x["region"] == region) + return row["on_hand"] - row["reserved"] + row["inbound"] + + +def product_lead_time(product_id: int) -> int: + return PRODUCTS[product_id]["lead_time_days"] + + +def product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int: + totals = {} + for oid in get_orders(region, category, month_start, month_end): + o = ORDERS[oid] + totals[o["product_id"]] = totals.get(o["product_id"], 0) + o["qty"] + if not totals: + return -1 + return min((-qty, pid) for pid, qty in totals.items())[1] + + +def units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int: + total = 0 + for o in DATA["orders"]: + if o["product_id"] != product_id or o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + if c["region"] == region and month_start <= o["month"] <= month_end: + total += o["qty"] + return total + + +def tickets_for_orders(order_ids: list, severity: str) -> list: + s = set(order_ids) + return sorted(t["ticket_id"] for t in DATA["tickets"] + if t["order_id"] in s and t["severity"] == severity) + + +def ticket_order_id(ticket_id: int) -> int: + return next(t["order_id"] for t in DATA["tickets"] if t["ticket_id"] == ticket_id) + + +def sla_breached(ticket_id: int, first_response_limit_hours: int, + resolution_limit_hours: int) -> bool: + t = next(x for x in DATA["tickets"] if x["ticket_id"] == ticket_id) + return (t["first_response_hours"] > first_response_limit_hours or + t["resolution_hours"] > resolution_limit_hours) + + +def delayed_orders(order_ids: list) -> list: + s = set(order_ids) + return sorted(o["order_id"] for o in DATA["orders"] + if o["order_id"] in s and o["ship_days"] > o["promised_days"]) + + +def unique_customers(order_ids: list) -> list: + return sorted({ORDERS[oid]["customer_id"] for oid in order_ids}) + + +def count_items(values: list) -> int: + return len(values) + + +def sum_values(values: list) -> int: + return sum(values) + + +def count_true(values: list) -> int: + return sum(1 for v in values if bool(v)) + + +def count_below(values: list, threshold: int) -> int: + return sum(1 for v in values if v < threshold) + + +TOOLS = { + "region_currency": ("region_currency(region: str) -> str", + "ISO currency code for a region.", region_currency), + "get_orders": ("get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]", + "Paid/refunded order ids for a region, product category, and inclusive month window.", + get_orders), + "order_gross_usd": ("order_gross_usd(order_id: int) -> int", + "Gross order revenue in USD before discounts/refunds.", order_gross_usd), + "order_margin_usd": ("order_margin_usd(order_id: int) -> int", + "Gross order margin in USD before discounts/refunds.", order_margin_usd), + "refund_usd": ("refund_usd(order_id: int) -> int", + "Refund amount in USD for returned quantity on an order.", refund_usd), + "customer_tier": ("customer_tier(order_id: int) -> str", + "Customer loyalty tier for an order.", customer_tier), + "apply_discount": ("apply_discount(amount_usd: int, tier: str) -> int", + "Apply the order customer's loyalty discount to a USD amount.", apply_discount), + "net_revenue_usd": ("net_revenue_usd(order_id: int) -> int", + "Net USD revenue after loyalty discount and refunds.", net_revenue_usd), + "to_local": ("to_local(amount_usd: int, currency: str) -> int", + "Convert a USD integer amount to a local-currency integer.", to_local), + "inventory_position": ("inventory_position(product_id: int, region: str) -> int", + "Available inventory position: on_hand - reserved + inbound.", + inventory_position), + "product_lead_time": ("product_lead_time(product_id: int) -> int", + "Supplier lead time in days for a product.", product_lead_time), + "product_id_for_top_seller": ( + "product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int", + "Product id with the highest units sold in a region/category/month window.", + product_id_for_top_seller), + "units_sold": ("units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int", + "Units sold for one product in a region and month window.", units_sold), + "tickets_for_orders": ("tickets_for_orders(order_ids: list[int], severity: str) -> list[int]", + "Support ticket ids for given orders and severity.", tickets_for_orders), + "ticket_order_id": ("ticket_order_id(ticket_id: int) -> int", + "Order id associated with a support ticket.", ticket_order_id), + "sla_breached": ( + "sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool", + "Whether a support ticket breaches first-response or resolution SLA.", + sla_breached), + "delayed_orders": ("delayed_orders(order_ids: list[int]) -> list[int]", + "Subset of order ids whose ship_days exceeded promised_days.", delayed_orders), + "unique_customers": ("unique_customers(order_ids: list[int]) -> list[int]", + "Unique customer ids among the given orders.", unique_customers), + "count_items": ("count_items(values: list) -> int", "Length of a list.", count_items), + "sum_values": ("sum_values(values: list[int]) -> int", "Sum a list of integers.", sum_values), + "count_true": ("count_true(values: list[bool]) -> int", "Count true values.", count_true), + "count_below": ("count_below(values: list[int], threshold: int) -> int", + "Count values below a threshold.", count_below), +} + +__all__ = [name for name in TOOLS.keys()] + ['TOOLS'] diff --git a/harbor/tasks/v3_depth2_order_count_t2/environment/task.json b/harbor/tasks/v3_depth2_order_count_t2/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..1db32c80cefc36b1fdd765e34dad240de02b71ad --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t2/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_order_count_t2", + "depth": 2, + "family": "order_count", + "params": { + "region": "EU", + "category": "C", + "month_start": 202601, + "month_end": 202604 + }, + "question": "How many paid/refunded orders are in region EU, category C, from month 202601 through 202604? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_order_count_t2/instruction.md b/harbor/tasks/v3_depth2_order_count_t2/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..c2ca5209376bd6c1bf4944164844327ab599c1fb --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t2/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +How many paid/refunded orders are in region EU, category C, from month 202601 through 202604? Report the count. + +Available tools: +- `region_currency(region: str) -> str`: ISO currency code for a region. +- `get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]`: Paid/refunded order ids for a region, product category, and inclusive month window. +- `order_gross_usd(order_id: int) -> int`: Gross order revenue in USD before discounts/refunds. +- `order_margin_usd(order_id: int) -> int`: Gross order margin in USD before discounts/refunds. +- `refund_usd(order_id: int) -> int`: Refund amount in USD for returned quantity on an order. +- `customer_tier(order_id: int) -> str`: Customer loyalty tier for an order. +- `apply_discount(amount_usd: int, tier: str) -> int`: Apply the order customer's loyalty discount to a USD amount. +- `net_revenue_usd(order_id: int) -> int`: Net USD revenue after loyalty discount and refunds. +- `to_local(amount_usd: int, currency: str) -> int`: Convert a USD integer amount to a local-currency integer. +- `inventory_position(product_id: int, region: str) -> int`: Available inventory position: on_hand - reserved + inbound. +- `product_lead_time(product_id: int) -> int`: Supplier lead time in days for a product. +- `product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int`: Product id with the highest units sold in a region/category/month window. +- `units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int`: Units sold for one product in a region and month window. +- `tickets_for_orders(order_ids: list[int], severity: str) -> list[int]`: Support ticket ids for given orders and severity. +- `ticket_order_id(ticket_id: int) -> int`: Order id associated with a support ticket. +- `sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool`: Whether a support ticket breaches first-response or resolution SLA. +- `delayed_orders(order_ids: list[int]) -> list[int]`: Subset of order ids whose ship_days exceeded promised_days. +- `unique_customers(order_ids: list[int]) -> list[int]`: Unique customer ids among the given orders. +- `count_items(values: list) -> int`: Length of a list. +- `sum_values(values: list[int]) -> int`: Sum a list of integers. +- `count_true(values: list[bool]) -> int`: Count true values. +- `count_below(values: list[int], threshold: int) -> int`: Count values below a threshold. diff --git a/harbor/tasks/v3_depth2_order_count_t2/task.toml b/harbor/tasks/v3_depth2_order_count_t2/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..2fe84cc3d0d3fd499a0834d7586bf1157127769f --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t2/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_order_count_t2" +description = "FlowBench v3 public task metadata. Public verifier is smoke-only." +authors = [{ name = "Mind Lab", email = "contact@mindlab.ltd" }] +keywords = ["flowbench", "tool-use", "data-orchestration", "operations"] + +[metadata] +benchmark = "FlowBench-v3" +split = "public-task-only" +category = "data-processing" +depth = 2 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +network_mode = "no-network" +build_timeout_sec = 600.0 +os = "linux" +cpus = 1 +memory_mb = 2048 +storage_mb = 2048 +gpus = 0 diff --git a/harbor/tasks/v3_depth2_order_count_t2/tests/check_output_shape.py b/harbor/tasks/v3_depth2_order_count_t2/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t2/tests/check_output_shape.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import json +import os +import re +from pathlib import Path + + +def write_reward(score: float, diagnostic: str) -> None: + log_dir = Path(os.environ.get("LOG_DIR", "/logs/verifier")) + log_dir.mkdir(parents=True, exist_ok=True) + (log_dir / "reward.txt").write_text(f"{score:.6g}\n") + (log_dir / "reward.json").write_text( + json.dumps({"reward": score, "smoke_only": True}, indent=2) + "\n" + ) + (log_dir / "diagnostic.txt").write_text(diagnostic + "\n") + + +def main() -> int: + app_dir = Path(os.environ.get("APP_DIR", "/app")) + task = json.loads((app_dir / "task.json").read_text()) + answer_path = app_dir / "answer.txt" + if not answer_path.exists(): + write_reward(0.0, "missing /app/answer.txt") + return 1 + + got = answer_path.read_text().strip() + if task["answer_format"] == "exact integer": + ok = bool(re.fullmatch(r"-?\d+", got)) + diagnostic = "valid integer smoke output" if ok else f"not an exact integer: {got!r}" + else: + ok = bool(re.fullmatch(r"[A-Za-z]+", got)) + diagnostic = "valid code smoke output" if ok else f"not an exact code: {got!r}" + + # This is intentionally not official scoring; it only verifies I/O shape. + write_reward(1.0 if ok else 0.0, diagnostic) + return 0 if ok else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/harbor/tasks/v3_depth2_order_count_t2/tests/test.sh b/harbor/tasks/v3_depth2_order_count_t2/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t2/tests/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -u +python /tests/check_output_shape.py diff --git a/harbor/tasks/v3_depth2_order_count_t20/environment/Dockerfile b/harbor/tasks/v3_depth2_order_count_t20/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t20/environment/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.12-slim +WORKDIR /app +COPY flowbench_tools.py /app/flowbench_tools.py +COPY task.json /app/task.json diff --git a/harbor/tasks/v3_depth2_order_count_t20/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_order_count_t20/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t20/environment/flowbench_tools.py @@ -0,0 +1,311 @@ +"""Deterministic FlowBench v3 tools. This file contains no task answers.""" + + +REGIONS = ["NA", "EU", "APAC", "LATAM"] +CATEGORIES = ["A", "B", "C", "D"] +CURRENCIES = {"NA": "USD", "EU": "EUR", "APAC": "JPY", "LATAM": "BRL"} +FX_TO_USD_BP = {"USD": 10000, "EUR": 10900, "JPY": 67, "BRL": 1850} +TIERS = ["std", "gold", "plat"] +DISCOUNT_PCT = {"std": 0, "gold": 10, "plat": 20} +CHANNELS = ["web", "store", "partner"] +MONTHS = [202601, 202602, 202603, 202604, 202605, 202606] + +N_CUSTOMERS = 72 +N_PRODUCTS = 48 +N_ORDERS = 720 +N_TICKETS = 260 +N_RETURNS = 180 + + +def _h(*xs): + import hashlib + s = "|".join(str(x) for x in xs).encode() + return int.from_bytes(hashlib.sha256(s).digest()[:8], "big") & 0x7FFFFFFF + + +def build_data(): + customers = [] + for cid in range(N_CUSTOMERS): + region = REGIONS[_h("region", cid) % len(REGIONS)] + customers.append({ + "customer_id": cid, + "region": region, + "tier": TIERS[_h("tier", cid) % len(TIERS)], + "segment": ["consumer", "smb", "enterprise"][_h("segment", cid) % 3], + }) + + products = [] + for pid in range(N_PRODUCTS): + cat = CATEGORIES[_h("cat", pid) % len(CATEGORIES)] + unit_price = 12 + _h("price", pid) % 240 + cogs = unit_price * (45 + _h("margin", pid) % 35) // 100 + products.append({ + "product_id": pid, + "category": cat, + "unit_price_usd": unit_price, + "unit_cogs_usd": cogs, + "lead_time_days": 3 + _h("lead", pid) % 18, + }) + + inventory = [] + for pid in range(N_PRODUCTS): + for region in REGIONS: + inventory.append({ + "product_id": pid, + "region": region, + "on_hand": 10 + _h("onhand", pid, region) % 140, + "reserved": _h("reserved", pid, region) % 28, + "inbound": _h("inbound", pid, region) % 85, + }) + + orders = [] + for oid in range(N_ORDERS): + customer_id = _h("ocust", oid) % N_CUSTOMERS + product_id = _h("oprod", oid) % N_PRODUCTS + month = MONTHS[_h("month", oid) % len(MONTHS)] + qty = 1 + _h("qty", oid) % 9 + ship_days = 1 + _h("shipdays", oid) % 16 + promised_days = 3 + _h("promise", oid) % 9 + status = ["paid", "paid", "paid", "paid", "cancelled", "refunded"][ + _h("status", oid) % 6] + orders.append({ + "order_id": oid, + "customer_id": customer_id, + "product_id": product_id, + "month": month, + "qty": qty, + "status": status, + "channel": CHANNELS[_h("channel", oid) % len(CHANNELS)], + "ship_days": ship_days, + "promised_days": promised_days, + }) + + returns = [] + for rid in range(N_RETURNS): + oid = _h("roid", rid) % N_ORDERS + order = orders[oid] + if order["status"] == "cancelled": + continue + returned_qty = 1 + _h("rqty", rid) % max(1, order["qty"]) + reason = ["defect", "late", "changed_mind", "wrong_item"][_h("reason", rid) % 4] + returns.append({ + "return_id": rid, + "order_id": oid, + "month": MONTHS[_h("rmonth", rid) % len(MONTHS)], + "returned_qty": returned_qty, + "reason": reason, + }) + + tickets = [] + for tid in range(N_TICKETS): + oid = _h("toid", tid) % N_ORDERS + severity = ["low", "medium", "high", "critical"][_h("sev", tid) % 4] + opened = MONTHS[_h("tmonth", tid) % len(MONTHS)] + first_response_hours = 1 + _h("resp", tid) % 96 + resolution_hours = first_response_hours + _h("res", tid) % 240 + tickets.append({ + "ticket_id": tid, + "order_id": oid, + "opened_month": opened, + "severity": severity, + "first_response_hours": first_response_hours, + "resolution_hours": resolution_hours, + }) + + return { + "customers": customers, + "products": products, + "inventory": inventory, + "orders": orders, + "returns": returns, + "tickets": tickets, + "fx_to_usd_bp": FX_TO_USD_BP, + } + + +DATA = build_data() +CUSTOMERS = {c["customer_id"]: c for c in DATA["customers"]} +PRODUCTS = {p["product_id"]: p for p in DATA["products"]} +ORDERS = {o["order_id"]: o for o in DATA["orders"]} + + +def region_currency(region: str) -> str: + return CURRENCIES[region] + + +def get_orders(region: str, category: str, month_start: int, month_end: int) -> list: + """Paid/refunded order ids in a region/category/month window.""" + out = [] + for o in DATA["orders"]: + if o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + p = PRODUCTS[o["product_id"]] + if c["region"] == region and p["category"] == category and month_start <= o["month"] <= month_end: + out.append(o["order_id"]) + return sorted(out) + + +def order_gross_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * p["unit_price_usd"] + + +def order_margin_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * (p["unit_price_usd"] - p["unit_cogs_usd"]) + + +def refund_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + qty = sum(r["returned_qty"] for r in DATA["returns"] if r["order_id"] == order_id) + qty = min(qty, o["qty"]) + return qty * p["unit_price_usd"] + + +def customer_tier(order_id: int) -> str: + o = ORDERS[order_id] + return CUSTOMERS[o["customer_id"]]["tier"] + + +def apply_discount(amount_usd: int, tier: str) -> int: + return amount_usd * (100 - DISCOUNT_PCT[tier]) // 100 + + +def net_revenue_usd(order_id: int) -> int: + gross = apply_discount(order_gross_usd(order_id), customer_tier(order_id)) + return max(0, gross - refund_usd(order_id)) + + +def to_local(amount_usd: int, currency: str) -> int: + return amount_usd * 10000 // FX_TO_USD_BP[currency] + + +def inventory_position(product_id: int, region: str) -> int: + row = next(x for x in DATA["inventory"] + if x["product_id"] == product_id and x["region"] == region) + return row["on_hand"] - row["reserved"] + row["inbound"] + + +def product_lead_time(product_id: int) -> int: + return PRODUCTS[product_id]["lead_time_days"] + + +def product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int: + totals = {} + for oid in get_orders(region, category, month_start, month_end): + o = ORDERS[oid] + totals[o["product_id"]] = totals.get(o["product_id"], 0) + o["qty"] + if not totals: + return -1 + return min((-qty, pid) for pid, qty in totals.items())[1] + + +def units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int: + total = 0 + for o in DATA["orders"]: + if o["product_id"] != product_id or o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + if c["region"] == region and month_start <= o["month"] <= month_end: + total += o["qty"] + return total + + +def tickets_for_orders(order_ids: list, severity: str) -> list: + s = set(order_ids) + return sorted(t["ticket_id"] for t in DATA["tickets"] + if t["order_id"] in s and t["severity"] == severity) + + +def ticket_order_id(ticket_id: int) -> int: + return next(t["order_id"] for t in DATA["tickets"] if t["ticket_id"] == ticket_id) + + +def sla_breached(ticket_id: int, first_response_limit_hours: int, + resolution_limit_hours: int) -> bool: + t = next(x for x in DATA["tickets"] if x["ticket_id"] == ticket_id) + return (t["first_response_hours"] > first_response_limit_hours or + t["resolution_hours"] > resolution_limit_hours) + + +def delayed_orders(order_ids: list) -> list: + s = set(order_ids) + return sorted(o["order_id"] for o in DATA["orders"] + if o["order_id"] in s and o["ship_days"] > o["promised_days"]) + + +def unique_customers(order_ids: list) -> list: + return sorted({ORDERS[oid]["customer_id"] for oid in order_ids}) + + +def count_items(values: list) -> int: + return len(values) + + +def sum_values(values: list) -> int: + return sum(values) + + +def count_true(values: list) -> int: + return sum(1 for v in values if bool(v)) + + +def count_below(values: list, threshold: int) -> int: + return sum(1 for v in values if v < threshold) + + +TOOLS = { + "region_currency": ("region_currency(region: str) -> str", + "ISO currency code for a region.", region_currency), + "get_orders": ("get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]", + "Paid/refunded order ids for a region, product category, and inclusive month window.", + get_orders), + "order_gross_usd": ("order_gross_usd(order_id: int) -> int", + "Gross order revenue in USD before discounts/refunds.", order_gross_usd), + "order_margin_usd": ("order_margin_usd(order_id: int) -> int", + "Gross order margin in USD before discounts/refunds.", order_margin_usd), + "refund_usd": ("refund_usd(order_id: int) -> int", + "Refund amount in USD for returned quantity on an order.", refund_usd), + "customer_tier": ("customer_tier(order_id: int) -> str", + "Customer loyalty tier for an order.", customer_tier), + "apply_discount": ("apply_discount(amount_usd: int, tier: str) -> int", + "Apply the order customer's loyalty discount to a USD amount.", apply_discount), + "net_revenue_usd": ("net_revenue_usd(order_id: int) -> int", + "Net USD revenue after loyalty discount and refunds.", net_revenue_usd), + "to_local": ("to_local(amount_usd: int, currency: str) -> int", + "Convert a USD integer amount to a local-currency integer.", to_local), + "inventory_position": ("inventory_position(product_id: int, region: str) -> int", + "Available inventory position: on_hand - reserved + inbound.", + inventory_position), + "product_lead_time": ("product_lead_time(product_id: int) -> int", + "Supplier lead time in days for a product.", product_lead_time), + "product_id_for_top_seller": ( + "product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int", + "Product id with the highest units sold in a region/category/month window.", + product_id_for_top_seller), + "units_sold": ("units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int", + "Units sold for one product in a region and month window.", units_sold), + "tickets_for_orders": ("tickets_for_orders(order_ids: list[int], severity: str) -> list[int]", + "Support ticket ids for given orders and severity.", tickets_for_orders), + "ticket_order_id": ("ticket_order_id(ticket_id: int) -> int", + "Order id associated with a support ticket.", ticket_order_id), + "sla_breached": ( + "sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool", + "Whether a support ticket breaches first-response or resolution SLA.", + sla_breached), + "delayed_orders": ("delayed_orders(order_ids: list[int]) -> list[int]", + "Subset of order ids whose ship_days exceeded promised_days.", delayed_orders), + "unique_customers": ("unique_customers(order_ids: list[int]) -> list[int]", + "Unique customer ids among the given orders.", unique_customers), + "count_items": ("count_items(values: list) -> int", "Length of a list.", count_items), + "sum_values": ("sum_values(values: list[int]) -> int", "Sum a list of integers.", sum_values), + "count_true": ("count_true(values: list[bool]) -> int", "Count true values.", count_true), + "count_below": ("count_below(values: list[int], threshold: int) -> int", + "Count values below a threshold.", count_below), +} + +__all__ = [name for name in TOOLS.keys()] + ['TOOLS'] diff --git a/harbor/tasks/v3_depth2_order_count_t20/environment/task.json b/harbor/tasks/v3_depth2_order_count_t20/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..a3b1ea20f9386aa86613b62c664bba9ea046a30a --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t20/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_order_count_t20", + "depth": 2, + "family": "order_count", + "params": { + "region": "NA", + "category": "C", + "month_start": 202602, + "month_end": 202604 + }, + "question": "How many paid/refunded orders are in region NA, category C, from month 202602 through 202604? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_order_count_t20/instruction.md b/harbor/tasks/v3_depth2_order_count_t20/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..ef179f5b5995c01b01136eb9f9cc045e8c644d27 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t20/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +How many paid/refunded orders are in region NA, category C, from month 202602 through 202604? Report the count. + +Available tools: +- `region_currency(region: str) -> str`: ISO currency code for a region. +- `get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]`: Paid/refunded order ids for a region, product category, and inclusive month window. +- `order_gross_usd(order_id: int) -> int`: Gross order revenue in USD before discounts/refunds. +- `order_margin_usd(order_id: int) -> int`: Gross order margin in USD before discounts/refunds. +- `refund_usd(order_id: int) -> int`: Refund amount in USD for returned quantity on an order. +- `customer_tier(order_id: int) -> str`: Customer loyalty tier for an order. +- `apply_discount(amount_usd: int, tier: str) -> int`: Apply the order customer's loyalty discount to a USD amount. +- `net_revenue_usd(order_id: int) -> int`: Net USD revenue after loyalty discount and refunds. +- `to_local(amount_usd: int, currency: str) -> int`: Convert a USD integer amount to a local-currency integer. +- `inventory_position(product_id: int, region: str) -> int`: Available inventory position: on_hand - reserved + inbound. +- `product_lead_time(product_id: int) -> int`: Supplier lead time in days for a product. +- `product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int`: Product id with the highest units sold in a region/category/month window. +- `units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int`: Units sold for one product in a region and month window. +- `tickets_for_orders(order_ids: list[int], severity: str) -> list[int]`: Support ticket ids for given orders and severity. +- `ticket_order_id(ticket_id: int) -> int`: Order id associated with a support ticket. +- `sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool`: Whether a support ticket breaches first-response or resolution SLA. +- `delayed_orders(order_ids: list[int]) -> list[int]`: Subset of order ids whose ship_days exceeded promised_days. +- `unique_customers(order_ids: list[int]) -> list[int]`: Unique customer ids among the given orders. +- `count_items(values: list) -> int`: Length of a list. +- `sum_values(values: list[int]) -> int`: Sum a list of integers. +- `count_true(values: list[bool]) -> int`: Count true values. +- `count_below(values: list[int], threshold: int) -> int`: Count values below a threshold. diff --git a/harbor/tasks/v3_depth2_order_count_t20/task.toml b/harbor/tasks/v3_depth2_order_count_t20/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..61e606e7b0d3f0ba8c5c6a5455dc865f8b29c3bd --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t20/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_order_count_t20" +description = "FlowBench v3 public task metadata. Public verifier is smoke-only." +authors = [{ name = "Mind Lab", email = "contact@mindlab.ltd" }] +keywords = ["flowbench", "tool-use", "data-orchestration", "operations"] + +[metadata] +benchmark = "FlowBench-v3" +split = "public-task-only" +category = "data-processing" +depth = 2 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +network_mode = "no-network" +build_timeout_sec = 600.0 +os = "linux" +cpus = 1 +memory_mb = 2048 +storage_mb = 2048 +gpus = 0 diff --git a/harbor/tasks/v3_depth2_order_count_t20/tests/check_output_shape.py b/harbor/tasks/v3_depth2_order_count_t20/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t20/tests/check_output_shape.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import json +import os +import re +from pathlib import Path + + +def write_reward(score: float, diagnostic: str) -> None: + log_dir = Path(os.environ.get("LOG_DIR", "/logs/verifier")) + log_dir.mkdir(parents=True, exist_ok=True) + (log_dir / "reward.txt").write_text(f"{score:.6g}\n") + (log_dir / "reward.json").write_text( + json.dumps({"reward": score, "smoke_only": True}, indent=2) + "\n" + ) + (log_dir / "diagnostic.txt").write_text(diagnostic + "\n") + + +def main() -> int: + app_dir = Path(os.environ.get("APP_DIR", "/app")) + task = json.loads((app_dir / "task.json").read_text()) + answer_path = app_dir / "answer.txt" + if not answer_path.exists(): + write_reward(0.0, "missing /app/answer.txt") + return 1 + + got = answer_path.read_text().strip() + if task["answer_format"] == "exact integer": + ok = bool(re.fullmatch(r"-?\d+", got)) + diagnostic = "valid integer smoke output" if ok else f"not an exact integer: {got!r}" + else: + ok = bool(re.fullmatch(r"[A-Za-z]+", got)) + diagnostic = "valid code smoke output" if ok else f"not an exact code: {got!r}" + + # This is intentionally not official scoring; it only verifies I/O shape. + write_reward(1.0 if ok else 0.0, diagnostic) + return 0 if ok else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/harbor/tasks/v3_depth2_order_count_t20/tests/test.sh b/harbor/tasks/v3_depth2_order_count_t20/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t20/tests/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -u +python /tests/check_output_shape.py diff --git a/harbor/tasks/v3_depth2_order_count_t21/environment/Dockerfile b/harbor/tasks/v3_depth2_order_count_t21/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t21/environment/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.12-slim +WORKDIR /app +COPY flowbench_tools.py /app/flowbench_tools.py +COPY task.json /app/task.json diff --git a/harbor/tasks/v3_depth2_order_count_t21/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_order_count_t21/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t21/environment/flowbench_tools.py @@ -0,0 +1,311 @@ +"""Deterministic FlowBench v3 tools. This file contains no task answers.""" + + +REGIONS = ["NA", "EU", "APAC", "LATAM"] +CATEGORIES = ["A", "B", "C", "D"] +CURRENCIES = {"NA": "USD", "EU": "EUR", "APAC": "JPY", "LATAM": "BRL"} +FX_TO_USD_BP = {"USD": 10000, "EUR": 10900, "JPY": 67, "BRL": 1850} +TIERS = ["std", "gold", "plat"] +DISCOUNT_PCT = {"std": 0, "gold": 10, "plat": 20} +CHANNELS = ["web", "store", "partner"] +MONTHS = [202601, 202602, 202603, 202604, 202605, 202606] + +N_CUSTOMERS = 72 +N_PRODUCTS = 48 +N_ORDERS = 720 +N_TICKETS = 260 +N_RETURNS = 180 + + +def _h(*xs): + import hashlib + s = "|".join(str(x) for x in xs).encode() + return int.from_bytes(hashlib.sha256(s).digest()[:8], "big") & 0x7FFFFFFF + + +def build_data(): + customers = [] + for cid in range(N_CUSTOMERS): + region = REGIONS[_h("region", cid) % len(REGIONS)] + customers.append({ + "customer_id": cid, + "region": region, + "tier": TIERS[_h("tier", cid) % len(TIERS)], + "segment": ["consumer", "smb", "enterprise"][_h("segment", cid) % 3], + }) + + products = [] + for pid in range(N_PRODUCTS): + cat = CATEGORIES[_h("cat", pid) % len(CATEGORIES)] + unit_price = 12 + _h("price", pid) % 240 + cogs = unit_price * (45 + _h("margin", pid) % 35) // 100 + products.append({ + "product_id": pid, + "category": cat, + "unit_price_usd": unit_price, + "unit_cogs_usd": cogs, + "lead_time_days": 3 + _h("lead", pid) % 18, + }) + + inventory = [] + for pid in range(N_PRODUCTS): + for region in REGIONS: + inventory.append({ + "product_id": pid, + "region": region, + "on_hand": 10 + _h("onhand", pid, region) % 140, + "reserved": _h("reserved", pid, region) % 28, + "inbound": _h("inbound", pid, region) % 85, + }) + + orders = [] + for oid in range(N_ORDERS): + customer_id = _h("ocust", oid) % N_CUSTOMERS + product_id = _h("oprod", oid) % N_PRODUCTS + month = MONTHS[_h("month", oid) % len(MONTHS)] + qty = 1 + _h("qty", oid) % 9 + ship_days = 1 + _h("shipdays", oid) % 16 + promised_days = 3 + _h("promise", oid) % 9 + status = ["paid", "paid", "paid", "paid", "cancelled", "refunded"][ + _h("status", oid) % 6] + orders.append({ + "order_id": oid, + "customer_id": customer_id, + "product_id": product_id, + "month": month, + "qty": qty, + "status": status, + "channel": CHANNELS[_h("channel", oid) % len(CHANNELS)], + "ship_days": ship_days, + "promised_days": promised_days, + }) + + returns = [] + for rid in range(N_RETURNS): + oid = _h("roid", rid) % N_ORDERS + order = orders[oid] + if order["status"] == "cancelled": + continue + returned_qty = 1 + _h("rqty", rid) % max(1, order["qty"]) + reason = ["defect", "late", "changed_mind", "wrong_item"][_h("reason", rid) % 4] + returns.append({ + "return_id": rid, + "order_id": oid, + "month": MONTHS[_h("rmonth", rid) % len(MONTHS)], + "returned_qty": returned_qty, + "reason": reason, + }) + + tickets = [] + for tid in range(N_TICKETS): + oid = _h("toid", tid) % N_ORDERS + severity = ["low", "medium", "high", "critical"][_h("sev", tid) % 4] + opened = MONTHS[_h("tmonth", tid) % len(MONTHS)] + first_response_hours = 1 + _h("resp", tid) % 96 + resolution_hours = first_response_hours + _h("res", tid) % 240 + tickets.append({ + "ticket_id": tid, + "order_id": oid, + "opened_month": opened, + "severity": severity, + "first_response_hours": first_response_hours, + "resolution_hours": resolution_hours, + }) + + return { + "customers": customers, + "products": products, + "inventory": inventory, + "orders": orders, + "returns": returns, + "tickets": tickets, + "fx_to_usd_bp": FX_TO_USD_BP, + } + + +DATA = build_data() +CUSTOMERS = {c["customer_id"]: c for c in DATA["customers"]} +PRODUCTS = {p["product_id"]: p for p in DATA["products"]} +ORDERS = {o["order_id"]: o for o in DATA["orders"]} + + +def region_currency(region: str) -> str: + return CURRENCIES[region] + + +def get_orders(region: str, category: str, month_start: int, month_end: int) -> list: + """Paid/refunded order ids in a region/category/month window.""" + out = [] + for o in DATA["orders"]: + if o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + p = PRODUCTS[o["product_id"]] + if c["region"] == region and p["category"] == category and month_start <= o["month"] <= month_end: + out.append(o["order_id"]) + return sorted(out) + + +def order_gross_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * p["unit_price_usd"] + + +def order_margin_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * (p["unit_price_usd"] - p["unit_cogs_usd"]) + + +def refund_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + qty = sum(r["returned_qty"] for r in DATA["returns"] if r["order_id"] == order_id) + qty = min(qty, o["qty"]) + return qty * p["unit_price_usd"] + + +def customer_tier(order_id: int) -> str: + o = ORDERS[order_id] + return CUSTOMERS[o["customer_id"]]["tier"] + + +def apply_discount(amount_usd: int, tier: str) -> int: + return amount_usd * (100 - DISCOUNT_PCT[tier]) // 100 + + +def net_revenue_usd(order_id: int) -> int: + gross = apply_discount(order_gross_usd(order_id), customer_tier(order_id)) + return max(0, gross - refund_usd(order_id)) + + +def to_local(amount_usd: int, currency: str) -> int: + return amount_usd * 10000 // FX_TO_USD_BP[currency] + + +def inventory_position(product_id: int, region: str) -> int: + row = next(x for x in DATA["inventory"] + if x["product_id"] == product_id and x["region"] == region) + return row["on_hand"] - row["reserved"] + row["inbound"] + + +def product_lead_time(product_id: int) -> int: + return PRODUCTS[product_id]["lead_time_days"] + + +def product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int: + totals = {} + for oid in get_orders(region, category, month_start, month_end): + o = ORDERS[oid] + totals[o["product_id"]] = totals.get(o["product_id"], 0) + o["qty"] + if not totals: + return -1 + return min((-qty, pid) for pid, qty in totals.items())[1] + + +def units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int: + total = 0 + for o in DATA["orders"]: + if o["product_id"] != product_id or o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + if c["region"] == region and month_start <= o["month"] <= month_end: + total += o["qty"] + return total + + +def tickets_for_orders(order_ids: list, severity: str) -> list: + s = set(order_ids) + return sorted(t["ticket_id"] for t in DATA["tickets"] + if t["order_id"] in s and t["severity"] == severity) + + +def ticket_order_id(ticket_id: int) -> int: + return next(t["order_id"] for t in DATA["tickets"] if t["ticket_id"] == ticket_id) + + +def sla_breached(ticket_id: int, first_response_limit_hours: int, + resolution_limit_hours: int) -> bool: + t = next(x for x in DATA["tickets"] if x["ticket_id"] == ticket_id) + return (t["first_response_hours"] > first_response_limit_hours or + t["resolution_hours"] > resolution_limit_hours) + + +def delayed_orders(order_ids: list) -> list: + s = set(order_ids) + return sorted(o["order_id"] for o in DATA["orders"] + if o["order_id"] in s and o["ship_days"] > o["promised_days"]) + + +def unique_customers(order_ids: list) -> list: + return sorted({ORDERS[oid]["customer_id"] for oid in order_ids}) + + +def count_items(values: list) -> int: + return len(values) + + +def sum_values(values: list) -> int: + return sum(values) + + +def count_true(values: list) -> int: + return sum(1 for v in values if bool(v)) + + +def count_below(values: list, threshold: int) -> int: + return sum(1 for v in values if v < threshold) + + +TOOLS = { + "region_currency": ("region_currency(region: str) -> str", + "ISO currency code for a region.", region_currency), + "get_orders": ("get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]", + "Paid/refunded order ids for a region, product category, and inclusive month window.", + get_orders), + "order_gross_usd": ("order_gross_usd(order_id: int) -> int", + "Gross order revenue in USD before discounts/refunds.", order_gross_usd), + "order_margin_usd": ("order_margin_usd(order_id: int) -> int", + "Gross order margin in USD before discounts/refunds.", order_margin_usd), + "refund_usd": ("refund_usd(order_id: int) -> int", + "Refund amount in USD for returned quantity on an order.", refund_usd), + "customer_tier": ("customer_tier(order_id: int) -> str", + "Customer loyalty tier for an order.", customer_tier), + "apply_discount": ("apply_discount(amount_usd: int, tier: str) -> int", + "Apply the order customer's loyalty discount to a USD amount.", apply_discount), + "net_revenue_usd": ("net_revenue_usd(order_id: int) -> int", + "Net USD revenue after loyalty discount and refunds.", net_revenue_usd), + "to_local": ("to_local(amount_usd: int, currency: str) -> int", + "Convert a USD integer amount to a local-currency integer.", to_local), + "inventory_position": ("inventory_position(product_id: int, region: str) -> int", + "Available inventory position: on_hand - reserved + inbound.", + inventory_position), + "product_lead_time": ("product_lead_time(product_id: int) -> int", + "Supplier lead time in days for a product.", product_lead_time), + "product_id_for_top_seller": ( + "product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int", + "Product id with the highest units sold in a region/category/month window.", + product_id_for_top_seller), + "units_sold": ("units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int", + "Units sold for one product in a region and month window.", units_sold), + "tickets_for_orders": ("tickets_for_orders(order_ids: list[int], severity: str) -> list[int]", + "Support ticket ids for given orders and severity.", tickets_for_orders), + "ticket_order_id": ("ticket_order_id(ticket_id: int) -> int", + "Order id associated with a support ticket.", ticket_order_id), + "sla_breached": ( + "sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool", + "Whether a support ticket breaches first-response or resolution SLA.", + sla_breached), + "delayed_orders": ("delayed_orders(order_ids: list[int]) -> list[int]", + "Subset of order ids whose ship_days exceeded promised_days.", delayed_orders), + "unique_customers": ("unique_customers(order_ids: list[int]) -> list[int]", + "Unique customer ids among the given orders.", unique_customers), + "count_items": ("count_items(values: list) -> int", "Length of a list.", count_items), + "sum_values": ("sum_values(values: list[int]) -> int", "Sum a list of integers.", sum_values), + "count_true": ("count_true(values: list[bool]) -> int", "Count true values.", count_true), + "count_below": ("count_below(values: list[int], threshold: int) -> int", + "Count values below a threshold.", count_below), +} + +__all__ = [name for name in TOOLS.keys()] + ['TOOLS'] diff --git a/harbor/tasks/v3_depth2_order_count_t21/environment/task.json b/harbor/tasks/v3_depth2_order_count_t21/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..b5034949595564c72eeeea095c9c5615eda966d1 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t21/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_order_count_t21", + "depth": 2, + "family": "order_count", + "params": { + "region": "EU", + "category": "B", + "month_start": 202604, + "month_end": 202606 + }, + "question": "How many paid/refunded orders are in region EU, category B, from month 202604 through 202606? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_order_count_t21/instruction.md b/harbor/tasks/v3_depth2_order_count_t21/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..f46db01168d52158157a0d546d537d15a86edcd6 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t21/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +How many paid/refunded orders are in region EU, category B, from month 202604 through 202606? Report the count. + +Available tools: +- `region_currency(region: str) -> str`: ISO currency code for a region. +- `get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]`: Paid/refunded order ids for a region, product category, and inclusive month window. +- `order_gross_usd(order_id: int) -> int`: Gross order revenue in USD before discounts/refunds. +- `order_margin_usd(order_id: int) -> int`: Gross order margin in USD before discounts/refunds. +- `refund_usd(order_id: int) -> int`: Refund amount in USD for returned quantity on an order. +- `customer_tier(order_id: int) -> str`: Customer loyalty tier for an order. +- `apply_discount(amount_usd: int, tier: str) -> int`: Apply the order customer's loyalty discount to a USD amount. +- `net_revenue_usd(order_id: int) -> int`: Net USD revenue after loyalty discount and refunds. +- `to_local(amount_usd: int, currency: str) -> int`: Convert a USD integer amount to a local-currency integer. +- `inventory_position(product_id: int, region: str) -> int`: Available inventory position: on_hand - reserved + inbound. +- `product_lead_time(product_id: int) -> int`: Supplier lead time in days for a product. +- `product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int`: Product id with the highest units sold in a region/category/month window. +- `units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int`: Units sold for one product in a region and month window. +- `tickets_for_orders(order_ids: list[int], severity: str) -> list[int]`: Support ticket ids for given orders and severity. +- `ticket_order_id(ticket_id: int) -> int`: Order id associated with a support ticket. +- `sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool`: Whether a support ticket breaches first-response or resolution SLA. +- `delayed_orders(order_ids: list[int]) -> list[int]`: Subset of order ids whose ship_days exceeded promised_days. +- `unique_customers(order_ids: list[int]) -> list[int]`: Unique customer ids among the given orders. +- `count_items(values: list) -> int`: Length of a list. +- `sum_values(values: list[int]) -> int`: Sum a list of integers. +- `count_true(values: list[bool]) -> int`: Count true values. +- `count_below(values: list[int], threshold: int) -> int`: Count values below a threshold. diff --git a/harbor/tasks/v3_depth2_order_count_t21/task.toml b/harbor/tasks/v3_depth2_order_count_t21/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..63fab962838237f87f6389434d1df913487770f1 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t21/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_order_count_t21" +description = "FlowBench v3 public task metadata. Public verifier is smoke-only." +authors = [{ name = "Mind Lab", email = "contact@mindlab.ltd" }] +keywords = ["flowbench", "tool-use", "data-orchestration", "operations"] + +[metadata] +benchmark = "FlowBench-v3" +split = "public-task-only" +category = "data-processing" +depth = 2 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +network_mode = "no-network" +build_timeout_sec = 600.0 +os = "linux" +cpus = 1 +memory_mb = 2048 +storage_mb = 2048 +gpus = 0 diff --git a/harbor/tasks/v3_depth2_order_count_t21/tests/check_output_shape.py b/harbor/tasks/v3_depth2_order_count_t21/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t21/tests/check_output_shape.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import json +import os +import re +from pathlib import Path + + +def write_reward(score: float, diagnostic: str) -> None: + log_dir = Path(os.environ.get("LOG_DIR", "/logs/verifier")) + log_dir.mkdir(parents=True, exist_ok=True) + (log_dir / "reward.txt").write_text(f"{score:.6g}\n") + (log_dir / "reward.json").write_text( + json.dumps({"reward": score, "smoke_only": True}, indent=2) + "\n" + ) + (log_dir / "diagnostic.txt").write_text(diagnostic + "\n") + + +def main() -> int: + app_dir = Path(os.environ.get("APP_DIR", "/app")) + task = json.loads((app_dir / "task.json").read_text()) + answer_path = app_dir / "answer.txt" + if not answer_path.exists(): + write_reward(0.0, "missing /app/answer.txt") + return 1 + + got = answer_path.read_text().strip() + if task["answer_format"] == "exact integer": + ok = bool(re.fullmatch(r"-?\d+", got)) + diagnostic = "valid integer smoke output" if ok else f"not an exact integer: {got!r}" + else: + ok = bool(re.fullmatch(r"[A-Za-z]+", got)) + diagnostic = "valid code smoke output" if ok else f"not an exact code: {got!r}" + + # This is intentionally not official scoring; it only verifies I/O shape. + write_reward(1.0 if ok else 0.0, diagnostic) + return 0 if ok else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/harbor/tasks/v3_depth2_order_count_t21/tests/test.sh b/harbor/tasks/v3_depth2_order_count_t21/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t21/tests/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -u +python /tests/check_output_shape.py diff --git a/harbor/tasks/v3_depth2_order_count_t22/environment/Dockerfile b/harbor/tasks/v3_depth2_order_count_t22/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t22/environment/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.12-slim +WORKDIR /app +COPY flowbench_tools.py /app/flowbench_tools.py +COPY task.json /app/task.json diff --git a/harbor/tasks/v3_depth2_order_count_t22/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_order_count_t22/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t22/environment/flowbench_tools.py @@ -0,0 +1,311 @@ +"""Deterministic FlowBench v3 tools. This file contains no task answers.""" + + +REGIONS = ["NA", "EU", "APAC", "LATAM"] +CATEGORIES = ["A", "B", "C", "D"] +CURRENCIES = {"NA": "USD", "EU": "EUR", "APAC": "JPY", "LATAM": "BRL"} +FX_TO_USD_BP = {"USD": 10000, "EUR": 10900, "JPY": 67, "BRL": 1850} +TIERS = ["std", "gold", "plat"] +DISCOUNT_PCT = {"std": 0, "gold": 10, "plat": 20} +CHANNELS = ["web", "store", "partner"] +MONTHS = [202601, 202602, 202603, 202604, 202605, 202606] + +N_CUSTOMERS = 72 +N_PRODUCTS = 48 +N_ORDERS = 720 +N_TICKETS = 260 +N_RETURNS = 180 + + +def _h(*xs): + import hashlib + s = "|".join(str(x) for x in xs).encode() + return int.from_bytes(hashlib.sha256(s).digest()[:8], "big") & 0x7FFFFFFF + + +def build_data(): + customers = [] + for cid in range(N_CUSTOMERS): + region = REGIONS[_h("region", cid) % len(REGIONS)] + customers.append({ + "customer_id": cid, + "region": region, + "tier": TIERS[_h("tier", cid) % len(TIERS)], + "segment": ["consumer", "smb", "enterprise"][_h("segment", cid) % 3], + }) + + products = [] + for pid in range(N_PRODUCTS): + cat = CATEGORIES[_h("cat", pid) % len(CATEGORIES)] + unit_price = 12 + _h("price", pid) % 240 + cogs = unit_price * (45 + _h("margin", pid) % 35) // 100 + products.append({ + "product_id": pid, + "category": cat, + "unit_price_usd": unit_price, + "unit_cogs_usd": cogs, + "lead_time_days": 3 + _h("lead", pid) % 18, + }) + + inventory = [] + for pid in range(N_PRODUCTS): + for region in REGIONS: + inventory.append({ + "product_id": pid, + "region": region, + "on_hand": 10 + _h("onhand", pid, region) % 140, + "reserved": _h("reserved", pid, region) % 28, + "inbound": _h("inbound", pid, region) % 85, + }) + + orders = [] + for oid in range(N_ORDERS): + customer_id = _h("ocust", oid) % N_CUSTOMERS + product_id = _h("oprod", oid) % N_PRODUCTS + month = MONTHS[_h("month", oid) % len(MONTHS)] + qty = 1 + _h("qty", oid) % 9 + ship_days = 1 + _h("shipdays", oid) % 16 + promised_days = 3 + _h("promise", oid) % 9 + status = ["paid", "paid", "paid", "paid", "cancelled", "refunded"][ + _h("status", oid) % 6] + orders.append({ + "order_id": oid, + "customer_id": customer_id, + "product_id": product_id, + "month": month, + "qty": qty, + "status": status, + "channel": CHANNELS[_h("channel", oid) % len(CHANNELS)], + "ship_days": ship_days, + "promised_days": promised_days, + }) + + returns = [] + for rid in range(N_RETURNS): + oid = _h("roid", rid) % N_ORDERS + order = orders[oid] + if order["status"] == "cancelled": + continue + returned_qty = 1 + _h("rqty", rid) % max(1, order["qty"]) + reason = ["defect", "late", "changed_mind", "wrong_item"][_h("reason", rid) % 4] + returns.append({ + "return_id": rid, + "order_id": oid, + "month": MONTHS[_h("rmonth", rid) % len(MONTHS)], + "returned_qty": returned_qty, + "reason": reason, + }) + + tickets = [] + for tid in range(N_TICKETS): + oid = _h("toid", tid) % N_ORDERS + severity = ["low", "medium", "high", "critical"][_h("sev", tid) % 4] + opened = MONTHS[_h("tmonth", tid) % len(MONTHS)] + first_response_hours = 1 + _h("resp", tid) % 96 + resolution_hours = first_response_hours + _h("res", tid) % 240 + tickets.append({ + "ticket_id": tid, + "order_id": oid, + "opened_month": opened, + "severity": severity, + "first_response_hours": first_response_hours, + "resolution_hours": resolution_hours, + }) + + return { + "customers": customers, + "products": products, + "inventory": inventory, + "orders": orders, + "returns": returns, + "tickets": tickets, + "fx_to_usd_bp": FX_TO_USD_BP, + } + + +DATA = build_data() +CUSTOMERS = {c["customer_id"]: c for c in DATA["customers"]} +PRODUCTS = {p["product_id"]: p for p in DATA["products"]} +ORDERS = {o["order_id"]: o for o in DATA["orders"]} + + +def region_currency(region: str) -> str: + return CURRENCIES[region] + + +def get_orders(region: str, category: str, month_start: int, month_end: int) -> list: + """Paid/refunded order ids in a region/category/month window.""" + out = [] + for o in DATA["orders"]: + if o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + p = PRODUCTS[o["product_id"]] + if c["region"] == region and p["category"] == category and month_start <= o["month"] <= month_end: + out.append(o["order_id"]) + return sorted(out) + + +def order_gross_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * p["unit_price_usd"] + + +def order_margin_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * (p["unit_price_usd"] - p["unit_cogs_usd"]) + + +def refund_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + qty = sum(r["returned_qty"] for r in DATA["returns"] if r["order_id"] == order_id) + qty = min(qty, o["qty"]) + return qty * p["unit_price_usd"] + + +def customer_tier(order_id: int) -> str: + o = ORDERS[order_id] + return CUSTOMERS[o["customer_id"]]["tier"] + + +def apply_discount(amount_usd: int, tier: str) -> int: + return amount_usd * (100 - DISCOUNT_PCT[tier]) // 100 + + +def net_revenue_usd(order_id: int) -> int: + gross = apply_discount(order_gross_usd(order_id), customer_tier(order_id)) + return max(0, gross - refund_usd(order_id)) + + +def to_local(amount_usd: int, currency: str) -> int: + return amount_usd * 10000 // FX_TO_USD_BP[currency] + + +def inventory_position(product_id: int, region: str) -> int: + row = next(x for x in DATA["inventory"] + if x["product_id"] == product_id and x["region"] == region) + return row["on_hand"] - row["reserved"] + row["inbound"] + + +def product_lead_time(product_id: int) -> int: + return PRODUCTS[product_id]["lead_time_days"] + + +def product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int: + totals = {} + for oid in get_orders(region, category, month_start, month_end): + o = ORDERS[oid] + totals[o["product_id"]] = totals.get(o["product_id"], 0) + o["qty"] + if not totals: + return -1 + return min((-qty, pid) for pid, qty in totals.items())[1] + + +def units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int: + total = 0 + for o in DATA["orders"]: + if o["product_id"] != product_id or o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + if c["region"] == region and month_start <= o["month"] <= month_end: + total += o["qty"] + return total + + +def tickets_for_orders(order_ids: list, severity: str) -> list: + s = set(order_ids) + return sorted(t["ticket_id"] for t in DATA["tickets"] + if t["order_id"] in s and t["severity"] == severity) + + +def ticket_order_id(ticket_id: int) -> int: + return next(t["order_id"] for t in DATA["tickets"] if t["ticket_id"] == ticket_id) + + +def sla_breached(ticket_id: int, first_response_limit_hours: int, + resolution_limit_hours: int) -> bool: + t = next(x for x in DATA["tickets"] if x["ticket_id"] == ticket_id) + return (t["first_response_hours"] > first_response_limit_hours or + t["resolution_hours"] > resolution_limit_hours) + + +def delayed_orders(order_ids: list) -> list: + s = set(order_ids) + return sorted(o["order_id"] for o in DATA["orders"] + if o["order_id"] in s and o["ship_days"] > o["promised_days"]) + + +def unique_customers(order_ids: list) -> list: + return sorted({ORDERS[oid]["customer_id"] for oid in order_ids}) + + +def count_items(values: list) -> int: + return len(values) + + +def sum_values(values: list) -> int: + return sum(values) + + +def count_true(values: list) -> int: + return sum(1 for v in values if bool(v)) + + +def count_below(values: list, threshold: int) -> int: + return sum(1 for v in values if v < threshold) + + +TOOLS = { + "region_currency": ("region_currency(region: str) -> str", + "ISO currency code for a region.", region_currency), + "get_orders": ("get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]", + "Paid/refunded order ids for a region, product category, and inclusive month window.", + get_orders), + "order_gross_usd": ("order_gross_usd(order_id: int) -> int", + "Gross order revenue in USD before discounts/refunds.", order_gross_usd), + "order_margin_usd": ("order_margin_usd(order_id: int) -> int", + "Gross order margin in USD before discounts/refunds.", order_margin_usd), + "refund_usd": ("refund_usd(order_id: int) -> int", + "Refund amount in USD for returned quantity on an order.", refund_usd), + "customer_tier": ("customer_tier(order_id: int) -> str", + "Customer loyalty tier for an order.", customer_tier), + "apply_discount": ("apply_discount(amount_usd: int, tier: str) -> int", + "Apply the order customer's loyalty discount to a USD amount.", apply_discount), + "net_revenue_usd": ("net_revenue_usd(order_id: int) -> int", + "Net USD revenue after loyalty discount and refunds.", net_revenue_usd), + "to_local": ("to_local(amount_usd: int, currency: str) -> int", + "Convert a USD integer amount to a local-currency integer.", to_local), + "inventory_position": ("inventory_position(product_id: int, region: str) -> int", + "Available inventory position: on_hand - reserved + inbound.", + inventory_position), + "product_lead_time": ("product_lead_time(product_id: int) -> int", + "Supplier lead time in days for a product.", product_lead_time), + "product_id_for_top_seller": ( + "product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int", + "Product id with the highest units sold in a region/category/month window.", + product_id_for_top_seller), + "units_sold": ("units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int", + "Units sold for one product in a region and month window.", units_sold), + "tickets_for_orders": ("tickets_for_orders(order_ids: list[int], severity: str) -> list[int]", + "Support ticket ids for given orders and severity.", tickets_for_orders), + "ticket_order_id": ("ticket_order_id(ticket_id: int) -> int", + "Order id associated with a support ticket.", ticket_order_id), + "sla_breached": ( + "sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool", + "Whether a support ticket breaches first-response or resolution SLA.", + sla_breached), + "delayed_orders": ("delayed_orders(order_ids: list[int]) -> list[int]", + "Subset of order ids whose ship_days exceeded promised_days.", delayed_orders), + "unique_customers": ("unique_customers(order_ids: list[int]) -> list[int]", + "Unique customer ids among the given orders.", unique_customers), + "count_items": ("count_items(values: list) -> int", "Length of a list.", count_items), + "sum_values": ("sum_values(values: list[int]) -> int", "Sum a list of integers.", sum_values), + "count_true": ("count_true(values: list[bool]) -> int", "Count true values.", count_true), + "count_below": ("count_below(values: list[int], threshold: int) -> int", + "Count values below a threshold.", count_below), +} + +__all__ = [name for name in TOOLS.keys()] + ['TOOLS'] diff --git a/harbor/tasks/v3_depth2_order_count_t22/environment/task.json b/harbor/tasks/v3_depth2_order_count_t22/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..21cdfe4e1e859f8612aeb2102fb596b265b8f220 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t22/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_order_count_t22", + "depth": 2, + "family": "order_count", + "params": { + "region": "APAC", + "category": "D", + "month_start": 202603, + "month_end": 202605 + }, + "question": "How many paid/refunded orders are in region APAC, category D, from month 202603 through 202605? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_order_count_t22/instruction.md b/harbor/tasks/v3_depth2_order_count_t22/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..ba2066489c6c60e629294356980cf1d307bf6041 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t22/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +How many paid/refunded orders are in region APAC, category D, from month 202603 through 202605? Report the count. + +Available tools: +- `region_currency(region: str) -> str`: ISO currency code for a region. +- `get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]`: Paid/refunded order ids for a region, product category, and inclusive month window. +- `order_gross_usd(order_id: int) -> int`: Gross order revenue in USD before discounts/refunds. +- `order_margin_usd(order_id: int) -> int`: Gross order margin in USD before discounts/refunds. +- `refund_usd(order_id: int) -> int`: Refund amount in USD for returned quantity on an order. +- `customer_tier(order_id: int) -> str`: Customer loyalty tier for an order. +- `apply_discount(amount_usd: int, tier: str) -> int`: Apply the order customer's loyalty discount to a USD amount. +- `net_revenue_usd(order_id: int) -> int`: Net USD revenue after loyalty discount and refunds. +- `to_local(amount_usd: int, currency: str) -> int`: Convert a USD integer amount to a local-currency integer. +- `inventory_position(product_id: int, region: str) -> int`: Available inventory position: on_hand - reserved + inbound. +- `product_lead_time(product_id: int) -> int`: Supplier lead time in days for a product. +- `product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int`: Product id with the highest units sold in a region/category/month window. +- `units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int`: Units sold for one product in a region and month window. +- `tickets_for_orders(order_ids: list[int], severity: str) -> list[int]`: Support ticket ids for given orders and severity. +- `ticket_order_id(ticket_id: int) -> int`: Order id associated with a support ticket. +- `sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool`: Whether a support ticket breaches first-response or resolution SLA. +- `delayed_orders(order_ids: list[int]) -> list[int]`: Subset of order ids whose ship_days exceeded promised_days. +- `unique_customers(order_ids: list[int]) -> list[int]`: Unique customer ids among the given orders. +- `count_items(values: list) -> int`: Length of a list. +- `sum_values(values: list[int]) -> int`: Sum a list of integers. +- `count_true(values: list[bool]) -> int`: Count true values. +- `count_below(values: list[int], threshold: int) -> int`: Count values below a threshold. diff --git a/harbor/tasks/v3_depth2_order_count_t22/task.toml b/harbor/tasks/v3_depth2_order_count_t22/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..a7315cf788f9a61b003957fd4f7d72fab1c9c406 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t22/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_order_count_t22" +description = "FlowBench v3 public task metadata. Public verifier is smoke-only." +authors = [{ name = "Mind Lab", email = "contact@mindlab.ltd" }] +keywords = ["flowbench", "tool-use", "data-orchestration", "operations"] + +[metadata] +benchmark = "FlowBench-v3" +split = "public-task-only" +category = "data-processing" +depth = 2 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +network_mode = "no-network" +build_timeout_sec = 600.0 +os = "linux" +cpus = 1 +memory_mb = 2048 +storage_mb = 2048 +gpus = 0 diff --git a/harbor/tasks/v3_depth2_order_count_t22/tests/check_output_shape.py b/harbor/tasks/v3_depth2_order_count_t22/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t22/tests/check_output_shape.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import json +import os +import re +from pathlib import Path + + +def write_reward(score: float, diagnostic: str) -> None: + log_dir = Path(os.environ.get("LOG_DIR", "/logs/verifier")) + log_dir.mkdir(parents=True, exist_ok=True) + (log_dir / "reward.txt").write_text(f"{score:.6g}\n") + (log_dir / "reward.json").write_text( + json.dumps({"reward": score, "smoke_only": True}, indent=2) + "\n" + ) + (log_dir / "diagnostic.txt").write_text(diagnostic + "\n") + + +def main() -> int: + app_dir = Path(os.environ.get("APP_DIR", "/app")) + task = json.loads((app_dir / "task.json").read_text()) + answer_path = app_dir / "answer.txt" + if not answer_path.exists(): + write_reward(0.0, "missing /app/answer.txt") + return 1 + + got = answer_path.read_text().strip() + if task["answer_format"] == "exact integer": + ok = bool(re.fullmatch(r"-?\d+", got)) + diagnostic = "valid integer smoke output" if ok else f"not an exact integer: {got!r}" + else: + ok = bool(re.fullmatch(r"[A-Za-z]+", got)) + diagnostic = "valid code smoke output" if ok else f"not an exact code: {got!r}" + + # This is intentionally not official scoring; it only verifies I/O shape. + write_reward(1.0 if ok else 0.0, diagnostic) + return 0 if ok else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/harbor/tasks/v3_depth2_order_count_t22/tests/test.sh b/harbor/tasks/v3_depth2_order_count_t22/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t22/tests/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -u +python /tests/check_output_shape.py diff --git a/harbor/tasks/v3_depth2_order_count_t23/environment/Dockerfile b/harbor/tasks/v3_depth2_order_count_t23/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t23/environment/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.12-slim +WORKDIR /app +COPY flowbench_tools.py /app/flowbench_tools.py +COPY task.json /app/task.json diff --git a/harbor/tasks/v3_depth2_order_count_t23/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_order_count_t23/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t23/environment/flowbench_tools.py @@ -0,0 +1,311 @@ +"""Deterministic FlowBench v3 tools. This file contains no task answers.""" + + +REGIONS = ["NA", "EU", "APAC", "LATAM"] +CATEGORIES = ["A", "B", "C", "D"] +CURRENCIES = {"NA": "USD", "EU": "EUR", "APAC": "JPY", "LATAM": "BRL"} +FX_TO_USD_BP = {"USD": 10000, "EUR": 10900, "JPY": 67, "BRL": 1850} +TIERS = ["std", "gold", "plat"] +DISCOUNT_PCT = {"std": 0, "gold": 10, "plat": 20} +CHANNELS = ["web", "store", "partner"] +MONTHS = [202601, 202602, 202603, 202604, 202605, 202606] + +N_CUSTOMERS = 72 +N_PRODUCTS = 48 +N_ORDERS = 720 +N_TICKETS = 260 +N_RETURNS = 180 + + +def _h(*xs): + import hashlib + s = "|".join(str(x) for x in xs).encode() + return int.from_bytes(hashlib.sha256(s).digest()[:8], "big") & 0x7FFFFFFF + + +def build_data(): + customers = [] + for cid in range(N_CUSTOMERS): + region = REGIONS[_h("region", cid) % len(REGIONS)] + customers.append({ + "customer_id": cid, + "region": region, + "tier": TIERS[_h("tier", cid) % len(TIERS)], + "segment": ["consumer", "smb", "enterprise"][_h("segment", cid) % 3], + }) + + products = [] + for pid in range(N_PRODUCTS): + cat = CATEGORIES[_h("cat", pid) % len(CATEGORIES)] + unit_price = 12 + _h("price", pid) % 240 + cogs = unit_price * (45 + _h("margin", pid) % 35) // 100 + products.append({ + "product_id": pid, + "category": cat, + "unit_price_usd": unit_price, + "unit_cogs_usd": cogs, + "lead_time_days": 3 + _h("lead", pid) % 18, + }) + + inventory = [] + for pid in range(N_PRODUCTS): + for region in REGIONS: + inventory.append({ + "product_id": pid, + "region": region, + "on_hand": 10 + _h("onhand", pid, region) % 140, + "reserved": _h("reserved", pid, region) % 28, + "inbound": _h("inbound", pid, region) % 85, + }) + + orders = [] + for oid in range(N_ORDERS): + customer_id = _h("ocust", oid) % N_CUSTOMERS + product_id = _h("oprod", oid) % N_PRODUCTS + month = MONTHS[_h("month", oid) % len(MONTHS)] + qty = 1 + _h("qty", oid) % 9 + ship_days = 1 + _h("shipdays", oid) % 16 + promised_days = 3 + _h("promise", oid) % 9 + status = ["paid", "paid", "paid", "paid", "cancelled", "refunded"][ + _h("status", oid) % 6] + orders.append({ + "order_id": oid, + "customer_id": customer_id, + "product_id": product_id, + "month": month, + "qty": qty, + "status": status, + "channel": CHANNELS[_h("channel", oid) % len(CHANNELS)], + "ship_days": ship_days, + "promised_days": promised_days, + }) + + returns = [] + for rid in range(N_RETURNS): + oid = _h("roid", rid) % N_ORDERS + order = orders[oid] + if order["status"] == "cancelled": + continue + returned_qty = 1 + _h("rqty", rid) % max(1, order["qty"]) + reason = ["defect", "late", "changed_mind", "wrong_item"][_h("reason", rid) % 4] + returns.append({ + "return_id": rid, + "order_id": oid, + "month": MONTHS[_h("rmonth", rid) % len(MONTHS)], + "returned_qty": returned_qty, + "reason": reason, + }) + + tickets = [] + for tid in range(N_TICKETS): + oid = _h("toid", tid) % N_ORDERS + severity = ["low", "medium", "high", "critical"][_h("sev", tid) % 4] + opened = MONTHS[_h("tmonth", tid) % len(MONTHS)] + first_response_hours = 1 + _h("resp", tid) % 96 + resolution_hours = first_response_hours + _h("res", tid) % 240 + tickets.append({ + "ticket_id": tid, + "order_id": oid, + "opened_month": opened, + "severity": severity, + "first_response_hours": first_response_hours, + "resolution_hours": resolution_hours, + }) + + return { + "customers": customers, + "products": products, + "inventory": inventory, + "orders": orders, + "returns": returns, + "tickets": tickets, + "fx_to_usd_bp": FX_TO_USD_BP, + } + + +DATA = build_data() +CUSTOMERS = {c["customer_id"]: c for c in DATA["customers"]} +PRODUCTS = {p["product_id"]: p for p in DATA["products"]} +ORDERS = {o["order_id"]: o for o in DATA["orders"]} + + +def region_currency(region: str) -> str: + return CURRENCIES[region] + + +def get_orders(region: str, category: str, month_start: int, month_end: int) -> list: + """Paid/refunded order ids in a region/category/month window.""" + out = [] + for o in DATA["orders"]: + if o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + p = PRODUCTS[o["product_id"]] + if c["region"] == region and p["category"] == category and month_start <= o["month"] <= month_end: + out.append(o["order_id"]) + return sorted(out) + + +def order_gross_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * p["unit_price_usd"] + + +def order_margin_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * (p["unit_price_usd"] - p["unit_cogs_usd"]) + + +def refund_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + qty = sum(r["returned_qty"] for r in DATA["returns"] if r["order_id"] == order_id) + qty = min(qty, o["qty"]) + return qty * p["unit_price_usd"] + + +def customer_tier(order_id: int) -> str: + o = ORDERS[order_id] + return CUSTOMERS[o["customer_id"]]["tier"] + + +def apply_discount(amount_usd: int, tier: str) -> int: + return amount_usd * (100 - DISCOUNT_PCT[tier]) // 100 + + +def net_revenue_usd(order_id: int) -> int: + gross = apply_discount(order_gross_usd(order_id), customer_tier(order_id)) + return max(0, gross - refund_usd(order_id)) + + +def to_local(amount_usd: int, currency: str) -> int: + return amount_usd * 10000 // FX_TO_USD_BP[currency] + + +def inventory_position(product_id: int, region: str) -> int: + row = next(x for x in DATA["inventory"] + if x["product_id"] == product_id and x["region"] == region) + return row["on_hand"] - row["reserved"] + row["inbound"] + + +def product_lead_time(product_id: int) -> int: + return PRODUCTS[product_id]["lead_time_days"] + + +def product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int: + totals = {} + for oid in get_orders(region, category, month_start, month_end): + o = ORDERS[oid] + totals[o["product_id"]] = totals.get(o["product_id"], 0) + o["qty"] + if not totals: + return -1 + return min((-qty, pid) for pid, qty in totals.items())[1] + + +def units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int: + total = 0 + for o in DATA["orders"]: + if o["product_id"] != product_id or o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + if c["region"] == region and month_start <= o["month"] <= month_end: + total += o["qty"] + return total + + +def tickets_for_orders(order_ids: list, severity: str) -> list: + s = set(order_ids) + return sorted(t["ticket_id"] for t in DATA["tickets"] + if t["order_id"] in s and t["severity"] == severity) + + +def ticket_order_id(ticket_id: int) -> int: + return next(t["order_id"] for t in DATA["tickets"] if t["ticket_id"] == ticket_id) + + +def sla_breached(ticket_id: int, first_response_limit_hours: int, + resolution_limit_hours: int) -> bool: + t = next(x for x in DATA["tickets"] if x["ticket_id"] == ticket_id) + return (t["first_response_hours"] > first_response_limit_hours or + t["resolution_hours"] > resolution_limit_hours) + + +def delayed_orders(order_ids: list) -> list: + s = set(order_ids) + return sorted(o["order_id"] for o in DATA["orders"] + if o["order_id"] in s and o["ship_days"] > o["promised_days"]) + + +def unique_customers(order_ids: list) -> list: + return sorted({ORDERS[oid]["customer_id"] for oid in order_ids}) + + +def count_items(values: list) -> int: + return len(values) + + +def sum_values(values: list) -> int: + return sum(values) + + +def count_true(values: list) -> int: + return sum(1 for v in values if bool(v)) + + +def count_below(values: list, threshold: int) -> int: + return sum(1 for v in values if v < threshold) + + +TOOLS = { + "region_currency": ("region_currency(region: str) -> str", + "ISO currency code for a region.", region_currency), + "get_orders": ("get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]", + "Paid/refunded order ids for a region, product category, and inclusive month window.", + get_orders), + "order_gross_usd": ("order_gross_usd(order_id: int) -> int", + "Gross order revenue in USD before discounts/refunds.", order_gross_usd), + "order_margin_usd": ("order_margin_usd(order_id: int) -> int", + "Gross order margin in USD before discounts/refunds.", order_margin_usd), + "refund_usd": ("refund_usd(order_id: int) -> int", + "Refund amount in USD for returned quantity on an order.", refund_usd), + "customer_tier": ("customer_tier(order_id: int) -> str", + "Customer loyalty tier for an order.", customer_tier), + "apply_discount": ("apply_discount(amount_usd: int, tier: str) -> int", + "Apply the order customer's loyalty discount to a USD amount.", apply_discount), + "net_revenue_usd": ("net_revenue_usd(order_id: int) -> int", + "Net USD revenue after loyalty discount and refunds.", net_revenue_usd), + "to_local": ("to_local(amount_usd: int, currency: str) -> int", + "Convert a USD integer amount to a local-currency integer.", to_local), + "inventory_position": ("inventory_position(product_id: int, region: str) -> int", + "Available inventory position: on_hand - reserved + inbound.", + inventory_position), + "product_lead_time": ("product_lead_time(product_id: int) -> int", + "Supplier lead time in days for a product.", product_lead_time), + "product_id_for_top_seller": ( + "product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int", + "Product id with the highest units sold in a region/category/month window.", + product_id_for_top_seller), + "units_sold": ("units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int", + "Units sold for one product in a region and month window.", units_sold), + "tickets_for_orders": ("tickets_for_orders(order_ids: list[int], severity: str) -> list[int]", + "Support ticket ids for given orders and severity.", tickets_for_orders), + "ticket_order_id": ("ticket_order_id(ticket_id: int) -> int", + "Order id associated with a support ticket.", ticket_order_id), + "sla_breached": ( + "sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool", + "Whether a support ticket breaches first-response or resolution SLA.", + sla_breached), + "delayed_orders": ("delayed_orders(order_ids: list[int]) -> list[int]", + "Subset of order ids whose ship_days exceeded promised_days.", delayed_orders), + "unique_customers": ("unique_customers(order_ids: list[int]) -> list[int]", + "Unique customer ids among the given orders.", unique_customers), + "count_items": ("count_items(values: list) -> int", "Length of a list.", count_items), + "sum_values": ("sum_values(values: list[int]) -> int", "Sum a list of integers.", sum_values), + "count_true": ("count_true(values: list[bool]) -> int", "Count true values.", count_true), + "count_below": ("count_below(values: list[int], threshold: int) -> int", + "Count values below a threshold.", count_below), +} + +__all__ = [name for name in TOOLS.keys()] + ['TOOLS'] diff --git a/harbor/tasks/v3_depth2_order_count_t23/environment/task.json b/harbor/tasks/v3_depth2_order_count_t23/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..7fc831089ac68f0fb95d7fe1e442f43fa1a49ab6 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t23/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_order_count_t23", + "depth": 2, + "family": "order_count", + "params": { + "region": "LATAM", + "category": "C", + "month_start": 202601, + "month_end": 202602 + }, + "question": "How many paid/refunded orders are in region LATAM, category C, from month 202601 through 202602? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_order_count_t23/instruction.md b/harbor/tasks/v3_depth2_order_count_t23/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..0fe9f946ef6c0af59396ab11f7a99e5d079b6752 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t23/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +How many paid/refunded orders are in region LATAM, category C, from month 202601 through 202602? Report the count. + +Available tools: +- `region_currency(region: str) -> str`: ISO currency code for a region. +- `get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]`: Paid/refunded order ids for a region, product category, and inclusive month window. +- `order_gross_usd(order_id: int) -> int`: Gross order revenue in USD before discounts/refunds. +- `order_margin_usd(order_id: int) -> int`: Gross order margin in USD before discounts/refunds. +- `refund_usd(order_id: int) -> int`: Refund amount in USD for returned quantity on an order. +- `customer_tier(order_id: int) -> str`: Customer loyalty tier for an order. +- `apply_discount(amount_usd: int, tier: str) -> int`: Apply the order customer's loyalty discount to a USD amount. +- `net_revenue_usd(order_id: int) -> int`: Net USD revenue after loyalty discount and refunds. +- `to_local(amount_usd: int, currency: str) -> int`: Convert a USD integer amount to a local-currency integer. +- `inventory_position(product_id: int, region: str) -> int`: Available inventory position: on_hand - reserved + inbound. +- `product_lead_time(product_id: int) -> int`: Supplier lead time in days for a product. +- `product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int`: Product id with the highest units sold in a region/category/month window. +- `units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int`: Units sold for one product in a region and month window. +- `tickets_for_orders(order_ids: list[int], severity: str) -> list[int]`: Support ticket ids for given orders and severity. +- `ticket_order_id(ticket_id: int) -> int`: Order id associated with a support ticket. +- `sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool`: Whether a support ticket breaches first-response or resolution SLA. +- `delayed_orders(order_ids: list[int]) -> list[int]`: Subset of order ids whose ship_days exceeded promised_days. +- `unique_customers(order_ids: list[int]) -> list[int]`: Unique customer ids among the given orders. +- `count_items(values: list) -> int`: Length of a list. +- `sum_values(values: list[int]) -> int`: Sum a list of integers. +- `count_true(values: list[bool]) -> int`: Count true values. +- `count_below(values: list[int], threshold: int) -> int`: Count values below a threshold. diff --git a/harbor/tasks/v3_depth2_order_count_t23/task.toml b/harbor/tasks/v3_depth2_order_count_t23/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..74c2a2a6cfa852661201bec0dfc9c4eb44c3bb13 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t23/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_order_count_t23" +description = "FlowBench v3 public task metadata. Public verifier is smoke-only." +authors = [{ name = "Mind Lab", email = "contact@mindlab.ltd" }] +keywords = ["flowbench", "tool-use", "data-orchestration", "operations"] + +[metadata] +benchmark = "FlowBench-v3" +split = "public-task-only" +category = "data-processing" +depth = 2 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +network_mode = "no-network" +build_timeout_sec = 600.0 +os = "linux" +cpus = 1 +memory_mb = 2048 +storage_mb = 2048 +gpus = 0 diff --git a/harbor/tasks/v3_depth2_order_count_t23/tests/check_output_shape.py b/harbor/tasks/v3_depth2_order_count_t23/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t23/tests/check_output_shape.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import json +import os +import re +from pathlib import Path + + +def write_reward(score: float, diagnostic: str) -> None: + log_dir = Path(os.environ.get("LOG_DIR", "/logs/verifier")) + log_dir.mkdir(parents=True, exist_ok=True) + (log_dir / "reward.txt").write_text(f"{score:.6g}\n") + (log_dir / "reward.json").write_text( + json.dumps({"reward": score, "smoke_only": True}, indent=2) + "\n" + ) + (log_dir / "diagnostic.txt").write_text(diagnostic + "\n") + + +def main() -> int: + app_dir = Path(os.environ.get("APP_DIR", "/app")) + task = json.loads((app_dir / "task.json").read_text()) + answer_path = app_dir / "answer.txt" + if not answer_path.exists(): + write_reward(0.0, "missing /app/answer.txt") + return 1 + + got = answer_path.read_text().strip() + if task["answer_format"] == "exact integer": + ok = bool(re.fullmatch(r"-?\d+", got)) + diagnostic = "valid integer smoke output" if ok else f"not an exact integer: {got!r}" + else: + ok = bool(re.fullmatch(r"[A-Za-z]+", got)) + diagnostic = "valid code smoke output" if ok else f"not an exact code: {got!r}" + + # This is intentionally not official scoring; it only verifies I/O shape. + write_reward(1.0 if ok else 0.0, diagnostic) + return 0 if ok else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/harbor/tasks/v3_depth2_order_count_t23/tests/test.sh b/harbor/tasks/v3_depth2_order_count_t23/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t23/tests/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -u +python /tests/check_output_shape.py diff --git a/harbor/tasks/v3_depth2_order_count_t24/environment/Dockerfile b/harbor/tasks/v3_depth2_order_count_t24/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t24/environment/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.12-slim +WORKDIR /app +COPY flowbench_tools.py /app/flowbench_tools.py +COPY task.json /app/task.json diff --git a/harbor/tasks/v3_depth2_order_count_t24/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_order_count_t24/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t24/environment/flowbench_tools.py @@ -0,0 +1,311 @@ +"""Deterministic FlowBench v3 tools. This file contains no task answers.""" + + +REGIONS = ["NA", "EU", "APAC", "LATAM"] +CATEGORIES = ["A", "B", "C", "D"] +CURRENCIES = {"NA": "USD", "EU": "EUR", "APAC": "JPY", "LATAM": "BRL"} +FX_TO_USD_BP = {"USD": 10000, "EUR": 10900, "JPY": 67, "BRL": 1850} +TIERS = ["std", "gold", "plat"] +DISCOUNT_PCT = {"std": 0, "gold": 10, "plat": 20} +CHANNELS = ["web", "store", "partner"] +MONTHS = [202601, 202602, 202603, 202604, 202605, 202606] + +N_CUSTOMERS = 72 +N_PRODUCTS = 48 +N_ORDERS = 720 +N_TICKETS = 260 +N_RETURNS = 180 + + +def _h(*xs): + import hashlib + s = "|".join(str(x) for x in xs).encode() + return int.from_bytes(hashlib.sha256(s).digest()[:8], "big") & 0x7FFFFFFF + + +def build_data(): + customers = [] + for cid in range(N_CUSTOMERS): + region = REGIONS[_h("region", cid) % len(REGIONS)] + customers.append({ + "customer_id": cid, + "region": region, + "tier": TIERS[_h("tier", cid) % len(TIERS)], + "segment": ["consumer", "smb", "enterprise"][_h("segment", cid) % 3], + }) + + products = [] + for pid in range(N_PRODUCTS): + cat = CATEGORIES[_h("cat", pid) % len(CATEGORIES)] + unit_price = 12 + _h("price", pid) % 240 + cogs = unit_price * (45 + _h("margin", pid) % 35) // 100 + products.append({ + "product_id": pid, + "category": cat, + "unit_price_usd": unit_price, + "unit_cogs_usd": cogs, + "lead_time_days": 3 + _h("lead", pid) % 18, + }) + + inventory = [] + for pid in range(N_PRODUCTS): + for region in REGIONS: + inventory.append({ + "product_id": pid, + "region": region, + "on_hand": 10 + _h("onhand", pid, region) % 140, + "reserved": _h("reserved", pid, region) % 28, + "inbound": _h("inbound", pid, region) % 85, + }) + + orders = [] + for oid in range(N_ORDERS): + customer_id = _h("ocust", oid) % N_CUSTOMERS + product_id = _h("oprod", oid) % N_PRODUCTS + month = MONTHS[_h("month", oid) % len(MONTHS)] + qty = 1 + _h("qty", oid) % 9 + ship_days = 1 + _h("shipdays", oid) % 16 + promised_days = 3 + _h("promise", oid) % 9 + status = ["paid", "paid", "paid", "paid", "cancelled", "refunded"][ + _h("status", oid) % 6] + orders.append({ + "order_id": oid, + "customer_id": customer_id, + "product_id": product_id, + "month": month, + "qty": qty, + "status": status, + "channel": CHANNELS[_h("channel", oid) % len(CHANNELS)], + "ship_days": ship_days, + "promised_days": promised_days, + }) + + returns = [] + for rid in range(N_RETURNS): + oid = _h("roid", rid) % N_ORDERS + order = orders[oid] + if order["status"] == "cancelled": + continue + returned_qty = 1 + _h("rqty", rid) % max(1, order["qty"]) + reason = ["defect", "late", "changed_mind", "wrong_item"][_h("reason", rid) % 4] + returns.append({ + "return_id": rid, + "order_id": oid, + "month": MONTHS[_h("rmonth", rid) % len(MONTHS)], + "returned_qty": returned_qty, + "reason": reason, + }) + + tickets = [] + for tid in range(N_TICKETS): + oid = _h("toid", tid) % N_ORDERS + severity = ["low", "medium", "high", "critical"][_h("sev", tid) % 4] + opened = MONTHS[_h("tmonth", tid) % len(MONTHS)] + first_response_hours = 1 + _h("resp", tid) % 96 + resolution_hours = first_response_hours + _h("res", tid) % 240 + tickets.append({ + "ticket_id": tid, + "order_id": oid, + "opened_month": opened, + "severity": severity, + "first_response_hours": first_response_hours, + "resolution_hours": resolution_hours, + }) + + return { + "customers": customers, + "products": products, + "inventory": inventory, + "orders": orders, + "returns": returns, + "tickets": tickets, + "fx_to_usd_bp": FX_TO_USD_BP, + } + + +DATA = build_data() +CUSTOMERS = {c["customer_id"]: c for c in DATA["customers"]} +PRODUCTS = {p["product_id"]: p for p in DATA["products"]} +ORDERS = {o["order_id"]: o for o in DATA["orders"]} + + +def region_currency(region: str) -> str: + return CURRENCIES[region] + + +def get_orders(region: str, category: str, month_start: int, month_end: int) -> list: + """Paid/refunded order ids in a region/category/month window.""" + out = [] + for o in DATA["orders"]: + if o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + p = PRODUCTS[o["product_id"]] + if c["region"] == region and p["category"] == category and month_start <= o["month"] <= month_end: + out.append(o["order_id"]) + return sorted(out) + + +def order_gross_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * p["unit_price_usd"] + + +def order_margin_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * (p["unit_price_usd"] - p["unit_cogs_usd"]) + + +def refund_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + qty = sum(r["returned_qty"] for r in DATA["returns"] if r["order_id"] == order_id) + qty = min(qty, o["qty"]) + return qty * p["unit_price_usd"] + + +def customer_tier(order_id: int) -> str: + o = ORDERS[order_id] + return CUSTOMERS[o["customer_id"]]["tier"] + + +def apply_discount(amount_usd: int, tier: str) -> int: + return amount_usd * (100 - DISCOUNT_PCT[tier]) // 100 + + +def net_revenue_usd(order_id: int) -> int: + gross = apply_discount(order_gross_usd(order_id), customer_tier(order_id)) + return max(0, gross - refund_usd(order_id)) + + +def to_local(amount_usd: int, currency: str) -> int: + return amount_usd * 10000 // FX_TO_USD_BP[currency] + + +def inventory_position(product_id: int, region: str) -> int: + row = next(x for x in DATA["inventory"] + if x["product_id"] == product_id and x["region"] == region) + return row["on_hand"] - row["reserved"] + row["inbound"] + + +def product_lead_time(product_id: int) -> int: + return PRODUCTS[product_id]["lead_time_days"] + + +def product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int: + totals = {} + for oid in get_orders(region, category, month_start, month_end): + o = ORDERS[oid] + totals[o["product_id"]] = totals.get(o["product_id"], 0) + o["qty"] + if not totals: + return -1 + return min((-qty, pid) for pid, qty in totals.items())[1] + + +def units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int: + total = 0 + for o in DATA["orders"]: + if o["product_id"] != product_id or o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + if c["region"] == region and month_start <= o["month"] <= month_end: + total += o["qty"] + return total + + +def tickets_for_orders(order_ids: list, severity: str) -> list: + s = set(order_ids) + return sorted(t["ticket_id"] for t in DATA["tickets"] + if t["order_id"] in s and t["severity"] == severity) + + +def ticket_order_id(ticket_id: int) -> int: + return next(t["order_id"] for t in DATA["tickets"] if t["ticket_id"] == ticket_id) + + +def sla_breached(ticket_id: int, first_response_limit_hours: int, + resolution_limit_hours: int) -> bool: + t = next(x for x in DATA["tickets"] if x["ticket_id"] == ticket_id) + return (t["first_response_hours"] > first_response_limit_hours or + t["resolution_hours"] > resolution_limit_hours) + + +def delayed_orders(order_ids: list) -> list: + s = set(order_ids) + return sorted(o["order_id"] for o in DATA["orders"] + if o["order_id"] in s and o["ship_days"] > o["promised_days"]) + + +def unique_customers(order_ids: list) -> list: + return sorted({ORDERS[oid]["customer_id"] for oid in order_ids}) + + +def count_items(values: list) -> int: + return len(values) + + +def sum_values(values: list) -> int: + return sum(values) + + +def count_true(values: list) -> int: + return sum(1 for v in values if bool(v)) + + +def count_below(values: list, threshold: int) -> int: + return sum(1 for v in values if v < threshold) + + +TOOLS = { + "region_currency": ("region_currency(region: str) -> str", + "ISO currency code for a region.", region_currency), + "get_orders": ("get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]", + "Paid/refunded order ids for a region, product category, and inclusive month window.", + get_orders), + "order_gross_usd": ("order_gross_usd(order_id: int) -> int", + "Gross order revenue in USD before discounts/refunds.", order_gross_usd), + "order_margin_usd": ("order_margin_usd(order_id: int) -> int", + "Gross order margin in USD before discounts/refunds.", order_margin_usd), + "refund_usd": ("refund_usd(order_id: int) -> int", + "Refund amount in USD for returned quantity on an order.", refund_usd), + "customer_tier": ("customer_tier(order_id: int) -> str", + "Customer loyalty tier for an order.", customer_tier), + "apply_discount": ("apply_discount(amount_usd: int, tier: str) -> int", + "Apply the order customer's loyalty discount to a USD amount.", apply_discount), + "net_revenue_usd": ("net_revenue_usd(order_id: int) -> int", + "Net USD revenue after loyalty discount and refunds.", net_revenue_usd), + "to_local": ("to_local(amount_usd: int, currency: str) -> int", + "Convert a USD integer amount to a local-currency integer.", to_local), + "inventory_position": ("inventory_position(product_id: int, region: str) -> int", + "Available inventory position: on_hand - reserved + inbound.", + inventory_position), + "product_lead_time": ("product_lead_time(product_id: int) -> int", + "Supplier lead time in days for a product.", product_lead_time), + "product_id_for_top_seller": ( + "product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int", + "Product id with the highest units sold in a region/category/month window.", + product_id_for_top_seller), + "units_sold": ("units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int", + "Units sold for one product in a region and month window.", units_sold), + "tickets_for_orders": ("tickets_for_orders(order_ids: list[int], severity: str) -> list[int]", + "Support ticket ids for given orders and severity.", tickets_for_orders), + "ticket_order_id": ("ticket_order_id(ticket_id: int) -> int", + "Order id associated with a support ticket.", ticket_order_id), + "sla_breached": ( + "sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool", + "Whether a support ticket breaches first-response or resolution SLA.", + sla_breached), + "delayed_orders": ("delayed_orders(order_ids: list[int]) -> list[int]", + "Subset of order ids whose ship_days exceeded promised_days.", delayed_orders), + "unique_customers": ("unique_customers(order_ids: list[int]) -> list[int]", + "Unique customer ids among the given orders.", unique_customers), + "count_items": ("count_items(values: list) -> int", "Length of a list.", count_items), + "sum_values": ("sum_values(values: list[int]) -> int", "Sum a list of integers.", sum_values), + "count_true": ("count_true(values: list[bool]) -> int", "Count true values.", count_true), + "count_below": ("count_below(values: list[int], threshold: int) -> int", + "Count values below a threshold.", count_below), +} + +__all__ = [name for name in TOOLS.keys()] + ['TOOLS'] diff --git a/harbor/tasks/v3_depth2_order_count_t24/environment/task.json b/harbor/tasks/v3_depth2_order_count_t24/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..c338aa1eb623e572068486030aca8660d35880b2 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t24/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_order_count_t24", + "depth": 2, + "family": "order_count", + "params": { + "region": "NA", + "category": "D", + "month_start": 202601, + "month_end": 202603 + }, + "question": "How many paid/refunded orders are in region NA, category D, from month 202601 through 202603? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_order_count_t24/instruction.md b/harbor/tasks/v3_depth2_order_count_t24/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..85e9fbd938f93888ad0c09dea15e7bf24c6062c7 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t24/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +How many paid/refunded orders are in region NA, category D, from month 202601 through 202603? Report the count. + +Available tools: +- `region_currency(region: str) -> str`: ISO currency code for a region. +- `get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]`: Paid/refunded order ids for a region, product category, and inclusive month window. +- `order_gross_usd(order_id: int) -> int`: Gross order revenue in USD before discounts/refunds. +- `order_margin_usd(order_id: int) -> int`: Gross order margin in USD before discounts/refunds. +- `refund_usd(order_id: int) -> int`: Refund amount in USD for returned quantity on an order. +- `customer_tier(order_id: int) -> str`: Customer loyalty tier for an order. +- `apply_discount(amount_usd: int, tier: str) -> int`: Apply the order customer's loyalty discount to a USD amount. +- `net_revenue_usd(order_id: int) -> int`: Net USD revenue after loyalty discount and refunds. +- `to_local(amount_usd: int, currency: str) -> int`: Convert a USD integer amount to a local-currency integer. +- `inventory_position(product_id: int, region: str) -> int`: Available inventory position: on_hand - reserved + inbound. +- `product_lead_time(product_id: int) -> int`: Supplier lead time in days for a product. +- `product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int`: Product id with the highest units sold in a region/category/month window. +- `units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int`: Units sold for one product in a region and month window. +- `tickets_for_orders(order_ids: list[int], severity: str) -> list[int]`: Support ticket ids for given orders and severity. +- `ticket_order_id(ticket_id: int) -> int`: Order id associated with a support ticket. +- `sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool`: Whether a support ticket breaches first-response or resolution SLA. +- `delayed_orders(order_ids: list[int]) -> list[int]`: Subset of order ids whose ship_days exceeded promised_days. +- `unique_customers(order_ids: list[int]) -> list[int]`: Unique customer ids among the given orders. +- `count_items(values: list) -> int`: Length of a list. +- `sum_values(values: list[int]) -> int`: Sum a list of integers. +- `count_true(values: list[bool]) -> int`: Count true values. +- `count_below(values: list[int], threshold: int) -> int`: Count values below a threshold. diff --git a/harbor/tasks/v3_depth2_order_count_t24/task.toml b/harbor/tasks/v3_depth2_order_count_t24/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..5da299ed3dfb50695d9f6c97d03f27a52e5f342f --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t24/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_order_count_t24" +description = "FlowBench v3 public task metadata. Public verifier is smoke-only." +authors = [{ name = "Mind Lab", email = "contact@mindlab.ltd" }] +keywords = ["flowbench", "tool-use", "data-orchestration", "operations"] + +[metadata] +benchmark = "FlowBench-v3" +split = "public-task-only" +category = "data-processing" +depth = 2 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +network_mode = "no-network" +build_timeout_sec = 600.0 +os = "linux" +cpus = 1 +memory_mb = 2048 +storage_mb = 2048 +gpus = 0 diff --git a/harbor/tasks/v3_depth2_order_count_t24/tests/check_output_shape.py b/harbor/tasks/v3_depth2_order_count_t24/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t24/tests/check_output_shape.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import json +import os +import re +from pathlib import Path + + +def write_reward(score: float, diagnostic: str) -> None: + log_dir = Path(os.environ.get("LOG_DIR", "/logs/verifier")) + log_dir.mkdir(parents=True, exist_ok=True) + (log_dir / "reward.txt").write_text(f"{score:.6g}\n") + (log_dir / "reward.json").write_text( + json.dumps({"reward": score, "smoke_only": True}, indent=2) + "\n" + ) + (log_dir / "diagnostic.txt").write_text(diagnostic + "\n") + + +def main() -> int: + app_dir = Path(os.environ.get("APP_DIR", "/app")) + task = json.loads((app_dir / "task.json").read_text()) + answer_path = app_dir / "answer.txt" + if not answer_path.exists(): + write_reward(0.0, "missing /app/answer.txt") + return 1 + + got = answer_path.read_text().strip() + if task["answer_format"] == "exact integer": + ok = bool(re.fullmatch(r"-?\d+", got)) + diagnostic = "valid integer smoke output" if ok else f"not an exact integer: {got!r}" + else: + ok = bool(re.fullmatch(r"[A-Za-z]+", got)) + diagnostic = "valid code smoke output" if ok else f"not an exact code: {got!r}" + + # This is intentionally not official scoring; it only verifies I/O shape. + write_reward(1.0 if ok else 0.0, diagnostic) + return 0 if ok else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/harbor/tasks/v3_depth2_order_count_t24/tests/test.sh b/harbor/tasks/v3_depth2_order_count_t24/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t24/tests/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -u +python /tests/check_output_shape.py diff --git a/harbor/tasks/v3_depth2_order_count_t3/environment/Dockerfile b/harbor/tasks/v3_depth2_order_count_t3/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t3/environment/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.12-slim +WORKDIR /app +COPY flowbench_tools.py /app/flowbench_tools.py +COPY task.json /app/task.json diff --git a/harbor/tasks/v3_depth2_order_count_t3/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_order_count_t3/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t3/environment/flowbench_tools.py @@ -0,0 +1,311 @@ +"""Deterministic FlowBench v3 tools. This file contains no task answers.""" + + +REGIONS = ["NA", "EU", "APAC", "LATAM"] +CATEGORIES = ["A", "B", "C", "D"] +CURRENCIES = {"NA": "USD", "EU": "EUR", "APAC": "JPY", "LATAM": "BRL"} +FX_TO_USD_BP = {"USD": 10000, "EUR": 10900, "JPY": 67, "BRL": 1850} +TIERS = ["std", "gold", "plat"] +DISCOUNT_PCT = {"std": 0, "gold": 10, "plat": 20} +CHANNELS = ["web", "store", "partner"] +MONTHS = [202601, 202602, 202603, 202604, 202605, 202606] + +N_CUSTOMERS = 72 +N_PRODUCTS = 48 +N_ORDERS = 720 +N_TICKETS = 260 +N_RETURNS = 180 + + +def _h(*xs): + import hashlib + s = "|".join(str(x) for x in xs).encode() + return int.from_bytes(hashlib.sha256(s).digest()[:8], "big") & 0x7FFFFFFF + + +def build_data(): + customers = [] + for cid in range(N_CUSTOMERS): + region = REGIONS[_h("region", cid) % len(REGIONS)] + customers.append({ + "customer_id": cid, + "region": region, + "tier": TIERS[_h("tier", cid) % len(TIERS)], + "segment": ["consumer", "smb", "enterprise"][_h("segment", cid) % 3], + }) + + products = [] + for pid in range(N_PRODUCTS): + cat = CATEGORIES[_h("cat", pid) % len(CATEGORIES)] + unit_price = 12 + _h("price", pid) % 240 + cogs = unit_price * (45 + _h("margin", pid) % 35) // 100 + products.append({ + "product_id": pid, + "category": cat, + "unit_price_usd": unit_price, + "unit_cogs_usd": cogs, + "lead_time_days": 3 + _h("lead", pid) % 18, + }) + + inventory = [] + for pid in range(N_PRODUCTS): + for region in REGIONS: + inventory.append({ + "product_id": pid, + "region": region, + "on_hand": 10 + _h("onhand", pid, region) % 140, + "reserved": _h("reserved", pid, region) % 28, + "inbound": _h("inbound", pid, region) % 85, + }) + + orders = [] + for oid in range(N_ORDERS): + customer_id = _h("ocust", oid) % N_CUSTOMERS + product_id = _h("oprod", oid) % N_PRODUCTS + month = MONTHS[_h("month", oid) % len(MONTHS)] + qty = 1 + _h("qty", oid) % 9 + ship_days = 1 + _h("shipdays", oid) % 16 + promised_days = 3 + _h("promise", oid) % 9 + status = ["paid", "paid", "paid", "paid", "cancelled", "refunded"][ + _h("status", oid) % 6] + orders.append({ + "order_id": oid, + "customer_id": customer_id, + "product_id": product_id, + "month": month, + "qty": qty, + "status": status, + "channel": CHANNELS[_h("channel", oid) % len(CHANNELS)], + "ship_days": ship_days, + "promised_days": promised_days, + }) + + returns = [] + for rid in range(N_RETURNS): + oid = _h("roid", rid) % N_ORDERS + order = orders[oid] + if order["status"] == "cancelled": + continue + returned_qty = 1 + _h("rqty", rid) % max(1, order["qty"]) + reason = ["defect", "late", "changed_mind", "wrong_item"][_h("reason", rid) % 4] + returns.append({ + "return_id": rid, + "order_id": oid, + "month": MONTHS[_h("rmonth", rid) % len(MONTHS)], + "returned_qty": returned_qty, + "reason": reason, + }) + + tickets = [] + for tid in range(N_TICKETS): + oid = _h("toid", tid) % N_ORDERS + severity = ["low", "medium", "high", "critical"][_h("sev", tid) % 4] + opened = MONTHS[_h("tmonth", tid) % len(MONTHS)] + first_response_hours = 1 + _h("resp", tid) % 96 + resolution_hours = first_response_hours + _h("res", tid) % 240 + tickets.append({ + "ticket_id": tid, + "order_id": oid, + "opened_month": opened, + "severity": severity, + "first_response_hours": first_response_hours, + "resolution_hours": resolution_hours, + }) + + return { + "customers": customers, + "products": products, + "inventory": inventory, + "orders": orders, + "returns": returns, + "tickets": tickets, + "fx_to_usd_bp": FX_TO_USD_BP, + } + + +DATA = build_data() +CUSTOMERS = {c["customer_id"]: c for c in DATA["customers"]} +PRODUCTS = {p["product_id"]: p for p in DATA["products"]} +ORDERS = {o["order_id"]: o for o in DATA["orders"]} + + +def region_currency(region: str) -> str: + return CURRENCIES[region] + + +def get_orders(region: str, category: str, month_start: int, month_end: int) -> list: + """Paid/refunded order ids in a region/category/month window.""" + out = [] + for o in DATA["orders"]: + if o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + p = PRODUCTS[o["product_id"]] + if c["region"] == region and p["category"] == category and month_start <= o["month"] <= month_end: + out.append(o["order_id"]) + return sorted(out) + + +def order_gross_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * p["unit_price_usd"] + + +def order_margin_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * (p["unit_price_usd"] - p["unit_cogs_usd"]) + + +def refund_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + qty = sum(r["returned_qty"] for r in DATA["returns"] if r["order_id"] == order_id) + qty = min(qty, o["qty"]) + return qty * p["unit_price_usd"] + + +def customer_tier(order_id: int) -> str: + o = ORDERS[order_id] + return CUSTOMERS[o["customer_id"]]["tier"] + + +def apply_discount(amount_usd: int, tier: str) -> int: + return amount_usd * (100 - DISCOUNT_PCT[tier]) // 100 + + +def net_revenue_usd(order_id: int) -> int: + gross = apply_discount(order_gross_usd(order_id), customer_tier(order_id)) + return max(0, gross - refund_usd(order_id)) + + +def to_local(amount_usd: int, currency: str) -> int: + return amount_usd * 10000 // FX_TO_USD_BP[currency] + + +def inventory_position(product_id: int, region: str) -> int: + row = next(x for x in DATA["inventory"] + if x["product_id"] == product_id and x["region"] == region) + return row["on_hand"] - row["reserved"] + row["inbound"] + + +def product_lead_time(product_id: int) -> int: + return PRODUCTS[product_id]["lead_time_days"] + + +def product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int: + totals = {} + for oid in get_orders(region, category, month_start, month_end): + o = ORDERS[oid] + totals[o["product_id"]] = totals.get(o["product_id"], 0) + o["qty"] + if not totals: + return -1 + return min((-qty, pid) for pid, qty in totals.items())[1] + + +def units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int: + total = 0 + for o in DATA["orders"]: + if o["product_id"] != product_id or o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + if c["region"] == region and month_start <= o["month"] <= month_end: + total += o["qty"] + return total + + +def tickets_for_orders(order_ids: list, severity: str) -> list: + s = set(order_ids) + return sorted(t["ticket_id"] for t in DATA["tickets"] + if t["order_id"] in s and t["severity"] == severity) + + +def ticket_order_id(ticket_id: int) -> int: + return next(t["order_id"] for t in DATA["tickets"] if t["ticket_id"] == ticket_id) + + +def sla_breached(ticket_id: int, first_response_limit_hours: int, + resolution_limit_hours: int) -> bool: + t = next(x for x in DATA["tickets"] if x["ticket_id"] == ticket_id) + return (t["first_response_hours"] > first_response_limit_hours or + t["resolution_hours"] > resolution_limit_hours) + + +def delayed_orders(order_ids: list) -> list: + s = set(order_ids) + return sorted(o["order_id"] for o in DATA["orders"] + if o["order_id"] in s and o["ship_days"] > o["promised_days"]) + + +def unique_customers(order_ids: list) -> list: + return sorted({ORDERS[oid]["customer_id"] for oid in order_ids}) + + +def count_items(values: list) -> int: + return len(values) + + +def sum_values(values: list) -> int: + return sum(values) + + +def count_true(values: list) -> int: + return sum(1 for v in values if bool(v)) + + +def count_below(values: list, threshold: int) -> int: + return sum(1 for v in values if v < threshold) + + +TOOLS = { + "region_currency": ("region_currency(region: str) -> str", + "ISO currency code for a region.", region_currency), + "get_orders": ("get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]", + "Paid/refunded order ids for a region, product category, and inclusive month window.", + get_orders), + "order_gross_usd": ("order_gross_usd(order_id: int) -> int", + "Gross order revenue in USD before discounts/refunds.", order_gross_usd), + "order_margin_usd": ("order_margin_usd(order_id: int) -> int", + "Gross order margin in USD before discounts/refunds.", order_margin_usd), + "refund_usd": ("refund_usd(order_id: int) -> int", + "Refund amount in USD for returned quantity on an order.", refund_usd), + "customer_tier": ("customer_tier(order_id: int) -> str", + "Customer loyalty tier for an order.", customer_tier), + "apply_discount": ("apply_discount(amount_usd: int, tier: str) -> int", + "Apply the order customer's loyalty discount to a USD amount.", apply_discount), + "net_revenue_usd": ("net_revenue_usd(order_id: int) -> int", + "Net USD revenue after loyalty discount and refunds.", net_revenue_usd), + "to_local": ("to_local(amount_usd: int, currency: str) -> int", + "Convert a USD integer amount to a local-currency integer.", to_local), + "inventory_position": ("inventory_position(product_id: int, region: str) -> int", + "Available inventory position: on_hand - reserved + inbound.", + inventory_position), + "product_lead_time": ("product_lead_time(product_id: int) -> int", + "Supplier lead time in days for a product.", product_lead_time), + "product_id_for_top_seller": ( + "product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int", + "Product id with the highest units sold in a region/category/month window.", + product_id_for_top_seller), + "units_sold": ("units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int", + "Units sold for one product in a region and month window.", units_sold), + "tickets_for_orders": ("tickets_for_orders(order_ids: list[int], severity: str) -> list[int]", + "Support ticket ids for given orders and severity.", tickets_for_orders), + "ticket_order_id": ("ticket_order_id(ticket_id: int) -> int", + "Order id associated with a support ticket.", ticket_order_id), + "sla_breached": ( + "sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool", + "Whether a support ticket breaches first-response or resolution SLA.", + sla_breached), + "delayed_orders": ("delayed_orders(order_ids: list[int]) -> list[int]", + "Subset of order ids whose ship_days exceeded promised_days.", delayed_orders), + "unique_customers": ("unique_customers(order_ids: list[int]) -> list[int]", + "Unique customer ids among the given orders.", unique_customers), + "count_items": ("count_items(values: list) -> int", "Length of a list.", count_items), + "sum_values": ("sum_values(values: list[int]) -> int", "Sum a list of integers.", sum_values), + "count_true": ("count_true(values: list[bool]) -> int", "Count true values.", count_true), + "count_below": ("count_below(values: list[int], threshold: int) -> int", + "Count values below a threshold.", count_below), +} + +__all__ = [name for name in TOOLS.keys()] + ['TOOLS'] diff --git a/harbor/tasks/v3_depth2_order_count_t3/environment/task.json b/harbor/tasks/v3_depth2_order_count_t3/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..2605af0e54e41d9f6c00dd98d3ab3775a6476eb8 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t3/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_order_count_t3", + "depth": 2, + "family": "order_count", + "params": { + "region": "EU", + "category": "D", + "month_start": 202603, + "month_end": 202606 + }, + "question": "How many paid/refunded orders are in region EU, category D, from month 202603 through 202606? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_order_count_t3/instruction.md b/harbor/tasks/v3_depth2_order_count_t3/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..41c997824a1987cb3fdef101459a7224e9eb87aa --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t3/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +How many paid/refunded orders are in region EU, category D, from month 202603 through 202606? Report the count. + +Available tools: +- `region_currency(region: str) -> str`: ISO currency code for a region. +- `get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]`: Paid/refunded order ids for a region, product category, and inclusive month window. +- `order_gross_usd(order_id: int) -> int`: Gross order revenue in USD before discounts/refunds. +- `order_margin_usd(order_id: int) -> int`: Gross order margin in USD before discounts/refunds. +- `refund_usd(order_id: int) -> int`: Refund amount in USD for returned quantity on an order. +- `customer_tier(order_id: int) -> str`: Customer loyalty tier for an order. +- `apply_discount(amount_usd: int, tier: str) -> int`: Apply the order customer's loyalty discount to a USD amount. +- `net_revenue_usd(order_id: int) -> int`: Net USD revenue after loyalty discount and refunds. +- `to_local(amount_usd: int, currency: str) -> int`: Convert a USD integer amount to a local-currency integer. +- `inventory_position(product_id: int, region: str) -> int`: Available inventory position: on_hand - reserved + inbound. +- `product_lead_time(product_id: int) -> int`: Supplier lead time in days for a product. +- `product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int`: Product id with the highest units sold in a region/category/month window. +- `units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int`: Units sold for one product in a region and month window. +- `tickets_for_orders(order_ids: list[int], severity: str) -> list[int]`: Support ticket ids for given orders and severity. +- `ticket_order_id(ticket_id: int) -> int`: Order id associated with a support ticket. +- `sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool`: Whether a support ticket breaches first-response or resolution SLA. +- `delayed_orders(order_ids: list[int]) -> list[int]`: Subset of order ids whose ship_days exceeded promised_days. +- `unique_customers(order_ids: list[int]) -> list[int]`: Unique customer ids among the given orders. +- `count_items(values: list) -> int`: Length of a list. +- `sum_values(values: list[int]) -> int`: Sum a list of integers. +- `count_true(values: list[bool]) -> int`: Count true values. +- `count_below(values: list[int], threshold: int) -> int`: Count values below a threshold. diff --git a/harbor/tasks/v3_depth2_order_count_t3/task.toml b/harbor/tasks/v3_depth2_order_count_t3/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..8e6eca4e4e17d9755cfa50f8711add61f1151270 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t3/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_order_count_t3" +description = "FlowBench v3 public task metadata. Public verifier is smoke-only." +authors = [{ name = "Mind Lab", email = "contact@mindlab.ltd" }] +keywords = ["flowbench", "tool-use", "data-orchestration", "operations"] + +[metadata] +benchmark = "FlowBench-v3" +split = "public-task-only" +category = "data-processing" +depth = 2 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +network_mode = "no-network" +build_timeout_sec = 600.0 +os = "linux" +cpus = 1 +memory_mb = 2048 +storage_mb = 2048 +gpus = 0 diff --git a/harbor/tasks/v3_depth2_order_count_t3/tests/check_output_shape.py b/harbor/tasks/v3_depth2_order_count_t3/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t3/tests/check_output_shape.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import json +import os +import re +from pathlib import Path + + +def write_reward(score: float, diagnostic: str) -> None: + log_dir = Path(os.environ.get("LOG_DIR", "/logs/verifier")) + log_dir.mkdir(parents=True, exist_ok=True) + (log_dir / "reward.txt").write_text(f"{score:.6g}\n") + (log_dir / "reward.json").write_text( + json.dumps({"reward": score, "smoke_only": True}, indent=2) + "\n" + ) + (log_dir / "diagnostic.txt").write_text(diagnostic + "\n") + + +def main() -> int: + app_dir = Path(os.environ.get("APP_DIR", "/app")) + task = json.loads((app_dir / "task.json").read_text()) + answer_path = app_dir / "answer.txt" + if not answer_path.exists(): + write_reward(0.0, "missing /app/answer.txt") + return 1 + + got = answer_path.read_text().strip() + if task["answer_format"] == "exact integer": + ok = bool(re.fullmatch(r"-?\d+", got)) + diagnostic = "valid integer smoke output" if ok else f"not an exact integer: {got!r}" + else: + ok = bool(re.fullmatch(r"[A-Za-z]+", got)) + diagnostic = "valid code smoke output" if ok else f"not an exact code: {got!r}" + + # This is intentionally not official scoring; it only verifies I/O shape. + write_reward(1.0 if ok else 0.0, diagnostic) + return 0 if ok else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/harbor/tasks/v3_depth2_order_count_t3/tests/test.sh b/harbor/tasks/v3_depth2_order_count_t3/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t3/tests/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -u +python /tests/check_output_shape.py diff --git a/harbor/tasks/v3_depth2_order_count_t4/environment/Dockerfile b/harbor/tasks/v3_depth2_order_count_t4/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t4/environment/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.12-slim +WORKDIR /app +COPY flowbench_tools.py /app/flowbench_tools.py +COPY task.json /app/task.json diff --git a/harbor/tasks/v3_depth2_order_count_t4/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_order_count_t4/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t4/environment/flowbench_tools.py @@ -0,0 +1,311 @@ +"""Deterministic FlowBench v3 tools. This file contains no task answers.""" + + +REGIONS = ["NA", "EU", "APAC", "LATAM"] +CATEGORIES = ["A", "B", "C", "D"] +CURRENCIES = {"NA": "USD", "EU": "EUR", "APAC": "JPY", "LATAM": "BRL"} +FX_TO_USD_BP = {"USD": 10000, "EUR": 10900, "JPY": 67, "BRL": 1850} +TIERS = ["std", "gold", "plat"] +DISCOUNT_PCT = {"std": 0, "gold": 10, "plat": 20} +CHANNELS = ["web", "store", "partner"] +MONTHS = [202601, 202602, 202603, 202604, 202605, 202606] + +N_CUSTOMERS = 72 +N_PRODUCTS = 48 +N_ORDERS = 720 +N_TICKETS = 260 +N_RETURNS = 180 + + +def _h(*xs): + import hashlib + s = "|".join(str(x) for x in xs).encode() + return int.from_bytes(hashlib.sha256(s).digest()[:8], "big") & 0x7FFFFFFF + + +def build_data(): + customers = [] + for cid in range(N_CUSTOMERS): + region = REGIONS[_h("region", cid) % len(REGIONS)] + customers.append({ + "customer_id": cid, + "region": region, + "tier": TIERS[_h("tier", cid) % len(TIERS)], + "segment": ["consumer", "smb", "enterprise"][_h("segment", cid) % 3], + }) + + products = [] + for pid in range(N_PRODUCTS): + cat = CATEGORIES[_h("cat", pid) % len(CATEGORIES)] + unit_price = 12 + _h("price", pid) % 240 + cogs = unit_price * (45 + _h("margin", pid) % 35) // 100 + products.append({ + "product_id": pid, + "category": cat, + "unit_price_usd": unit_price, + "unit_cogs_usd": cogs, + "lead_time_days": 3 + _h("lead", pid) % 18, + }) + + inventory = [] + for pid in range(N_PRODUCTS): + for region in REGIONS: + inventory.append({ + "product_id": pid, + "region": region, + "on_hand": 10 + _h("onhand", pid, region) % 140, + "reserved": _h("reserved", pid, region) % 28, + "inbound": _h("inbound", pid, region) % 85, + }) + + orders = [] + for oid in range(N_ORDERS): + customer_id = _h("ocust", oid) % N_CUSTOMERS + product_id = _h("oprod", oid) % N_PRODUCTS + month = MONTHS[_h("month", oid) % len(MONTHS)] + qty = 1 + _h("qty", oid) % 9 + ship_days = 1 + _h("shipdays", oid) % 16 + promised_days = 3 + _h("promise", oid) % 9 + status = ["paid", "paid", "paid", "paid", "cancelled", "refunded"][ + _h("status", oid) % 6] + orders.append({ + "order_id": oid, + "customer_id": customer_id, + "product_id": product_id, + "month": month, + "qty": qty, + "status": status, + "channel": CHANNELS[_h("channel", oid) % len(CHANNELS)], + "ship_days": ship_days, + "promised_days": promised_days, + }) + + returns = [] + for rid in range(N_RETURNS): + oid = _h("roid", rid) % N_ORDERS + order = orders[oid] + if order["status"] == "cancelled": + continue + returned_qty = 1 + _h("rqty", rid) % max(1, order["qty"]) + reason = ["defect", "late", "changed_mind", "wrong_item"][_h("reason", rid) % 4] + returns.append({ + "return_id": rid, + "order_id": oid, + "month": MONTHS[_h("rmonth", rid) % len(MONTHS)], + "returned_qty": returned_qty, + "reason": reason, + }) + + tickets = [] + for tid in range(N_TICKETS): + oid = _h("toid", tid) % N_ORDERS + severity = ["low", "medium", "high", "critical"][_h("sev", tid) % 4] + opened = MONTHS[_h("tmonth", tid) % len(MONTHS)] + first_response_hours = 1 + _h("resp", tid) % 96 + resolution_hours = first_response_hours + _h("res", tid) % 240 + tickets.append({ + "ticket_id": tid, + "order_id": oid, + "opened_month": opened, + "severity": severity, + "first_response_hours": first_response_hours, + "resolution_hours": resolution_hours, + }) + + return { + "customers": customers, + "products": products, + "inventory": inventory, + "orders": orders, + "returns": returns, + "tickets": tickets, + "fx_to_usd_bp": FX_TO_USD_BP, + } + + +DATA = build_data() +CUSTOMERS = {c["customer_id"]: c for c in DATA["customers"]} +PRODUCTS = {p["product_id"]: p for p in DATA["products"]} +ORDERS = {o["order_id"]: o for o in DATA["orders"]} + + +def region_currency(region: str) -> str: + return CURRENCIES[region] + + +def get_orders(region: str, category: str, month_start: int, month_end: int) -> list: + """Paid/refunded order ids in a region/category/month window.""" + out = [] + for o in DATA["orders"]: + if o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + p = PRODUCTS[o["product_id"]] + if c["region"] == region and p["category"] == category and month_start <= o["month"] <= month_end: + out.append(o["order_id"]) + return sorted(out) + + +def order_gross_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * p["unit_price_usd"] + + +def order_margin_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * (p["unit_price_usd"] - p["unit_cogs_usd"]) + + +def refund_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + qty = sum(r["returned_qty"] for r in DATA["returns"] if r["order_id"] == order_id) + qty = min(qty, o["qty"]) + return qty * p["unit_price_usd"] + + +def customer_tier(order_id: int) -> str: + o = ORDERS[order_id] + return CUSTOMERS[o["customer_id"]]["tier"] + + +def apply_discount(amount_usd: int, tier: str) -> int: + return amount_usd * (100 - DISCOUNT_PCT[tier]) // 100 + + +def net_revenue_usd(order_id: int) -> int: + gross = apply_discount(order_gross_usd(order_id), customer_tier(order_id)) + return max(0, gross - refund_usd(order_id)) + + +def to_local(amount_usd: int, currency: str) -> int: + return amount_usd * 10000 // FX_TO_USD_BP[currency] + + +def inventory_position(product_id: int, region: str) -> int: + row = next(x for x in DATA["inventory"] + if x["product_id"] == product_id and x["region"] == region) + return row["on_hand"] - row["reserved"] + row["inbound"] + + +def product_lead_time(product_id: int) -> int: + return PRODUCTS[product_id]["lead_time_days"] + + +def product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int: + totals = {} + for oid in get_orders(region, category, month_start, month_end): + o = ORDERS[oid] + totals[o["product_id"]] = totals.get(o["product_id"], 0) + o["qty"] + if not totals: + return -1 + return min((-qty, pid) for pid, qty in totals.items())[1] + + +def units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int: + total = 0 + for o in DATA["orders"]: + if o["product_id"] != product_id or o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + if c["region"] == region and month_start <= o["month"] <= month_end: + total += o["qty"] + return total + + +def tickets_for_orders(order_ids: list, severity: str) -> list: + s = set(order_ids) + return sorted(t["ticket_id"] for t in DATA["tickets"] + if t["order_id"] in s and t["severity"] == severity) + + +def ticket_order_id(ticket_id: int) -> int: + return next(t["order_id"] for t in DATA["tickets"] if t["ticket_id"] == ticket_id) + + +def sla_breached(ticket_id: int, first_response_limit_hours: int, + resolution_limit_hours: int) -> bool: + t = next(x for x in DATA["tickets"] if x["ticket_id"] == ticket_id) + return (t["first_response_hours"] > first_response_limit_hours or + t["resolution_hours"] > resolution_limit_hours) + + +def delayed_orders(order_ids: list) -> list: + s = set(order_ids) + return sorted(o["order_id"] for o in DATA["orders"] + if o["order_id"] in s and o["ship_days"] > o["promised_days"]) + + +def unique_customers(order_ids: list) -> list: + return sorted({ORDERS[oid]["customer_id"] for oid in order_ids}) + + +def count_items(values: list) -> int: + return len(values) + + +def sum_values(values: list) -> int: + return sum(values) + + +def count_true(values: list) -> int: + return sum(1 for v in values if bool(v)) + + +def count_below(values: list, threshold: int) -> int: + return sum(1 for v in values if v < threshold) + + +TOOLS = { + "region_currency": ("region_currency(region: str) -> str", + "ISO currency code for a region.", region_currency), + "get_orders": ("get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]", + "Paid/refunded order ids for a region, product category, and inclusive month window.", + get_orders), + "order_gross_usd": ("order_gross_usd(order_id: int) -> int", + "Gross order revenue in USD before discounts/refunds.", order_gross_usd), + "order_margin_usd": ("order_margin_usd(order_id: int) -> int", + "Gross order margin in USD before discounts/refunds.", order_margin_usd), + "refund_usd": ("refund_usd(order_id: int) -> int", + "Refund amount in USD for returned quantity on an order.", refund_usd), + "customer_tier": ("customer_tier(order_id: int) -> str", + "Customer loyalty tier for an order.", customer_tier), + "apply_discount": ("apply_discount(amount_usd: int, tier: str) -> int", + "Apply the order customer's loyalty discount to a USD amount.", apply_discount), + "net_revenue_usd": ("net_revenue_usd(order_id: int) -> int", + "Net USD revenue after loyalty discount and refunds.", net_revenue_usd), + "to_local": ("to_local(amount_usd: int, currency: str) -> int", + "Convert a USD integer amount to a local-currency integer.", to_local), + "inventory_position": ("inventory_position(product_id: int, region: str) -> int", + "Available inventory position: on_hand - reserved + inbound.", + inventory_position), + "product_lead_time": ("product_lead_time(product_id: int) -> int", + "Supplier lead time in days for a product.", product_lead_time), + "product_id_for_top_seller": ( + "product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int", + "Product id with the highest units sold in a region/category/month window.", + product_id_for_top_seller), + "units_sold": ("units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int", + "Units sold for one product in a region and month window.", units_sold), + "tickets_for_orders": ("tickets_for_orders(order_ids: list[int], severity: str) -> list[int]", + "Support ticket ids for given orders and severity.", tickets_for_orders), + "ticket_order_id": ("ticket_order_id(ticket_id: int) -> int", + "Order id associated with a support ticket.", ticket_order_id), + "sla_breached": ( + "sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool", + "Whether a support ticket breaches first-response or resolution SLA.", + sla_breached), + "delayed_orders": ("delayed_orders(order_ids: list[int]) -> list[int]", + "Subset of order ids whose ship_days exceeded promised_days.", delayed_orders), + "unique_customers": ("unique_customers(order_ids: list[int]) -> list[int]", + "Unique customer ids among the given orders.", unique_customers), + "count_items": ("count_items(values: list) -> int", "Length of a list.", count_items), + "sum_values": ("sum_values(values: list[int]) -> int", "Sum a list of integers.", sum_values), + "count_true": ("count_true(values: list[bool]) -> int", "Count true values.", count_true), + "count_below": ("count_below(values: list[int], threshold: int) -> int", + "Count values below a threshold.", count_below), +} + +__all__ = [name for name in TOOLS.keys()] + ['TOOLS'] diff --git a/harbor/tasks/v3_depth2_order_count_t4/environment/task.json b/harbor/tasks/v3_depth2_order_count_t4/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..fd6609388ac0ca2206eb0f98cb74b9838e6e9163 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t4/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_order_count_t4", + "depth": 2, + "family": "order_count", + "params": { + "region": "APAC", + "category": "A", + "month_start": 202602, + "month_end": 202605 + }, + "question": "How many paid/refunded orders are in region APAC, category A, from month 202602 through 202605? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_order_count_t4/instruction.md b/harbor/tasks/v3_depth2_order_count_t4/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..f737e1d7a0c99b5859ada8190a1eb8772d7d6506 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t4/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +How many paid/refunded orders are in region APAC, category A, from month 202602 through 202605? Report the count. + +Available tools: +- `region_currency(region: str) -> str`: ISO currency code for a region. +- `get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]`: Paid/refunded order ids for a region, product category, and inclusive month window. +- `order_gross_usd(order_id: int) -> int`: Gross order revenue in USD before discounts/refunds. +- `order_margin_usd(order_id: int) -> int`: Gross order margin in USD before discounts/refunds. +- `refund_usd(order_id: int) -> int`: Refund amount in USD for returned quantity on an order. +- `customer_tier(order_id: int) -> str`: Customer loyalty tier for an order. +- `apply_discount(amount_usd: int, tier: str) -> int`: Apply the order customer's loyalty discount to a USD amount. +- `net_revenue_usd(order_id: int) -> int`: Net USD revenue after loyalty discount and refunds. +- `to_local(amount_usd: int, currency: str) -> int`: Convert a USD integer amount to a local-currency integer. +- `inventory_position(product_id: int, region: str) -> int`: Available inventory position: on_hand - reserved + inbound. +- `product_lead_time(product_id: int) -> int`: Supplier lead time in days for a product. +- `product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int`: Product id with the highest units sold in a region/category/month window. +- `units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int`: Units sold for one product in a region and month window. +- `tickets_for_orders(order_ids: list[int], severity: str) -> list[int]`: Support ticket ids for given orders and severity. +- `ticket_order_id(ticket_id: int) -> int`: Order id associated with a support ticket. +- `sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool`: Whether a support ticket breaches first-response or resolution SLA. +- `delayed_orders(order_ids: list[int]) -> list[int]`: Subset of order ids whose ship_days exceeded promised_days. +- `unique_customers(order_ids: list[int]) -> list[int]`: Unique customer ids among the given orders. +- `count_items(values: list) -> int`: Length of a list. +- `sum_values(values: list[int]) -> int`: Sum a list of integers. +- `count_true(values: list[bool]) -> int`: Count true values. +- `count_below(values: list[int], threshold: int) -> int`: Count values below a threshold. diff --git a/harbor/tasks/v3_depth2_order_count_t4/task.toml b/harbor/tasks/v3_depth2_order_count_t4/task.toml new file mode 100644 index 0000000000000000000000000000000000000000..5ceb854e5e8b773c708eada2311fe5c5178dd02b --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t4/task.toml @@ -0,0 +1,28 @@ +schema_version = "1.3" + +[task] +name = "mindlab/v3_depth2_order_count_t4" +description = "FlowBench v3 public task metadata. Public verifier is smoke-only." +authors = [{ name = "Mind Lab", email = "contact@mindlab.ltd" }] +keywords = ["flowbench", "tool-use", "data-orchestration", "operations"] + +[metadata] +benchmark = "FlowBench-v3" +split = "public-task-only" +category = "data-processing" +depth = 2 + +[verifier] +timeout_sec = 120.0 + +[agent] +timeout_sec = 900.0 + +[environment] +network_mode = "no-network" +build_timeout_sec = 600.0 +os = "linux" +cpus = 1 +memory_mb = 2048 +storage_mb = 2048 +gpus = 0 diff --git a/harbor/tasks/v3_depth2_order_count_t4/tests/check_output_shape.py b/harbor/tasks/v3_depth2_order_count_t4/tests/check_output_shape.py new file mode 100644 index 0000000000000000000000000000000000000000..19511d8e36ceaadad8043c93afbca73e685e53b6 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t4/tests/check_output_shape.py @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +from __future__ import annotations + +import json +import os +import re +from pathlib import Path + + +def write_reward(score: float, diagnostic: str) -> None: + log_dir = Path(os.environ.get("LOG_DIR", "/logs/verifier")) + log_dir.mkdir(parents=True, exist_ok=True) + (log_dir / "reward.txt").write_text(f"{score:.6g}\n") + (log_dir / "reward.json").write_text( + json.dumps({"reward": score, "smoke_only": True}, indent=2) + "\n" + ) + (log_dir / "diagnostic.txt").write_text(diagnostic + "\n") + + +def main() -> int: + app_dir = Path(os.environ.get("APP_DIR", "/app")) + task = json.loads((app_dir / "task.json").read_text()) + answer_path = app_dir / "answer.txt" + if not answer_path.exists(): + write_reward(0.0, "missing /app/answer.txt") + return 1 + + got = answer_path.read_text().strip() + if task["answer_format"] == "exact integer": + ok = bool(re.fullmatch(r"-?\d+", got)) + diagnostic = "valid integer smoke output" if ok else f"not an exact integer: {got!r}" + else: + ok = bool(re.fullmatch(r"[A-Za-z]+", got)) + diagnostic = "valid code smoke output" if ok else f"not an exact code: {got!r}" + + # This is intentionally not official scoring; it only verifies I/O shape. + write_reward(1.0 if ok else 0.0, diagnostic) + return 0 if ok else 1 + + +if __name__ == "__main__": + raise SystemExit(main()) diff --git a/harbor/tasks/v3_depth2_order_count_t4/tests/test.sh b/harbor/tasks/v3_depth2_order_count_t4/tests/test.sh new file mode 100644 index 0000000000000000000000000000000000000000..8943b5d6a288c8fd56844aec54a60479395af94b --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t4/tests/test.sh @@ -0,0 +1,3 @@ +#!/usr/bin/env bash +set -u +python /tests/check_output_shape.py diff --git a/harbor/tasks/v3_depth2_order_count_t5/environment/Dockerfile b/harbor/tasks/v3_depth2_order_count_t5/environment/Dockerfile new file mode 100644 index 0000000000000000000000000000000000000000..97377a0aa30bcf17ddd3345fff9e77e27b28ddb3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t5/environment/Dockerfile @@ -0,0 +1,4 @@ +FROM python:3.12-slim +WORKDIR /app +COPY flowbench_tools.py /app/flowbench_tools.py +COPY task.json /app/task.json diff --git a/harbor/tasks/v3_depth2_order_count_t5/environment/flowbench_tools.py b/harbor/tasks/v3_depth2_order_count_t5/environment/flowbench_tools.py new file mode 100644 index 0000000000000000000000000000000000000000..96661210d32ed1d8089959097124c723844255a3 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t5/environment/flowbench_tools.py @@ -0,0 +1,311 @@ +"""Deterministic FlowBench v3 tools. This file contains no task answers.""" + + +REGIONS = ["NA", "EU", "APAC", "LATAM"] +CATEGORIES = ["A", "B", "C", "D"] +CURRENCIES = {"NA": "USD", "EU": "EUR", "APAC": "JPY", "LATAM": "BRL"} +FX_TO_USD_BP = {"USD": 10000, "EUR": 10900, "JPY": 67, "BRL": 1850} +TIERS = ["std", "gold", "plat"] +DISCOUNT_PCT = {"std": 0, "gold": 10, "plat": 20} +CHANNELS = ["web", "store", "partner"] +MONTHS = [202601, 202602, 202603, 202604, 202605, 202606] + +N_CUSTOMERS = 72 +N_PRODUCTS = 48 +N_ORDERS = 720 +N_TICKETS = 260 +N_RETURNS = 180 + + +def _h(*xs): + import hashlib + s = "|".join(str(x) for x in xs).encode() + return int.from_bytes(hashlib.sha256(s).digest()[:8], "big") & 0x7FFFFFFF + + +def build_data(): + customers = [] + for cid in range(N_CUSTOMERS): + region = REGIONS[_h("region", cid) % len(REGIONS)] + customers.append({ + "customer_id": cid, + "region": region, + "tier": TIERS[_h("tier", cid) % len(TIERS)], + "segment": ["consumer", "smb", "enterprise"][_h("segment", cid) % 3], + }) + + products = [] + for pid in range(N_PRODUCTS): + cat = CATEGORIES[_h("cat", pid) % len(CATEGORIES)] + unit_price = 12 + _h("price", pid) % 240 + cogs = unit_price * (45 + _h("margin", pid) % 35) // 100 + products.append({ + "product_id": pid, + "category": cat, + "unit_price_usd": unit_price, + "unit_cogs_usd": cogs, + "lead_time_days": 3 + _h("lead", pid) % 18, + }) + + inventory = [] + for pid in range(N_PRODUCTS): + for region in REGIONS: + inventory.append({ + "product_id": pid, + "region": region, + "on_hand": 10 + _h("onhand", pid, region) % 140, + "reserved": _h("reserved", pid, region) % 28, + "inbound": _h("inbound", pid, region) % 85, + }) + + orders = [] + for oid in range(N_ORDERS): + customer_id = _h("ocust", oid) % N_CUSTOMERS + product_id = _h("oprod", oid) % N_PRODUCTS + month = MONTHS[_h("month", oid) % len(MONTHS)] + qty = 1 + _h("qty", oid) % 9 + ship_days = 1 + _h("shipdays", oid) % 16 + promised_days = 3 + _h("promise", oid) % 9 + status = ["paid", "paid", "paid", "paid", "cancelled", "refunded"][ + _h("status", oid) % 6] + orders.append({ + "order_id": oid, + "customer_id": customer_id, + "product_id": product_id, + "month": month, + "qty": qty, + "status": status, + "channel": CHANNELS[_h("channel", oid) % len(CHANNELS)], + "ship_days": ship_days, + "promised_days": promised_days, + }) + + returns = [] + for rid in range(N_RETURNS): + oid = _h("roid", rid) % N_ORDERS + order = orders[oid] + if order["status"] == "cancelled": + continue + returned_qty = 1 + _h("rqty", rid) % max(1, order["qty"]) + reason = ["defect", "late", "changed_mind", "wrong_item"][_h("reason", rid) % 4] + returns.append({ + "return_id": rid, + "order_id": oid, + "month": MONTHS[_h("rmonth", rid) % len(MONTHS)], + "returned_qty": returned_qty, + "reason": reason, + }) + + tickets = [] + for tid in range(N_TICKETS): + oid = _h("toid", tid) % N_ORDERS + severity = ["low", "medium", "high", "critical"][_h("sev", tid) % 4] + opened = MONTHS[_h("tmonth", tid) % len(MONTHS)] + first_response_hours = 1 + _h("resp", tid) % 96 + resolution_hours = first_response_hours + _h("res", tid) % 240 + tickets.append({ + "ticket_id": tid, + "order_id": oid, + "opened_month": opened, + "severity": severity, + "first_response_hours": first_response_hours, + "resolution_hours": resolution_hours, + }) + + return { + "customers": customers, + "products": products, + "inventory": inventory, + "orders": orders, + "returns": returns, + "tickets": tickets, + "fx_to_usd_bp": FX_TO_USD_BP, + } + + +DATA = build_data() +CUSTOMERS = {c["customer_id"]: c for c in DATA["customers"]} +PRODUCTS = {p["product_id"]: p for p in DATA["products"]} +ORDERS = {o["order_id"]: o for o in DATA["orders"]} + + +def region_currency(region: str) -> str: + return CURRENCIES[region] + + +def get_orders(region: str, category: str, month_start: int, month_end: int) -> list: + """Paid/refunded order ids in a region/category/month window.""" + out = [] + for o in DATA["orders"]: + if o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + p = PRODUCTS[o["product_id"]] + if c["region"] == region and p["category"] == category and month_start <= o["month"] <= month_end: + out.append(o["order_id"]) + return sorted(out) + + +def order_gross_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * p["unit_price_usd"] + + +def order_margin_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + return o["qty"] * (p["unit_price_usd"] - p["unit_cogs_usd"]) + + +def refund_usd(order_id: int) -> int: + o = ORDERS[order_id] + p = PRODUCTS[o["product_id"]] + qty = sum(r["returned_qty"] for r in DATA["returns"] if r["order_id"] == order_id) + qty = min(qty, o["qty"]) + return qty * p["unit_price_usd"] + + +def customer_tier(order_id: int) -> str: + o = ORDERS[order_id] + return CUSTOMERS[o["customer_id"]]["tier"] + + +def apply_discount(amount_usd: int, tier: str) -> int: + return amount_usd * (100 - DISCOUNT_PCT[tier]) // 100 + + +def net_revenue_usd(order_id: int) -> int: + gross = apply_discount(order_gross_usd(order_id), customer_tier(order_id)) + return max(0, gross - refund_usd(order_id)) + + +def to_local(amount_usd: int, currency: str) -> int: + return amount_usd * 10000 // FX_TO_USD_BP[currency] + + +def inventory_position(product_id: int, region: str) -> int: + row = next(x for x in DATA["inventory"] + if x["product_id"] == product_id and x["region"] == region) + return row["on_hand"] - row["reserved"] + row["inbound"] + + +def product_lead_time(product_id: int) -> int: + return PRODUCTS[product_id]["lead_time_days"] + + +def product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int: + totals = {} + for oid in get_orders(region, category, month_start, month_end): + o = ORDERS[oid] + totals[o["product_id"]] = totals.get(o["product_id"], 0) + o["qty"] + if not totals: + return -1 + return min((-qty, pid) for pid, qty in totals.items())[1] + + +def units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int: + total = 0 + for o in DATA["orders"]: + if o["product_id"] != product_id or o["status"] not in ("paid", "refunded"): + continue + c = CUSTOMERS[o["customer_id"]] + if c["region"] == region and month_start <= o["month"] <= month_end: + total += o["qty"] + return total + + +def tickets_for_orders(order_ids: list, severity: str) -> list: + s = set(order_ids) + return sorted(t["ticket_id"] for t in DATA["tickets"] + if t["order_id"] in s and t["severity"] == severity) + + +def ticket_order_id(ticket_id: int) -> int: + return next(t["order_id"] for t in DATA["tickets"] if t["ticket_id"] == ticket_id) + + +def sla_breached(ticket_id: int, first_response_limit_hours: int, + resolution_limit_hours: int) -> bool: + t = next(x for x in DATA["tickets"] if x["ticket_id"] == ticket_id) + return (t["first_response_hours"] > first_response_limit_hours or + t["resolution_hours"] > resolution_limit_hours) + + +def delayed_orders(order_ids: list) -> list: + s = set(order_ids) + return sorted(o["order_id"] for o in DATA["orders"] + if o["order_id"] in s and o["ship_days"] > o["promised_days"]) + + +def unique_customers(order_ids: list) -> list: + return sorted({ORDERS[oid]["customer_id"] for oid in order_ids}) + + +def count_items(values: list) -> int: + return len(values) + + +def sum_values(values: list) -> int: + return sum(values) + + +def count_true(values: list) -> int: + return sum(1 for v in values if bool(v)) + + +def count_below(values: list, threshold: int) -> int: + return sum(1 for v in values if v < threshold) + + +TOOLS = { + "region_currency": ("region_currency(region: str) -> str", + "ISO currency code for a region.", region_currency), + "get_orders": ("get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]", + "Paid/refunded order ids for a region, product category, and inclusive month window.", + get_orders), + "order_gross_usd": ("order_gross_usd(order_id: int) -> int", + "Gross order revenue in USD before discounts/refunds.", order_gross_usd), + "order_margin_usd": ("order_margin_usd(order_id: int) -> int", + "Gross order margin in USD before discounts/refunds.", order_margin_usd), + "refund_usd": ("refund_usd(order_id: int) -> int", + "Refund amount in USD for returned quantity on an order.", refund_usd), + "customer_tier": ("customer_tier(order_id: int) -> str", + "Customer loyalty tier for an order.", customer_tier), + "apply_discount": ("apply_discount(amount_usd: int, tier: str) -> int", + "Apply the order customer's loyalty discount to a USD amount.", apply_discount), + "net_revenue_usd": ("net_revenue_usd(order_id: int) -> int", + "Net USD revenue after loyalty discount and refunds.", net_revenue_usd), + "to_local": ("to_local(amount_usd: int, currency: str) -> int", + "Convert a USD integer amount to a local-currency integer.", to_local), + "inventory_position": ("inventory_position(product_id: int, region: str) -> int", + "Available inventory position: on_hand - reserved + inbound.", + inventory_position), + "product_lead_time": ("product_lead_time(product_id: int) -> int", + "Supplier lead time in days for a product.", product_lead_time), + "product_id_for_top_seller": ( + "product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int", + "Product id with the highest units sold in a region/category/month window.", + product_id_for_top_seller), + "units_sold": ("units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int", + "Units sold for one product in a region and month window.", units_sold), + "tickets_for_orders": ("tickets_for_orders(order_ids: list[int], severity: str) -> list[int]", + "Support ticket ids for given orders and severity.", tickets_for_orders), + "ticket_order_id": ("ticket_order_id(ticket_id: int) -> int", + "Order id associated with a support ticket.", ticket_order_id), + "sla_breached": ( + "sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool", + "Whether a support ticket breaches first-response or resolution SLA.", + sla_breached), + "delayed_orders": ("delayed_orders(order_ids: list[int]) -> list[int]", + "Subset of order ids whose ship_days exceeded promised_days.", delayed_orders), + "unique_customers": ("unique_customers(order_ids: list[int]) -> list[int]", + "Unique customer ids among the given orders.", unique_customers), + "count_items": ("count_items(values: list) -> int", "Length of a list.", count_items), + "sum_values": ("sum_values(values: list[int]) -> int", "Sum a list of integers.", sum_values), + "count_true": ("count_true(values: list[bool]) -> int", "Count true values.", count_true), + "count_below": ("count_below(values: list[int], threshold: int) -> int", + "Count values below a threshold.", count_below), +} + +__all__ = [name for name in TOOLS.keys()] + ['TOOLS'] diff --git a/harbor/tasks/v3_depth2_order_count_t5/environment/task.json b/harbor/tasks/v3_depth2_order_count_t5/environment/task.json new file mode 100644 index 0000000000000000000000000000000000000000..5b06115893332f89b0255c96da78599f0c455730 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t5/environment/task.json @@ -0,0 +1,13 @@ +{ + "task_id": "v3_depth2_order_count_t5", + "depth": 2, + "family": "order_count", + "params": { + "region": "APAC", + "category": "D", + "month_start": 202601, + "month_end": 202606 + }, + "question": "How many paid/refunded orders are in region APAC, category D, from month 202601 through 202606? Report the count.", + "answer_format": "exact integer" +} diff --git a/harbor/tasks/v3_depth2_order_count_t5/instruction.md b/harbor/tasks/v3_depth2_order_count_t5/instruction.md new file mode 100644 index 0000000000000000000000000000000000000000..9b3f5b6d0351ea4e84d3f024d080d61a12992e57 --- /dev/null +++ b/harbor/tasks/v3_depth2_order_count_t5/instruction.md @@ -0,0 +1,38 @@ +# FlowBench v3 Public Task + +You are in `/app`. The file `/app/flowbench_tools.py` contains deterministic +Python tools over a synthetic business-operations dataset. Use those tools +to compute the requested value, then write the final output to +`/app/answer.txt`. + +Required output: +- `/app/answer.txt` must contain only the exact integer. +- Use integer arithmetic for currency and counts. Do not use floating point + arithmetic. + +Task: +How many paid/refunded orders are in region APAC, category D, from month 202601 through 202606? Report the count. + +Available tools: +- `region_currency(region: str) -> str`: ISO currency code for a region. +- `get_orders(region: str, category: str, month_start: int, month_end: int) -> list[int]`: Paid/refunded order ids for a region, product category, and inclusive month window. +- `order_gross_usd(order_id: int) -> int`: Gross order revenue in USD before discounts/refunds. +- `order_margin_usd(order_id: int) -> int`: Gross order margin in USD before discounts/refunds. +- `refund_usd(order_id: int) -> int`: Refund amount in USD for returned quantity on an order. +- `customer_tier(order_id: int) -> str`: Customer loyalty tier for an order. +- `apply_discount(amount_usd: int, tier: str) -> int`: Apply the order customer's loyalty discount to a USD amount. +- `net_revenue_usd(order_id: int) -> int`: Net USD revenue after loyalty discount and refunds. +- `to_local(amount_usd: int, currency: str) -> int`: Convert a USD integer amount to a local-currency integer. +- `inventory_position(product_id: int, region: str) -> int`: Available inventory position: on_hand - reserved + inbound. +- `product_lead_time(product_id: int) -> int`: Supplier lead time in days for a product. +- `product_id_for_top_seller(region: str, category: str, month_start: int, month_end: int) -> int`: Product id with the highest units sold in a region/category/month window. +- `units_sold(product_id: int, region: str, month_start: int, month_end: int) -> int`: Units sold for one product in a region and month window. +- `tickets_for_orders(order_ids: list[int], severity: str) -> list[int]`: Support ticket ids for given orders and severity. +- `ticket_order_id(ticket_id: int) -> int`: Order id associated with a support ticket. +- `sla_breached(ticket_id: int, first_response_limit_hours: int, resolution_limit_hours: int) -> bool`: Whether a support ticket breaches first-response or resolution SLA. +- `delayed_orders(order_ids: list[int]) -> list[int]`: Subset of order ids whose ship_days exceeded promised_days. +- `unique_customers(order_ids: list[int]) -> list[int]`: Unique customer ids among the given orders. +- `count_items(values: list) -> int`: Length of a list. +- `sum_values(values: list[int]) -> int`: Sum a list of integers. +- `count_true(values: list[bool]) -> int`: Count true values. +- `count_below(values: list[int], threshold: int) -> int`: Count values below a threshold.