Python: semantic-kernel to agent-framework migration code samples (#1045)

* wip migrations

* Wip: workflow migrations

* Add migration samples for sk to af

* Fix typo

* Fixes
This commit is contained in:
Evan Mattson
2025-10-01 16:02:03 +09:00
committed by GitHub
Unverified
parent 498fc06fd6
commit fb51d917fd
23 changed files with 1817 additions and 5 deletions
@@ -0,0 +1,37 @@
# Copyright (c) Microsoft. All rights reserved.
"""Call a Copilot Studio agent with SK and Agent Framework."""
import asyncio
async def run_semantic_kernel() -> None:
from semantic_kernel.agents import CopilotStudioAgent
# SK agent talks to the configured Copilot Studio bot directly.
agent = CopilotStudioAgent(
name="PhysicsAgent",
instructions="Answer physics questions concisely.",
)
response = await agent.get_response("Why is the sky blue?")
print("[SK]", response.message.content)
async def run_agent_framework() -> None:
from agent_framework.microsoft import CopilotStudioAgent
# AF exposes an equivalent CopilotStudioAgent wrapper.
agent = CopilotStudioAgent(
name="PhysicsAgent",
instructions="Answer physics questions concisely.",
)
reply = await 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())
@@ -0,0 +1,43 @@
# Copyright (c) Microsoft. All rights reserved.
"""Stream responses from Copilot Studio agents in SK and AF."""
import asyncio
async def run_semantic_kernel() -> None:
from semantic_kernel.agents import CopilotStudioAgent
agent = CopilotStudioAgent(
name="TourGuide",
instructions="Provide travel recommendations in short bursts.",
)
# SK streaming yields chunks with message metadata.
print("[SK][stream]", end=" ")
async for chunk in agent.invoke_stream("Plan a day in Copenhagen for foodies."):
if chunk.message:
print(chunk.message.content, end="", flush=True)
print()
async def run_agent_framework() -> None:
from agent_framework.microsoft import CopilotStudioAgent
agent = CopilotStudioAgent(
name="TourGuide",
instructions="Provide travel recommendations in short bursts.",
)
# AF streaming provides incremental AgentRunResponseUpdate objects.
print("[AF][stream]", end=" ")
async for update in agent.run_stream("Plan a day in Copenhagen for foodies."):
if update.text:
print(update.text, end="", flush=True)
print()
async def main() -> None:
await run_semantic_kernel()
await run_agent_framework()
if __name__ == "__main__":
asyncio.run(main())