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
@@ -4,8 +4,8 @@ import asyncio
from random import randint
from typing import Annotated
from agent_framework import ChatClientAgent
from agent_framework.azure import AzureAssistantsClient
from azure.identity import DefaultAzureCredential
from pydantic import Field
@@ -23,8 +23,7 @@ async def non_streaming_example() -> None:
# Since no assistant ID is provided, the assistant will be automatically created
# and deleted after getting a response
async with ChatClientAgent(
chat_client=AzureAssistantsClient(),
async with AzureAssistantsClient(ad_credential=DefaultAzureCredential()).create_agent(
instructions="You are a helpful weather agent.",
tools=get_weather,
) as agent:
@@ -40,8 +39,7 @@ async def streaming_example() -> None:
# Since no assistant ID is provided, the assistant will be automatically created
# and deleted after getting a response
async with ChatClientAgent(
chat_client=AzureAssistantsClient(),
async with AzureAssistantsClient(ad_credential=DefaultAzureCredential()).create_agent(
instructions="You are a helpful weather agent.",
tools=get_weather,
) as agent:
@@ -4,6 +4,7 @@ import asyncio
from agent_framework import AgentRunResponseUpdate, ChatClientAgent, ChatResponseUpdate, HostedCodeInterpreterTool
from agent_framework.azure import AzureAssistantsClient
from azure.identity import DefaultAzureCredential
from openai.types.beta.threads.runs import (
CodeInterpreterToolCallDelta,
RunStepDelta,
@@ -37,7 +38,7 @@ async def main() -> None:
print("=== Azure OpenAI Assistants Agent with Code Interpreter Example ===")
async with ChatClientAgent(
chat_client=AzureAssistantsClient(),
chat_client=AzureAssistantsClient(ad_credential=DefaultAzureCredential()),
instructions="You are a helpful assistant that can write and execute Python code to solve problems.",
tools=HostedCodeInterpreterTool(),
) as agent:
@@ -7,6 +7,7 @@ from typing import Annotated
from agent_framework import ChatClientAgent
from agent_framework.azure import AzureAssistantsClient
from azure.identity 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=AzureAssistantsClient(),
chat_client=AzureAssistantsClient(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=AzureAssistantsClient(),
chat_client=AzureAssistantsClient(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=AzureAssistantsClient(),
chat_client=AzureAssistantsClient(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.azure import AzureAssistantsClient
from azure.identity 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=AzureAssistantsClient(),
chat_client=AzureAssistantsClient(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=AzureAssistantsClient(),
chat_client=AzureAssistantsClient(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=AzureAssistantsClient(),
chat_client=AzureAssistantsClient(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=AzureAssistantsClient(thread_id=existing_thread_id),
chat_client=AzureAssistantsClient(thread_id=existing_thread_id, ad_credential=DefaultAzureCredential()),
instructions="You are a helpful weather agent.",
tools=get_weather,
) as agent: