airflow.providers.common.ai.example_dags.example_langchain_toolset_bridge

Expose an Airflow toolset to a LangChain agent (the reverse bridge).

common.ai’s curated toolsets (SQLToolset, HookToolset, MCPToolset) are pydantic-ai toolsets, so AgentOperator uses them natively. This example shows the reverse direction: convert a SQLToolset into LangChain StructuredTool objects with airflow_toolset_to_langchain_tools() and hand them to a LangChain ReAct agent built with create_agent. The agent gets Airflow’s managed connections and read-only SQL validation for free.

Forward direction (LangChain tools -> AgentOperator): no Airflow code is needed. pydantic-ai ships pydantic_ai.ext.langchain.LangChainToolset upstream, so LangChainToolset([my_langchain_tool]) drops straight into AgentOperator(toolsets=[...]). See https://ai.pydantic.dev for details.

Before running:

  1. Install LangChain: pip install "apache-airflow-providers-common-ai[langchain]" langchain-openai

  2. Create a langchain connection named langchain_default (set password to your API key) for the model.

  3. Create a database connection (DB_CONN_ID, default sql_default) whose hook is a DbApiHook (e.g. SQLite, Postgres, MySQL).

Attributes

LLM_CONN_ID

LLM_MODEL

DB_CONN_ID

DEFAULT_QUESTION

Functions

example_langchain_toolset_bridge()

Run a LangChain SQL agent backed by Airflow's curated SQLToolset.

Module Contents

airflow.providers.common.ai.example_dags.example_langchain_toolset_bridge.LLM_CONN_ID[source]
airflow.providers.common.ai.example_dags.example_langchain_toolset_bridge.LLM_MODEL[source]
airflow.providers.common.ai.example_dags.example_langchain_toolset_bridge.DB_CONN_ID[source]
airflow.providers.common.ai.example_dags.example_langchain_toolset_bridge.DEFAULT_QUESTION = 'Which tables exist, and how many rows does each contain?'[source]
airflow.providers.common.ai.example_dags.example_langchain_toolset_bridge.example_langchain_toolset_bridge()[source]

Run a LangChain SQL agent backed by Airflow’s curated SQLToolset.

Was this entry helpful?