Fix LLM call limits for non-ADK runtimes - #1038
Open
FirstayZheng wants to merge 1 commit into
Open
Conversation
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.
背景
RunConfig(max_llm_calls=...)和MODEL_AGENT_MAX_LLM_CALLS依赖 ADK 原生BaseLlmFlow._call_llm_async在真正模型调用前执行invocation_context.increment_llm_call_count()。Codex 和 PiAgent runtime 绕过了 ADK 原生 LLM flow,因此此前这些 runtime 不会消耗 LLM 调用预算,导致 max_llm_calls 实际失效。修复内容
Codex runtime:
ResponsesShim的 turn context 中新增before_model_call回调。litellm.aresponses(...)前调用该回调。ctx.increment_llm_call_count。LlmCallsLimitExceededError,避免实际请求模型。PiAgent runtime:
client.prompt(prompt)前执行一次ctx.increment_llm_call_count()。测试:
client.prompt(prompt)用例。验证
已执行:
结果:
86 passed。另跑过全量
pytest,当前仓库有 4 个与本次 runtime 改动无关的既有/非相关失败:两个 generated-agent debug 用例在全量顺序下 504 但单跑通过;两个 Studio RBAC media audit log 用例单跑仍因caplog抓不到项目自定义 stdout logger 失败。手动集成验证:
LlmCallsLimitExceededError,backend_calls=1。client.prompt(prompt)前抛出LlmCallsLimitExceededError,fake Pi 未收到 prompt。