Skip to content

feat: add Message Threads examples across SDK languages - #77

Open
Arun Sekhar (achandmsft) wants to merge 2 commits into
feat/portable-anthropic-sdk-clients-20261029from
feat/message-threads-20261110-public
Open

Arun Sekhar (achandmsft) wants to merge 2 commits into
feat/portable-anthropic-sdk-clients-20261029from
feat/message-threads-20261110-public

Conversation

@achandmsft

@achandmsft Arun Sekhar (achandmsft) commented Nov 10, 2026 •

Copy link
Copy Markdown
Collaborator

What

Add separate Message Threads examples for Python, TypeScript, C#, Go, Java, PHP and Ruby.

Why

Fixes #76. Stacked on #71 so this PR contains only the Threads work.

How

  • Use native SDK thread helpers and existing authentication. The beta header stays opt-in; no custom replay code.
  • Raise Python's SDK floor to 2.4 and TypeScript's tested pin to 1.4. Other SDK versions stay unchanged.
  • Review each language with Sonnet 5.5. Add wire tests, run instructions and compatibility findings.

Foundry accepted adding/removing top-level cache_control despite the documented fixed-field rule; a recheck reproduced it on both models (4/4 returned 200). TTL/effort changes were rejected correctly. This is a documentation-contract comparison, not a confirmed Foundry-only bug: no native Anthropic account key was available.

Verification

  • azd up succeeded end-to-end on a fresh env (Bicep)
  • azd up succeeded end-to-end on a fresh env (Terraform)
  • python src/hello_claude.py returned a live model response
  • N/A — docs-only / CI-only change

No IaC changes or fresh provisioning. Live checks reused the gitignored exported Foundry profile; subscription identifiers are intentionally omitted.

GitHub validation on the latest commit: all 10 jobs passed, including all seven SDK paths.

Used local runtimes (Python from .venv) and a cached Maven repository ($repo).

Scope Command and result
Python python -m unittest discover -s tests -v: 68 passed; python -m compileall -q src tests: passed; python -m pip check: passed
TypeScript npm ci --ignore-scripts: passed, with the pre-existing advisory below; npm run build: passed; npm test: 65 passed, including type-check
C# dotnet test samples\dotnet\AnthropicStandardSdk.sln --configuration Release --no-restore --nologo: 133 passed
Go gofmt -l .: clean; go vet ./...: passed; go test -count=1 ./...: 60 top-level tests passed; go mod verify: passed
Java mvn -o -B "-Dmaven.repo.local=$repo" test: 139 passed
PHP composer test --no-ansi: 56 passed
Ruby bundle exec ruby test\run.rb: 43 passed, 527 assertions

Live entrypoints all returned ORCHID-47:

  • python src\message_threads.py: passed.
  • node src\message_threads.ts: passed.
  • dotnet run --project samples\dotnet\src\AnthropicStandardSdk --configuration Release --no-build -- --threads: passed.
  • go run . -threads: passed.
  • mvn -o -q "-Dmaven.repo.local=$repo" compile exec:java "-Dexec.mainClass=sample.anthropic.MessageThreads": passed.
  • php -d "curl.cainfo=$env:TRUSTED_CA_BUNDLE" -d "openssl.cafile=$env:TRUSTED_CA_BUNDLE" message_threads.php: passed, TLS verification enabled.
  • ruby message_threads.rb: passed.

Protocol checks passed on Opus 5.5 and Sonnet 5.5 in eastus2: streaming continuation, tool results, replay, missing/reused IDs, fixed-field rejection and idle expiry. Python's native helper also recovered after 310 seconds idle. The basic flow passed with API versions 2026-10-21 and 2023-06-01. The existing TypeScript Messages and --stream paths also passed live on SDK 1.4.0.

Environment caveats: PHP on Windows needed a trusted CA bundle; Java emitted its existing SLF4J warning.

npm ci audit: one pre-existing high advisory, GHSA-xcx6-jx8p-x3h5, in @azure/msal-node 6.0.1 via @azure/identity 4.14.0. The advisory affects MSAL's authorization-code flow, which these samples do not use. This PR changes only @anthropic-ai/sdk in the lockfile. @azure/identity 4.14.1 depends on @azure/msal-node ^7.1.0; that bump belongs in #71.

Review follow-up: aligned the TypeScript example with main.ts constants and error output, removed a redundant PHP default and a long Go comment, and tightened the docs. Final Sonnet 5.5 review: no actionable issues.

Checklist

  • Mirrored the change across both infra-bicep/ and infra-terraform/ (if applicable)
  • No secrets / subscription IDs / tenant IDs / object IDs in commits, comments, or PR body
  • README updated if user-facing behavior changed
  • Conventional one logical change per PR

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Approval recommended

The review reports no active issues blocking approval of the opt-in Message Threads examples.

No open issues 🎉

1 file not reviewed
  • samples/typescript/package-lock.json: Generated file
What changed in this PR

Adds opt-in Message Threads examples across all seven SDK languages, building on the standard clients and authentication helpers from #71 to address #76. Existing Messages and streaming examples remain separate.

Changes:

  • Add two-turn examples using native SDK thread helpers and existing authentication.
  • Add offline tests for create/continue requests, replay, error handling and text output.
  • Document usage and Foundry compatibility observations; raise Python’s SDK minimum to 2.4 and TypeScript’s pin to 1.4.0.
File Description
tests/​test_message_threads.py Tests Python thread requests, replay and errors.
src/​message_threads.py Adds the Python two-turn example.
samples/​typescript/​test/​message_threads.test.ts Tests thread requests, replay, errors and deadlines.
samples/​typescript/​src/​message_threads.ts Adds the TypeScript thread entrypoint.
samples/​typescript/​src/​main.ts Exports shared error formatting.
samples/​typescript/​README.md Documents thread usage and tested SDK version.
samples/​typescript/​package.json Adds the threads command and updates the SDK pin.
samples/​typescript/​package-lock.json Locks SDK version 1.4.0.
samples/​ruby/​test/​message_threads_test.rb Tests Ruby thread behavior and failures.
samples/​ruby/​README.md Documents thread usage and client reuse.
samples/​ruby/​message_threads.rb Adds the Ruby executable entrypoint.
samples/​ruby/​lib/​claude_sample/​sample.rb Exposes shared diagnostic helpers.
samples/​ruby/​lib/​claude_sample/​message_threads.rb Implements the Ruby thread example.
samples/​README.md Links thread examples and compatibility guidance.
samples/​php/​tests/​run.php Registers the thread tests.
samples/​php/​tests/​MessageThreadsTest.php Tests requests, replay, authentication and diagnostics.
samples/​php/​src/​Sample.php Exposes shared credential and diagnostic helpers.
samples/​php/​src/​MessageThreads.php Implements the PHP thread example.
samples/​php/​README.md Documents thread usage and test coverage.
samples/​php/​message_threads.php Adds the PHP executable entrypoint.
samples/​message-threads.md Documents the contract, SDK versions and Foundry observations.
samples/​java/​src/​test/​java/​sample/​anthropic/​MessageThreadsTest.java Tests Java thread requests, recovery and failures.
samples/​java/​src/​main/​java/​sample/​anthropic/​SampleRunner.java Shares client lifecycle and error handling between examples.
samples/​java/​src/​main/​java/​sample/​anthropic/​MessageThreads.java Adds the Java thread entrypoint.
samples/​java/​README.md Documents the Java thread command.
samples/​go/​README.md Documents thread mode and its tests.
samples/​go/​message_threads.go Implements the Go thread example.
samples/​go/​message_threads_test.go Tests thread behavior and beta isolation.
samples/​go/​main.go Adds and validates the -threads option.
samples/​dotnet/​tests/​AnthropicStandardSdk.Tests/​TestSupport.cs Adds configurable response IDs and thread error codes.
samples/​dotnet/​tests/​AnthropicStandardSdk.Tests/​SampleRunnerTests.Threads.cs Tests thread behavior, diagnostics and beta isolation.
samples/​dotnet/​tests/​AnthropicStandardSdk.Tests/​SampleRunnerTests.cs Makes the test class partial for thread tests.
samples/​dotnet/​src/​AnthropicStandardSdk/​ThreadsExample.cs Implements the C# thread example.
samples/​dotnet/​src/​AnthropicStandardSdk/​SampleRunner.cs Adds and validates the --threads option.
samples/​dotnet/​README.md Documents C# thread usage.
requirements.txt Raises the Python Anthropic SDK minimum to 2.4.0.
README.md Adds thread links, usage and the updated Python requirement.

Review effort: Balanced

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
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.

2 participants