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:
Install LangChain:
pip install "apache-airflow-providers-common-ai[langchain]" langchain-openaiCreate a
langchainconnection namedlangchain_default(setpasswordto your API key) for the model.Create a database connection (
DB_CONN_ID, defaultsql_default) whose hook is aDbApiHook(e.g. SQLite, Postgres, MySQL).
Attributes¶
Functions¶
Run a LangChain SQL agent backed by Airflow's curated |