chore: import upstream snapshot with attribution
CodeQL / Analyze (csharp) (push) Waiting to run
CodeQL / Analyze (python) (push) Waiting to run
dotnet-build-and-test / dotnet-test-functions (push) Has been cancelled
dotnet-build-and-test / paths-filter (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Debug, windows-latest, net9.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Release, ubuntu-latest, net10.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Release, ubuntu-latest, net8.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Release, windows-latest, net472) (push) Has been cancelled
dotnet-build-and-test / dotnet-test (Release, integration, true, ubuntu-latest, net10.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-test (Release, integration, true, windows-latest, net472) (push) Has been cancelled
dotnet-build-and-test / dotnet-foundry-hosted-it (push) Has been cancelled
dotnet-build-and-test / dotnet-build-and-test-check (push) Has been cancelled
dotnet-build-and-test / Integration Test Report (push) Has been cancelled
CodeQL / Analyze (csharp) (push) Waiting to run
CodeQL / Analyze (python) (push) Waiting to run
dotnet-build-and-test / dotnet-test-functions (push) Has been cancelled
dotnet-build-and-test / paths-filter (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Debug, windows-latest, net9.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Release, ubuntu-latest, net10.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Release, ubuntu-latest, net8.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-build (Release, windows-latest, net472) (push) Has been cancelled
dotnet-build-and-test / dotnet-test (Release, integration, true, ubuntu-latest, net10.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-test (Release, integration, true, windows-latest, net472) (push) Has been cancelled
dotnet-build-and-test / dotnet-foundry-hosted-it (push) Has been cancelled
dotnet-build-and-test / dotnet-build-and-test-check (push) Has been cancelled
dotnet-build-and-test / Integration Test Report (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
# /// script
|
||||
# requires-python = ">=3.10"
|
||||
# dependencies = [
|
||||
# "agent-framework-openai",
|
||||
# "semantic-kernel",
|
||||
# ]
|
||||
# ///
|
||||
# Run with any PEP 723 compatible runner, e.g.:
|
||||
# uv run samples/semantic-kernel-migration/openai_responses/01_basic_responses_agent.py
|
||||
|
||||
# Copyright (c) Microsoft. All rights reserved.
|
||||
"""Issue a basic Responses API call using SK and Agent Framework."""
|
||||
|
||||
import asyncio
|
||||
|
||||
from dotenv import load_dotenv
|
||||
|
||||
# Load environment variables from .env file
|
||||
load_dotenv()
|
||||
|
||||
|
||||
async def run_semantic_kernel() -> None:
|
||||
from semantic_kernel.agents import OpenAIResponsesAgent
|
||||
from semantic_kernel.connectors.ai.open_ai import OpenAISettings
|
||||
|
||||
openai_settings = OpenAISettings()
|
||||
assert openai_settings.responses_model_id is not None, "Responses model ID must be set in OpenAISettings"
|
||||
|
||||
client = OpenAIResponsesAgent.create_client()
|
||||
# SK response agents wrap OpenAI's hosted Responses API.
|
||||
agent = OpenAIResponsesAgent(
|
||||
ai_model_id=openai_settings.responses_model_id,
|
||||
client=client,
|
||||
instructions="Answer in one concise sentence.",
|
||||
name="Expert",
|
||||
)
|
||||
response = await agent.get_response("Why is the sky blue?")
|
||||
print("[SK]", response.message.content)
|
||||
|
||||
|
||||
async def run_agent_framework() -> None:
|
||||
from agent_framework import Agent
|
||||
from agent_framework.openai import OpenAIChatClient
|
||||
|
||||
# AF Agent can swap in an OpenAIChatClient directly.
|
||||
chat_agent = Agent(
|
||||
client=OpenAIChatClient(),
|
||||
instructions="Answer in one concise sentence.",
|
||||
name="Expert",
|
||||
)
|
||||
reply = await chat_agent.run("Why is the sky blue?")
|
||||
print("[AF]", reply.text)
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
await run_semantic_kernel()
|
||||
await run_agent_framework()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
+73
@@ -0,0 +1,73 @@
|
||||
# /// script
|
||||
# requires-python = ">=3.10"
|
||||
# dependencies = [
|
||||
# "agent-framework-openai",
|
||||
# "semantic-kernel",
|
||||
# ]
|
||||
# ///
|
||||
# Run with any PEP 723 compatible runner, e.g.:
|
||||
# uv run samples/semantic-kernel-migration/openai_responses/02_responses_agent_with_tool.py
|
||||
|
||||
# Copyright (c) Microsoft. All rights reserved.
|
||||
"""Attach a lightweight function tool to the Responses API in SK and AF."""
|
||||
|
||||
import asyncio
|
||||
|
||||
from dotenv import load_dotenv
|
||||
|
||||
# Load environment variables from .env file
|
||||
load_dotenv()
|
||||
|
||||
|
||||
async def run_semantic_kernel() -> None:
|
||||
from semantic_kernel.agents import OpenAIResponsesAgent
|
||||
from semantic_kernel.connectors.ai.open_ai import OpenAISettings
|
||||
from semantic_kernel.functions import kernel_function
|
||||
|
||||
class MathPlugin:
|
||||
@kernel_function(name="add", description="Add two numbers")
|
||||
def add(self, a: float, b: float) -> float:
|
||||
return a + b
|
||||
|
||||
openai_settings = OpenAISettings()
|
||||
assert openai_settings.responses_model_id is not None, "Responses model ID must be set in OpenAISettings"
|
||||
|
||||
client = OpenAIResponsesAgent.create_client()
|
||||
# Plugins advertise callable tools to the Responses agent.
|
||||
agent = OpenAIResponsesAgent(
|
||||
ai_model_id=openai_settings.responses_model_id,
|
||||
client=client,
|
||||
instructions="Use the add tool when math is required.",
|
||||
name="MathExpert",
|
||||
plugins=[MathPlugin()],
|
||||
)
|
||||
response = await agent.get_response("Use add(41, 1) and explain the result.")
|
||||
print("[SK]", response.message.content)
|
||||
|
||||
|
||||
async def run_agent_framework() -> None:
|
||||
from agent_framework import Agent, tool
|
||||
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=OpenAIChatClient(),
|
||||
instructions="Use the add tool when math is required.",
|
||||
name="MathExpert",
|
||||
# AF registers the async function as a tool at construction.
|
||||
tools=[add],
|
||||
)
|
||||
reply = await chat_agent.run("Use add(41, 1) and explain the result.")
|
||||
print("[AF]", reply.text)
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
await run_semantic_kernel()
|
||||
await run_agent_framework()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
+74
@@ -0,0 +1,74 @@
|
||||
# /// script
|
||||
# requires-python = ">=3.10"
|
||||
# dependencies = [
|
||||
# "agent-framework-openai",
|
||||
# "semantic-kernel",
|
||||
# ]
|
||||
# ///
|
||||
# Run with any PEP 723 compatible runner, e.g.:
|
||||
# uv run samples/semantic-kernel-migration/openai_responses/03_responses_agent_structured_output.py
|
||||
|
||||
# Copyright (c) Microsoft. All rights reserved.
|
||||
"""Request structured JSON output from the Responses API in SK and AF."""
|
||||
|
||||
import asyncio
|
||||
|
||||
from dotenv import load_dotenv
|
||||
from pydantic import BaseModel
|
||||
|
||||
# Load environment variables from .env file
|
||||
load_dotenv()
|
||||
|
||||
|
||||
class ReleaseBrief(BaseModel):
|
||||
feature: str
|
||||
benefit: str
|
||||
launch_date: str
|
||||
|
||||
|
||||
async def run_semantic_kernel() -> None:
|
||||
from semantic_kernel.agents import OpenAIResponsesAgent
|
||||
from semantic_kernel.connectors.ai.open_ai import OpenAISettings
|
||||
|
||||
openai_settings = OpenAISettings()
|
||||
assert openai_settings.responses_model_id is not None, "Responses model ID must be set in OpenAISettings"
|
||||
|
||||
client = OpenAIResponsesAgent.create_client()
|
||||
# response_format requests schema-constrained output from the model.
|
||||
agent = OpenAIResponsesAgent(
|
||||
ai_model_id=openai_settings.responses_model_id,
|
||||
client=client,
|
||||
instructions="Return launch briefs as structured JSON.",
|
||||
name="ProductMarketer",
|
||||
text=OpenAIResponsesAgent.configure_response_format(ReleaseBrief), # type: ignore
|
||||
)
|
||||
response = await agent.get_response(
|
||||
"Draft a launch brief for the Contoso Note app.",
|
||||
)
|
||||
print("[SK]", response.message.content)
|
||||
|
||||
|
||||
async def run_agent_framework() -> None:
|
||||
from agent_framework import Agent
|
||||
from agent_framework.openai import OpenAIChatClient
|
||||
|
||||
chat_agent = Agent(
|
||||
client=OpenAIChatClient(),
|
||||
instructions="Return launch briefs as structured JSON.",
|
||||
name="ProductMarketer",
|
||||
)
|
||||
# AF forwards the same response_format payload at invocation time.
|
||||
reply = await chat_agent.run(
|
||||
"Draft a launch brief for the Contoso Note app.",
|
||||
options={"response_format": ReleaseBrief},
|
||||
)
|
||||
print("[AF]", reply.text)
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
await run_semantic_kernel()
|
||||
await run_agent_framework()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
Reference in New Issue
Block a user