write-context-rules
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
Chinesewrite-context-rules
write-context-rules
RULES.md- Orchestrator — point the agent to the right context fast (which metric → which table, which topic → which file, which question type → which skill).
- Broad rules — how to query and how to answer.
Anything else (per-table schema, full metric semantics, domain-specific rules) belongs in a referenced file: , , or a domain . Reference: docs.getnao.io/nao-agent/context-builder/rules-context.
databases/<table>.mdsemantics/<metric>.yaml.mdRULES.md- 编排器——快速引导agent找到正确的上下文(哪个指标对应哪个表,哪个主题对应哪个文件,哪种问题类型对应哪个skill)。
- 通用规则——查询方式与回答规范。
其他所有内容(每张表的 schema、完整的指标语义、领域特定规则)都应放在引用文件中:、或领域相关的文件。参考文档:docs.getnao.io/nao-agent/context-builder/rules-context。
databases/<table>.mdsemantics/<metric>.yaml.mdStandard sections (see templates/RULES.md
)
templates/RULES.md标准章节(详见templates/RULES.md
)
templates/RULES.md- — Product + Business model.
## Business overview - — Warehouse, data stack, layers, sources.
## Data architecture - —
## Core data models(one-line pointers) +### Most Used Tables(Purpose / Granularity / Key Columns ≤10 / Use For).### Tables detail - — grouped by category;
## Key Metrics Reference.**metric** → table, column, formula - — three example formulas (last X weeks / last X days / current month). Don't enumerate every period.
## Date filtering - — 5 subsections: Understand → Select Table → Write Query → Validate → Context.
## Analysis Process
- — 产品+商业模式。
## Business overview - — 数据仓库、数据栈、数据层、数据源。
## Data architecture - —
## Core data models(单行指向说明) +### Most Used Tables(用途/粒度/关键列≤10个/适用场景)。### Tables detail - — 按类别分组;格式为
## Key Metrics Reference。**metric** → table, column, formula - — 三个示例公式(最近X周/最近X天/当月)。无需枚举所有时间周期。
## Date filtering - — 5个子章节:理解→选择表→编写查询→验证→上下文。
## Analysis Process
Flow
流程
Generate section by section. Write each section to , show the user, then move on. Don't read everything and write everything in one batch — the user needs to see progress and catch wrong inferences early.
RULES.mdIf already has content, run the audit-and-fill flow at the bottom instead.
RULES.md逐章节生成。将每个章节写入,展示给用户后再进行下一章节。不要一次性读取所有内容并完成全部编写——用户需要看到进度,尽早发现错误推断。
RULES.md如果已有内容,请改用底部的审计填充流程。
RULES.mdStep 1 — ## Business overview
## Business overview步骤1 — ## Business overview
## Business overviewSources: web search for the company name/domain (from ), then and . Output two paragraphs: Product (what the company does) + Business model (revenue + customer journey).
nao_config.yamldatabases/repos/<dbt>/数据源:从获取公司名称/域名后进行网页搜索,再结合和中的内容。输出两段内容:产品(公司业务内容)+商业模式(收入+客户旅程)。
nao_config.yamldatabases/repos/<dbt>/Step 2 — ## Data architecture
## Data architecture步骤2 — ## Data architecture
## Data architectureFrom and : Warehouse type/project/dataset, Data stack (e.g. ), Data layers (e.g. ), Data sources (numbered list with prefix + one-line description).
databases/repos/<dbt>/dlt, dbt, no semantic layerbronze / silver / gold从和中提取:数据仓库类型/项目/数据集、数据栈(例如)、数据层(例如)、数据源(带前缀的编号列表+单行描述)。
databases/repos/<dbt>/dlt, dbt, no semantic layerbronze / silver / goldStep 3 — ## Core data models
## Core data models步骤3 — ## Core data models
## Core data models### Most Used Tables- `dim_users` — user dimension. See `databases/.../table=dim_users/`.### Tables detaildatabases/### Most Used Tables- `dim_users` — 用户维度表。详见`databases/.../table=dim_users/`。### Tables detaildatabases/Step 4 — ## Key Metrics Reference
## Key Metrics Reference步骤4 — ## Key Metrics Reference
## Key Metrics ReferenceGroup by category (Revenue / Activity / Conversion). Format:
undefined按类别分组(收入/活跃度/转化率)。格式示例:
undefinedRevenue
Revenue
- MRR → ,
fct_stripe_mrr.mrr_amountSUM(mrr_amount) WHERE status='active'
If a semantic layer is configured (`add-semantic-layer`), route through it: `**ARR** → query via dbt MCP query_metric (semantic layer)`.- MRR → ,
fct_stripe_mrr.mrr_amountSUM(mrr_amount) WHERE status='active'
如果已配置语义层(`add-semantic-layer`),则通过语义层查询:`**ARR** → query via dbt MCP query_metric (semantic layer)`。Step 5 — ## Date filtering
(placeholder until Step 7)
## Date filtering步骤5 — ## Date filtering
(占位,待步骤7填充)
## Date filteringLeave a Filled in Step 7.
> TODO: filled in via the user-validation step below.留下,在步骤7中完成填充。
> TODO: 后续通过下方的用户验证步骤填充。Step 6 — ## Analysis Process
## Analysis Process步骤6 — ## Analysis Process
## Analysis ProcessUse the template's 5 subsections verbatim. The project-specific bit is subsection 2 (Select Right Tables): map each major question category to its starting table, derived from Steps 3-4.
直接使用模板中的5个子章节内容。项目特定部分是第2小节(选择正确的表):将每个主要问题类别映射到其起始表,此映射源自步骤3-4的内容。
Step 7 — Validate metrics with the user
步骤7 — 与用户验证指标
For each metric in , ask the user to confirm or correct the source-of-truth pointer. Update in place.
## Key Metrics Reference针对中的每个指标,请用户确认或更正真实数据源的指向。直接在原位置更新内容。
## Key Metrics ReferenceStep 8 — Date filtering, with the user
步骤8 — 与用户确认日期过滤规则
Two questions decide most of it:
- Week boundary: does a week start Sunday (BigQuery ) or Monday (
WEEK)? Applies to "last week", "last N weeks", week-over-week.ISOWEEK - Current period inclusion: when the user says "last 8 weeks" / "last 30 days", include the current incomplete period or exclude it? Rolling-from-now vs. boundary-aligned.
Then: fiscal year start if non-calendar; anything else org-specific.
Write three example formulas only — Last X weeks, Last X days, Current month. The agent extrapolates other periods from these. Each block gets a one-line note above stating the convention used.
sql
-- Last X weeks (Monday-start, excludes current incomplete week)
WHERE date >= DATE_TRUNC(CURRENT_DATE - INTERVAL (X * 7) DAY, ISOWEEK)
AND date < DATE_TRUNC(CURRENT_DATE, ISOWEEK)两个问题可确定大部分规则:
- 周边界:一周从周日(BigQuery )还是周一(
WEEK)开始?适用于“上周”、“最近N周”、周环比场景。ISOWEEK - 当前周期是否包含:当用户说“最近8周”/“最近30天”时,是否包含当前未完成的周期?即从当前时间往前滚动,还是按边界对齐。
此外:如果财年起始日非自然年,请确认;以及其他组织特定规则。
仅编写三个示例公式——最近X周、最近X天、当月。agent会根据这些示例推导出其他时间周期的规则。每个公式块上方添加一行说明,注明所使用的规则约定。
sql
-- Last X weeks (Monday-start, excludes current incomplete week)
WHERE date >= DATE_TRUNC(CURRENT_DATE - INTERVAL (X * 7) DAY, ISOWEEK)
AND date < DATE_TRUNC(CURRENT_DATE, ISOWEEK)Audit-and-fill flow (when RULES.md
is not empty)
RULES.md审计填充流程(当RULES.md
不为空时)
RULES.md- Read it. Compare against the six standard sections. Produce a one-line gap report (present / missing / thin per section).
- Ask the user which sections to fill.
- Run only the relevant generation steps above. Show diffs before saving.
For deeper diagnostics (MECE, schema drift, test failure root causes), route to .
audit-context- 读取现有内容,与六个标准章节对比,生成一行差距报告(每个章节的状态:已存在/缺失/内容单薄)。
- 询问用户需要填充哪些章节。
- 仅运行上述相关的生成步骤。保存前展示差异内容。
如需更深入的诊断(MECE、schema漂移、测试失败根本原因),请转至。
audit-contextGuardrails
约束规则
- Section by section, not all-at-once. Show progress, let the user course-correct.
- Show diffs, don't auto-overwrite.
- Don't bloat . Per-table detail in
RULES.md.databases/<table>.md - Don't invent metric sources. Unclear → list for user validation in Step 7.
- keeps three examples max.
## Date filtering
- 逐章节进行,而非一次性完成。展示进度,让用户可以及时调整方向。
- 展示差异,不要自动覆盖。
- 不要让内容臃肿。每张表的详情请放在
RULES.md中。databases/<table>.md - 不要编造指标数据源。若信息不明确,请在步骤7中列出供用户验证。
- 最多保留三个示例。
## Date filtering
Templates
模板
- — six-section scaffold. This skill is the only one that writes to
templates/RULES.md.RULES.md
- — 包含六个章节的框架。本skill是唯一可写入
templates/RULES.md的功能。RULES.md