Functional Cache Grafting: Robust and Rapid Code-Policy Synthesis for Embodied Agents

Saehun Chun, Wonje Choi, Sera Choi, Sanghyun Ahn, Honguk Woo

TL;DR: FCGraft is a novel framework that accelerates and stabilizes how embodied agents use Large Language Models (LLMs) to write control code. By "grafting" pre-validated function-level Key-Value (KV) caches, it achieves an 18.31% higher task success rate and a 2.3× speedup compared to state-of-the-art caching methods.

The Bottleneck in Code-as-Policies

The "Code-as-Policies" (CaP) paradigm allows robots to translate natural language instructions (e.g., "pick up the burner and place it on the desk") directly into executable Python code using LLMs. While highly flexible, deploying this approach in open-domain, real-world environments faces two fundamental limitations:

  1. Latency from Repetitive Prefilling: LLMs are computationally heavy. For every new instruction, the model typically must process (prefill) thousands of tokens of API documentation, environmental constraints, and examples. In time-critical scenarios—such as stopping a gas leak—this delay can lead to catastrophic failure.
  2. Brittleness of Generative Decoding: Fully generative models are prone to hallucination. They frequently produce API mismatches, omit crucial safety guards, or generate unstable control logic. In a robotic script, a single typographical error or logical misstep can cause the entire task to fail.

Existing solutions like RAGCache or PromptCache attempt to reuse the model's internal intermediate states (Key-Value or KV caches) to save time. However, these methods operate at the document level, making them ill-suited for the dynamic, modular nature of robotic skills.

The FCGraft Solution

To address these limitations, researchers introduce FCGraft (Functional Cache Grafting). FCGraft treats robotic skills as modular building blocks at the function level, utilizing two core mechanisms to optimize both speed and reliability.

1. Two-Tier Functional Cache

Rather than maintaining a single, monolithic memory bank, FCGraft splits its cache into two distinct tiers:

  • Interface Tier ($I$): Stores function signatures (names and parameters) alongside their KV states. This allows the model to instantly "know" which skills are available without loading heavy code bodies.
  • Implementation Tier ($C$): Stores the actual, validated code bodies. These are only retrieved during execution or error repair, keeping the active reasoning space lightweight and efficient.

2. Cache Grafting: Stitching and Patching

When a new task is introduced, FCGraft synthesizes policies through a two-part grafting process:

  • Cache-Stitching: FCGraft retrieves relevant function interfaces and "stitches" their KV states together. This bypasses the expensive prefill computation, allowing the LLM to begin generating the new policy immediately.
  • Cache-Patching: If the generated code encounters an execution error (e.g., a NameError or a RobotError), FCGraft avoids starting from scratch. Instead, it performs surgical repair. By reusing the KV state of the code prefix (the code executed successfully before the error), the LLM regenerates only the faulty line or block, minimizing additional decoding.

3. Semantic-Aware Management

To prevent the cache from exceeding GPU memory limits, FCGraft employs a Locality Scoring system. Rather than simply retaining the most recently used functions, it prioritizes functions based on frequency of use, association (functions that frequently appear together), and semantic diversity.

Evaluation and Results

The framework was rigorously evaluated across three major simulated benchmarks and on real-world hardware:

  • Simulated Benchmarks: ALFRED (long-horizon household tasks), TEACh (dialogue-driven human-robot collaboration), and RLBench (low-level, precise manipulation tasks).
  • Real-World Hardware: A 7-DoF Franka Emika Research 3 robot tasked with office desk rearrangement and cooking workstation preparation, including a high-stakes "gas leak" intervention scenario.

Key Findings: * Unprecedented Speed: FCGraft synthesizes policies 2.3× faster than RAGCache, significantly reducing the "Time to First Token" (TTFT). * Enhanced Reliability: The framework achieved an 18.31% higher task success rate on average across all benchmarks. On the ALFRED benchmark, it outperformed the second-best baseline (LRLL) by 4.04% in success rate while operating 2.67× faster. * Real-World Robustness: During physical robot tests, FCGraft successfully managed unexpected disruptions (such as a disconnected gas hose) by rapidly synthesizing and deploying corrective code. Baseline methods, by contrast, were either too slow to react or generated inconsistent logic.

Key Insights

  • Granularity Matters: Reusing memory at the function level is the ideal granularity for robotics. It aligns perfectly with the modular way we conceptualize robot skills (e.g., pick(), place(), open_drawer()).
  • Robustness Through Reuse: By stitching together pre-validated code skeletons, the model is inherently biased toward control structures that have succeeded in the past. This drastically reduces the likelihood of API mismatches compared to generating code from a blank slate.
  • The Power of Patching: Localized repair is significantly more effective than full regeneration. Reusing the KV state of the successful prefix allows the LLM to correct mistakes with minimal new computation.

Limitations and Future Directions

While FCGraft represents a major leap forward for CodeLLM-driven embodied agents, the authors note a few areas for future development:

  • Multi-Agent Cache Sharing: Currently, each robot maintains an isolated cache. Extending this to allow multi-agent cache sharing could dramatically accelerate learning for collaborative robot swarms.
  • Dynamic Eviction: The current cache management relies on fixed weighted coefficients. Future iterations could employ reinforcement learning to dynamically optimize which functions to retain or discard based on specific environmental demands.
  • Formal Safety Guarantees: Despite its improved robustness, FCGraft still relies on probabilistic LLMs and does not provide formal, provable safety guarantees—a persistent challenge in the deployment of autonomous systems.

Summary updated

BibTeX
@inproceedings{chun2026functional,
  author = {Saehun Chun and Wonje Choi and Sera Choi and Sanghyun Ahn and Honguk Woo},
  title = {{Functional Cache Grafting: Robust and Rapid Code-Policy Synthesis for Embodied Agents}},
  booktitle = {International Conference on Machine Learning},
  year = {2026},
  url = {https://openreview.net/forum?id=hkmpUHQxgv},
}
Figure