---
document_id: agent.dataset.douyin.task.aggregate_drilldown
schema_version: 1
---

<!-- Generated by scripts.build_agent_guide; do not edit. -->

# Aggregate and product drilldown / 汇总与商品下钻

Query a category scope, then rank products under the same filters.

先查询品类汇总，再在相同筛选条件下对商品排名。

## Required inputs / 必要输入

- `scope` — `search_values`; required (`category_l3`): Exact category value
  精确品类值
- `time` — `user_required`; required: Analysis time range
  分析时间范围
- `ranking_metric` — `user_required`; optional; default `gmv`; allowed: `gmv, units`: Product ranking metric
  商品排名指标
- `top_n` — `user_required`; optional; default `20`: Number of products
  商品数量

## Steps / 步骤

1. `resolve_scope` · `search_values` — Resolve the category value.
   对齐品类值。
   - search `category_l3` with `${scope}`
2. `query_scope` · `query_metrics` — Query aggregate sales and units.
   查询汇总销售额和销量。
   - bundle: `aggregate_and_products` (one `query_metrics` call)
   - metrics: `gmv`, `units`
   - filters: `category_l3 eq ${scope}`
   - time: `${time}`
3. `query_products` · `query_metrics` — Query products under the same scope.
   使用相同范围查询商品。
   - bundle: `aggregate_and_products` (one `query_metrics` call)
   - metrics: `gmv`, `units`
   - group_by: `product_id`, `title`, `product_url`
   - result entity: `product`
   - filters: `category_l3 eq ${scope}`
   - time: `${time}`
   - order_by: `${ranking_metric}` desc
   - limit: `${top_n}`

## Agent computation / Agent 计算

- `rank_products` · `rank` from `query_products` — Rank products by the selected metric.
  按选定指标对商品排名。

## Output requirements / 输出要求

- Show the aggregate before the product ranking.
  先展示汇总结果，再展示商品排名。

## Limitations / 限制

- Keep aggregate and drilldown filters identical.
  汇总与下钻必须使用相同筛选条件。

## Stop conditions / 停止条件

- Stop if the scope cannot be resolved exactly.
  无法精确对齐范围时停止。
