Fix AG-UI backend tool rendering example — broken imports and API changes#417
Open
Ashutosh0x wants to merge 1 commit into
Open
Fix AG-UI backend tool rendering example — broken imports and API changes#417Ashutosh0x wants to merge 1 commit into
Ashutosh0x wants to merge 1 commit into
Conversation
- Remove ToolCallContent/ToolResultContent imports that no longer exist in agent_framework package (ImportError on current versions) - Use AGUIChatClient(endpoint=) keyword argument instead of positional - Replace isinstance() checks with getattr() type-string checking for forward-compatible content type detection - Guard against None contents with (update.contents or []) Fixes MicrosoftDocs#406
Contributor
|
Learn Build status updates of commit 24d478a:
|
| File | Status | Preview URL | Details |
|---|---|---|---|
| agent-framework/get-started/workflows.md | Details | ||
| agent-framework/integrations/ag-ui/backend-tool-rendering.md | ✅Succeeded |
agent-framework/get-started/workflows.md
- Line 64, Column 1: [Warning: invalid-code]
The code snippet "~/../agent-framework-code/python/samples/01-get-started/05_first_workflow.py" could not be found. - Line 68, Column 1: [Warning: invalid-code]
The code snippet "~/../agent-framework-code/python/samples/01-get-started/05_first_workflow.py" could not be found.
For more details, please refer to the build report.
Note: Your PR may contain errors or warnings or suggestions unrelated to the files you changed. This happens when external dependencies like GitHub alias, Microsoft alias, cross repo links are updated. Please use these instructions to resolve them.
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.
Fixes #406
Problem
The AG-UI backend tool rendering example in
backend-tool-rendering.mdthrows anImportErrorwhen executed:from agent_framework import Agent, ToolCallContent, ToolResultContent ImportError: cannot import name 'ToolCallContent' from 'agent_framework'The
ToolCallContentandToolResultContentclasses were removed/renamed in recent agent-framework releases, breaking the documented example.Changes
Removed broken imports —
ToolCallContentandToolResultContentno longer exist inagent_framework. Changed import to justfrom agent_framework import AgentFixed
AGUIChatClientconstructor — Changed from positionalserver_urlto keywordendpoint=server_urlto match current APIReplaced
isinstance()checks withgetattr()type-string checking — More resilient to API changes:isinstance(content, ToolCallContent)→getattr(content, 'type', '') == 'function_call'isinstance(content, ToolResultContent)→content_type in {'function_result', 'tool_result'}Added null guard —
update.contents→(update.contents or [])to preventTypeErroronNoneTesting
Verified the corrected code follows the working pattern reported by @mjmadhu in #406.
Context
I'm an active contributor to the microsoft/agent-framework repo (PRs #6642 and #6643) and encountered these same API changes while working on the Python hosting stack.