Skip to content

Remove code_mode from AgentOperator in favor of the CodeMode capability - #74312

Merged
kaxil merged 1 commit into
apache:mainfrom
astronomer:commonai-remove-code-mode-flag
Oct 6, 2026
Merged

kaxil merged 1 commit into
apache:mainfrom
astronomer:commonai-remove-code-mode-flag

Conversation

@kaxil

@kaxil kaxil commented Oct 6, 2026

Copy link
Copy Markdown
Member

AgentOperator(code_mode=True) did one thing: it appended a bare CodeMode() from pydantic-ai-harness to the agent's capabilities. Since capabilities= became a first-class argument (#73984), that is one line in the Dag file, so this removes the flag and documents the capability instead:

from pydantic_ai_harness import CodeMode

AgentOperator(..., capabilities=[CodeMode(max_tool_calls=200)])

The flag also hid every CodeMode argument, and one of them matters in practice. max_tool_calls caps the nested tool calls a single run_code snippet 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=True hit 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 with CodeMode(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=True with capabilities=[CodeMode()], and move any agent_params["capabilities"] into capabilities= too, since the two cannot be combined.

The code-mode extra's floor goes from pydantic-ai-harness>=0.3.0 to >=0.24.0, the first release with max_tool_calls; the docs and example now use it, and uv.lock already resolves 0.34.0.

Two things change for users beyond the argument:

  • The harness is imported when the Dag file is parsed, not when the task runs, so the code-mode extra 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.rst says so and suggests keeping code mode agents in their own Dag file.
  • The docs said a tool that needs approval fails the task under code mode. That was wrong. pydantic-ai-harness catches ApprovalRequired inside run_code and 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.rst and the operator docstring now say that, and how to keep such a tool out of run_code with CodeMode(tools=[...]).

The durable and tool-approval guards already recognised a CodeMode capability (including one nested in a CombinedCapability or PrefixTools), so they need no change; only the flag's branches go.


  • Read the Pull Request Guidelines for more information. Note: commit author/co-author name and email in commits become permanently public when merged.
  • For fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
  • When adding dependency, check compliance with the ASF 3rd Party License Policy.
  • For significant user-facing changes create newsfragment: {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.

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.
@kaxil
kaxil merged commit ac147d0 into apache:main Oct 6, 2026
98 checks passed
@kaxil
kaxil deleted the commonai-remove-code-mode-flag branch October 6, 2026 07:28
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.

2 participants