Skip to main content

SDK for building LLM workflows and agents using Apache Airflow

Project description

airflow-ai-sdk

A Python SDK for working with LLMs from Apache Airflow. It allows users to call LLMs and orchestrate agent calls directly within their Airflow pipelines using decorator-based tasks.

We find it's often helpful to rely on mature orchestration tooling like Airflow for instrumenting LLM workflows and agents in production, as these LLM workflows follow the same form factor as more traditional workflows like ETL pipelines, operational processes, and ML workflows.

Quick Start

pip install airflow-ai-sdk[openai]

Installing with no optional dependencies will give you the slim version of the package. The available optional dependencies are listed in pyproject.toml.

Features

  • LLM tasks with @task.llm: Define tasks that call language models to process text
  • Agent tasks with @task.agent: Orchestrate multi-step AI reasoning with custom tools
  • Automatic output parsing: Use type hints to automatically parse and validate LLM outputs
  • Branching with @task.llm_branch: Change DAG control flow based on LLM output
  • Model support: All models in the Pydantic AI library (OpenAI, Anthropic, Gemini, etc.)
  • Embedding tasks with @task.embed: Create vector embeddings from text

Example

from typing import Literal
import pendulum
from airflow.decorators import dag, task
from airflow.models.dagrun import DagRun


@task.llm(
    model="gpt-4o-mini",
    result_type=Literal["positive", "negative", "neutral"],
    system_prompt="Classify the sentiment of the given text.",
)
def process_with_llm(dag_run: DagRun) -> str:
    input_text = dag_run.conf.get("input_text")

    # can do pre-processing here (e.g. PII redaction)
    return input_text


@dag(
    schedule=None,
    start_date=pendulum.datetime(2025, 1, 1),
    catchup=False,
    params={"input_text": "I'm very happy with the product."},
)
def sentiment_classification():
    process_with_llm()


sentiment_classification()

Examples Repository

To get started with a complete example environment, check out the examples repository, which offers a full local Airflow instance with the AI SDK installed and 5 example pipelines:

git clone https://github.com/astronomer/ai-sdk-examples.git
cd ai-sdk-examples
astro dev start

If you don't have the Astro CLI installed, run brew install astro or see other options here.

Documentation

For detailed documentation, see the docs directory:

License

LICENSE

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

airflow_ai_sdk-0.1.4.tar.gz (231.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

airflow_ai_sdk-0.1.4-py3-none-any.whl (16.7 kB view details)

Uploaded Python 3

File details

Details for the file airflow_ai_sdk-0.1.4.tar.gz.

File metadata

  • Download URL: airflow_ai_sdk-0.1.4.tar.gz
  • Upload date:
  • Size: 231.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.6.10

File hashes

Hashes for airflow_ai_sdk-0.1.4.tar.gz
Algorithm Hash digest
SHA256 afa173b54765a5ecd0779edece7473373c5bed64c3b2467b50f5be53c503f112
MD5 e5412cd93ce077035c01c2b5738a469a
BLAKE2b-256 c1cd8556ea9e3a8a043441c161de90657c4d40de72c9f4b9f83f73142554ab50

See more details on using hashes here.

File details

Details for the file airflow_ai_sdk-0.1.4-py3-none-any.whl.

File metadata

File hashes

Hashes for airflow_ai_sdk-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 7f0250bbb8f78d279bf4dd50964e365a61fe9a1a139e6bf744ec672026108c59
MD5 39318093d46ee1d4eba499f391be01ed
BLAKE2b-256 febff5d3fafbc74ba0e2b8b6818a5940082cba40f385288c3451de05a8fad30e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page