AI/TLDR

AdalFlow

A PyTorch-like library to build and auto-optimize LLM pipelines

Overview

AdalFlow is an open-source Python library for building and auto-optimizing language model workflows, from chatbots and RAG systems to tool-using agents. It takes a PyTorch-like approach: you assemble your pipeline from model-agnostic building blocks, then let the framework tune the prompts across those components instead of hand-editing them.

It is aimed at developers who are tired of manual prompt engineering and want a structured way to improve accuracy. AdalFlow provides an auto-differentiative framework for both zero-shot and few-shot prompt optimization, so prompts are optimized end-to-end against your task rather than guessed by hand.

Within the prompt-programming and LLM-orchestration space, AdalFlow sits between a raw SDK and a higher-level framework. You can swap the underlying model through configuration, and the library ships agent, runner, and tracing primitives with human-in-the-loop support built in.

What it does

  • Build chatbots, RAG, and agents from model-agnostic building blocks
  • Auto-optimize prompts with a unified auto-differentiative framework (zero-shot and few-shot)
  • Switch the underlying LLM via configuration without rewriting your pipeline
  • Agent and Runner primitives with synchronous, asynchronous, and streaming call modes
  • Built-in tool calling, tracing, and human-in-the-loop, with no extra API required
  • 100% open-source and lightweight

Getting started

Install AdalFlow with pip, set your model provider key, then define tools and run an agent.

Install AdalFlow

Install the library from PyPI.

bashbash
pip install adalflow

Set your API key

Set your OpenAI key in the environment so the model client can authenticate.

bashbash
export OPENAI_API_KEY=your-key-here

Create and run an agent

Define plain Python functions as tools, build an Agent with a model client, and call it through a Runner.

pythonpython
from adalflow import Agent, Runner
from adalflow.components.model_client.openai_client import OpenAIClient

def calculator(expression: str) -> str:
    """Evaluate a mathematical expression."""
    try:
        result = eval(expression)
        return f"The result of {expression} is {result}"
    except Exception as e:
        return f"Error: {e}"

agent = Agent(
    name="MyAgent",
    tools=[calculator],
    model_client=OpenAIClient(),
    model_kwargs={"model": "gpt-4o", "temperature": 0.3},
    max_steps=5,
)

runner = Runner(agent=agent)
result = runner.call(
    prompt_kwargs={"input_str": "Calculate 15 * 7 + 23"}
)
print(result.answer)

Commands and code are distilled from the project's own documentation — always check the official repo for the latest.

When to use it

  • Building a tool-using agent that can call functions like a calculator or web search and stream its steps
  • Replacing manual prompt engineering with automatic prompt optimization for a RAG or classification task
  • Prototyping an LLM pipeline that needs to swap between model providers through configuration
  • Adding tracing and human-in-the-loop review to an existing LLM workflow

How AdalFlow compares

AdalFlow alongside other open-source prompt programming tools AI/TLDR tracks, ranked by GitHub stars.

ToolStarsWhat it does
DSPy★ 35.8kA Stanford framework for programming language models with composable modules and automatic prompt optimization instead of hand-written prompts.
ell★ 5.9kA Python library that treats prompts as versioned functions, with tooling to track, visualize, and iterate on them as code.
GEPA★ 5.5kA reflective, evolutionary optimizer that improves prompts and other text components of a system using language-model feedback.
LMQL★ 4.2kA query language for LLMs that mixes Python control flow with prompts and constraints to script multi-step generation.
AdalFlow★ 4.2kA PyTorch-like library to build and auto-optimize LLM pipelines
TextGrad★ 3.6kA library that optimizes prompts and other text variables using textual gradients, applying a backpropagation-like loop driven by LLM feedback.
Mirascope★ 1.5kA lightweight Python toolkit for writing LLM calls as typed functions with prompt templates, chaining, and a single interface across providers.