Lee-W commented on code in PR #77071:
URL: https://github.com/apache/airflow/pull/77071#discussion_r4639853735


##########
providers/common/ai/docs/frameworks/openai_agents.rst:
##########
@@ -115,18 +118,29 @@ Run the agent in a task
 -----------------------
 
 In a Dag, build the agent inside the ``@task`` function, so connections are 
read when
-the task runs rather than when the Dag file is parsed. Here the model's API 
key, and
-optionally the base URL of another OpenAI-compatible endpoint such as a 
gateway or a
-self-hosted server, come from an Airflow connection too:
+the task runs rather than when the Dag file is parsed. Here the model's client 
comes
+from an Airflow connection too:
+:meth:`~airflow.providers.openai.hooks.openai.OpenAIHook.aget_conn` returns an
+``AsyncOpenAI`` built from it, which is what the SDK's models take:
 
 .. exampleinclude:: 
/../../ai/src/airflow/providers/common/ai/example_dags/example_openai_agents_agent.py
     :language: python
     :start-after: [START example_openai_agents_agent]
     :end-before: [END example_openai_agents_agent]
 
-The example reads two connections: ``openai_default``, whose password is the 
API key and
-whose host, if set, is the base URL, and ``sql_default``, a database 
connection. Set the
-``LLM_CONN_ID`` and ``DB_CONN_ID`` environment variables to use others.
+The example reads two connections: ``openai_default``, an OpenAI connection, 
and
+``sql_default``, a database connection. Set the ``LLM_CONN_ID`` and 
``DB_CONN_ID``
+environment variables to use others. The OpenAI connection's password is the 
API key and
+its host, if set, is the base URL of another OpenAI-compatible endpoint, such 
as a
+gateway or a self-hosted server. Because the hook builds the client, the 
connection's
+other settings apply too: ``openai_client_kwargs`` in its extra (such as 
``timeout``,
+``organization`` or ``default_headers``), and workload identity instead of an 
API key.
+See :doc:`apache-airflow-providers-openai:connections`.
+
+The task is ``async`` because ``aget_conn`` is a coroutine, and async tasks 
need Airflow
+3.2.1 or later. On an earlier Airflow, a sync task can pass
+``AsyncOpenAI(api_key=conn.password, base_url=conn.host or None)`` to the 
model and run
+the agent with ``Runner.run_sync``, without the connection's other settings.

Review Comment:
   The fallback for Airflow before 3.2.1 names 
`AsyncOpenAI(api_key=conn.password, base_url=conn.host or None)`, but conn 
isn’t defined anywhere in the guide any more, and `BaseHook/get_connectio`n 
aren’t mentioned either. For Airflow 2.11 to 3.1,  this sentence is the whole 
migration path. Could it show where conn comes from (or avoid the variable) and 
mention the `AsyncOpenAI` import, in one short snippet?



##########
providers/common/ai/src/airflow/providers/common/ai/example_dags/example_openai_agents_agent.py:
##########
@@ -27,10 +27,11 @@
 
 Before running:
 
-1. Install the SDK: ``pip install "openai-agents>=0.20.0"``.
-2. Create a connection (``LLM_CONN_ID``, default ``openai_default``) whose 
password is
-   an OpenAI API key. Set its host to the base URL of any other 
OpenAI-compatible
-   endpoint, such as a gateway or a self-hosted server.
+1. Install the SDK and the OpenAI provider:
+   ``pip install "openai-agents>=0.20.0" 
"apache-airflow-providers-openai>=2.2.0"``.
+2. Create an OpenAI connection (``LLM_CONN_ID``, default ``openai_default``) 
whose
+   password is an OpenAI API key. Set its host to the base URL of any other
+   OpenAI-compatible endpoint, such as a gateway or a self-hosted server.

Review Comment:
   For `example_openai_agents_durable.py` and 
`example_openai_agents_data_access.py`: these tasks are now async def, which 
the PR says needs Airflow 3.2.1+, but “Before running” doesn’t say so (only the 
approval example does). Could you add a one-line Airflow requirement to “Before 
running” in all three, pointing to the guide’s fallback?



##########
providers/common/ai/src/airflow/providers/common/ai/example_dags/example_openai_agents_data_access.py:
##########
@@ -25,11 +25,12 @@
 
 Before running:
 
-1. Install the SDK and the provider the bucket needs:
-   ``pip install "openai-agents>=0.20.0" 
"apache-airflow-providers-amazon[s3fs]"``.
-2. Create a connection (``LLM_CONN_ID``, default ``openai_default``) whose 
password is
-   an OpenAI API key. Set its host to the base URL of any other 
OpenAI-compatible
-   endpoint, such as a gateway or a self-hosted server.
+1. Install the SDK, the OpenAI provider and the provider the bucket needs:
+   ``pip install "openai-agents>=0.20.0" 
"apache-airflow-providers-openai>=2.2.0"
+   "apache-airflow-providers-amazon[s3fs]"``.

Review Comment:
   Nit: the pip install command inside the double-backtick literal now spans 
two source lines, so copied from the source file the second line runs as a 
separate shell command. Could it go on one line, or into a literal block?



-- 
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