From d9e391da9c65e1c5284d4f012035a3e30203119b Mon Sep 17 00:00:00 2001 From: DavdGao Date: Tue, 20 Jan 2026 20:26:53 +0800 Subject: [PATCH 1/2] feat: add metadata to the usage --- src/agentscope/model/_dashscope_model.py | 2 ++ src/agentscope/model/_model_usage.py | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/agentscope/model/_dashscope_model.py b/src/agentscope/model/_dashscope_model.py index c17a08e703..9b3dc22a37 100644 --- a/src/agentscope/model/_dashscope_model.py +++ b/src/agentscope/model/_dashscope_model.py @@ -368,6 +368,7 @@ async def _parse_dashscope_stream_response( input_tokens=chunk.usage.input_tokens, output_tokens=chunk.usage.output_tokens, time=(datetime.now() - start_datetime).total_seconds(), + metadata=chunk.usage, ) parsed_chunk = ChatResponse( @@ -469,6 +470,7 @@ async def _parse_dashscope_generation_response( input_tokens=response.usage.input_tokens, output_tokens=response.usage.output_tokens, time=(datetime.now() - start_datetime).total_seconds(), + metadata=response.usage, ) parsed_response = ChatResponse( diff --git a/src/agentscope/model/_model_usage.py b/src/agentscope/model/_model_usage.py index fcc76120ff..d8345e4b84 100644 --- a/src/agentscope/model/_model_usage.py +++ b/src/agentscope/model/_model_usage.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- """The model usage class in agentscope.""" from dataclasses import dataclass, field -from typing import Literal +from typing import Literal, Any from .._utils._mixin import DictMixin @@ -21,3 +21,6 @@ class ChatUsage(DictMixin): type: Literal["chat"] = field(default_factory=lambda: "chat") """The type of the usage, must be `chat`.""" + + metadata: dict[str, Any] | None = field(default=None) + """The metadata of the usage.""" From 70b9ce9c20cc4eebfae7b3f42bf5e87dc5103523 Mon Sep 17 00:00:00 2001 From: DavdGao Date: Wed, 21 Jan 2026 09:52:42 +0800 Subject: [PATCH 2/2] fix(memory): fix the bug in redis memory that use bytes data as the message key --- src/agentscope/model/_openai_model.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/agentscope/model/_openai_model.py b/src/agentscope/model/_openai_model.py index 3655a80808..222761829d 100644 --- a/src/agentscope/model/_openai_model.py +++ b/src/agentscope/model/_openai_model.py @@ -331,6 +331,7 @@ async def _parse_openai_stream_response( input_tokens=chunk.usage.prompt_tokens, output_tokens=chunk.usage.completion_tokens, time=(datetime.now() - start_datetime).total_seconds(), + metadata=chunk.usage, ) if not chunk.choices: @@ -531,6 +532,7 @@ def _parse_openai_completion_response( input_tokens=response.usage.prompt_tokens, output_tokens=response.usage.completion_tokens, time=(datetime.now() - start_datetime).total_seconds(), + metadata=response.usage, ) parsed_response = ChatResponse(