Town CLI
命令环境要求
解释当前 city 命令组需要什么环境、文件与变量优先级
命令环境要求
这页只回答一个问题:不同 town 命令组运行时,各自需要什么环境。
0)一级命令边界
一级命令组只有:
town consoletown agenttown plugin
像 town chat、town task、town memory、town shell、town skill、town asr、town tts 这些,都是 plugin 命令,不是一级根命令。
1)按命令组看环境要求
| 命令组 | 必需环境 | 可选环境 | 说明 |
|---|---|---|---|
town init | 可写 ~/.downcity/ | 无 | 写入 ~/.downcity/downcity.db |
town start/stop/restart/status | 可写 ~/.downcity/console/ | 无 | 管理 Town runtime、gateway 与受管 agent registry |
town console | Town runtime 已运行;浏览器可访问 UI 端口 | --host、--port | 一个 UI 可切换多个运行中的 agent |
town agent create | 目标目录可写 | 无 | 生成 downcity.json、PROFILE.md、.downcity/ |
town agent start | Town runtime 已运行;项目包含 downcity.json + PROFILE.md | --host | agent 端口由 Town runtime 分配并登记进受管 agent registry |
town agent restart/status/doctor | 目标 agent 已登记在受管 agent registry | 无 | 通过 registry 解析 |
town config ... | 目标路径下存在合法 downcity.json | --path | 只读写项目配置,不调用 agent API |
town plugin list/info | 无 | --json | 静态 plugin catalog,不解析 agent |
town plugin start/stop/restart/command | 目标 agent 正在运行 | --agent、--path、--host、--port | 面向托管 plugin |
town plugin action ... | 项目存在 downcity.json | --path | 高级本地执行形式 |
town <managed-plugin> <action> | 目标 agent 正在运行 | --path、--host、--port | 如 town chat、town task、town memory、town shell |
town <local-plugin> <action> | 项目存在 downcity.json | --path | 如 town skill、town web、town asr、town tts |
2)运行时传输
默认规则:
- 不传
--host/--port:托管 runtime 命令默认通过 registry 解析目标 agent 的本地 RPC 端点 - 传了
--host或--port:覆盖 RPC endpoint,按给定 host/port 连接
只有调用 Town Agent HTTP gateway,且目标 HTTP 端点当前启用了鉴权时,Bearer Token 解析才有意义。
3)DC_AUTH_TOKEN
对大多数本地使用场景,你不需要关心 auth 环境变量。
托管 runtime 调用会按命令分别使用本地 Agent RPC 或 Town Agent HTTP gateway。DC_AUTH_TOKEN 只在 HTTP gateway 端点要求鉴权时才生效。
优先级顺序:
- 显式
--token DC_AUTH_TOKEN
4)常见命令的上下文变量
town chat ...
- 省略
--chat-key时,会尝试DC_CTX_CHAT_KEY - 省略
--session-id时,会先尝试DC_SESSION_ID
town task ...
- task 创建与运行需要
sessionId - 可以显式传
--session-id,或依赖DC_SESSION_ID
5)推荐用法
日常操作优先直接使用 plugin 根命令:
town chat send --chat-key ctx_xxx --text "hi"
town task list
town memory search "release decision"
town plugin list