Install
openclaw skills install @trend0522/agentscope-gemini-usage-fixWork around a Gemini usage normalization bug in AgentScope where cached_content_token_count=None causes Usage validation to fail. Use this whenever the user uses GeminiChatModel and sees ValidationError on cache_input_tokens.
openclaw skills install @trend0522/agentscope-gemini-usage-fixThis skill documents a known bug and a runtime workaround for GeminiChatModel usage extraction.
GeminiChatModel._extract_usage uses getattr(..., "cached_content_token_count", 0), which returns None when the attribute exists but is None. ChatUsage validates cache_input_tokens as int, so None raises a pydantic ValidationError.
Apply this patch before using Gemini models:
from agentscope.model._gemini._model import GeminiChatModel
_original = GeminiChatModel._extract_usage
def _patched_extract_usage(self, usage_metadata, start_datetime):
if not usage_metadata:
return None
usage = _original(self, usage_metadata, start_datetime)
if usage and getattr(usage, "cache_input_tokens", None) is None:
usage.cache_input_tokens = 0
return usage
GeminiChatModel._extract_usage = _patched_extract_usage
The upstream fix is a one-line change:
cache_input_tokens=getattr(
usage_metadata,
"cached_content_token_count",
0,
) or 0,
Reference: https://github.com/agentscope-ai/agentscope/issues/3077