陆 · 校验

Jev 判断

ctx.jev

调用 TypeSafe Jev 或本地部署的 Laya(二选一),返回 Choice / Noul / Score 的类型化判断和概率;一次 judge() 有严格的总时长。

接口

import { choice, noul, score } from '@mc/dsh-agent-kit'

const { answers } = await ctx.jev.judge({
  state: { input, candidate },
  questions: {
    wrong: noul('候选结果与输入证据不符', { true: '不符', false: '相符' }),
    pick: choice('输入最符合哪个类别', { bug: '缺陷', feature: '需求', question: '咨询' }),
    severity: score('严重程度', ['无影响', '轻微', '严重', '致命']),
  },
  signal,
  traceId,
})

if (answers.wrong.noul >= 0.7) escalate()
if (answers.pick.confidence < 0.6) askHuman()

judge() 返回 { model, answers, usage? }。answers 的类型按问题推断:

问题答案说明
noul(instructions, { true, false }){ type: 'noul', noul }noul 是回答”是”的概率,范围 [0, 1]
choice(instructions, { A: 描述, B: 描述 }){ type: 'choice', choice, confidence, probabilities }choice 是选中的标签,probabilities 按标签给出
score(instructions, [档位0, 档位1, …]){ type: 'score', score, confidence, legend, probabilities }score 是期望分数,可能介于整数档位之间

问题构造函数由本包导出,与 SDK 的线上格式一致;没有启用 jev 的项目不需要安装 SDK。

Provider:Jev 与本地 Laya 二选一

provider 决定请求发往哪里,业务代码里的 ctx.jev.judge() 与返回类型不变:

provider服务需要
typesafe(默认)TypeSafe 托管的 JevTypeSafe API Key
laya本地部署的 Laya,接口与 Jev 相同(POST /v1/systemone)baseURL;Key 可选
- id: agent-kit-jev
  disabled: false
  config:
    provider: laya
    baseURL: http://127.0.0.1:8000   # laya-serve 默认端口
    apiKeyRef: LAYA_API_KEY          # 可选,默认即 LAYA_API_KEY

依赖与 Key

超时与重试

配置

在 Profile 的 cordis.patch.yml 中按 id agent-kit-jev 启用并给出配置。按 id 修改 config 时整段替换,未给出的字段使用默认值。下表由本包源码中的配置 schema 生成。

- id: agent-kit-jev
  disabled: false
  config:
    # 只写需要改的字段,其余使用下表的默认值
字段默认值取值范围说明
provider typesafe typesafe | laya typesafe:TypeSafe 托管的 Jev;laya:本地部署的 Laya
baseURL — 匹配 /^https?:\/\/\S+$/ Laya 服务地址,provider 为 laya 时必填
apiKeyRef — 匹配 /^[A-Za-z_][A-Za-z0-9_]*$/ Laya Key 的 ref(环境变量名 / dsh 凭据键),默认 LAYA_API_KEY
model jev-latest — SDK 支持的模型名
timeoutMs 30000 [1000, 300000] 一次 judge() 的总时长,包含 SDK 内部重试
keychainService — 见说明 macOS 钥匙串服务名,推荐共享名 ai.typesafe.api-key;可给列表按顺序尝试
keychainAccount — 匹配 /^[\w.@:-]{1,128}$/ 钥匙串账户名,默认 $USER

约束与说明

错误码

所有错误都是 KitError:用 isKitError(e) 判断,按 code 与 retryable 决定是否重试。

code可重试含义
unavailable 是 网络错误、5xx、408 或超过总时长。
rate_limited 是 TypeSafe / Laya API 返回 429。
unauthorized 否 TypeSafe / Laya API 返回 401 / 403;health() 同时置为 failed。
bad_request 否 其余 4xx 与参数错误。
aborted 否 调用方 signal 中止或 Service 卸载。
invalid_config 否 配置或环境变量非法,Service 启动失败。