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_contenthandling in the codebase. - Assistant
Implementing the fix: DeepSeek requires
reasoning_contenton every assistant message with tool calls in thinking mode; deferred capabilities inject a syntheticsearch_toolsassistant message without it. - Assistant
Root Cause
With
defer_loading=True, loading a capability triggers a client-side syntheticsearch_toolsexchange (inToolSearchCapability.before_model_request) so deferred tools become visible without busting the prompt cache.
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.