Skip to content

Add TextReasoningContent #6222

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 2, 2025
Merged

Conversation

stephentoub
Copy link
Member

@stephentoub stephentoub commented Apr 1, 2025

Contributes to #6057

Microsoft Reviewers: Open in CodeFlow

@stephentoub stephentoub requested a review from a team as a code owner April 1, 2025 03:06
@github-actions github-actions bot added the area-ai Microsoft.Extensions.AI libraries label Apr 1, 2025
@SteveSandersonMS
Copy link
Member

Looks good.

Do you think there should be reasoningtext equivalents for the cases where we concat TextContent:

  • ChatMessage.TextReasoning (or maybe better named ChatMessage.ReasoningText as that's what people actually say)
  • ChatResponseExtensions.ToChatResponse[Async] coalescing consecutive TextReasoningContent into a single TextReasoningContent

Of these, I'm more interested in the second one, since otherwise streamed output will produce a huge amount of overhead when added to conversation history, having separate content objects for every chunk of reasoning.

@stephentoub
Copy link
Member Author

@tghamm, IIRC, your anthropic library has two custom types for reasoning. Am I correct that this will enable you to replace one or both of them? I think one was for redacted content and the other not, so at a minimum I'd hope this could be used in place of the non-redacted one?

@stephentoub
Copy link
Member Author

Looks good.

Do you think there should be reasoningtext equivalents for the cases where we concat TextContent:

  • ChatMessage.TextReasoning (or maybe better named ChatMessage.ReasoningText as that's what people actually say)
  • ChatResponseExtensions.ToChatResponse[Async] coalescing consecutive TextReasoningContent into a single TextReasoningContent

Of these, I'm more interested in the second one, since otherwise streamed output will produce a huge amount of overhead when added to conversation history, having separate content objects for every chunk of reasoning.

I will hold off on the first; I'd like us to get more experience with this first. I'll do the second.

@tghamm
Copy link

tghamm commented Apr 1, 2025

@stephentoub You are correct about the two types, and I THINK using the AdditionalProperties dict would allow for storing the necessary Signature field and perhaps a delineator between Redacted/Normal Thinking Text.

So In short, yes, I believe this would allow for the replacement of at least one, if not both types I had to create.

@RogerBarreto
Copy link
Contributor

RogerBarreto commented Apr 1, 2025

Actually the Reasoning Content represents the model Thinking, have we considered using the Thinking name? TextThinkingContent or ThinkingTextContent ?

@stephentoub
Copy link
Member Author

Personally, I prefer "reasoning" over "thinking". These models are generally referred to as reasoning, as this content represents the performed reasoning. @SteveSandersonMS, naming opinion?

@SteveSandersonMS
Copy link
Member

Agreed.

Abstractly, "thinking" and "reasoning" are close enough to synonymous that I don't think there's any first-principles reason to say one is more accurate than the other.

Practically, "reasoning" is the word most commonly used for this type of LLM behavior, so I'd side with that. I know there are examples of people referring to "thinking models" and "thinking tokens" but it seems a lot less common than "reasoning models" and "reasoning tokens".

@RogerBarreto
Copy link
Contributor

Thanks for the input, brought this more by experience using the Ollama where they use the first token sharing the Assistant.Content within <think/> xml node.

image

@stephentoub stephentoub merged commit 444e5cb into dotnet:main Apr 2, 2025
6 checks passed
@stephentoub stephentoub deleted the reasoningcontent branch April 2, 2025 15:31
joperezr pushed a commit to joperezr/extensions that referenced this pull request Apr 8, 2025
* Add TextReasoningContent

* Coalesce TextReasoningContent
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-ai Microsoft.Extensions.AI libraries
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants