Skip to content

The agent that grows with you

fix(agent): fall back to messages.create on Anthropic stream usage aggregation errors

hejuntt1014d26909c99e16
diff --git a/agent/anthropic_adapter.py b/agent/anthropic_adapter.py
index 98fc1ba8183..8efe353a66f 100644
--- a/agent/anthropic_adapter.py
+++ b/agent/anthropic_adapter.py
@@ -717,6 +717,15 @@ def _is_stream_unavailable_error(exc: Exception) -> bool:
return True
if "unexpected event order" in err_lower:
return True
+ # Anthropic SDK accumulate_event() assumes message_start carried a usage
+ # object; some Anthropic-compatible providers (e.g. MiniMax api.minimaxi.com)
+ # emit usage: null on message_start and only populate it on message_delta,
+ # so get_final_message() raises AttributeError on output_tokens (#60683).
+ if isinstance(exc, AttributeError):
+ if "output_tokens" in err_lower:
+ return True
+ if "nonetype" in err_lower and "usage" in err_lower:
+ return True
if "invokemodelwithresponsestream" not in err_lower:
return False
from agent.bedrock_adapter import is_streaming_access_denied_error