Skip to content

Python: [Bug]: dataclass, Enum and set tool results are sent to the model as Python repr #10274

Closed

Description

Observed Behavior

When a function tool returns a dataclass, an Enum member or a set (or a dict/list that contains one of them), the text sent back to the model is the Python repr instead of JSON. For example an Enum value reaches the model as "Color.RED" and a dataclass as "Point(x=1)", so the model sees Python syntax rather than the actual values.

Expected Behavior

These should be converted to JSON values like Pydantic model results already are since #9036: Enum -> its value ("red"), dataclass -> a JSON object ({"x": 1}), set -> a JSON array (["a"]).

Steps to Reproduce

  1. Define a tool result containing an Enum, a dataclass or a set.
  2. Pass it through FunctionTool.parse_result (this is what FunctionTool.invoke does with the return value).
  3. Look at the text of the returned content.

Minimal Reproduction

from dataclasses import dataclass
from enum import Enum

from agent_framework import FunctionTool


class Color(Enum):
    RED = "red"


@dataclass
class Point:
    x: int


print(FunctionTool.parse_result({"color": Color.RED})[0].text)  # {"color": "Color.RED"}
print(FunctionTool.parse_result(Point(x=1))[0].text)             # "Point(x=1)"
print(FunctionTool.parse_result({"tags": {"a"}})[0].text)        # {"tags": "{'a'}"}

Error Messages and Stack Traces

No error. The output is just the repr strings shown above.

Package Versions

agent-framework-core: main (22b5e75)

Python Version

Python 3.13

Operating System

Linux

Regression

No

Additional Context

_make_dumpable handles Pydantic models (JSON mode, from #9036) and Content, but other objects fall through to json.dumps(..., default=str), so dataclasses, Enum members and sets end up as str() of the object. The same Color.RED inside a Pydantic model already becomes "red", but outside a model it doesn't. The parse_result docstring also says arbitrary objects are serialized to JSON text.

A possible fix is to convert dataclasses (recursively), Enum members (to .value) and sets/frozensets (to lists) in _make_dumpable before json.dumps. I have this with a test locally and can open a PR once the direction is agreed.

Acknowledgements

  • I searched existing issues and did not find a duplicate.
  • I personally verified this behavior and the reproduction details are authentic.
  • I will wait for explicit maintainer agreement before starting implementation of a non-trivial change.

Activity

  1. added
    pythonUsage: [Issues, PRs], Target: Python
    triageUsage: [Issues], Target: All issues that still need to be triaged
    on Nov 11, 2026
  2. added
    agentsUsage: [Issues, PRs], Target: Single agent
    reproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflow
    on Nov 11, 2026
  3. github-actions commented on Nov 11, 2026

    @github-actions
    Contributor

    Reproduced on main (22b5e75) with a minimal script based on the report: FunctionTool.parse_result returns {"color": "Color.RED"}, "Point(x=1)" and {"tags": "{'a'}"} — Python reprs rather than JSON values. Run: https://github.com/microsoft/agent-framework/actions/runs/43079857465

    Support boundary: unclear. The parse_result docstring suggests arbitrary objects are serialized to JSON, but I found no spec or decision record setting the scope, so a maintainer should decide. Routed to the agent-framework-core owner. Maintainers decide on acceptance and priority.

    Generated by Issue Routing for #10274 · copilot · auto · ~19 AIC · ⌖ ~1 AIC · ⊞ 5.2K · ◷

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

agentsUsage: [Issues, PRs], Target: Single agentpythonUsage: [Issues, PRs], Target: PythonreproducedUsage: [Issues], Target: all issues that can be reproduced by the triage workflowtriageUsage: [Issues], Target: All issues that still need to be triaged

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions