Skip to content

ToolMessage is not msgpack serializable when tool call result contains non_text_contents (artifact) #295

@styukovs

Description

@styukovs

Hello,

When the tool response contains an artifact, it has the type

from mcp.types import EmbeddedResource, ImageContent

NonTextContent = ImageContent | EmbeddedResource

and appears in the ToolMessage as something like:

ToolMessage(
    content=...,
    name=...,
    id=...,
    tool_call_id=...,
    artifact=[
        EmbeddedResource(
            type="resource",
            resource=TextResourceContents(
                uri=AnyUrl("https://example.com/"),
                mimeType=None,
                meta=None,
                text=...
            )
        )
    ]
)

The problem occurs when I use this tool inside a ReAct agent together with a checkpointer.
In this case, I get the following error:

TypeError: Type is not msgpack serializable: ToolMessage

It seems this happens because of the required uri field, which is of type AnyUrl, and msgpack cannot serialize it directly.

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions