Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/google/adk/models/anthropic_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,12 +330,17 @@ def to_claude_role(role: Optional[str]) -> Literal["user", "assistant"]:


# Mapping of Anthropic stop_reason strings to FinishReason enum values
_STOP_REASON_MAPPING: dict[anthropic_types.StopReason, types.FinishReason] = {
# Keyed by str: "model_context_window_exceeded" is newer than the minimum
# supported anthropic SDK's StopReason literal.
_STOP_REASON_MAPPING: dict[str, types.FinishReason] = {
"end_turn": types.FinishReason.STOP,
"stop_sequence": types.FinishReason.STOP,
"tool_use": types.FinishReason.STOP,
"pause_turn": types.FinishReason.STOP,
"max_tokens": types.FinishReason.MAX_TOKENS,
# Generation stopped because the context window filled up, so the output
# is truncated just as with max_tokens.
"model_context_window_exceeded": types.FinishReason.MAX_TOKENS,
"refusal": types.FinishReason.SAFETY,
}

Expand Down
1 change: 1 addition & 0 deletions tests/unittests/models/test_anthropic_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -4243,6 +4243,7 @@ async def mock_coro():
("stop_sequence", types.FinishReason.STOP),
("tool_use", types.FinishReason.STOP),
("max_tokens", types.FinishReason.MAX_TOKENS),
("model_context_window_exceeded", types.FinishReason.MAX_TOKENS),
("pause_turn", types.FinishReason.STOP),
("refusal", types.FinishReason.SAFETY),
(None, None),
Expand Down
Loading