Google 借助 Gemini 4 Argon 一夜之间优化 Agent Development Kit 的 20 万行 Python 代码库
原题Google Optimizes Agent Development Kit's 200K-line Python Codebase Overnight with Gemini 4 Argon
推荐理由Google 借 Gemini 4 Argon 优化 ADK 的案例提供先基准、后改动、再人工筛选的实践,过滤再复制和懒加载两项获接受,适合学习既有代码库的可验证优化而非只看一夜完成。
读前速览
Google 使用 Gemini 4 Argon 优化 Agent Development Kit(ADK)代码库,使内存中会话准备开销降低 40%、冷包导入时间减少 21%,两项关键优化在 11 小时无人值守运行后获得采纳。
此次优化聚焦于降低 ADK 框架的开销,具体针对内存中的会话准备和包导入时间。
ADK 框架虽然功能强大,但在会话建立和包加载方面会引入延迟。目标是尽量减少这部分开销,使框架本身不会显著拖慢构建于其上的智能体的执行速度。
Gemini 4 Argon 能够成功梳理复杂的既有代码库,识别出优化机会。
与简单的代码生成任务不同,优化既有代码库需要理解模块之间的相互依赖关系以及具体的性能瓶颈。该模型展现了执行这种分析并提出有效改动的能力。
两项具体优化获得采纳:过滤会话事件和包的懒加载。
第一项优化通过在会话准备阶段过滤掉不必要的事件,减少了复制的数据量。第二项优化通过将重型包(如 `matplotlib` 后端)的导入延迟到真正需要时,改善了启动时间。
这些优化带来了显著的性能提升,会话准备时间降低 40%,包导入时间减少 21%。
对于长时间运行的会话或多智能体工作流而言,这些改进至关重要,因为框架开销会不断累积。这些改动使底层智能体逻辑得以更快执行。
完整摘要
Google 工程师借助 Gemini 4 Argon 对超过 20 万行代码的 ADK 代码库进行了一夜优化。该模型成功识别并实施了两项显著的性能改进:在复制前过滤会话事件以降低内存开销,以及引入懒加载以延迟导入重型包。这些改动大幅缩短了会话准备时间和包导入时间,展现出该模型有效处理复杂既有代码库的能力。
Google 解释了 Gemini 4 Argon 一次持续 11 小时的无人值守运行如何为 Google Agent Development Kit 代码库带来两项获采纳的优化:将长会话中的内存会话准备开销降低约 40%,并将冷启动时的包导入时间缩短 21%。Google explained how an 11-hour unattended run of Gemini 4 Argon produced two accepted optimizations for Google Agent Development Kit's codebase, reducing in-memory session-preparation overhead by about 40% in long sessions and cold package import time by 21%.
谷歌工程师表示,他们的目标之一是了解“模型如何处理现有代码库”。这比“从空文件夹开始构建全新应用”要难得多。为了测试这一点,他们专注于优化自家智能体开发套件(ADK)的性能。该代码库包含约 800 个文件、超过 20 万行代码,以及近 1.7 万个单元测试。One of the goals of Google engineers' was to learn "about how the model handles an existing codebase", a much harder task than creating "greenfield apps built from an empty folder", they say. To test this, they focused on optimizing the performance of their own Agent Development Kit (ADK), a codebase spanning over 200k lines of code across approximately 800 files and including nearly 17,000 unit tests.
性能优化工作对模型来说是一项艰巨的考验,因为你不能只打开一个文件就发现性能瓶颈。你必须从症状出现的位置之外的角度进行审视,并在整个过程中掌握整个代码库如何相互关联。Performance work is a hard test for a model because you can't just open one file and spot the slowdown. You have to look orthogonally to where the symptom appears and hold a map of how the entire codebase fits together over a long run.
在进行了一次简短的初步试运行后,他们发现了提示词需要包含哪些内容,才能确保智能体遵循团队在单元测试和基准测试方面的惯例。随后,Google 工程师通过 .agents/skills 文件指定了针对特定代码库的指南,“就像为新工程师准备的入职指南”。他们指示智能体仅加载任务所需的技能,以免上下文窗口被塞得过满。最后,他们拟定了以下提示词,并使用 Antigravity 的 /goal 模式,确保目标在上下文压缩过程中得以保留:After an initial, short run helped them identify what the prompt needed to include to ensure the agent followed the team's conventions for unit testing and benchmarking, Google engineers specified repository-specific guidelines through .agents/skills files, "like an onboarding guide for a new engineer". The agent was instructed to load only the required skill for the task, to avoid flooding the context window. Finally they came up with the following prompt, where they used Antigravity's /goal mode to ensure the goal was preserved across context compaction:
/goal Make ADK add no noticeable overhead to any agent: at startup, in long sessions, in multi-agent and workflow setups. Keep what the model receives and the public API unchanged, and back each change with a test that would catch a regression. Open one pull request against main that the ADK maintainers would approve, with before and after numbers in its description. Don't merge it.
谷歌解释说,任务完成时,Argon 的日志显示,该智能体已阅读代码库指南、建立性能基准、提出优化方案、审查自身更改,并在结束前运行了全部 16,892 项开源单元测试。On task completion, Google explains, Argon's logs showed that the agent had read the repository guidelines, established performance baselines, proposed optimizations, reviewed its own changes, and ran all 16,892 open-source unit tests before finishing.
更重要的是,Argon 完成了性能分析器无法替你完成的跨模块排查工作。性能分析器会告诉你,复制会话和导入包需要时间;但它不会跨越 40 个文件追踪每个调用方、模拟目标和共享引用,确保加速这些路径不会破坏现有应用。More importantly, Argon did the cross-module legwork a profiler can't do for you. A profiler will tell you that copying sessions and importing packages take time. What it won't do is trace every caller, mock target, and shared reference across 40 files so that speeding up those paths doesn't break existing apps.
最终合入代码库的两项优化改进了 ADK 处理会话历史的方式:一项在复制事件前对其进行筛选,另一项引入了延迟加载,以避免过早导入庞大的软件包。The two optimizations finally accepted into the codebase improved how the ADK handled session history by filtering events before copying them and introduced lazy loading to prevent heavy packages from being imported until needed.
这些更改使内存中的会话准备速度提升了 40%,包导入速度提升了 21%。Google 指出,与智能体运行的总时长相比,这些任务的开销并不大;ADK 支持跨越数十次甚至数百次迭代的多工具交互,因此这些小幅性能提升能够累积起来:These changes made in-memory session preparation and package import faster by 40% and 21%, respectively. These tasks are not particularly expensive compared with the overall duration of an agent run, Google notes that the ADK supports multi-tool interactions spanning dozens or even hundreds of iterations, allowing these small performance gains to compound:
对于一次耗时数秒的 LLM 调用,人类不会察觉到 28 毫秒或 78 毫秒的差异。然而,在 158 轮内部工具调用交互中,这些开销会不断累积:移除它们后,完整的 158 轮运行时间会从 65.6 秒缩短至 56.1 秒(纯框架开销减少了近 10 秒)。On a single LLM call that takes seconds, a human won't feel 28 ms or 78 ms. Across 158 internal turns of tool calling interactions, however, those copies compound: removing them cuts the full 158-turn run from 65.6 seconds to 56.1 seconds (nearly 10 seconds of pure framework overhead).
谷歌使用 Gemini 4 Argon 优化 ADK 代码库的经验表明,AI 智能体能够成功修改现有代码库,但其效用目前仍受限于编写代码后的任务所需的时间和精力,包括 PR 审查、调试和测试。谷歌的研究结果证实了这一趋势:Argon 提出的 4 项修改在开发者审查后均遭拒绝,原因是人们担心其可靠性、可维护性、兼容性或是否能带来可衡量的性能提升。While Google's experience with Gemini 4 Argon optimizing the ADK codebase demonstrates AI agents' ability to modify existing codebases successfully, their effectiveness remains currently limited by the time and effort required for post-coding tasks, including PR review, debugging, and testing. Google's findings confirm this trend, with Argon producing 4 modifications that were rejected upon developer review because of concerns about reliability, maintainability, compatibility, or measurable performance benefits.