Add extended thinking examples (multi-turn + tool use)#166
Open
ElliotJLT wants to merge 1 commit intoanthropics:mainfrom
Open
Add extended thinking examples (multi-turn + tool use)#166ElliotJLT wants to merge 1 commit intoanthropics:mainfrom
ElliotJLT wants to merge 1 commit intoanthropics:mainfrom
Conversation
Adds two new examples demonstrating common thinking patterns that are currently missing from the examples directory (requested in anthropics#85): - thinking_multi_turn.rb: Shows how to carry thinking blocks forward across conversation turns, a common gotcha where the API rejects requests that strip thinking blocks from prior assistant messages. - thinking_with_tools.rb: Shows extended thinking combined with tool use, including the three-step flow of request → tool execution → tool result with all content blocks preserved.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds two new example files for extended thinking, as requested in #85:
thinking_multi_turn.rb— Demonstrates carrying thinking blocks forward across conversation turns. This is a common gotcha: the API rejects requests that stripthinkingorredacted_thinkingblocks from prior assistant messages. The example shows how to passresponse.contentdirectly as the assistant message content.thinking_with_tools.rb— Demonstrates extended thinking combined with tool use. Shows the three-step flow: initial request with thinking + tools → handle tool call and compute result → send tool result back with all content blocks (thinking + tool_use) preserved.Both files follow existing conventions (
# typed:,require_relative, compact hash braces,Anthropic::Client.new) and live in theexamples/directory which is hand-maintained.Test plan
ruby examples/thinking_multi_turn.rbwithANTHROPIC_API_KEYsetruby examples/thinking_with_tools.rbwithANTHROPIC_API_KEYset