You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "kaxil (via GitHub)" <gi...@apache.org> on 2026/09/30 14:10:52 UTC
[PR] Let Common AI toolsets use the agent's tool retry budget [airflow]
kaxil opened a new pull request, #73957:
URL: https://github.com/apache/airflow/pull/73957
`SQLToolset`, `HookToolset`, `DataFusionToolset` and `ObjectStorageToolset` pinned `max_retries=1` on every tool, which overrides the agent's `retries`. An agent given `retries=3` still ended its run on the second failed query in a row, so a model that needed two tries to get a column name right could not recover. The only workaround was to subclass the toolset and rewrite `max_retries` in `get_tools`.
Each toolset now takes `max_retries`, defaulting to `None`, which uses the run's own tool retry budget (`ctx.max_retries`, the agent's `retries`). That is the order pydantic-ai's own `FunctionToolset` and `MCPServer` use, so these toolsets now behave like pydantic-ai's. The fallback lives once on `AirflowToolset`.
**Agents that already set `retries` now apply it to these toolsets.** They used to allow exactly one correction whatever `retries` said. `retries=0` now fails the run on the first bad query, and a large integer `retries` meant for output validation also lets a failing database be queried that many times. A dict such as `retries={"output": 3}` raises only the output budget, and `max_retries=1` on a toolset keeps the old behaviour. The new docs section spells this out.
**What the budget counts differs by toolset**, and the docs now say so. `SQLToolset` and `DataFusionToolset` turn every query error into `ModelRetry`. `HookToolset` counts invalid arguments and attempts to change a pinned argument; an exception from the hook fails the run straight away. `ObjectStorageToolset` counts invalid arguments only, since a failed read comes back as `ToolFailed`, which pydantic-ai does not count.
**Outside a pydantic-ai agent** (the LangChain, Strands and Google ADK bridges) there is no agent budget, so the bridge's placeholder `RunContext` now carries pydantic-ai's default of one correction. Each bridged call also gets its own copy with the tool's retry count, as pydantic-ai's `ToolManager` does, so `ctx.last_attempt` means the same through a bridge as inside a run. One side effect: a bare `FunctionToolset` or `MCPToolset` bridged without its own `max_retries` now gets one correction instead of none, matching a default pydantic-ai agent.
`SandboxToolset` still pins `max_retries=2`. Moving it to the agent's budget would lower its default to one, so it is left for a follow-up.
Run end to end on a local Airflow 3.4.0 with a real `SQLToolset` against SQLite. The model is a scripted pydantic-ai `FunctionModel` that misspells a column twice before reading the error, since a real model will not make the same mistake on demand. With `agent_params={"retries": 3}`, the first two queries fail with `no such column: totl`, the third uses `total`, and the task succeeds:

The same Dag with the default budget still fails on the second error, as before:

--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Let Common AI toolsets use the agent's tool retry budget [airflow]
Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on code in PR #73957:
URL: https://github.com/apache/airflow/pull/73957#discussion_r4152887669
##########
providers/common/ai/src/airflow/providers/common/ai/utils/toolset_base.py:
##########
@@ -181,6 +188,18 @@ async def call_tool(
name, self.execute_tool(name, tool_args, ctx=ctx, tool=tool), count_as=type(self).__name__
)
+ #: A subclass that takes ``max_retries`` stores it here; ``None`` follows the run.
+ _max_retries: int | None = None
+
+ def _tool_max_retries(self, ctx: RunContext[Any]) -> int:
Review Comment:
```suggestion
def _get_tool_max_retries(self, ctx: RunContext[Any]) -> int:
```
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Let Common AI toolsets use the agent's tool retry budget [airflow]
Posted by "kaxil (via GitHub)" <gi...@apache.org>.
kaxil merged PR #73957:
URL: https://github.com/apache/airflow/pull/73957
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Let Common AI toolsets use the agent's tool retry budget [airflow]
Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W commented on code in PR #73957:
URL: https://github.com/apache/airflow/pull/73957#discussion_r4152885378
##########
providers/common/ai/src/airflow/providers/common/ai/utils/toolset_base.py:
##########
@@ -181,6 +188,18 @@ async def call_tool(
name, self.execute_tool(name, tool_args, ctx=ctx, tool=tool), count_as=type(self).__name__
)
+ #: A subclass that takes ``max_retries`` stores it here; ``None`` follows the run.
Review Comment:
We decided not to use this syntax some time ago in antoher PR review
```suggestion
# A subclass that takes ``max_retries`` stores it here; ``None`` follows the run.
```
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Let Common AI toolsets use the agent's tool retry budget [airflow]
Posted by "kaxil (via GitHub)" <gi...@apache.org>.
kaxil commented on code in PR #73957:
URL: https://github.com/apache/airflow/pull/73957#discussion_r4153396595
##########
providers/common/ai/src/airflow/providers/common/ai/utils/toolset_base.py:
##########
@@ -181,6 +188,18 @@ async def call_tool(
name, self.execute_tool(name, tool_args, ctx=ctx, tool=tool), count_as=type(self).__name__
)
+ #: A subclass that takes ``max_retries`` stores it here; ``None`` follows the run.
Review Comment:
Done in 6a861d67db9: plain comment, and renamed to `_get_tool_max_retries` at all call sites.
##########
providers/common/ai/src/airflow/providers/common/ai/utils/toolset_base.py:
##########
@@ -181,6 +188,18 @@ async def call_tool(
name, self.execute_tool(name, tool_args, ctx=ctx, tool=tool), count_as=type(self).__name__
)
+ #: A subclass that takes ``max_retries`` stores it here; ``None`` follows the run.
+ _max_retries: int | None = None
+
+ def _tool_max_retries(self, ctx: RunContext[Any]) -> int:
Review Comment:
Done in 6a861d67db9: plain comment, and renamed to `_get_tool_max_retries` at all call sites.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org