Repository navigation
fix: convert common Python types in Agent tool results to JSON - #13728
Conversation
|
@astroknot-sheep is attempting to deploy a commit to the deepset Team on Vercel. A member of the Team first needs to authorize it. |
Coverage reportClick to see where and how coverage changed
This report was generated by python-coverage-comment-action |
||||||||||||||||||||||||
| "path": Path("/tmp/a.txt"), | ||
| } | ||
| ) | ||
| ) == {"color": "red", "tags": ["a"], "day": "2026-01-02", "price": "1.50", "path": "/tmp/a.txt"} |
There was a problem hiding this comment.
This fails on Windows because str(Path("/tmp/a.txt")) is \tmp\a.txt there. Could we use a path without separators?
| "path": Path("/tmp/a.txt"), | |
| } | |
| ) | |
| ) == {"color": "red", "tags": ["a"], "day": "2026-01-02", "price": "1.50", "path": "/tmp/a.txt"} | |
| "path": Path("a.txt"), | |
| } | |
| ) | |
| ) == {"color": "red", "tags": ["a"], "day": "2026-01-02", "price": "1.50", "path": "a.txt"} |
There was a problem hiding this comment.
Thanks for catching that. Done in 9fe49eb, the test now uses Path("a.txt").
| from concurrent.futures import ThreadPoolExecutor | ||
| from typing import Any | ||
|
|
||
| from pydantic_core import to_jsonable_python |
There was a problem hiding this comment.
Since we import pydantic_core directly now, could we also declare it in the dependencies in pyproject.toml? We do the same for MarkupSafe, e.g. "pydantic-core", # already required by pydantic but used directly in tool_calling._result_to_string
There was a problem hiding this comment.
Added "pydantic-core" to the dependencies in pyproject.toml with the same kind of comment as MarkupSafe (9fe49eb).
|
Hey @astroknot-sheep pinging to ask if you have time to work on this |
|
Review the following changes in direct dependencies. Learn more about Socket for GitHub.
|
Related Issues
Proposed Changes:
_result_to_stringserializes tool results withjson.dumps, and when that fails the whole result falls back tostr(). So a tool returning a Pydantic model, dataclass, Enum, set,datetime/date/time,UUID,Decimalor path (also when nested in a list/dict) sent a Python repr to the LLM, e.g.id=1 status=<Status.OPEN: 'open'>or{'created': datetime.date(2026, 1, 2)}, and logged a warning on every call.I added a small
_json_defaulthook passed asdefault=tojson.dumps:model_dump(mode="json").value, set/frozenset -> listdatetime/date/time-> ISO format,UUID/Decimal/paths ->strAnything else still raises
TypeError, so the existingstr()fallback and warning are unchanged for truly unsupported types. Objects withto_dict()(Document, ChatMessage, ...) are still handled by_serializable_valuefirst.How did you test it?
test_result_to_string_with_common_python_types(fails on main, passes with the fix) andtest_result_to_string_falls_back_to_str_for_unsupported_types.pytest -m "not integration" test/components/agents test/tools(645 passed, 2 skipped;test_component_tool.pyskipped locally because theflakyplugin isn't installed in my env).Notes for the reviewer
Release note added under
fixes. I used an AI coding assistant to help find and write this fix; I reproduced the bug, reviewed the change and ran the tests myself.Checklist
fix:,feat:,build:,chore:,ci:,docs:,style:,refactor:,perf:,test:and added!in case the PR includes breaking changes.