perf(agent): CLI 模式编排 chat 通道短路绕过 litellm 启动开销#129
Merged
Conversation
本机 agentic CLI 模式下,编排自有步骤(路由/judge/summary)的 chat 通道 直接调本机 CLI、不再 import pr_agent / litellm。CLI 路径本就绕过 litellm, 无谓拉起整套 import 会给每次 chat 子进程白增数百 ms~1s+ 启动开销,而一个 编排流程要调多次。 - cli/install.py: 子进程逻辑抽成自包含的 run_cli_chat; _install_cli_chat_completion(服务 pr-agent 工具 run)改为薄包装委托它, 工具 run 路径零行为变化。 - chat.py: CLI 模式直接调 run_cli_chat 返回,跳过 pr_agent/litellm import; API 模式保持原 litellm 路径(litellm 即 HTTP 客户端、不可绕)。 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
背景
本机 agentic CLI 模式下,编排 chat 通道(
meebox_pragent_shim.chat)无论 provider 都先import pr_agent+import litellm才能拿到被 shim 替换的chat_completion。但 CLI 路径的真实调用本就完全绕过 litellm(子进程逻辑自包含),这套 import 纯属白付——每次 chat 子进程多扛数百 ms~1s+ 启动开销,而一个编排流程(路由 / judge / summary)要调多次,累计可观。改动
run_cli_chat(bin, system, user)(仅依赖 shim 内 runtime/usage/specs,无 pr_agent/litellm)。_install_cli_chat_completion(服务 pr-agent 工具 run)改为薄包装委托它——工具 run 路径零行为变化。MEEBOX_CLI_MODE)直接调run_cli_chat返回,完全跳过import pr_agent/import litellm;API 模式保持原 litellm 路径不动(litellm 即 HTTP 客户端、不可绕)。验证
定向冒烟(嵌入式 CPython):
pr_agent/litellm均未 import,正确返回文本,usage 哨兵正确(prompt 15=11+4cache、completion 7、turns 3)。chat_completion仍返回(text, "stop")契约。四步把关:
lint✅typecheck✅build✅。test仅repo-mirror-manager.test.ts6 项失败,已切干净 dev 比对确认完全相同(既有的沙箱 git 环境失败),与本改动无关。shim 已prepare:pragent同步进 vendor。🤖 Generated with Claude Code