Skip to content

Python: Fix AG-UI examples server import and getting-started client calls - #9755

Draft
Naveen Chatlapalli (1aifanatic) wants to merge 2 commits into
microsoft:mainfrom
1aifanatic:contrib/python-agui-examples-server
Draft

Naveen Chatlapalli (1aifanatic) wants to merge 2 commits into
microsoft:mainfrom
1aifanatic:contrib/python-agui-examples-server

Conversation

@1aifanatic

Copy link
Copy Markdown
Contributor

Motivation & Context

Two AG-UI entry points fail on main.

Examples server. python -m agent_framework_ag_ui_examples is the documented way to start the AG-UI examples server, which ships in the agent-framework-ag-ui wheel. It crashes at import:

ImportError: cannot import name 'AzureOpenAIChatClient' from 'agent_framework.azure'

AzureOpenAIChatClient was removed with the other deprecated OpenAI/Azure surfaces in #4990. server/main.py still imports it at module level for its Azure OpenAI default.

Getting-started client. getting_started/client_advanced.py passes metadata= and tools= directly to AGUIChatClient.get_response(). get_response accepts these only inside options, so the script stops at its second example:

TypeError: FunctionInvocationLayer.get_response() got an unexpected keyword argument 'metadata'

The tool_example and conversation_example steps fail the same way on tools=. The streaming client snippet in getting_started/README.md and the AGUIChatClient class docstring also use metadata=.

Description & Review Guide

  • What are the major changes?
    • server/main.py: the default client is now OpenAIChatCompletionClient(). Without OPENAI_API_KEY, it routes to Azure OpenAI from AZURE_OPENAI_ENDPOINT, AZURE_OPENAI_API_KEY and AZURE_OPENAI_MODEL. The comment names those variables, and .env.example gains AZURE_OPENAI_MODEL, which the client requires.
    • client_advanced.py, the README snippet and the AGUIChatClient docstring now pass metadata and tools through options, as client.py and the streaming example in the same file already do.
    • getting_started/README.md describes client_with_agent.py's session as AgentSession, which the script uses, instead of AgentThread / thread.message_store.
  • What is the impact of these changes? Examples and docs only; library code is unchanged.
  • What do you want reviewers to focus on? Whether the examples server should default to OpenAIChatCompletionClient for Azure or to another client, such as FoundryChatClient.

Verification:

  • With only the AZURE_OPENAI_* variables set, agent_framework_ag_ui_examples.server.main imports. It builds an OpenAIChatCompletionClient backed by AsyncAzureOpenAI and registers all example routes.
  • I ran every function in client_advanced.py against a local AG-UI endpoint (add_agent_framework_fastapi_endpoint with a stub agent, over httpx.ASGITransport). On main, non_streaming_example and tool_example raise the TypeError. With this change, all four examples complete, the server side receives the two tool definitions, and the thread_id round-trips.
  • The ag-ui test suite passes: 1776 passed.

Related Issue

N/A - trivial change: replaces a removed class with its documented successor and moves metadata and tools into options, as the API requires.

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 these while checking examples for removed APIs, run the AG-UI client examples against a local endpoint, make the edits, 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

- The examples server imported the removed AzureOpenAIChatClient, so
  python -m agent_framework_ag_ui_examples failed with ImportError. Use
  OpenAIChatCompletionClient, which reads the AZURE_OPENAI_* settings, and
  add AZURE_OPENAI_MODEL to the examples .env template.
- client_advanced.py, the getting-started README and the AGUIChatClient
  docstring passed metadata= and tools= directly to get_response, which
  raises TypeError; pass them through options instead.
- Describe the client_with_agent.py session as AgentSession, not AgentThread.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Copilot AI balanced review requested due to automatic review settings October 27, 2026 12:46
@agent-framework-automation agent-framework-automation Bot added documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python labels Oct 27, 2026
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

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

The focused changes match the current client contracts and Azure configuration behavior, with no unresolved findings.

No open issues 🎉

What changed in this PR

Repairs AG-UI example entry points after the deprecated Azure client removal in #4990 and aligns sample calls with the current client API. Library runtime behavior is unchanged.

Changes:

  • Replaces the removed Azure client with OpenAIChatCompletionClient and documents the required Azure model setting.
  • Passes metadata and tools through options in examples and documentation.
  • Updates session terminology to AgentSession.
File Description
python/​packages/​ag-ui/​getting_started/​README.md Corrects streaming calls and session documentation.
python/​packages/​ag-ui/​getting_started/​client_advanced.py Moves metadata and tools into request options.
python/​packages/​ag-ui/​agent_framework_ag_ui/​_client.py Corrects the metadata argument in the docstring example.
python/​packages/​ag-ui/​agent_framework_ag_ui_examples/​server/​main.py Replaces the removed Azure client with its supported successor.
python/​packages/​ag-ui/​agent_framework_ag_ui_examples/​.env.example Adds the required Azure model environment variable.

Review effort: Balanced

This branch was previously deployed

1 inactive deployment
github-app-auth — 7ea53114 Deployed Oct 27, 2026 by 1aifanatic via add_label #26285
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

documentation Usage: [Issues, PRs], Target: documentation in the code base and learn docs python Usage: [Issues, PRs], Target: Python

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants