Code-writing large language models (CodeLLMs) generate executable code policies for embodied agents by translating natural language goals and environmental constraints into structured control programs. However, policy generation in open-domain embodied environments suffers from two fundamental limitations: (i) delayed decoding caused by repetitive prefill computation over long prompts, and (ii) limited robustness due to fully generative decoding, which often produces API mismatches, missing safety guards, and unstable control logic. To address these limitations, we present FCGraft, a Functional Cache Grafting framework. FCGraft maintains a library of function-level validated code skeletons and their associated prompt-level Transformer key-value (KV) caches, and synthesizes new policies by retrieving relevant functions and grafting their KV caches when a new task is provided. Given retrieved function caches, FCGraft performs cache grafting via stitching, which composes cached function segments into a composite policy, and patching, which locally adapts only the necessary code regions to satisfy task-specific parameters and constraints with minimal additional decoding. By eliminating redundant prefill computation, this approach reduces generation latency, while reusing validated control structures improves robustness over prompt-level caching methods RAGCache, achieving 18.31% higher task success rate and 2.3x faster policy synthesis.
翻译:代码编写大语言模型(CodeLLMs)通过将自然语言目标和环境约束转化为结构化控制程序,为具身智能体生成可执行代码策略。然而,在开放域具身环境中的策略生成存在两个根本限制:(i)长提示词上重复预填充计算导致的解码延迟,以及(ii)完全生成式解码导致的鲁棒性有限,常引发应用程序接口不匹配、缺少安全防护及控制逻辑不稳定。为解决这些问题,我们提出FCGraft——一种功能缓存嫁接框架。FCGraft维护一个包含函数级验证代码骨架及其关联提示词层Transformer键值(KV)缓存的数据集,并在新任务提供时通过检索相关函数并嫁接其KV缓存来综合新策略。基于检索到的函数缓存,FCGraft通过拼接(stitching)与修补(patching)执行缓存嫁接:拼接将缓存函数片段组合成复合策略,修补则仅局部调整必要代码区域以满足任务特定参数和约束,从而最大程度减少额外解码。该方法通过消除冗余预填充计算降低生成延迟,同时通过复用已验证的控制结构,在提示词级缓存方法RAGCache的基础上提升鲁棒性,实现18.31%更高的任务成功率与2.3倍更快的策略综合速度。