β‘ AdalFlow is a PyTorch-like library to build and auto-optimize any LM workflows, from Chatbots, RAG, to Agents. β‘
- 100% Open-source Agents SDK: Lightweight and requires no additional API to setup
Human-in-the-Loop
andTracing
Functionalities. - Say goodbye to manual prompting: AdalFlow provides a unified auto-differentiative framework for both zero-shot optimization and few-shot prompt optimization. Our research,
LLM-AutoDiff
andLearn-to-Reason Few-shot In Context Learning
, achieve the highest accuracy among all auto-prompt optimization libraries. - Switch your LLM app to any model via a config: AdalFlow provides
Model-agnostic
building blocks for LLM task pipelines, ranging from RAG, Agents to classical NLP tasks.
View Documentation
Install AdalFlow with pip:
pip install adalflow
from adalflow import Agent, Runner
from adalflow.components.model_client.openai_client import OpenAIClient
# Create a simple agent
agent = Agent(
name="Assistant",
model_client=OpenAIClient(),
model_kwargs={"model": "gpt-4o", "temperature": 0.3}
)
runner = Runner(agent=agent)
result = runner.call(prompt_kwargs={"input_str": "Write a haiku about AI and coding"})
print(result.answer)
# Output:
# Code flows like water,
# AI minds think in patterns,
# Logic blooms in bytes.
Set your OPENAI_API_KEY
environment variable to run this example.
def calculator(expression: str) -> str:
"""Evaluate a mathematical expression."""
try:
result = eval(expression)
return f"Result: {result}"
except Exception as e:
return f"Error: {e}"
# Create agent with tools
agent = Agent(
name="CalculatorAgent",
tools=[calculator],
model_client=OpenAIClient(),
model_kwargs={"model": "gpt-4o", "temperature": 0.3}
)
runner = Runner(agent=agent)
result = runner.call(prompt_kwargs={"input_str": "Calculate 15 * 7 + 23"})
print(result.answer)
# Output: The result of 15 * 7 + 23 is 128.
View Quickstart: Learn How AdalFlow
optimizes LM workflows end-to-end in 15 mins.
Go to Documentation for tracing, human-in-the-loop, and more.
[Jan 2025] Auto-Differentiating Any LLM Workflow: A Farewell to Manual Prompting
- LLM Applications as auto-differentiation graphs
- Token-efficient and better performance than DsPy
We work closely with the VITA Group at University of Texas at Austin, under the leadership of Dr. Atlas Wang, who provides valuable support in driving project initiatives.
For collaboration, contact Li Yin.
We are looking for a Dev Rel to help us build the community and support our users. If you are interested, please contact Li Yin.
AdalFlow full documentation available at adalflow.sylph.ai:
AdalFlow is named in honor of Ada Lovelace, the pioneering female mathematician who first recognized that machines could go beyond mere calculations. As a team led by a female founder, we aim to inspire more women to pursue careers in AI.
The AdalFlow is a community-driven project, and we welcome everyone to join us in building the future of LLM applications.
Join our Discord community to ask questions, share your projects, and get updates on AdalFlow.
To contribute, please read our Contributor Guide.
Many existing works greatly inspired AdalFlow library! Here is a non-exhaustive list:
- π PyTorch for design philosophy and design pattern of
Component
,Parameter
,Sequential
. - π Micrograd: A tiny autograd engine for our auto-differentiative architecture.
- π Text-Grad for the
Textual Gradient Descent
text optimizer. - π DSPy for inspiring the
__{input/output}__fields
in ourDataClass
and the bootstrap few-shot optimizer. - π OPRO for adding past text instructions along with its accuracy in the text optimizer.
- π PyTorch Lightning for the
AdalComponent
andTrainer
.