Jev 是一个类型化判断模型
Jev 不负责续写文本。它接收一份状态(state)和一组边界明确的问题,然后返回可以被程序读取的 Choice、Score 或 Noul。适合它的任务通常答案空间已知,但无法只靠 if/else 从原始输入中精确判断。
Choice从命名选项中选择一个,例如把工单路由到 billing、technical 或 human。
Score落在有序等级上,例如 calm → frustrated → angry。
Noul估计一个命题为真的概率,例如“该请求是否紧急”。
判断和执行必须分开
一次可靠调用有五个层次。业务先整理证据,再声明问题;Jev 返回概率化答案;应用策略检查结构、阈值和风险;最后才允许代码执行动作。模型没有退款、删库或发布内容的权限。
- 1State
只保留会影响当前判断的证据,字段名、单位和来源要清晰。
- 2Question
用 Choice、Score 或 Noul 声明答案形状与判断标准。
- 3Typed answer
读取胜出项、完整分布或 P(true),不要把结果当自然语言。
- 4Policy
校验选项、置信度、业务风险和是否需要人工复核。
- 5Action
由业务代码执行,并记录问题版本、模型版本和最终动作。
贯穿全文的工单路由案例
假设输入是一条客户消息。我们需要判断应该交给哪个团队,并判断是否紧急。路由是 Choice,紧急性是 Noul;真正的派单动作仍由程序决定。
{
"message": "Stripe has failed for three days. Help ASAP.",
"account_tier": "enterprise"
}route → billing | technical | human
urgent → P(true)
policy → automate | review这个拆分很重要:模型只回答两个小问题,业务策略再组合答案。以后增加 SLA、VIP 客户或高风险词规则时,不需要把隐藏策略塞进一段超长提示词。
用 Python 完成第一次 Jev 调用
官方 Python 客户端是 typesafe-sdk。密钥只放在服务端环境变量中,先从一个可撤销、容易人工核对的任务开始。
python -m pip install typesafe-sdkexport TYPESAFE_API_KEY="your-api-key"from typesafe_sdk import Choice, Noul, TypeSafeClient
questions = {
"route": Choice(
instructions="Which team should handle this request?",
criteria={
"billing": "Payments or subscriptions",
"technical": "Bugs or integrations",
"human": "Ambiguous or sensitive cases",
},
),
"urgent": Noul(
instructions="Does this message express urgency?"
),
}
with TypeSafeClient() as client:
result = client.system_one(
state={
"message": "Stripe has failed for three days. Help ASAP.",
"account_tier": "enterprise",
},
questions=questions,
)
route = result.answers["route"]
urgent = result.answers["urgent"]
if route.choice == "human" or route.confidence < 0.75:
enqueue_for_review(result)
else:
assign_team(route.choice)
print(route.probabilities, urgent.noul) 选项键是否存在、questions 是否非空、响应结构是否完整。
低置信度转人工;不可逆动作不因高分自动获得权限。
记录模型、问题版本、分布、阈值与最终动作。
把同一决策契约接入 Runnable
LangChain 的官方 TypeSafe 集成把 TypeSafeClassifier 实现为 Runnable。state 和 questions 都随每次 invoke 传入,因此可以进入批处理、异步调用、回调和追踪链路。
uv add langchain-typesafeexport TYPESAFE_API_KEY="your-api-key"from langchain_typesafe import Choice, Noul, TypeSafeClassifier
classifier = TypeSafeClassifier()
questions = {
"route": Choice(
instructions="Which team should handle this request?",
criteria={
"billing": "Payments or subscriptions",
"technical": "Bugs or integrations",
"human": "Ambiguous or sensitive cases",
},
),
"urgent": Noul(
instructions="Does this message express urgency?"
),
}
if not questions:
raise ValueError("At least one Jev question is required")
result = classifier.invoke({
"state": "Stripe has failed for three days. Help ASAP.",
"questions": questions,
})
print(result.choices["route"].choice)
print(result.nouls["urgent"].noul) 编排、批处理、回调与追踪
封闭问题的概率化判断
阈值、权限、人工复核与副作用