HackerPapers

arXiv:2501.16673cs.CL

LLM-AutoDiff: Auto-Differentiate Any LLM Workflow

Li Yin, Zhangyang Wang

Abstract

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.

arXiv comments
Journal reference
DOI
Subjects
cs.CLComputation and Language

On Hacker News

Linked by 2 identifiable commenters in 4 comments across 4 threads, from Feb 2025 to Jul 2025. Found in 1 HN submission from Jan 2025 to Jan 2025. Open submission discussions.

Comments linking this paper, per year.

Discussed in comments4 threads

    • >A database query might return 10,000 rows, but the agent only needs to know "query succeeded, 10k results, here are the first 5." Designing these abstractions is an art. It seems the author never used prompt/workflow optimization techniques. LLM-AutoDiff: Auto-Differentiate Any…

      Xmd5aView on HNParent context

    • This is exactly what I'm doing. Some papers I'm studying: TextGrad: Automatic "Differentiation" via Text: https://arxiv.org/abs/2406.07496 LLM-AutoDiff: Auto-Differentiate Any LLM Workflow : https://arxiv.org/abs/2501.16673 Trace is the Next AutoDiff: Generative Optimization…

      Xmd5aView on HNParent context

    • Stumbled upon this in another thread: https://ai-analytics.wharton.upenn.edu/generative-ai-labs/re... My point still holds that it is optimizable though (https://github.com/zou-group/textgrad, https://arxiv.org/abs/2501.16673) >Subjects develop elaborate "rain dances" in the…

      Xmd5aView on HNParent context

Submitted to Hacker News

Connected through shared HN threads, not inferred similarity or a recommendation.