[Bug]: ToolResponse.metadata not preserved when storing tool_result in memory
Describe the bug
When a tool function returns a ToolResponse(..., metadata=some_dict), the metadata field is not preserved in the stored Msg within memory. In my use‐case I expected the Msg.metadata to equal the tool response metadata, but found it None.
To Reproduce
Steps to reproduce the behavior:
-
Define a tool function that returns e.g.
from agentscope.tool import ToolResponse from agentscope.message import TextBlock def my_tool(...): return ToolResponse( content=[TextBlock(text="Result text")], metadata={"key": "value", "other": 123} ) -
Register the tool via
Toolkit.register_tool_function(my_tool, ...) -
Use the tool in a ReActAgent call, e.g. tool call:
{"type": "tool_use", "name": "my_tool", "input": {...}} -
After execution, inspect agent memory. Find the corresponding
Msgwith"type": "tool_result"; verifymsg.metadataisNone.
Expected behavior
The msg.metadata associated with the tool result should contain the same dictionary passed as ToolResponse.metadata.
Environment
- AgentScope version: 1.0.7
- Python version: 3.12.10
- OS: Ubuntu 22.04
Additional context
This is important for scenarios where structured data from tool invocation must be stored/referenced downstream (e.g., audit logs, database persistence) without additional parsing of content. Without metadata, one must parse JSON from content.text, increasing risk of parse errors, inconsistency, and extra processing.
Possible workaround
As a temporary workaround, I serialize structured result into content.text (e.g., via json.dumps(metadata)) and then parse it downstream. But this is not ideal and violates the design intent of metadata.
Would like to propose
Either preserve ToolResponse.metadata into Msg.metadata, or explicitly document that metadata will not be stored and provide a recommended approach for structured tool outputs (e.g., specialized JSONBlock).