feat(claude-agent-sdk): add Claude Agent SDK as a provider#1947
feat(claude-agent-sdk): add Claude Agent SDK as a provider#1947KennyVaneetvelde wants to merge 10 commits into567-labs:mainfrom
Conversation
Add support for the Claude Agent SDK as a new provider in instructor, enabling structured outputs with the SDK's native JSON schema validation. Key features: - New `from_claude_agent_sdk()` factory function - `CLAUDE_AGENT_SDK` mode for structured outputs - Automatic Pydantic model to JSON schema conversion - Async-only API leveraging the SDK's async generator pattern - Built-in retry support with error context - Message format conversion (instructor -> prompt) This allows users to leverage Claude Agent SDK's agentic capabilities while using instructor's familiar interface for structured outputs. Fixes 567-labs#1640
There was a problem hiding this comment.
Important
Looks good to me! 👍
Reviewed everything up to 49d9d6f in 1 minute and 7 seconds. Click for details.
- Reviewed
905lines of code in9files - Skipped
0files when reviewing. - Skipped posting
3draft comments. View those below. - Modify your settings and rules to customize what types of comments Ellipsis leaves. And don't forget to react with 👍 or 👎 to teach Ellipsis.
1. instructor/providers/claude_agent_sdk/client.py:147
- Draft comment:
When appending error context to the prompt for retries (lines 147-152), consider the potential for the prompt to grow significantly in length if many retries occur. It may be useful to implement a limit or log a warning if the prompt becomes too long. - Reason this comment was not posted:
Confidence changes required:80%<= threshold85%None
2. instructor/providers/claude_agent_sdk/client.py:140
- Draft comment:
The validated model has a dynamic attribute _raw_response attached. Make sure that the response model permits such attribute assignment (e.g. if using frozen models) or document this behavior for clarity. - Reason this comment was not posted:
Confidence changes required:70%<= threshold85%None
3. instructor/providers/claude_agent_sdk/client.py:110
- Draft comment:
The code uses actual_model.model_json_schema() for schema conversion. Ensure that the Pydantic model implements this method (pydantic v2) and document version requirements if supporting older versions. - Reason this comment was not posted:
Comment did not seem useful. Confidence is useful =30%<= threshold85%The comment is asking the author to ensure that a method is implemented and to document version requirements. This violates the rule against asking the author to ensure behavior or document version requirements. However, it does point out a potential issue with version compatibility, which could be useful if rephrased to suggest checking compatibility or updating documentation if necessary.
Workflow ID: wflow_eT8xfOXEW4LxgsHl
You can customize by changing your verbosity settings, reacting with 👍 or 👎, replying to comments, or adding code review rules.
Add synchronous interface alongside the async one. - New `use_async` parameter in `from_claude_agent_sdk()` (default: True) - `claude_agent_sdk_create_sync()` function using anyio.run() internally - Updated documentation with sync/async examples - Refactored code to share logic between sync and async implementations
Don't break early from the async generator - let it complete naturally to ensure proper cleanup of the subprocess transport.
|
Seems like the @ellipsis has not (yet) updated the description but it is no longer async-only now EDIT: now it has |
|
@jxnl Any chance to get a review on this? I'd love to integrate Claude Code SDK with Atomic Agents, which requires it to be integrated in Instructor. Perhaps a good future concept would be to make these clients more pluggable? |
|
@jxnl What is stopping us from integrating this PR, currently? Would really love to start using this client in Instructor! |
- Add proper detection for Partial/Iterable models using PartialBase and get_origin - Add CLAUDE_AGENT_SDK mode to Iterable exclusion list in core client - Add stream parameter validation in create functions - Add default options merging without client mutation - Require response_model to be non-None - Fix type annotations (Type -> type) - Add type safety assertions and annotations - Fix linting issues with noqa comments 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Clarify async and sync support - Document no streaming/Partial/Iterable limitations - Simplify limitations section 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
- Remove unverified Claude Code CLI/Max requirements - Keep only verified ANTHROPIC_API_KEY requirement - Simplify limitations section 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
|
sorry, job interviews.... back on this, shuold be in the jan 7th release |
- Remove unverified Claude Code CLI/Max requirements - Keep only verified ANTHROPIC_API_KEY requirement - Simplify limitations section 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
|
Wonderful! Happy holidays! |
Summary
Add support for the Claude Agent SDK as a new provider in instructor, enabling structured outputs with the SDK's native JSON schema validation capabilities.
Key Features
from_claude_agent_sdk()factory function - Creates an Instructor configured for Claude Agent SDKCLAUDE_AGENT_SDKmode - New mode for structured outputs via the SDKoutput_formatUsage Example
Files Added/Modified
New files:
instructor/providers/claude_agent_sdk/__init__.pyinstructor/providers/claude_agent_sdk/client.pyinstructor/providers/claude_agent_sdk/utils.pyexamples/claude_agent_sdk/run.pydocs/integrations/claude_agent_sdk.mdModified files:
instructor/__init__.py- Conditional import whenclaude_agent_sdkis availableinstructor/mode.py- AddedCLAUDE_AGENT_SDKmodeinstructor/utils/providers.py- AddedCLAUDE_AGENT_SDKproviderinstructor/processing/response.py- Added handler mappingsBenefits
Fixes #1640
Adds Claude Agent SDK as a new provider to the instructor framework, enabling structured outputs with JSON schema validation.
from_claude_agent_sdk()factory function inclient.pyto create anInstructorfor Claude Agent SDK.CLAUDE_AGENT_SDKmode inmode.pyfor structured outputs.instructor/providers/claude_agent_sdk/__init__.py,client.py, andutils.pyfor Claude Agent SDK integration.instructor/__init__.pyfor conditional import offrom_claude_agent_sdk.instructor/processing/response.pyto include handler mappings for Claude Agent SDK.docs/integrations/claude_agent_sdk.mdfor integration guide.examples/claude_agent_sdk/run.pyfor usage examples.CLAUDE_AGENT_SDKtoProviderenum inproviders.py.This description was created by
for 49d9d6f. You can customize this summary. It will automatically update as commits are pushed.