feat: add native Anthropic Messages API support via adapter pattern#19
Merged
Jiaaqiliu merged 1 commit intoaiming-lab:mainfrom Mar 17, 2026
Merged
Conversation
- Add AnthropicAdapter that translates Anthropic Messages API responses to OpenAI-compatible format, enabling seamless provider switching - Restore PROVIDER_PRESETS base_url fallback logic with new anthropic preset - Convert httpx exceptions to urllib errors for unified retry mechanism - Support json_mode via system prompt injection for Anthropic provider - Add httpx as optional dependency (pip install researchclaw[anthropic]) - Add connectivity test and detailed changelog with architecture diagrams
Jiaaqiliu
added a commit
that referenced
this pull request
Mar 17, 2026
Merged community PRs: - PR #12: researchclaw init command and config auto-detection - PR #14: CONTRIBUTING.md - PR #17: ssh_remote and colab_drive experiment sandbox backends - PR #19: native Anthropic Messages API support via adapter pattern Additional fixes: - Deduplicate pyproject.toml optional-dependencies section - Handle OSError in colab drive availability check - Add test_outputs and local docs to .gitignore
Collaborator
|
Hi @Program120, thanks for this well-structured contribution! We've reviewed and merged this PR. The Anthropic Messages API adapter is now part of What we did during integration:
During our post-merge code audit, we identified a few areas for future improvement:
None of these are blockers — the adapter works correctly for the standard use case (direct Anthropic API). Would love to see follow-up PRs addressing any of these! Excellent adapter pattern and great documentation in the changelog. Thanks for contributing! |
Jiaaqiliu
added a commit
that referenced
this pull request
Mar 17, 2026
PR #12 (cli init): - Fix provider replacement: match "openai-compatible" instead of "openai" - Fix example config path: search repo root + package dir, not just CWD - Handle EOFError on stdin close during interactive prompt - Return exit code 1 when refusing to overwrite existing config PR #17 (SSH/Colab sandbox): - Fix shell injection: shlex.quote() all user-supplied values in commands - Fix SSH option ordering: ConnectTimeout placed before hostname - Fix subdirectory support: run_project() and scp_upload() now copy dirs - Fix Docker cmd: add explicit python3 invocation, fix GPU flag quoting - Add cleanup of remote dir on upload failure PR #19 (Anthropic adapter): - Fix stop_reason mapping: end_turn→stop, max_tokens→length (truncation) - Fix MetaClaw conflict: adapter uses original URL, not proxy URL - Extract all text content blocks, not just the first - Concatenate multiple system messages instead of dropping earlier ones - Catch all httpx transport errors (ReadError, RemoteProtocolError, etc.) - Detect Anthropic error responses before conversion config.py: - Remove 84 lines of duplicate function definitions (dead code)
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
AnthropicAdapter— translates Anthropic Messages API to OpenAI-compatible formatPROVIDER_PRESETSbase_url fallback with new anthropic presetjson_modevia system prompt injection for Anthropic providerhttpxas optional dependency (pip install researchclaw[anthropic])docs/CHANGELOG_ANTHROPIC_ADAPTER.mdZero Impact on Existing Providers
AnthropicAdapteris only instantiated whenprovider == "anthropic".For all other providers,
self._anthropicremainsNone— code path is identical to before.Test Plan
ANTHROPIC_API_KEYand runpython tests/test_anthropic.py