Apache Casbin Gateway
2. Agent客户端

2.6 聊天

聊天把一条消息交给这台机器上的某个Agent,并让你看着它干活:边写边出的回答、它调用的每个工具,以及这一轮花了多少。它在侧边栏里紧挨着Agent客户端,只有管理员能看到。

回答你的就是那个Agent本身,不是一份副本。它用的是自己的配置、Gateway给它绑定的供应商,以及Gateway装进去的钩子,所以它花了多少、被允许做什么,记录下来和有人在终端里跟它打字时一模一样。

哪些Agent能被驱动

只有提供了非交互模式的Agent才能被驱动,因为Gateway是在没有终端的情况下运行它的:

Agent消息之间是否保留对话
Claude Code是
CodeBuddy Code是
Codex CLI是
Qwen Code是
Gemini CLI否——每条消息各自独立

这台机器上没装的Agent不会出现在选项里。一个都没装时,页面会直接这么说。

Gemini CLI只能恢复它最近的一次会话,不能按编号恢复指定的会话,所以发给它的每条消息都从零开始。它的会话上会带一个每条消息各自独立的标记。

开一个会话

  1. 选一个Agent。
  2. 要在某个项目里工作的话,填上工作目录:一个完整路径,或者以~开头的路径。留空则在用户主目录里工作。不存在的路径会在这一步就被拒绝,不会等到运行时。
  3. 点新建会话,然后输入。Enter发送,Shift+Enter换行。

第一条消息发出之前什么都不会运行:会话只是约定了Agent将在哪里启动。

回答里有什么

  • 正文,按Markdown渲染,随着Agent的输出逐步变长。
  • 它的思考过程(如果Agent会报告的话),折叠在回答下方。
  • 每一次工具调用单独一个框:调用的工具、传给它的参数、返回的结果。
  • Agent顺带提到、但没有中断这一轮的事情,会以提示的形式显示出来。
  • 输入和输出的token数,Agent报告了费用时也会显示费用。

同一时间只运行一轮。运行期间发送按钮会变成停止按钮,按下就结束这一轮。

没有终端的Agent

被驱动的Agent没法停下来请你批准某个工具,因为终端前没有人可以回答。它只会做自己的设置允许它不经询问就做的事。

Gateway的约束照样有效。权限页上的工具开关由钩子在工具执行前检查;模型和供应商规则约束所有走代理的请求。

Claude Code、Gemini CLI和Qwen Code会在这一次运行里通过环境变量拿到绑定给它的供应商,它们的配置文件一个字都不会动。Codex CLI和CodeBuddy Code读取的是绑定供应商时Gateway写好的配置(3.2)。

会话列表

左侧列出所有被驱动的会话,最新的在前,以第一条问题命名,也包括从聊天渠道开的会话——它们运行时也能在这里旁观。点垃圾桶图标可以删掉一个。

会话保存在数据库里,所以Gateway重启后列表还在,下一条消息仍会接着原来的对话。重启之前说过的内容不会在这一页重新显示;它们在Agent自己的会话记录里,会话页读的就是那份记录。

下一节:2.7 聊天渠道。

在GitHub上编辑
Apache Incubator

Apache Casbin (Incubating) is an effort undergoing incubation at The Apache Software Foundation (ASF), sponsored by the Apache Incubator. Incubation is required of all newly accepted projects until a further review indicates that the infrastructure, communications, and decision making process have stabilized in a manner consistent with other successful ASF projects. While incubation status is not necessarily a reflection of the completeness or stability of the code, it does indicate that the project has yet to be fully endorsed by the ASF.

Copyright © 2026 The Apache Software Foundation, Licensed under the Apache License, Version 2.0.

Apache, Apache Casbin, the names of Apache projects, and the feather logo are either registered trademarks or trademarks of The Apache Software Foundation in the United States and/or other countries. All other marks mentioned may be trademarks or registered trademarks of their respective owners.

本页内容