agentscope icon indicating copy to clipboard operation
agentscope copied to clipboard

[Bug]: ToolResponse.metadata not preserved when storing tool_result in memory

Open Adoubf opened this issue 1 month ago • 0 comments

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:

  1. 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}
        )
    
  2. Register the tool via Toolkit.register_tool_function(my_tool, ...)

  3. Use the tool in a ReActAgent call, e.g. tool call:

    {"type": "tool_use", "name": "my_tool", "input": {...}}
    
  4. After execution, inspect agent memory. Find the corresponding Msg with "type": "tool_result"; verify msg.metadata is None.

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).

Adoubf avatar Nov 24 '25 03:11 Adoubf