Package com.tnsai.reasoning
Class ExtendedThinkingClient
java.lang.Object
com.tnsai.reasoning.ExtendedThinkingClient
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
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classBuilder for ExtendedThinkingClient. -
Method Summary
Modifier and TypeMethodDescriptionbuilder()Creates a new builder for ExtendedThinkingClient.com.tnsai.llm.LLMClientGets the underlying Anthropic client.intGets the thinking budget.Performs extended thinking on the given problem.Performs extended thinking with an optional system prompt.Performs extended thinking with conversation history.
-
Method Details
-
builder
Creates a new builder for ExtendedThinkingClient. -
think
Performs extended thinking on the given problem.- Parameters:
problem- The problem to think through- Returns:
- The thinking result with process and answer
-
think
Performs extended thinking with an optional system prompt.- Parameters:
problem- The problem to think throughsystemPrompt- Optional additional system instructions- Returns:
- The thinking result
-
thinkWithHistory
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.
-