niceeval 0.4.3 → 0.4.5
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.
- package/README.md +21 -12
- package/README.zh.md +8 -9
- package/docs-site/.mintignore +13 -0
- package/docs-site/AGENTS.md +46 -0
- package/docs-site/concepts/adapter.mdx +287 -0
- package/docs-site/concepts/assert.mdx +243 -0
- package/docs-site/concepts/drive.mdx +118 -0
- package/docs-site/concepts/evals.mdx +108 -0
- package/docs-site/concepts/experiment.mdx +37 -0
- package/docs-site/concepts/hitl.mdx +83 -0
- package/docs-site/concepts/judge.mdx +129 -0
- package/docs-site/concepts/overview.mdx +98 -0
- package/docs-site/concepts/tier.mdx +42 -0
- package/docs-site/docs-ref/00-index.md +23 -0
- package/docs-site/docs-ref/01-page-types.md +43 -0
- package/docs-site/docs-ref/03-style-rules.md +45 -0
- package/docs-site/docs-ref/04-code-examples.md +37 -0
- package/docs-site/docs-ref/05-dx-failure-paths.md +45 -0
- package/docs-site/docs-ref/06-checklists.md +53 -0
- package/docs-site/docs.json +256 -0
- package/docs-site/example/ai-agent-application.mdx +148 -0
- package/docs-site/example/claude-code-codex-plugin.mdx +162 -0
- package/docs-site/example/claude-code-codex-skill.mdx +147 -0
- package/docs-site/example/showcase.mdx +39 -0
- package/docs-site/example/tier1-ai-sdk-v7.mdx +136 -0
- package/docs-site/example/tier1-claude-sdk.mdx +119 -0
- package/docs-site/example/tier1-codex-sdk.mdx +111 -0
- package/docs-site/example/tier1-langgraph.mdx +119 -0
- package/docs-site/example/tier1-pi-sdk.mdx +119 -0
- package/docs-site/favicon.svg +5 -0
- package/docs-site/github-diff.css +135 -0
- package/docs-site/github-diff.js +11 -0
- package/docs-site/guides/authoring.mdx +129 -0
- package/docs-site/guides/ci-integration.mdx +97 -0
- package/docs-site/guides/connect-otel.mdx +209 -0
- package/docs-site/guides/connect-your-agent.mdx +221 -0
- package/docs-site/guides/dataset-fanout.mdx +98 -0
- package/docs-site/guides/experiments.mdx +71 -0
- package/docs-site/guides/fixtures.mdx +147 -0
- package/docs-site/guides/reporters.mdx +113 -0
- package/docs-site/guides/runner.mdx +79 -0
- package/docs-site/guides/sandbox-agent.mdx +138 -0
- package/docs-site/guides/sandbox-backends.mdx +64 -0
- package/docs-site/guides/scoring-guide.mdx +92 -0
- package/docs-site/guides/viewing-results.mdx +195 -0
- package/docs-site/guides/write-experiment.mdx +81 -0
- package/docs-site/guides/write-send.mdx +347 -0
- package/docs-site/images/adapter-tiers-zh.svg +60 -0
- package/docs-site/images/agent-turn-roundtrip-en.svg +62 -0
- package/docs-site/images/agent-turn-roundtrip-zh.svg +77 -0
- package/docs-site/images/hitl-handshake-zh.svg +89 -0
- package/docs-site/images/logo.svg +6 -0
- package/docs-site/index.mdx +181 -0
- package/docs-site/introduction.mdx +141 -0
- package/docs-site/quickstart.mdx +136 -0
- package/docs-site/reference/builtin-agents.mdx +161 -0
- package/docs-site/reference/capabilities.mdx +76 -0
- package/docs-site/reference/cli.mdx +120 -0
- package/docs-site/reference/define-agent.mdx +168 -0
- package/docs-site/reference/define-config.mdx +41 -0
- package/docs-site/reference/define-eval.mdx +160 -0
- package/docs-site/reference/events.mdx +131 -0
- package/docs-site/reference/expect.mdx +112 -0
- package/docs-site/tracker.js +8 -0
- package/docs-site/zh/concepts/adapter.mdx +286 -0
- package/docs-site/zh/concepts/assert.mdx +243 -0
- package/docs-site/zh/concepts/drive.mdx +118 -0
- package/docs-site/zh/concepts/evals.mdx +124 -0
- package/docs-site/zh/concepts/experiment.mdx +37 -0
- package/docs-site/zh/concepts/hitl.mdx +83 -0
- package/docs-site/zh/concepts/judge.mdx +130 -0
- package/docs-site/zh/concepts/overview.mdx +109 -0
- package/docs-site/zh/concepts/tier.mdx +44 -0
- package/docs-site/zh/example/ai-agent-application.mdx +152 -0
- package/docs-site/zh/example/claude-code-codex-plugin.mdx +163 -0
- package/docs-site/zh/example/claude-code-codex-skill.mdx +147 -0
- package/docs-site/zh/example/showcase.mdx +39 -0
- package/docs-site/zh/example/tier1-ai-sdk-v7.mdx +140 -0
- package/docs-site/zh/example/tier1-claude-sdk.mdx +122 -0
- package/docs-site/zh/example/tier1-codex-sdk.mdx +117 -0
- package/docs-site/zh/example/tier1-langgraph.mdx +123 -0
- package/docs-site/zh/example/tier1-pi-sdk.mdx +122 -0
- package/docs-site/zh/guides/agent-feedback-loop.mdx +79 -0
- package/docs-site/zh/guides/authoring.mdx +129 -0
- package/docs-site/zh/guides/ci-integration.mdx +97 -0
- package/docs-site/zh/guides/connect-otel.mdx +208 -0
- package/docs-site/zh/guides/connect-your-agent.mdx +226 -0
- package/docs-site/zh/guides/dataset-fanout.mdx +83 -0
- package/docs-site/zh/guides/experiments.mdx +72 -0
- package/docs-site/zh/guides/fixtures.mdx +147 -0
- package/docs-site/zh/guides/official-adapters.mdx +132 -0
- package/docs-site/zh/guides/reporters.mdx +113 -0
- package/docs-site/zh/guides/runner.mdx +82 -0
- package/docs-site/zh/guides/sandbox-agent.mdx +139 -0
- package/docs-site/zh/guides/sandbox-backends.mdx +75 -0
- package/docs-site/zh/guides/scoring-guide.mdx +92 -0
- package/docs-site/zh/guides/viewing-results.mdx +195 -0
- package/docs-site/zh/guides/write-experiment.mdx +101 -0
- package/docs-site/zh/guides/write-send.mdx +353 -0
- package/docs-site/zh/index.mdx +180 -0
- package/docs-site/zh/introduction.mdx +140 -0
- package/docs-site/zh/quickstart.mdx +137 -0
- package/docs-site/zh/reference/builtin-agents.mdx +364 -0
- package/docs-site/zh/reference/capabilities.mdx +76 -0
- package/docs-site/zh/reference/cli.mdx +140 -0
- package/docs-site/zh/reference/define-agent.mdx +461 -0
- package/docs-site/zh/reference/define-config.mdx +107 -0
- package/docs-site/zh/reference/define-eval.mdx +674 -0
- package/docs-site/zh/reference/events.mdx +252 -0
- package/docs-site/zh/reference/expect.mdx +208 -0
- package/package.json +3 -2
- package/src/agents/bub.ts +1 -1
- package/src/agents/claude-code.ts +8 -5
- package/src/agents/codex.ts +9 -5
- package/src/agents/sdk-streams.test.ts +4 -4
- package/src/agents/sdk-streams.ts +14 -9
- package/src/agents/types.ts +40 -1
- package/src/agents/ui-message-stream.ts +1 -0
- package/src/cli.ts +40 -10
- package/src/context/types.ts +140 -0
- package/src/expect/index.ts +15 -8
- package/src/i18n/en.ts +20 -6
- package/src/i18n/zh-CN.ts +20 -6
- package/src/o11y/parsers/bub.test.ts +71 -0
- package/src/o11y/parsers/bub.ts +5 -0
- package/src/o11y/types.ts +27 -2
- package/src/runner/attempt.ts +2 -1
- package/src/runner/reporters/artifacts.ts +11 -3
- package/src/runner/reporters/live.ts +45 -8
- package/src/runner/run.test.ts +50 -0
- package/src/runner/run.ts +135 -41
- package/src/runner/types.ts +55 -2
- package/src/sandbox/types.ts +18 -0
- package/src/scoring/types.ts +5 -0
- package/src/shared/types.ts +3 -0
- package/src/util.test.ts +26 -1
- package/src/util.ts +16 -0
- package/src/view/app/App.tsx +2 -2
- package/src/view/app/components/AttemptModal.tsx +2 -0
- package/src/view/app/components/CopyControls.tsx +87 -28
- package/src/view/app/i18n.ts +3 -3
- package/src/view/client-dist/app.css +1 -1
- package/src/view/client-dist/app.js +18 -18
- package/docs/README.md +0 -120
- package/docs/adapters/README.md +0 -60
- package/docs/adapters/authoring.md +0 -179
- package/docs/adapters/coding-agent-skills-plugins.md +0 -324
- package/docs/adapters/collection.md +0 -128
- package/docs/adapters/contract.md +0 -264
- package/docs/adapters/reference/agent-eval.md +0 -215
- package/docs/adapters/reference/agent-loop-apis.md +0 -69
- package/docs/adapters/reference/claude-code-otel-telemetry.md +0 -100
- package/docs/adapters/reference/eve-protocol.md +0 -127
- package/docs/adapters/reference/otel-genai.md +0 -107
- package/docs/adapters/reference/otel-instrumentation.md +0 -65
- package/docs/adapters/targets.md +0 -99
- package/docs/architecture.md +0 -140
- package/docs/assertions.md +0 -387
- package/docs/capabilities-by-construction.md +0 -48
- package/docs/cli.md +0 -173
- package/docs/concepts.md +0 -106
- package/docs/e2e-ci.md +0 -332
- package/docs/eval-authoring.md +0 -319
- package/docs/experiments.md +0 -157
- package/docs/getting-started.md +0 -224
- package/docs/multi-agent.md +0 -145
- package/docs/observability.md +0 -337
- package/docs/origin-integration.md +0 -195
- package/docs/references.md +0 -35
- package/docs/reports.md +0 -551
- package/docs/results-format.md +0 -228
- package/docs/results-lib.md +0 -191
- package/docs/runner.md +0 -104
- package/docs/sandbox.md +0 -276
- package/docs/scoring.md +0 -119
- package/docs/source-map.md +0 -126
- package/docs/tier-sync.md +0 -193
- package/docs/view.md +0 -194
- package/docs/vision.md +0 -88
|
@@ -0,0 +1,674 @@
|
|
|
1
|
+
---
|
|
2
|
+
title: "defineEval:声明、配置并运行 NiceEval eval"
|
|
3
|
+
sidebarTitle: "defineEval"
|
|
4
|
+
description: "defineEval 参考:选项、test context t、Turn 返回值、sandbox helper 和数据集数组导出。"
|
|
5
|
+
---
|
|
6
|
+
|
|
7
|
+
`defineEval` 是编写 eval 的主要入口。每个 eval 文件调用一次,传入描述和 `test(t)`,并默认导出结果。
|
|
8
|
+
|
|
9
|
+
```ts
|
|
10
|
+
import { defineEval } from "niceeval";
|
|
11
|
+
|
|
12
|
+
export default defineEval({
|
|
13
|
+
description: "Brooklyn weather query",
|
|
14
|
+
async test(t) {
|
|
15
|
+
await t.send("What's the weather like in Brooklyn today?");
|
|
16
|
+
t.succeeded();
|
|
17
|
+
},
|
|
18
|
+
});
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
<Note>
|
|
22
|
+
不要提供 `id` 或 `name`。[NiceEval](https://niceeval.com/) 从文件路径推导 eval ID。
|
|
23
|
+
</Note>
|
|
24
|
+
|
|
25
|
+
## `defineEval` 选项
|
|
26
|
+
|
|
27
|
+
{/* GENERATED:BEGIN defineeval-options */}
|
|
28
|
+
|
|
29
|
+
#### `id`
|
|
30
|
+
|
|
31
|
+
```ts
|
|
32
|
+
id?: string;
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
路径推导,定义里禁止手写。
|
|
36
|
+
|
|
37
|
+
#### `description`
|
|
38
|
+
|
|
39
|
+
```ts
|
|
40
|
+
description?: string;
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
一句话描述,展示在 `niceeval list` 和 view 里;纯说明,不影响调度或打分。
|
|
44
|
+
|
|
45
|
+
#### `tags`
|
|
46
|
+
|
|
47
|
+
```ts
|
|
48
|
+
tags?: string[];
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
标签,供 CLI `--tag` 过滤和 view 分类;与 id 前缀过滤是两套独立的筛选维度。
|
|
52
|
+
|
|
53
|
+
#### `judge`
|
|
54
|
+
|
|
55
|
+
```ts
|
|
56
|
+
judge?: JudgeConfig;
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
覆盖项目级 Config.judge,只对这一个 eval 生效(如换个更贵的评审模型)。
|
|
60
|
+
|
|
61
|
+
#### `reporters`
|
|
62
|
+
|
|
63
|
+
```ts
|
|
64
|
+
reporters?: Reporter[];
|
|
65
|
+
```
|
|
66
|
+
|
|
67
|
+
覆盖 / 追加项目级 Config.reporters,只对这一个 eval 生效。
|
|
68
|
+
|
|
69
|
+
#### `timeoutMs`
|
|
70
|
+
|
|
71
|
+
```ts
|
|
72
|
+
timeoutMs?: number;
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
覆盖项目级 / CLI 的单次 attempt 超时(毫秒),只对这一个 eval 生效。
|
|
76
|
+
|
|
77
|
+
#### `metadata`
|
|
78
|
+
|
|
79
|
+
```ts
|
|
80
|
+
metadata?: Record<string, unknown>;
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
任意附加元数据,原样透传进 EvalResult,不参与调度或打分;供自定义 reporter 消费。
|
|
84
|
+
|
|
85
|
+
#### `setup`
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
setup?: (sandbox: Sandbox) => Promise<void | Cleanup> | void | Cleanup;
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
eval 级预置:拿到沙箱(已上传 workspace + git 基线 + 装好依赖前)。
|
|
92
|
+
默认命令以非 root 跑(agent 的自然环境);装系统依赖时给 `runCommand` 传 `{ root: true }`
|
|
93
|
+
(如 `runCommand("apt-get", ["install", …], { root: true })`),跨后端语义一致。
|
|
94
|
+
|
|
95
|
+
#### `test`
|
|
96
|
+
|
|
97
|
+
```ts
|
|
98
|
+
test(t: TestContext): Promise<void> | void;
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
eval 主体:拿到 TestContext,驱动对话 / 沙箱操作并就地断言。
|
|
102
|
+
|
|
103
|
+
{/* GENERATED:END defineeval-options */}
|
|
104
|
+
|
|
105
|
+
## Test context: `t`
|
|
106
|
+
|
|
107
|
+
`t`(`TestContext`)是 eval 作者拿到的高层上下文。运行器按 agent 的实际能力组装它——`t.sandbox` 这类字段只在 `defineSandboxAgent` 构造的 agent 上才有意义,完整规则见[能力位参考](/zh/reference/capabilities)。全部成员:
|
|
108
|
+
|
|
109
|
+
{/* GENERATED:BEGIN test-context */}
|
|
110
|
+
|
|
111
|
+
#### `send`
|
|
112
|
+
|
|
113
|
+
```ts
|
|
114
|
+
send(text: string): Promise<TurnHandle>;
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
向默认会话发一条消息,返回该轮的 TurnHandle。事件同时累加进默认会话的累计事件流,供下面的作用域断言使用。
|
|
118
|
+
|
|
119
|
+
#### `sendFile`
|
|
120
|
+
|
|
121
|
+
```ts
|
|
122
|
+
sendFile(path: string, text?: string): Promise<TurnHandle>;
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
发一条带文件(图片等多模态输入)的消息。`path` 相对项目根;读出后 base64 随 TurnInput.files 交给 adapter。
|
|
126
|
+
|
|
127
|
+
#### `requireInputRequest`
|
|
128
|
+
|
|
129
|
+
```ts
|
|
130
|
+
requireInputRequest(filter?: InputRequestFilter): InputRequest;
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
取默认会话里等待中的 HITL 输入请求;不传 filter 要求恰好一条,拿不到就抛。
|
|
134
|
+
|
|
135
|
+
#### `respond`
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
respond(...responses: (string | RespondAnswer)[]): Promise<TurnHandle>;
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
回答默认会话里等待中的输入请求,返回续接的 TurnHandle。字符串形式按顺序对应各请求;
|
|
142
|
+
多个请求并停、需要指名回答哪一条时用 RespondAnswer 对象形式(见其类型注释)。
|
|
143
|
+
|
|
144
|
+
#### `respondAll`
|
|
145
|
+
|
|
146
|
+
```ts
|
|
147
|
+
respondAll(optionId: string): Promise<TurnHandle>;
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
用同一个 optionId 批量回答默认会话里全部等待中的输入请求。
|
|
151
|
+
|
|
152
|
+
#### `reply`
|
|
153
|
+
|
|
154
|
+
```ts
|
|
155
|
+
readonly reply: string;
|
|
156
|
+
```
|
|
157
|
+
|
|
158
|
+
默认会话最近一轮的助手回复文本。
|
|
159
|
+
|
|
160
|
+
#### `sessionId`
|
|
161
|
+
|
|
162
|
+
```ts
|
|
163
|
+
readonly sessionId: string | undefined;
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
adapter 侧的默认会话 id(有会话概念的 agent 才有)。
|
|
167
|
+
|
|
168
|
+
#### `events`
|
|
169
|
+
|
|
170
|
+
```ts
|
|
171
|
+
readonly events: readonly StreamEvent[];
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
默认会话累计的事件流(跨该会话所有轮次)。
|
|
175
|
+
|
|
176
|
+
#### `newSession`
|
|
177
|
+
|
|
178
|
+
```ts
|
|
179
|
+
newSession(): SessionHandle;
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
另开一路独立会话,返回它的 SessionHandle——不是 void。多会话隔离的关键入口:
|
|
183
|
+
新会话的发送与断言都与默认会话及其它 newSession() 会话相互隔离,常用于「多用户
|
|
184
|
+
并行对话」「一条主线 + 一条旁支」这类场景。
|
|
185
|
+
|
|
186
|
+
#### `signal`
|
|
187
|
+
|
|
188
|
+
```ts
|
|
189
|
+
readonly signal: AbortSignal;
|
|
190
|
+
```
|
|
191
|
+
|
|
192
|
+
本次 attempt 的中止信号;超时 / 早停 / 用户 Ctrl-C 时触发,传给 adapter 的长耗时调用做取消。
|
|
193
|
+
|
|
194
|
+
#### `model`
|
|
195
|
+
|
|
196
|
+
```ts
|
|
197
|
+
readonly model?: string;
|
|
198
|
+
```
|
|
199
|
+
|
|
200
|
+
本次 attempt 使用的模型名(由 experiment/CLI flag 决定);省略即 agent 原生默认,不代表「无模型」。
|
|
201
|
+
|
|
202
|
+
#### `reasoningEffort`
|
|
203
|
+
|
|
204
|
+
```ts
|
|
205
|
+
readonly reasoningEffort?: string;
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
本次 attempt 的推理努力程度(如 "low"/"medium"/"high",取值由 adapter/模型决定)。
|
|
209
|
+
|
|
210
|
+
#### `flags`
|
|
211
|
+
|
|
212
|
+
```ts
|
|
213
|
+
readonly flags: Readonly<Record<string, unknown>>;
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
本次 attempt 生效的 flags(experiment.flags 与 CLI flag 合并后的只读视图)。
|
|
217
|
+
|
|
218
|
+
#### `log`
|
|
219
|
+
|
|
220
|
+
```ts
|
|
221
|
+
log(msg: string): void;
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
打一行调试日志;有 live 进度回调时走该回调,否则落到 stderr,不出现在最终结果里。
|
|
225
|
+
|
|
226
|
+
#### `skip`
|
|
227
|
+
|
|
228
|
+
```ts
|
|
229
|
+
skip(reason: string): never;
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
立即中止本 eval 并标记为 skipped(outcome / EvalResult.skipReason),reason 不能为空。
|
|
233
|
+
|
|
234
|
+
#### `check`
|
|
235
|
+
|
|
236
|
+
```ts
|
|
237
|
+
check(value: unknown, assertion: ValueAssertion): AssertionHandle;
|
|
238
|
+
```
|
|
239
|
+
|
|
240
|
+
对任意值跑一个 ValueAssertion,返回可链 `.gate()` / `.atLeast()` 的 AssertionHandle。
|
|
241
|
+
打分延迟到 eval 结束后统一 finalize,调用本身同步、不抛错——不通过只是记一条失败断言,
|
|
242
|
+
不会中止后续代码。要「不满足就立即中止 eval」用 require。
|
|
243
|
+
|
|
244
|
+
#### `require`
|
|
245
|
+
|
|
246
|
+
```ts
|
|
247
|
+
require(value: unknown, assertion: ValueAssertion): Promise<unknown>;
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
对任意值跑一个 ValueAssertion,立即(await 时)求值;不满足就抛错中止整个 eval 剩余步骤
|
|
251
|
+
(仍会把这条断言计入报告,不影响已记录的其它断言)。跟 check 的区别:check 只记录、
|
|
252
|
+
从不抛错,打分留到最后统一算;require 当场判定、失败即中止,适合「前置条件不满足,
|
|
253
|
+
后面写了也没意义」的场景。
|
|
254
|
+
|
|
255
|
+
#### `group`
|
|
256
|
+
|
|
257
|
+
```ts
|
|
258
|
+
group<T>(title: string, fn: () => Promise<T> | T): Promise<T>;
|
|
259
|
+
```
|
|
260
|
+
|
|
261
|
+
把一组断言归到一个有标题的分组下(对照 vitest 的 test('title', ...))。纯组织/报告用,
|
|
262
|
+
不改打分:组里每条断言仍独立计分。可嵌套(标题用 › 连接)。
|
|
263
|
+
|
|
264
|
+
#### `succeeded`
|
|
265
|
+
|
|
266
|
+
```ts
|
|
267
|
+
succeeded(): AssertionHandle;
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
断言默认会话累计状态为 "completed"(跨该会话所有轮次,不止最后一轮)。
|
|
271
|
+
|
|
272
|
+
#### `parked`
|
|
273
|
+
|
|
274
|
+
```ts
|
|
275
|
+
parked(): AssertionHandle;
|
|
276
|
+
```
|
|
277
|
+
|
|
278
|
+
断言默认会话当前卡在 HITL 输入请求上。
|
|
279
|
+
|
|
280
|
+
#### `messageIncludes`
|
|
281
|
+
|
|
282
|
+
```ts
|
|
283
|
+
messageIncludes(token: string | RegExp): AssertionHandle;
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
断言默认会话累计的助手回复包含 token(跨该会话所有轮次,不止最后一轮)。
|
|
287
|
+
|
|
288
|
+
#### `calledTool`
|
|
289
|
+
|
|
290
|
+
```ts
|
|
291
|
+
calledTool(name: string, match?: ToolMatch): AssertionHandle;
|
|
292
|
+
```
|
|
293
|
+
|
|
294
|
+
断言默认会话累计调用过指定名字的工具;match 可约束入参 / 次数 / 状态。
|
|
295
|
+
|
|
296
|
+
#### `notCalledTool`
|
|
297
|
+
|
|
298
|
+
```ts
|
|
299
|
+
notCalledTool(name: string, match?: ToolMatch): AssertionHandle;
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
断言默认会话累计未调用指定工具(或未按 match 条件调用)。
|
|
303
|
+
|
|
304
|
+
#### `toolOrder`
|
|
305
|
+
|
|
306
|
+
```ts
|
|
307
|
+
toolOrder(names: string[]): AssertionHandle;
|
|
308
|
+
```
|
|
309
|
+
|
|
310
|
+
断言默认会话累计工具调用按给定顺序出现(允许中间夹杂其它调用)。
|
|
311
|
+
|
|
312
|
+
#### `usedNoTools`
|
|
313
|
+
|
|
314
|
+
```ts
|
|
315
|
+
usedNoTools(): AssertionHandle;
|
|
316
|
+
```
|
|
317
|
+
|
|
318
|
+
断言默认会话至今未调用任何工具。
|
|
319
|
+
|
|
320
|
+
#### `maxToolCalls`
|
|
321
|
+
|
|
322
|
+
```ts
|
|
323
|
+
maxToolCalls(max: number): AssertionHandle;
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
断言默认会话累计工具调用总数不超过 max。
|
|
327
|
+
|
|
328
|
+
#### `loadedSkill`
|
|
329
|
+
|
|
330
|
+
```ts
|
|
331
|
+
loadedSkill(skill: string): AssertionHandle;
|
|
332
|
+
```
|
|
333
|
+
|
|
334
|
+
断言默认会话累计加载过指定 skill。
|
|
335
|
+
|
|
336
|
+
#### `noFailedActions`
|
|
337
|
+
|
|
338
|
+
```ts
|
|
339
|
+
noFailedActions(): AssertionHandle;
|
|
340
|
+
```
|
|
341
|
+
|
|
342
|
+
断言默认会话累计没有失败的工具调用 / 命令。
|
|
343
|
+
|
|
344
|
+
#### `event`
|
|
345
|
+
|
|
346
|
+
```ts
|
|
347
|
+
event(type: StreamEvent["type"], opts?: { count?: number }): AssertionHandle;
|
|
348
|
+
```
|
|
349
|
+
|
|
350
|
+
断言默认会话累计出现过指定类型的事件;opts.count 可约束出现次数。
|
|
351
|
+
|
|
352
|
+
#### `notEvent`
|
|
353
|
+
|
|
354
|
+
```ts
|
|
355
|
+
notEvent(type: StreamEvent["type"]): AssertionHandle;
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
断言默认会话累计未出现指定类型的事件。
|
|
359
|
+
|
|
360
|
+
#### `calledSubagent`
|
|
361
|
+
|
|
362
|
+
```ts
|
|
363
|
+
calledSubagent(name: string, match?: SubagentMatch): AssertionHandle;
|
|
364
|
+
```
|
|
365
|
+
|
|
366
|
+
断言默认会话累计调用过指定名字的子 agent;match 可约束次数 / 状态 / remoteUrl。
|
|
367
|
+
|
|
368
|
+
#### `eventOrder`
|
|
369
|
+
|
|
370
|
+
```ts
|
|
371
|
+
eventOrder(types: StreamEvent["type"][]): AssertionHandle;
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
断言默认会话累计事件按给定类型顺序出现(允许中间夹杂其它事件)。
|
|
375
|
+
|
|
376
|
+
#### `eventsSatisfy`
|
|
377
|
+
|
|
378
|
+
```ts
|
|
379
|
+
eventsSatisfy(predicate: (events: readonly StreamEvent[]) => boolean, label?: string): AssertionHandle;
|
|
380
|
+
```
|
|
381
|
+
|
|
382
|
+
用自定义谓词对默认会话累计的整段事件流断言;失败时用 label 说明原因。
|
|
383
|
+
|
|
384
|
+
#### `sandbox`
|
|
385
|
+
|
|
386
|
+
```ts
|
|
387
|
+
readonly sandbox: SandboxHandle;
|
|
388
|
+
```
|
|
389
|
+
|
|
390
|
+
受限沙箱视图:能执行命令 / 读写文件 / 看最终 diff,不能 stop 沙箱本身(见 SandboxHandle)。
|
|
391
|
+
|
|
392
|
+
#### `usage`
|
|
393
|
+
|
|
394
|
+
```ts
|
|
395
|
+
readonly usage: Usage;
|
|
396
|
+
```
|
|
397
|
+
|
|
398
|
+
默认会话累计的 token 用量与估算成本。
|
|
399
|
+
|
|
400
|
+
#### `maxTokens`
|
|
401
|
+
|
|
402
|
+
```ts
|
|
403
|
+
maxTokens(max: number): AssertionHandle;
|
|
404
|
+
```
|
|
405
|
+
|
|
406
|
+
断言默认会话累计 token 用量不超过 max。
|
|
407
|
+
|
|
408
|
+
#### `maxCost`
|
|
409
|
+
|
|
410
|
+
```ts
|
|
411
|
+
maxCost(usd: number): AssertionHandle;
|
|
412
|
+
```
|
|
413
|
+
|
|
414
|
+
断言默认会话累计花费(USD)不超过 usd。
|
|
415
|
+
|
|
416
|
+
#### `judge`
|
|
417
|
+
|
|
418
|
+
```ts
|
|
419
|
+
readonly judge: JudgeNamespace;
|
|
420
|
+
```
|
|
421
|
+
|
|
422
|
+
可用的 judge 命名空间(t.judge.autoevals.*)。
|
|
423
|
+
|
|
424
|
+
{/* GENERATED:END test-context */}
|
|
425
|
+
|
|
426
|
+
## Judge 断言
|
|
427
|
+
|
|
428
|
+
```ts
|
|
429
|
+
t.judge.autoevals.factuality(expected, { on: t.reply }).atLeast(0.8);
|
|
430
|
+
t.judge.autoevals.closedQA(question, { on: t.reply }).atLeast(0.7);
|
|
431
|
+
t.judge.autoevals.closedQA(rubric, { on: t.reply }).atLeast(0.75);
|
|
432
|
+
t.judge.autoevals.summarizes(sourceText, { on: t.reply }).atLeast(0.7);
|
|
433
|
+
```
|
|
434
|
+
|
|
435
|
+
`t.judge.autoevals` 目前有三个方法:`factuality`(回复与 `expected` 事实是否一致)、`closedQA`(回复是否满足给定问题或 rubric)、`summarizes`(回复是否是给定原文 `source` 的合格摘要)。三者都直接用 [autoevals](https://github.com/braintrustdata/autoevals)(braintrust)库的评分器,`{ on: t.reply }` 指定被评的文本。
|
|
436
|
+
|
|
437
|
+
## `Turn` 返回类型
|
|
438
|
+
|
|
439
|
+
`t.send(...)` 返回一个 `TurnHandle`:从事件流派生的便利字段,加上一整套本轮作用域断言。
|
|
440
|
+
|
|
441
|
+
{/* GENERATED:BEGIN turn-handle */}
|
|
442
|
+
|
|
443
|
+
#### `events`
|
|
444
|
+
|
|
445
|
+
```ts
|
|
446
|
+
readonly events: StreamEvent[];
|
|
447
|
+
```
|
|
448
|
+
|
|
449
|
+
本轮的原始事件流(工具调用、消息增量等);下面的派生字段都算自它。
|
|
450
|
+
|
|
451
|
+
#### `toolCalls`
|
|
452
|
+
|
|
453
|
+
```ts
|
|
454
|
+
readonly toolCalls: readonly ToolCall[];
|
|
455
|
+
```
|
|
456
|
+
|
|
457
|
+
本轮内被调用的工具列表,从 events 派生。
|
|
458
|
+
|
|
459
|
+
#### `status`
|
|
460
|
+
|
|
461
|
+
```ts
|
|
462
|
+
readonly status: "completed" | "failed" | "waiting";
|
|
463
|
+
```
|
|
464
|
+
|
|
465
|
+
本轮结束状态:"completed" 正常结束、"failed" 出错、"waiting" 卡在 HITL 输入请求上。
|
|
466
|
+
|
|
467
|
+
#### `message`
|
|
468
|
+
|
|
469
|
+
```ts
|
|
470
|
+
readonly message: string;
|
|
471
|
+
```
|
|
472
|
+
|
|
473
|
+
本轮助手最终文本回复(events 里的消息增量拼接结果)。
|
|
474
|
+
|
|
475
|
+
#### `data`
|
|
476
|
+
|
|
477
|
+
```ts
|
|
478
|
+
readonly data?: unknown;
|
|
479
|
+
```
|
|
480
|
+
|
|
481
|
+
adapter 附带的结构化输出(如有),供 outputEquals / outputMatches 比对。
|
|
482
|
+
|
|
483
|
+
#### `usage`
|
|
484
|
+
|
|
485
|
+
```ts
|
|
486
|
+
readonly usage?: Usage;
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
本轮 token 用量与估算成本(仅上报了 usage 的 agent 才有)。
|
|
490
|
+
|
|
491
|
+
#### `expectOk`
|
|
492
|
+
|
|
493
|
+
```ts
|
|
494
|
+
expectOk(): TurnHandle;
|
|
495
|
+
```
|
|
496
|
+
|
|
497
|
+
上一轮若 failed 则抛(中止后续)。
|
|
498
|
+
|
|
499
|
+
#### `outputEquals`
|
|
500
|
+
|
|
501
|
+
```ts
|
|
502
|
+
outputEquals(value: unknown): AssertionHandle;
|
|
503
|
+
```
|
|
504
|
+
|
|
505
|
+
断言 data 与给定值深度相等。
|
|
506
|
+
|
|
507
|
+
#### `outputMatches`
|
|
508
|
+
|
|
509
|
+
```ts
|
|
510
|
+
outputMatches(schema: unknown): AssertionHandle;
|
|
511
|
+
```
|
|
512
|
+
|
|
513
|
+
断言 data 满足给定 schema(如 zod schema)。
|
|
514
|
+
|
|
515
|
+
#### `messageIncludes`
|
|
516
|
+
|
|
517
|
+
```ts
|
|
518
|
+
messageIncludes(token: string | RegExp): AssertionHandle;
|
|
519
|
+
```
|
|
520
|
+
|
|
521
|
+
断言本轮助手回复包含 token(仅限本轮事件流,不跨轮)。
|
|
522
|
+
|
|
523
|
+
#### `succeeded`
|
|
524
|
+
|
|
525
|
+
```ts
|
|
526
|
+
succeeded(): AssertionHandle;
|
|
527
|
+
```
|
|
528
|
+
|
|
529
|
+
断言本轮 status 为 "completed"。
|
|
530
|
+
|
|
531
|
+
#### `parked`
|
|
532
|
+
|
|
533
|
+
```ts
|
|
534
|
+
parked(): AssertionHandle;
|
|
535
|
+
```
|
|
536
|
+
|
|
537
|
+
断言本轮卡在 HITL 输入请求上(status 为 "waiting")。
|
|
538
|
+
|
|
539
|
+
#### `calledTool`
|
|
540
|
+
|
|
541
|
+
```ts
|
|
542
|
+
calledTool(name: string, match?: ToolMatch): AssertionHandle;
|
|
543
|
+
```
|
|
544
|
+
|
|
545
|
+
断言本轮调用过指定名字的工具;`match` 可进一步约束入参 / 次数 / 状态。
|
|
546
|
+
|
|
547
|
+
#### `notCalledTool`
|
|
548
|
+
|
|
549
|
+
```ts
|
|
550
|
+
notCalledTool(name: string, match?: ToolMatch): AssertionHandle;
|
|
551
|
+
```
|
|
552
|
+
|
|
553
|
+
断言本轮未调用指定工具(或未按 match 条件调用)。
|
|
554
|
+
|
|
555
|
+
#### `toolOrder`
|
|
556
|
+
|
|
557
|
+
```ts
|
|
558
|
+
toolOrder(names: string[]): AssertionHandle;
|
|
559
|
+
```
|
|
560
|
+
|
|
561
|
+
断言本轮工具调用按给定顺序出现(允许中间夹杂其它调用)。
|
|
562
|
+
|
|
563
|
+
#### `usedNoTools`
|
|
564
|
+
|
|
565
|
+
```ts
|
|
566
|
+
usedNoTools(): AssertionHandle;
|
|
567
|
+
```
|
|
568
|
+
|
|
569
|
+
断言本轮未调用任何工具。
|
|
570
|
+
|
|
571
|
+
#### `maxToolCalls`
|
|
572
|
+
|
|
573
|
+
```ts
|
|
574
|
+
maxToolCalls(max: number): AssertionHandle;
|
|
575
|
+
```
|
|
576
|
+
|
|
577
|
+
断言本轮工具调用总数不超过 max。
|
|
578
|
+
|
|
579
|
+
#### `loadedSkill`
|
|
580
|
+
|
|
581
|
+
```ts
|
|
582
|
+
loadedSkill(skill: string): AssertionHandle;
|
|
583
|
+
```
|
|
584
|
+
|
|
585
|
+
断言本轮加载过指定 skill。
|
|
586
|
+
|
|
587
|
+
#### `noFailedActions`
|
|
588
|
+
|
|
589
|
+
```ts
|
|
590
|
+
noFailedActions(): AssertionHandle;
|
|
591
|
+
```
|
|
592
|
+
|
|
593
|
+
断言本轮没有失败的工具调用 / 命令。
|
|
594
|
+
|
|
595
|
+
#### `event`
|
|
596
|
+
|
|
597
|
+
```ts
|
|
598
|
+
event(type: StreamEvent["type"], opts?: { count?: number }): AssertionHandle;
|
|
599
|
+
```
|
|
600
|
+
|
|
601
|
+
断言本轮出现过指定类型的事件;`opts.count` 可约束出现次数。
|
|
602
|
+
|
|
603
|
+
#### `notEvent`
|
|
604
|
+
|
|
605
|
+
```ts
|
|
606
|
+
notEvent(type: StreamEvent["type"]): AssertionHandle;
|
|
607
|
+
```
|
|
608
|
+
|
|
609
|
+
断言本轮未出现指定类型的事件。
|
|
610
|
+
|
|
611
|
+
#### `calledSubagent`
|
|
612
|
+
|
|
613
|
+
```ts
|
|
614
|
+
calledSubagent(name: string, match?: SubagentMatch): AssertionHandle;
|
|
615
|
+
```
|
|
616
|
+
|
|
617
|
+
断言本轮调用过指定名字的子 agent;`match` 可约束次数 / 状态 / remoteUrl。
|
|
618
|
+
|
|
619
|
+
#### `eventOrder`
|
|
620
|
+
|
|
621
|
+
```ts
|
|
622
|
+
eventOrder(types: StreamEvent["type"][]): AssertionHandle;
|
|
623
|
+
```
|
|
624
|
+
|
|
625
|
+
断言本轮事件按给定类型顺序出现(允许中间夹杂其它事件)。
|
|
626
|
+
|
|
627
|
+
#### `eventsSatisfy`
|
|
628
|
+
|
|
629
|
+
```ts
|
|
630
|
+
eventsSatisfy(predicate: (events: readonly StreamEvent[]) => boolean, label?: string): AssertionHandle;
|
|
631
|
+
```
|
|
632
|
+
|
|
633
|
+
用自定义谓词对本轮整段事件流断言;失败时用 label 说明原因。
|
|
634
|
+
|
|
635
|
+
#### `maxTokens`
|
|
636
|
+
|
|
637
|
+
```ts
|
|
638
|
+
maxTokens(max: number): AssertionHandle;
|
|
639
|
+
```
|
|
640
|
+
|
|
641
|
+
断言本轮 token 用量不超过 max。
|
|
642
|
+
|
|
643
|
+
#### `maxCost`
|
|
644
|
+
|
|
645
|
+
```ts
|
|
646
|
+
maxCost(usd: number): AssertionHandle;
|
|
647
|
+
```
|
|
648
|
+
|
|
649
|
+
断言本轮花费(USD)不超过 usd。
|
|
650
|
+
|
|
651
|
+
#### `judge`
|
|
652
|
+
|
|
653
|
+
```ts
|
|
654
|
+
readonly judge: JudgeNamespace;
|
|
655
|
+
```
|
|
656
|
+
|
|
657
|
+
本轮可用的 judge 命名空间(t.judge.autoevals.*)。
|
|
658
|
+
|
|
659
|
+
{/* GENERATED:END turn-handle */}
|
|
660
|
+
|
|
661
|
+
## 数据集导出
|
|
662
|
+
|
|
663
|
+
```ts
|
|
664
|
+
export default rows.map((row) =>
|
|
665
|
+
defineEval({
|
|
666
|
+
description: row.task,
|
|
667
|
+
async test(t) {
|
|
668
|
+
await t.send(row.prompt);
|
|
669
|
+
},
|
|
670
|
+
}),
|
|
671
|
+
);
|
|
672
|
+
```
|
|
673
|
+
|
|
674
|
+
数组导出会生成稳定 ID:`file/0000`、`file/0001` 等。
|