python-yama 0.3.0__tar.gz → 0.4.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {python_yama-0.3.0 → python_yama-0.4.0}/PKG-INFO +3 -2
- {python_yama-0.3.0 → python_yama-0.4.0}/README.md +2 -1
- {python_yama-0.3.0 → python_yama-0.4.0}/README.zh-CN.md +2 -1
- {python_yama-0.3.0 → python_yama-0.4.0}/docs/agent-skill-test-framework-design.md +176 -48
- {python_yama-0.3.0 → python_yama-0.4.0}/skills/eval-plugin-with-yama/SKILL.md +11 -4
- {python_yama-0.3.0 → python_yama-0.4.0}/skills/eval-plugin-with-yama/references/case-schema.md +39 -5
- {python_yama-0.3.0 → python_yama-0.4.0}/skills/eval-plugin-with-yama/references/debugging.md +10 -4
- {python_yama-0.3.0 → python_yama-0.4.0}/tests/test_assertions.py +23 -2
- {python_yama-0.3.0 → python_yama-0.4.0}/tests/test_cli.py +94 -1
- {python_yama-0.3.0 → python_yama-0.4.0}/tests/test_framework.py +153 -0
- {python_yama-0.3.0 → python_yama-0.4.0}/tests/test_report.py +73 -2
- {python_yama-0.3.0 → python_yama-0.4.0}/tests/test_skill_tool.py +18 -2
- python_yama-0.4.0/tests/test_tool_loader.py +343 -0
- python_yama-0.4.0/tests/test_usage.py +224 -0
- {python_yama-0.3.0 → python_yama-0.4.0}/tests/test_workspace.py +69 -0
- {python_yama-0.3.0 → python_yama-0.4.0}/yama/assertions.py +4 -0
- {python_yama-0.3.0 → python_yama-0.4.0}/yama/cli.py +67 -21
- {python_yama-0.3.0 → python_yama-0.4.0}/yama/llm.py +31 -1
- {python_yama-0.3.0 → python_yama-0.4.0}/yama/loaders/case.py +12 -33
- python_yama-0.4.0/yama/loaders/tool_loader.py +324 -0
- {python_yama-0.3.0 → python_yama-0.4.0}/yama/models.py +1 -0
- {python_yama-0.3.0 → python_yama-0.4.0}/yama/report.py +73 -9
- {python_yama-0.3.0 → python_yama-0.4.0}/yama/runner.py +45 -1
- {python_yama-0.3.0 → python_yama-0.4.0}/yama/tools/bash/fs.py +13 -2
- {python_yama-0.3.0 → python_yama-0.4.0}/yama/tools/skill/skill.py +8 -2
- {python_yama-0.3.0 → python_yama-0.4.0}/yama/workspace.py +29 -0
- python_yama-0.3.0/yama/loaders/tool_loader.py +0 -173
- {python_yama-0.3.0 → python_yama-0.4.0}/.github/workflows/publish.yml +0 -0
- {python_yama-0.3.0 → python_yama-0.4.0}/.gitignore +0 -0
- {python_yama-0.3.0 → python_yama-0.4.0}/CLAUDE.md +0 -0
- {python_yama-0.3.0 → python_yama-0.4.0}/LICENSE +0 -0
- {python_yama-0.3.0 → python_yama-0.4.0}/pyproject.toml +0 -0
- {python_yama-0.3.0 → python_yama-0.4.0}/tests/test_cli_shim.py +0 -0
- {python_yama-0.3.0 → python_yama-0.4.0}/tests/test_main_entrypoint.py +0 -0
- {python_yama-0.3.0 → python_yama-0.4.0}/tests/test_mocks.py +0 -0
- {python_yama-0.3.0 → python_yama-0.4.0}/tests/test_public_api.py +0 -0
- {python_yama-0.3.0 → python_yama-0.4.0}/uv.lock +0 -0
- {python_yama-0.3.0 → python_yama-0.4.0}/yama/__init__.py +0 -0
- {python_yama-0.3.0 → python_yama-0.4.0}/yama/__main__.py +0 -0
- {python_yama-0.3.0 → python_yama-0.4.0}/yama/loaders/__init__.py +0 -0
- {python_yama-0.3.0 → python_yama-0.4.0}/yama/loaders/common.py +0 -0
- {python_yama-0.3.0 → python_yama-0.4.0}/yama/mocks.py +0 -0
- {python_yama-0.3.0 → python_yama-0.4.0}/yama/tools/__init__.py +0 -0
- {python_yama-0.3.0 → python_yama-0.4.0}/yama/tools/base.py +0 -0
- {python_yama-0.3.0 → python_yama-0.4.0}/yama/tools/bash/__init__.py +0 -0
- {python_yama-0.3.0 → python_yama-0.4.0}/yama/tools/bash/_cli_shim.py +0 -0
- {python_yama-0.3.0 → python_yama-0.4.0}/yama/tools/bash/bash.py +0 -0
- {python_yama-0.3.0 → python_yama-0.4.0}/yama/tools/skill/__init__.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: python-yama
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.4.0
|
|
4
4
|
Summary: A reproducible evaluation runner for tool-using Agent skills
|
|
5
5
|
Project-URL: Repository, https://github.com/world-sim-dev/yama
|
|
6
6
|
Project-URL: Issues, https://github.com/world-sim-dev/yama/issues
|
|
@@ -75,7 +75,7 @@ outcome:
|
|
|
75
75
|
|
|
76
76
|
- `description` (optional) is a one-line summary of what the Case tests; it is shown in the CLI output and the HTML report.
|
|
77
77
|
- `context.tools` is the tool schema sent to the model; `mocks.tools` is how the runner responds when a tool call arrives. The two sets of tool names must match exactly.
|
|
78
|
-
- To use a Skill, declare it by name under `context.skills` and also declare `{builtin: skill}` under `context.tools`; the model reads the Skill body via `skill(name, file?)`.
|
|
78
|
+
- To use a Skill, declare it by name under `context.skills` and also declare `{builtin: skill}` under `context.tools`; the model reads the Skill body via `skill(name, file?, call_reason?)`.
|
|
79
79
|
- To simulate command-line tools, declare `{builtin: bash}` and configure per-command output under `mocks.cli`.
|
|
80
80
|
- `steps[].assert.hard` are deterministic checks (nine types, including `tool_called`, `tool_arguments`, and `assistant_contains`); add `assert.judge` for LLM scoring.
|
|
81
81
|
|
|
@@ -93,6 +93,7 @@ uv run --project yama yama --plugin dingding-simple --report
|
|
|
93
93
|
| `--plugin-root PATH` | Use the given path as the single plugin root |
|
|
94
94
|
| `--plugin NAME` (repeatable) | Select plugins by name from `yama.toml` |
|
|
95
95
|
| `--all-plugins` | Run every plugin configured in `yama.toml` |
|
|
96
|
+
| `-k, --filter PATTERN` (repeatable) | Only run cases whose case key (path relative to the plugin root) matches — a substring, or an fnmatch glob when the pattern contains `*` `?` `[`; with several patterns a case runs if any matches |
|
|
96
97
|
| `--result-dir PATH` | Override the artifact root (default `<plugin_root>/.yama/runs`) |
|
|
97
98
|
| `--concurrency N` | Maximum number of cases running in parallel (default 10; `1` runs cases one at a time) |
|
|
98
99
|
| `--report [PATH]` | Also generate a single-file HTML report (default `.yama/reports/latest.html`) |
|
|
@@ -50,7 +50,7 @@ outcome:
|
|
|
50
50
|
|
|
51
51
|
- `description` (optional) is a one-line summary of what the Case tests; it is shown in the CLI output and the HTML report.
|
|
52
52
|
- `context.tools` is the tool schema sent to the model; `mocks.tools` is how the runner responds when a tool call arrives. The two sets of tool names must match exactly.
|
|
53
|
-
- To use a Skill, declare it by name under `context.skills` and also declare `{builtin: skill}` under `context.tools`; the model reads the Skill body via `skill(name, file?)`.
|
|
53
|
+
- To use a Skill, declare it by name under `context.skills` and also declare `{builtin: skill}` under `context.tools`; the model reads the Skill body via `skill(name, file?, call_reason?)`.
|
|
54
54
|
- To simulate command-line tools, declare `{builtin: bash}` and configure per-command output under `mocks.cli`.
|
|
55
55
|
- `steps[].assert.hard` are deterministic checks (nine types, including `tool_called`, `tool_arguments`, and `assistant_contains`); add `assert.judge` for LLM scoring.
|
|
56
56
|
|
|
@@ -68,6 +68,7 @@ uv run --project yama yama --plugin dingding-simple --report
|
|
|
68
68
|
| `--plugin-root PATH` | Use the given path as the single plugin root |
|
|
69
69
|
| `--plugin NAME` (repeatable) | Select plugins by name from `yama.toml` |
|
|
70
70
|
| `--all-plugins` | Run every plugin configured in `yama.toml` |
|
|
71
|
+
| `-k, --filter PATTERN` (repeatable) | Only run cases whose case key (path relative to the plugin root) matches — a substring, or an fnmatch glob when the pattern contains `*` `?` `[`; with several patterns a case runs if any matches |
|
|
71
72
|
| `--result-dir PATH` | Override the artifact root (default `<plugin_root>/.yama/runs`) |
|
|
72
73
|
| `--concurrency N` | Maximum number of cases running in parallel (default 10; `1` runs cases one at a time) |
|
|
73
74
|
| `--report [PATH]` | Also generate a single-file HTML report (default `.yama/reports/latest.html`) |
|
|
@@ -50,7 +50,7 @@ outcome:
|
|
|
50
50
|
|
|
51
51
|
- `description`(可选)是一句话说明当前 Case 测试什么;会展示在 CLI 输出和 HTML 报告中。
|
|
52
52
|
- `context.tools` 是发给模型的 Tool Schema,`mocks.tools` 是 Runner 收到 Tool Call 后如何返回结果;两者的 Tool 名字集合必须完全一致。
|
|
53
|
-
- 需要 Skill 时在 `context.skills` 中按名字声明,并在 `context.tools` 中同时声明 `{builtin: skill}`;模型通过 `skill(name, file?)` 读取正文。
|
|
53
|
+
- 需要 Skill 时在 `context.skills` 中按名字声明,并在 `context.tools` 中同时声明 `{builtin: skill}`;模型通过 `skill(name, file?, call_reason?)` 读取正文。
|
|
54
54
|
- 需要模拟命令行工具时声明 `{builtin: bash}`,在 `mocks.cli` 中按命令配置输出。
|
|
55
55
|
- `steps[].assert.hard` 是确定性检查(`tool_called`、`tool_arguments`、`assistant_contains` 等九种类型);还可以加 `assert.judge` 做 LLM 打分。
|
|
56
56
|
|
|
@@ -68,6 +68,7 @@ uv run --project yama yama --plugin dingding-simple --report
|
|
|
68
68
|
| `--plugin-root PATH` | 以指定路径作为单一 Plugin Root |
|
|
69
69
|
| `--plugin NAME`(可重复) | 按 `yama.toml` 中的 Plugin 名字选择 |
|
|
70
70
|
| `--all-plugins` | 运行 `yama.toml` 中配置的全部 Plugin |
|
|
71
|
+
| `-k, --filter PATTERN`(可重复) | 只运行 case key(相对 Plugin Root 的路径)匹配 PATTERN 的 Case——默认子串匹配,PATTERN 含 `*` `?` `[` 时按 fnmatch 通配符匹配;传多个时命中任意一个即运行 |
|
|
71
72
|
| `--result-dir PATH` | 覆盖产物根目录(默认 `<plugin_root>/.yama/runs`) |
|
|
72
73
|
| `--concurrency N` | 同时运行的 Case 数上限(默认 10;`1` 表示逐个顺序执行) |
|
|
73
74
|
| `--report [PATH]` | 额外生成单文件 HTML 报告(默认 `.yama/reports/latest.html`) |
|
|
@@ -72,7 +72,7 @@ SYSTEM.md Skill Catalog Extra Messages
|
|
|
72
72
|
| `workspace.py` | 定位 `yama.toml`、解析 Workspace/Plugin Root、Case 文件发现 | `WorkspaceConfig`、`resolve_plugin_root`、`collect_case_paths` |
|
|
73
73
|
| `loaders/__init__.py` | 重新导出包的公开 API | `resolve_case`、`CollectionError`、`load_yaml` |
|
|
74
74
|
| `loaders/common.py` | Case 加载共用的小工具:YAML 加载、文件 sha256 | `load_yaml`、`sha256_file`、`CollectionError` |
|
|
75
|
-
| `loaders/tool_loader.py` | 把一个 `context.tools` 条目展开成 `ToolSchema
|
|
75
|
+
| `loaders/tool_loader.py` | 把一个 `context.tools` 条目展开成 `ToolSchema`;再统一把 `mocks.tools` 中 `handler: {builtin: skill\|bash}` 的条目展开成对应的内置 Python Handler(`{builtin: x}` 声明会先 setdefault 一条这样的 Mock) | `load_tool`、`resolve_builtin_handlers` |
|
|
76
76
|
| `loaders/case.py` | 把一个 Case YAML 展开成 `ResolvedCase`:加载 system prompt、Skill frontmatter、渲染 `<available_skills>`、调用 `tool_loader.load_tool`、解析多模态消息 part 并生成 fixture manifest | `resolve_case`、`_load_skill`、`_render_system_prompt`、`_resolve_message_parts` |
|
|
77
77
|
| `models.py` | 纯数据结构(无行为副作用) | `ResolvedCase`、`ToolSchema`、`ToolCall`、`LLMResponse`、`StepResult`、`ToolCallRecord`、`CheckerResult`、`LoadedSkill` |
|
|
78
78
|
| `mocks.py` | 通用 Mock 框架:校验 `mocks` 配置、声明式 `respond` 解析、Python `handler` 加载与调用、参数匹配器 `_matches`、Mock Event 记录、run 级共享 `state` 的 diff 与 `ToolMockContext` | `MockToolRegistry`、`ToolMockContext`、`ToolMockError`、`load_python_callable` |
|
|
@@ -95,10 +95,12 @@ cli.main
|
|
|
95
95
|
└─ loaders.case.resolve_case(path) # 产出 ResolvedCase(纯数据)
|
|
96
96
|
├─ 加载 system prompt + skills → 渲染 <available_skills>
|
|
97
97
|
├─ loaders.tool_loader.load_tool 加载 context.tools → ToolSchema[]
|
|
98
|
-
|
|
99
|
-
│
|
|
100
|
-
│
|
|
101
|
-
│
|
|
98
|
+
├─ loaders.tool_loader.resolve_builtin_handlers 展开 builtin Mock:
|
|
99
|
+
│ └─ {builtin: bash}/{builtin: skill} 声明先 setdefault 一条
|
|
100
|
+
│ handler: {builtin: x} 的 mocks.tools 条目
|
|
101
|
+
│ └─ 所有 handler: {builtin: bash} 条目接到 tools/bash/bash.py:run_bash
|
|
102
|
+
│ (消费 mocks.cli / mocks.fs);handler: {builtin: skill} 条目
|
|
103
|
+
│ 接到 tools/skill/skill.py:read_skill(派生 enabled/skills_dir)
|
|
102
104
|
└─ 解析 context.messages / steps[].user 里的 fixture 引用
|
|
103
105
|
└─ YamaRunner.run_case(case)
|
|
104
106
|
└─ 按 execution.repeat 跑 N 次 _run_once
|
|
@@ -143,7 +145,9 @@ cli.main
|
|
|
143
145
|
确定性测试/回放,两者共用同一套消息/工具转换逻辑 (`_litellm_call_arguments`)。
|
|
144
146
|
脚本响应可带 `expect`(`tools`/`last_role`/`last_user_contains`)对当次请求做
|
|
145
147
|
断言;请求没有工具时 litellm 参数会整体省略 `tools` 键,`expect: {tools: []}`
|
|
146
|
-
按空列表匹配(Judge
|
|
148
|
+
按空列表匹配(Judge 请求正是这种无工具请求)。脚本响应还可带可选 `usage`
|
|
149
|
+
(token 用量,模拟 Provider 计费口径,见第 11 节),两个 Client 都会把
|
|
150
|
+
Provider/脚本的 usage 规范化后挂在 `LLMResponse.usage` 上。
|
|
147
151
|
|
|
148
152
|
## 4. Workspace 与 Plugin
|
|
149
153
|
|
|
@@ -217,6 +221,7 @@ yama --plugin-root ./dingding-simple
|
|
|
217
221
|
| `--plugin-root PATH` | 以指定路径作为单一 Plugin Root |
|
|
218
222
|
| `--plugin NAME`(可重复) | 按 `yama.toml` 中的 Plugin 名字选择,一次可传多次 |
|
|
219
223
|
| `--all-plugins` | 运行 `yama.toml` 中配置的全部 Plugin |
|
|
224
|
+
| `-k, --filter PATTERN`(可重复) | Case 筛选:只保留 case key 匹配 PATTERN 的 Case(见下) |
|
|
220
225
|
| `--result-dir PATH` | 覆盖产物根目录(默认每个 Case 写到其所属 `plugin_root/.yama/runs`) |
|
|
221
226
|
| `--concurrency N` | 同时运行的 Case 数上限(必须 ≥ 1,默认 10);`1` 表示按收集顺序逐个执行 |
|
|
222
227
|
| `--report [PATH]` | 额外写一份单文件 HTML 报告;省略路径时默认写到 `<第一个 result_root 的上级>/reports/latest.html` |
|
|
@@ -228,6 +233,16 @@ yama --plugin-root ./dingding-simple
|
|
|
228
233
|
Workspace Root(或 cwd 本身)作为单一 Plugin Root——这正是 `cd dingding-simple && yama`
|
|
229
234
|
可行的原因。
|
|
230
235
|
|
|
236
|
+
**Case 筛选(`-k/--filter`,`workspace.py:matches_case_filter`)。** 收集阶段
|
|
237
|
+
(`collect_case_paths`)在 glob/显式路径展开之后、YAML 解析之前,用 case key
|
|
238
|
+
(`case_key_for_path`:Case 路径相对 Plugin Root 的 POSIX 形式,Plugin Root 之外
|
|
239
|
+
的显式路径退化为纯文件名——与结果展示用的 `case_key` 完全同源)对每个候选做匹配:
|
|
240
|
+
PATTERN 含 `*`/`?`/`[` 任一字符时按 `fnmatch` 通配符(大小写敏感)匹配完整 key,
|
|
241
|
+
否则按子串匹配;`-k` 可重复,多个 PATTERN 之间是 OR 关系。筛选发生在解析之前,
|
|
242
|
+
所以被筛掉的 Case 即使 YAML 损坏也不会阻塞本次运行;`--list` 同样受筛选影响。
|
|
243
|
+
筛选后一个 Case 都不剩时报 `No eval cases matched the case filter.` 并以退出码 2
|
|
244
|
+
结束(与"根本没收集到 Case"同级别,但错误信息区分两种情况)。
|
|
245
|
+
|
|
231
246
|
**Case 级并发调度(`--concurrency`,`cli.py:_run`)。** 收集到的多个 Case 用
|
|
232
247
|
`asyncio.Semaphore(concurrency)` + `asyncio.gather` 在同一事件循环里并发执行
|
|
233
248
|
(执行链路本就是全异步:LiteLLM `acompletion`、bash 沙箱的 asyncio 子进程——
|
|
@@ -478,7 +493,7 @@ context:
|
|
|
478
493
|
|
|
479
494
|
### 6.4 Skill Tool
|
|
480
495
|
|
|
481
|
-
`<available_skills>` 永远只包含 `name` 和 `description`,不存在正文注入模式。只要 Case 的 `context.skills` 非空,就必须在 `context.tools` 中显式声明 `{builtin: skill}
|
|
496
|
+
`<available_skills>` 永远只包含 `name` 和 `description`,不存在正文注入模式。只要 Case 的 `context.skills` 非空,就必须在 `context.tools` 中显式声明 `{builtin: skill}`——或者声明一个自定义 Schema 的 Tool,并在它的 `mocks.tools` 条目里使用 `handler: {builtin: skill}`(见本节末尾);两者都缺失时在 collection 阶段失败(`"context.tools must include {builtin: skill} (or a tool whose mocks.tools entry uses handler: {builtin: skill}) when context.skills is non-empty"`)。这样每个 Case 都会测试真实的 Skill 查阅行为,不会因 Prompt 预先包含正文而绕过 Tool Call。
|
|
482
497
|
|
|
483
498
|
使用框架内置实现:
|
|
484
499
|
|
|
@@ -491,31 +506,40 @@ context:
|
|
|
491
506
|
- builtin: skill
|
|
492
507
|
```
|
|
493
508
|
|
|
494
|
-
框架自动向模型暴露名为 `skill` 的 Tool(`loaders/tool_loader.py:_skill_tool_schema
|
|
509
|
+
框架自动向模型暴露名为 `skill` 的 Tool(`loaders/tool_loader.py:_skill_tool_schema`)。Schema 是**静态**的(不随 `context.skills` 变化),取自生产 Agent Runner 的 skill 工具定义——描述是一段完整的调用守则(何时调用、不要猜名字、已加载不要重复调用等),参数为:
|
|
495
510
|
|
|
496
511
|
```yaml
|
|
497
512
|
name: skill
|
|
498
|
-
description: Read an enabled Skill entry or one file inside that Skill directory.
|
|
499
513
|
parameters:
|
|
500
|
-
type: object
|
|
501
514
|
properties:
|
|
502
515
|
name:
|
|
516
|
+
description: Skill directory name under workspace/skills.
|
|
503
517
|
type: string
|
|
504
|
-
enum: [analyze-music-rhythm, plan-visual-style]
|
|
505
|
-
description: Enabled Skill name.
|
|
506
518
|
file:
|
|
519
|
+
default: ''
|
|
520
|
+
description: Optional relative file path inside the skill directory; reads SKILL.md when empty.
|
|
507
521
|
type: string
|
|
508
|
-
|
|
522
|
+
call_reason:
|
|
523
|
+
anyOf:
|
|
524
|
+
- anyOf: [{type: string}, {type: 'null'}]
|
|
525
|
+
description: one-sentence reason for calling this tool (prefer <=120 chars; longer values are accepted)
|
|
526
|
+
- type: 'null'
|
|
527
|
+
default: null
|
|
509
528
|
required: [name]
|
|
510
|
-
|
|
529
|
+
type: object
|
|
511
530
|
```
|
|
512
531
|
|
|
513
532
|
内置实现(`tools/skill/skill.py:SkillTool`)的读取规则:
|
|
514
533
|
|
|
515
|
-
- `name` 只能是当前 Case 在 `context.skills` 中启用的 Skill
|
|
516
|
-
|
|
517
|
-
|
|
534
|
+
- `name` 只能是当前 Case 在 `context.skills` 中启用的 Skill。Schema 本身不含 enum
|
|
535
|
+
约束(与生产一致,模型只能从 `<available_skills>` 里选名字);这条限制由框架自动
|
|
536
|
+
注册的默认 Mock 的 `match.arguments.name.one_of: [...]` 与 Handler 内部的
|
|
537
|
+
`enabled` 检查兜底(未声明自定义 Handler 时才生效)。
|
|
538
|
+
- 省略 `file`、或传空串/空白串/`null` 时,返回 `<skill-dir>/SKILL.md`(或该 Plugin
|
|
539
|
+
配置的 `skill_entry`)的完整内容——与 Schema 声明的 `default: ''`/"reads SKILL.md
|
|
540
|
+
when empty" 一致。
|
|
518
541
|
- 指定 `file` 时返回 `<skill-dir>/<file>` 的完整内容,例如 `references/music-analysis-detail-generation.md`。
|
|
542
|
+
- `call_reason` 仅作为调用参数记录在 Mock Event 里,不影响执行。
|
|
519
543
|
- `file` 必须是相对当前 Skill 目录的普通文件路径;绝对路径、`..` 越界、符号链接越界、
|
|
520
544
|
目录和不存在的文件都硬失败(错误码分别为 `INVALID_SKILL_FILE`、
|
|
521
545
|
`INVALID_SKILL_FILE`、`SKILL_FILE_NOT_FOUND`);非 UTF-8 文本文件额外硬失败,
|
|
@@ -524,7 +548,7 @@ parameters:
|
|
|
524
548
|
- `skill` Tool Schema 按 `{builtin: skill}` 在 `context.tools` 中的声明位置排列。
|
|
525
549
|
- 未声明 `mocks.tools.skill` 时,框架自动配置内置文件读取 Handler。
|
|
526
550
|
|
|
527
|
-
Case 也可以替换执行实现,但保持相同的 `skill(name, file?)` 模型侧接口:
|
|
551
|
+
Case 也可以替换执行实现,但保持相同的 `skill(name, file?, call_reason?)` 模型侧接口:
|
|
528
552
|
|
|
529
553
|
```yaml
|
|
530
554
|
context:
|
|
@@ -541,7 +565,38 @@ mocks:
|
|
|
541
565
|
source: recorded-snapshot
|
|
542
566
|
```
|
|
543
567
|
|
|
544
|
-
自定义 Handler 使用与其他 Python Tool Mock 相同的 `arguments / context / config` 签名、返回与异常语义。框架仍负责生成固定 Schema
|
|
568
|
+
自定义 Handler 使用与其他 Python Tool Mock 相同的 `arguments / context / config` 签名、返回与异常语义。框架仍负责生成固定 Schema,并把调用写入统一 Mock Event;自定义实现负责解释 `file` 和返回内容。
|
|
569
|
+
|
|
570
|
+
反过来,Case 也可以**替换模型侧 Schema、保留框架内置的执行实现**:用 `inline`/`file` 声明一个自定义 Tool(名字任意,比如复刻宿主 Agent 的工具名与描述文案),并在它的 `mocks.tools` 条目里把 handler 指定为 builtin:
|
|
571
|
+
|
|
572
|
+
```yaml
|
|
573
|
+
context:
|
|
574
|
+
skills:
|
|
575
|
+
- analyze-music-rhythm
|
|
576
|
+
tools:
|
|
577
|
+
- inline:
|
|
578
|
+
name: Skill
|
|
579
|
+
description: Load a skill by name. # 自定义描述
|
|
580
|
+
parameters:
|
|
581
|
+
type: object
|
|
582
|
+
properties:
|
|
583
|
+
name: { type: string }
|
|
584
|
+
file: { type: string }
|
|
585
|
+
required: [name]
|
|
586
|
+
additionalProperties: false
|
|
587
|
+
mocks:
|
|
588
|
+
tools:
|
|
589
|
+
Skill:
|
|
590
|
+
handler:
|
|
591
|
+
builtin: skill
|
|
592
|
+
```
|
|
593
|
+
|
|
594
|
+
collection 阶段的展开与校验(`loaders/tool_loader.py:resolve_builtin_handlers`):
|
|
595
|
+
|
|
596
|
+
- `handler: {builtin: skill}` 被展开成 `python: yama.tools.skill.skill:read_skill` 加上派生配置(`enabled` = `context.skills` 全集、`skills_dir`/`skill_entry` 来自 Plugin 约定),与 `{builtin: skill}` 声明自动接线的结果完全一致;条目未写 `match` 时同样注入默认的 `name.one_of` 约束,写了则尊重 Case 自己的 `match`。
|
|
597
|
+
- 自定义 Schema 必须满足内置 Handler 的调用契约:`parameters.properties` 必须包含 `name` 且 `required` 包含 `name`(bash 对应 `command`),否则 collection 失败(`"tool 'Skill' uses handler {builtin: skill} so its parameters must declare a required 'name' property"`)。`file` 等其余参数不做强制。
|
|
598
|
+
- `handler: {builtin: ...}` 不接受 `with` 等其他字段(配置全部由框架派生);未知 builtin 名、`context.tools` 中不存在同名 Tool 均在 collection 阶段失败。
|
|
599
|
+
- `{builtin: skill}` 声明本质上就是"内置 Schema + `mocks.tools.skill` 缺省时自动补一条 `handler: {builtin: skill}`"的糖;两种写法展开后无差别。
|
|
545
600
|
|
|
546
601
|
## 7. Context 与 Message Builder
|
|
547
602
|
|
|
@@ -621,8 +676,32 @@ context:
|
|
|
621
676
|
|
|
622
677
|
当前内置 Tool 有两个:
|
|
623
678
|
|
|
624
|
-
- `skill
|
|
625
|
-
- `bash
|
|
679
|
+
- `skill`:暴露静态的 Skill 读取 Schema(`name`/`file?`/`call_reason?`,取自生产 skill 工具定义,见 6.4 节),并在未配置 `mocks.tools.skill` 时使用框架内置 Handler;启用集合的约束由默认 Mock 的 `match` 与 Handler 的 `enabled` 检查实现,不在 Schema 里。
|
|
680
|
+
- `bash`:暴露一个命令执行 Tool。默认按 `mocks.cli` 声明的命令返回确定性的 stdout / stderr / exit code,未声明的命令一律 `command not found`(exit code 127),详见 8.4.1;需要模型执行任意命令(包括任意 Python 脚本)时改用 `mocks.fs`,在一个真实、隔离的工作目录里执行真实 shell,详见 8.4.3。二者互斥,一个 Case 只能选一种。
|
|
681
|
+
|
|
682
|
+
内置 bash 的 Schema(`loaders/tool_loader.py:_bash_tool_schema`)参考生产 Agent Runner 的 Bash 工具编写:描述是一段完整的使用指引(用途、When to use、Arguments、Execution behavior、Safety constraints),参数为:
|
|
683
|
+
|
|
684
|
+
```yaml
|
|
685
|
+
name: bash
|
|
686
|
+
parameters:
|
|
687
|
+
type: object
|
|
688
|
+
properties:
|
|
689
|
+
command:
|
|
690
|
+
type: string
|
|
691
|
+
description: Shell command to execute via bash -c.
|
|
692
|
+
timeout_seconds:
|
|
693
|
+
type: integer
|
|
694
|
+
description: Maximum runtime in seconds before timeout.
|
|
695
|
+
call_reason:
|
|
696
|
+
type: string
|
|
697
|
+
description: One-sentence reason for calling this tool (max 120 chars).
|
|
698
|
+
required: [command]
|
|
699
|
+
additionalProperties: false
|
|
700
|
+
```
|
|
701
|
+
|
|
702
|
+
执行层只消费 `command` 与 `timeout_seconds`:模型传入的 `timeout_seconds` 会与 Case 配置的超时上限取较小值(`tools/bash/fs.py:_effective_timeout`,上限来自 `mocks.fs.limits.timeout_seconds` 或 `mocks.cli.passthrough_timeout_seconds`,默认 30 秒),无效值(非正数、非数字)被忽略;`call_reason` 仅作为调用参数记录在 Mock Event 里,不影响执行。
|
|
703
|
+
|
|
704
|
+
`builtin` 声明只是"内置 Schema + 默认执行接线"的糖。Case 也可以用 `inline`/`file` 声明一个自定义 Schema 的 Tool(名字、描述、参数都可自定义),再在 `mocks.tools.<name>.handler` 里写 `{builtin: skill}` / `{builtin: bash}` 保留框架内置的执行实现——自定义 Schema 必须满足内置 Handler 的调用契约(bash 要求 `command`、skill 要求 `name` 是 required 属性),详见 6.4 节末尾与 8.4.1/8.4.3 的前置条件。
|
|
626
705
|
|
|
627
706
|
每个 Tool 在模型侧的规范化结构是 `models.py:ToolSchema`(原设计文档中的
|
|
628
707
|
`ResolvedToolSchema` 是同一个类的旧称):
|
|
@@ -708,7 +787,8 @@ context:
|
|
|
708
787
|
#### 7.2.3 加载、顺序和校验规则
|
|
709
788
|
|
|
710
789
|
- Tool 顺序严格采用 `context.tools` 的声明顺序,并原样用于每次 LLM Request。
|
|
711
|
-
- 文件中的 `name`、内联的 `name` 与 `mocks.tools` 的 key 必须完全一致;未覆盖 Handler 的内置 Tool
|
|
790
|
+
- 文件中的 `name`、内联的 `name` 与 `mocks.tools` 的 key 必须完全一致;未覆盖 Handler 的内置 Tool 由框架自动补齐(补的是一条 `handler: {builtin: x}` 条目,随后与手写的同类条目一起统一展开)。
|
|
791
|
+
- `mocks.tools.<name>.handler` 写成 `{builtin: skill}` / `{builtin: bash}` 时,`<name>` 必须对应 `context.tools` 中声明的 Tool,且该 Tool 的 `parameters` 必须把内置 Handler 需要的参数(skill: `name`;bash: `command`)声明为 required 属性;`{builtin: ...}` 旁不允许其他字段(`with` 配置全部由框架派生)。这些校验都发生在 collection 阶段(`resolve_builtin_handlers`)。
|
|
712
792
|
- 同一 Case 不允许重复 Tool name,不允许后一个 Tool 静默覆盖前一个。
|
|
713
793
|
- `name`、`description`、`parameters` 都是必填项。
|
|
714
794
|
- `parameters` 使用 JSON Schema 语义编写,但**加载器实际只校验一条规则**:
|
|
@@ -1043,7 +1123,7 @@ Judge 使用的模型写在 `steps[].assert.judge.model` 或全局 Judge 配置
|
|
|
1043
1123
|
| `system_prompt` | 使用 Plugin 默认 System Prompt,或显式指定覆盖文件。 |
|
|
1044
1124
|
| `skills` | 按声明顺序暴露的 Skill metadata;正文只能通过 `skill` Tool 读取。 |
|
|
1045
1125
|
| `messages` | Step 开始前已经存在的 History Message。 |
|
|
1046
|
-
| `tools` | 发送给模型的内置 Tool 或 Tool Schema;`skills` 非空时必须包含 `{builtin: skill}
|
|
1126
|
+
| `tools` | 发送给模型的内置 Tool 或 Tool Schema;`skills` 非空时必须包含 `{builtin: skill}`(或一个 Mock 使用 `handler: {builtin: skill}` 的自定义 Tool,见 6.4 节)。 |
|
|
1047
1127
|
| `builders` | 在 Case 开始前的三个位置(`after_system`/`before_history`/`after_history`)插入额外 Message(Schema 不做 collection 期校验,见 7.3 节)。Step 级/Tool Call 级的插入见 `steps[].message_inject`(8.6 节、7.6 节)。 |
|
|
1048
1128
|
|
|
1049
1129
|
```yaml
|
|
@@ -1102,13 +1182,16 @@ mocks:
|
|
|
1102
1182
|
|
|
1103
1183
|
`state` 是本次 run 内所有 Python Handler 共享的可变初始状态;每次 `repeat` 都从其深拷贝开始(`MockToolRegistry.__init__` 里对 `mocks.state` 做 `_json_clone`),不能跨 run 泄漏。未声明工具与无法匹配的参数始终是硬失败,无需配置。Mock 只负责回答"工具被调用时返回什么";"工具必须(或不能)被调用"属于断言职责,用 Step 的 `assert.hard` 中的 `tool_called` / `tool_not_called` 表达。
|
|
1104
1184
|
|
|
1105
|
-
`mocks` 顶层只允许 `state`/`tools` 两个 key(`cli`/`fs` 会在
|
|
1106
|
-
里被 `pop` 出来做 schema
|
|
1107
|
-
`MockToolRegistry`
|
|
1185
|
+
`mocks` 顶层只允许 `state`/`tools` 两个 key(`cli`/`fs` 会在
|
|
1186
|
+
`resolve_builtin_handlers` 里被 `pop` 出来做 schema 校验,并合并进每一条
|
|
1187
|
+
`handler: {builtin: bash}` Mock 的 handler 配置,不是 `MockToolRegistry`
|
|
1188
|
+
直接认识的字段)。`mocks.tools.<name>.handler` 除了 `python` 引用外还可以写
|
|
1189
|
+
`{builtin: skill|bash}`——它在 collection 阶段就地展开成对应的内置 Python
|
|
1190
|
+
Handler(9.3 节),`MockToolRegistry` 看到的永远是展开后的 `python` 形态。
|
|
1108
1191
|
|
|
1109
1192
|
#### 8.4.1 `mocks.cli`:builtin bash Tool 的命令级 Mock
|
|
1110
1193
|
|
|
1111
|
-
当
|
|
1194
|
+
当 Case 里存在由内置 bash 实现驱动的 Tool——`context.tools` 声明了 `{builtin: bash}`,或某个自定义 Tool 的 Mock 使用 `handler: {builtin: bash}`——时,可以在 `mocks.cli` 中按命令名声明 Mock,而不必为每个 Case 编写 Python Handler:
|
|
1112
1195
|
|
|
1113
1196
|
```yaml
|
|
1114
1197
|
context:
|
|
@@ -1239,7 +1322,7 @@ Runner 收到 bash Tool Call 后,把整条 `command` 字符串原样交给持
|
|
|
1239
1322
|
- 命令未在 `mocks.cli` 中声明、不是 bash 内建命令、且未开启透传(见下)时,得到真实 bash 自己的 `command not found`(`bash: line 2: <name>: command not found\n`,exit code 127;见前述"行号固定为 2"的说明)。
|
|
1240
1323
|
- Handler 返回值统一为 `{stdout, stderr, exit_code}`,由 8.4.3 节的 marker 协议从持久 shell 的真实 stdout/stderr 中截取;这份完整信封保留在 Mock Event 与 `tool_calls[].result` 中供断言使用。但 Runner 发给模型的 Tool Result Message 只取其中的 `stdout + stderr`(`runner.py:_tool_result_content`,不加分隔符地原样拼接,不再是三个字段的 JSON),贴近真实终端工具"给什么就是什么"的观感;`exit_code` 不出现在模型看到的内容里,模型只能通过输出文本本身判断命令是否成功。这个"bash 形状结果特判"逻辑位于 `runner.py`,而非 `mocks.py`。
|
|
1241
1324
|
|
|
1242
|
-
`mocks.cli`
|
|
1325
|
+
`mocks.cli` 只服务于内置 bash 执行实现:Case 里没有任何 `handler: {builtin: bash}` Mock(既没声明 `{builtin: bash}`,也没有自定义 Tool 指向 builtin handler)时出现 `mocks.cli` 在 collection 阶段失败(`"mocks.cli requires a builtin bash handler: ..."`);声明了 `{builtin: bash}` 却用自定义 `mocks.tools.bash` Handler 覆盖其 Mock 时同样失败(`"mocks.cli cannot be combined with a custom mocks.tools.bash handler"`);与 `mocks.fs` 同时出现同样失败(8.4.3 节)。多个 Tool 的 Mock 都指向 `handler: {builtin: bash}` 时共享同一份 `mocks.cli`/`mocks.fs` 执行配置与同一个沙箱会话。
|
|
1243
1326
|
|
|
1244
1327
|
#### 8.4.2 透传:找不到 Mock 时执行真实命令
|
|
1245
1328
|
|
|
@@ -1277,7 +1360,7 @@ mocks:
|
|
|
1277
1360
|
|
|
1278
1361
|
`mocks.cli` 与 `mocks.fs` 底层是**同一套执行引擎**(`yama/tools/bash/fs.py` 的持久 shell 会话):区别只在于沙箱工作目录里预先放了什么——`mocks.fs.files`/`mocks.fs.bin` 是 Case 作者直接声明的内容,`mocks.cli` 是框架把声明式规则树编译成的 `.mockbin/` 脚本(8.4.1 节)。两者因此共享本节描述的生命周期、marker 协议、PATH shadow 机制、rlimit/环境变量护栏;差别仅是 `mocks.cli` 固定用 `backend: none`(不叠加 macOS Seatbelt),而 `mocks.fs` 默认 `backend: auto`。会话环境变量里始终有 `YAMA_WORKSPACE`(沙箱工作目录绝对路径)、`YAMA_PYTHON`(运行 yama 的解释器路径)、`YAMA_REAL_PATH`(未叠加 `.mockbin/` 的真实系统 PATH,供节点/规则级 `passthrough: true` 或用户自己的 `mocks.fs.bin` 脚本按需 `exec` 真实二进制)。
|
|
1279
1362
|
|
|
1280
|
-
`mocks.fs` 与 `mocks.cli` **互斥**:一个 Case 要么用 `mocks.cli` 换取完全确定性回放,要么用 `mocks.fs` 换取真实执行能力,二者同时声明在 collection 阶段报错(`"mocks.cli cannot be combined with mocks.fs"`);同样,`mocks.fs` 只在 `
|
|
1363
|
+
`mocks.fs` 与 `mocks.cli` **互斥**:一个 Case 要么用 `mocks.cli` 换取完全确定性回放,要么用 `mocks.fs` 换取真实执行能力,二者同时声明在 collection 阶段报错(`"mocks.cli cannot be combined with mocks.fs"`);同样,`mocks.fs` 只在 Case 里存在 `handler: {builtin: bash}` Mock(`{builtin: bash}` 声明或自定义 Tool 指向 builtin handler)时生效,缺失时报错。声明了 `{builtin: bash}` 却用自定义 `mocks.tools.bash` Handler 覆盖其 Mock 时同样报错(`"mocks.fs cannot be combined with a custom mocks.tools.bash handler"`)。
|
|
1281
1364
|
|
|
1282
1365
|
**配置 Schema:**
|
|
1283
1366
|
|
|
@@ -1355,7 +1438,8 @@ printf '%s %d\n' '<marker>' "$__yama_ec__" 1>&2
|
|
|
1355
1438
|
`readline`,以兼容不以换行结尾的命令输出,例如 `printf` / `echo -n`)直到两个流各自
|
|
1356
1439
|
读到 marker 为止,marker 之前的内容就是这次调用的 `stdout`/`stderr`。单条命令超时
|
|
1357
1440
|
(默认 30 秒,`mocks.fs.limits.timeout_seconds` 与 `mocks.cli.passthrough_timeout_seconds`
|
|
1358
|
-
两处默认值都是 30.0
|
|
1441
|
+
两处默认值都是 30.0;模型通过 bash Tool 的 `timeout_seconds` 参数请求的更短超时会生效,
|
|
1442
|
+
超过配置上限的请求被钳到上限,见 `fs.py:_effective_timeout`)会 `os.killpg` 杀掉整个进程组并重新起一个 shell(cwd 重置为
|
|
1359
1443
|
初始值),返回 `ToolMockError("BASH_TIMEOUT", "sandboxed command timed out after
|
|
1360
1444
|
{timeout}s")`;若管道意外断开(`BrokenPipeError`/`ConnectionResetError`)则返回
|
|
1361
1445
|
`BASH_SESSION_DIED` 错误,同样会在下次调用时重新起一个会话。因为是真实 shell,
|
|
@@ -1408,11 +1492,12 @@ OS-level isolation"`),要求显式改成 `backend: none`——这是为了
|
|
|
1408
1492
|
#### 8.4.4 `tools/bash/` 子系统内部关系
|
|
1409
1493
|
|
|
1410
1494
|
```text
|
|
1411
|
-
context.tools: [{builtin: bash}]
|
|
1495
|
+
context.tools: [{builtin: bash}] # 或自定义 Tool + handler: {builtin: bash}
|
|
1412
1496
|
│
|
|
1413
1497
|
▼
|
|
1414
|
-
loaders.tool_loader.
|
|
1415
|
-
│
|
|
1498
|
+
loaders.tool_loader.resolve_builtin_handlers # 校验+归一化 mocks.cli / mocks.fs,二选一
|
|
1499
|
+
│ 把每条 handler: {builtin: bash} 展开为
|
|
1500
|
+
│ handler.python = "yama.tools.bash.bash:run_bash"
|
|
1416
1501
|
▼
|
|
1417
1502
|
tools/bash/bash.py: run_bash(arguments, context, config)
|
|
1418
1503
|
│
|
|
@@ -1818,6 +1903,8 @@ respond:
|
|
|
1818
1903
|
|
|
1819
1904
|
`respond` 与 `handler` 互斥。同一个 Tool Mock 必须且只能使用其中一种执行方式;`match` 对二者采用相同语义。
|
|
1820
1905
|
|
|
1906
|
+
`handler` 有两种形态:`{python: ..., with: ...}` 指向 Case 自己的 Python Handler(9.4 节);`{builtin: skill}` / `{builtin: bash}` 复用框架内置实现——它在 collection 阶段(`loaders/tool_loader.py:resolve_builtin_handlers`)就地展开成对应的 `python` 形态并派生 `with` 配置(skill: `enabled`/`skills_dir`/`skill_entry`;bash: 归一化后的 `mocks.cli` 或 `mocks.fs`),因此 `MockToolRegistry` 与 Mock Event 里看到的始终是 `python` Handler。`{builtin: ...}` 不接受其他字段;对应 Tool 的 Schema 必须把内置实现需要的参数(skill: `name`;bash: `command`)声明为 required 属性。
|
|
1907
|
+
|
|
1821
1908
|
`sequence` 必须是非空列表,按调用次数从第一条开始依次消费(`sequence_indexes`
|
|
1822
1909
|
按 tool 名字独立计数)。**序列被消费完之后如果还有下一次调用,是一次硬失败**:
|
|
1823
1910
|
`MockInvocationError("mock response sequence exhausted: <name>")`,未捕获,导致
|
|
@@ -2077,7 +2164,7 @@ execution:
|
|
|
2077
2164
|
|
|
2078
2165
|
原设计文档设想了独立的 `Transcript`/`Usage` 类;**实际代码库中不存在这两个类**。
|
|
2079
2166
|
对应概念分散在 `runner.py` 的 `RunResult` 与 `models.py` 的 `StepResult`/
|
|
2080
|
-
`ToolCallRecord`
|
|
2167
|
+
`ToolCallRecord` 里:
|
|
2081
2168
|
|
|
2082
2169
|
```python
|
|
2083
2170
|
# runner.py
|
|
@@ -2093,6 +2180,8 @@ class RunResult:
|
|
|
2093
2180
|
requests: list[dict[str, Any]] = field(default_factory=list)
|
|
2094
2181
|
artifact_dir: Path | None = None
|
|
2095
2182
|
|
|
2183
|
+
def usage(self) -> dict[str, int] | None: ... # 见下方 token 用量说明
|
|
2184
|
+
|
|
2096
2185
|
@dataclass
|
|
2097
2186
|
class CaseResult:
|
|
2098
2187
|
case_key: str
|
|
@@ -2100,8 +2189,28 @@ class CaseResult:
|
|
|
2100
2189
|
runs: list[RunResult]
|
|
2101
2190
|
pass_rate: float
|
|
2102
2191
|
description: str = "" # Case 顶层 description 的透传,供 CLI/JSON 输出展示
|
|
2192
|
+
|
|
2193
|
+
def usage(self) -> dict[str, int] | None: ... # 各 run usage() 之和
|
|
2103
2194
|
```
|
|
2104
2195
|
|
|
2196
|
+
**Token 用量统计**没有独立的 `Usage` 类,而是一条贯穿各层的普通字典字段
|
|
2197
|
+
(`{"prompt_tokens", "completion_tokens", "total_tokens"}`,值均为 int):
|
|
2198
|
+
|
|
2199
|
+
- **采集**:`llm.py:_normalized_usage` 把 Provider 返回的 usage 负载规范化成上述
|
|
2200
|
+
三个计数器(丢弃 `prompt_tokens_details` 等 Provider 特有的明细块;缺
|
|
2201
|
+
`total_tokens` 时用 prompt+completion 补齐;三个计数器都缺时得到 `None`),挂在
|
|
2202
|
+
`LLMResponse.usage`。`ScriptedLLMClient` 的脚本响应可带可选的 `usage` 键,走同一
|
|
2203
|
+
个规范化(用于测试与回放)。
|
|
2204
|
+
- **记录**:tool-loop 的每次请求把非空 usage 写进对应请求记录
|
|
2205
|
+
(`requests[].usage`,见 `runner.py:_run_step`);Judge 调用不经过 `requests`
|
|
2206
|
+
记录,`assertions.py:run_judge` 把它的 usage 补在返回的 `judge_result["usage"]`
|
|
2207
|
+
上(Provider 未报用量时两处都没有该键)。
|
|
2208
|
+
- **聚合**:`runner.py:combine_usage` 对多个 usage 字典逐键求和,全部无数据时返回
|
|
2209
|
+
`None`(「没有数据」与「0 token」必须可区分——脚本回放或中途死掉的 run 不应显示
|
|
2210
|
+
成 0)。`RunResult.usage()` = 该 run 全部 `requests[].usage` + 各 Step
|
|
2211
|
+
`judge_result["usage"]` 之和;`CaseResult.usage()` = 各 run 之和。两者的
|
|
2212
|
+
`to_dict()` 都带 `usage` 字段,因此 `result.json` 与 `--json` 输出天然携带。
|
|
2213
|
+
|
|
2105
2214
|
```python
|
|
2106
2215
|
# models.py
|
|
2107
2216
|
@dataclass
|
|
@@ -2139,14 +2248,14 @@ class ToolCallRecord:
|
|
|
2139
2248
|
├── fixtures/
|
|
2140
2249
|
│ └── <sha256前12位>-<原始文件名> # 用到的 fixture 文件本身的拷贝
|
|
2141
2250
|
├── requests/
|
|
2142
|
-
│ ├── request-001.json # run 内全局递增编号,不按 Step
|
|
2251
|
+
│ ├── request-001.json # run 内全局递增编号,不按 Step 分段;Provider 报了用量时带 usage
|
|
2143
2252
|
│ └── request-002.json
|
|
2144
2253
|
├── transcript.json # [StepResult.to_dict(), ...]
|
|
2145
2254
|
├── mock-events.json
|
|
2146
2255
|
├── mock-state.json
|
|
2147
2256
|
├── hard-checks.json # {step_id: hard_checks}
|
|
2148
|
-
├── judge-result.json # {step_id: judge_result}(只含有 Judge 结果的 Step)
|
|
2149
|
-
└── result.json # RunResult.to_dict()
|
|
2257
|
+
├── judge-result.json # {step_id: judge_result}(只含有 Judge 结果的 Step;含 Judge 调用的 usage)
|
|
2258
|
+
└── result.json # RunResult.to_dict()(含 run 级 usage 汇总)+ generated_at + traceback?
|
|
2150
2259
|
```
|
|
2151
2260
|
|
|
2152
2261
|
写产物前,`YamaRunner.run_case` 会先整体删除该 Case 的产物目录
|
|
@@ -2316,7 +2425,9 @@ judge:
|
|
|
2316
2425
|
| `dimensions[].min_score` | 否 | 该维度 `1..5` 的最低原始分;省略时默认 `1`(不设下限)。 |
|
|
2317
2426
|
|
|
2318
2427
|
Judge 实际返回的结构化结果(`run_judge` 在 Judge LLM 的原始输出上原地补充
|
|
2319
|
-
`overall`/`passed`
|
|
2428
|
+
`overall`/`passed` 两个字段后整体返回;Judge Provider 报了 token 用量时再补一个
|
|
2429
|
+
`usage`——Judge 调用不进 run 的 `requests` 记录,其用量靠这个字段进入 run 级
|
|
2430
|
+
聚合,见第 11 节):
|
|
2320
2431
|
|
|
2321
2432
|
```json
|
|
2322
2433
|
{
|
|
@@ -2329,7 +2440,8 @@ Judge 实际返回的结构化结果(`run_judge` 在 Judge LLM 的原始输出
|
|
|
2329
2440
|
}
|
|
2330
2441
|
],
|
|
2331
2442
|
"overall": 0.82,
|
|
2332
|
-
"passed": true
|
|
2443
|
+
"passed": true,
|
|
2444
|
+
"usage": {"prompt_tokens": 800, "completion_tokens": 120, "total_tokens": 920}
|
|
2333
2445
|
}
|
|
2334
2446
|
```
|
|
2335
2447
|
|
|
@@ -2362,12 +2474,14 @@ outcome:
|
|
|
2362
2474
|
"case_key": "__evals__/cases/image-led-mv.yaml",
|
|
2363
2475
|
"passed": true,
|
|
2364
2476
|
"pass_rate": 1.0,
|
|
2477
|
+
"usage": { "prompt_tokens": 2000, "completion_tokens": 460, "total_tokens": 2460 },
|
|
2365
2478
|
"runs": [
|
|
2366
2479
|
{
|
|
2367
2480
|
"run_index": 1,
|
|
2368
2481
|
"passed": true,
|
|
2369
2482
|
"steps": [ { "step_id": "...", "hard_pass": true, "judge_result": { "...": "..." } } ],
|
|
2370
2483
|
"error": null,
|
|
2484
|
+
"usage": { "prompt_tokens": 2000, "completion_tokens": 460, "total_tokens": 2460 },
|
|
2371
2485
|
"mock_events": [ "..." ],
|
|
2372
2486
|
"mock_state": { "...": "..." },
|
|
2373
2487
|
"requests": [ "..." ],
|
|
@@ -2377,6 +2491,8 @@ outcome:
|
|
|
2377
2491
|
}
|
|
2378
2492
|
```
|
|
2379
2493
|
|
|
2494
|
+
(Case/run 级的 `usage` 是第 11 节所述的聚合结果;无任何用量数据时为 `null`。)
|
|
2495
|
+
|
|
2380
2496
|
质量分不能抵消硬检查失败:`_case_passed` 先判空 `all(step.hard_pass for step in
|
|
2381
2497
|
steps)`,任一为 `False` 就直接返回 `False`,Judge 相关逻辑不会再被求值。
|
|
2382
2498
|
|
|
@@ -2411,7 +2527,11 @@ run-id 目录树;每个 Case 各自落在自己 Plugin 的 `.yama/runs` 里。
|
|
|
2411
2527
|
|
|
2412
2528
|
报告的实际形态(`report.py:write_html_report`)是**一个单独的、自包含的 HTML
|
|
2413
2529
|
文件**(内联 CSS,不依赖外部资源),汇总本次 CLI 调用涉及的**全部** Case/Run/
|
|
2414
|
-
Step——不是按 Plugin 拆开的多个文件,也没有 JSON 版的 `summary.json
|
|
2530
|
+
Step——不是按 Plugin 拆开的多个文件,也没有 JSON 版的 `summary.json`。LLM token
|
|
2531
|
+
用量(第 11 节的聚合链)在报告的每一层都有展示:顶部摘要多一张「LLM tokens」
|
|
2532
|
+
卡片(总量 + in/out 拆分),Case 头部 metadata 多一格逐 Case 汇总,Run/Step 的
|
|
2533
|
+
summary 行、执行时间线里的每次 assistant 响应、LLM requests 诊断列表和 Judge
|
|
2534
|
+
小节各自带本层级的 token 数;没有用量数据的层级显示 `–` 或不显示:
|
|
2415
2535
|
|
|
2416
2536
|
```text
|
|
2417
2537
|
<result_root 的上级>/reports/latest.html # --report 省略路径时的默认位置
|
|
@@ -2433,13 +2553,19 @@ Step——不是按 Plugin 拆开的多个文件,也没有 JSON 版的 `summar
|
|
|
2433
2553
|
├── Expected ...
|
|
2434
2554
|
├── Actual ...
|
|
2435
2555
|
└── Reason ...
|
|
2436
|
-
✓ <case_key> 2/2 runs passed 100%
|
|
2556
|
+
✓ <case_key> 2/2 runs passed 100% tokens 2,460
|
|
2437
2557
|
|
|
2438
2558
|
Yama Eval Results
|
|
2439
|
-
Result | Case(含 description 副行) | Runs | Pass rate
|
|
2559
|
+
Result | Case(含 description 副行) | Runs | Pass rate | Tokens
|
|
2440
2560
|
...
|
|
2561
|
+
<caption:m/n cases passed • j/k runs passed • tokens 2,460 (in 2,000 / out 460)>
|
|
2441
2562
|
```
|
|
2442
2563
|
|
|
2564
|
+
`tokens ...` 片段与表格 `Tokens` 列来自 `CaseResult.usage()`/`RunResult.usage()`
|
|
2565
|
+
(case 完成行与表格 caption 里是总量,caption 另带 in/out 拆分;明细树里 Case 行
|
|
2566
|
+
带拆分、Run 行只带总量);聚合为 `None`(Provider 没报用量)时不打印该片段,
|
|
2567
|
+
表格单元格显示 `–`,caption 也不带 tokens 段。
|
|
2568
|
+
|
|
2443
2569
|
**并发模式**(并发 >1 且收集到多个 Case,默认即是):不同 Case 的 Step 结果会
|
|
2444
2570
|
乱序到达,逐 Step 流式打印会把不相关 Case 的行交错在错误的 Case 标题下,因此改为
|
|
2445
2571
|
在终端底部维护一张**原地刷新的逐 Case 状态面板**(transient `rich Live`):每个
|
|
@@ -2452,14 +2578,14 @@ Yama Eval Results
|
|
|
2452
2578
|
|
|
2453
2579
|
```text
|
|
2454
2580
|
(面板上方,按完成顺序逐块追加)
|
|
2455
|
-
✓ <case_key B> 100%
|
|
2456
|
-
├── ✓ Run 1
|
|
2581
|
+
✓ <case_key B> 100% tokens 2,460 (in 2,000 / out 460)
|
|
2582
|
+
├── ✓ Run 1 tokens 2,460
|
|
2457
2583
|
│ └── ✓ <step_id> hard checks 3/3
|
|
2458
2584
|
...
|
|
2459
2585
|
|
|
2460
2586
|
(终端底部的临时面板,逐行原地刷新)
|
|
2461
2587
|
⠧ <case_key A> Run 1/2 · <step_id>
|
|
2462
|
-
✓ <case_key B> 1/1 runs 100%
|
|
2588
|
+
✓ <case_key B> 1/1 runs 100% tokens 2,460
|
|
2463
2589
|
· <case_key C> waiting
|
|
2464
2590
|
```
|
|
2465
2591
|
|
|
@@ -2539,7 +2665,7 @@ Case。
|
|
|
2539
2665
|
| --- | --- | --- | --- |
|
|
2540
2666
|
| 1 | `runner.py:17` | 直接 `from .tools.bash.fs import cleanup_session` 做 run 结束清理,runner 因此耦合了"哪个具体 builtin 工具持有需要清理的会话资源"这一细节;以后再加一个有生命周期的 builtin 工具就得继续在 runner 里加 import。 | 给 `MockToolRegistry` 加通用 `aclose()`/cleanup 钩子,由各 handler 通过 `context.state` 登记自己的清理回调,runner 只调用 `registry.aclose()`。 |
|
|
2541
2667
|
| 2 | `mocks.py` `_matches` | 下划线前缀(约定上是模块私有),但 `tools/bash/_cli_shim.py` 和 `runner.py`(`steps[].message_inject` 的 `after_tool_call.match.arguments`,见 7.6 节)都直接 `from ...mocks import _matches` / `from .mocks import _matches` 跨模块使用;`tests/test_framework.py` 也直接伸手拿 `tools.bash.fs._SESSIONS`。这个私有符号事实上已经是稳定的跨模块契约,现在多了第三个调用方。 | 去掉下划线正式导出(如 `match_value`),或挪到一个中立的共享模块,避免"私有符号被当公共 API 用"的坏味道。 |
|
|
2542
|
-
| 3 |
|
|
2668
|
+
| 3 | ~~`loaders/tool_loader.py` `_resolve_builtin_bash_tool` / `_resolve_builtin_skill_tool`~~ | ~~"模型看到什么 Schema"和"这个 Schema 怎么被执行"两个关注点被揉进同一个函数。~~ **已解决**(2026-07-18):拆成了 `load_tool`(纯 Schema 构造,不再触碰 `mocks`)+ `resolve_builtin_handlers`(统一展开 `handler: {builtin: ...}` Mock,docstring 标注了会 mutate `mocks`),并顺带把"builtin 执行"开放给自定义 Schema 的 Tool。 | — |
|
|
2543
2669
|
| 4 | `tools/base.py` `Tool` | 目前只是一个人工遵守的命名约定:`mocks.py` 的 Handler 加载机制(`load_python_callable` + `getattr`)完全不知道 `Tool` 的存在,也不会检查某个 handler 是否实现了它——新增一个 builtin 工具时,即使忘了继承 `Tool` 或忘了导出 `xxx = XxxTool().run` 别名,框架不会报错,只会在运行时因为 `handler.python` 指向的名字不存在而失败。 | 可以接受(这是刻意的轻量选择,避免给 `mocks.py` 引入对 `tools/` 的反向依赖);如果以后 builtin 工具变多,可以加一个简单的单测遍历 `tools/` 下的 Handler,断言它们都是 `Tool` 子类的绑定方法。 |
|
|
2544
2670
|
| 5 | `assertions.py` 与 `mocks.py` 各自实现一份 `_matches`/`_match` | 两个匹配器函数几乎同构(`equals`/`contains`/`matches`/`is_instance`/`exists`),但 `mocks.py` 多支持一个 `one_of` 操作符、且支持隐式嵌套 dict 递归匹配,`assertions.py` 没有。两处独立演化,容易在未来出现语义漂移(例如只在一处修 bug)。 | 抽成一个共享的匹配器模块(如 `matchers.py`),两处都从这里导入;若确有意图让 `mocks` 和 `assert` 的匹配能力不同,至少在两处的文档字符串里互相标注差异。 |
|
|
2545
2671
|
| 6 | `loaders/case.py` 与 `llm.py` 各自实现一份 fixture delivery 别名归一化(`metadata→file_path_inline`/`content→file_content`) | 同一份映射表在两个文件里各写了一次;`loaders/case.py` 那份决定 collection 期是否报错,`llm.py` 那份决定运行期实际转换行为。 | 抽成一个共享的小函数/常量,两处 import 同一份,避免未来只改了一处。 |
|
|
@@ -2560,9 +2686,9 @@ Case。
|
|
|
2560
2686
|
| `case.py` | `loaders/case.py`(`resolve_case`,一致) |
|
|
2561
2687
|
| `system_loader.py` / `skill_loader.py` / `templates.py` / `fixtures.py` | 仍合并在 `loaders/case.py`(`_load_skill`/`_render_system_prompt`/`_resolve_message_parts`),未按文档拆成独立文件——且"模板"实际是硬编码字符串拼接,并非独立可配置的模板层(见第 6 节) |
|
|
2562
2688
|
| `context.py` / `builders.py` | Case scope 部分在 `runner.py`(`_run_builders`),Schema 校验完全没有实现(见 7.3 节);Step scope 部分(原设计未预见,用户驱动新增)落在 `loaders/case.py`(`_resolve_message_inject`,collection 期严格校验)+ `runner.py`(`_run_step` 内的四个触发点),见 7.6 节 |
|
|
2563
|
-
| `tools.py`("加载 Tool Schema") | `loaders/tool_loader.py`(`load_tool` 及 `
|
|
2689
|
+
| `tools.py`("加载 Tool Schema") | `loaders/tool_loader.py`(`load_tool` 及 `resolve_builtin_handlers`)——现在是独立文件 |
|
|
2564
2690
|
| `mocks.py` | `mocks.py`(一致,`ToolMockContext` 也定义在这里) |
|
|
2565
|
-
| `transcript.py` | 并入 `models.py`(`StepResult`/`ToolCallRecord`)+ `runner.py`(`RunResult`/`CaseResult`);独立的 `Transcript`/`Usage`
|
|
2691
|
+
| `transcript.py` | 并入 `models.py`(`StepResult`/`ToolCallRecord`)+ `runner.py`(`RunResult`/`CaseResult`);独立的 `Transcript`/`Usage` 类未实现(token 用量统计存在,但以普通字典字段贯穿各层,见第 11 节) |
|
|
2566
2692
|
| `judge.py` | 并入 `assertions.py`(`run_judge`) |
|
|
2567
2693
|
| `pytest_plugin.py` | **未实现**(目前只有 `cli.py` 一种入口,见第 16 节) |
|
|
2568
2694
|
| (无对应章节) | `tools/base.py`(`Tool` 抽象接口)、`tools/bash/bash.py`、`tools/bash/fs.py`、`tools/bash/_cli_shim.py`、`tools/skill/skill.py`:mocks.tools.bash/skill 的默认 Handler 实现,设计文档只在协议层描述了行为,没有规划对应的代码文件或"Tool 公共接口"这一层。 |
|
|
@@ -2613,6 +2739,8 @@ Case。
|
|
|
2613
2739
|
- 纯文本与多模态 Message Part、fixture manifest。
|
|
2614
2740
|
- 9 种硬检查、多维 LLM Judge、`execution.repeat` 稳定通过率统计。
|
|
2615
2741
|
- JSON 产物(逐 Case/逐 run)与单文件 HTML 汇总报告。
|
|
2742
|
+
- LLM token 用量统计:逐请求采集、run/Case 级聚合、CLI 与 HTML 报告展示
|
|
2743
|
+
(见第 11 节与第 13 节)。
|
|
2616
2744
|
|
|
2617
2745
|
## 17. 最终边界
|
|
2618
2746
|
|
|
@@ -81,14 +81,16 @@ outcome:
|
|
|
81
81
|
|
|
82
82
|
1. **`context.tools` 与 `mocks.tools` 的 Tool 名字集合必须完全相等**(双向,不是单向包含)。
|
|
83
83
|
builtin Tool 未自定义 Mock 时由框架自动补齐。
|
|
84
|
-
2. **`context.skills` 非空时,`context.tools` 必须包含 `{builtin: skill}
|
|
85
|
-
|
|
84
|
+
2. **`context.skills` 非空时,`context.tools` 必须包含 `{builtin: skill}`**(或一个自定义
|
|
85
|
+
Schema 的 Tool,其 Mock 使用 `handler: {builtin: skill}`);Skill 正文只能由模型通过
|
|
86
|
+
Skill 读取 Tool 获得,`<available_skills>` 只含 name/description。
|
|
86
87
|
3. Skill 的 frontmatter `name` 必须与 Case 请求的名字一致;同一 Case 不允许重复
|
|
87
88
|
Skill 名或 Tool 名。
|
|
88
89
|
4. 每个 Tool 条目在 `builtin` / `file` / `inline` 中三选一;`mocks.tools.<name>` 的
|
|
89
90
|
`respond` 与 `handler` 二选一。
|
|
90
|
-
5. `mocks.cli` 与 `mocks.fs` 互斥,且都要求
|
|
91
|
-
|
|
91
|
+
5. `mocks.cli` 与 `mocks.fs` 互斥,且都要求 Case 里存在内置 bash 执行——声明
|
|
92
|
+
`{builtin: bash}`,或某个 Tool 的 Mock 使用 `handler: {builtin: bash}`;
|
|
93
|
+
也不能与自定义 `mocks.tools.bash` Handler 并存。
|
|
92
94
|
6. `steps` 至少一个,每个 Step 必须有 Case 内唯一的 `id` 和 `user`。
|
|
93
95
|
|
|
94
96
|
### 容易写错的语义
|
|
@@ -135,6 +137,11 @@ yama --plugin <name> --report
|
|
|
135
137
|
# 只跑一个 Case;只列出会收集到哪些 Case
|
|
136
138
|
yama __evals__/cases/foo.yaml
|
|
137
139
|
yama --list
|
|
140
|
+
|
|
141
|
+
# 按 case key(相对 Plugin Root 的路径)筛选要跑的 Case:
|
|
142
|
+
# 默认子串匹配,含 * ? [ 时按 fnmatch 通配符匹配;-k 可重复,命中任意一个即运行
|
|
143
|
+
yama -k smoke
|
|
144
|
+
yama -k "__evals__/cases/smoke/*.yaml" -k regress
|
|
138
145
|
```
|
|
139
146
|
|
|
140
147
|
多个 Case 默认并行执行(最多同时 10 个,`--concurrency N` 调整;Case 内的多个
|