Skip to content

Fix AG-UI backend tool rendering example — broken imports and API changes#417

Open
Ashutosh0x wants to merge 1 commit into
MicrosoftDocs:mainfrom
Ashutosh0x:fix/ag-ui-backend-tool-rendering-imports
Open

Fix AG-UI backend tool rendering example — broken imports and API changes#417
Ashutosh0x wants to merge 1 commit into
MicrosoftDocs:mainfrom
Ashutosh0x:fix/ag-ui-backend-tool-rendering-imports

Conversation

@Ashutosh0x

Copy link
Copy Markdown

Fixes #406

Problem

The AG-UI backend tool rendering example in backend-tool-rendering.md throws an ImportError when executed:

from agent_framework import Agent, ToolCallContent, ToolResultContent ImportError: cannot import name 'ToolCallContent' from 'agent_framework'

The ToolCallContent and ToolResultContent classes were removed/renamed in recent agent-framework releases, breaking the documented example.

Changes

  1. Removed broken importsToolCallContent and ToolResultContent no longer exist in agent_framework. Changed import to just from agent_framework import Agent

  2. Fixed AGUIChatClient constructor — Changed from positional server_url to keyword endpoint=server_url to match current API

  3. Replaced isinstance() checks with getattr() 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'}
  4. Added null guardupdate.contents(update.contents or []) to prevent TypeError on None

Testing

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.

- 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
@learn-build-service-prod

Copy link
Copy Markdown
Contributor

Learn Build status updates of commit 24d478a:

⚠️ Validation status: warnings

File Status Preview URL Details
agent-framework/get-started/workflows.md ⚠️Warning 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.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The getting started example is not working any more for AG UI Integration

1 participant