arXiv:2501.16673cs.CL2025-01被引 21

让大模型工作流自动优化提示词,提升效率与准确率。

LLM-AutoDiff: Auto-Differentiate Any LLM Workflow

  • 将提示词视为可训练参数,用文本梯度迭代优化
  • 在多跳问答和智能体流程中显著提升准确率与训练效率
  • 适合需要自动化复杂提示工程的研究者与开发者

大型语言模型(LLMs)已重塑自然语言处理,驱动从多跳检索到自主智能体工作流的广泛应用。然而,提示工程——即设计有效引导模型的文本输入——仍困难且耗时,尤其在整合多个LLM调用与检索、格式化等操作的复杂流水线中。我们提出LLM-AutoDiff:一种新型自动提示工程框架,将文本梯度方法(如Text-Grad)扩展至多组件、可能含循环的LLM架构。该框架基于AdalFlow实现,将每个文本输入视为可训练参数,并利用冻结的反向引擎模型生成类文本梯度反馈,指导迭代优化。相比单节点方法,它天然支持功能节点,保留重复调用的时间顺序性(如多跳循环),并通过隔离不同子提示解决“中间丢失”问题。同时,通过选择性梯度计算聚焦错误样本,提升训练效率。在单步分类、多跳检索问答及代理驱动流水线等任务中,其性能持续优于现有文本梯度基线,在准确率和训练成本上均表现更优。通过图视角统一提示优化,LLM-AutoDiff为规模化自动化大模型工作流提供了强大新范式,类比于自动微分在神经网络研究中的变革性作用。

原文摘要 · Abstract (English)

Large Language Models (LLMs) have reshaped natural language processing, powering applications from multi-hop retrieval and question answering to autonomous agent workflows. Yet, prompt engineering -- the task of crafting textual inputs to effectively direct LLMs -- remains difficult and labor-intensive, particularly for complex pipelines that combine multiple LLM calls with functional operations like retrieval and data formatting. We introduce LLM-AutoDiff: a novel framework for Automatic Prompt Engineering (APE) that extends textual gradient-based methods (such as Text-Grad) to multi-component, potentially cyclic LLM architectures. Implemented within the AdalFlow library, LLM-AutoDiff treats each textual input as a trainable parameter and uses a frozen backward engine LLM to generate feedback-akin to textual gradients -- that guide iterative prompt updates. Unlike prior single-node approaches, LLM-AutoDiff inherently accommodates functional nodes, preserves time-sequential behavior in repeated calls (e.g., multi-hop loops), and combats the "lost-in-the-middle" problem by isolating distinct sub-prompts (instructions, formats, or few-shot examples). It further boosts training efficiency by focusing on error-prone samples through selective gradient computation. Across diverse tasks, including single-step classification, multi-hop retrieval-based QA, and agent-driven pipelines, LLM-AutoDiff consistently outperforms existing textual gradient baselines in both accuracy and training cost. By unifying prompt optimization through a graph-centric lens, LLM-AutoDiff offers a powerful new paradigm for scaling and automating LLM workflows - mirroring the transformative role that automatic differentiation libraries have long played in neural network research.

提示工程自动微分大模型智能体

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。