kaxil commented on code in PR #76917:
URL: https://github.com/apache/airflow/pull/76917#discussion_r4647242536
##########
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:
Good catch, I could reproduce it: change the Dag between attempts and the
fallback ran attempt 1's tool again, then left the old journal behind. Fixed in
e6701ffa09b. The operator opens the journal before building the agent now, and
if pydantic-ai refuses the first run under the default while the journal
already holds a run (same `holds_steps()` check the run-time fallback uses),
the task fails and the log points at `durable=False`. If nothing was recorded
it still falls back and cleans up the old run id.
I left HITL regeneration falling back on purpose, since it carries on from
the stored conversation and doesn't repeat run 0. A retry after a review round
goes through `execute`, so it hits the same check. The new tests are in
`test_agent.py` and `test_agent_hitl_review.py`.
--
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]