Skip to content

Let Common AI toolsets use the agent's tool retry budget - #73957

Merged
kaxil merged 2 commits into
apache:mainfrom
astronomer:toolset-retries
Oct 1, 2026
Merged

kaxil merged 2 commits into
apache:mainfrom
astronomer:toolset-retries

Conversation

@kaxil

@kaxil kaxil commented Sep 30, 2026 •

Copy link
Copy Markdown
Member

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:

Agent retries 3: two failed queries, then the corrected query succeeds

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

Default budget: the second failed query ends the run

SQLToolset, HookToolset, DataFusionToolset and ObjectStorageToolset pinned
max_retries=1 on every tool, overriding 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 a couple of attempts to get a column name right could not.

Each toolset now takes max_retries, defaulting to the run's own tool retry
budget, the way pydantic-ai's FunctionToolset does. Outside a pydantic-ai run
(the LangChain, Strands and ADK bridges) there is no agent budget, so tools
get pydantic-ai's default of one correction, and each bridged call now gets a
context with its own retry count, so ctx.last_attempt means what it does
inside a pydantic-ai run.
@kaxil
kaxil merged commit d886882 into apache:main Oct 1, 2026
81 of 82 checks passed
@kaxil
kaxil deleted the toolset-retries branch October 1, 2026 09:25
kaxil added a commit to astronomer/airflow that referenced this pull request Oct 14, 2026
The toolsets now take max_retries (apache#73957), so the guide no longer says they
allow exactly one correction, and the retry budget docs list the Anthropic
tool runner among the bridges that have no agent budget.
kaxil added a commit to astronomer/airflow that referenced this pull request Oct 14, 2026
The toolsets now take max_retries (apache#73957), so the guide no longer says they
allow exactly one correction, and the retry budget docs list the Anthropic
tool runner among the bridges that have no agent budget. The frameworks page
also names the Anthropic SDK among the frameworks a team can keep.
kaxil added a commit to astronomer/airflow that referenced this pull request Oct 14, 2026
The toolsets now take max_retries (apache#73957), so the guide no longer says they
allow exactly one correction, and the retry budget docs list the Anthropic
tool runner among the bridges that have no agent budget. The frameworks page
also names the Anthropic SDK among the frameworks a team can keep.
kaxil added a commit that referenced this pull request Oct 14, 2026
Agents written on the Anthropic SDK's client.beta.messages.tool_runner can now
use common.ai's connection-backed toolsets (SQLToolset, HookToolset,
ObjectStorageToolset, sandboxes) through AirflowTools and AsyncAirflowTools,
with the same guarantees as the Strands and ADK adapters: masked results,
correctable failures returned as is_error results within the retry limit,
and any other failure failing the task before the next model request.

run_coroutine_sync now copies the caller's context into its worker thread,
and the anthropic extra's floor moves to 1.1.0, the first release whose tool
runner only runs a turn's tool calls when the turn ends in tool_use.

* Tighten the Anthropic tool runner guide

* Narrow the message block type in the Anthropic adapter tests

* Mention toolset max_retries in the Anthropic tool runner guide

The toolsets now take max_retries (#73957), so the guide no longer says they
allow exactly one correction, and the retry budget docs list the Anthropic
tool runner among the bridges that have no agent budget. The frameworks page
also names the Anthropic SDK among the frameworks a team can keep.

* Fail the Anthropic tool runner adapter's run at max_iterations mid-task

A runner that reaches max_iterations while the model is still calling tools
ends on that tool_use turn, which holds no answer. tools.run now raises
ToolRunnerMaxIterationsError instead of returning it, so the task fails
rather than succeeding with an empty result.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants