Skip to content

Add extended thinking examples (multi-turn + tool use)#166

Open
ElliotJLT wants to merge 1 commit intoanthropics:mainfrom
ElliotJLT:add-thinking-examples
Open

Add extended thinking examples (multi-turn + tool use)#166
ElliotJLT wants to merge 1 commit intoanthropics:mainfrom
ElliotJLT:add-thinking-examples

Conversation

@ElliotJLT
Copy link
Copy Markdown

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 strip thinking or redacted_thinking blocks from prior assistant messages. The example shows how to pass response.content directly 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 the examples/ directory which is hand-maintained.

Test plan

  • Run ruby examples/thinking_multi_turn.rb with ANTHROPIC_API_KEY set
  • Run ruby examples/thinking_with_tools.rb with ANTHROPIC_API_KEY set
  • Verify both complete without errors and produce expected output

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.
@ElliotJLT ElliotJLT requested a review from a team as a code owner March 26, 2026 16:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant