build
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseBuild AI Method using the MTHDS standard (Agentic)
使用MTHDS标准构建AI方法(Agent化)
Create new MTHDS bundles through an adaptive, phase-based approach. This skill guides you through drafting (markdown), structuring (CLI/JSON), and assembling complete .mthds bundles.
通过自适应的分阶段方法创建新的MTHDS捆绑包。本Skill将引导你完成草稿编写(Markdown)、结构搭建(CLI/JSON)以及完整.mthds捆绑包的组装过程。
Philosophy
设计理念
- Drafting phases: Generate human-readable markdown documents
- Structuring phases: Use agent CLI commands for JSON-to-TOML conversion
- Visualization: Present ASCII graphs at overview and detail levels
- Iterative: Refine at each phase before proceeding
- 草稿阶段:生成人类可读的Markdown文档
- 结构阶段:使用Agent CLI命令完成JSON到TOML的转换
- 可视化:在概览和细节层面展示ASCII图表
- 迭代式:在进入下一阶段前,对当前阶段内容进行优化
Mode Selection
模式选择
See Mode Selection for general mode behavior.
Default: Automatic for simple-to-moderate methods. Interactive for complex multi-step methods or when the user's request is ambiguous.
Detection heuristics:
- User provides a clear one-sentence goal → automatic
- User describes a complex multi-step process → interactive
- User mentions batching, conditions, or parallel execution → interactive
- User says "create a pipeline for X" with no elaboration → automatic
有关通用模式行为,请参阅模式选择。
默认模式:对于简单到中等复杂度的方法,采用自动模式;对于复杂的多步骤方法,或用户请求模糊时,采用交互模式。
检测规则:
- 用户提供清晰的单句目标 → 自动模式
- 用户描述复杂的多步骤流程 → 交互模式
- 用户提及批量处理、条件分支或并行执行 → 交互模式
- 用户仅说“为X创建流水线”且无进一步说明 → 自动模式
Existing Method Detection
现有方法检测
Goal: Before starting a new build, check whether the project already contains methods that overlap with the user's request.
When to check: Always, before entering automatic or interactive mode — with these exceptions:
- Skip entirely if the user's request signals intent to create something new. This includes phrases like "new method", "a new method", "brand new", "from scratch", "create a method", or similar.
- Targeted search if the user references a specific existing method by name or path, search specifically for that method instead of scanning broadly. If the specific method cannot be found, fall back to the general search approach below.
For the general case, scan and any other directories containing files in the project.
mthds-wip/.mthdsHow to check:
- List all files in the project (glob for
.mthds)**/*.mthds - For each file found, read the file header (domain, main pipe code, description) to understand what it does
- Compare with the user's current request — look for overlap in topic, domain, or purpose
If no existing methods overlap: Proceed normally with the build.
If one or more existing methods overlap, present the user with three options:
I found an existing method that seems related to what you're asking for:
— <brief description of what it does><path/to/bundle.mthds>How would you like to proceed?
- Start fresh — Create a wholly new method from scratch (ignoring the existing one)
- Use the existing method — It already does what you need; cancel this build
- Build upon it — Extend the existing method by adding pipes before or after the current flow
Handling each choice:
- Start fresh: Proceed with the build as normal (automatic or interactive path below).
- Use the existing method: End the build. Remind the user they can run it with and point them to its
/runif available.inputs.json - Build upon it: Switch to the /edit skill, framing the task as an extension — ask the user what additional processing they want to add (e.g., a preprocessing step before the main pipe, a postprocessing step after, or additional parallel branches). Pass the existing file path to the edit workflow.
.mthds
目标:在开始构建新方法前,检查项目中是否已存在与用户请求重叠的方法。
检查时机:在进入自动或交互模式前,始终执行检查,但以下情况除外:
- 完全跳过检查:如果用户的请求明确表示要创建新内容,例如包含“new method”“a new method”“brand new”“from scratch”“create a method”等类似表述。
- 定向搜索:如果用户引用了特定的现有方法名称或路径,则仅针对该方法进行搜索,而非全面扫描。如果未找到该特定方法,则回退到下文的通用搜索方法。
对于通用情况,扫描项目中的目录及其他包含文件的目录。
mthds-wip/.mthds检查方法:
- 列出项目中所有文件(使用通配符
.mthds)**/*.mthds - 对于每个找到的文件,读取文件头(领域信息、主管道代码、描述)以了解其功能
- 将其与用户当前请求进行对比,查找主题、领域或用途上的重叠
如果无重叠的现有方法:正常推进构建流程。
如果存在一个或多个重叠的现有方法,向用户提供三个选项:
我发现一个与你的需求相关的现有方法:
— <该方法功能的简要描述><path/to/bundle.mthds>你希望如何继续?
- 从头开始 — 完全忽略现有方法,创建全新的方法
- 使用现有方法 — 该方法已能满足你的需求,取消本次构建
- 基于现有方法扩展 — 通过在当前流程前后添加管道来扩展现有方法
各选项的处理方式:
- 从头开始:按正常流程推进构建(下文的自动或交互路径)。
- 使用现有方法:终止构建。提醒用户可使用命令运行该方法,并在
/run可用时指向该文件。inputs.json - 基于现有方法扩展:切换到/edit Skill,将任务定义为扩展操作——询问用户想要添加哪些额外处理(例如,主管道之前的预处理步骤、之后的后处理步骤,或额外的并行分支)。将现有文件路径传递给编辑工作流。
.mthds
Prerequisites
前置条件
See CLI Prerequisites
请参阅CLI前置条件
Phase 1: Understand Requirements
阶段1:理解需求
Goal: Gather complete information before planning.
Ask the user:
- What are the method's inputs? (documents, images, text, structured data)
- What outputs should it produce?
- What transformations are needed?
- Are there conditional branches or parallel operations?
- Should items be processed in batches?
Output: Requirements summary (keep in context)
目标:在规划前收集完整信息。
询问用户:
- 该方法的输入是什么?(文档、图片、文本、结构化数据)
- 应生成哪些输出?
- 需要进行哪些转换?
- 是否存在条件分支或并行操作?
- 是否需要批量处理项目?
输出:需求总结(保留在上下文环境中)
Phase 2: Draft the Plan
阶段2:起草计划
Goal: Create a pseudo-code narrative of the method.
Draft a plan in markdown that describes:
- The overall flow from inputs to outputs
- Each processing step with its purpose
- Variable names (snake_case) for inputs and outputs of each step
- Where structured data or lists are involved
Rules:
- Name variables consistently across steps
- Use plural names for lists (e.g., ), singular for items (e.g.,
documents)document - Don't detail types yet - focus on the flow
Show ASCII Overview — see Manual Build Phases for the diagram template.
Output: Plan draft (markdown)
目标:创建方法的伪代码式叙述。
用Markdown起草一份计划,内容包括:
- 从输入到输出的整体流程
- 每个处理步骤及其用途
- 每个步骤输入和输出的变量名(采用snake_case命名法)
- 涉及结构化数据或列表的位置
规则:
- 各步骤间变量命名保持一致
- 列表使用复数名称(例如),单个项目使用单数名称(例如
documents)document - 暂不详细说明类型,重点关注流程
展示ASCII概览图 — 请参阅手动构建阶段获取图表模板。
输出:计划草稿(Markdown格式)
Phase 3: Draft Concepts
阶段3:起草概念定义
Goal: Identify all data types needed in the method.
From the plan, identify input, intermediate, and output concepts.
For each concept, draft:
- Name: PascalCase, singular noun (e.g., not
Invoice)Invoices - Description: What it represents
- Type: Either OR
refines: NativeConceptstructure: {...}
Native concepts (built-in, do NOT redefine): , , , , , , , , , , . See MTHDS Language Reference — Native Concepts
TextHtmlImageDocumentNumberPageTextAndImagesImgGenPromptJSONAnythingDynamicNote:is the native concept for any document (PDF, Word, etc.).Documentis for any image format (JPEG, PNG, etc.). File formats like "PDF" or "JPEG" are not concepts.Image
Each native concept has accessible attributes (e.g., has , , , ...; has , , ...; has and ). See Native Content Types for the full attribute reference — essential for prompts and blocks.
Imageurlpublic_urlfilenamecaptionDocumenturlpublic_urlfilenamePagetext_and_imagespage_view$var.fieldconstructConcept naming rules:
- No adjectives: not
ArticleLongArticle - No circumstances: not
ArgumentCounterArgument - Always singular: not
EmployeeEmployees
Output: Concepts draft (markdown)
目标:识别方法所需的所有数据类型。
从计划中识别输入、中间和输出概念。
为每个概念起草:
- 名称:采用PascalCase,单数名词(例如而非
Invoice)Invoices - 描述:该概念代表的内容
- 类型:要么是,要么是
refines: NativeConceptstructure: {...}
原生概念(内置,无需重新定义):、、、、、、、、、、。请参阅MTHDS语言参考——原生概念
TextHtmlImageDocumentNumberPageTextAndImagesImgGenPromptJSONAnythingDynamic注意:是所有文档(PDF、Word等)的原生概念。Document适用于所有图像格式(JPEG、PNG等)。“PDF”或“JPEG”等文件格式不属于概念范畴。Image
每个原生概念都有可访问的属性(例如包含、、、等;包含、、等;包含和)。请参阅原生内容类型获取完整的属性参考——这对于提示和块至关重要。
Imageurlpublic_urlfilenamecaptionDocumenturlpublic_urlfilenamePagetext_and_imagespage_view$var.fieldconstruct概念命名规则:
- 不使用形容词:而非
ArticleLongArticle - 不使用场景限定词:而非
ArgumentCounterArgument - 始终使用单数:而非
EmployeeEmployees
输出:概念定义草稿(Markdown格式)
Phase 4: Structure Concepts
阶段4:结构化概念定义
Goal: Convert concept drafts to validated TOML using the CLI.
Prepare JSON specs for all concepts, then convert them in parallel by making multiple concurrent tool calls.
Example (3 concepts converted in parallel):
bash
undefined目标:使用CLI将概念定义草稿转换为经过验证的TOML格式。
为所有概念准备JSON规范,然后通过发起多个并发工具调用,并行完成转换。
示例(3个概念并行转换):
bash
undefinedCall all three in parallel (single response, multiple tool calls):
并行调用三个命令(单次响应,多个工具调用):
mthds-agent pipelex concept --spec '{"the_concept_code": "Invoice", "description": "A commercial invoice document", "structure": {"invoice_number": "The unique identifier", "vendor_name": {"type": "text", "description": "Vendor name", "required": true}, "total_amount": {"type": "number", "description": "Total amount", "required": true}}}'
mthds-agent pipelex concept --spec '{"the_concept_code": "LineItem", "description": "A single line item on an invoice", "structure": {"description": "Item description", "quantity": {"type": "integer", "required": true}, "unit_price": {"type": "number", "required": true}}}'
mthds-agent pipelex concept --spec '{"the_concept_code": "Summary", "description": "A text summary of content", "refines": "Text"}'
**Field types**: `text`, `integer`, `boolean`, `number`, `date`, `concept`, `list`
**Choices (enum-like constrained values)**:
```toml
status = {choices = ["pending", "processing", "completed"], description = "Order status", required = true}
score = {type = "number", choices = ["0", "0.5", "1", "1.5", "2"], description = "Score on a half-point scale"}When is present, defaults to if omitted. You can also pair choices with or types explicitly.
choicestypetextintegernumberNested concept references in structures:
toml
field = {type = "concept", concept_ref = "my_domain.OtherConcept", description = "...", required = true}
items = {type = "list", item_type = "concept", item_concept_ref = "my_domain.OtherConcept", description = "..."}Output: Validated concept TOML fragments
Partial failures: If some commands fail, fix the failing specs using the error JSON (means the spec is wrong). Re-run only the failed commands.error_domain: "input"
mthds-agent pipelex concept --spec '{"the_concept_code": "Invoice", "description": "A commercial invoice document", "structure": {"invoice_number": "The unique identifier", "vendor_name": {"type": "text", "description": "Vendor name", "required": true}, "total_amount": {"type": "number", "description": "Total amount", "required": true}}}'
mthds-agent pipelex concept --spec '{"the_concept_code": "LineItem", "description": "A single line item on an invoice", "structure": {"description": "Item description", "quantity": {"type": "integer", "required": true}, "unit_price": {"type": "number", "description": "Unit price", "required": true}}}'
mthds-agent pipelex concept --spec '{"the_concept_code": "Summary", "description": "A text summary of content", "refines": "Text"}'
**字段类型**:`text`、`integer`、`boolean`、`number`、`date`、`concept`、`list`
**可选值(类似枚举的约束值)**:
```toml
status = {choices = ["pending", "processing", "completed"], description = "Order status", required = true}
score = {type = "number", choices = ["0", "0.5", "1", "1.5", "2"], description = "Score on a half-point scale"}当存在时,如果未指定,则默认值为。你也可以显式地将可选值与或类型配对使用。
choicestypetextintegernumber结构中的嵌套概念引用:
toml
field = {type = "concept", concept_ref = "my_domain.OtherConcept", description = "...", required = true}
items = {type = "list", item_type = "concept", item_concept_ref = "my_domain.OtherConcept", description = "..."}输出:经过验证的概念TOML片段
部分失败处理:如果部分命令执行失败,使用错误JSON(表示规范错误)修复失败的规范。仅重新运行失败的命令。error_domain: "input"
Phase 5: Draft the Flow
阶段5:起草流程定义
Goal: Design the complete pipeline structure with controller selection.
目标:设计完整的流水线结构并选择控制器。
Controller Selection Guide
控制器选择指南
| Controller | Use When | Key Pattern |
|---|---|---|
| PipeSequence | Steps must execute in order | step1 → step2 → step3 |
| PipeBatch | Same operation on each list item | map(items, transform) |
| PipeParallel | Independent operations run together | fork → join |
| PipeCondition | Route based on data values | if-then-else |
| 控制器 | 使用场景 | 核心模式 |
|---|---|---|
| PipeSequence | 步骤必须按顺序执行 | step1 → step2 → step3 |
| PipeBatch | 对列表中的每个项目执行相同操作 | map(items, transform) |
| PipeParallel | 独立操作同时运行 | fork → join |
| PipeCondition | 根据数据值路由流程 | if-then-else |
Operator Selection Guide
操作符选择指南
| Operator | Use When |
|---|---|
| PipeLLM | Generate text or structured objects with AI |
| PipeExtract | Extract content from PDF/Image → Page[] |
| PipeCompose | Template text or construct objects |
| PipeImgGen | Generate images from text prompts |
| PipeFunc | Custom Python logic |
Note:outputs from PipeExtract automatically convert to text when inserted into prompts usingPage[].@variable
Show detailed ASCII flow — see Manual Build Phases for all controller flow diagrams.
Output: Flow draft with pipe contracts (markdown)
| 操作符 | 使用场景 |
|---|---|
| PipeLLM | 使用AI生成文本或结构化对象 |
| PipeExtract | 从PDF/图片中提取内容 → Page[] |
| PipeCompose | 模板化文本或构造对象 |
| PipeImgGen | 根据文本提示生成图片 |
| PipeFunc | 自定义Python逻辑 |
注意:当使用将PipeExtract的@variable输出插入到提示中时,会自动转换为文本。Page[]
展示详细ASCII流程图 — 请参阅手动构建阶段获取所有控制器的流程图。
输出:带有管道契约的流程草稿(Markdown格式)
Phase 6: Review & Refine
阶段6:审核与优化
Goal: Validate consistency before structuring.
Check:
- Main pipe is clearly identified and handles method inputs
- Variable names are consistent across all pipes
- Input/output types match between connected pipes
- PipeBatch branches receive singular items, not lists
- PipeBatch: (singular) differs from
input_item_name(plural) and allinput_list_namekeysinputs - PipeSequence batch steps: (singular) differs from
batch_as(plural)batch_over - PipeImgGen inputs are text (add PipeLLM if needed to generate prompt)
- No circular dependencies
Confirm with user before proceeding to structuring.
目标:在结构化前验证一致性。
检查项:
- 主管道已明确标识并处理方法输入
- 所有管道间变量命名保持一致
- 相连管道间的输入/输出类型匹配
- PipeBatch分支接收单个项目,而非列表
- PipeBatch:(单数)与
input_item_name(复数)及所有input_list_name键不同inputs - PipeSequence批量步骤:(单数)与
batch_as(复数)不同batch_over - PipeImgGen的输入为文本(如果需要生成提示,添加PipeLLM步骤)
- 无循环依赖
在进入结构化阶段前,与用户确认。
Phase 7: Structure Pipes
阶段7:结构化管道
Goal: Convert pipe drafts to validated TOML using the CLI.
Default to talent names from Talents and Presets. Only look up specific model presets when the user has explicit instructions about model choice. In all cases, verify that referenced presets exist:
bash
mthds-agent pipelex models --type llm # when structuring PipeLLM pipes
mthds-agent pipelex models --type extract # when structuring PipeExtract pipes
mthds-agent pipelex models --type img_gen # when structuring PipeImgGen pipesPrepare JSON specs for all pipes, then convert them in parallel by making multiple concurrent tool calls.
For detailed CLI examples for each pipe type (PipeLLM, PipeSequence, PipeBatch, PipeCondition, PipeCompose, PipeParallel, PipeExtract, PipeImgGen), see Manual Build Phases.
Output: Validated pipe TOML fragments
Partial failures: Fix failing specs using the error JSON. Re-run only the failed commands.
目标:使用CLI将管道草稿转换为经过验证的TOML格式。
默认使用Talents和预设中的talent名称。仅当用户对模型选择有明确要求时,才查找特定的模型预设。在所有情况下,验证引用的预设是否存在:
bash
mthds-agent pipelex models --type llm # 结构化PipeLLM管道时使用
mthds-agent pipelex models --type extract # 结构化PipeExtract管道时使用
mthds-agent pipelex models --type img_gen # 结构化PipeImgGen管道时使用为所有管道准备JSON规范,然后通过发起多个并发工具调用,并行完成转换。
有关每种管道类型(PipeLLM、PipeSequence、PipeBatch、PipeCondition、PipeCompose、PipeParallel、PipeExtract、PipeImgGen)的详细CLI示例,请参阅手动构建阶段。
输出:经过验证的管道TOML片段
部分失败处理:使用错误JSON修复失败的规范。仅重新运行失败的命令。
Phase 8: Assemble Bundle
阶段8:组装捆绑包
Goal: Combine all parts into a complete .mthds file.
Save location: Always save method bundles to . Do not ask the user for the save location.
mthds-wip/For the assemble CLI command and direct .mthds writing examples, see Manual Build Phases.
目标:将所有部分组合成完整的.mthds文件。
保存位置:始终将方法捆绑包保存到目录。无需询问用户保存位置。
mthds-wip/有关组装CLI命令和直接编写.mthds文件的示例,请参阅手动构建阶段。
Phase 9: Validate & Test
阶段9:验证与测试
Goal: Ensure the bundle is valid and works correctly.
Always use pointing to the bundle's own directory to avoid namespace collisions with other bundles in the project.
-Lbash
undefined目标:确保捆绑包有效且能正常工作。
始终使用参数指向捆绑包自身的目录,以避免与项目中的其他捆绑包发生命名空间冲突。
-Lbash
undefinedValidate (isolated from other bundles)
验证(与其他捆绑包隔离)
mthds-agent pipelex validate mthds-wip/pipeline_01/bundle.mthds -L mthds-wip/pipeline_01/
mthds-agent pipelex validate mthds-wip/pipeline_01/bundle.mthds -L mthds-wip/pipeline_01/
Generate example inputs
生成示例输入
mthds-agent pipelex inputs mthds-wip/pipeline_01/bundle.mthds -L mthds-wip/pipeline_01/
mthds-agent pipelex inputs mthds-wip/pipeline_01/bundle.mthds -L mthds-wip/pipeline_01/
Dry run (directory mode: auto-detects bundle, inputs, library dir)
试运行(目录模式:自动检测捆绑包、输入和库目录)
mthds-agent pipelex run pipe mthds-wip/pipeline_01/ --dry-run --mock-inputs
Fix any validation errors and re-validate. If validation fails unexpectedly or errors are unclear, re-run with `--log-level debug` for additional context:
```bash
mthds-agent --log-level debug pipelex validate mthds-wip/pipeline_01/bundle.mthds -L mthds-wip/pipeline_01/mthds-agent pipelex run pipe mthds-wip/pipeline_01/ --dry-run --mock-inputs
修复所有验证错误并重新验证。如果验证意外失败或错误不清晰,使用`--log-level debug`参数重新运行以获取更多上下文信息:
```bash
mthds-agent --log-level debug pipelex validate mthds-wip/pipeline_01/bundle.mthds -L mthds-wip/pipeline_01/Phase 10: Deliver
阶段10:交付
Goal: Generate input template after a successful build.
After validation passes (Phase 9), generate the input template:
bash
undefined目标:构建成功后生成输入模板。
在阶段9验证通过后,生成输入模板:
bash
undefinedInput template (extracts the input schema as JSON)
输入模板(将输入架构提取为JSON格式)
mthds-agent pipelex inputs <mthds_file> -L <output_dir>/
Replace `<mthds_file>` and `<output_dir>` with actual paths from the build output.mthds-agent pipelex inputs <mthds_file> -L <output_dir>/
将`<mthds_file>`和`<output_dir>`替换为构建输出中的实际路径。Present Results
展示结果
After the command succeeds:
-
Input template: Show theJSON from the inputs command output. Save it to
inputsfor the user to fill in.<output_dir>/inputs.json -
Next steps — try it now: If the method requires inputs, the savedstill contains placeholder values, so suggest a dry run first:
inputs.jsonTo try this method right now, use /run or from the terminal:mthds run <output_dir>/ --dry-run --mock-inputs -
Next steps — run with real data: Explain how to prepare real inputs, then run for real:To run with real data, use /inputs to prepare your inputs (provide your own files, or generate synthetic test data), then:
mthds run <output_dir>/Replacewith the actual output directory path used throughout the build.<output_dir>
命令执行成功后:
-
输入模板:展示inputs命令输出中的JSON。将其保存到
inputs供用户填写。<output_dir>/inputs.json -
下一步——立即试用:如果该方法需要输入,保存的仍包含占位符值,因此建议先进行试运行:
inputs.json要立即试用该方法,请使用/run命令,或在终端中运行:mthds run <output_dir>/ --dry-run --mock-inputs -
下一步——使用真实数据运行:说明如何准备真实输入,然后实际运行:要使用真实数据运行,请使用/inputs命令准备你的输入(提供你自己的文件,或生成 synthetic 测试数据),然后运行:
mthds run <output_dir>/将替换为整个构建过程中使用的实际输出目录路径。<output_dir>
Quick Reference
快速参考
Multiplicity Notation
多重性表示法
- - single item
Text - - variable-length list
Text[] - - exactly 3 items
Text[3]
- - 单个项目
Text - - 可变长度列表
Text[] - - 恰好3个项目
Text[3]
Prompt Variables
提示变量
- - Block insertion (multi-line, with delimiters)
@variable - - Inline insertion (short text)
$variable - - Access nested field
$var.field
- - 块插入(多行,带分隔符)
@variable - - 内联插入(短文本)
$variable - - 访问嵌套字段
$var.field
Naming Conventions
命名规范
- Domain:
snake_case - Concepts: , singular
PascalCase - Pipes:
snake_case - Variables:
snake_case
- 领域:
snake_case - 概念:,单数
PascalCase - 管道:
snake_case - 变量:
snake_case
Reference
参考资料
- CLI Prerequisites — read at skill start to check CLI availability
- Error Handling — read when CLI returns an error to determine recovery
- MTHDS Agent Guide — read for CLI command syntax or output format details
- MTHDS Language Reference — read when writing or modifying .mthds TOML syntax
- Native Content Types — read when using in prompts or
$var.fieldin construct blocks, to know which attributes each native concept exposesfrom - Manual Build Phases — read for detailed ASCII diagrams and CLI examples per phase
- Talents and Presets — read when selecting model talents for pipe structuring
- CLI前置条件 — 在Skill启动时阅读,检查CLI是否可用
- 错误处理 — 当CLI返回错误时阅读,以确定恢复方式
- MTHDS Agent指南 — 阅读以了解CLI命令语法或输出格式细节
- MTHDS语言参考 — 在编写或修改.mthds TOML语法时阅读
- 原生内容类型 — 在提示中使用或在construct块中使用
$var.field时阅读,以了解每个原生概念暴露的属性from - 手动构建阶段 — 阅读以获取各阶段的详细ASCII图表和CLI示例
- Talents和预设 — 在为管道结构化选择模型talents时阅读