Concordat: Typed Sessions for LLM Agents

Agent Tool Learning Agent Eval Benchmarks AI Safety / AI Ethics AVAR
2026年10月27日
基于大语言模型构建的智能体正日益被赋予具有实际影响的操作权限:例如取消预订、发放退款、修改账户信息等。而规范此类操作的规则(如“在执行任何变更前必须获得客户的明确确认”)通常仅以提示词(prompt)形式给出,其执行效果完全取决于模型自身是否选择遵守这些规则。本文提出 Concordat——一个 Python 库,它将智能体建模为一个对象,其接口由有限状态协议(finite-state protocol)定义,设计理念源自类型状态(typestate)与会话类型(session types),并在运行时对模型强制实施该协议。在每一轮交互中,模型仅能调用当前协议状态下允许使用的工具;任何超出许可范围的调用均会在产生副作用之前即被拒绝;需由人类最终决策的事项只能以“请求”方式提出,不得擅自决定;同时,token 消耗与工具调用预算在线程交接(handoff)过程中按线性方式分配并实时扣减。协议本身在定义阶段即进行静态检查;若某智能体子类可能绕过其父类所规定的协议,则该子类将被明确拒绝——这是一种体现行为层面里氏替换原则(Liskov Substitution Principle)的机制。我们在 tau-bench 的 50 个航空业任务上,将 Concordat 智能体与基准智能体进行了对比评估,并引入模拟客户施加压力,诱导智能体跳过确认环节。实验结果表明:在使用 gpt-4.1 的 50 项任务中,基准智能体在 13 项任务中未经客户明确说“是”(yes)即擅自执行了变更;在使用 Claude Haiku 5.5 的 128 次任务运行中,该违规行为更高达 29 次;而 Concordat 智能体则在全部任务中零违规,且任务完成率与基准智能体相比无显著差异。值得注意的是,tau-bench 自带的奖励函数未能检出上述绝大多数违规行为。Concordat 已开源。
Agents built on large language models are increasingly allowed to take consequential actions: cancelling bookings, issuing refunds, changing accounts. The rules that govern those actions, such as "obtain the customer's explicit confirmation before changing anything", are usually stated in the prompt and followed only as reliably as the model chooses to follow them. We present Concordat, a Python library that treats an agent as an object whose interface is a finite-state protocol, in the spirit of typestate and session types, and enforces that protocol on the model at run time. On every turn the model is offered only the tools that are legal in the current protocol state, calls outside that set are rejected before they have side effects, decisions reserved for humans can only be requested, and token and tool-call budgets are charged and split linearly across handoffs. Protocols are checked when they are defined, and a subclass of an agent is rejected if it could bypass its parent's protocol, a behavioural form of Liskov substitution. We evaluate a Concordat agent against the standard agent of tau-bench on its 50 airline tasks, adding simulated customers who pressure the agent to skip confirmation. The standard agent made changes without the required "yes" in 13 of 50 tasks with gpt-4.1 and in 29 of 128 task-runs with Claude Haiku 5.5; the Concordat agent made none, with no significant difference in task success. tau-bench's own reward did not detect most of these violations. Concordat is open source.
许愿