Skip to content

fix(anthropic): tolerate proxy responses without message ids - #1156

Closed
Alexxigang wants to merge 1 commit into
agentscope-ai:mainfrom
Alexxigang:fix/anthropic-missing-response-id
Closed

Alexxigang wants to merge 1 commit into
agentscope-ai:mainfrom
Alexxigang:fix/anthropic-missing-response-id

Conversation

@Alexxigang

Copy link
Copy Markdown
Contributor

Summary

  • tolerate Anthropic proxy responses that omit the top-level id field
  • reuse the SDK raw _id() field when available and fall back gracefully when it is missing
  • add parser- and formatter-level regression coverage for both non-streaming and message-start streaming paths

Root cause

AnthropicResponseParser called message.id() directly in both the non-streaming parse path and the streaming message-start path. Some proxy services strip the top-level id field, and the Anthropic SDK throws before AgentScope can build a ChatResponse.

Fix

  • add a safe message-id reader that prefers the SDK raw _id() field
  • fall back to a generated ChatResponse id when the payload really has no id
  • cover raw-id reuse and missing-id fallback in parser and formatter tests

Validation

  • mvn -pl :agentscope-core -am spotless:apply
  • mvn -pl :agentscope-core -am "-Dtest=AnthropicResponseParserTest,AnthropicChatFormatterTest" test

@Alexxigang
Alexxigang force-pushed the fix/anthropic-missing-response-id branch from 9342c8e to 44b0bfe Compare April 9, 2026 13:45
@Alexxigang

Copy link
Copy Markdown
Contributor Author

Rebased this PR onto the current main and reran the targeted Anthropic formatter/parser tests locally. The branch head is refreshed and ready for review again.

@LearningGp LearningGp left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please run 'mvn spotless:apply' to fix these violations.

@LearningGp LearningGp added the wait-for-response PRs that require further response label May 15, 2026
@github-actions

Copy link
Copy Markdown

Closing due to inactivity. Feel free to reopen when ready.

@github-actions github-actions Bot added the stale label May 23, 2026
@github-actions github-actions Bot closed this May 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale wait-for-response PRs that require further response

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants