Copilot commented on code in PR #76917:
URL: https://github.com/apache/airflow/pull/76917#discussion_r4594308416
##########
providers/common/ai/docs/operators/agent.rst:
##########
@@ -236,8 +236,9 @@ file, and ``system_prompt`` is added to the file's
``instructions``:
Build the path from ``__file__``: a relative path resolves against the worker's
working directory, not the Dag file.
-With ``durable=True``, the toolsets that spec-file capabilities contribute are
replayed
-like any other, and need an id the same way (see :doc:`../durable_execution`).
The
+With durable execution (on by default for a task that can retry on Airflow 3.3
and later;
+see :doc:`../durable_execution`), the toolsets that spec-file capabilities
contribute are
+replayed like any other, and need an id the same way. The
operator cannot see inside a spec file when the Dag is parsed, so a missing id
there
fails the task when the agent is built rather than the Dag when it loads.
Review Comment:
This paragraph now includes the default-on mode, but still says a missing
spec-file toolset id fails the task. `_build_agent_as_decided()` catches that
build-time `UserError` under the default and runs without durable execution
instead. Please distinguish that fallback from the task failure retained by
`durable=True`.
---
Drafted-by: GitHub Copilot (no human review before posting)
##########
providers/common/ai/src/airflow/providers/common/ai/operators/agent.py:
##########
@@ -1079,6 +1170,27 @@ def prepare(toolset: AbstractToolset[Any] |
ToolsetFunc[Any]) -> AbstractToolset
**extra_kwargs,
)
+ def _build_agent_as_decided(self, *, approval_context: Context | None =
None) -> Agent[object, Any]:
+ """
+ Build the agent, durable if the run was decided durable.
+
+ pydantic-ai checks a durable agent when it builds it and refuses some
shapes the checks in
+ ``_durable_problem`` do not cover, such as a capability with durable
operations and no
+ ``id``. Under the default, such an agent is built without durable
execution and the task
+ log gives pydantic-ai's reason; ``durable=True`` keeps the error.
+ """
+ try:
+ return self._build_agent(approval_context=approval_context)
+ except UserError as error:
+ if not self._is_durable_run or self.durable is not None:
+ raise
+ self._is_durable_run = False
+ self._durable_journal = None
+ # Built first: an error unrelated to durable execution raises
again here, unlogged.
+ agent = self._build_agent(approval_context=approval_context)
Review Comment:
If an earlier attempt completed a side-effecting tool and the retry's
configuration now fails durable construction, this fallback runs that tool live
again and leaves the old journal behind after success. Check the persisted
journal before disabling durability, and retain the refusal when earlier work
exists, as the runtime fallback does with `holds_steps()`. Cover both initial
execution and HITL regeneration, and add a two-attempt regression for a
build-time refusal.
---
Drafted-by: GitHub Copilot (no human review before posting)
--
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]