Frame a capability's tool content at its authority ceiling when the tool is called through Code Mode or `ToolBridge`
- No linked issue.
Why we make these changes
Custom capabilities documents that the ToolReturn.content of a tool a capability at 'none' contributes goes out as <capability_content> data naming the capability, not as user text. That held when the model called the tool directly. Called from run_code (CodeMode, IPythonCodeMode) or ToolBridge's tool_call, the content was re-emitted as the calling tool's own, so the calling capability's authority applied and it went out as plain user text.
The nested paths now return that content with the capability each tool came from, and core holds each tool's content to each capability it passed through, innermost first: its own, then the calling tool's. That also covers code that calls tool_call from run_code.
Two separate commits fix the docstrings of RetryFeedbackPart and RetryFeedbackCause, which said retry feedback goes out in the user voice: OpenAIDecisionsModel sends it as a developer message, as the Decisions API docs say.
New public surface
None.
User-visible behavior
from pydantic_ai import Agent, ToolReturn
from pydantic_ai.capabilities import Capability
from pydantic_ai_harness import CodeMode
def fetch() -> ToolReturn:
return ToolReturn(return_value='ok', content='page text')
agent = Agent(..., capabilities=[Capability(id='plugin', tools=[fetch]).with_authority('none'), CodeMode()])
# The model's `run_code` calls `await fetch()`. The next request carries:
# before: 'page text' as plain user text
# after: the same frame a direct `fetch` call gets: a note naming the `plugin` capability, then
# <capability_content>page text</capability_content>
Verification
tests/harness/code_mode/test_code_mode.py::TestCodeMode::test_tool_return_content_is_held_to_its_capabilitys_authoritytests/harness/tool_bridge/test_tool_bridge.py::TestToolBridge::test_bridged_tool_content_is_held_to_its_capabilitys_authoritytests/harness/tool_bridge/test_tool_bridge.py::TestToolBridge::test_code_mode_keeps_a_bridged_tools_capabilitytests/harness/ipython_code_mode/test_ipython_code_mode.py::TestIPythonCodeModeTools::test_tool_return_content_is_held_to_its_capabilitys_authoritytests/harness/ipython_code_mode/test_ipython_code_mode.py::TestIPythonCodeModeTools::test_a_bridged_tools_content_is_held_to_its_capabilitys_authority
Each compares what the model receives against a direct call of the same tool, and fails without the fix. The Code Mode tests also pin that content from other tools around it stays user text, in call order.
What changes for existing users
Only content from a tool of a capability below 'operator' that a nested call returns is framed differently; every other nested content keeps the single user part it had.
PR decisions
2026-11-24 · Nested content carries its capability through ToolReturn.content, not ctx.enqueue · iter -
- Decision: Code Mode, IPythonCodeMode and ToolBridge return nested ToolReturn.content as NestedCallContent (private, pydantic_ai._tool_execution); core's _tool_user_parts holds each tool's content to its own capability, then to the calling tool's
- Why: Enqueued 'asap' content can force one more model request when a run would otherwise end, and ctx.enqueue raises inside durable units; a direct call's ToolReturn.content does neither
- Source: https://github.com/pydantic/pydantic-ai/tree/nested-call-content-framing
- Session: c2361f9a-a90d-45f9-aeca-a0a4bb7a329a
2026-11-24 · IPythonCodeMode is in scope · iter -
- Decision: Fix IPythonCodeMode alongside Code Mode
- Why: It shares record_nested_call, and its new test fails on the pre-fix source
- Source: https://github.com/pydantic/pydantic-ai/tree/nested-call-content-framing
- Session: c2361f9a-a90d-45f9-aeca-a0a4bb7a329a
2026-11-24 · pre-push review 1 of 3 at e288ede08cf2d71daabb8d961dc017d9c44636ec · iter -
- Decision: remediated: Code Mode calling a bridged tool now keeps the bridged tool's capability (reproduced first); comment no longer describes past state. Dismissed: missing coverage of adjacent user-text segments (test_tool_return_content_reaches_the_model merges two such segments and asserts the single part)
- Why: tree dd9ac4bf041897801d621d92dccefe9b0a38580a; scope 6fe9278597..e288ede08c, full branch
- Source: https://github.com/pydantic/pydantic-ai/tree/nested-call-content-framing
- Session: c2361f9a-a90d-45f9-aeca-a0a4bb7a329a
2026-11-24 · pre-push review 2 of 3 at fe819d9e78861324c4bdb1e80d2626bcacfb1221 · iter -
- Decision: remediated: added an IPythonCodeMode test for code calling a bridged tool (it fails at e288ede08c, passes at fe819d9e78), so the shared record_nested_call change is reproduced there. Dismissed: 'RetryFeedbackPart docstring not applied' (it is in e288ede08c, outside the follow-up delta the reviewer read)
- Why: tree c8e4e0c9a528ee73f74a108953deb8dcc70c34bb; scope e288ede08c..fe819d9e78
- Source: https://github.com/pydantic/pydantic-ai/tree/nested-call-content-framing
- Session: c2361f9a-a90d-45f9-aeca-a0a4bb7a329a
2026-11-24 · exempt delta ab5b2faca1 from reviewed fe819d9e78 · iter -
- Decision: no third pre-push review
- Why: test code only (tests/harness/ipython_code_mode/test_ipython_code_mode.py); the expectation is the direct-call framing the other new tests pin; the test passes at ab5b2faca1
- Source: https://github.com/pydantic/pydantic-ai/tree/nested-call-content-framing
- Session: c2361f9a-a90d-45f9-aeca-a0a4bb7a329a
Checklist
- No breaking changes in accordance with the version policy.
- Any permitted compatibility impact has a label, warning, migration and release note, and an exact API-check waiver if the gate reports it.
- PR title is fit for the release changelog.
Summary by cubic
Fixes capability authority framing for nested tool content, so a tool's ToolReturn.content reaches the model with its own capability's authority when called through run_code (CodeMode, IPythonCodeMode) or ToolBridge's tool_call, matching a direct call. Previously the nested paths re-emitted that content as the calling tool's own, so a capability at 'none' authority had its content pass as plain user text.
- Held-to-capability content now carries the run id of every capability it passed through, innermost first; content that stays user text keeps the single part it had.
ToolBridgekeeps a bridged tool's capability when code callstool_call, andCodeMode/IPythonCodeModepreserve it in their collection of nested results.- A bridged tool no capability below
'operator'contributes keeps itsToolReturn.contentas returned, so hooks and result events see the originalstrrather than a list. - A hook that edits
run_code's ortool_call'sToolReturn.contentin place now reaches the model as edited, held to every capability that contributed to it; replaced content is held to the calling tool's capability alone. - Corrects
RetryFeedbackPartandRetryFeedbackCausedocstrings:OpenAIDecisionsModelsends retry feedback as adevelopermessage, not in the user voice. - Refactors
_tool_user_parts, shares str-or-sequence flattening, and inlines theToolReturnguard inToolBridge._callso importing the media store no longer loadspydantic_ai.
Verification
- New tests pin that nested content matches a direct call across
CodeMode,IPythonCodeMode, bridged calls, code callingtool_callfromrun_code, in-place hook edits, a chain where each capability lowers the content further, and a bridged tool at no or'operator'authority; they fail without the fix.
No breaking changes and no new public surface.