Accelerating Multi‑turn LLM Agent Workflows via Context Templating and Opportunistic Prefill
摘要
Large Language Model (LLM) based agents have become essential interfaces for delivering AI-assisted services in daily workflows. However, these agentic workflows typically involve complex in-context dependencies, long context histories and small batch sizes, which lead to under-utilization of GPU resources and elevated end-to-end generation latency. To tackle this challenge, we propose a context templating mechanism that decouples agents’ context as a combination of static templates and dynamic string variables, allowing partial prompt construction and runtime updates. Built on this abstraction, our execution engine resolves dependencies, identifies satisfiable contexts and issues generation calls as soon as their dependencies are met, without waiting for unrelated segments. Known context portions are opportunistically prefilled during idle GPU cycles, priming the key-value (KV) cache to reduce decoding overhead. This strategy not only enhances GPU utilization via asynchronous prefill but also eliminates unnecessary serialization between generation steps, thus maximizing opportunities for intra-conversation parallelism. We implement these techniques in a modular orchestration framework supporting multi-agent, multi-turn workflows. In a simulated multi-agent debate task, our method reduces up to 20% end-to-end generation latency in long-context, low-batch settings compared to a standard Python-threaded baseline. The benefits diminish at higher batch sizes, where traditional batching is sufficient. Our results highlight that leveraging the structural regularities of agent conversations can meaningfully accelerate LLM-backed services.