lithe-cli 0.8.8__tar.gz → 0.9.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of lithe-cli might be problematic. Click here for more details.
- {lithe_cli-0.8.8 → lithe_cli-0.9.0}/PKG-INFO +21 -8
- {lithe_cli-0.8.8 → lithe_cli-0.9.0}/README.md +19 -6
- {lithe_cli-0.8.8 → lithe_cli-0.9.0}/lithe_cli/__init__.py +1 -1
- {lithe_cli-0.8.8 → lithe_cli-0.9.0}/lithe_cli/agent.py +106 -3
- {lithe_cli-0.8.8 → lithe_cli-0.9.0}/lithe_cli/config.py +36 -0
- {lithe_cli-0.8.8 → lithe_cli-0.9.0}/lithe_cli/main.py +59 -0
- {lithe_cli-0.8.8 → lithe_cli-0.9.0}/lithe_cli/profiles.py +19 -0
- {lithe_cli-0.8.8 → lithe_cli-0.9.0}/lithe_cli/ttui.py +23 -6
- {lithe_cli-0.8.8 → lithe_cli-0.9.0}/lithe_cli/tui.py +8 -0
- {lithe_cli-0.8.8 → lithe_cli-0.9.0}/lithe_cli/workbench.py +73 -12
- {lithe_cli-0.8.8 → lithe_cli-0.9.0}/lithe_cli.egg-info/PKG-INFO +21 -8
- {lithe_cli-0.8.8 → lithe_cli-0.9.0}/lithe_cli.egg-info/SOURCES.txt +2 -0
- {lithe_cli-0.8.8 → lithe_cli-0.9.0}/lithe_cli.egg-info/requires.txt +1 -1
- {lithe_cli-0.8.8 → lithe_cli-0.9.0}/pyproject.toml +1 -1
- lithe_cli-0.9.0/tests/test_cli_budget_steer.py +272 -0
- lithe_cli-0.9.0/tests/test_cli_subagents.py +118 -0
- {lithe_cli-0.8.8 → lithe_cli-0.9.0}/tests/test_ttui.py +10 -6
- {lithe_cli-0.8.8 → lithe_cli-0.9.0}/LICENSE +0 -0
- {lithe_cli-0.8.8 → lithe_cli-0.9.0}/lithe_cli/__main__.py +0 -0
- {lithe_cli-0.8.8 → lithe_cli-0.9.0}/lithe_cli/commands.py +0 -0
- {lithe_cli-0.8.8 → lithe_cli-0.9.0}/lithe_cli/prompts.py +0 -0
- {lithe_cli-0.8.8 → lithe_cli-0.9.0}/lithe_cli/py.typed +0 -0
- {lithe_cli-0.8.8 → lithe_cli-0.9.0}/lithe_cli/sessions.py +0 -0
- {lithe_cli-0.8.8 → lithe_cli-0.9.0}/lithe_cli/setup.py +0 -0
- {lithe_cli-0.8.8 → lithe_cli-0.9.0}/lithe_cli/ui.py +0 -0
- {lithe_cli-0.8.8 → lithe_cli-0.9.0}/lithe_cli.egg-info/dependency_links.txt +0 -0
- {lithe_cli-0.8.8 → lithe_cli-0.9.0}/lithe_cli.egg-info/entry_points.txt +0 -0
- {lithe_cli-0.8.8 → lithe_cli-0.9.0}/lithe_cli.egg-info/top_level.txt +0 -0
- {lithe_cli-0.8.8 → lithe_cli-0.9.0}/setup.cfg +0 -0
- {lithe_cli-0.8.8 → lithe_cli-0.9.0}/tests/test_cli.py +0 -0
- {lithe_cli-0.8.8 → lithe_cli-0.9.0}/tests/test_cli_sessions.py +0 -0
- {lithe_cli-0.8.8 → lithe_cli-0.9.0}/tests/test_profiles.py +0 -0
- {lithe_cli-0.8.8 → lithe_cli-0.9.0}/tests/test_tui_v2.py +0 -0
- {lithe_cli-0.8.8 → lithe_cli-0.9.0}/tests/test_workbench.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: lithe-cli
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.9.0
|
|
4
4
|
Summary: Command-line interface for the lithe agent kernel: chat, one-shot runs, undo, and run inspection.
|
|
5
5
|
License: MIT License
|
|
6
6
|
|
|
@@ -39,7 +39,7 @@ Classifier: Typing :: Typed
|
|
|
39
39
|
Requires-Python: >=3.10
|
|
40
40
|
Description-Content-Type: text/markdown
|
|
41
41
|
License-File: LICENSE
|
|
42
|
-
Requires-Dist: lithe>=0.9.
|
|
42
|
+
Requires-Dist: lithe>=0.9.21
|
|
43
43
|
Requires-Dist: prompt-toolkit>=3.0.38
|
|
44
44
|
Requires-Dist: textual>=1.0
|
|
45
45
|
Provides-Extra: dev
|
|
@@ -148,7 +148,12 @@ $ lithe run "总结 README.md 的要点,存到 SUMMARY.md"
|
|
|
148
148
|
usage/context gauges; `--max-steps` caps the tool loop;
|
|
149
149
|
`--context-window` enables fullness gauges; `--reasoning-effort LEVEL`
|
|
150
150
|
sets the reasoning intensity for one invocation (flag > profile field;
|
|
151
|
-
`/reasoning` adjusts it in-session).
|
|
151
|
+
`/reasoning` adjusts it in-session). Run budgets end the turn with
|
|
152
|
+
status `budget_exceeded` once crossed: `--max-cost USD` (needs a
|
|
153
|
+
`pricing` table in the profile on endpoints that report no usage cost)
|
|
154
|
+
and `--max-tokens N` (cumulative); both show progress lines in the
|
|
155
|
+
sidebar and adjust via `/set` (`off` clears). Sampling:
|
|
156
|
+
`--temperature` / `--max-output-tokens` (flag > profile field).
|
|
152
157
|
|
|
153
158
|
### Full-screen interface
|
|
154
159
|
|
|
@@ -160,7 +165,7 @@ the conversation; the right sidebar is five fixed sections — 会话(current
|
|
|
160
165
|
工具/待办、用量:
|
|
161
166
|
|
|
162
167
|
```text
|
|
163
|
-
lithe 0.
|
|
168
|
+
lithe 0.9.0 · ▣ #12 重构计划 │ zhipu · glm-4.6 │ ~/myproj ● 运行中
|
|
164
169
|
╭──────────────────────────────────────╮╭──────────────────────────╮
|
|
165
170
|
│ 把 a.txt 改成三行待办清单 ││ ◆ 会话 │
|
|
166
171
|
│ ◆ edit_file · 局部修改 a.txt ││ #12 重构计划 ● │
|
|
@@ -186,10 +191,14 @@ you come back. Typing `/` shows matching commands above the prompt (`Tab`
|
|
|
186
191
|
accepts; `/model`, `/profile`, `/set` complete their arguments too),
|
|
187
192
|
and `↑`/`↓` recall the persistent input history. `Ctrl+C` cancels the
|
|
188
193
|
current turn (a second press during the same turn force-exits) and exits
|
|
189
|
-
when idle.
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
194
|
+
when idle. Plain text typed mid-turn **steers** the running agent: it is
|
|
195
|
+
queued into the kernel's steering inbox and injected as a user message at
|
|
196
|
+
the next step boundary (rendered in the transcript; persistently
|
|
197
|
+
recorded), so you can correct course while it works — texts that cannot
|
|
198
|
+
be injected before the turn ends are honestly reported as dropped. Slash
|
|
199
|
+
commands work while a turn runs. The transcript follows new output only
|
|
200
|
+
while you're at the bottom — scroll up to re-read and your position
|
|
201
|
+
sticks.
|
|
193
202
|
|
|
194
203
|
Text selection uses the terminal's native `Shift+drag` (hide the sidebar
|
|
195
204
|
with F2 first if it grabs both panes). Pipes and CI keep the plain
|
|
@@ -249,11 +258,15 @@ The kernel ships these as bundles; the CLI grants them per flag:
|
|
|
249
258
|
| `--vision` | `image_info` / `analyze_image` | image probe is stdlib-only; analysis routes one vision call to the main endpoint |
|
|
250
259
|
| `--document` | `document_info` / `analyze_document` | PDF/DOCX/XLSX/PPTX reading on the main endpoint; `/set document` toggles in-session |
|
|
251
260
|
| `--document-format` | (dialect for `analyze_document`) | `inline-file` (OpenRouter family) / `files-api` (strict OpenAI upload) / `none` (probe only); default: profile field `document_format`, else provider preset |
|
|
261
|
+
| `--max-cost USD` | (run budget) | the turn ends `budget_exceeded` once cumulative cost crosses it; on endpoints reporting no `usage.cost` add a profile `pricing` table (`{"prompt": 3, "completion": 15}` per 1M) — the preset providers' known prices work too |
|
|
262
|
+
| `--max-tokens N` | (run budget) | cumulative token budget for the turn; `--max-output-tokens N` is the different per-call cap |
|
|
263
|
+
| `--subagents` | `delegate` / `delegate_parallel` | kernel delegation on the default roster — `researcher` (read-only lookup, gains vision/document tools with those flags), `coder` (file edits + `run_code` with `--code`), `operator` (`run_command`/`download_file`, present only with `--shell`/`--download`); children inherit the endpoint and budgets, parallel workers share one live cost ceiling; `/set subagents` toggles in-session |
|
|
252
264
|
| `--mcp SPEC` | whatever the servers expose | JSON array/object or `@file` (env `LITHE_MCP`); stdio and streamable-http; failed servers degrade gracefully |
|
|
253
265
|
|
|
254
266
|
```bash
|
|
255
267
|
$ lithe run --code "用 run_code 验证 results.csv 的行数"
|
|
256
268
|
$ lithe run --document "总结 report.pdf 的结论,存到 NOTES.md"
|
|
269
|
+
$ lithe run --subagents "先让 researcher 摸清 src 结构,再让 coder 分头改"
|
|
257
270
|
$ lithe run --shell "检查当前目录的项目状态"
|
|
258
271
|
$ lithe chat --skills ~/my-skills --mcp @~/mcp.json
|
|
259
272
|
```
|
|
@@ -99,7 +99,12 @@ $ lithe run "总结 README.md 的要点,存到 SUMMARY.md"
|
|
|
99
99
|
usage/context gauges; `--max-steps` caps the tool loop;
|
|
100
100
|
`--context-window` enables fullness gauges; `--reasoning-effort LEVEL`
|
|
101
101
|
sets the reasoning intensity for one invocation (flag > profile field;
|
|
102
|
-
`/reasoning` adjusts it in-session).
|
|
102
|
+
`/reasoning` adjusts it in-session). Run budgets end the turn with
|
|
103
|
+
status `budget_exceeded` once crossed: `--max-cost USD` (needs a
|
|
104
|
+
`pricing` table in the profile on endpoints that report no usage cost)
|
|
105
|
+
and `--max-tokens N` (cumulative); both show progress lines in the
|
|
106
|
+
sidebar and adjust via `/set` (`off` clears). Sampling:
|
|
107
|
+
`--temperature` / `--max-output-tokens` (flag > profile field).
|
|
103
108
|
|
|
104
109
|
### Full-screen interface
|
|
105
110
|
|
|
@@ -111,7 +116,7 @@ the conversation; the right sidebar is five fixed sections — 会话(current
|
|
|
111
116
|
工具/待办、用量:
|
|
112
117
|
|
|
113
118
|
```text
|
|
114
|
-
lithe 0.
|
|
119
|
+
lithe 0.9.0 · ▣ #12 重构计划 │ zhipu · glm-4.6 │ ~/myproj ● 运行中
|
|
115
120
|
╭──────────────────────────────────────╮╭──────────────────────────╮
|
|
116
121
|
│ 把 a.txt 改成三行待办清单 ││ ◆ 会话 │
|
|
117
122
|
│ ◆ edit_file · 局部修改 a.txt ││ #12 重构计划 ● │
|
|
@@ -137,10 +142,14 @@ you come back. Typing `/` shows matching commands above the prompt (`Tab`
|
|
|
137
142
|
accepts; `/model`, `/profile`, `/set` complete their arguments too),
|
|
138
143
|
and `↑`/`↓` recall the persistent input history. `Ctrl+C` cancels the
|
|
139
144
|
current turn (a second press during the same turn force-exits) and exits
|
|
140
|
-
when idle.
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
145
|
+
when idle. Plain text typed mid-turn **steers** the running agent: it is
|
|
146
|
+
queued into the kernel's steering inbox and injected as a user message at
|
|
147
|
+
the next step boundary (rendered in the transcript; persistently
|
|
148
|
+
recorded), so you can correct course while it works — texts that cannot
|
|
149
|
+
be injected before the turn ends are honestly reported as dropped. Slash
|
|
150
|
+
commands work while a turn runs. The transcript follows new output only
|
|
151
|
+
while you're at the bottom — scroll up to re-read and your position
|
|
152
|
+
sticks.
|
|
144
153
|
|
|
145
154
|
Text selection uses the terminal's native `Shift+drag` (hide the sidebar
|
|
146
155
|
with F2 first if it grabs both panes). Pipes and CI keep the plain
|
|
@@ -200,11 +209,15 @@ The kernel ships these as bundles; the CLI grants them per flag:
|
|
|
200
209
|
| `--vision` | `image_info` / `analyze_image` | image probe is stdlib-only; analysis routes one vision call to the main endpoint |
|
|
201
210
|
| `--document` | `document_info` / `analyze_document` | PDF/DOCX/XLSX/PPTX reading on the main endpoint; `/set document` toggles in-session |
|
|
202
211
|
| `--document-format` | (dialect for `analyze_document`) | `inline-file` (OpenRouter family) / `files-api` (strict OpenAI upload) / `none` (probe only); default: profile field `document_format`, else provider preset |
|
|
212
|
+
| `--max-cost USD` | (run budget) | the turn ends `budget_exceeded` once cumulative cost crosses it; on endpoints reporting no `usage.cost` add a profile `pricing` table (`{"prompt": 3, "completion": 15}` per 1M) — the preset providers' known prices work too |
|
|
213
|
+
| `--max-tokens N` | (run budget) | cumulative token budget for the turn; `--max-output-tokens N` is the different per-call cap |
|
|
214
|
+
| `--subagents` | `delegate` / `delegate_parallel` | kernel delegation on the default roster — `researcher` (read-only lookup, gains vision/document tools with those flags), `coder` (file edits + `run_code` with `--code`), `operator` (`run_command`/`download_file`, present only with `--shell`/`--download`); children inherit the endpoint and budgets, parallel workers share one live cost ceiling; `/set subagents` toggles in-session |
|
|
203
215
|
| `--mcp SPEC` | whatever the servers expose | JSON array/object or `@file` (env `LITHE_MCP`); stdio and streamable-http; failed servers degrade gracefully |
|
|
204
216
|
|
|
205
217
|
```bash
|
|
206
218
|
$ lithe run --code "用 run_code 验证 results.csv 的行数"
|
|
207
219
|
$ lithe run --document "总结 report.pdf 的结论,存到 NOTES.md"
|
|
220
|
+
$ lithe run --subagents "先让 researcher 摸清 src 结构,再让 coder 分头改"
|
|
208
221
|
$ lithe run --shell "检查当前目录的项目状态"
|
|
209
222
|
$ lithe chat --skills ~/my-skills --mcp @~/mcp.json
|
|
210
223
|
```
|
|
@@ -12,7 +12,8 @@ Everything here maps lithe's host contract onto CLI defaults:
|
|
|
12
12
|
library), ``--vision`` (image probe/analysis), ``--document``
|
|
13
13
|
(PDF/OOXML probe/analysis — dialect from ``--document-format`` > profile
|
|
14
14
|
``document_format`` > provider preset), ``--download`` (SSRF-guarded
|
|
15
|
-
network fetch)
|
|
15
|
+
network fetch), ``--mcp`` (external MCP servers) and ``--subagents``
|
|
16
|
+
(kernel delegation on the CLI's default roster);
|
|
16
17
|
- undo — the bundled tools register reverters, so ``lithe undo`` works with
|
|
17
18
|
zero configuration.
|
|
18
19
|
"""
|
|
@@ -87,6 +88,10 @@ def build_system_prompt(cfg: Config) -> str:
|
|
|
87
88
|
if cfg.document:
|
|
88
89
|
extras.append("可以用 analyze_document 直接阅读 PDF/DOCX/XLSX/PPTX 文档并回答关于它的具体问题;"
|
|
89
90
|
"确定元信息(格式/页数)先用 document_info。")
|
|
91
|
+
if cfg.subagents:
|
|
92
|
+
extras.append("可以用 delegate 把独立子任务委派给子代理(可用名单见工具说明:检索/编码/操作),"
|
|
93
|
+
"互不依赖的子任务用 delegate_parallel 并行委派;"
|
|
94
|
+
"子代理与本对话共享预算,汇报时合并它们的结果。")
|
|
90
95
|
if not extras:
|
|
91
96
|
return SYSTEM_PROMPT_BASE
|
|
92
97
|
return SYSTEM_PROMPT_BASE + "".join(extras)
|
|
@@ -109,6 +114,14 @@ def build_llm(cfg: Config) -> LLMConfig:
|
|
|
109
114
|
# Explicit dialect (flag/profile) overrides the preset default;
|
|
110
115
|
# apply_preset skips the None override so the preset fills in.
|
|
111
116
|
"document_format": cfg.document_format,
|
|
117
|
+
# Sampling + vendor passthrough + pricing: None skips (preset may
|
|
118
|
+
# fill extra_body/default_headers; dict fields merge per key with
|
|
119
|
+
# the explicit value winning per key).
|
|
120
|
+
"temperature": cfg.temperature,
|
|
121
|
+
"max_tokens": cfg.max_tokens,
|
|
122
|
+
"extra_body": cfg.extra_body,
|
|
123
|
+
"default_headers": cfg.default_headers,
|
|
124
|
+
"pricing": cfg.pricing,
|
|
112
125
|
}
|
|
113
126
|
# The CLI's transport field defaults to "chat" and is only overridden by
|
|
114
127
|
# offline tests (custom transports); the default must not clobber a
|
|
@@ -183,10 +196,94 @@ def build_host(cfg: Config, reg: ToolRegistry) -> AgentHost:
|
|
|
183
196
|
build_llm(cfg),
|
|
184
197
|
store,
|
|
185
198
|
max_steps=cfg.max_steps,
|
|
199
|
+
max_cost=cfg.max_cost,
|
|
200
|
+
max_total_tokens=cfg.max_total_tokens,
|
|
186
201
|
build_system_prompt=lambda ctx, mode, anchor: prompt,
|
|
187
202
|
)
|
|
188
203
|
|
|
189
204
|
|
|
205
|
+
# -- subagent delegation (--subagents) ----------------------------------------
|
|
206
|
+
#
|
|
207
|
+
# The kernel's delegation bundle (lithe.bundles.subagents) is host data: a
|
|
208
|
+
# roster of SubagentSpecs + an engine over the host. The CLI's default roster
|
|
209
|
+
# filters each spec's tool list against what is actually registered, so a
|
|
210
|
+
# capability flag (--vision, --code, …) automatically shapes the workers.
|
|
211
|
+
|
|
212
|
+
_RESEARCHER_PROMPT = (
|
|
213
|
+
"你是只读检索子代理。用文件/文档/图像工具查找、阅读并汇总信息,绝不修改、新建或删除任何文件。"
|
|
214
|
+
"输出简明的发现清单,标注出处路径;找不到就如实说找不到。"
|
|
215
|
+
)
|
|
216
|
+
_CODER_PROMPT = (
|
|
217
|
+
"你是编码子代理。先用只读工具了解现状,再做最小必要的修改"
|
|
218
|
+
"(优先 edit_file / apply_patch 局部修改,仅新建文件或确需重写时用 write_file),"
|
|
219
|
+
"可用 run_code 验证;完成后简述改了什么、为什么。"
|
|
220
|
+
)
|
|
221
|
+
_OPERATOR_PROMPT = (
|
|
222
|
+
"你是操作子代理。用 run_command 执行命令、download_file 下载文件来完成指定操作。"
|
|
223
|
+
"命令以当前用户权限运行且副作用不可撤销,执行前先确认必要性;输出关键结果与退出码。"
|
|
224
|
+
)
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
def register_subagents(cfg: Config, host: AgentHost, reg: ToolRegistry):
|
|
228
|
+
"""Register delegate/delegate_parallel over the CLI's default roster.
|
|
229
|
+
|
|
230
|
+
Must run after ``build_host`` (the engine shares the host's registry,
|
|
231
|
+
store and LLM config — children inherit the endpoint, retry policy and
|
|
232
|
+
budgets; parallel siblings share one live cost ceiling, kernel ≥0.9.20).
|
|
233
|
+
Returns the engine (roster inspection for hosts and tests).
|
|
234
|
+
"""
|
|
235
|
+
from lithe.bundles.subagents import (
|
|
236
|
+
SubagentEngine,
|
|
237
|
+
SubagentRoster,
|
|
238
|
+
SubagentSpec,
|
|
239
|
+
register_delegate_tools,
|
|
240
|
+
)
|
|
241
|
+
|
|
242
|
+
available = set(reg.names())
|
|
243
|
+
|
|
244
|
+
def pick(names: list[str]) -> list[str]:
|
|
245
|
+
return [n for n in names if n in available]
|
|
246
|
+
|
|
247
|
+
specs = [
|
|
248
|
+
SubagentSpec(
|
|
249
|
+
"researcher", "检索员",
|
|
250
|
+
"只读检索:在工作区查找、阅读、汇总信息与文档(不修改文件)",
|
|
251
|
+
pick(["read_file", "list_files", "search_files", "glob_files",
|
|
252
|
+
"image_info", "analyze_image",
|
|
253
|
+
"document_info", "analyze_document"]),
|
|
254
|
+
_RESEARCHER_PROMPT, read_only=True),
|
|
255
|
+
SubagentSpec(
|
|
256
|
+
"coder", "编码员",
|
|
257
|
+
"读写代码:定位、修改、验证工作区内的代码",
|
|
258
|
+
pick(["read_file", "write_file", "edit_file", "apply_patch",
|
|
259
|
+
"list_files", "search_files", "glob_files",
|
|
260
|
+
"run_code", "run_file"]),
|
|
261
|
+
_CODER_PROMPT),
|
|
262
|
+
]
|
|
263
|
+
op_core = pick(["run_command", "download_file"])
|
|
264
|
+
if op_core:
|
|
265
|
+
specs.append(SubagentSpec(
|
|
266
|
+
"operator", "操作员",
|
|
267
|
+
"执行主机命令与网络下载等操作",
|
|
268
|
+
op_core + pick(["read_file", "list_files"]),
|
|
269
|
+
_OPERATOR_PROMPT))
|
|
270
|
+
# A spec whose tool list filtered to nothing can do nothing meaningful;
|
|
271
|
+
# researcher/coder always keep the ever-present file tools.
|
|
272
|
+
specs = [s for s in specs if s.tools]
|
|
273
|
+
engine = SubagentEngine(host, SubagentRoster(specs))
|
|
274
|
+
register_delegate_tools(reg, engine, parallel=True)
|
|
275
|
+
return engine
|
|
276
|
+
|
|
277
|
+
|
|
278
|
+
def tool_names(cfg: Config) -> list[str]:
|
|
279
|
+
"""Sorted tool names for /tools: the registry plus the delegation pair
|
|
280
|
+
when enabled (registered later against the host, same names)."""
|
|
281
|
+
names = sorted(build_registry(cfg).names())
|
|
282
|
+
if cfg.subagents:
|
|
283
|
+
names = sorted(names + ["delegate", "delegate_parallel"])
|
|
284
|
+
return names
|
|
285
|
+
|
|
286
|
+
|
|
190
287
|
def render_event(
|
|
191
288
|
ev: dict,
|
|
192
289
|
verbose: bool = False,
|
|
@@ -247,6 +344,7 @@ async def execute(
|
|
|
247
344
|
on_event=None,
|
|
248
345
|
stop=None,
|
|
249
346
|
conversation_id: int | None = None,
|
|
347
|
+
inbox=None,
|
|
250
348
|
) -> tuple[str, dict, Any]:
|
|
251
349
|
"""Run one task end-to-end; returns (run_id, done_event, host).
|
|
252
350
|
|
|
@@ -255,10 +353,14 @@ async def execute(
|
|
|
255
353
|
footer — the caller renders from the events instead. ``stop`` is the
|
|
256
354
|
kernel's cancellation handle, surfaced so Ctrl+C can cancel a turn
|
|
257
355
|
without killing the process. ``conversation_id`` attaches the run to a
|
|
258
|
-
stored session (kernel host already consumes ctx.extra).
|
|
356
|
+
stored session (kernel host already consumes ctx.extra). ``inbox`` is
|
|
357
|
+
the steering channel: a queue of user texts the kernel drains at step
|
|
358
|
+
boundaries and injects as user messages (see AgentRuntime.run).
|
|
259
359
|
"""
|
|
260
360
|
reg = build_registry(cfg)
|
|
261
361
|
host = build_host(cfg, reg)
|
|
362
|
+
if cfg.subagents:
|
|
363
|
+
register_subagents(cfg, host, reg)
|
|
262
364
|
rid = run_id or uuid.uuid4().hex[:12]
|
|
263
365
|
extra = {"conversation_id": conversation_id} if conversation_id is not None else {}
|
|
264
366
|
ctx = AgentContext(run_id=rid, user_id=cfg.user_id, extra=extra)
|
|
@@ -280,7 +382,8 @@ async def execute(
|
|
|
280
382
|
ev: dict = {}
|
|
281
383
|
pending: dict[str, float] = {}
|
|
282
384
|
try:
|
|
283
|
-
async for ev in host.run(ctx, task, history=history, stop=stop
|
|
385
|
+
async for ev in host.run(ctx, task, history=history, stop=stop,
|
|
386
|
+
inbox=inbox):
|
|
284
387
|
if on_event is not None:
|
|
285
388
|
on_event(ev)
|
|
286
389
|
else:
|
|
@@ -67,6 +67,30 @@ class Config:
|
|
|
67
67
|
# in-session profile switches re-resolve it). None = not explicit.
|
|
68
68
|
document_format: str | None = None
|
|
69
69
|
document: bool = False
|
|
70
|
+
# Subagent delegation (kernel bundles.subagents): grants delegate /
|
|
71
|
+
# delegate_parallel on the CLI's default roster. Off by default — each
|
|
72
|
+
# delegation is a full agent run, so token spend multiplies.
|
|
73
|
+
subagents: bool = False
|
|
74
|
+
# Run budgets (kernel AgentHost): the run ends with status
|
|
75
|
+
# "budget_exceeded" once cumulative cost / tokens cross the cap. None
|
|
76
|
+
# disables the cap.
|
|
77
|
+
max_cost: float | None = None
|
|
78
|
+
max_total_tokens: int | None = None
|
|
79
|
+
# Sampling knobs forwarded to LLMConfig (None = endpoint default).
|
|
80
|
+
temperature: float | None = None
|
|
81
|
+
# Per-call output cap (LLMConfig.max_tokens); the run-level budget is
|
|
82
|
+
# max_total_tokens above — different things despite similar names.
|
|
83
|
+
max_tokens: int | None = None
|
|
84
|
+
# Vendor request fields / headers (LLMConfig passthrough). Usually
|
|
85
|
+
# contributed by a provider preset; a profile can carry its own for
|
|
86
|
+
# gateways no preset knows.
|
|
87
|
+
extra_body: dict | None = None
|
|
88
|
+
default_headers: dict | None = None
|
|
89
|
+
# Per-1M-token price table (LLMConfig.pricing): computes call cost on
|
|
90
|
+
# endpoints that report no usage.cost, which is what makes max_cost
|
|
91
|
+
# actually enforceable there. {"prompt": float, "completion": float,
|
|
92
|
+
# "cached_prompt": float?}
|
|
93
|
+
pricing: dict | None = None
|
|
70
94
|
store_dir: Path = field(default_factory=lambda: default_store_dir())
|
|
71
95
|
workspace_dir: Path = field(default_factory=lambda: Path.cwd())
|
|
72
96
|
user_id: str = DEFAULT_USER
|
|
@@ -295,6 +319,18 @@ def load_config(args: Any) -> Config:
|
|
|
295
319
|
if isinstance(document_format, str)
|
|
296
320
|
and document_format.strip() else None),
|
|
297
321
|
document=g("document", False),
|
|
322
|
+
subagents=g("subagents", False),
|
|
323
|
+
max_cost=g("max_cost", None),
|
|
324
|
+
max_total_tokens=g("max_total_tokens", None),
|
|
325
|
+
temperature=(
|
|
326
|
+
g("temperature", None) if g("temperature", None) is not None
|
|
327
|
+
else saved.get("temperature")),
|
|
328
|
+
max_tokens=(
|
|
329
|
+
g("max_tokens", None) if g("max_tokens", None) is not None
|
|
330
|
+
else saved.get("max_tokens")),
|
|
331
|
+
extra_body=saved.get("extra_body"),
|
|
332
|
+
default_headers=saved.get("default_headers"),
|
|
333
|
+
pricing=saved.get("pricing"),
|
|
298
334
|
reasoning_effort=(effort.strip() if isinstance(effort, str) and effort.strip()
|
|
299
335
|
else None),
|
|
300
336
|
store_dir=store_dir,
|
|
@@ -104,6 +104,13 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
104
104
|
help="grant document_info/analyze_document "
|
|
105
105
|
"(PDF/OOXML reading on the main endpoint)",
|
|
106
106
|
)
|
|
107
|
+
sp.add_argument(
|
|
108
|
+
"--subagents",
|
|
109
|
+
action="store_true",
|
|
110
|
+
help="grant delegate/delegate_parallel (subagent delegation on "
|
|
111
|
+
"the default roster: researcher/coder/operator; multiplies "
|
|
112
|
+
"token spend)",
|
|
113
|
+
)
|
|
107
114
|
sp.add_argument(
|
|
108
115
|
"--document-format",
|
|
109
116
|
metavar="DIALECT",
|
|
@@ -152,6 +159,36 @@ def build_parser() -> argparse.ArgumentParser:
|
|
|
152
159
|
sp.add_argument(
|
|
153
160
|
"--attempts", type=int, default=2, help="per-call retry attempts"
|
|
154
161
|
)
|
|
162
|
+
sp.add_argument(
|
|
163
|
+
"--temperature",
|
|
164
|
+
type=float,
|
|
165
|
+
default=None,
|
|
166
|
+
help="sampling temperature (default: profile field, else endpoint default)",
|
|
167
|
+
)
|
|
168
|
+
sp.add_argument(
|
|
169
|
+
"--max-output-tokens",
|
|
170
|
+
dest="max_tokens",
|
|
171
|
+
type=int,
|
|
172
|
+
default=None,
|
|
173
|
+
help="per-call output token cap (default: profile max_tokens, "
|
|
174
|
+
"else endpoint default); NOT the run budget --max-tokens",
|
|
175
|
+
)
|
|
176
|
+
sp.add_argument(
|
|
177
|
+
"--max-cost",
|
|
178
|
+
type=float,
|
|
179
|
+
default=None,
|
|
180
|
+
help="run cost budget in USD: the run ends with status "
|
|
181
|
+
"budget_exceeded once cumulative cost crosses it (needs a "
|
|
182
|
+
"pricing table on endpoints that report no usage cost)",
|
|
183
|
+
)
|
|
184
|
+
sp.add_argument(
|
|
185
|
+
"--max-tokens",
|
|
186
|
+
dest="max_total_tokens",
|
|
187
|
+
type=int,
|
|
188
|
+
default=None,
|
|
189
|
+
help="run total-token budget: ends with budget_exceeded once "
|
|
190
|
+
"cumulative tokens cross it",
|
|
191
|
+
)
|
|
155
192
|
sp.add_argument(
|
|
156
193
|
"--reasoning-effort",
|
|
157
194
|
metavar="LEVEL",
|
|
@@ -366,6 +403,7 @@ def _cmd_doctor() -> int:
|
|
|
366
403
|
api_key = base_url = model = profile = store = workspace = user = None
|
|
367
404
|
skills = mcp = None
|
|
368
405
|
download = code = shell = vision = color = no_color = verbose = False
|
|
406
|
+
subagents = document = False
|
|
369
407
|
|
|
370
408
|
cfg = load_config(_Args())
|
|
371
409
|
print(ui.s(f"lithe-cli {__version__}(lithe {lithe_version})", CYAN, BOLD))
|
|
@@ -442,6 +480,9 @@ def _cmd_doctor() -> int:
|
|
|
442
480
|
print(ui.kv("mcp", f"{len(cfg.mcp_servers)} 个服务器:{names}"))
|
|
443
481
|
else:
|
|
444
482
|
print(ui.kv("mcp", "未配置(--mcp 或环境变量 LITHE_MCP)"))
|
|
483
|
+
delegation = "已启用(delegate 可委派子代理,token 花费会放大)" \
|
|
484
|
+
if cfg.subagents else "未启用(--subagents 显式授权)"
|
|
485
|
+
print(ui.kv("subagents", delegation))
|
|
445
486
|
print(ui.kv("color", "on" if ui.color else "off"))
|
|
446
487
|
return 0
|
|
447
488
|
|
|
@@ -503,6 +544,24 @@ def _cmd_config(args: Any) -> int:
|
|
|
503
544
|
print(ui.kv("provider", saved["provider"]))
|
|
504
545
|
if saved.get("document_format"):
|
|
505
546
|
print(ui.kv("document_format", saved["document_format"]))
|
|
547
|
+
ep = store.endpoint() # full dict: sampling/vendor/pricing fields
|
|
548
|
+
if ep.get("context_window"):
|
|
549
|
+
print(ui.kv("context_window", f"{ep['context_window']:,}"))
|
|
550
|
+
if ep.get("temperature") is not None:
|
|
551
|
+
print(ui.kv("temperature", ep["temperature"]))
|
|
552
|
+
if ep.get("max_tokens"):
|
|
553
|
+
print(ui.kv("max_tokens", f"{ep['max_tokens']:,}"))
|
|
554
|
+
if ep.get("extra_body"):
|
|
555
|
+
import json as _json
|
|
556
|
+
|
|
557
|
+
print(ui.kv("extra_body",
|
|
558
|
+
_json.dumps(ep["extra_body"], ensure_ascii=False)))
|
|
559
|
+
if ep.get("default_headers"):
|
|
560
|
+
print(ui.kv("default_headers",
|
|
561
|
+
",".join(ep["default_headers"])))
|
|
562
|
+
if ep.get("pricing"):
|
|
563
|
+
print(ui.kv("pricing", "、".join(
|
|
564
|
+
f"{k}=${v}/1M" for k, v in ep["pricing"].items())))
|
|
506
565
|
print(ui.kv("base_url", saved["base_url"]))
|
|
507
566
|
print(ui.kv("api_key", masked))
|
|
508
567
|
print(ui.kv("model", saved["model"]))
|
|
@@ -83,6 +83,25 @@ def _clean_endpoint(data: dict) -> dict:
|
|
|
83
83
|
v = data.get(k)
|
|
84
84
|
if isinstance(v, int) and v > 0:
|
|
85
85
|
out[k] = v
|
|
86
|
+
temperature = data.get("temperature")
|
|
87
|
+
if isinstance(temperature, (int, float)) and not isinstance(temperature, bool):
|
|
88
|
+
out["temperature"] = float(temperature)
|
|
89
|
+
max_tokens = data.get("max_tokens")
|
|
90
|
+
if isinstance(max_tokens, int) and not isinstance(max_tokens, bool) \
|
|
91
|
+
and max_tokens > 0:
|
|
92
|
+
out["max_tokens"] = max_tokens
|
|
93
|
+
extra_body = data.get("extra_body")
|
|
94
|
+
if isinstance(extra_body, dict) and extra_body:
|
|
95
|
+
out["extra_body"] = extra_body
|
|
96
|
+
headers = data.get("default_headers")
|
|
97
|
+
if isinstance(headers, dict) and headers:
|
|
98
|
+
out["default_headers"] = headers
|
|
99
|
+
pricing = data.get("pricing")
|
|
100
|
+
if isinstance(pricing, dict) and pricing:
|
|
101
|
+
# keep numeric entries only; LLMConfig validates the exact contract
|
|
102
|
+
out["pricing"] = {k: v for k, v in pricing.items()
|
|
103
|
+
if isinstance(v, (int, float))
|
|
104
|
+
and not isinstance(v, bool)}
|
|
86
105
|
cm = data.get("cached_models")
|
|
87
106
|
if isinstance(cm, list) and cm:
|
|
88
107
|
out["cached_models"] = [str(m) for m in cm if str(m).strip()]
|
|
@@ -124,6 +124,10 @@ def sidebar_markup(state: TuiState) -> str:
|
|
|
124
124
|
out.append(f"合计 {tokens:,}")
|
|
125
125
|
out.append(f"本轮费用 ${turn_cost:.4f}")
|
|
126
126
|
out.append(f"累计费用 ${cost:.4f}")
|
|
127
|
+
if state.max_cost is not None:
|
|
128
|
+
out.append(f"[dim]成本预算 ${cost:.4f} / ${state.max_cost:.2f}[/]")
|
|
129
|
+
if state.max_total_tokens is not None:
|
|
130
|
+
out.append(f"[dim]token 预算 {tokens:,} / {state.max_total_tokens:,}[/]")
|
|
127
131
|
out.append(f"上下文 {context}")
|
|
128
132
|
return "\n".join(out)
|
|
129
133
|
|
|
@@ -447,7 +451,7 @@ class LitheApp(App):
|
|
|
447
451
|
title = ""
|
|
448
452
|
if cid is not None:
|
|
449
453
|
title = (self.wb.sessions.get(cid) or {}).get("title", "")
|
|
450
|
-
|
|
454
|
+
st = TuiState(
|
|
451
455
|
self.cfg.model or "(scripted)",
|
|
452
456
|
str(self.cfg.workspace_dir.resolve()),
|
|
453
457
|
self.cfg.max_steps,
|
|
@@ -456,12 +460,18 @@ class LitheApp(App):
|
|
|
456
460
|
session_id=cid,
|
|
457
461
|
session_title=title,
|
|
458
462
|
)
|
|
463
|
+
st.max_cost = self.cfg.max_cost
|
|
464
|
+
st.max_total_tokens = self.cfg.max_total_tokens
|
|
465
|
+
return st
|
|
459
466
|
|
|
460
467
|
def _refresh_meta(self) -> None:
|
|
461
468
|
st = self.state
|
|
462
469
|
st.model = self.cfg.model or "(scripted)"
|
|
463
470
|
st.profile = self.cfg.profile or ""
|
|
464
471
|
st.reasoning_effort = self.cfg.reasoning_effort
|
|
472
|
+
st.max_steps = self.cfg.max_steps
|
|
473
|
+
st.max_cost = self.cfg.max_cost
|
|
474
|
+
st.max_total_tokens = self.cfg.max_total_tokens
|
|
465
475
|
if self.wb.current is not None:
|
|
466
476
|
st.session_id = self.wb.current["id"]
|
|
467
477
|
st.session_title = self.wb.current.get("title") or ""
|
|
@@ -604,11 +614,18 @@ class LitheApp(App):
|
|
|
604
614
|
if not line:
|
|
605
615
|
return
|
|
606
616
|
if self.state.running and not line.startswith("/"):
|
|
607
|
-
# Plain text mid-turn
|
|
608
|
-
#
|
|
609
|
-
#
|
|
610
|
-
#
|
|
611
|
-
#
|
|
617
|
+
# Plain text mid-turn steers the running turn: queued into the
|
|
618
|
+
# kernel's inbox and injected as a user message at the next
|
|
619
|
+
# step boundary (user_injected event renders the line). When
|
|
620
|
+
# no turn is actually draining (one-shot mode), fall back to
|
|
621
|
+
# putting the text back in the input box. Slash commands still
|
|
622
|
+
# dispatch below — the workbench supports them mid-turn.
|
|
623
|
+
if self.wb.steer(line, self._current_cid()):
|
|
624
|
+
from .ui import truncate
|
|
625
|
+
self.state.say(
|
|
626
|
+
"dim", f"(已排队,将在当前步骤后注入:{truncate(line, 48)})")
|
|
627
|
+
self._sync_feed()
|
|
628
|
+
return
|
|
612
629
|
self.query_one("#prompt", HistoryInput).value = line
|
|
613
630
|
self.state.say("warn", "本轮还在进行中,未发送;文本已放回输入框,命令仍可用")
|
|
614
631
|
self._sync_feed()
|
|
@@ -83,6 +83,9 @@ class TuiState:
|
|
|
83
83
|
self.context_window = None
|
|
84
84
|
self.context_percent = None
|
|
85
85
|
self.reasoning_effort: str | None = None
|
|
86
|
+
# Run budgets (for the sidebar progress lines); None = no cap.
|
|
87
|
+
self.max_cost: float | None = None
|
|
88
|
+
self.max_total_tokens: int | None = None
|
|
86
89
|
self.tools: list[dict] = []
|
|
87
90
|
self.feed: list[tuple[str, str]] = []
|
|
88
91
|
self.streaming = ""
|
|
@@ -208,6 +211,11 @@ class TuiState:
|
|
|
208
211
|
self.say("err", str(ev.get("message") or "运行出错"))
|
|
209
212
|
elif kind == "cancelled":
|
|
210
213
|
self.say("warn", "(已取消)")
|
|
214
|
+
elif kind == "user_injected":
|
|
215
|
+
# Steering: a queued user text the kernel injected mid-run at a
|
|
216
|
+
# step boundary; render it as a user line so the transcript
|
|
217
|
+
# shows why the model's course changed.
|
|
218
|
+
self.say("user", str(ev.get("text") or ""))
|
|
211
219
|
elif kind == "done":
|
|
212
220
|
status = str(ev.get("status") or _STATUS_DONE)
|
|
213
221
|
self.last_status = status
|