Skip to content

Python: fix: add to_json to Content for serialization compatibility#4721

Open
jnMetaCode wants to merge 1 commit intomicrosoft:mainfrom
jnMetaCode:fix/content-to-json
Open

Python: fix: add to_json to Content for serialization compatibility#4721
jnMetaCode wants to merge 1 commit intomicrosoft:mainfrom
jnMetaCode:fix/content-to-json

Conversation

@jnMetaCode
Copy link

Summary

  • Add to_json() method to the Content class, fixing TypeError when Azure Functions serializes Message objects containing Content instances.
  • Content already has to_dict() but lacked the corresponding to_json() that SerializationMixin provides. This adds it following the same pattern: delegates to json.dumps(self.to_dict()).

Fixes #4719

Test plan

  • Verify Content.from_text("hello").to_json() returns valid JSON
  • Verify kwargs pass through (e.g. to_json(indent=2))
  • Verify exclude_none and exclude parameters work as expected
  • Confirm Azure Functions can serialize Message objects containing Content without TypeError

Content has to_dict() but lacks to_json(), causing TypeError when
Azure Functions serializes Message objects containing Content instances.
Add to_json() matching the pattern used by SerializationMixin.

Fixes microsoft#4719

Signed-off-by: JiangNan <1394485448@qq.com>
@github-actions github-actions bot changed the title fix: add to_json to Content for serialization compatibility Python: fix: add to_json to Content for serialization compatibility Mar 16, 2026
@jnMetaCode
Copy link
Author

@microsoft-github-policy-service agree

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

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Python: [Bug]: class 'agent_framework._types.Content'> does not expose a to_json function

2 participants