Agent · 进阶
Agent 路由
从预先定义的流程中选择下一个 Agent 或 tool;选择结果不等于执行授权。
ChoiceNoul
适合什么时候使用
- 多 Agent 系统
- Tool 路由
- 工作流分支
示例 state
{
"request": "Check the current rate-limit settings before proposing a change.",
"current_node": "start",
"allowed_next": [
"research_agent",
"support_agent",
"ops_agent"
]
}决策问题
Choicenext_node
只能从允许的下一个节点中选择。
research_agent— 研究外部或背景信息support_agent— 处理用户支持请求ops_agent— 检查或提出运营配置变更clarify— 信息不足,无法安全路由
Noulenough_information
根据当前请求和 workflow 状态,信息是否足够选择下一个节点?
预期输出
下一个节点,以及当前信息是否足够支持这个选择的概率。
TypeScript 示例
import { choice, noul, TypeSafeClient } from "@typesafe-ai/sdk";
const client = new TypeSafeClient();
const result = await client.systemOne({
state: {
request: "Check the current rate-limit settings before proposing a change.",
current_node: "start",
allowed_next: ["research_agent", "support_agent", "ops_agent"],
},
questions: {
next_node: choice("Choose only among the allowed next nodes.", {
research_agent: "Research background information",
support_agent: "Handle user-support requests",
ops_agent: "Inspect or propose operational configuration changes",
clarify: "Not enough information to route safely",
}),
enough_information: noul(
"Is there enough information to choose a next node safely?"
),
},
});为什么这样设计
- 可选节点由程序提前提供,不让模型自己发明新的去向。
- 真正的权限检查和执行仍然由应用负责。
- `clarify` 是正常选项,不是异常情况。
注意事项
- 路由到具体 tool 后,仍然要做明确的权限检查。
- 绝不允许模型输出图中不存在的工具名称。
来源与参考
这个模板和来源链接最近核验:2026-09-21。
继续浏览
先在Playground中运行这个模式,浏览全部模板,了解官方 SDK 用法,或使用成本计算器估算实际使用成本。