Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion python/packages/ag-ui/agent_framework_ag_ui/_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()


Expand All @@ -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()
Expand Down
13 changes: 9 additions & 4 deletions python/packages/ag-ui/getting_started/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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


Expand Down Expand Up @@ -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")
Expand Down
11 changes: 6 additions & 5 deletions python/packages/ag-ui/getting_started/client_advanced.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")

Expand Down Expand Up @@ -140,8 +143,7 @@ async def tool_example(client: AGUIChatClient, thread_id: str | None = None):

response = await client.get_response(
[Message(role="user", contents=["What's the weather in Seattle?"])],
tools=[get_weather, calculate],
metadata=metadata,
options={"tools": [get_weather, calculate], "metadata": metadata or {}},
)

print(f"Assistant: {response.text}")
Expand Down Expand Up @@ -196,8 +198,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}")

Expand Down
Loading