Skip to content

Commit f806cfc

Browse files
committed
Cleanup
1 parent f9bb338 commit f806cfc

5 files changed

Lines changed: 46 additions & 26 deletions

File tree

agent-framework/integrations/ag-ui/backend-tool-rendering.md

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,9 @@ Before you begin, ensure you have completed the [Getting Started](getting-starte
299299
- Azure OpenAI service configured
300300
- Basic understanding of AG-UI server and client setup
301301

302+
> [!NOTE]
303+
> These samples use `DefaultAzureCredential` for authentication. Make sure you're authenticated with Azure (e.g., via `az login`). For more information, see the [Azure Identity documentation](/python/api/azure-identity/azure.identity.defaultazurecredential).
304+
302305
## What is Backend Tool Rendering?
303306

304307
Backend tool rendering means:
@@ -392,6 +395,7 @@ from typing import Annotated, Any
392395
from agent_framework import ChatAgent, ai_function
393396
from agent_framework.azure import AzureOpenAIChatClient
394397
from agent_framework_ag_ui import add_agent_framework_fastapi_endpoint
398+
from azure.identity import AzureCliCredential
395399
from fastapi import FastAPI
396400
from pydantic import Field
397401

@@ -424,21 +428,26 @@ def search_restaurants(
424428
}
425429

426430

427-
# Read configuration
431+
# Read required configuration
428432
endpoint = os.environ.get("AZURE_OPENAI_ENDPOINT")
429433
deployment_name = os.environ.get("AZURE_OPENAI_DEPLOYMENT_NAME")
430434

431-
if not endpoint or not deployment_name:
432-
raise ValueError("AZURE_OPENAI_ENDPOINT and AZURE_OPENAI_DEPLOYMENT_NAME are required")
435+
if not endpoint:
436+
raise ValueError("AZURE_OPENAI_ENDPOINT environment variable is required")
437+
if not deployment_name:
438+
raise ValueError("AZURE_OPENAI_DEPLOYMENT_NAME environment variable is required")
439+
440+
chat_client = AzureOpenAIChatClient(
441+
credential=AzureCliCredential(),
442+
endpoint=endpoint,
443+
deployment_name=deployment_name,
444+
)
433445

434446
# Create agent with tools
435447
agent = ChatAgent(
436448
name="TravelAssistant",
437449
instructions="You are a helpful travel assistant. Use the available tools to help users plan their trips.",
438-
chat_client=AzureOpenAIChatClient(
439-
endpoint=endpoint,
440-
deployment_name=deployment_name,
441-
),
450+
chat_client=chat_client,
442451
tools=[get_weather, search_restaurants],
443452
)
444453

agent-framework/integrations/ag-ui/getting-started.md

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -410,32 +410,29 @@ import os
410410
from agent_framework import ChatAgent
411411
from agent_framework.azure import AzureOpenAIChatClient
412412
from agent_framework_ag_ui import add_agent_framework_fastapi_endpoint
413+
from azure.identity import AzureCliCredential
413414
from fastapi import FastAPI
414415

415416
# Read required configuration
416417
endpoint = os.environ.get("AZURE_OPENAI_ENDPOINT")
417418
deployment_name = os.environ.get("AZURE_OPENAI_DEPLOYMENT_NAME")
418-
# Note: a token may also be used in place of the api_key using:
419-
# from azure.identity import AzureCliCredential
420-
# chat_client = AzureOpenAIChatClient(credential=AzureCliCredential())
421-
api_key = os.environ.get("AZURE_OPENAI_API_KEY")
422419

423420
if not endpoint:
424421
raise ValueError("AZURE_OPENAI_ENDPOINT environment variable is required")
425422
if not deployment_name:
426423
raise ValueError("AZURE_OPENAI_DEPLOYMENT_NAME environment variable is required")
427-
if not api_key:
428-
raise ValueError("AZURE_OPENAI_API_KEY environment variable is required")
424+
425+
chat_client = AzureOpenAIChatClient(
426+
credential=AzureCliCredential(),
427+
endpoint=endpoint,
428+
deployment_name=deployment_name,
429+
)
429430

430431
# Create the AI agent
431432
agent = ChatAgent(
432433
name="AGUIAssistant",
433434
instructions="You are a helpful assistant.",
434-
chat_client=AzureOpenAIChatClient(
435-
endpoint=endpoint,
436-
deployment_name=deployment_name,
437-
api_key=api_key,
438-
),
435+
chat_client=chat_client,
439436
)
440437

441438
# Create FastAPI app

agent-framework/integrations/ag-ui/human-in-the-loop.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -584,6 +584,7 @@ from typing import Annotated
584584
from agent_framework import ChatAgent, ai_function
585585
from agent_framework.azure import AzureOpenAIChatClient
586586
from agent_framework_ag_ui import AgentFrameworkAgent, add_agent_framework_fastapi_endpoint
587+
from azure.identity import AzureCliCredential
587588
from fastapi import FastAPI
588589
from pydantic import Field
589590

@@ -618,21 +619,26 @@ def check_balance(
618619
return f"Account {account} balance: $5,432.10 USD"
619620

620621

621-
# Read configuration
622+
# Read required configuration
622623
endpoint = os.environ.get("AZURE_OPENAI_ENDPOINT")
623624
deployment_name = os.environ.get("AZURE_OPENAI_DEPLOYMENT_NAME")
624625

625-
if not endpoint or not deployment_name:
626-
raise ValueError("AZURE_OPENAI_ENDPOINT and AZURE_OPENAI_DEPLOYMENT_NAME are required")
626+
if not endpoint:
627+
raise ValueError("AZURE_OPENAI_ENDPOINT environment variable is required")
628+
if not deployment_name:
629+
raise ValueError("AZURE_OPENAI_DEPLOYMENT_NAME environment variable is required")
630+
631+
chat_client = AzureOpenAIChatClient(
632+
credential=AzureCliCredential(),
633+
endpoint=endpoint,
634+
deployment_name=deployment_name,
635+
)
627636

628637
# Create agent with tools
629638
agent = ChatAgent(
630639
name="BankingAssistant",
631640
instructions="You are a banking assistant. Help users with their banking needs. Always confirm details before performing transfers.",
632-
chat_client=AzureOpenAIChatClient(
633-
endpoint=endpoint,
634-
deployment_name=deployment_name,
635-
),
641+
chat_client=chat_client,
636642
tools=[transfer_money, cancel_subscription, check_balance],
637643
)
638644

agent-framework/integrations/ag-ui/state-management.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,7 @@ from agent_framework_ag_ui import (
412412
RecipeConfirmationStrategy,
413413
add_agent_framework_fastapi_endpoint,
414414
)
415+
from azure.identity import AzureCliCredential
415416
from fastapi import FastAPI
416417

417418
# Create the chat agent with tools
@@ -451,7 +452,11 @@ agent = ChatAgent(
451452
- Add finishing touches: lemon zest, fresh parsley
452453
- Make instructions more detailed and professional
453454
""",
454-
chat_client=AzureOpenAIChatClient(),
455+
chat_client=AzureOpenAIChatClient(
456+
credential=AzureCliCredential(),
457+
endpoint=endpoint,
458+
deployment_name=deployment_name,
459+
),
455460
tools=[update_recipe],
456461
)
457462

agent-framework/integrations/ag-ui/testing-with-dojo.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,9 @@ AZURE_OPENAI_API_KEY=your_api_key_here
7070
AZURE_OPENAI_CHAT_DEPLOYMENT_NAME=your_deployment_here
7171
```
7272

73+
> [!NOTE]
74+
> If using `DefaultAzureCredential`, in place for an `api_key` for authentication, make sure you're authenticated with Azure (e.g., via `az login`). For more information, see the [Azure Identity documentation](/python/api/azure-identity/azure.identity.defaultazurecredential).
75+
7376
## Running the Dojo Application
7477

7578
### 1. Start the Backend Server

0 commit comments

Comments
 (0)