Skip to content

Conversation

@AlanPonnachan
Copy link
Contributor

Support sending thinking parts in custom request fields for OpenAI-compatible models

Closes: #3446

This PR implements the ability to send reasoning/thinking content in a specific field of the request message (e.g., reasoning_content) for OpenAI-compatible providers that support it, such as Moonshot AI.

Currently, OpenAIChatModel embeds thinking parts into the content string using tags (e.g. <think>...</think>). However, providers like Moonshot recommend sending this data in a separate field to allow the model to process context more effectively.

Changes:

  • pydantic_ai_slim/pydantic_ai/profiles/openai.py: Added openai_chat_reasoning_field to OpenAIModelProfile.
  • pydantic_ai_slim/pydantic_ai/models/openai.py: Updated OpenAIChatModel to check this profile setting. If set, ThinkingPart content is collected and injected into the specified field of the message payload (e.g., messages[i]['reasoning_content']) instead of being appended to content.
  • pydantic_ai_slim/pydantic_ai/profiles/moonshotai.py: Updated the Moonshot AI profile to use reasoning_content.
  • tests/models/test_openai.py: Added test_openai_chat_reasoning_field to verify that the extra field is correctly present in the API request arguments.

@ZeroAurora
Copy link
Contributor

I was working on the same logic in my branch XD
I still have some test work left there though

@DouweM
Copy link
Collaborator

DouweM commented Nov 25, 2025

@AlanPonnachan The other PR by @ZeroAurora is further along so I'll go with that one; still appreciate the effort!

@DouweM DouweM closed this Nov 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants