-
-
Notifications
You must be signed in to change notification settings - Fork 888
feat(v2/anthropic): implement provider with mode registry integration #1919
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Draft
jxnl
wants to merge
12
commits into
feat/v2-core-infrastructure
Choose a base branch
from
feat/v2-anthropic-provider
base: feat/v2-core-infrastructure
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,987
−82
Conversation
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
Deploying with
|
| Status | Name | Latest Commit | Updated (UTC) |
|---|---|---|---|
| ❌ Deployment failed View logs |
instructor | 609f3a9 | Nov 12 2025, 05:35 AM |
Collaborator
Author
|
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
01dd834 to
702eb7c
Compare
…ng parameter support - Update v2 core registry & patch to use instructor.core.exceptions (fix import paths) - Enhance AnthropicToolsHandler to auto-detect thinking parameter - Add AnthropicReasoningToolsHandler as deprecated wrapper that delegates to TOOLS - Automatically use auto tool_choice when thinking is enabled (API requirement) - Handle ThinkingBlock content in parse_response - Respect user-provided tool_choice parameter (pass through kwargs) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
…h thinking parameter
- Add warn_anthropic_reasoning_tools_deprecation() method
- Shows deprecation warning once per session
- Directs users to use Mode.TOOLS with thinking={'type': 'enabled'} instead
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
- Use instructor.v2.from_anthropic instead of v1 implementation - Use Mode.TOOLS instead of deprecated Mode.ANTHROPIC_TOOLS - Remove max_tokens parameter (passes through kwargs if needed) - Add comprehensive tests for thinking parameter detection - Test deprecation warning, tool_choice respecting, and reasoning mode Tests verify: - ANTHROPIC_REASONING_TOOLS mode registration - Deprecation warning on mode usage - TOOLS mode auto-detects thinking parameter - TOOLS mode uses auto tool_choice when thinking enabled - TOOLS mode respects user-provided tool_choice - Mode count updated to 3 (TOOLS, JSON, REASONING_TOOLS) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
- Replace all Mode.ANTHROPIC_TOOLS with Mode.TOOLS throughout - Replace Mode.ANTHROPIC_JSON with Mode.JSON - Replace Mode.ANTHROPIC_PARALLEL_TOOLS with Mode.PARALLEL_TOOLS - Update all claude-3-5-haiku-latest to claude-4-5-haiku-latest - Rewrite thinking/extended thinking section with new approach - Explain automatic mode detection when thinking parameter is used - Add deprecation notice for Mode.ANTHROPIC_REASONING_TOOLS - Fix syntax errors in caching examples (missing parenthesis) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
…on[...]] response models
- Detect parallel mode automatically when response_model is Iterable[Union[...]]
- Use auto tool_choice for parallel mode (required by API)
- Generate multiple tool schemas from union members
- Update parse_response to handle both single and parallel responses
- Returns single model for regular tools, generator for parallel tools
- No need to explicitly specify Mode.ANTHROPIC_PARALLEL_TOOLS or Mode.PARALLEL_TOOLS
Example:
response = client.chat.completions.create(
response_model=Iterable[Weather | GoogleSearch],
messages=[...]
)
for result in response:
print(result)
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <[email protected]>
- Add tests/v2/conftest.py to auto-skip if ANTHROPIC_API_KEY not set - Create test_anthropic_llm.py with 4 passing LLM tests: * Basic TOOLS mode with model injection * Async TOOLS mode * Parallel tools with auto-detection from Iterable[Union[...]] * JSON mode - Fix auto_client to pass model_name to from_anthropic - Add default max_tokens=4096 to auto_client (like v1) - Fix parallel mode handling in v2 handlers: * Return proper generator (not relying on v1 parallel wrapper) * Extract tool names from union members * Validate against correct model class per tool call Tests now hit real Anthropic API and verify: - Single tool extraction works - Parallel tools auto-detected from response model shape - Mode auto-detects when response is Iterable[Union[...]] Skipped tests: - Thinking mode (requires Claude 3.7 Sonnet paid API) - Async parallel (needs async generator wrapper implementation) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
- Update parallel tools section to explain auto-detection from Iterable[Union[...]] - No longer need Mode.PARALLEL_TOOLS - just use Iterable response model - Add mode auto-detection table showing all combinations: * Single tool (forced choice) * Thinking mode (auto choice) * Parallel tools (auto choice) * Parallel + thinking - Mark Mode.PARALLEL_TOOLS as deprecated - Clarify Mode.TOOLS is all-in-one solution 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
…dling - Add comprehensive README.md for v2 core architecture detailing registry-based design, exception handling, and component interactions. - Implement centralized exception handling with new exception classes: RegistryError and ValidationContextError. - Introduce RegistryValidationMixin for validating mode registration and context parameters. - Update patch and retry logic to utilize new exception handling mechanisms. This commit lays the groundwork for the v2 architecture, enhancing modularity and error management.
702eb7c to
fce90d2
Compare
9e3f360 to
267282f
Compare
…pdate tests - Remove deprecated usage of from_anthropic() in favor of instructor.v2.from_anthropic() with Mode.TOOLS. - Update AnthropicToolsHandler to streamline request preparation and response parsing. - Adjust tests to reflect the removal of ANTHROPIC_REASONING_TOOLS and ensure correct mode registration. - Ensure deprecation warnings are correctly emitted for old usage patterns. This commit enhances clarity and maintains alignment with the v2 architecture.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
enhancement
New feature or request
python
Pull requests that update python code
size:L
This PR changes 100-499 lines, ignoring generated files.
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.

No description provided.