Skip to content

Python: Fix serialization docstring examples - #10078

Draft
Naveen Chatlapalli (1aifanatic) wants to merge 1 commit into
microsoft:mainfrom
1aifanatic:contrib/python-serialization-docstring-examples
Draft

Naveen Chatlapalli (1aifanatic) wants to merge 1 commit into
microsoft:mainfrom
1aifanatic:contrib/python-serialization-docstring-examples

Conversation

@1aifanatic

Copy link
Copy Markdown
Contributor

Motivation & Context

Five of the eight code examples in agent_framework/_serialization.py fail when run:

Example Error on main
SerializationProtocol: "simpler classes like UsageDetails" AttributeError: 'dict' object has no attribute 'to_dict' (UsageDetails is a TypedDict)
SerializationMixin: "Framework tools with exclusion patterns" ImportError: cannot import name 'BaseTool' from 'agent_framework._tools'
SerializationMixin: CustomAgent TypeError: BaseAgent.__init__() got an unexpected keyword argument 'context_provider', and CustomAgent.from_dict(...) then fails with got multiple values for keyword argument 'name'
from_dict: OpenAI client injection ValueError: Type mismatch: expected 'open_a_i_chat_client', got 'open_ai_chat_client'. The injected key is also client, but the constructor parameter is async_client
from_dict: AgentContext injection AttributeError: type object 'AgentContext' has no attribute 'from_dict'

Description & Review Guide

  • What are the major changes? Docstring examples only:
    • The protocol example uses Content, which does implement to_dict/from_dict.
    • The exclusion example uses FunctionTool, which has additional_properties in DEFAULT_EXCLUDE and func in INJECTABLE.
    • CustomAgent uses context_providers and sets its name and description defaults through kwargs.setdefault, so from_dict can pass them back in.
    • The OpenAI example uses the real type id open_a_i_chat_client and injects async_client.
    • The AgentContext example, which isn't serializable, becomes an example of the documented instance-specific injection ("name:get_weather" keys).
  • What is the impact of these changes? Documentation only.
  • What do you want reviewers to focus on? open_a_i_chat_client is what _get_type_identifier() produces for OpenAIChatClient. If that identifier isn't intended, it's worth a separate issue, but I left the code alone here.

I extracted and ran every example in the module: all 8 run on this branch. I also checked their outputs: the restored agent keeps its name, each tool receives the function meant for it, and the injected client is the one that was passed in.

Related Issue

N/A - trivial change: docstring examples are corrected to the current APIs, with no behavior change.

AI Assistance

  • No material AI assistance was used.
  • This is an AI-assisted contribution. I reviewed, understood, and verified all submitted content and accept responsibility for it.

AI assistance details: Claude Code helped find the failing examples by executing every docstring code block, rewrite them, re-run them, and draft this description.

Contribution Checklist

  • The code builds clean without any errors or warnings
  • All unit tests pass, and I have added new tests where possible
  • The PR follows the Contribution Guidelines
  • This PR links to an agreed issue with no competing open PR, or the Related Issue section documents a trivial-change or repository-automation exception.
  • This is not a breaking change. If it is a breaking change, add the breaking change label (or add "[BREAKING]" to the title prefix, before or after any language prefix) — a workflow keeps the label and title prefix in sync automatically.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings November 4, 2026 05:36
@agent-framework-automation agent-framework-automation Bot added the python Usage: [Issues, PRs], Target: Python label Nov 4, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No active review issues are reported for this documentation-only update to serialization examples.

No open issues 🎉

What changed in this PR

This documentation-only PR corrects serialization examples to match current Agent Framework APIs. Runtime behavior is unchanged.

Changes:

  • Replace unsupported UsageDetails, BaseTool, and AgentContext examples with serializable types and instance-specific tool injection.
  • Correct CustomAgent initialization and its documented serialized fields.
  • Fix the OpenAI client type identifier and dependency injection parameter.
File Description
python/​packages/​core/​agent_framework/​_serialization.py Corrects five docstring examples covering serialization, exclusions, and dependency injection.

Review effort: Balanced

This branch was previously deployed

1 inactive deployment
github-app-auth — 3a731132 Deployed Nov 4, 2026 by 1aifanatic via team_check #8667
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants