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 AzureResponsesClient
from azure.identity import DefaultAzureCredential
from pydantic import Field
@@ -21,8 +21,7 @@ async def non_streaming_example() -> None:
"""Example of non-streaming response (get the complete result at once)."""
print("=== Non-streaming Response Example ===")
agent = ChatClientAgent(
chat_client=AzureResponsesClient(),
agent = AzureResponsesClient(ad_credential=DefaultAzureCredential()).create_agent(
instructions="You are a helpful weather agent.",
tools=get_weather,
)
@@ -37,8 +36,7 @@ async def streaming_example() -> None:
"""Example of streaming response (get results as they are generated)."""
print("=== Streaming Response Example ===")
agent = ChatClientAgent(
chat_client=AzureResponsesClient(),
agent = AzureResponsesClient(ad_credential=DefaultAzureCredential()).create_agent(
instructions="You are a helpful weather agent.",
tools=get_weather,
)
@@ -4,6 +4,7 @@ import asyncio
from agent_framework import ChatClientAgent, ChatResponse, HostedCodeInterpreterTool
from agent_framework.azure import AzureResponsesClient
from azure.identity import DefaultAzureCredential
from openai.types.responses.response import Response as OpenAIResponse
from openai.types.responses.response_code_interpreter_tool_call import ResponseCodeInterpreterToolCall
@@ -13,7 +14,7 @@ async def main() -> None:
print("=== Azure OpenAI Responses Agent with Code Interpreter Example ===")
agent = ChatClientAgent(
chat_client=AzureResponsesClient(),
chat_client=AzureResponsesClient(ad_credential=DefaultAzureCredential()),
instructions="You are a helpful assistant that can write and execute Python code to solve problems.",
tools=HostedCodeInterpreterTool(),
)
@@ -7,6 +7,7 @@ from typing import Annotated
from agent_framework import ChatClientAgent
from agent_framework.azure import AzureResponsesClient
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
agent = ChatClientAgent(
chat_client=AzureResponsesClient(),
chat_client=AzureResponsesClient(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
)
@@ -61,7 +62,7 @@ async def tools_on_run_level() -> None:
# Agent created without tools
agent = ChatClientAgent(
chat_client=AzureResponsesClient(),
chat_client=AzureResponsesClient(ad_credential=DefaultAzureCredential()),
instructions="You are a helpful assistant.",
# No tools defined here
)
@@ -91,7 +92,7 @@ async def mixed_tools_example() -> None:
# Agent created with some base tools
agent = ChatClientAgent(
chat_client=AzureResponsesClient(),
chat_client=AzureResponsesClient(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
)
@@ -6,6 +6,7 @@ from typing import Annotated
from agent_framework import ChatClientAgent, ChatClientAgentThread
from agent_framework.azure import AzureResponsesClient
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 ===")
agent = ChatClientAgent(
chat_client=AzureResponsesClient(),
chat_client=AzureResponsesClient(ad_credential=DefaultAzureCredential()),
instructions="You are a helpful weather agent.",
tools=get_weather,
)
@@ -49,7 +50,7 @@ async def example_with_thread_persistence_in_memory() -> None:
print("=== Thread Persistence Example (In-Memory) ===")
agent = ChatClientAgent(
chat_client=AzureResponsesClient(),
chat_client=AzureResponsesClient(ad_credential=DefaultAzureCredential()),
instructions="You are a helpful weather agent.",
tools=get_weather,
)
@@ -92,7 +93,7 @@ async def example_with_existing_thread_id() -> None:
existing_thread_id = None
agent = ChatClientAgent(
chat_client=AzureResponsesClient(),
chat_client=AzureResponsesClient(ad_credential=DefaultAzureCredential()),
instructions="You are a helpful weather agent.",
tools=get_weather,
)
@@ -116,7 +117,7 @@ async def example_with_existing_thread_id() -> None:
print("\n--- Continuing with the same thread ID in a new agent instance ---")
agent = ChatClientAgent(
chat_client=AzureResponsesClient(),
chat_client=AzureResponsesClient(ad_credential=DefaultAzureCredential()),
instructions="You are a helpful weather agent.",
tools=get_weather,
)