Bug Description
When a tool function returns a structured type (dict, list, Pydantic model, dataclass), AutoGen's ToolCallResult silently coerces it to str() via Python's default string conversion. This causes type information loss that propagates through the agent's message history and prevents downstream agents from consuming structured data.
Steps to Reproduce
from autogen_agentchat.messages import ToolCallResult, ToolCallSummaryMessage
# Tool returns structured data
def my_tool() -> dict:
return {"status": "success", "data": {"count": 42, "items": ["a", "b", "c"]}}
# Result is coerced to str
result = ToolCallResult(
content=[ToolCallResult(...)], # simplified
...
)
# content[0].content becomes "{'status': 'success', 'data': {'count': 42, 'items': ['a', 'b', 'c']}}"
# Downstream agents must parse this string back to access the data
Expected Behavior
ToolCallResult should preserve the original Python type (or a serializable representation like JSON) so downstream agents and message processors can consume structured tool outputs without string parsing.
Actual Behavior
All non-string return values become their str() representation. Dicts become Python-repr strings (not valid JSON), lists become repr strings, and complex objects become their repr.
Impact
- Multi-agent pipelines where one agent's tool output feeds another's input break
- Tools returning JSON don't produce valid JSON in the message history
- Type information from Pydantic/dataclass returns is completely lost
- Agents must write fragile parsing code to recover structured data from repr strings
Proposed Fix
Preserve the original type when possible, or at minimum serialize to valid JSON rather than Python repr. Consider adding a content_type field to distinguish between string/structured results.
Bug Description
When a tool function returns a structured type (dict, list, Pydantic model, dataclass), AutoGen's
ToolCallResultsilently coerces it tostr()via Python's default string conversion. This causes type information loss that propagates through the agent's message history and prevents downstream agents from consuming structured data.Steps to Reproduce
Expected Behavior
ToolCallResultshould preserve the original Python type (or a serializable representation like JSON) so downstream agents and message processors can consume structured tool outputs without string parsing.Actual Behavior
All non-string return values become their
str()representation. Dicts become Python-repr strings (not valid JSON), lists become repr strings, and complex objects become their repr.Impact
Proposed Fix
Preserve the original type when possible, or at minimum serialize to valid JSON rather than Python repr. Consider adding a
content_typefield to distinguish between string/structured results.