Skip to content

feat(agents): 插件注入模型清单,Core 管模型的显示开关和推理强度、速度的选择 - #263

Merged
xiaoyumuxi merged 1 commit into
mainfrom
feat/agent-model-catalog
Dec 3, 2026
Merged

xiaoyumuxi merged 1 commit into
mainfrom
feat/agent-model-catalog

Conversation

@xiaoyumuxi

@xiaoyumuxi xiaoyumuxi commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

关联

改动

都是 API-45、agents 能力 0 内的补充,不升版本。插件后端协议沿用 providers 的 read/edit,没有新增插件函数;四个 SDK 都没有 providers 的类型化代码,只更新了 README 说明。

一、插件注入模型清单

  • providers read 快照新增以下字段:
    • models:每项 {id, name?, provider?, efforts?, defaultEffort?, speeds?, defaultSpeed?, contextWindow?, description?};
    • efforts、speeds:CLI 提供的推理强度和速度档,每项 {id, name?};
    • effort、speed:正在用的值,每项 {id, source?},source 是来源层;
    • modelMenu 与 targets.modelMenu:CLI 自己的模型菜单。
  • Core 的校验:
    • 模型最多 512 个,ID 不重复,provider 必须是快照里的供应商;
    • 每个模型的 efforts、speeds 必须是 Agent 所提供的子集,默认值也要在其中;
    • contextWindow 取 1..=1e9;description 最长 1024 字符;efforts、speeds 各最多 16 项;
    • modelMenu 必须是清单的子集。
  • Core 在内存里按 Agent 缓存最近一次读到的清单。

二、显示开关

  • 被隐藏的模型按隐藏顺序存在资源库目录的 models.json,仅所有者可读写,不含机密。
  • 默认全部显示,插件新加的模型也显示。插件去掉的模型,记录保留但不显示;它再出现时仍是隐藏的。
  • 每个 Agent 最多 1024 条记录,满了先丢最早的、已经不在清单里的那条。
  • 插件声明 setModelMenu 时,Core 通过暂存副本让插件把显示的模型写进 CLI 的菜单:写前先备份,写失败就把开关恢复原状。没有声明时,开关只影响 Lithe 的选择器。
  • 新宿主命令 agentProviders.showModels {agent, show?, hide?},回答 {changed}。只接受用户发起的请求;show、hide 各最多 512 个,至少给一个,同一 ID 不能两边都出现。

三、选择

  • agentProviders.apply 的 setModel 可以带 effort、speed,需要插件也声明了 setEffort、setSpeed;另新增 setEffort、setSpeed 两种操作。
  • Core 在调用插件前先检查:
    • 值在清单里,否则报 unknownModel、unknownEffort、unknownSpeed;
    • 组合规则,否则报 unsupportedCombination:只能用模型列出的强度和速度;换模型时,沿用的强度和速度也要新模型支持。来源层为 default 的值随模型变化,不做检查。
  • 宿主经 apply 发 setModelMenu 会被拒,错误码 invalidChange。

四、整组读写(给以后的“方案”用)

  • agentProviders.readModelSettings {agent} 读出 {settings: {hidden, model?, effort?, speed?}}。
  • agentProviders.applyModelSettings {agent, settings} 整组写回:先检查全部修改,有一项被拒就什么都不改。只接受用户发起的请求。

五、错误码与日志

  • 新错误码 agentProviders.unknownModel、unknownEffort、unknownSpeed(entry_not_found),以及 agentProviders.unsupportedCombination(invalid_request)。
  • 插件清单 configuration.providers.operations 新增 setEffort、setSpeed、setModelMenu。
  • 日志 agent.providers.change_applied、change_failed 的 change 新增取值 showModels、applyModelSettings;没有新事件。

六、文档

  • 改了以下文档:
    • 契约 README;
    • 清单 schema,agents.plugin.json,新增 fixture fixtures/agents/model-catalog.json;
    • rust/contracts/rust-core-api.md;
    • domains/agents.md(中英);
    • API 总表和能力版本表的 API-45 与 agents 0 行;
    • 四个 SDK 的 README。
  • 协议更新记录:本 PR 一行写在“待合入”。
  • 顺手补齐:
    • library.rs 模块文档里资源库目录的文件清单,加上 saved-providers.json 和 models.json;
    • 契约 README 的 fixture 表加上原来漏掉的 record-read.json。

对宿主的影响

  • 桌面端接入在 1lck/Lithe-IDEA 另开 PR,同时把 PINNED_CORE_REVISION 升到本 PR 的合入提交。要做的有:
    • Agent 页行内选择模型、推理强度和速度;
    • 约 490×420 的模型选择弹层:显示中的模型加上当前模型,按供应商分组;
    • 模型显示/隐藏列表;
    • 新错误码的文案。
  • 换模型时,如果当前推理强度新模型不支持,宿主在同一次 setModel 里带上新模型的 defaultEffort,速度同理。
  • 插件侧(Lithe-IDEA/lithe-ai-plugins 的 Codex、Claude Code)另做,不由本 PR 发布:
    • 在 read 里报 models、efforts、speeds、当前 effort、speed;
    • 声明并实现 setEffort、setSpeed;
    • CLI 有自己的模型菜单时,再声明 setModelMenu。

验证

本机 macOS arm64,基于 main 3351f74(含 #262):

检查 结果
cargo test --locked -p lithe-agent-runtime -p lithe-plugin-agents -p lithe-core 全部通过(变基后 agent-runtime 129,其中模型相关 10 个;plugin-agents 21;core 975 等)
cargo clippy --locked --workspace --all-targets -- -D warnings、cargo fmt --all -- --check 通过
Windows:LIBSQLITE3_SYS_USE_PKG_CONFIG=1 cargo clippy --target x86_64-pc-windows-msvc agent-runtime、plugin-agents、diagnostics 通过;lithe-core 经插件市场依赖 zstd-sys,本机缺 Windows C 头文件编不了,留给 CI
verify-docs.mjs 通过
generate-log-events.mjs --check 通过
verify-rust-core-comments.sh 通过
verify-platform-tests.mjs 通过
sdk-e2e.mjs 通过

新测试覆盖:

  • 插件不注入时清单为空;
  • 清单校验与上限;
  • 默认显示;
  • 插件新增和去掉模型时开关的变化;
  • 选择的值不在清单里时拒绝;
  • 不支持的组合被拒;
  • 插件能写和不能写 CLI 菜单两种情况;
  • 开关和选择整组读出、写回,有一项被拒时整组不变。

已变基到含 #262 的 main:API 总表和能力版本表的 API-45、agents 0 行保留 #262 的会话说明,本 PR 的模型清单接在后面;协议更新记录里已合入的 #262 移进时间线 2026-12-03,“待合入”只剩本 PR。

@xiaoyumuxi
xiaoyumuxi force-pushed the feat/agent-model-catalog branch from 877bf0a to 5bb7cf7 Compare December 3, 2026 12:46
@xiaoyumuxi
xiaoyumuxi marked this pull request as ready for review December 3, 2026 12:46
@xiaoyumuxi
xiaoyumuxi merged commit 5364983 into main Dec 3, 2026
7 of 10 checks passed

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 4 potential issues.

Devin Review

Comment on lines +217 to +228
let model = differs(&self.model, snapshot.model.as_ref().map(|m| m.id.as_str()));
let effort = differs(
&self.effort,
snapshot.effort.as_ref().map(|e| e.id.as_str()),
);
let speed = differs(&self.speed, snapshot.speed.as_ref().map(|s| s.id.as_str()));
if let Some(model) = model {
let change = ProviderChange::SetModel {
model,
effort,
speed,
};

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Model plans silently lose selected levels

When a plan switches models, selection_changes drops requested levels that match the current model’s defaults. The new model can use different defaults. Staged verification accepts those values because the edit omitted the requested levels.

Learn more

read_model_settings saves the effective effort and speed, including defaults. A default is not a setting in the file; the CLI derives it from the selected model. During a model switch, check_selection lets omitted default levels follow the new model. shows_in then verifies only levels the edit carried.

Example: Save a plan for Model A with medium effort. Switch to Model B, whose default is also medium, after setting Model A’s saved effort explicitly to medium even though Model A defaults to low. Applying the original plan from Model B omits medium, and Model A runs at low if neither model has an explicit effort in effect in the current configuration. More directly, a plan requesting Model A at medium applied from any model defaulting to medium succeeds without restoring the requested level when Model A defaults to low.

Recommended fix: Compare requested levels with the effective values after the proposed switch, not just with the current model’s values. Carry levels that would differ, and verify all explicitly requested values on the staged snapshot before committing.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +447 to +452
let mut changed = false;
for (op, change) in changes {
changed |= self.apply_providers_checked(runtime, agent, op, change)?;
}
let hidden = settings.hidden;
changed |= self.change_hidden(runtime, agent, |_, _| Ok(hidden))?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Partial writes from rejected model plans

apply_model_settings_checked commits model selections before checking whether the CLI menu has an editable target. When menu sync returns noTarget, only the hidden switches roll back. The plan fails, but the CLI keeps the new selection.

Learn more

A model plan groups the CLI selection with the list of models hidden in Lithe. The preflight validates only selection operations; each subsequent apply_providers_checked call can commit its own file. change_hidden runs afterwards and restores only its own visibility write on failure. edit_providers rejects a missing model-menu target before calling the backend.

Example: An agent reports an editable model file and the current CLI menu, but no editable menu target in its current configuration. Apply a plan that changes the model from A to B and hides C. Core commits B and then reports agentProviders.noTarget; C is still visible.

Recommended fix: Preflight the visibility file and required menu target before committing selections. Stage and verify all requested changes before committing the group, combining changes that share a target; ensure a later failure cannot leave earlier writes committed without a partial-result response.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +378 to +384
if edited.is_err() && saved {
let _writing = self.lock_writing();
// The plugin's refusal is what the user needs to see; switches
// that cannot be put back read as the user just set them.
// log-exempt: Same failure already recorded: this put-back follows the menu edit failure returned below, which the command logs as agent.providers.change_failed and the request trace records; switches it cannot put back stay as the user set them, and Lithe's pickers show them.
let _ = store(&config, &key, &before);
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔴 Failed toggle erases saved visibility changes

When a second toggle commits while the first menu edit is pending, change_hidden can roll back both toggles. edit_staged rejects the first edit as stale, but its rollback overwrites the newer switches. The CLI keeps the newer menu.

Learn more

change_hidden saves hidden models under a write lock, then releases it before calling the plugin. The agent dispatcher does not serialize requests. A later toggle can read and update the same hidden records while the first staged edit is awaiting its plugin response. If the later edit commits first, edit_staged rejects the earlier staged copy because the CLI file changed. The earlier call then restores its original hidden list, overwriting the successful update.

Example: Hide A and let Core stage the CLI edit. While that edit is pending, hide B in another request and let it finish. The CLI hides A and B. The first edit then fails the file comparison and restores the empty hidden list, so both models reappear in Lithe.

Recommended fix: Make updates to an agent’s hidden list and CLI menu one serialized or revision-checked transaction. Avoid publishing tentative visibility records that another request can build on; a failed edit must not overwrite any later committed update.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Comment on lines +364 to +377
if in_menu == Some(shown.iter().collect()) {
return Ok(saved);
}
let menu = ProviderChange::SetModelMenu { models: shown };
let edited = self.edit_providers(
runtime,
agent,
&config,
&paths,
&snapshot,
&menu,
json!(menu),
None,
);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Unchanged CLI menu passes toggle verification

When the CLI menu differs but the plugin edits nothing, change_hidden still reports a successful visibility change. edit_staged skips verification for no-op edits. Lithe hides the model, but the CLI still lists it.

Learn more

Core compares the requested menu with the current menu before sending a staged edit. edit_staged returns Ok(false) without readback if the backend reports changed: false or the staged bytes match the original. The caller rolls back the stored switches only on an error, so it treats this result as success for visibility even though the desired menu was never verified.

Example: The CLI lists A and B. The user hides B, and the plugin reports changed: false without updating the menu. Lithe hides B and returns changed: true, but the CLI still shows B.

Recommended fix: For a menu edit, verify the effective menu even when the staged helper would normally return a no-op. If it does not match, return agentProviders.editNotApplied and restore the hidden switches.

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant