kaxil commented on code in PR #77071:
URL: https://github.com/apache/airflow/pull/77071#discussion_r4649237493


##########
providers/common/ai/docs/frameworks/openai_agents.rst:
##########
@@ -558,9 +573,9 @@ Outside a task there is nothing to replay into, and the 
agent runs as ``Runner.r
 it.
 
 What was recorded is deleted when the agent's run succeeds, so clearing the 
task later
-starts over. That happens when ``run_durably_sync`` returns, not when the task
-succeeds: if the task fails after the agent has answered, for example while 
writing the
-answer somewhere, the retry runs the whole agent again. Write the answer in a
+starts over. That happens when ``run_durably`` or ``run_durably_sync`` 
returns, not when
+the task succeeds: if the task fails after the agent has answered, for example 
while
+writing the answer somewhere, the retry runs the whole agent again. Write the 
answer in a
 downstream task, so that a failed write retries on its own. Here 
``build_agent()``
 stands for building the agent as the task example does:

Review Comment:
   Done: it's an async task now, with `aget_conn` and `await run_durably`, same 
as the example.



##########
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"``.

Review Comment:
   Added a "Use Airflow 3.2.1 or later" step to the agent, durable and 
data-access examples, pointing to the guide's fallback.



##########
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:
   Added a short snippet with the `AsyncOpenAI` import and 
`BaseHook.get_connection`. It also mentions 
`OpenAIHook(...).get_conn(async_client=True)` from the next openai provider 
release (#77139), which keeps the connection's other settings.



##########
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:
   Put it on one line.



##########
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:
   Done in all three, same step as above.



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