Class ExtendedThinkingClient

java.lang.Object
com.tnsai.reasoning.ExtendedThinkingClient

public class ExtendedThinkingClient extends Object
Extended thinking mode client for deep reasoning tasks.

Wraps an LLM client to enable extended thinking capabilities, particularly for Anthropic's Claude models with extended_thinking beta.

Extended thinking allows the model to allocate more tokens for internal reasoning before producing the final answer, resulting in better performance on complex problems.

Usage


 ExtendedThinkingClient client = ExtendedThinkingClient.builder()
     .anthropic(anthropicClient)
     .thinkingBudget(10000)  // Max tokens for thinking
     .build();

 ThinkingResult result = client.think("Prove that there are infinitely many primes");
 System.out.println("Thinking: " + result.getThinkingProcess());
 System.out.println("Answer: " + result.getFinalAnswer());
 System.out.println("Thinking tokens: " + result.getThinkingTokens());
 

Anthropic Extended Thinking

When using Anthropic Claude, this client adds the appropriate beta flags and parameters for extended thinking mode:

  • Sets `anthropic-beta: extended-thinking-2024-12-19`
  • Configures thinking budget tokens
  • Parses thinking blocks from response
  • Method Details

    • builder

      public static ExtendedThinkingClient.Builder builder()
      Creates a new builder for ExtendedThinkingClient.
    • think

      public ThinkingResult think(String problem)
      Performs extended thinking on the given problem.
      Parameters:
      problem - The problem to think through
      Returns:
      The thinking result with process and answer
    • think

      public ThinkingResult think(String problem, Optional<String> systemPrompt)
      Performs extended thinking with an optional system prompt.
      Parameters:
      problem - The problem to think through
      systemPrompt - Optional additional system instructions
      Returns:
      The thinking result
    • thinkWithHistory

      public ThinkingResult thinkWithHistory(String problem, List<Map<String,Object>> history)
      Performs extended thinking with conversation history.
    • getAnthropicClient

      public com.tnsai.llm.LLMClient getAnthropicClient()
      Gets the underlying Anthropic client.
    • getThinkingBudget

      public int getThinkingBudget()
      Gets the thinking budget.