Skip to content
TheChatArchiveThe Chat Archive
Claudeclaude-sonnet-5· anthropicHugging Face ibragim-bad/swe_rebench_07_2026_trajectories

ISSUE DESCRIPTION Deferred capabilities throw error 400 with Deepseek models Initial…

  1. User

    ISSUE DESCRIPTION

    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.

    ADDITIONAL ADVICE

    Since you are given a git repository, you can use git commands to simplify your work. For example, if you made a mistake and want to revert your changes, you can use git checkout <file> to restore the file to its original state. You can also reset all changes in the repository using git reset --hard command. Additionally, you can use git stash and git stash pop to temporarily save your changes and restore them later. Finally, you can see the changes that you've made (which will be submitted when you call submit) using git status or git diff commands. However you don't need to use git add or git commit before submitting your changes. In fact, submit only submits currently unstaged changes because it uses git diff to get the changes that need to be submitted.

    CHECKLIST

    Before submitting your solution, please go over the following checklist and make sure you've done everything:

    • If an error was reported in the issue description, I have successfully reproduced it.
    • If an error was reported in the issue description, I have confirmed that my fix resolves the error.
    • I have thought about edge cases and made sure my fix handles them as well.
    • I have run existing tests in the repository that might have been affected by the change I made and confirmed that they pass. I want you to list every bullet from this checklist and write your reasoning for why you think you did it or didn't need to.

    Repository has been uploaded and your shell is currently at the repository root. Time to solve the issue!

    (Current directory: /pydantic-ai, current file: none) bash-$

  2. Claude Assistant

    Let's look at the test around line 3100-3170 which shows the exact synthesized structure and see if there's related context about DeepSeek/thinking.

  3. Claude Assistant

    Now let's make the edit. First update the imports to include ThinkingPart:

  4. Claude Assistant

    There's a duplicate closing paren at line 19. Let's fix it.

  5. Claude Assistant

    Good, fixed. Now let's update the before_model_request method to carry forward thinking parts.

  6. Claude Assistant

    I'll use edit directly on line ranges instead.

  7. Claude Assistant

    Now let's re-run the reproduction script to confirm the fix.

  8. Claude Assistant

    Now the synthetic assistant message includes reasoning_content, matching what DeepSeek requires. Let's clean up temp scripts and run the test suite for capabilities/tool_search/deepseek.

  9. Claude Assistant

    All passing. Now let's run the tool search tests and deepseek tests.

  10. Claude Assistant

    Let's also run the broader test suite for models and native tool search / anthropic to ensure no regressions from adding ThinkingPart to synthetic exchanges (in case of Anthropic-specific handling).

  11. Claude Assistant

    Now let's run the full test suite to be safe (or at least a broad relevant subset) plus type checking/linting used by this repo.

  12. Claude Assistant

    Now let's run the broader test suite to catch any regressions across the whole repo (in parallel for speed).

  13. Claude Assistant

    Confirmed pre-existing failures unrelated to my change (dbos/sqlalchemy environment issue). Let's check the two "UserWarning" test failures in models that appeared in the full run to make sure they aren't related.

  14. Claude Assistant

    Identical baseline results (26 failed, 7814 passed, 526 skipped, 3 xfailed, 6 errors) — confirming these failures are pre-existing environment issues unrelated to my change. My change introduces no new failures.

  15. Claude Assistant

    No changelog file to update. Let's do a final review of the diff and clean up.

  16. Claude Assistant

    Let's also run the full test_capabilities.py, test_tool_search.py, and the relevant model tests once more together to be safe, and remove any leftover temp files.

  17. Claude Assistant

    All 1316 tests pass. Temp files were already cleaned up (the ls non-zero exit is just because no leftover repro files exist, which is expected).

  18. Claude Assistant

    Good, no leftover temp files. Let's do a final review of the diff.

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