test
Some checks failed
CodeQL / Analyze (csharp) (push) Has been cancelled
CodeQL / Analyze (python) (push) Has been cancelled
dotnet-build-and-test / paths-filter (push) Has been cancelled
dotnet-build-and-test / dotnet-build-and-test (Debug, windows-latest, net9.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-build-and-test (Release, integration, true, ubuntu-latest, net10.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-build-and-test (Release, integration, true, windows-latest, net472) (push) Has been cancelled
dotnet-build-and-test / dotnet-build-and-test (Release, ubuntu-latest, net8.0) (push) Has been cancelled
dotnet-build-and-test / dotnet-build-and-test-check (push) Has been cancelled
Python - Merge - Tests / paths-filter (push) Has been cancelled
Python - Merge - Tests / Python Tests - Core (integration, ubuntu-latest, 3.10) (push) Has been cancelled
Python - Merge - Tests / Python Tests - Azure AI (integration, ubuntu-latest, 3.10) (push) Has been cancelled
Python - Merge - Tests / python-integration-tests-check (push) Has been cancelled
Python - Lab Tests / paths-filter (push) Has been cancelled
Python - Lab Tests / Python Lab Tests (ubuntu-latest, 3.10) (push) Has been cancelled
Python - Lab Tests / Python Lab Tests (ubuntu-latest, 3.11) (push) Has been cancelled
Python - Lab Tests / Python Lab Tests (ubuntu-latest, 3.12) (push) Has been cancelled
Python - Lab Tests / Python Lab Tests (ubuntu-latest, 3.13) (push) Has been cancelled
Python - Lab Tests / Python Lab Tests (ubuntu-latest, 3.14) (push) Has been cancelled
Python - Lab Tests / Python Lab Tests (windows-latest, 3.10) (push) Has been cancelled
Python - Lab Tests / Python Lab Tests (windows-latest, 3.11) (push) Has been cancelled
Python - Lab Tests / Python Lab Tests (windows-latest, 3.12) (push) Has been cancelled
Python - Lab Tests / Python Lab Tests (windows-latest, 3.13) (push) Has been cancelled
Python - Lab Tests / Python Lab Tests (windows-latest, 3.14) (push) Has been cancelled
Check .md links / markdown-link-check (push) Has been cancelled

This commit is contained in:
2026-01-24 03:05:12 +11:00
parent f78f2388b3
commit 539852f81c
2584 changed files with 287471 additions and 0 deletions

View File

@@ -0,0 +1,46 @@
# Copyright (c) Microsoft. All rights reserved.
"""Basic SK ChatCompletionAgent vs Agent Framework ChatAgent.
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
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 ChatAgent created from OpenAIChatClient."""
from agent_framework.openai import OpenAIChatClient
# AF constructs a lightweight ChatAgent backed by OpenAIChatClient.
chat_agent = OpenAIChatClient().as_agent(
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())

View File

@@ -0,0 +1,65 @@
# 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
async def run_semantic_kernel() -> None:
from semantic_kernel.agents import ChatCompletionAgent, ChatHistoryAgentThread
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()],
)
thread = ChatHistoryAgentThread()
response = await agent.get_response(
messages="What soup can I order today?",
thread=thread,
)
print("[SK]", response.message.content)
async def run_agent_framework() -> None:
from agent_framework._tools import ai_function
from agent_framework.openai import OpenAIChatClient
@ai_function(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 = OpenAIChatClient().as_agent(
name="Host",
instructions="Answer menu questions accurately.",
tools=[specials],
)
thread = chat_agent.get_new_thread()
reply = await chat_agent.run(
"What soup can I order today?",
thread=thread,
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())

View File

@@ -0,0 +1,71 @@
# 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
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 thread objects are requested explicitly from the agent.
chat_agent = OpenAIChatClient().as_agent(
name="Writer",
instructions="Keep answers short and friendly.",
)
thread = chat_agent.get_new_thread()
first = await chat_agent.run(
"Suggest a catchy headline for our product launch.",
thread=thread,
)
print("[AF]", first.text)
print("[AF][stream]", end=" ")
async for chunk in chat_agent.run_stream(
"Draft a 2 sentence blurb.",
thread=thread,
):
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())