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,64 @@
|
||||
# /// 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/chat_completion/01_basic_chat_completion.py
|
||||
|
||||
# Copyright (c) Microsoft. All rights reserved.
|
||||
"""Basic SK ChatCompletionAgent vs Agent Framework Agent.
|
||||
|
||||
Both samples expect OpenAI-compatible environment variables (OPENAI_API_KEY or
|
||||
Azure OpenAI configuration). Update the prompts or client wiring to match your
|
||||
model of choice before running.
|
||||
"""
|
||||
|
||||
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:
|
||||
"""Call SK's ChatCompletionAgent for a simple question."""
|
||||
|
||||
from semantic_kernel.agents import ChatCompletionAgent
|
||||
from semantic_kernel.connectors.ai.open_ai import OpenAIChatCompletion
|
||||
|
||||
# SK agent holds the thread state internally via ChatCompletionAgent.
|
||||
agent = ChatCompletionAgent(
|
||||
service=OpenAIChatCompletion(),
|
||||
name="Support",
|
||||
instructions="Answer in one sentence.",
|
||||
)
|
||||
response = await agent.get_response(messages="How do I reset my bike tire?")
|
||||
print("[SK]", response.message.content)
|
||||
|
||||
|
||||
async def run_agent_framework() -> None:
|
||||
"""Call Agent Framework's Agent created from OpenAIChatClient."""
|
||||
from agent_framework.openai import OpenAIChatClient
|
||||
|
||||
# AF constructs a lightweight Agent backed by OpenAIChatClient.
|
||||
chat_agent = Agent(
|
||||
client=OpenAIChatClient(),
|
||||
name="Support",
|
||||
instructions="Answer in one sentence.",
|
||||
)
|
||||
reply = await chat_agent.run("How do I reset my bike tire?")
|
||||
print("[AF]", reply.text)
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
await run_semantic_kernel()
|
||||
await run_agent_framework()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
+72
@@ -0,0 +1,72 @@
|
||||
# /// 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/chat_completion/02_chat_completion_with_tool.py
|
||||
|
||||
# Copyright (c) Microsoft. All rights reserved.
|
||||
"""Demonstrate SK plugins vs Agent Framework tools with a chat agent.
|
||||
|
||||
Configure your OpenAI or Azure OpenAI credentials before running. The example
|
||||
exposes a "specials" tool that both SDKs call during the conversation.
|
||||
"""
|
||||
|
||||
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 ChatCompletionAgent
|
||||
from semantic_kernel.connectors.ai.open_ai import OpenAIChatCompletion
|
||||
from semantic_kernel.functions import kernel_function
|
||||
|
||||
class SpecialsPlugin:
|
||||
@kernel_function(name="specials", description="List daily specials")
|
||||
def specials(self) -> str:
|
||||
return "Clam chowder, Cobb salad, Chai tea"
|
||||
|
||||
# SK advertises tools by attaching plugin instances at construction time.
|
||||
agent = ChatCompletionAgent(
|
||||
service=OpenAIChatCompletion(),
|
||||
name="Host",
|
||||
instructions="Answer menu questions accurately.",
|
||||
plugins=[SpecialsPlugin()],
|
||||
)
|
||||
response = await agent.get_response("What soup can I order today?")
|
||||
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="specials", description="List daily specials")
|
||||
async def specials() -> str:
|
||||
return "Clam chowder, Cobb salad, Chai tea"
|
||||
|
||||
# AF tools are provided as callables on each agent instance.
|
||||
chat_agent = Agent(
|
||||
client=OpenAIChatClient(),
|
||||
name="Host",
|
||||
instructions="Answer menu questions accurately.",
|
||||
tools=[specials],
|
||||
)
|
||||
reply = await chat_agent.run("What soup can I order today?")
|
||||
print("[AF]", reply.text)
|
||||
|
||||
|
||||
async def main() -> None:
|
||||
await run_semantic_kernel()
|
||||
await run_agent_framework()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
asyncio.run(main())
|
||||
+89
@@ -0,0 +1,89 @@
|
||||
# /// 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/chat_completion/03_chat_completion_thread_and_stream.py
|
||||
|
||||
# Copyright (c) Microsoft. All rights reserved.
|
||||
"""Compare conversation threading and streaming responses for chat agents.
|
||||
|
||||
Both implementations reuse a conversation thread across turns and stream output
|
||||
for the second turn.
|
||||
"""
|
||||
|
||||
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 ChatCompletionAgent, ChatHistoryAgentThread
|
||||
from semantic_kernel.connectors.ai.open_ai import OpenAIChatCompletion
|
||||
|
||||
# SK thread object keeps the conversation history on the agent side.
|
||||
agent = ChatCompletionAgent(
|
||||
service=OpenAIChatCompletion(),
|
||||
name="Writer",
|
||||
instructions="Keep answers short and friendly.",
|
||||
)
|
||||
thread = ChatHistoryAgentThread()
|
||||
|
||||
first = await agent.get_response(
|
||||
messages="Suggest a catchy headline for our product launch.",
|
||||
thread=thread,
|
||||
)
|
||||
print("[SK]", first.message.content)
|
||||
|
||||
print("[SK][stream]", end=" ")
|
||||
async for update in agent.invoke_stream(
|
||||
messages="Draft a 2 sentence blurb.",
|
||||
thread=thread,
|
||||
):
|
||||
if update.message:
|
||||
print(update.message.content, end="", flush=True)
|
||||
print()
|
||||
|
||||
|
||||
async def run_agent_framework() -> None:
|
||||
from agent_framework.openai import OpenAIChatClient
|
||||
|
||||
# AF session objects are requested explicitly from the agent.
|
||||
chat_agent = Agent(
|
||||
client=OpenAIChatClient(),
|
||||
name="Writer",
|
||||
instructions="Keep answers short and friendly.",
|
||||
)
|
||||
session = chat_agent.create_session()
|
||||
|
||||
first = await chat_agent.run(
|
||||
"Suggest a catchy headline for our product launch.",
|
||||
session=session,
|
||||
)
|
||||
print("[AF]", first.text)
|
||||
|
||||
print("[AF][stream]", end=" ")
|
||||
async for chunk in chat_agent.run(
|
||||
"Draft a 2 sentence blurb.",
|
||||
session=session,
|
||||
stream=True,
|
||||
):
|
||||
if chunk.text:
|
||||
print(chunk.text, end="", flush=True)
|
||||
print()
|
||||
|
||||
|
||||
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