Skip to content

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

Open
Alexxigang wants to merge 3 commits intoagentscope-ai:mainfrom
Alexxigang:fix/anthropic-missing-response-id
Open

fix(anthropic): tolerate proxy responses without message ids#1156
Alexxigang wants to merge 3 commits intoagentscope-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

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