Agents + Chat Client Samples Doctsring Updates (#1028)

* agents + chat client samples doctsring updates

* fixes
This commit is contained in:
Giles Odigwe
2025-10-01 00:18:53 -07:00
committed by GitHub
Unverified
parent 3d04517877
commit b88143b686
68 changed files with 511 additions and 45 deletions
@@ -21,6 +21,7 @@ This folder contains examples demonstrating different ways to create and use age
| [`azure_responses_client_with_function_tools.py`](azure_responses_client_with_function_tools.py) | Demonstrates how to use function tools with agents. Shows both agent-level tools (defined when creating the agent) and query-level tools (provided with specific queries). |
| [`azure_responses_client_with_code_interpreter.py`](azure_responses_client_with_code_interpreter.py) | Shows how to use the HostedCodeInterpreterTool with Azure agents to write and execute Python code. Includes helper methods for accessing code interpreter data from response chunks. |
| [`azure_responses_client_with_thread.py`](azure_responses_client_with_thread.py) | Demonstrates thread management with Azure agents, including automatic thread creation for stateless conversations and explicit thread management for maintaining conversation context across multiple interactions. |
| [`azure_responses_client_image_analysis.py`](azure_responses_client_image_analysis.py) | Shows how to use Azure OpenAI Responses for image analysis and vision tasks. Demonstrates multi-modal messages combining text and image content using remote URLs. |
## Environment Variables
@@ -8,6 +8,13 @@ from agent_framework.azure import AzureOpenAIAssistantsClient
from azure.identity import AzureCliCredential
from pydantic import Field
"""
Azure OpenAI Assistants Basic Example
This sample demonstrates basic usage of AzureOpenAIAssistantsClient with automatic
assistant lifecycle management, showing both streaming and non-streaming responses.
"""
def get_weather(
location: Annotated[str, Field(description="The location to get the weather for.")],
@@ -13,6 +13,13 @@ from openai.types.beta.threads.runs import (
)
from openai.types.beta.threads.runs.code_interpreter_tool_call_delta import CodeInterpreter
"""
Azure OpenAI Assistants with Code Interpreter Example
This sample demonstrates using HostedCodeInterpreterTool with Azure OpenAI Assistants
for Python code execution and mathematical problem solving.
"""
def get_code_interpreter_chunk(chunk: AgentRunResponseUpdate) -> str | None:
"""Helper method to access code interpreter data."""
@@ -11,6 +11,13 @@ from azure.identity import AzureCliCredential, get_bearer_token_provider
from openai import AsyncAzureOpenAI
from pydantic import Field
"""
Azure OpenAI Assistants with Existing Assistant Example
This sample demonstrates working with pre-existing Azure OpenAI Assistants
using existing assistant IDs rather than creating new ones.
"""
def get_weather(
location: Annotated[str, Field(description="The location to get the weather for.")],
@@ -9,6 +9,13 @@ from agent_framework.azure import AzureOpenAIAssistantsClient
from azure.identity import AzureCliCredential
from pydantic import Field
"""
Azure OpenAI Assistants with Explicit Settings Example
This sample demonstrates creating Azure OpenAI Assistants with explicit configuration
settings rather than relying on environment variable defaults.
"""
def get_weather(
location: Annotated[str, Field(description="The location to get the weather for.")],
@@ -10,6 +10,13 @@ from agent_framework.azure import AzureOpenAIAssistantsClient
from azure.identity import AzureCliCredential
from pydantic import Field
"""
Azure OpenAI Assistants with Function Tools Example
This sample demonstrates function tool integration with Azure OpenAI Assistants,
showing both agent-level and query-level tool configuration patterns.
"""
def get_weather(
location: Annotated[str, Field(description="The location to get the weather for.")],
@@ -9,6 +9,13 @@ from agent_framework.azure import AzureOpenAIAssistantsClient
from azure.identity import AzureCliCredential
from pydantic import Field
"""
Azure OpenAI Assistants with Thread Management Example
This sample demonstrates thread management with Azure OpenAI Assistants, comparing
automatic thread creation with explicit thread management for persistent context.
"""
def get_weather(
location: Annotated[str, Field(description="The location to get the weather for.")],
@@ -8,6 +8,13 @@ from agent_framework.azure import AzureOpenAIChatClient
from azure.identity import AzureCliCredential
from pydantic import Field
"""
Azure OpenAI Chat Client Basic Example
This sample demonstrates basic usage of AzureOpenAIChatClient for direct chat-based
interactions, showing both streaming and non-streaming responses.
"""
def get_weather(
location: Annotated[str, Field(description="The location to get the weather for.")],
@@ -9,6 +9,13 @@ from agent_framework.azure import AzureOpenAIChatClient
from azure.identity import AzureCliCredential
from pydantic import Field
"""
Azure OpenAI Chat Client with Explicit Settings Example
This sample demonstrates creating Azure OpenAI Chat Client with explicit configuration
settings rather than relying on environment variable defaults.
"""
def get_weather(
location: Annotated[str, Field(description="The location to get the weather for.")],
@@ -10,6 +10,13 @@ from agent_framework.azure import AzureOpenAIChatClient
from azure.identity import AzureCliCredential
from pydantic import Field
"""
Azure OpenAI Chat Client with Function Tools Example
This sample demonstrates function tool integration with Azure OpenAI Chat Client,
showing both agent-level and query-level tool configuration patterns.
"""
def get_weather(
location: Annotated[str, Field(description="The location to get the weather for.")],
@@ -9,6 +9,13 @@ from agent_framework.azure import AzureOpenAIChatClient
from azure.identity import AzureCliCredential
from pydantic import Field
"""
Azure OpenAI Chat Client with Thread Management Example
This sample demonstrates thread management with Azure OpenAI Chat Client, comparing
automatic thread creation with explicit thread management for persistent context.
"""
def get_weather(
location: Annotated[str, Field(description="The location to get the weather for.")],
@@ -8,6 +8,13 @@ from agent_framework.azure import AzureOpenAIResponsesClient
from azure.identity import AzureCliCredential
from pydantic import Field
"""
Azure OpenAI Responses Client Basic Example
This sample demonstrates basic usage of AzureOpenAIResponsesClient for structured
response generation, showing both streaming and non-streaming responses.
"""
def get_weather(
location: Annotated[str, Field(description="The location to get the weather for.")],
@@ -0,0 +1,46 @@
# Copyright (c) Microsoft. All rights reserved.
import asyncio
from agent_framework import ChatMessage, TextContent, UriContent
from agent_framework.azure import AzureOpenAIResponsesClient
from azure.identity import AzureCliCredential
"""
Azure OpenAI Responses Client with Image Analysis Example
This sample demonstrates using Azure OpenAI Responses for image analysis and vision tasks,
showing multi-modal messages combining text and image content.
"""
async def main():
print("=== Azure Responses Agent with Image Analysis ===")
# 1. Create an Azure Responses agent with vision capabilities
agent = AzureOpenAIResponsesClient(credential=AzureCliCredential()).create_agent(
name="VisionAgent",
instructions="You are a helpful agent that can analyze images.",
)
# 2. Create a simple message with both text and image content
user_message = ChatMessage(
role="user",
contents=[
TextContent(text="What do you see in this image?"),
UriContent(
uri="https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg",
media_type="image/jpeg",
),
],
)
# 3. Get the agent's response
print("User: What do you see in this image? [Image provided]")
result = await agent.run(user_message)
print(f"Agent: {result.text}")
print()
if __name__ == "__main__":
asyncio.run(main())
@@ -8,6 +8,13 @@ from azure.identity import AzureCliCredential
from openai.types.responses.response import Response as OpenAIResponse
from openai.types.responses.response_code_interpreter_tool_call import ResponseCodeInterpreterToolCall
"""
Azure OpenAI Responses Client with Code Interpreter Example
This sample demonstrates using HostedCodeInterpreterTool with Azure OpenAI Responses
for Python code execution and mathematical problem solving.
"""
async def main() -> None:
"""Example showing how to use the HostedCodeInterpreterTool with Azure OpenAI Responses."""
@@ -9,6 +9,13 @@ from agent_framework.azure import AzureOpenAIResponsesClient
from azure.identity import AzureCliCredential
from pydantic import Field
"""
Azure OpenAI Responses Client with Explicit Settings Example
This sample demonstrates creating Azure OpenAI Responses Client with explicit configuration
settings rather than relying on environment variable defaults.
"""
def get_weather(
location: Annotated[str, Field(description="The location to get the weather for.")],
@@ -10,6 +10,13 @@ from agent_framework.azure import AzureOpenAIResponsesClient
from azure.identity import AzureCliCredential
from pydantic import Field
"""
Azure OpenAI Responses Client with Function Tools Example
This sample demonstrates function tool integration with Azure OpenAI Responses Client,
showing both agent-level and query-level tool configuration patterns.
"""
def get_weather(
location: Annotated[str, Field(description="The location to get the weather for.")],
@@ -9,6 +9,13 @@ from agent_framework.azure import AzureOpenAIResponsesClient
from azure.identity import AzureCliCredential
from pydantic import Field
"""
Azure OpenAI Responses Client with Thread Management Example
This sample demonstrates thread management with Azure OpenAI Responses Client, comparing
automatic thread creation with explicit thread management for persistent context.
"""
def get_weather(
location: Annotated[str, Field(description="The location to get the weather for.")],