Skip to content

Handle anthropic beta messages and refactor#1774

Merged
alexmojaki merged 10 commits intomainfrom
alex/anthropic-beta
Mar 11, 2026
Merged

Handle anthropic beta messages and refactor#1774
alexmojaki merged 10 commits intomainfrom
alex/anthropic-beta

Conversation

@alexmojaki
Copy link
Copy Markdown
Collaborator

@alexmojaki alexmojaki commented Mar 11, 2026

Part of #1737


Summary by cubic

Adds support for anthropic beta messages (including streaming) and refactors content/tool-call parsing for more reliable semconv output. Adds tests for beta async and streaming flows.

  • New Features

    • Handle anthropic beta Message (BetaMessage) in span updates and semconv output, including BetaTextBlock, BetaToolUseBlock, and BetaTextDelta in parsing and streaming events.
    • Treat /v1/messages?beta=true as a messages endpoint.
  • Refactors

    • Centralize content parsing with _convert_content_part_or_parts; _convert_content_part now accepts any object.
    • Add make_tool_call_part to standardize tool-call creation and parse JSON string arguments.
    • Use ChatMessage/OutputMessage constructors; access role directly; build input_messages via list comprehension.
    • Remove redundant content is not None check; falsy handling in _convert_content_part_or_parts covers it.
    • Tests: add VCR cassettes and assertions for beta sync streaming and async calls; set default ANTHROPIC_API_KEY in test env.

Written for commit 5203520. Summary will update on new commits.

…arsing

Apply equivalent changes from OpenAI refactoring PR #1769:
- Add _convert_content_part_or_parts for str/list content handling
- Add make_tool_call_part helper for standardized tool-call creation
- Update _convert_content_part to accept object, handle non-dict inputs
- Replace dict literals with ChatMessage/OutputMessage constructors
- Remove cast('Role', ...) in favor of direct attribute access
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Mar 11, 2026

Deploying logfire-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 5203520
Status: ✅  Deploy successful!
Preview URL: https://6d5a4f63.logfire-docs.pages.dev
Branch Preview URL: https://alex-anthropic-beta.logfire-docs.pages.dev

View logs

The falsy check inside _convert_content_part_or_parts already handles None.
cubic-dev-ai[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

cubic-dev-ai[bot]

This comment was marked as resolved.

BetaMessage content uses BetaTextBlock/BetaToolUseBlock which are
separate classes from TextBlock/ToolUseBlock. Add them to isinstance
tuples in convert_response_to_semconv and content_from_messages so
beta responses are handled correctly.
devin-ai-integration[bot]

This comment was marked as resolved.

devin-ai-integration[bot]

This comment was marked as resolved.

@alexmojaki alexmojaki enabled auto-merge (squash) March 11, 2026 15:52
@alexmojaki alexmojaki merged commit 6f53262 into main Mar 11, 2026
16 checks passed
@alexmojaki alexmojaki deleted the alex/anthropic-beta branch March 11, 2026 15:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant