.NET: Add Prompt to support and improve AI Agent SK->AF Migration Results (#1081)

* Prompt progress

* Enriched prompt + Added to SLN visibility

* Set starting point for Copilot Migration

* Address prompt detail + prepare copilot migration to work with Agent nugets

* Address more prompt details

* Prompt update

* Improve description for migration

* Improve description for migration

* Improve description for migration

* Improve description for migration

* SLnx Upgrade Assistant use-case

* Extra tweaks to the migration prompt

* Update prompt

* Adding the migration guida as a visible reference to the project

* Improvements

* IMprovement

* Small improvements

* AI Guidance Overhaul.

* Update migration guide with better straightforward examples

* Update breaking glass instructions

* Namespace change + address feedback

* ChatComletionService considerations

* Add middleware guidance + public packages

* Removing + ignoring future generated files

* Potential gh bug?

* Prompt progress

* Enriched prompt + Added to SLN visibility

* Set starting point for Copilot Migration

* Address prompt detail + prepare copilot migration to work with Agent nugets

* Address more prompt details

* Prompt update

* Improve description for migration

* Improve description for migration

* Improve description for migration

* Improve description for migration

* SLnx Upgrade Assistant use-case

* Extra tweaks to the migration prompt

* Update prompt

* Adding the migration guida as a visible reference to the project

* Improvements

* IMprovement

* Small improvements

* AI Guidance Overhaul.

* Update migration guide with better straightforward examples

* Update breaking glass instructions

* Namespace change + address feedback

* ChatComletionService considerations

* Add middleware guidance + public packages

* Removing + ignoring future generated files

* Potential gh bug?

* Version bump

* Address observation

* Address observation

---------

Co-authored-by: Chris <66376200+crickman@users.noreply.github.com>
This commit is contained in:
Roger Barreto
2025-10-02 16:00:19 +01:00
committed by GitHub
Unverified
parent 08ea625de0
commit 79def868b6
8 changed files with 1787 additions and 1 deletions
File diff suppressed because it is too large Load Diff
+4
View File
@@ -50,6 +50,10 @@
<PackageVersion Include="OpenTelemetry.Extensions.Hosting" Version="1.12.0" />
<!-- Microsoft.Extensions.* -->
<PackageVersion Include="Microsoft.Bcl.HashCode" Version="6.0.0" />
<PackageVersion Include="Microsoft.Agents.AI" Version="1.0.0-preview.251001.3" />
<PackageVersion Include="Microsoft.Agents.AI.Abstractions" Version="1.0.0-preview.251001.3" />
<PackageVersion Include="Microsoft.Agents.AI.AzureAI" Version="1.0.0-preview.251001.3" />
<PackageVersion Include="Microsoft.Agents.AI.OpenAI" Version="1.0.0-preview.251001.3" />
<PackageVersion Include="Microsoft.Bcl.AsyncInterfaces" Version="9.0.9" />
<PackageVersion Include="OpenAI" Version="2.4.0" />
<PackageVersion Include="Microsoft.Extensions.AI" Version="9.9.1" />
+8
View File
@@ -131,6 +131,10 @@
<Project Path="samples/SemanticKernelMigration/AzureAIFoundry/Step03_DependencyInjection/AzureAIFoundry_Step03_DependencyInjection.csproj" />
<Project Path="samples/SemanticKernelMigration/AzureAIFoundry/Step04_CodeInterpreter/AzureAIFoundry_Step04_CodeInterpreter.csproj" />
</Folder>
<Folder Name="/Samples/SemanticKernelMigration/Playground/">
<File Path="samples/SemanticKernelMigration/Playground/README.md" />
<Project Path="samples/SemanticKernelMigration/Playground/SemanticKernelBasic/SemanticKernelBasic.csproj" />
</Folder>
<Folder Name="/Samples/SemanticKernelMigration/OpenAI/">
<Project Path="samples/SemanticKernelMigration/OpenAI/Step01_Basics/OpenAI_Step01_Basics.csproj" />
<Project Path="samples/SemanticKernelMigration/OpenAI/Step02_ToolCall/OpenAI_Step02_ToolCall.csproj" />
@@ -175,6 +179,10 @@
<File Path="nuget.config" />
</Folder>
<Folder Name="/Solution Items/.github/" />
<Folder Name="/Solution Items/.github/upgrades/" />
<Folder Name="/Solution Items/.github/upgrades/prompts/">
<File Path="../.github/upgrades/prompts/SemanticKernelToAgentFramework.md" />
</Folder>
<Folder Name="/Solution Items/.github/workflows/">
<File Path="../.github/workflows/dotnet-build-and-test.yml" />
<File Path="../.github/workflows/dotnet-check-coverage.ps1" />
+1 -1
View File
@@ -14,4 +14,4 @@
<package pattern="Microsoft.PowerFx.*" />
</packageSource>
</packageSourceMapping>
</configuration>
</configuration>
@@ -77,6 +77,9 @@ async Task AFAgentAsync()
StringBuilder generatedCode = new();
foreach (object? updateRawRepresentation in chatResponse?.RawRepresentation as IEnumerable<object?> ?? [])
{
// To capture the code interpreter input we need to break glass all the updates raw representations, to check for the RunStepDetailsUpdate type and
// get the CodeInterpreterInput property which contains the generated code.
// Note: Similar logic would needed for each individual update if used in the agent.RunStreamingAsync streaming API to aggregate or yield the generated code.
if (updateRawRepresentation is RunStepDetailsUpdate update && update.CodeInterpreterInput is not null)
{
generatedCode.Append(update.CodeInterpreterInput);
@@ -0,0 +1,20 @@
# Semantic Kernel Migration Playground
This is a playground folder with different **Semantic Kernel** projects that can be used to test automatic AI migration to the new **Agent Framework (AF)**.
## Prompting
Open your IDE Agentic extension and create a new chat providing the following prompt:
```
I need to convert code from Semantic Kernel to the Agent Framework.
Please use the migration guide provided in the #SemanticKernelToAgentFramework.md as a reference.
The current solution is using central package manager, when referencing the projects in the csproj don't provide the versions.
Check external references provided by the migration guide if needed.
You don't need to look for the Central Package Management file, just focus on the project file and the code files.
When you need help or don't know how to proceed, please ask.
```
@@ -0,0 +1,89 @@
// Copyright (c) Microsoft. All rights reserved.
using Azure.AI.Agents.Persistent;
using Azure.Identity;
using Microsoft.SemanticKernel;
using Microsoft.SemanticKernel.Agents;
using Microsoft.SemanticKernel.Agents.AzureAI;
using Microsoft.SemanticKernel.ChatCompletion;
#pragma warning disable SKEXP0110 // Type is for evaluation purposes only and is subject to change or removal in future updates. Suppress this diagnostic to proceed.
var client = new PersistentAgentsClient(Environment.GetEnvironmentVariable("AZURE_FOUNDRY_PROJECT_ENDPOINT"), new AzureCliCredential());
// Define the agent
PersistentAgent definition = await client.Administration.CreateAgentAsync(
Environment.GetEnvironmentVariable("AZURE_FOUNDRY_PROJECT_DEPLOYMENT_NAME"),
instructions: "You are a coding assistant that always generates code using the code interpreter tool.",
tools: [new CodeInterpreterToolDefinition()]);
AzureAIAgent agent = new(definition, client);
// Create a thread for the agent conversation.
AgentThread thread = new AzureAIAgentThread(client);
try
{
await InvokeAgentAsync("Create a python file where it determines the values in the Fibonacci sequence that that are less then the value of 101.");
}
finally
{
await thread.DeleteAsync();
await client.Administration.DeleteAgentAsync(agent.Id);
}
async Task InvokeAgentAsync(string input)
{
ChatMessageContent message = new(AuthorRole.User, input);
WriteAgentChatMessage(message);
await foreach (ChatMessageContent response in agent.InvokeAsync(message, thread))
{
WriteAgentChatMessage(response);
}
}
void WriteAgentChatMessage(ChatMessageContent message)
{
// Include ChatMessageContent.AuthorName in output, if present.
string authorExpression = message.Role == AuthorRole.User ? string.Empty : FormatAuthor();
// Include TextContent (via ChatMessageContent.Content), if present.
string contentExpression = string.IsNullOrWhiteSpace(message.Content) ? string.Empty : message.Content;
bool isCode = message.Metadata?.ContainsKey(AzureAIAgent.CodeInterpreterMetadataKey) ?? false;
string codeMarker = isCode ? "\n [CODE]\n" : " ";
Console.WriteLine($"\n# {message.Role}{authorExpression}:{codeMarker}{contentExpression}");
// Provide visibility for inner content (that isn't TextContent).
foreach (KernelContent item in message.Items)
{
if (item is AnnotationContent annotation)
{
if (annotation.Kind == AnnotationKind.UrlCitation)
{
Console.WriteLine($" [{item.GetType().Name}] {annotation.Label}: {annotation.ReferenceId} - {annotation.Title}");
}
else
{
Console.WriteLine($" [{item.GetType().Name}] {annotation.Label}: File #{annotation.ReferenceId}");
}
}
else if (item is ActionContent action)
{
Console.WriteLine($" [{item.GetType().Name}] {action.Text}");
}
else if (item is ReasoningContent reasoning)
{
Console.WriteLine($" [{item.GetType().Name}] {reasoning.Text ?? "Thinking..."}");
}
else if (item is FileReferenceContent fileReference)
{
Console.WriteLine($" [{item.GetType().Name}] File #{fileReference.FileId}");
}
}
if ((message.Metadata?.TryGetValue("Usage", out object? usage) ?? false) && usage is RunStepCompletionUsage agentUsage)
{
Console.WriteLine($" [Usage] Tokens: {agentUsage.TotalTokens}, Input: {agentUsage.PromptTokens}, Output: {agentUsage.CompletionTokens}");
}
string FormatAuthor() => message.AuthorName is not null ? $" - {message.AuthorName ?? " * "}" : string.Empty;
}
@@ -0,0 +1,23 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Azure.AI.Agents.Persistent" />
<PackageReference Include="Azure.Identity" />
<PackageReference Include="Microsoft.Extensions.Configuration" />
<PackageReference Include="Microsoft.SemanticKernel" VersionOverride="1.*" />
<PackageReference Include="Microsoft.SemanticKernel.Agents.Core" VersionOverride="1.*" />
<PackageReference Include="Microsoft.SemanticKernel.Agents.AzureAI" VersionOverride="1.*-*" />
</ItemGroup>
<ItemGroup>
<Content Include="../../../../../.github/upgrades/prompts/*" />
</ItemGroup>
</Project>