Repository navigation
Python: Fix serialization docstring examples - #10078
Draft
Naveen Chatlapalli (1aifanatic) wants to merge 1 commit into
Draft
Naveen Chatlapalli (1aifanatic) wants to merge 1 commit into
Naveen Chatlapalli (1aifanatic) wants to merge 1 commit into
Conversation
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Naveen Chatlapalli (1aifanatic)
temporarily deployed
to
github-app-auth
November 4, 2026 05:36 — with
GitHub Actions
Inactive
Naveen Chatlapalli (1aifanatic)
temporarily deployed
to
github-app-auth
November 4, 2026 05:37 — with
GitHub Actions
Inactive
Contributor
There was a problem hiding this comment.
🟢 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, andAgentContextexamples with serializable types and instance-specific tool injection. - Correct
CustomAgentinitialization 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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation & Context
Five of the eight code examples in
agent_framework/_serialization.pyfail when run:mainSerializationProtocol: "simpler classes likeUsageDetails"AttributeError: 'dict' object has no attribute 'to_dict'(UsageDetailsis aTypedDict)SerializationMixin: "Framework tools with exclusion patterns"ImportError: cannot import name 'BaseTool' from 'agent_framework._tools'SerializationMixin:CustomAgentTypeError: BaseAgent.__init__() got an unexpected keyword argument 'context_provider', andCustomAgent.from_dict(...)then fails withgot multiple values for keyword argument 'name'from_dict: OpenAI client injectionValueError: Type mismatch: expected 'open_a_i_chat_client', got 'open_ai_chat_client'. The injected key is alsoclient, but the constructor parameter isasync_clientfrom_dict:AgentContextinjectionAttributeError: type object 'AgentContext' has no attribute 'from_dict'Description & Review Guide
Content, which does implementto_dict/from_dict.FunctionTool, which hasadditional_propertiesinDEFAULT_EXCLUDEandfuncinINJECTABLE.CustomAgentusescontext_providersand sets its name and description defaults throughkwargs.setdefault, sofrom_dictcan pass them back in.open_a_i_chat_clientand injectsasync_client.AgentContextexample, which isn't serializable, becomes an example of the documented instance-specific injection ("name:get_weather"keys).open_a_i_chat_clientis what_get_type_identifier()produces forOpenAIChatClient. 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
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
breaking changelabel (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