Skip to content

Fix equality for copied tool messages - #366

Open
anbuzin wants to merge 1 commit into
mainfrom
fix-tool-message-copy
Open

anbuzin wants to merge 1 commit into
mainfrom
fix-tool-message-copy

Conversation

@anbuzin

@anbuzin anbuzin commented Nov 17, 2026

Copy link
Copy Markdown
Collaborator

Tool messages with no model_input didn't compare equal to their deep copies or after a pickle round trip. Copying or unpickling made a new unset marker; now we keep the same one. The dumped data and JSON haven't changed.

Restore the module's unset model-input sentinel when copying or
unpickling it. Tool messages then compare equal to their pickle, deep
copy and deep model copy without changing their serialized fields.
@anbuzin anbuzin added the fix Bug fix label Nov 17, 2026
@vercel

vercel Bot commented Nov 17, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated
ai-python Ready Ready Preview, v0 Nov 17, 2026 11:52pm UTC

Comment thread src/ai/types/messages.py
Comment on lines +205 to +206
def __reduce__(self) -> str:
return "MODEL_INPUT_UNSET"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm I don't understand this.

We should consider using the new sentinel feature though

Comment thread src/ai/types/messages.py
return "MODEL_INPUT_UNSET"


MODEL_INPUT_UNSET: Any = _ModelInputUnset()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Aha: "If a string is returned, the string should be interpreted as the name of a global variable.", from __reduce__ docs...

This branch was successfully deployed

1 active deployment
Preview — 7b2273cb Deployed Nov 17, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

fix Bug fix

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants