jedcunningham commented on code in PR #65172:
URL: https://github.com/apache/airflow/pull/65172#discussion_r3081295872


##########
providers/common/ai/src/airflow/providers/common/ai/example_dags/example_llm_survey_agentic.py:
##########
@@ -0,0 +1,265 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+Multi-query synthesis — an agentic survey analysis pattern.
+
+Demonstrates how Dynamic Task Mapping turns a multi-dimensional research
+question into a fan-out / fan-in pipeline that is observable, retryable,
+and auditable at each step.
+
+**Question:** *"What does a typical Airflow deployment look like for
+practitioners who actively use AI tools in their workflow?"*
+
+This question cannot be answered with a single SQL query.  It requires
+querying four independent dimensions — executor type, deployment method,
+cloud provider, and Airflow version — all filtered to respondents who use
+AI tools to write Airflow code.  The results are then synthesized by a
+second LLM call into a single narrative characterization.
+
+``example_llm_survey_agentic`` (manual trigger):
+
+.. code-block:: text
+
+    decompose_question (@task)
+        → generate_sql  (LLMSQLQueryOperator, mapped ×4)
+        → wrap_query    (@task, mapped ×4)
+        → run_query     (AnalyticsOperator, mapped ×4)
+        → collect_results (@task)
+        → synthesize_answer (LLMOperator)
+        → result_confirmation (ApprovalOperator)
+
+**What this makes visible that an agent harness hides:**
+
+* Each sub-query is a named, logged task instance — not a hidden tool call.
+* If the cloud-provider query fails, only that mapped instance retries;
+  the other three results are preserved in XCom.
+* The synthesis step's inputs are fully auditable XCom values — not an
+  opaque continuation of an LLM reasoning loop.
+
+Before running:
+
+1. Create an LLM connection named ``pydanticai_default`` (or the value of
+   ``LLM_CONN_ID``) for your chosen model provider.
+2. Place the cleaned survey CSV at the path set by ``SURVEY_CSV_PATH``.
+"""
+
+from __future__ import annotations
+
+import datetime
+import json
+import os
+
+from airflow.providers.common.ai.operators.llm import LLMOperator
+from airflow.providers.common.ai.operators.llm_sql import LLMSQLQueryOperator
+from airflow.providers.common.compat.sdk import dag, task
+from airflow.providers.common.sql.config import DataSourceConfig
+from airflow.providers.common.sql.operators.analytics import AnalyticsOperator
+from airflow.providers.standard.operators.hitl import ApprovalOperator
+
+# ---------------------------------------------------------------------------
+# Configuration
+# ---------------------------------------------------------------------------
+
+LLM_CONN_ID = "pydanticai_default"
+
+SURVEY_CSV_PATH = os.environ.get(
+    "SURVEY_CSV_PATH",
+    "/opt/airflow/data/airflow-user-survey-2025.csv",
+)
+SURVEY_CSV_URI = f"file://{SURVEY_CSV_PATH}"
+
+# Schema context for LLMSQLQueryOperator.
+# All column names must be quoted in SQL because they contain spaces and 
punctuation.
+SURVEY_SCHEMA = """
+Table: survey
+Key columns (quote all names in SQL):
+  "How important is Airflow to your business?"                                 
               TEXT
+  "Which version of Airflow do you currently use?"                             
               TEXT
+  "CeleryExecutor"                                                             
               TEXT
+  "KubernetesExecutor"                                                         
               TEXT
+  "LocalExecutor"                                                              
               TEXT
+  "How do you deploy Airflow?"                                                 
               TEXT
+  "What best describes your current occupation?"                               
               TEXT
+  "What industry do you currently work in?"                                    
               TEXT
+  "How many years of experience do you have with Airflow?"                     
               TEXT
+  "Which of the following is your company's primary cloud provider for 
Airflow?"              TEXT
+  "How many people work at your company?"                                      
               TEXT
+  "How many people at your company directly work on data?"                     
               TEXT
+  "How many people at your company use Airflow?"                               
               TEXT
+  "How likely are you to recommend Apache Airflow?"                            
               TEXT
+  "Are you using AI/LLM (ChatGPT/Cursor/Claude etc) to assist you in writing 
Airflow code?"  TEXT

Review Comment:
   ```suggestion
     "Are you using AI/LLM (ChatGPT/Cursor/Claude etc) to assist you in writing 
Airflow code?"   TEXT
   ```
   
   nit



##########
providers/common/ai/src/airflow/providers/common/ai/example_dags/example_llm_survey_analysis.py:
##########
@@ -0,0 +1,423 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+"""
+<<<<<<< HEAD
+Natural language analysis of a survey CSV — interactive and scheduled variants.
+
+Both DAGs query the `Airflow Community Survey 2025
+<https://airflow.apache.org/survey/>`__ CSV using
+:class:`~airflow.providers.common.ai.operators.llm_sql.LLMSQLQueryOperator`
+and 
:class:`~airflow.providers.common.sql.operators.analytics.AnalyticsOperator`.
+
+``example_llm_survey_interactive`` (five tasks, manual trigger)
+  Adds human-in-the-loop review at both ends of the pipeline:
+
+  1. **HITLEntryOperator** — human reviews and optionally edits the question.
+  2. **LLMSQLQueryOperator** — translates the confirmed question into SQL.
+  3. **AnalyticsOperator** — executes the SQL against the CSV via Apache 
DataFusion.
+  4. A ``@task`` function — extracts the data rows from the JSON payload.
+  5. **ApprovalOperator** — human approves or rejects the query result.
+
+``example_llm_survey_scheduled`` (three tasks, runs on a schedule)
+  Runs a fixed question end-to-end without human review — suitable for
+  recurring reporting or dashboards:
+
+  1. **LLMSQLQueryOperator** — translates the question into SQL.
+  2. **AnalyticsOperator** — executes the SQL against the CSV.
+  3. A ``@task`` function — extracts the data rows from the JSON payload.
+
+Before running either DAG:
+=======
+Interactive natural language analysis of a survey CSV.
+
+``example_llm_survey_interactive`` queries the `Airflow Community Survey 2025
+<https://airflow.apache.org/survey/>`__ CSV using a five-step pipeline:
+
+  1. **HITLEntryOperator** — human reviews and optionally edits the question.
+  2. **LLMSQLQueryOperator** — translates the confirmed question into SQL.
+  3. **AnalyticsOperator** — executes the SQL against the CSV via Apache
+     DataFusion and returns the results as JSON.
+  4. A ``@task`` function — extracts the data rows from the JSON payload.
+  5. **ApprovalOperator** — human approves or rejects the query result.
+
+Before running:
+>>>>>>> 6d60bff29b8b7c6916d49033f0956ae6ceff5ab3
+
+1. Create an LLM connection named ``pydanticai_default`` (or the value of
+   ``LLM_CONN_ID`` below) for your chosen model provider.
+2. Place the survey CSV at the path set by the ``SURVEY_CSV_PATH``
+   environment variable, or update ``SURVEY_CSV_PATH`` below.
+   A cleaned copy of the 2025 survey CSV (duplicate columns renamed, embedded
+   newlines removed) is required — Apache DataFusion is strict about these.
+"""
+
+from __future__ import annotations
+
+import datetime
+import json
+import os
+
+<<<<<<< HEAD

Review Comment:
   Got some leftovers in here :)



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to