Airflow

AirflowTools lets agents save and read Apache Airflow DAG files.

Prerequisites

The following example requires the openai library.

uv pip install agno openai

The Agent model uses an OpenAI key, separately from any toolkit provider credentials.

Set OpenAI Key

Set your OPENAI_API_KEY as an environment variable. You can get one from OpenAI.

export OPENAI_API_KEY=sk-***

Example

The following agent will use Airflow to save and read a DAG file.

cookbook/91_tools/airflow_tools.py
from agno.agent import Agent
from agno.tools.airflow import AirflowTools

agent = Agent(
    tools=[AirflowTools(dags_dir="dags", enable_save_dag_file=True, enable_read_dag_file=True)],
    markdown=True,
)

dag_content = """
from airflow import DAG
from airflow.operators.python import PythonOperator
from datetime import datetime, timedelta
default_args = {
    'owner': 'airflow',
    'depends_on_past': False,
    'start_date': datetime(2024, 1, 1),
    'email_on_failure': False,
    'email_on_retry': False,
    'retries': 1,
    'retry_delay': timedelta(minutes=5),
}
# Using 'schedule' instead of deprecated 'schedule_interval'
with DAG(
    'example_dag',
    default_args=default_args,
    description='A simple example DAG',
    schedule='@daily',  # Changed from schedule_interval
    catchup=False
) as dag:
    def print_hello():
        print("Hello from Airflow!")
        return "Hello task completed"
    task = PythonOperator(
        task_id='hello_task',
        python_callable=print_hello,
        dag=dag,
    )
"""

agent.run(f"Save this DAG file as 'example_dag.py': {dag_content}")

agent.print_response("Read the contents of 'example_dag.py'")

Toolkit Params

ParameterTypeDefaultDescription
dags_dirPath or strNoneDirectory for DAG files. Defaults to the current working directory
enable_save_dag_fileboolTrueEnables functionality to save Airflow DAG files
enable_read_dag_fileboolTrueEnables functionality to read Airflow DAG files
allboolFalseEnables all functionality when set to True

Toolkit Functions

FunctionDescription
save_dag_fileSaves python code for an Airflow DAG to a file
read_dag_fileReads an Airflow DAG file and returns the contents

Developer Resources