Skip to content

Conversation

@jxnl
Copy link
Collaborator

@jxnl jxnl commented Nov 12, 2025

No description provided.

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Nov 12, 2025

Deploying with  Cloudflare Workers  Cloudflare Workers

The latest updates on your project. Learn more about integrating Git with Workers.

Status Name Latest Commit Updated (UTC)
❌ Deployment failed
View logs
instructor faaddb0 Nov 20 2025, 01:01 AM

Copy link
Collaborator Author

jxnl commented Nov 12, 2025

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.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@github-actions github-actions bot added enhancement New feature or request python Pull requests that update python code size:L This PR changes 100-499 lines, ignoring generated files. labels Nov 12, 2025
@jxnl jxnl force-pushed the feat/v2-core-infrastructure branch from 01dd834 to 702eb7c Compare November 12, 2025 05:21
jxnl and others added 11 commits November 12, 2025 00:23
…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.
@jxnl jxnl force-pushed the feat/v2-core-infrastructure branch from 702eb7c to fce90d2 Compare November 12, 2025 05:25
@jxnl jxnl force-pushed the feat/v2-anthropic-provider branch from 9e3f360 to 267282f Compare November 12, 2025 05:25
jxnl and others added 10 commits November 12, 2025 00:29
…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.
- Change handlers to register with generic modes (TOOLS, PARALLEL_TOOLS, JSON)
- Add normalize_mode function to convert provider-specific modes to generic
- Update registry to normalize modes on lookup for backward compatibility
- Update from_anthropic client to use normalize_mode
Add JSON_SCHEMA fallback handling, comprehensive mode tests, and reask coverage for Anthropic handlers.

Tests: uv run pytest tests/v2/test_anthropic_modes_comprehensive.py tests/v2/test_anthropic_integration.py tests/v2/test_anthropic_llm.py tests/v2/providers/anthropic/test_handlers.py -v --cov=instructor.v2.providers.anthropic --cov=instructor.processing.function_calls --cov-report=term-missing --cov-report=html
- Restore AnthropicParallelBase class and AnthropicParallelModel function
  in instructor/dsl/parallel.py to maintain backward compatibility with
  legacy v1 code paths that use Mode.ANTHROPIC_PARALLEL_TOOLS

- Fix tests/v2/conftest.py to remove module-level skip that prevented
  unit tests from running in CI. Added pytest marker 'requires_api_key'
  and autouse fixture to skip only API-requiring tests when key is missing

- Mark integration/LLM tests with requires_api_key marker so unit tests
  (test_registry, test_routing, test_handlers) run without API keys
- Fix GenAI handler signatures to match protocol (kwargs: dict instead of **kwargs)
- Add model parameter injection for GenAI API calls
- Fix parse_response signatures to include stream and is_async parameters
- Add mode attribute to GenAI handlers via decorator
- Update Anthropic handlers to match parse_response signature
- Fix retry functions to pass stream and is_async to parse_response
- Remove redundant provider-specific test files:
  - test_anthropic_modes_comprehensive.py (covered by test_provider_modes.py)
  - test_anthropic_integration.py (covered by integration tests)
  - test_anthropic_llm.py (covered by test_provider_modes.py)
  - test_genai_modes_comprehensive.py (covered by test_provider_modes.py)
  - providers/*/test_handlers.py (unit tests redundant with integration tests)
- Fix linting errors for unused arguments
- All tests now pass for both Anthropic and GenAI providers
…migration guide

- Add detailed 'How the System Works' section explaining request flow, mode normalization, handler lifecycle, and registry internals
- Add comprehensive testing guide with examples for writing v2 provider tests
- Add migration checklist tracking completed and pending provider migrations
- Add comprehensive migration guide with step-by-step instructions for migrating providers from v1 to v2
- Include common migration patterns, troubleshooting guide, and before/after examples
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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants