Repository navigation
Let durable agent tasks use toolsets without an id - #76877
Merged
Merged
Conversation
kaxil
marked this pull request as ready for review
November 11, 2026 01:20
kaxil
force-pushed
the
durable-toolsets-without-id
branch
from
November 11, 2026 02:34
36dcaf2 to
ea2b7cb
Compare
Lee-W
reviewed
Nov 11, 2026
kaxil
force-pushed
the
durable-toolsets-without-id
branch
from
November 11, 2026 12:17
ea2b7cb to
d7253c2
Compare
kaxil
force-pushed
the
durable-toolsets-without-id
branch
from
November 11, 2026 17:05
d7253c2 to
67227e2
Compare
Contributor
|
The re-run of the jobs stopped by EC2 Spot interruptions finished: attempt 2 passed. |
kaxil
enabled stacked auto-merge (squash)
November 11, 2026 18:18
stacked auto-merge was automatically disabled
November 11, 2026 18:18
Replaced by a newer auto-merge request
kaxil
enabled stacked auto-merge (squash)
November 11, 2026 18:18
Lee-W
approved these changes
Nov 12, 2026
amoghrajesh
reviewed
Nov 12, 2026
kaxil
force-pushed
the
durable-toolsets-without-id
branch
from
November 12, 2026 11:54
67227e2 to
79212d5
Compare
stacked auto-merge was automatically disabled
November 12, 2026 13:10
Auto-merge was disabled for another pull request in the stack
kaxil
force-pushed
the
durable-toolsets-without-id
branch
2 times, most recently
from
November 12, 2026 13:11
07267aa to
f1affda
Compare
AgentOperator(durable=True) and @task.agent(durable=True) no longer refuse a FunctionToolset without an id or a function that builds a toolset per run. The operator gives an id-less FunctionToolset a copy numbered in the order the toolsets are passed, and a function its module and qualified name (without the path hash Airflow puts in a Dag file's module name). Function tool steps are named after the tool alone; a toolset id the author chose keeps its place in step names, so journals recorded before this change still replay. A pydantic-ai MCPToolset without an id is now refused when the Dag loads instead of on the first run, and so is a callable without a qualified name or two functions sharing one.
Rename callable_toolset_id to get_callable_toolset_id. The step namer now rewrites only the call_tool name: the validate_args name it also rewrote is never journaled, since argument validation runs live. Say in the tests why they fail if pydantic-ai stops reading the private FunctionToolset._id that durable runs write on a copy, and elide the memory address in the sample error in the durable execution docs.
pydantic-ai keeps toolset ids in angle brackets for roles it fills itself, such as <agent>, so the id given to a FunctionToolset without one is now __airflow_function_toolset_<n> instead of <airflow-function_toolset-<n>>. The helpers that give the ids are only used by AgentOperator, so they are private now: _get_callable_toolset_id, _get_chosen_toolset_id (was chosen_toolset_id), _give_durable_ids and _GivenIds.
kaxil
force-pushed
the
durable-toolsets-without-id
branch
from
November 12, 2026 13:12
f1affda to
40c4135
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
AgentOperator(durable=True)and@task.agent(durable=True)refused to load a Dag that passed aFunctionToolsetwithout anid, or a function that builds a toolset for each run:pydantic-ai names a durable step after the toolset's id, so the operator asked the Dag author for one. That makes an ordinary agent fail as soon as
durable=Trueis added, and it blocks turning durable execution on by default later in this stack. With this PR the operator fills in the ids itself, and this agent needs none:FunctionToolsetis handed to the agent as a copy with an id numbered in the order the toolsets are passed (__airflow_function_toolset_0). Its tool calls are recorded under the tool's name alone,durable_order_status__function_toolset.call_tool:get_order, so adding a tool to the toolset never renames another tool's step.DynamicToolset) gets its module and qualified name,example_agent_durable.carrier_tools. Theunusual_prefix_<sha1 of the file path>_that Airflow puts in a Dag file's module name is left out, because the path can differ between workers and bundle versions.This covers toolsets passed in
toolsets=,agent_params["toolsets"], and aFunctionToolsetheld directly by aToolsetcapability.AirflowDurabilityused in a plain@taskis unchanged: there pydantic-ai still raises for an id-less toolset.Still refused when the Dag loads:
MCPToolsetwithout an id. No id is derived from the server's URL or command, which can carry credentials. The old check testedleaf.id is None, but pydantic-ai 2.62+ derives.idfrom an HTTP server's hostname, so an id-less HTTPMCPToolsetpassed the load-time check. The check now reads the id the author set (_explicit_id, falling back to.idbefore 2.62).__qualname__(afunctools.partial, a callable object): pass it asDynamicToolset(function, id=...).Design rationale
Renaming steps alone wasn't enough. pydantic-ai's durability capability looks its durable toolsets up by id when the agent is built and swaps them in by id on every run, so an id-less toolset still hits its
UserError. The operator sets_idon a copy instead (_render_toolsetsalready copies toolsets to set rendered fields on them; the Dag author's object isn't touched). The other options I weighed were overriding_register_toolsets,_wrap_and_register_leafandget_wrapper_toolsetonBaseDurabilityCapability, which means three private methods to keep in step with pydantic-ai from 2.46 to 2.66, and journaling function tools in Airflow's own wrapper, which renames the steps of every toolset that already has an id.The old check refused derived ids on purpose, so that reordering the list couldn't point a retry at another toolset's recorded calls. The number Airflow assigns stays out of step names (an Airflow
JournalOperationNamerdrops it), and pydantic-ai refuses two tools with the same name in one agent, so a step named after the tool can't match the wrong toolset. Reordering or adding toolsets changes the tools the model is offered, and the retry runs again from the first model request, as it does today when someone edits a toolset that has an id. My first version used a random id, which broke replay for a toolset with instructions: pydantic-ai copies the toolset id into tool definitions and instruction ids, and the request fingerprint hashes both. There's no colon in the id because pydantic-ai rejects one on a toolset with instructions.Old journals: the namer only strips ids Airflow assigned, and every toolset journaled before this change had an id the author chose, because id-less ones were refused at load. I ran the previous code against a JSON-file journal until it recorded
orders_agent__function_toolset__orders.call_tool:lookupand failed on the next model request, then retried with this code over the same file. The model request andlookupreplayed (0 livelookupcalls) and only the final request ran live.End to end
A durable
AgentOperatorwith a real model (openai:gpt-5.4-minithrough a gateway),retries=1, an id-lessFunctionToolsetwithget_orderandpost_update, and acarrier_toolsfunction that builds aFunctionToolsetwithtrack_parcel.post_updateraises on try 1.Try 1 runs all three tools live, then fails in
post_update:Try 2 replays
get_orderandtrack_parcel(returned in 0.00s, noTOOL RAN LIVEline) and the recorded model requests, then runspost_updateand the final request:Known issues
A
FunctionToolsetnested deeper in the capabilities, insideCombinedCapability([...]),PrefixTools(wrapped=Toolset(...))or aToolset(build_fn), still doesn't get an id: the Dag loads and every durable attempt fails with pydantic-ai'sUserError, the same as before this PR. The docs only promise the three places above; the operator would have to walkWrapperCapability.wrappedandCombinedCapability.capabilitiesto reach the rest.