请求中可能同时包含目标与禁止项
“在内部台账中查找 42 号发票,不要发送任何发票”同时包含查找目标和禁止项。调度器将请求映射为业务操作前,先记录两者。
读取 3.0.0 解析结果
这个宿主代码片段使用 Node.js 20+ 和 ES 模块,依赖 @devcodex/intent-runtime@3.0.0 及其指定的 peer 版本 schema-dsl@3.0.4。运行解析时传入宿主已配置并授权的模型执行器 executor。声明并选取 invoiceId 后,输出会包含字段状态、目标、根级与节点级约束,以及待处理的问题。
import { Intent } from '@devcodex/intent-runtime';
import { s } from 'schema-dsl/pure';
const schema = s({
invoiceId: s('string!').description('Invoice ID explicitly supplied by the user'),
});
const intent = new Intent({ language: 'en', schema, executor });
function flatten(nodes) {
return nodes.flatMap(node => [node, ...flatten(node.children)]);
}
function inspect(result) {
return {
rootConstraints: result.effective.constraints,
intents: flatten(result.effective.intents).map(({ id, goal, inputs, constraints }) => ({
id, goal, inputs, constraints,
})),
fieldResults: result.fieldResults,
issues: result.issues,
};
}
try {
for (const input of [
'Find invoice 42 in the internal ledger. Do not send any invoices.',
'Find the invoice in the internal ledger. Do not send any invoices.',
]) {
console.log(inspect(await intent.parse({ input, fields: ['invoiceId'] })));
}
} finally {
await intent.dispose();
}
把歧义变成流程判断
下表使用符合公开结果契约的固定示例数据。模型可能采用不同措辞,也可能把等价约束放在不同层级。
| 输入 | 要核对的字段 | 宿主决策 |
|---|---|---|
| 在内部台账中查找 42 号发票,不要发送任何发票。 | 根级禁止发送约束为 kind: 'prohibition'、scope: { type: 'global' }。查找节点的内部台账约束为 kind: 'requirement'、scope: { type: 'intent', intentId: 'lookup' }。lookup 的 invoiceId 状态为 present,值为 "42"。 |
解析实际的 42 号发票资源,核对认证主体的查找权限,继续禁止发送。 |
| 在内部台账中查找那张发票,不要发送任何发票。 | lookup 的 invoiceId 为 not_provided,issues 中带有指向 /invoiceId 的问题,发送禁令和台账约束都保留。 |
先要求补充发票编号,等回答后再分派。 |
收到回答后,用 baseline 显式传入上一轮的 effective,用 context 传入宿主可信事实。宿主先按所属节点核对字段结果并解析出实际资源,再检查动作是否符合约束,以及认证主体是否确有权限,随后才能分派。