Repository navigation
Remove code_mode from AgentOperator in favor of the CodeMode capability - #74312
Merged
Merged
Conversation
code_mode=True only appended a bare CodeMode() to the agent's capabilities, which capabilities= now does directly. The flag hid CodeMode's own arguments, most importantly max_tool_calls, whose default of 100 nested calls per run_code snippet is too low for agents that fan out over a list.
vatsrahul1001
approved these changes
Oct 6, 2026
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(code_mode=True)did one thing: it appended a bareCodeMode()from pydantic-ai-harness to the agent's capabilities. Sincecapabilities=became a first-class argument (#73984), that is one line in the Dag file, so this removes the flag and documents the capability instead:The flag also hid every
CodeModeargument, and one of them matters in practice.max_tool_callscaps the nested tool calls a singlerun_codesnippet can make, and its default of 100 is low for an agent that fans out over a list. In a run that classified 167 issue comments (one listing call, 80 comment fetches, 167 classifier calls),code_mode=Truehit the cap and the model had to split its work across snippets: 11 model requests and about 39k input tokens, against 7 requests and about 20k tokens withCodeMode(max_tool_calls=400). A snippet that hits the cap also fails after the calls it already made, so their results are lost.Code mode is documented as experimental, so this is a removal rather than a deprecation. The changelog note covers the migration: replace
code_mode=Truewithcapabilities=[CodeMode()], and move anyagent_params["capabilities"]intocapabilities=too, since the two cannot be combined.The
code-modeextra's floor goes frompydantic-ai-harness>=0.3.0to>=0.24.0, the first release withmax_tool_calls; the docs and example now use it, anduv.lockalready resolves 0.34.0.Two things change for users beyond the argument:
code-modeextra is needed wherever Dag files are parsed. The old flag existed partly to avoid this. The import measured at about 0.02 s;code_mode.rstsays so and suggests keeping code mode agents in their own Dag file.ApprovalRequiredinsiderun_codeand returns it to the model as a retry, so the gated call does not run and the task can still succeed.code_mode.rst,tool_approval.rstand the operator docstring now say that, and how to keep such a tool out ofrun_codewithCodeMode(tools=[...]).The durable and tool-approval guards already recognised a
CodeModecapability (including one nested in aCombinedCapabilityorPrefixTools), so they need no change; only the flag's branches go.{pr_number}.significant.rst, in airflow-core/newsfragments. You can add this file in a follow-up commit after the PR is created so you know the PR number.