Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions python/packages/core/agent_framework/_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -1298,6 +1298,22 @@ def to_dict(self, *, exclude_none: bool = True, exclude: set[str] | None = None)

return result

def to_json(self, *, exclude_none: bool = True, exclude: set[str] | None = None, **kwargs: Any) -> str:
"""Serialize the content to a JSON string.

This is a convenience wrapper around ``to_dict()`` that returns a JSON
string via ``json.dumps()``.

Keyword Args:
exclude_none: Whether to exclude None values. Defaults to True.
exclude: Field names to exclude from serialization.
**kwargs: Additional keyword arguments passed to ``json.dumps()``.

Returns:
JSON string representation of the content.
"""
return json.dumps(self.to_dict(exclude_none=exclude_none, exclude=exclude), **kwargs)

def __eq__(self, other: object) -> bool:
"""Check if two Content instances are equal by comparing their dict representations."""
if not isinstance(other, Content):
Expand Down