Python: name changes executed (#607)

* name changes executed

* updated adr to accepted

* renamed openai base config

* renamed openai config to mixin

* added renames in user docs

* reverted mcperror

* fix tests

* remove sse from tests
This commit is contained in:
Eduard van Valkenburg
2025-09-04 17:00:38 +02:00
committed by GitHub
Unverified
parent 6310ca5be0
commit 40ab6e9d67
100 changed files with 1223 additions and 1100 deletions
@@ -6,7 +6,7 @@ This folder contains examples demonstrating different ways to create and use age
| File | Description |
|------|-------------|
| [`azure_assistants_basic.py`](azure_assistants_basic.py) | The simplest way to create an agent using `ChatClientAgent` with `AzureAssistantsClient`. Shows both streaming and non-streaming responses with automatic assistant creation and cleanup. |
| [`azure_assistants_basic.py`](azure_assistants_basic.py) | The simplest way to create an agent using `ChatAgent` with `AzureAssistantsClient`. Shows both streaming and non-streaming responses with automatic assistant creation and cleanup. |
| [`azure_assistants_with_existing_assistant.py`](azure_assistants_with_existing_assistant.py) | Shows how to work with a pre-existing assistant by providing the assistant ID to the Azure Assistants client. Demonstrates proper cleanup of manually created assistants. |
| [`azure_assistants_with_explicit_settings.py`](azure_assistants_with_explicit_settings.py) | Shows how to initialize an agent with a specific assistants client, configuring settings explicitly including endpoint and deployment name. |
| [`azure_assistants_with_function_tools.py`](azure_assistants_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). |
@@ -48,7 +48,7 @@ async def streaming_example() -> None:
query = "What's the weather like in Portland?"
print(f"User: {query}")
print("Agent: ", end="", flush=True)
async for chunk in agent.run_streaming(query):
async for chunk in agent.run_stream(query):
if chunk.text:
print(chunk.text, end="", flush=True)
print("\n")
@@ -2,7 +2,7 @@
import asyncio
from agent_framework import AgentRunResponseUpdate, ChatClientAgent, ChatResponseUpdate, HostedCodeInterpreterTool
from agent_framework import AgentRunResponseUpdate, ChatAgent, ChatResponseUpdate, HostedCodeInterpreterTool
from agent_framework.azure import AzureAssistantsClient
from azure.identity import AzureCliCredential
from openai.types.beta.threads.runs import (
@@ -39,7 +39,7 @@ async def main() -> None:
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
async with ChatClientAgent(
async with ChatAgent(
chat_client=AzureAssistantsClient(credential=AzureCliCredential()),
instructions="You are a helpful assistant that can write and execute Python code to solve problems.",
tools=HostedCodeInterpreterTool(),
@@ -48,7 +48,7 @@ async def main() -> None:
print(f"User: {query}")
print("Agent: ", end="", flush=True)
generated_code = ""
async for chunk in agent.run_streaming(query):
async for chunk in agent.run_stream(query):
if chunk.text:
print(chunk.text, end="", flush=True)
code_interpreter_chunk = get_code_interpreter_chunk(chunk)
@@ -5,7 +5,7 @@ import os
from random import randint
from typing import Annotated
from agent_framework import ChatClientAgent
from agent_framework import ChatAgent
from agent_framework.azure import AzureAssistantsClient
from azure.identity import AzureCliCredential, get_bearer_token_provider
from openai import AsyncAzureOpenAI
@@ -37,7 +37,7 @@ async def main() -> None:
)
try:
async with ChatClientAgent(
async with ChatAgent(
chat_client=AzureAssistantsClient(async_client=client, assistant_id=created_assistant.id),
instructions="You are a helpful weather agent.",
tools=get_weather,
@@ -5,7 +5,7 @@ from datetime import datetime, timezone
from random import randint
from typing import Annotated
from agent_framework import ChatClientAgent
from agent_framework import ChatAgent
from agent_framework.azure import AzureAssistantsClient
from azure.identity import AzureCliCredential
from pydantic import Field
@@ -33,7 +33,7 @@ async def tools_on_agent_level() -> None:
# The agent can use these tools for any query during its lifetime
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
async with ChatClientAgent(
async with ChatAgent(
chat_client=AzureAssistantsClient(credential=AzureCliCredential()),
instructions="You are a helpful assistant that can provide weather and time information.",
tools=[get_weather, get_time], # Tools defined at agent creation
@@ -64,7 +64,7 @@ async def tools_on_run_level() -> None:
# Agent created without tools
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
async with ChatClientAgent(
async with ChatAgent(
chat_client=AzureAssistantsClient(credential=AzureCliCredential()),
instructions="You are a helpful assistant.",
# No tools defined here
@@ -95,7 +95,7 @@ async def mixed_tools_example() -> None:
# Agent created with some base tools
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
async with ChatClientAgent(
async with ChatAgent(
chat_client=AzureAssistantsClient(credential=AzureCliCredential()),
instructions="You are a comprehensive assistant that can help with various information requests.",
tools=[get_weather], # Base tool available for all queries
@@ -4,7 +4,7 @@ import asyncio
from random import randint
from typing import Annotated
from agent_framework import AgentThread, ChatClientAgent
from agent_framework import AgentThread, ChatAgent
from agent_framework.azure import AzureAssistantsClient
from azure.identity import AzureCliCredential
from pydantic import Field
@@ -24,7 +24,7 @@ async def example_with_automatic_thread_creation() -> None:
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
async with ChatClientAgent(
async with ChatAgent(
chat_client=AzureAssistantsClient(credential=AzureCliCredential()),
instructions="You are a helpful weather agent.",
tools=get_weather,
@@ -50,7 +50,7 @@ async def example_with_thread_persistence() -> None:
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
async with ChatClientAgent(
async with ChatAgent(
chat_client=AzureAssistantsClient(credential=AzureCliCredential()),
instructions="You are a helpful weather agent.",
tools=get_weather,
@@ -88,7 +88,7 @@ async def example_with_existing_thread_id() -> None:
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
async with ChatClientAgent(
async with ChatAgent(
chat_client=AzureAssistantsClient(credential=AzureCliCredential()),
instructions="You are a helpful weather agent.",
tools=get_weather,
@@ -108,7 +108,7 @@ async def example_with_existing_thread_id() -> None:
print("\n--- Continuing with the same thread ID in a new agent instance ---")
# Create a new agent instance but use the existing thread ID
async with ChatClientAgent(
async with ChatAgent(
chat_client=AzureAssistantsClient(thread_id=existing_thread_id, credential=AzureCliCredential()),
instructions="You are a helpful weather agent.",
tools=get_weather,
@@ -6,7 +6,7 @@ This folder contains examples demonstrating different ways to create and use age
| File | Description |
|------|-------------|
| [`azure_chat_client_basic.py`](azure_chat_client_basic.py) | The simplest way to create an agent using `ChatClientAgent` with `AzureChatClient`. Shows both streaming and non-streaming responses for chat-based interactions with Azure OpenAI models. |
| [`azure_chat_client_basic.py`](azure_chat_client_basic.py) | The simplest way to create an agent using `ChatAgent` with `AzureChatClient`. Shows both streaming and non-streaming responses for chat-based interactions with Azure OpenAI models. |
| [`azure_chat_client_with_explicit_settings.py`](azure_chat_client_with_explicit_settings.py) | Shows how to initialize an agent with a specific chat client, configuring settings explicitly including endpoint and deployment name. |
| [`azure_chat_client_with_function_tools.py`](azure_chat_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_chat_client_with_thread.py`](azure_chat_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. |
@@ -50,7 +50,7 @@ async def streaming_example() -> None:
query = "What's the weather like in Portland?"
print(f"User: {query}")
print("Agent: ", end="", flush=True)
async for chunk in agent.run_streaming(query):
async for chunk in agent.run_stream(query):
if chunk.text:
print(chunk.text, end="", flush=True)
print("\n")
@@ -5,7 +5,7 @@ from datetime import datetime, timezone
from random import randint
from typing import Annotated
from agent_framework import ChatClientAgent
from agent_framework import ChatAgent
from agent_framework.azure import AzureChatClient
from azure.identity import AzureCliCredential
from pydantic import Field
@@ -33,7 +33,7 @@ async def tools_on_agent_level() -> None:
# The agent can use these tools for any query during its lifetime
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
agent = ChatClientAgent(
agent = ChatAgent(
chat_client=AzureChatClient(credential=AzureCliCredential()),
instructions="You are a helpful assistant that can provide weather and time information.",
tools=[get_weather, get_time], # Tools defined at agent creation
@@ -65,7 +65,7 @@ async def tools_on_run_level() -> None:
# Agent created without tools
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
agent = ChatClientAgent(
agent = ChatAgent(
chat_client=AzureChatClient(credential=AzureCliCredential()),
instructions="You are a helpful assistant.",
# No tools defined here
@@ -97,7 +97,7 @@ async def mixed_tools_example() -> None:
# Agent created with some base tools
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
agent = ChatClientAgent(
agent = ChatAgent(
chat_client=AzureChatClient(credential=AzureCliCredential()),
instructions="You are a comprehensive assistant that can help with various information requests.",
tools=[get_weather], # Base tool available for all queries
@@ -4,7 +4,7 @@ import asyncio
from random import randint
from typing import Annotated
from agent_framework import AgentThread, ChatClientAgent, ChatMessageList
from agent_framework import AgentThread, ChatAgent, ChatMessageList
from agent_framework.azure import AzureChatClient
from azure.identity import AzureCliCredential
from pydantic import Field
@@ -24,7 +24,7 @@ async def example_with_automatic_thread_creation() -> None:
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
agent = ChatClientAgent(
agent = ChatAgent(
chat_client=AzureChatClient(credential=AzureCliCredential()),
instructions="You are a helpful weather agent.",
tools=get_weather,
@@ -51,7 +51,7 @@ async def example_with_thread_persistence() -> None:
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
agent = ChatClientAgent(
agent = ChatAgent(
chat_client=AzureChatClient(credential=AzureCliCredential()),
instructions="You are a helpful weather agent.",
tools=get_weather,
@@ -86,7 +86,7 @@ async def example_with_existing_thread_messages() -> None:
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
agent = ChatClientAgent(
agent = ChatAgent(
chat_client=AzureChatClient(credential=AzureCliCredential()),
instructions="You are a helpful weather agent.",
tools=get_weather,
@@ -108,7 +108,7 @@ async def example_with_existing_thread_messages() -> None:
print("\n--- Continuing with the same thread in a new agent instance ---")
# Create a new agent instance but use the existing thread with its message history
new_agent = ChatClientAgent(
new_agent = ChatAgent(
chat_client=AzureChatClient(credential=AzureCliCredential()),
instructions="You are a helpful weather agent.",
tools=get_weather,
@@ -6,7 +6,7 @@ This folder contains examples demonstrating different ways to create and use age
| File | Description |
|------|-------------|
| [`azure_responses_client_basic.py`](azure_responses_client_basic.py) | The simplest way to create an agent using `ChatClientAgent` with `AzureResponsesClient`. Shows both streaming and non-streaming responses for structured response generation with Azure OpenAI models. |
| [`azure_responses_client_basic.py`](azure_responses_client_basic.py) | The simplest way to create an agent using `ChatAgent` with `AzureResponsesClient`. Shows both streaming and non-streaming responses for structured response generation with Azure OpenAI models. |
| [`azure_responses_client_with_explicit_settings.py`](azure_responses_client_with_explicit_settings.py) | Shows how to initialize an agent with a specific responses client, configuring settings explicitly including endpoint and deployment name. |
| [`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. |
@@ -48,7 +48,7 @@ async def streaming_example() -> None:
query = "What's the weather like in Portland?"
print(f"User: {query}")
print("Agent: ", end="", flush=True)
async for chunk in agent.run_streaming(query):
async for chunk in agent.run_stream(query):
if chunk.text:
print(chunk.text, end="", flush=True)
print("\n")
@@ -2,7 +2,7 @@
import asyncio
from agent_framework import ChatClientAgent, ChatResponse, HostedCodeInterpreterTool
from agent_framework import ChatAgent, ChatResponse, HostedCodeInterpreterTool
from agent_framework.azure import AzureResponsesClient
from azure.identity import AzureCliCredential
from openai.types.responses.response import Response as OpenAIResponse
@@ -15,7 +15,7 @@ async def main() -> None:
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
agent = ChatClientAgent(
agent = ChatAgent(
chat_client=AzureResponsesClient(credential=AzureCliCredential()),
instructions="You are a helpful assistant that can write and execute Python code to solve problems.",
tools=HostedCodeInterpreterTool(),
@@ -5,7 +5,7 @@ from datetime import datetime, timezone
from random import randint
from typing import Annotated
from agent_framework import ChatClientAgent
from agent_framework import ChatAgent
from agent_framework.azure import AzureResponsesClient
from azure.identity import AzureCliCredential
from pydantic import Field
@@ -33,7 +33,7 @@ async def tools_on_agent_level() -> None:
# The agent can use these tools for any query during its lifetime
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
agent = ChatClientAgent(
agent = ChatAgent(
chat_client=AzureResponsesClient(credential=AzureCliCredential()),
instructions="You are a helpful assistant that can provide weather and time information.",
tools=[get_weather, get_time], # Tools defined at agent creation
@@ -65,7 +65,7 @@ async def tools_on_run_level() -> None:
# Agent created without tools
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
agent = ChatClientAgent(
agent = ChatAgent(
chat_client=AzureResponsesClient(credential=AzureCliCredential()),
instructions="You are a helpful assistant.",
# No tools defined here
@@ -97,7 +97,7 @@ async def mixed_tools_example() -> None:
# Agent created with some base tools
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
agent = ChatClientAgent(
agent = ChatAgent(
chat_client=AzureResponsesClient(credential=AzureCliCredential()),
instructions="You are a comprehensive assistant that can help with various information requests.",
tools=[get_weather], # Base tool available for all queries
@@ -4,7 +4,7 @@ import asyncio
from random import randint
from typing import Annotated
from agent_framework import AgentThread, ChatClientAgent
from agent_framework import AgentThread, ChatAgent
from agent_framework.azure import AzureResponsesClient
from azure.identity import AzureCliCredential
from pydantic import Field
@@ -24,7 +24,7 @@ async def example_with_automatic_thread_creation() -> None:
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
agent = ChatClientAgent(
agent = ChatAgent(
chat_client=AzureResponsesClient(credential=AzureCliCredential()),
instructions="You are a helpful weather agent.",
tools=get_weather,
@@ -53,7 +53,7 @@ async def example_with_thread_persistence_in_memory() -> None:
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
agent = ChatClientAgent(
agent = ChatAgent(
chat_client=AzureResponsesClient(credential=AzureCliCredential()),
instructions="You are a helpful weather agent.",
tools=get_weather,
@@ -94,7 +94,7 @@ async def example_with_existing_thread_id() -> None:
# For authentication, run `az login` command in terminal or replace AzureCliCredential with preferred
# authentication option.
agent = ChatClientAgent(
agent = ChatAgent(
chat_client=AzureResponsesClient(credential=AzureCliCredential()),
instructions="You are a helpful weather agent.",
tools=get_weather,
@@ -116,7 +116,7 @@ async def example_with_existing_thread_id() -> None:
if existing_thread_id:
print("\n--- Continuing with the same thread ID in a new agent instance ---")
agent = ChatClientAgent(
agent = ChatAgent(
chat_client=AzureResponsesClient(credential=AzureCliCredential()),
instructions="You are a helpful weather agent.",
tools=get_weather,
@@ -6,7 +6,7 @@ This folder contains examples demonstrating different ways to create and use age
| File | Description |
|------|-------------|
| [`foundry_basic.py`](foundry_basic.py) | The simplest way to create an agent using `ChatClientAgent` with `FoundryChatClient`. It automatically handles all configuration using environment variables. |
| [`foundry_basic.py`](foundry_basic.py) | The simplest way to create an agent using `ChatAgent` with `FoundryChatClient`. It automatically handles all configuration using environment variables. |
| [`foundry_with_explicit_settings.py`](foundry_with_explicit_settings.py) | Shows how to create an agent with explicitly configured `FoundryChatClient` settings, including project endpoint, model deployment, credentials, and agent name. |
| [`foundry_with_existing_agent.py`](foundry_with_existing_agent.py) | Shows how to work with a pre-existing agent by providing the agent ID to the Foundry chat client. This example also demonstrates proper cleanup of manually created agents. |
| [`foundry_with_function_tools.py`](foundry_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). |
@@ -58,7 +58,7 @@ async def streaming_example() -> None:
query = "What's the weather like in Portland?"
print(f"User: {query}")
print("Agent: ", end="", flush=True)
async for chunk in agent.run_streaming(query):
async for chunk in agent.run_stream(query):
if chunk.text:
print(chunk.text, end="", flush=True)
print("\n")
@@ -2,7 +2,7 @@
import asyncio
from agent_framework import AgentRunResponseUpdate, ChatClientAgent, ChatResponseUpdate, HostedCodeInterpreterTool
from agent_framework import AgentRunResponseUpdate, ChatAgent, ChatResponseUpdate, HostedCodeInterpreterTool
from agent_framework.foundry import FoundryChatClient
from azure.ai.agents.models import (
RunStepDelta,
@@ -41,7 +41,7 @@ async def main() -> None:
# authentication option.
async with (
AzureCliCredential() as credential,
ChatClientAgent(
ChatAgent(
chat_client=FoundryChatClient(async_credential=credential),
instructions="You are a helpful assistant that can write and execute Python code to solve problems.",
tools=HostedCodeInterpreterTool(),
@@ -51,7 +51,7 @@ async def main() -> None:
print(f"User: {query}")
print("Agent: ", end="", flush=True)
generated_code = ""
async for chunk in agent.run_streaming(query):
async for chunk in agent.run_stream(query):
if chunk.text:
print(chunk.text, end="", flush=True)
code_interpreter_chunk = get_code_interpreter_chunk(chunk)
@@ -5,7 +5,7 @@ import os
from random import randint
from typing import Annotated
from agent_framework import ChatClientAgent
from agent_framework import ChatAgent
from agent_framework.foundry import FoundryChatClient
from azure.ai.projects.aio import AIProjectClient
from azure.identity.aio import AzureCliCredential
@@ -34,7 +34,7 @@ async def main() -> None:
)
try:
async with ChatClientAgent(
async with ChatAgent(
# passing in the client is optional here, so if you take the agent_id from the portal
# you can use it directly without the two lines above.
chat_client=FoundryChatClient(client=client, agent_id=created_agent.id),
@@ -5,7 +5,7 @@ import os
from random import randint
from typing import Annotated
from agent_framework import ChatClientAgent
from agent_framework import ChatAgent
from agent_framework.foundry import FoundryChatClient
from azure.identity.aio import AzureCliCredential
from pydantic import Field
@@ -28,7 +28,7 @@ async def main() -> None:
# authentication option.
async with (
AzureCliCredential() as credential,
ChatClientAgent(
ChatAgent(
chat_client=FoundryChatClient(
project_endpoint=os.environ["FOUNDRY_PROJECT_ENDPOINT"],
model_deployment_name=os.environ["FOUNDRY_MODEL_DEPLOYMENT_NAME"],
@@ -5,7 +5,7 @@ from datetime import datetime, timezone
from random import randint
from typing import Annotated
from agent_framework import ChatClientAgent
from agent_framework import ChatAgent
from agent_framework.foundry import FoundryChatClient
from azure.identity.aio import AzureCliCredential
from pydantic import Field
@@ -35,7 +35,7 @@ async def tools_on_agent_level() -> None:
# authentication option.
async with (
AzureCliCredential() as credential,
ChatClientAgent(
ChatAgent(
chat_client=FoundryChatClient(async_credential=credential),
instructions="You are a helpful assistant that can provide weather and time information.",
tools=[get_weather, get_time], # Tools defined at agent creation
@@ -69,7 +69,7 @@ async def tools_on_run_level() -> None:
# authentication option.
async with (
AzureCliCredential() as credential,
ChatClientAgent(
ChatAgent(
chat_client=FoundryChatClient(async_credential=credential),
instructions="You are a helpful assistant.",
# No tools defined here
@@ -103,7 +103,7 @@ async def mixed_tools_example() -> None:
# authentication option.
async with (
AzureCliCredential() as credential,
ChatClientAgent(
ChatAgent(
chat_client=FoundryChatClient(async_credential=credential),
instructions="You are a comprehensive assistant that can help with various information requests.",
tools=[get_weather], # Base tool available for all queries
@@ -4,7 +4,7 @@ import asyncio
from random import randint
from typing import Annotated
from agent_framework import AgentThread, ChatClientAgent
from agent_framework import AgentThread, ChatAgent
from agent_framework.foundry import FoundryChatClient
from azure.identity.aio import AzureCliCredential
from pydantic import Field
@@ -26,7 +26,7 @@ async def example_with_automatic_thread_creation() -> None:
# authentication option.
async with (
AzureCliCredential() as credential,
ChatClientAgent(
ChatAgent(
chat_client=FoundryChatClient(async_credential=credential),
instructions="You are a helpful weather agent.",
tools=get_weather,
@@ -55,7 +55,7 @@ async def example_with_thread_persistence() -> None:
# authentication option.
async with (
AzureCliCredential() as credential,
ChatClientAgent(
ChatAgent(
chat_client=FoundryChatClient(async_credential=credential),
instructions="You are a helpful weather agent.",
tools=get_weather,
@@ -96,7 +96,7 @@ async def example_with_existing_thread_id() -> None:
# authentication option.
async with (
AzureCliCredential() as credential,
ChatClientAgent(
ChatAgent(
chat_client=FoundryChatClient(async_credential=credential),
instructions="You are a helpful weather agent.",
tools=get_weather,
@@ -119,7 +119,7 @@ async def example_with_existing_thread_id() -> None:
# Create a new agent instance but use the existing thread ID
async with (
AzureCliCredential() as credential,
ChatClientAgent(
ChatAgent(
chat_client=FoundryChatClient(thread_id=existing_thread_id, async_credential=credential),
instructions="You are a helpful weather agent.",
tools=get_weather,
@@ -6,7 +6,7 @@ This folder contains examples demonstrating different ways to create and use age
| File | Description |
|------|-------------|
| [`openai_assistants_basic.py`](openai_assistants_basic.py) | The simplest way to create an agent using `ChatClientAgent` with `OpenAIAssistantsClient`. Shows both streaming and non-streaming responses with automatic assistant creation and cleanup. |
| [`openai_assistants_basic.py`](openai_assistants_basic.py) | The simplest way to create an agent using `ChatAgent` with `OpenAIAssistantsClient`. Shows both streaming and non-streaming responses with automatic assistant creation and cleanup. |
| [`openai_assistants_with_existing_assistant.py`](openai_assistants_with_existing_assistant.py) | Shows how to work with a pre-existing assistant by providing the assistant ID to the OpenAI Assistants client. Demonstrates proper cleanup of manually created assistants. |
| [`openai_assistants_with_explicit_settings.py`](openai_assistants_with_explicit_settings.py) | Shows how to initialize an agent with a specific assistants client, configuring settings explicitly including API key and model ID. |
| [`openai_assistants_with_function_tools.py`](openai_assistants_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). |
@@ -45,7 +45,7 @@ async def streaming_example() -> None:
query = "What's the weather like in Portland?"
print(f"User: {query}")
print("Agent: ", end="", flush=True)
async for chunk in agent.run_streaming(query):
async for chunk in agent.run_stream(query):
if chunk.text:
print(chunk.text, end="", flush=True)
print("\n")
@@ -2,7 +2,7 @@
import asyncio
from agent_framework import AgentRunResponseUpdate, ChatClientAgent, ChatResponseUpdate, HostedCodeInterpreterTool
from agent_framework import AgentRunResponseUpdate, ChatAgent, ChatResponseUpdate, HostedCodeInterpreterTool
from agent_framework.openai import OpenAIAssistantsClient
from openai.types.beta.threads.runs import (
CodeInterpreterToolCallDelta,
@@ -36,7 +36,7 @@ async def main() -> None:
"""Example showing how to use the HostedCodeInterpreterTool with OpenAI Assistants."""
print("=== OpenAI Assistants Agent with Code Interpreter Example ===")
async with ChatClientAgent(
async with ChatAgent(
chat_client=OpenAIAssistantsClient(),
instructions="You are a helpful assistant that can write and execute Python code to solve problems.",
tools=HostedCodeInterpreterTool(),
@@ -45,7 +45,7 @@ async def main() -> None:
print(f"User: {query}")
print("Agent: ", end="", flush=True)
generated_code = ""
async for chunk in agent.run_streaming(query):
async for chunk in agent.run_stream(query):
if chunk.text:
print(chunk.text, end="", flush=True)
code_interpreter_chunk = get_code_interpreter_chunk(chunk)
@@ -5,7 +5,7 @@ import os
from random import randint
from typing import Annotated
from agent_framework import ChatClientAgent
from agent_framework import ChatAgent
from agent_framework.openai import OpenAIAssistantsClient
from openai import AsyncOpenAI
from pydantic import Field
@@ -31,7 +31,7 @@ async def main() -> None:
)
try:
async with ChatClientAgent(
async with ChatAgent(
chat_client=OpenAIAssistantsClient(async_client=client, assistant_id=created_assistant.id),
instructions="You are a helpful weather agent.",
tools=get_weather,
@@ -2,7 +2,7 @@
import asyncio
from agent_framework import ChatClientAgent, HostedFileSearchTool, HostedVectorStoreContent
from agent_framework import ChatAgent, HostedFileSearchTool, HostedVectorStoreContent
from agent_framework.openai import OpenAIAssistantsClient
# Helper functions
@@ -33,7 +33,7 @@ async def delete_vector_store(client: OpenAIAssistantsClient, file_id: str, vect
async def main() -> None:
client = OpenAIAssistantsClient()
async with ChatClientAgent(
async with ChatAgent(
chat_client=client,
instructions="You are a helpful assistant that searches files in a knowledge base.",
tools=HostedFileSearchTool(),
@@ -43,7 +43,7 @@ async def main() -> None:
print(f"User: {query}")
print("Agent: ", end="", flush=True)
async for chunk in agent.run_streaming(
async for chunk in agent.run_stream(
query, tool_resources={"file_search": {"vector_store_ids": [vector_store.vector_store_id]}}
):
if chunk.text:
@@ -5,7 +5,7 @@ from datetime import datetime, timezone
from random import randint
from typing import Annotated
from agent_framework import ChatClientAgent
from agent_framework import ChatAgent
from agent_framework.openai import OpenAIAssistantsClient
from pydantic import Field
@@ -30,7 +30,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(
async with ChatAgent(
chat_client=OpenAIAssistantsClient(),
instructions="You are a helpful assistant that can provide weather and time information.",
tools=[get_weather, get_time], # Tools defined at agent creation
@@ -59,7 +59,7 @@ async def tools_on_run_level() -> None:
print("=== Tools Passed to Run Method ===")
# Agent created without tools
async with ChatClientAgent(
async with ChatAgent(
chat_client=OpenAIAssistantsClient(),
instructions="You are a helpful assistant.",
# No tools defined here
@@ -88,7 +88,7 @@ async def mixed_tools_example() -> None:
print("=== Mixed Tools Example (Agent + Run Method) ===")
# Agent created with some base tools
async with ChatClientAgent(
async with ChatAgent(
chat_client=OpenAIAssistantsClient(),
instructions="You are a comprehensive assistant that can help with various information requests.",
tools=[get_weather], # Base tool available for all queries
@@ -4,7 +4,7 @@ import asyncio
from random import randint
from typing import Annotated
from agent_framework import AgentThread, ChatClientAgent
from agent_framework import AgentThread, ChatAgent
from agent_framework.openai import OpenAIAssistantsClient
from pydantic import Field
@@ -21,7 +21,7 @@ async def example_with_automatic_thread_creation() -> None:
"""Example showing automatic thread creation (service-managed thread)."""
print("=== Automatic Thread Creation Example ===")
async with ChatClientAgent(
async with ChatAgent(
chat_client=OpenAIAssistantsClient(),
instructions="You are a helpful weather agent.",
tools=get_weather,
@@ -45,7 +45,7 @@ async def example_with_thread_persistence() -> None:
print("=== Thread Persistence Example ===")
print("Using the same thread across multiple conversations to maintain context.\n")
async with ChatClientAgent(
async with ChatAgent(
chat_client=OpenAIAssistantsClient(),
instructions="You are a helpful weather agent.",
tools=get_weather,
@@ -81,7 +81,7 @@ async def example_with_existing_thread_id() -> None:
# First, create a conversation and capture the thread ID
existing_thread_id = None
async with ChatClientAgent(
async with ChatAgent(
chat_client=OpenAIAssistantsClient(),
instructions="You are a helpful weather agent.",
tools=get_weather,
@@ -101,7 +101,7 @@ async def example_with_existing_thread_id() -> None:
print("\n--- Continuing with the same thread ID in a new agent instance ---")
# Create a new agent instance but use the existing thread ID
async with ChatClientAgent(
async with ChatAgent(
chat_client=OpenAIAssistantsClient(thread_id=existing_thread_id),
instructions="You are a helpful weather agent.",
tools=get_weather,
@@ -6,7 +6,7 @@ This folder contains examples demonstrating different ways to create and use age
| File | Description |
|------|-------------|
| [`openai_chat_client_basic.py`](openai_chat_client_basic.py) | The simplest way to create an agent using `ChatClientAgent` with `OpenAIChatClient`. Shows both streaming and non-streaming responses for chat-based interactions with OpenAI models. |
| [`openai_chat_client_basic.py`](openai_chat_client_basic.py) | The simplest way to create an agent using `ChatAgent` with `OpenAIChatClient`. Shows both streaming and non-streaming responses for chat-based interactions with OpenAI models. |
| [`openai_chat_client_with_explicit_settings.py`](openai_chat_client_with_explicit_settings.py) | Shows how to initialize an agent with a specific chat client, configuring settings explicitly including API key and model ID. |
| [`openai_chat_client_with_function_tools.py`](openai_chat_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). |
| [`openai_chat_client_with_local_mcp.py`](openai_chat_client_with_local_mcp.py) | Shows how to integrate OpenAI agents with local Model Context Protocol (MCP) servers for enhanced functionality and tool integration. |
@@ -44,7 +44,7 @@ async def streaming_example() -> None:
query = "What's the weather like in Portland?"
print(f"User: {query}")
print("Agent: ", end="", flush=True)
async for chunk in agent.run_streaming(query):
async for chunk in agent.run_stream(query):
if chunk.text:
print(chunk.text, end="", flush=True)
print("\n")
@@ -5,7 +5,7 @@ from datetime import datetime, timezone
from random import randint
from typing import Annotated
from agent_framework import ChatClientAgent
from agent_framework import ChatAgent
from agent_framework.openai import OpenAIChatClient
from pydantic import Field
@@ -30,7 +30,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(
agent = ChatAgent(
chat_client=OpenAIChatClient(),
instructions="You are a helpful assistant that can provide weather and time information.",
tools=[get_weather, get_time], # Tools defined at agent creation
@@ -60,7 +60,7 @@ async def tools_on_run_level() -> None:
print("=== Tools Passed to Run Method ===")
# Agent created without tools
agent = ChatClientAgent(
agent = ChatAgent(
chat_client=OpenAIChatClient(),
instructions="You are a helpful assistant.",
# No tools defined here
@@ -90,7 +90,7 @@ async def mixed_tools_example() -> None:
print("=== Mixed Tools Example (Agent + Run Method) ===")
# Agent created with some base tools
agent = ChatClientAgent(
agent = ChatAgent(
chat_client=OpenAIChatClient(),
instructions="You are a comprehensive assistant that can help with various information requests.",
tools=[get_weather], # Base tool available for all queries
@@ -2,7 +2,7 @@
import asyncio
from agent_framework import ChatClientAgent, McpStreamableHttpTool
from agent_framework import ChatAgent, MCPStreamableHTTPTool
from agent_framework.openai import OpenAIChatClient
@@ -14,11 +14,11 @@ async def mcp_tools_on_run_level() -> None:
# This means we have to ensure we connect to the MCP server before running the agent
# and pass the tools to the run method.
async with (
McpStreamableHttpTool(
MCPStreamableHTTPTool(
name="Microsoft Learn MCP",
url="https://learn.microsoft.com/api/mcp",
) as mcp_server,
ChatClientAgent(
ChatAgent(
chat_client=OpenAIChatClient(),
name="DocsAgent",
instructions="You are a helpful assistant that can help with microsoft documentation questions.",
@@ -47,7 +47,7 @@ async def mcp_tools_on_agent_level() -> None:
async with OpenAIChatClient().create_agent(
name="DocsAgent",
instructions="You are a helpful assistant that can help with microsoft documentation questions.",
tools=McpStreamableHttpTool( # Tools defined at agent creation
tools=MCPStreamableHTTPTool( # Tools defined at agent creation
name="Microsoft Learn MCP",
url="https://learn.microsoft.com/api/mcp",
),
@@ -4,7 +4,7 @@ import asyncio
from random import randint
from typing import Annotated
from agent_framework import AgentThread, ChatClientAgent, ChatMessageList
from agent_framework import AgentThread, ChatAgent, ChatMessageList
from agent_framework.openai import OpenAIChatClient
from pydantic import Field
@@ -21,7 +21,7 @@ async def example_with_automatic_thread_creation() -> None:
"""Example showing automatic thread creation (service-managed thread)."""
print("=== Automatic Thread Creation Example ===")
agent = ChatClientAgent(
agent = ChatAgent(
chat_client=OpenAIChatClient(),
instructions="You are a helpful weather agent.",
tools=get_weather,
@@ -46,7 +46,7 @@ async def example_with_thread_persistence() -> None:
print("=== Thread Persistence Example ===")
print("Using the same thread across multiple conversations to maintain context.\n")
agent = ChatClientAgent(
agent = ChatAgent(
chat_client=OpenAIChatClient(),
instructions="You are a helpful weather agent.",
tools=get_weather,
@@ -79,7 +79,7 @@ async def example_with_existing_thread_messages() -> None:
"""Example showing how to work with existing thread messages for OpenAI."""
print("=== Existing Thread Messages Example ===")
agent = ChatClientAgent(
agent = ChatAgent(
chat_client=OpenAIChatClient(),
instructions="You are a helpful weather agent.",
tools=get_weather,
@@ -101,7 +101,7 @@ async def example_with_existing_thread_messages() -> None:
print("\n--- Continuing with the same thread in a new agent instance ---")
# Create a new agent instance but use the existing thread with its message history
new_agent = ChatClientAgent(
new_agent = ChatAgent(
chat_client=OpenAIChatClient(),
instructions="You are a helpful weather agent.",
tools=get_weather,
@@ -6,7 +6,7 @@ This folder contains examples demonstrating different ways to create and use age
| File | Description |
|------|-------------|
| [`openai_responses_client_basic.py`](openai_responses_client_basic.py) | The simplest way to create an agent using `ChatClientAgent` with `OpenAIResponsesClient`. Shows both streaming and non-streaming responses for structured response generation with OpenAI models. |
| [`openai_responses_client_basic.py`](openai_responses_client_basic.py) | The simplest way to create an agent using `ChatAgent` with `OpenAIResponsesClient`. Shows both streaming and non-streaming responses for structured response generation with OpenAI models. |
| [`openai_responses_client_reasoning.py`](openai_responses_client_reasoning.py) | Demonstrates how to use reasoning capabilities with OpenAI agents, showing how the agent can provide detailed reasoning for its responses. |
| [`openai_responses_client_with_explicit_settings.py`](openai_responses_client_with_explicit_settings.py) | Shows how to initialize an agent with a specific responses client, configuring settings explicitly including API key and model ID. |
| [`openai_responses_client_with_function_tools.py`](openai_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). |
@@ -4,7 +4,7 @@ import asyncio
from random import randint
from typing import Annotated
from agent_framework import ChatClientAgent
from agent_framework import ChatAgent
from agent_framework.openai import OpenAIResponsesClient
from pydantic import Field
@@ -21,7 +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(
agent = ChatAgent(
chat_client=OpenAIResponsesClient(),
instructions="You are a helpful weather agent.",
tools=get_weather,
@@ -37,7 +37,7 @@ async def streaming_example() -> None:
"""Example of streaming response (get results as they are generated)."""
print("=== Streaming Response Example ===")
agent = ChatClientAgent(
agent = ChatAgent(
chat_client=OpenAIResponsesClient(),
instructions="You are a helpful weather agent.",
tools=get_weather,
@@ -46,7 +46,7 @@ async def streaming_example() -> None:
query = "What's the weather like in Portland?"
print(f"User: {query}")
print("Agent: ", end="", flush=True)
async for chunk in agent.run_streaming(query):
async for chunk in agent.run_stream(query):
if chunk.text:
print(chunk.text, end="", flush=True)
print("\n")
@@ -22,7 +22,7 @@ async def reasoning_example() -> None:
print(f"User: {query}")
print(f"{agent.name}: ", end="", flush=True)
usage = None
async for chunk in agent.run_streaming(query):
async for chunk in agent.run_stream(query):
if chunk.contents:
for content in chunk.contents:
if isinstance(content, TextReasoningContent):
@@ -2,7 +2,7 @@
import asyncio
from agent_framework import ChatClientAgent, ChatResponse, HostedCodeInterpreterTool
from agent_framework import ChatAgent, ChatResponse, HostedCodeInterpreterTool
from agent_framework.openai import OpenAIResponsesClient
from openai.types.responses.response import Response as OpenAIResponse
from openai.types.responses.response_code_interpreter_tool_call import ResponseCodeInterpreterToolCall
@@ -12,7 +12,7 @@ async def main() -> None:
"""Example showing how to use the HostedCodeInterpreterTool with OpenAI Responses."""
print("=== OpenAI Responses Agent with Code Interpreter Example ===")
agent = ChatClientAgent(
agent = ChatAgent(
chat_client=OpenAIResponsesClient(),
instructions="You are a helpful assistant that can write and execute Python code to solve problems.",
tools=HostedCodeInterpreterTool(),
@@ -5,7 +5,7 @@ from datetime import datetime, timezone
from random import randint
from typing import Annotated
from agent_framework import ChatClientAgent
from agent_framework import ChatAgent
from agent_framework.openai import OpenAIResponsesClient
from pydantic import Field
@@ -30,7 +30,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(
agent = ChatAgent(
chat_client=OpenAIResponsesClient(),
instructions="You are a helpful assistant that can provide weather and time information.",
tools=[get_weather, get_time], # Tools defined at agent creation
@@ -60,7 +60,7 @@ async def tools_on_run_level() -> None:
print("=== Tools Passed to Run Method ===")
# Agent created without tools
agent = ChatClientAgent(
agent = ChatAgent(
chat_client=OpenAIResponsesClient(),
instructions="You are a helpful assistant.",
# No tools defined here
@@ -90,7 +90,7 @@ async def mixed_tools_example() -> None:
print("=== Mixed Tools Example (Agent + Run Method) ===")
# Agent created with some base tools
agent = ChatClientAgent(
agent = ChatAgent(
chat_client=OpenAIResponsesClient(),
instructions="You are a comprehensive assistant that can help with various information requests.",
tools=[get_weather], # Base tool available for all queries
@@ -2,7 +2,7 @@
import asyncio
from agent_framework import ChatClientAgent, McpStreamableHttpTool
from agent_framework import ChatAgent, MCPStreamableHTTPTool
from agent_framework.openai import OpenAIResponsesClient
@@ -16,11 +16,11 @@ async def streaming_with_mcp(show_raw_stream: bool = False) -> None:
# Tools are provided when creating the agent
# The agent can use these tools for any query during its lifetime
async with ChatClientAgent(
async with ChatAgent(
chat_client=OpenAIResponsesClient(),
name="DocsAgent",
instructions="You are a helpful assistant that can help with microsoft documentation questions.",
tools=McpStreamableHttpTool( # Tools defined at agent creation
tools=MCPStreamableHTTPTool( # Tools defined at agent creation
name="Microsoft Learn MCP",
url="https://learn.microsoft.com/api/mcp",
),
@@ -29,7 +29,7 @@ async def streaming_with_mcp(show_raw_stream: bool = False) -> None:
query1 = "How to create an Azure storage account using az cli?"
print(f"User: {query1}")
print(f"{agent.name}: ", end="")
async for chunk in agent.run_streaming(query1):
async for chunk in agent.run_stream(query1):
if show_raw_stream:
print("Streamed event: ", chunk.raw_representation.raw_representation) # type:ignore
elif chunk.text:
@@ -40,7 +40,7 @@ async def streaming_with_mcp(show_raw_stream: bool = False) -> None:
query2 = "What is Microsoft Semantic Kernel?"
print(f"User: {query2}")
print(f"{agent.name}: ", end="")
async for chunk in agent.run_streaming(query2):
async for chunk in agent.run_stream(query2):
if show_raw_stream:
print("Streamed event: ", chunk.raw_representation.raw_representation) # type:ignore
elif chunk.text:
@@ -54,11 +54,11 @@ async def run_with_mcp() -> None:
# Tools are provided when creating the agent
# The agent can use these tools for any query during its lifetime
async with ChatClientAgent(
async with ChatAgent(
chat_client=OpenAIResponsesClient(),
name="DocsAgent",
instructions="You are a helpful assistant that can help with microsoft documentation questions.",
tools=McpStreamableHttpTool( # Tools defined at agent creation
tools=MCPStreamableHTTPTool( # Tools defined at agent creation
name="Microsoft Learn MCP",
url="https://learn.microsoft.com/api/mcp",
),
@@ -4,7 +4,7 @@ import asyncio
from random import randint
from typing import Annotated
from agent_framework import AgentThread, ChatClientAgent
from agent_framework import AgentThread, ChatAgent
from agent_framework.openai import OpenAIResponsesClient
from pydantic import Field
@@ -21,7 +21,7 @@ async def example_with_automatic_thread_creation() -> None:
"""Example showing automatic thread creation."""
print("=== Automatic Thread Creation Example ===")
agent = ChatClientAgent(
agent = ChatAgent(
chat_client=OpenAIResponsesClient(),
instructions="You are a helpful weather agent.",
tools=get_weather,
@@ -48,7 +48,7 @@ async def example_with_thread_persistence_in_memory() -> None:
"""
print("=== Thread Persistence Example (In-Memory) ===")
agent = ChatClientAgent(
agent = ChatAgent(
chat_client=OpenAIResponsesClient(),
instructions="You are a helpful weather agent.",
tools=get_weather,
@@ -87,7 +87,7 @@ async def example_with_existing_thread_id() -> None:
# First, create a conversation and capture the thread ID
existing_thread_id = None
agent = ChatClientAgent(
agent = ChatAgent(
chat_client=OpenAIResponsesClient(),
instructions="You are a helpful weather agent.",
tools=get_weather,
@@ -109,7 +109,7 @@ async def example_with_existing_thread_id() -> None:
if existing_thread_id:
print("\n--- Continuing with the same thread ID in a new agent instance ---")
agent = ChatClientAgent(
agent = ChatAgent(
chat_client=OpenAIResponsesClient(),
instructions="You are a helpful weather agent.",
tools=get_weather,