Skip to content
TheChatArchiveThe Chat Archive
gpt-5.6-sol· openaiHugging Face ibragim-bad/swe_rebench_07_2026_trajectories

Deferred capabilities throw error 400 with Deepseek models Initial Checks - [x] I'm…

  1. User

    Deferred capabilities throw error 400 with Deepseek models

    Initial Checks

    Description

    When running an agent using a DeepSeek reasoning model, using Capability(..., defer_loading=True) causes a ModelHTTPError: status_code: 400 during execution loop turns.

    openai.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_content produced during the thinking phase to be passed back exactly as-is in the subsequent conversation message history array. When defer_loading=True, the graph loop intercepted by PydanticAI's capability runner seems to drop or fail to serialize/propagate the reasoning_content token block back to DeepSeek's chat completions endpoint.

    Setting defer_loading=False solves the issue, and the agent executes successfully.

    Minimal, Reproducible Example

    # Remember to export the DEEPSEEK_API_KEY environment variable first, then run this code
    
    import random
    from pydantic_ai import Agent, RunContext
    from pydantic_ai.capabilities import Capability
    
    
    def roll_dice() -> str:
      """Roll a six-sided die and return the result."""
      return str(random.randint(1, 6))
    
    def get_player_name(ctx: RunContext[str]) -> str:
      """Get the player's name."""
      return ctx.deps
    
    
    agent = Agent(
      'deepseek:deepseek-v4-flash',  
      deps_type=str,  
      instructions=(
          "You're a dice game, you should roll the die and see if the number "
          "you get back matches the user's guess. If so, tell them they're a winner. "
          "Use the player's name in the response."
      ),
      capabilities=[Capability(id='DICE_ROLL', tools=[get_player_name, roll_dice], defer_loading=True)] # Change this to False and the agent will run successfully.
    )
    
    dice_result = agent.run_sync('My guess is 4', deps='Anne')  
    print(dice_result.output)
    

    Logfire Trace

    No response

    Python, Pydantic AI & LLM client version

    • Python: 3.14
    • Pydantic AI: 1.106.0
    • LLM provider SDK: deepseek

    Interface

    No new interfaces are introduced.

  2. Assistant

    I’ll trace the deferred-capability message round trip locally, reproduce the DeepSeek serialization gap with focused tests, then implement and verify the smallest compatible fix. I’m using the complete-partial-pr skill because this provider-specific symptom may expose adjacent message-history and round-trip requirements.

  3. Assistant

    The repository has no rg, so I’m using targeted find/grep searches. The issue description gives a concrete protocol contract; per the workspace restriction I’ll rely on local SDK types, tests, and git history rather than querying GitHub or provider docs.

  4. Assistant

    The normalized DeepSeek adapter already preserves real reasoning_content. The problematic adjacent surface is deferred loading’s framework-synthesized search_tools call: it creates an assistant tool-call message that never came from DeepSeek and therefore has no original reasoning block. I’m validating whether that bookkeeping should be omitted from local-provider wire history while remaining in Pydantic AI’s normalized history.

  5. Assistant

    The clean fix is a model-profile fact, not a DeepSeek name check: DeepSeek Chat requires the configured thinking field on replayed assistant tool-call messages, including framework-synthesized ones. Real reasoning remains byte-for-byte unchanged; synthetic calls receive an explicit empty reasoning_content field so the wire shape satisfies DeepSeek without inventing chain-of-thought.

  6. Assistant

    The regression now passes, and the broader OpenAI-chat and DeepSeek provider suites remain green. I’m finishing with targeted formatting/lint and type checks, then I’ll inspect the final diff for API and history-round-trip scope.

Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.