From 488cd29a2ba33dd56b167f53b0f6954acdc9e5f2 Mon Sep 17 00:00:00 2001 From: aifanatic Date: Tue, 27 Oct 2026 07:46:20 -0500 Subject: [PATCH 1/2] Python: fix AG-UI examples server and getting-started client calls - 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 --- .../ag-ui/agent_framework_ag_ui/_client.py | 2 +- .../agent_framework_ag_ui_examples/.env.example | 1 + .../server/main.py | 6 +++--- python/packages/ag-ui/getting_started/README.md | 13 +++++++++---- .../ag-ui/getting_started/client_advanced.py | 16 ++++++++++------ 5 files changed, 24 insertions(+), 14 deletions(-) diff --git a/python/packages/ag-ui/agent_framework_ag_ui/_client.py b/python/packages/ag-ui/agent_framework_ag_ui/_client.py index 7f21cc8c44e..2e2755e4774 100644 --- a/python/packages/ag-ui/agent_framework_ag_ui/_client.py +++ b/python/packages/ag-ui/agent_framework_ag_ui/_client.py @@ -162,7 +162,7 @@ class AGUIChatClient( # Second message - server retrieves history using thread_id response2 = await client.get_response( "How are you?", - metadata={"thread_id": thread_id} + options={"metadata": {"thread_id": thread_id}}, ) Recommended usage with Agent (client manages history): diff --git a/python/packages/ag-ui/agent_framework_ag_ui_examples/.env.example b/python/packages/ag-ui/agent_framework_ag_ui_examples/.env.example index ada219d9d9d..9c5b6a52731 100644 --- a/python/packages/ag-ui/agent_framework_ag_ui_examples/.env.example +++ b/python/packages/ag-ui/agent_framework_ag_ui_examples/.env.example @@ -1,3 +1,4 @@ AZURE_OPENAI_ENDPOINT=https://your-resource.openai.azure.com/ AZURE_OPENAI_API_KEY=your-api-key-here +AZURE_OPENAI_MODEL=gpt-4o-mini PORT=8000 diff --git a/python/packages/ag-ui/agent_framework_ag_ui_examples/server/main.py b/python/packages/ag-ui/agent_framework_ag_ui_examples/server/main.py index 06e289d00d2..4e7e9bddde9 100644 --- a/python/packages/ag-ui/agent_framework_ag_ui_examples/server/main.py +++ b/python/packages/ag-ui/agent_framework_ag_ui_examples/server/main.py @@ -13,7 +13,6 @@ from agent_framework import ChatOptions from agent_framework._clients import SupportsChatGetResponse from agent_framework.ag_ui import add_agent_framework_fastapi_endpoint as _add_agent_framework_fastapi_endpoint -from agent_framework.azure import AzureOpenAIChatClient from agent_framework.openai import OpenAIChatCompletionClient from fastapi import FastAPI from fastapi.middleware.cors import CORSMiddleware @@ -97,7 +96,8 @@ # Create a shared chat client for all agents # You can use different chat clients for different agents if needed # Set CHAT_CLIENT=anthropic for Anthropic, CHAT_CLIENT=openai (or just an -# OPENAI_API_KEY) for OpenAI Chat-Completions; otherwise defaults to Azure OpenAI. +# OPENAI_API_KEY) for OpenAI Chat-Completions; otherwise defaults to Azure OpenAI +# Chat-Completions configured by AZURE_OPENAI_ENDPOINT, AZURE_OPENAI_API_KEY and AZURE_OPENAI_MODEL. _chat_client_kind = os.getenv("CHAT_CLIENT", "").lower() @@ -109,7 +109,7 @@ def _default_shared_client() -> SupportsChatGetResponse[ChatOptions]: SupportsChatGetResponse[ChatOptions], OpenAIChatCompletionClient(model=os.getenv("OPENAI_CHAT_MODEL_ID", "gpt-4o")), ) - return cast(SupportsChatGetResponse[ChatOptions], AzureOpenAIChatClient()) + return cast(SupportsChatGetResponse[ChatOptions], OpenAIChatCompletionClient()) client: SupportsChatGetResponse[ChatOptions] = _default_shared_client() diff --git a/python/packages/ag-ui/getting_started/README.md b/python/packages/ag-ui/getting_started/README.md index aa8cd3e9e7c..be1dab88059 100644 --- a/python/packages/ag-ui/getting_started/README.md +++ b/python/packages/ag-ui/getting_started/README.md @@ -37,9 +37,9 @@ python client_advanced.py ### Agent Integration (`client_with_agent.py`) -Best practice example using `Agent` wrapper with **AgentThread** -- **AgentThread** maintains conversation state -- Client-side conversation history management via `thread.message_store` +Best practice example using `Agent` wrapper with **AgentSession** +- **AgentSession** (from `agent.create_session()`) maintains conversation state +- Client-side conversation history management through the session - **Hybrid tool execution**: client-side + server-side tools simultaneously - Full conversation history sent on each request - Tool calling with conversation context @@ -320,6 +320,7 @@ Create a file named `client.py`: import asyncio import os +from agent_framework import Message from agent_framework.ag_ui import AGUIChatClient @@ -350,7 +351,11 @@ async def main(): # Use metadata to maintain conversation continuity metadata = {"thread_id": thread_id} if thread_id else None - async for update in client.get_response(message, metadata=metadata, stream=True): + async for update in client.get_response( + [Message(role="user", contents=[message])], + stream=True, + options={"metadata": metadata} if metadata else None, + ): # Extract thread ID from first update if not thread_id and update.additional_properties: thread_id = update.additional_properties.get("thread_id") diff --git a/python/packages/ag-ui/getting_started/client_advanced.py b/python/packages/ag-ui/getting_started/client_advanced.py index 74bb8e74b8f..24ad76290fd 100644 --- a/python/packages/ag-ui/getting_started/client_advanced.py +++ b/python/packages/ag-ui/getting_started/client_advanced.py @@ -13,7 +13,7 @@ import asyncio import os -from typing import cast +from typing import Any, cast from agent_framework import ChatResponse, ChatResponseUpdate, Message, ResponseStream, tool from agent_framework.ag_ui import AGUIChatClient @@ -100,7 +100,10 @@ async def non_streaming_example(client: AGUIChatClient, thread_id: str | None = print("\nUser: What is 2 + 2?\n") - response = await client.get_response([Message(role="user", contents=["What is 2 + 2?"])], metadata=metadata) + response = await client.get_response( + [Message(role="user", contents=["What is 2 + 2?"])], + options={"metadata": metadata} if metadata else None, + ) print(f"Assistant: {response.text}") @@ -138,10 +141,12 @@ async def tool_example(client: AGUIChatClient, thread_id: str | None = None): print("Sending tool definitions to server...") print("(Server must be configured with matching tools to execute them)\n") + options: dict[str, Any] = {"tools": [get_weather, calculate]} + if metadata: + options["metadata"] = metadata response = await client.get_response( [Message(role="user", contents=["What's the weather in Seattle?"])], - tools=[get_weather, calculate], - metadata=metadata, + options=options, ) print(f"Assistant: {response.text}") @@ -196,8 +201,7 @@ async def conversation_example(client: AGUIChatClient): print("\nUser: Can you also tell me what 10 * 5 is?\n") response3 = await client.get_response( [Message(role="user", contents=["Can you also tell me what 10 * 5 is?"])], - options={"metadata": {"thread_id": thread_id}}, - tools=[calculate], + options={"metadata": {"thread_id": thread_id}, "tools": [calculate]}, ) print(f"Assistant: {response3.text}") From 7ea531147d4b2a2a9ba10cd9712ae5a067be111c Mon Sep 17 00:00:00 2001 From: aifanatic Date: Tue, 27 Oct 2026 07:48:47 -0500 Subject: [PATCH 2/2] Python: keep the AG-UI tool example options a ChatOptions literal Co-Authored-By: Claude Opus 5.5 --- python/packages/ag-ui/getting_started/client_advanced.py | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/python/packages/ag-ui/getting_started/client_advanced.py b/python/packages/ag-ui/getting_started/client_advanced.py index 24ad76290fd..edc07de9ac3 100644 --- a/python/packages/ag-ui/getting_started/client_advanced.py +++ b/python/packages/ag-ui/getting_started/client_advanced.py @@ -13,7 +13,7 @@ import asyncio import os -from typing import Any, cast +from typing import cast from agent_framework import ChatResponse, ChatResponseUpdate, Message, ResponseStream, tool from agent_framework.ag_ui import AGUIChatClient @@ -141,12 +141,9 @@ async def tool_example(client: AGUIChatClient, thread_id: str | None = None): print("Sending tool definitions to server...") print("(Server must be configured with matching tools to execute them)\n") - options: dict[str, Any] = {"tools": [get_weather, calculate]} - if metadata: - options["metadata"] = metadata response = await client.get_response( [Message(role="user", contents=["What's the weather in Seattle?"])], - options=options, + options={"tools": [get_weather, calculate], "metadata": metadata or {}}, ) print(f"Assistant: {response.text}")