mirror of
https://github.com/microsoft/agent-framework.git
synced 2026-06-16 21:04:09 +08:00
Python: [BREAKING] Remove deprecated Python OpenAI/Azure AI surfaces (#4990)
* [BREAKING] Remove deprecated Python OpenAI/Azure AI surfaces Also clean up follow-on docs, environment guidance, package metadata, and lab test stability. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Fix deleted semantic-kernel sample links Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * Address PR review feedback Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> * improve foundry language * Fix A2A Foundry sample regression Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
Unverified
parent
a5eacbbe65
commit
3a49b1d6dd
@@ -14,9 +14,9 @@ This gallery helps Semantic Kernel (SK) developers move to the Microsoft Agent F
|
||||
### Azure AI agent parity
|
||||
|
||||
### OpenAI Assistants API parity
|
||||
- [01_basic_openai_assistant.py](openai_assistant/01_basic_openai_assistant.py) — Baseline assistant comparison.
|
||||
- [02_openai_assistant_with_code_interpreter.py](openai_assistant/02_openai_assistant_with_code_interpreter.py) — Code interpreter tool usage.
|
||||
- [03_openai_assistant_function_tool.py](openai_assistant/03_openai_assistant_function_tool.py) — Custom function tooling.
|
||||
|
||||
OpenAI Assistants parity samples were removed alongside the deprecated Python assistants surface and are no longer
|
||||
part of this migration gallery.
|
||||
|
||||
### OpenAI Responses API parity
|
||||
- [01_basic_responses_agent.py](openai_responses/01_basic_responses_agent.py) — Basic responses agent migration.
|
||||
@@ -44,7 +44,7 @@ Each script is fully async and the `main()` routine runs both implementations ba
|
||||
- Python 3.10 or later.
|
||||
- Access to the necessary model endpoints (Azure OpenAI, OpenAI, Azure AI, Copilot Studio, etc.).
|
||||
- Installed SDKs: `semantic-kernel` and the Microsoft Agent Framework (`pip install semantic-kernel agent-framework`), or the repo’s editable packages if you are developing locally.
|
||||
- Service credentials exposed through environment variables (for example `OPENAI_API_KEY`, `AZURE_OPENAI_ENDPOINT`, `AZURE_OPENAI_KEY`, or Copilot Studio auth settings).
|
||||
- Service credentials exposed through environment variables (for example `OPENAI_API_KEY`, `AZURE_OPENAI_ENDPOINT`, `AZURE_OPENAI_API_KEY`, or Copilot Studio auth settings).
|
||||
|
||||
## Running Single-Agent Samples
|
||||
From the repository root:
|
||||
|
||||
-64
@@ -1,64 +0,0 @@
|
||||
# /// script
|
||||
# requires-python = ">=3.10"
|
||||
# dependencies = [
|
||||
# "semantic-kernel",
|
||||
# ]
|
||||
# ///
|
||||
# Run with any PEP 723 compatible runner, e.g.:
|
||||
# uv run samples/semantic-kernel-migration/openai_assistant/01_basic_openai_assistant.py
|
||||
|
||||
# Copyright (c) Microsoft. All rights reserved.
|
||||
"""Create an OpenAI Assistant using SK and Agent Framework."""
|
||||
import asyncio
|
||||
import os
|
||||
|
||||
from agent_framework import Agent
|
||||
from dotenv import load_dotenv
|
||||
|
||||
# Load environment variables from .env file
|
||||
load_dotenv()
|
||||
ASSISTANT_MODEL = os.environ.get("OPENAI_ASSISTANT_MODEL", "gpt-4o-mini")
|
||||
|
||||
|
||||
async def run_semantic_kernel() -> None:
|
||||
from semantic_kernel.agents import AssistantAgentThread, OpenAIAssistantAgent
|
||||
client = OpenAIAssistantAgent.create_client()
|
||||
# Provision the assistant on the OpenAI Assistants service.
|
||||
definition = await client.beta.assistants.create(
|
||||
model=ASSISTANT_MODEL,
|
||||
name="Helper",
|
||||
instructions="Answer questions in one concise paragraph.",
|
||||
)
|
||||
agent = OpenAIAssistantAgent(client=client, definition=definition)
|
||||
thread: AssistantAgentThread | None = None
|
||||
response = await agent.get_response("What is the capital of Denmark?", thread=thread)
|
||||
thread = response.thread
|
||||
print("[SK]", response.message.content)
|
||||
if thread is not None:
|
||||
print("[SK][thread-id]", thread.id)
|
||||
|
||||
|
||||
async def run_agent_framework() -> None:
|
||||
from agent_framework.openai import OpenAIAssistantsClient
|
||||
assistants_client = OpenAIAssistantsClient()
|
||||
# AF wraps the assistant lifecycle with an async context manager.
|
||||
async with Agent(
|
||||
client=assistants_client,
|
||||
) as assistant_agent:
|
||||
session = assistant_agent.create_session()
|
||||
reply = await assistant_agent.run("What is the capital of Denmark?", session=session)
|
||||
print("[AF]", reply.text)
|
||||
follow_up = await assistant_agent.run(
|
||||
"How many residents live there?",
|
||||
session=session,
|
||||
)
|
||||
print("[AF][follow-up]", follow_up.text)
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
await run_semantic_kernel()
|
||||
await run_agent_framework()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
-74
@@ -1,74 +0,0 @@
|
||||
# /// script
|
||||
|
||||
# requires-python = ">=3.10"
|
||||
# dependencies = [
|
||||
# "semantic-kernel",
|
||||
# ]
|
||||
# ///
|
||||
# Run with any PEP 723 compatible runner, e.g.:
|
||||
# uv run samples/semantic-kernel-migration/openai_assistant/02_openai_assistant_with_code_interpreter.py
|
||||
|
||||
# Copyright (c) Microsoft. All rights reserved.
|
||||
"""Enable the code interpreter tool for OpenAI Assistants in SK and AF."""
|
||||
|
||||
import asyncio
|
||||
|
||||
from agent_framework import Agent
|
||||
from dotenv import load_dotenv
|
||||
|
||||
# Load environment variables from .env file
|
||||
load_dotenv()
|
||||
|
||||
|
||||
async def run_semantic_kernel() -> None:
|
||||
from semantic_kernel.agents import OpenAIAssistantAgent
|
||||
from semantic_kernel.connectors.ai.open_ai import OpenAISettings
|
||||
|
||||
client = OpenAIAssistantAgent.create_client()
|
||||
|
||||
code_interpreter_tool, code_interpreter_tool_resources = OpenAIAssistantAgent.configure_code_interpreter_tool()
|
||||
|
||||
# Enable the hosted code interpreter tool on the assistant definition.
|
||||
definition = await client.beta.assistants.create(
|
||||
model=OpenAISettings().chat_model_id,
|
||||
name="CodeRunner",
|
||||
instructions="Run the provided request as code and return the result.",
|
||||
tools=code_interpreter_tool,
|
||||
tool_resources=code_interpreter_tool_resources,
|
||||
)
|
||||
agent = OpenAIAssistantAgent(client=client, definition=definition)
|
||||
response = await agent.get_response(
|
||||
"Use Python to calculate the mean of [41, 42, 45] and explain the steps.",
|
||||
)
|
||||
print(f"[SK]: {response}")
|
||||
|
||||
|
||||
async def run_agent_framework() -> None:
|
||||
from agent_framework.openai import OpenAIAssistantsClient
|
||||
|
||||
assistants_client = OpenAIAssistantsClient()
|
||||
|
||||
# Create code interpreter tool using static method
|
||||
code_interpreter_tool = OpenAIAssistantsClient.get_code_interpreter_tool()
|
||||
|
||||
# AF exposes the same tool configuration via create_agent.
|
||||
async with Agent(client=assistants_client,
|
||||
name="CodeRunner",
|
||||
instructions="Use the code interpreter when calculations are required.",
|
||||
model="gpt-4.1",
|
||||
tools=[code_interpreter_tool],
|
||||
) as assistant_agent:
|
||||
response = await assistant_agent.run(
|
||||
"Use Python to calculate the mean of [41, 42, 45] and explain the steps.",
|
||||
tool_choice="auto",
|
||||
)
|
||||
print(f"[AF]: {response.text}")
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
await run_semantic_kernel()
|
||||
await run_agent_framework()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
-103
@@ -1,103 +0,0 @@
|
||||
# /// script
|
||||
# requires-python = ">=3.10"
|
||||
# dependencies = [
|
||||
# "semantic-kernel",
|
||||
# ]
|
||||
# ///
|
||||
# Run with any PEP 723 compatible runner, e.g.:
|
||||
# uv run samples/semantic-kernel-migration/openai_assistant/03_openai_assistant_function_tool.py
|
||||
|
||||
# Copyright (c) Microsoft. All rights reserved.
|
||||
"""Implement a function tool for OpenAI Assistants in SK and AF."""
|
||||
|
||||
import asyncio
|
||||
import os
|
||||
from typing import Any
|
||||
|
||||
from dotenv import load_dotenv
|
||||
|
||||
# Load environment variables from .env file
|
||||
load_dotenv()
|
||||
|
||||
ASSISTANT_MODEL = os.environ.get("OPENAI_ASSISTANT_MODEL", "gpt-4o-mini")
|
||||
|
||||
|
||||
async def fake_weather_lookup(city: str, day: str) -> dict[str, Any]:
|
||||
"""Pretend to call a weather service."""
|
||||
|
||||
return {
|
||||
"city": city,
|
||||
"day": day,
|
||||
"forecast": "Sunny with scattered clouds",
|
||||
"high_c": 22,
|
||||
"low_c": 14,
|
||||
}
|
||||
|
||||
|
||||
async def run_semantic_kernel() -> None:
|
||||
from semantic_kernel.agents import AssistantAgentThread, OpenAIAssistantAgent
|
||||
from semantic_kernel.functions import kernel_function
|
||||
|
||||
class WeatherPlugin:
|
||||
@kernel_function(name="get_forecast", description="Look up the forecast for a city and day.")
|
||||
async def fake_weather_lookup(self, city: str, day: str) -> dict[str, Any]:
|
||||
"""Pretend to call a weather service."""
|
||||
return {
|
||||
"city": city,
|
||||
"day": day,
|
||||
"forecast": "Sunny with scattered clouds",
|
||||
"high_c": 22,
|
||||
"low_c": 14,
|
||||
}
|
||||
|
||||
client = OpenAIAssistantAgent.create_client()
|
||||
# Tool schema is registered on the assistant definition.
|
||||
definition = await client.beta.assistants.create(
|
||||
model=ASSISTANT_MODEL,
|
||||
name="WeatherHelper",
|
||||
instructions="Call get_forecast to fetch weather details.",
|
||||
)
|
||||
agent = OpenAIAssistantAgent(client=client, definition=definition, plugins=[WeatherPlugin()])
|
||||
|
||||
thread: AssistantAgentThread | None = None
|
||||
response = await agent.get_response(
|
||||
"What will the weather be like in Seattle tomorrow?",
|
||||
thread=thread,
|
||||
)
|
||||
thread = response.thread
|
||||
print("[SK][initial]", response.message.content)
|
||||
|
||||
|
||||
async def run_agent_framework() -> None:
|
||||
from agent_framework import Agent, tool
|
||||
from agent_framework.openai import OpenAIAssistantsClient
|
||||
|
||||
@tool(
|
||||
name="get_forecast",
|
||||
description="Look up the forecast for a city and day.",
|
||||
)
|
||||
async def get_forecast(city: str, day: str) -> dict[str, Any]:
|
||||
return await fake_weather_lookup(city, day)
|
||||
|
||||
assistants_client = OpenAIAssistantsClient()
|
||||
# AF converts the decorated function into an assistant-compatible tool.
|
||||
async with Agent(client=assistants_client,
|
||||
name="WeatherHelper",
|
||||
instructions="Call get_forecast to fetch weather details.",
|
||||
model=ASSISTANT_MODEL,
|
||||
tools=[get_forecast],
|
||||
) as assistant_agent:
|
||||
reply = await assistant_agent.run(
|
||||
"What will the weather be like in Seattle tomorrow?",
|
||||
tool_choice="auto",
|
||||
)
|
||||
print("[AF]", reply.text)
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
await run_semantic_kernel()
|
||||
await run_agent_framework()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
+3
-3
@@ -36,11 +36,11 @@ async def run_semantic_kernel() -> None:
|
||||
|
||||
async def run_agent_framework() -> None:
|
||||
from agent_framework import Agent
|
||||
from agent_framework.openai import OpenAIResponsesClient
|
||||
from agent_framework.openai import OpenAIChatClient
|
||||
|
||||
# AF Agent can swap in an OpenAIResponsesClient directly.
|
||||
# AF Agent can swap in an OpenAIChatClient directly.
|
||||
chat_agent = Agent(
|
||||
client=OpenAIResponsesClient(),
|
||||
client=OpenAIChatClient(),
|
||||
instructions="Answer in one concise sentence.",
|
||||
name="Expert",
|
||||
)
|
||||
|
||||
+2
-2
@@ -43,14 +43,14 @@ async def run_semantic_kernel() -> None:
|
||||
|
||||
async def run_agent_framework() -> None:
|
||||
from agent_framework import Agent, tool
|
||||
from agent_framework.openai import OpenAIResponsesClient
|
||||
from agent_framework.openai import OpenAIChatClient
|
||||
|
||||
@tool(name="add", description="Add two numbers")
|
||||
async def add(a: float, b: float) -> float:
|
||||
return a + b
|
||||
|
||||
chat_agent = Agent(
|
||||
client=OpenAIResponsesClient(),
|
||||
client=OpenAIChatClient(),
|
||||
instructions="Use the add tool when math is required.",
|
||||
name="MathExpert",
|
||||
# AF registers the async function as a tool at construction.
|
||||
|
||||
+2
-2
@@ -46,10 +46,10 @@ async def run_semantic_kernel() -> None:
|
||||
|
||||
async def run_agent_framework() -> None:
|
||||
from agent_framework import Agent
|
||||
from agent_framework.openai import OpenAIResponsesClient
|
||||
from agent_framework.openai import OpenAIChatClient
|
||||
|
||||
chat_agent = Agent(
|
||||
client=OpenAIResponsesClient(),
|
||||
client=OpenAIChatClient(),
|
||||
instructions="Return launch briefs as structured JSON.",
|
||||
name="ProductMarketer",
|
||||
)
|
||||
|
||||
@@ -16,7 +16,7 @@ from collections.abc import Sequence
|
||||
from typing import cast
|
||||
|
||||
from agent_framework import Agent, Message
|
||||
from agent_framework.azure import AzureOpenAIChatClient
|
||||
from agent_framework.openai import OpenAIChatCompletionClient
|
||||
from agent_framework.orchestrations import ConcurrentBuilder
|
||||
from azure.identity import AzureCliCredential
|
||||
from dotenv import load_dotenv
|
||||
@@ -89,7 +89,7 @@ def _print_semantic_kernel_outputs(outputs: Sequence[ChatMessageContent]) -> Non
|
||||
|
||||
|
||||
async def run_agent_framework_example(prompt: str) -> Sequence[list[Message]]:
|
||||
client = AzureOpenAIChatClient(credential=AzureCliCredential())
|
||||
client = OpenAIChatCompletionClient(credential=AzureCliCredential())
|
||||
|
||||
physics = Agent(client=client,
|
||||
instructions=("You are an expert in physics. Answer questions from a physics perspective."),
|
||||
|
||||
@@ -15,7 +15,7 @@ import asyncio
|
||||
from collections.abc import Sequence
|
||||
|
||||
from agent_framework import Agent
|
||||
from agent_framework.openai import OpenAIChatClient, OpenAIResponsesClient
|
||||
from agent_framework.openai import OpenAIChatClient
|
||||
from agent_framework.orchestrations import MagenticBuilder
|
||||
from dotenv import load_dotenv
|
||||
from semantic_kernel.agents import (
|
||||
@@ -141,8 +141,8 @@ async def run_agent_framework_example(prompt: str) -> str | None:
|
||||
)
|
||||
|
||||
# Create code interpreter tool using static method
|
||||
coder_client = OpenAIResponsesClient()
|
||||
code_interpreter_tool = OpenAIResponsesClient.get_code_interpreter_tool()
|
||||
coder_client = OpenAIChatClient()
|
||||
code_interpreter_tool = OpenAIChatClient.get_code_interpreter_tool()
|
||||
|
||||
coder = Agent(
|
||||
name="CoderAgent",
|
||||
|
||||
@@ -16,7 +16,7 @@ from collections.abc import Sequence
|
||||
from typing import cast
|
||||
|
||||
from agent_framework import Agent, Message
|
||||
from agent_framework.azure import AzureOpenAIChatClient
|
||||
from agent_framework.openai import OpenAIChatCompletionClient
|
||||
from agent_framework.orchestrations import SequentialBuilder
|
||||
from azure.identity import AzureCliCredential
|
||||
from dotenv import load_dotenv
|
||||
@@ -76,7 +76,7 @@ async def sk_agent_response_callback(
|
||||
|
||||
|
||||
async def run_agent_framework_example(prompt: str) -> list[Message]:
|
||||
client = AzureOpenAIChatClient(credential=AzureCliCredential())
|
||||
client = OpenAIChatCompletionClient(credential=AzureCliCredential())
|
||||
|
||||
writer = Agent(client=client,
|
||||
instructions=("You are a concise copywriter. Provide a single, punchy marketing sentence based on the prompt."),
|
||||
|
||||
Reference in New Issue
Block a user