Skip to content

initial thinking support for claude #15092

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 13 commits into from
Mar 27, 2025
Merged

initial thinking support for claude #15092

merged 13 commits into from
Mar 27, 2025

Conversation

eneufeld
Copy link
Contributor

@eneufeld eneufeld commented Mar 1, 2025

What it does

  • Updated the Anthropic SDK from v0.32.1 to v0.39.0
  • Added support for thinking messages in the language model interface
  • Added a ThinkingChatResponseContent implementation
  • Added proper handling for Claude's thinking feature in the Anthropic language model
  • Added a TextPartRenderer to display thinking content
  • Various interface updates to support thinking messages throughout the code

How to test

Add this or similar to your settings.json:

"ai-features.modelSettings.requestSettings": [
    {
        "scope": {
            "modelId": "claude-3-7-sonnet-latest",
            "agentId": "Architect"
        },
        "requestSettings": {
            "max_tokens": 40000,
            "temperature": 1,
            "thinking": {
                "type": "enabled",
                "budget_tokens": 8192
            }
        }
    }
],

This will enable the thinking mode on the Architect.
As you can provide chat settings you can just add the requestSettings part to your chat for any agent as long as it uses sonnet-3.7

Follow-ups

Breaking changes

  • This PR introduces breaking changes and requires careful review. If yes, the breaking changes section in the changelog has been updated.

Attribution

Review checklist

Reminder for reviewers

@eneufeld eneufeld requested review from planger and JonasHelming March 1, 2025 23:38
@github-project-automation github-project-automation bot moved this to Waiting on reviewers in PR Backlog Mar 1, 2025
@eneufeld eneufeld mentioned this pull request Mar 4, 2025
66 tasks
@JonasHelming
Copy link
Contributor

@eneufeld This is currently under work, right? So no review needed right now?

@eneufeld
Copy link
Contributor Author

exactly, no review needed, a test would be nice to confirm we go into the right direction. Then we can discuss next steps what needs to be added to make this final

@eneufeld eneufeld force-pushed the feat/claude-thinking branch 2 times, most recently from 333d23b to 3d50d23 Compare March 15, 2025 01:08
planger and others added 9 commits March 25, 2025 00:22
Currently, our application has fragmented tracking of the LLM
communications:

- Chat model doesn't track all LLM messages (e.g. system message) or
multiple LLM requests per user response
- Chat agents must manually record LLM communications via
`CommunicationRecordingService`
- Tool calls are tracked in the chat model in content parts, which are
rather UI focused, but tool calls missing in the
`CommunicationRecordingService`

This fragmentation means we lack a single source of truth for chat
session information.

This PR centralizes all LLM communication tracking in the chat model by:

1. Introducing a new `ChatLanguageModelService` that encapsulates LLM
request tracking
2. Moving related code from the abstract chat agent to this new service
3. Feeding the `CommunicationRecordingService` via a simple listener on
the chat model

- Complete tracking of all LLM requests, responses, and tool calls in
one place
- Simplified interface for chat agents to interact with LLMs
- Improved data structure to capture tool calls and LLM messages in the
History View (with minor UI enhancements)

Contributed on behalf of STMicroelectronics
* Move default request settings from individual models to frontend LanguageModelService
* Enhance RequestSettingsSchema with model/provider/agent scoping
* Add client-side settings for tool calls and thinking messages
- Updated the Anthropic SDK from v0.32.1 to v0.39.0
- Added support for thinking messages in the language model interface
- Added a ThinkingChatResponseContent implementation
- Added proper handling for Claude's thinking feature in the Anthropic language model
- Added a TextPartRenderer to display thinking content
- Various interface updates to support thinking messages throughout the code
@eneufeld eneufeld force-pushed the feat/claude-thinking branch from 1e2270a to f33edbb Compare March 24, 2025 23:41
Copy link
Member

@sdirix sdirix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a first look at the PR. To enable work on the PR I leave this intermediate review and will come with a full review later.

Overall it looks very good. However I did not yet

  • actually run the code
  • looked into detail on how the new request settings determination works

@github-project-automation github-project-automation bot moved this from Waiting on reviewers to Waiting on author in PR Backlog Mar 25, 2025
Copy link
Member

@sdirix sdirix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had a closer look at the PR. You can find my comments inline.

I tested the thinking support via the request settings in the preferences, as well as via the chat session requests. Both worked for me 👍

Based on my last review you adapted the handling of empty message for the HuggingFace language model, however we should handle this the same way for all language models. So we should either revert that change or apply it to all of them.

export const EDIT_SESSION_SETTINGS = Command.toLocalizedCommand({
id: 'chat:widget:session-settings',
category: CHAT_CATEGORY,
iconClass: codicon('bracket')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

Would be nice if this would not be a static icon, but update depending on whether the user did some customization. Similar to the history view sort button which changes depending on the sort state.

If this is out of scope for this PR then please create a follow up ticket to track this work.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added to the ai epic

<div className='theia-thinking'>
<details>
<summary>{nls.localize('theia/ai/chat-ui/thinking-part-renderer/thinking', 'Thinking')}</summary>
<pre>{response.content}</pre>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer this to be regular text or markdown rendering. Wrapping in <pre> does not do any wrapping, making it painful to inspect for longer lines.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added text wrapping for the pre element, maybe this is enough

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the rendering can be further improved, but this can be done in a follow up

@sdirix sdirix marked this pull request as ready for review March 26, 2025 10:24
Copy link
Member

@sdirix sdirix left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works for me! Great work ❤️

I only have minor comments left (the unresolved ones). Feel free to tackle them here or to create follow up issue(s).

@github-project-automation github-project-automation bot moved this from Waiting on author to Needs merge in PR Backlog Mar 26, 2025
@sdirix
Copy link
Member

sdirix commented Mar 26, 2025

@eneufeld actually this is a breaking change. So we should at adapt the changelog and at least indicate the changes in the request API

@sdirix sdirix merged commit 4877a0b into master Mar 27, 2025
10 of 11 checks passed
@github-project-automation github-project-automation bot moved this from Needs merge to Done in PR Backlog Mar 27, 2025
@sdirix sdirix deleted the feat/claude-thinking branch March 27, 2025 16:08
@github-actions github-actions bot added this to the 1.60.0 milestone Mar 27, 2025
@JonasHelming JonasHelming mentioned this pull request Apr 5, 2025
37 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants