Deferred capabilities throw error 400 with Deepseek models Initial Checks - [x] I'm…
- User
Deferred capabilities throw error 400 with Deepseek models
Initial Checks
- I'm using the latest version of Pydantic AI
- I've searched for my issue in the issue tracker before opening this issue
Description
When running an agent using a DeepSeek reasoning model, using
Capability(..., defer_loading=True)causes aModelHTTPError: status_code: 400during execution loop turns.codeopenai.BadRequestError: Error code: 400 - {'error': {'message': 'The `reasoning_content` in the thinking mode must be passed back to the API.', 'type': 'invalid_request_error', 'param': None, 'code': 'invalid_request_error'}}This is triggered because DeepSeek requires the original
reasoning_contentproduced during the thinking phase to be passed back exactly as-is in the subsequent conversation message history array. Whendefer_loading=True, the graph loop intercepted by PydanticAI's capability runner seems to drop or fail to serialize/propagate thereasoning_contenttoken block back to DeepSeek's chat completions endpoint.Setting
defer_loading=Falsesolves the issue, and the agent executes successfully.Minimal, Reproducible Example
Python - Assistant
Investigating how deferred capabilities interact with DeepSeek's
reasoning_contentin message history. - Assistant
Reproducing with a mock to see where
reasoning_contentis dropped in the deferred-capability flow. - Assistant
Identified the issue: after
load_capability,ToolSearchinjects a synthetic assistantsearch_toolsmessage withoutreasoning_content, which DeepSeek rejects. Fixing_into_message_paramto always include the thinking field whenopenai_chat_send_back_thinking_parts='field'. - Assistant
Root cause
With
defer_loading=True, loading a capability triggersToolSearch.before_model_requestto inject a synthetic assistant exchange so deferred tools become discoverable. That synthetic only contains a — no .
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.