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,51 @@
# Copyright (c) Microsoft. All rights reserved.
"""Create an Azure AI agent using both Semantic Kernel and Agent Framework.
Prerequisites:
- Azure AI agent resource with a deployed model.
- Logged-in Azure CLI or other credential supported by AzureCliCredential.
"""
import asyncio
async def run_semantic_kernel() -> None:
from azure.identity.aio import AzureCliCredential
from semantic_kernel.agents import AzureAIAgent, AzureAIAgentSettings
async with AzureCliCredential() as credential, AzureAIAgent.create_client(credential=credential) as client:
settings = AzureAIAgentSettings() # Reads env vars for region/deployment.
# SK builds the remote agent definition then wraps it with AzureAIAgent.
definition = await client.agents.as_agent(
model=settings.model_deployment_name,
name="Support",
instructions="Answer customer questions in one paragraph.",
)
agent = AzureAIAgent(client=client, definition=definition)
response = await agent.get_response("How do I upgrade my plan?")
print("[SK]", response.message.content)
async def run_agent_framework() -> None:
from agent_framework.azure import AzureAIAgentClient
from azure.identity.aio import AzureCliCredential
async with (
AzureCliCredential() as credential,
AzureAIAgentClient(credential=credential).as_agent(
name="Support",
instructions="Answer customer questions in one paragraph.",
) as agent,
):
# AF client returns an asynchronous context manager for remote agents.
reply = await agent.run("How do I upgrade my plan?")
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,58 @@
# Copyright (c) Microsoft. All rights reserved.
"""Enable the hosted code interpreter for Azure AI agents in SK and AF.
The Azure AI service natively executes the code interpreter tool. Provide the
resource details via AzureAIAgentSettings (SK) or environment variables consumed
by AzureAIAgentClient (AF).
"""
import asyncio
async def run_semantic_kernel() -> None:
from azure.identity.aio import AzureCliCredential
from semantic_kernel.agents import AzureAIAgent, AzureAIAgentSettings
async with AzureCliCredential() as credential, AzureAIAgent.create_client(credential=credential) as client:
settings = AzureAIAgentSettings()
# Register the hosted code interpreter tool with the remote agent.
definition = await client.agents.as_agent(
model=settings.model_deployment_name,
name="Analyst",
instructions="Use the code interpreter for numeric work.",
tools=[{"type": "code_interpreter"}],
)
agent = AzureAIAgent(client=client, definition=definition)
response = await agent.get_response(
"Use Python to compute 42 ** 2 and explain the result.",
)
print("[SK]", response.message.content)
async def run_agent_framework() -> None:
from agent_framework.azure import AzureAIAgentClient, HostedCodeInterpreterTool
from azure.identity.aio import AzureCliCredential
async with (
AzureCliCredential() as credential,
AzureAIAgentClient(credential=credential).as_agent(
name="Analyst",
instructions="Use the code interpreter for numeric work.",
tools=[HostedCodeInterpreterTool()],
) as agent,
):
# HostedCodeInterpreterTool mirrors the built-in Azure AI capability.
reply = await agent.run(
"Use Python to compute 42 ** 2 and explain the result.",
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,67 @@
# Copyright (c) Microsoft. All rights reserved.
"""Maintain Azure AI agent conversation state across turns in SK and AF."""
import asyncio
async def run_semantic_kernel() -> None:
from azure.identity.aio import AzureCliCredential
from semantic_kernel.agents import AzureAIAgent, AzureAIAgentSettings, AzureAIAgentThread
async with AzureCliCredential() as credential, AzureAIAgent.create_client(credential=credential) as client:
settings = AzureAIAgentSettings()
definition = await client.agents.as_agent(
model=settings.model_deployment_name,
name="Planner",
instructions="Track follow-up questions within the same thread.",
)
agent = AzureAIAgent(client=client, definition=definition)
thread: AzureAIAgentThread | None = None
# SK returns the updated AzureAIAgentThread on each response.
first = await agent.get_response("Outline the onboarding checklist.", thread=thread)
thread = first.thread
print("[SK][turn1]", first.message.content)
second = await agent.get_response(
"Highlight the items that require legal review.",
thread=thread,
)
print("[SK][turn2]", second.message.content)
if thread is not None:
print("[SK][thread-id]", thread.id)
async def run_agent_framework() -> None:
from agent_framework.azure import AzureAIAgentClient
from azure.identity.aio import AzureCliCredential
async with (
AzureCliCredential() as credential,
AzureAIAgentClient(credential=credential).as_agent(
name="Planner",
instructions="Track follow-up questions within the same thread.",
) as agent,
):
thread = agent.get_new_thread()
# AF threads are explicit and can be serialized for external storage.
first = await agent.run("Outline the onboarding checklist.", thread=thread)
print("[AF][turn1]", first.text)
second = await agent.run(
"Highlight the items that require legal review.",
thread=thread,
)
print("[AF][turn2]", second.text)
serialized = await thread.serialize()
print("[AF][thread-json]", serialized)
async def main() -> None:
await run_semantic_kernel()
await run_agent_framework()
if __name__ == "__main__":
asyncio.run(main())