Python: openai updates (#388)

* openai updates

* rebuild of openai structure

* updated responses structure

* renamed sample

* added file id support to code interpreter

* added hosted file ids to code interpretor

* mypy fixes

* removed default az cred from codebase

* updated agent name setup

* added kwargs to entra methods

* and further kwargs

* extra comment

* updated all samples

* readded custom get methods for responses

* updated int tests with ad credential

* missed one
This commit is contained in:
Eduard van Valkenburg
2025-08-12 08:14:22 +02:00
committed by GitHub
Unverified
parent 19676978e9
commit df9d85d1f0
53 changed files with 1668 additions and 1470 deletions
@@ -5,6 +5,7 @@ from random import randint
from typing import Annotated
from agent_framework.foundry import FoundryChatClient
from azure.identity.aio import DefaultAzureCredential
from pydantic import Field
@@ -22,7 +23,7 @@ async def non_streaming_example() -> None:
# Since no Agent ID is provided, the agent will be automatically created
# and deleted after getting a response
async with FoundryChatClient().create_agent(
async with FoundryChatClient(async_ad_credential=DefaultAzureCredential()).create_agent(
name="WeatherAgent",
instructions="You are a helpful weather agent.",
tools=get_weather,
@@ -39,7 +40,7 @@ async def streaming_example() -> None:
# Since no Agent ID is provided, the agent will be automatically created
# and deleted after getting a response
async with FoundryChatClient().create_agent(
async with FoundryChatClient(async_ad_credential=DefaultAzureCredential()).create_agent(
name="WeatherAgent",
instructions="You are a helpful weather agent.",
tools=get_weather,
@@ -11,6 +11,7 @@ from azure.ai.agents.models import (
RunStepDeltaCodeInterpreterToolCall,
RunStepDeltaToolCallObject,
)
from azure.identity.aio import DefaultAzureCredential
def get_code_interpreter_chunk(chunk: AgentRunResponseUpdate) -> str | None:
@@ -37,7 +38,7 @@ async def main() -> None:
print("=== Foundry Agent with Code Interpreter Example ===")
async with ChatClientAgent(
chat_client=FoundryChatClient(),
chat_client=FoundryChatClient(async_ad_credential=DefaultAzureCredential()),
instructions="You are a helpful assistant that can write and execute Python code to solve problems.",
tools=HostedCodeInterpreterTool(),
) as agent:
@@ -28,7 +28,7 @@ async def main() -> None:
chat_client=FoundryChatClient(
project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"],
model_deployment_name=os.environ["FOUNDRY_MODEL_DEPLOYMENT_NAME"],
credential=AzureCliCredential(),
async_ad_credential=AzureCliCredential(),
agent_name="WeatherAgent",
),
instructions="You are a helpful weather agent.",
@@ -7,6 +7,7 @@ from typing import Annotated
from agent_framework import ChatClientAgent
from agent_framework.foundry import FoundryChatClient
from azure.identity.aio import DefaultAzureCredential
from pydantic import Field
@@ -31,7 +32,7 @@ async def tools_on_agent_level() -> None:
# Tools are provided when creating the agent
# The agent can use these tools for any query during its lifetime
async with ChatClientAgent(
chat_client=FoundryChatClient(),
chat_client=FoundryChatClient(async_ad_credential=DefaultAzureCredential()),
instructions="You are a helpful assistant that can provide weather and time information.",
tools=[get_weather, get_time], # Tools defined at agent creation
) as agent:
@@ -60,7 +61,7 @@ async def tools_on_run_level() -> None:
# Agent created without tools
async with ChatClientAgent(
chat_client=FoundryChatClient(),
chat_client=FoundryChatClient(async_ad_credential=DefaultAzureCredential()),
instructions="You are a helpful assistant.",
# No tools defined here
) as agent:
@@ -89,7 +90,7 @@ async def mixed_tools_example() -> None:
# Agent created with some base tools
async with ChatClientAgent(
chat_client=FoundryChatClient(),
chat_client=FoundryChatClient(async_ad_credential=DefaultAzureCredential()),
instructions="You are a comprehensive assistant that can help with various information requests.",
tools=[get_weather], # Base tool available for all queries
) as agent:
@@ -6,6 +6,7 @@ from typing import Annotated
from agent_framework import ChatClientAgent, ChatClientAgentThread
from agent_framework.foundry import FoundryChatClient
from azure.identity.aio import DefaultAzureCredential
from pydantic import Field
@@ -22,7 +23,7 @@ async def example_with_automatic_thread_creation() -> None:
print("=== Automatic Thread Creation Example ===")
async with ChatClientAgent(
chat_client=FoundryChatClient(),
chat_client=FoundryChatClient(async_ad_credential=DefaultAzureCredential()),
instructions="You are a helpful weather agent.",
tools=get_weather,
) as agent:
@@ -46,7 +47,7 @@ async def example_with_thread_persistence() -> None:
print("Using the same thread across multiple conversations to maintain context.\n")
async with ChatClientAgent(
chat_client=FoundryChatClient(),
chat_client=FoundryChatClient(async_ad_credential=DefaultAzureCredential()),
instructions="You are a helpful weather agent.",
tools=get_weather,
) as agent:
@@ -82,7 +83,7 @@ async def example_with_existing_thread_id() -> None:
existing_thread_id = None
async with ChatClientAgent(
chat_client=FoundryChatClient(),
chat_client=FoundryChatClient(async_ad_credential=DefaultAzureCredential()),
instructions="You are a helpful weather agent.",
tools=get_weather,
) as agent:
@@ -102,7 +103,7 @@ async def example_with_existing_thread_id() -> None:
# Create a new agent instance but use the existing thread ID
async with ChatClientAgent(
chat_client=FoundryChatClient(thread_id=existing_thread_id),
chat_client=FoundryChatClient(thread_id=existing_thread_id, async_ad_credential=DefaultAzureCredential()),
instructions="You are a helpful weather agent.",
tools=get_weather,
) as agent: