feat(sdk): add Anthropic SDK integration#61
Open
Uchebuzz wants to merge 3 commits into
Open
Conversation
Contributor
|
Thanks for the PR Uche! I'll leave to the engineers to work with you but huge thanks for taking on Anthropic integration and i'd like to invite you to the private contributors discord community channel. https://discord.gg/zcwYwfdAFz I am 'maxicorbs' DM on there and i'll add you |
Patches anthropic.Anthropic and anthropic.AsyncAnthropic so every
messages.create call is captured as an Adrian PairedEvent and emitted
through the hook registry, with the same lifecycle guarantees as the
existing LangChain/LangGraph integration.
- sdk/python/adrian/anthropic_handler.py: core patch module
- _flatten_content / _flatten_anthropic_messages: normalise Anthropic
message params (strings, TypedDict blocks, SDK objects) to ChatMessage
- _extract_anthropic_tool_calls: pull ToolUseBlock records from response
- _extract_anthropic_usage: map input/output tokens to TokenUsage
- build_anthropic_llm_pair: assemble PairedEvent from request + response
- _emit_pair / _schedule_emit: async and sync emission paths
- patch_anthropic: idempotent monkey-patch; reads hooks/config at call
time so shutdown + re-init cycles are handled correctly
- anthropic_invocation / anthropic_invocation_sync: context managers
to group multi-turn calls under a single invocation_id
- sdk/python/adrian/__init__.py: wire auto-instrumentation
- patch_anthropic() public function (manual opt-in path)
- _auto_instrument_anthropic() called by init() when auto_instrument=True
- sdk/python/pyproject.toml: add anthropic optional-dep group and to dev
- sdk/python/tests/test_anthropic_handler.py: 61 unit tests covering all
helper functions, PairedEvent assembly, emission, patching, and context
managers; all passing locally
- examples/python/anthropic_quickstart.py: minimal two-turn async example
All new source files carry the LICENSE_HEADER.txt SPDX header per
CONTRIBUTING.md.
4417956 to
a379747
Compare
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
Adds first-class Anthropic SDK support to the Adrian Python SDK. Every
messages.createcall on bothanthropic.Anthropicandanthropic.AsyncAnthropicis now captured automatically as aPairedEventand emitted through the hook registry — no changes neededto user agent code beyond
adrian.init().Changes
sdk/adrian/anthropic_handler.py(new): message format conversion,tool call and usage extraction,
PairedEventassembly, idempotentmonkey-patch of
Messages.create/AsyncMessages.create, andanthropic_invocation()/anthropic_invocation_sync()context managersfor grouping multi-turn calls under a single invocation ID.
sdk/tests/test_anthropic_handler.py(new): 61 tests covering allhelper functions, emission, getter lifecycle, the no-package no-op path,
and both context managers. All pass.
sdk/adrian/__init__.py:patch_anthropic(),anthropic_invocation,and
anthropic_invocation_syncexported;_auto_instrument_anthropic()wired into
init()alongside LangChain auto-instrumentation.sdk/pyproject.toml:anthropicoptional dependency group added;anthropic>=0.40.0added to[dev]for the test suite.examples/anthropic_quickstart.py(new): minimal demo showing single-calland multi-turn
anthropic_invocation()usage.Test plan
uv pip install -e ./sdk[dev,anthropic]thenpytest sdk/tests/test_anthropic_handler.py -v— 61 tests passpytest sdk/tests/— no regressions in existing suiteexamples/anthropic_quickstart.pyagainst a live backend andconfirm events appear in the dashboard with correct model, messages,
and usage fields
anthropic_invocation()groups multi-turn calls under ashared
invocation_idin the dashboardChecklist