用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/rudironsoni/Synaxis --skill dotnet-semantic-kernel命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
AI-powered wiki generation for code repositories with commands, agents, and skills
Routes .NET/C# work to domain skills. Loads coding-standards for code paths.
Skill manifest management for dotnet-agent-harness. Tracks skill dependencies, conflicts, version compatibility, and provides validation and resolution tools. Triggers on: skill manifest, dependency resolution, skill compatibility, version conflicts, build manifest, validate dependencies.
基于 SOC 职业分类
正在显示 SKILL.md
| name | dotnet-semantic-kernel |
| description | Integrates AI/LLM via Semantic Kernel. Plugins, prompt templates, memory stores, agents. |
| metadata | {"short-description":".NET skill guidance for foundation tasks"} |
Microsoft Semantic Kernel for AI and LLM orchestration in .NET applications. Covers kernel setup and configuration, plugin/function calling, prompt templates with Handlebars and Liquid syntax, memory and vector store integration, planners, the agents framework, and integration with Azure OpenAI, OpenAI, and local models.
Cross-references: [skill:dotnet-csharp-async-patterns] for async streaming patterns used with chat completions, [skill:dotnet-csharp-dependency-injection] for kernel service registration in ASP.NET Core, [skill:dotnet-resilience] for retry policies on AI service calls, [skill:dotnet-csharp-configuration] for managing API keys and model configuration.
The Kernel is the central object in Semantic Kernel. It manages AI service connections, plugins, and function
invocation.
| Package | Purpose |
|---|---|
Microsoft.SemanticKernel | Core kernel, function calling, prompt templates |
Microsoft.SemanticKernel.Connectors.AzureOpenAI | Azure OpenAI chat/embedding/image services |
Microsoft.SemanticKernel.Connectors.OpenAI | OpenAI chat/embedding/image services |
Microsoft.SemanticKernel.Connectors.Ollama | Ollama local model integration |
Microsoft.SemanticKernel.Plugins.Core | Built-in plugins (time, math, text) |
Microsoft.SemanticKernel.Agents.Core | Agent framework (chat agents, group chat) |
Microsoft.Extensions.VectorData.Abstractions | Vector store abstraction layer |
Microsoft.SemanticKernel.Connectors.Qdrant | Qdrant vector store connector |
Microsoft.SemanticKernel.Connectors.AzureAISearch | Azure AI Search vector store connector |
using Microsoft.SemanticKernel;
var builder = Kernel.CreateBuilder();
// Azure OpenAI
builder.AddAzureOpenAIChatCompletion(
deploymentName: "gpt-4o",
endpoint: Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT")!,
apiKey: Environment.GetEnvironmentVariable("AZURE_OPENAI_API_KEY")!);
var kernel = builder.Build();
```text
### DI Integration with ASP.NET Core
```csharp
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddKernel();
builder.Services.AddAzureOpenAIChatCompletion(
deploymentName: builder.Configuration["AI:DeploymentName"]!,
endpoint: builder.Configuration["AI:Endpoint"]!,
apiKey: builder.Configuration["AI:ApiKey"]!);
// Register plugins
builder.Services.AddSingleton<OrderPlugin>();
builder.Services.AddSingleton(sp =>
{
var kernel = sp.GetRequiredService<Kernel>();
kernel.Plugins.AddFromObject(sp.GetRequiredService<OrderPlugin>());
return kernel;
});
```text
### Multiple AI Services
Register multiple AI services and select by service ID:
```csharp
var builder = Kernel.CreateBuilder();
builder.AddAzureOpenAIChatCompletion(
deploymentName: "gpt-4o",
endpoint: endpoint,
apiKey: apiKey,
serviceId: "gpt4o");
builder.AddAzureOpenAIChatCompletion(
deploymentName: "gpt-4o-mini",
endpoint: endpoint,
apiKey: apiKey,
serviceId: "gpt4o-mini");
var kernel = builder.Build();
// Select service at invocation time
var settings = new PromptExecutionSettings { ServiceId = "gpt4o-mini" };
var result = await kernel.InvokePromptAsync("Summarize: {{$input}}", (settings)
{
[] = longDocument
});
```text
```csharp
builder = Kernel.CreateBuilder();
builder.AddOllamaChatCompletion(
modelId: ,
endpoint: Uri());
kernel = builder.Build();
```text
---
Plugins expose .NET methods functions that the AI model can invoke. This the primary mechanism grounding LLM responses real data actions.
```csharp
Microsoft.SemanticKernel;
System.ComponentModel;
{
IOrderRepository _repository;
=> _repository = repository;
[]
[]
Task<OrderSummary?> GetOrderAsync(
[] orderId,
CancellationToken ct = )
{
order = _repository.GetByIdAsync(orderId, ct);
order ? : OrderSummary(order);
}
[]
[]
Task<IReadOnlyList<OrderSummary>> ListRecentOrdersAsync(
[] customerId,
[] limit = ,
CancellationToken ct = )
{
orders = _repository.GetRecentAsync(customerId, limit, ct);
orders.Select(o => OrderSummary(o)).ToList();
}
}
```text
```csharp
kernel = builder.Build();
kernel.Plugins.AddFromObject( OrderPlugin(orderRepo), );
kernel.Plugins.AddFromType<TimePlugin>();
kernel.Plugins.AddFromFunctions(,
[
KernelFunctionFactory.CreateFromMethod(
([Description()] a, [Description()] b) => a + b,
,
)
]);
```text
Enable the model to call functions automatically during chat:
```csharp
settings = AzureOpenAIPromptExecutionSettings
{
FunctionChoiceBehavior = FunctionChoiceBehavior.Auto()
};
chatHistory = ChatHistory();
chatHistory.AddUserMessage();
result = kernel.GetRequiredService<IChatCompletionService>()
.GetChatMessageContentAsync(chatHistory, settings, kernel);
Console.WriteLine(result.Content);
```text
Intercept function calls logging, authorization, modification:
```csharp
:
{
{
(context.Function.Name == )
{
orderId = context.Arguments[]?.ToString();
}
next(context);
}
}
builder.Services.AddSingleton<IFunctionInvocationFilter, AuthorizationFilter>();
```text
---
Prompt templates support variable substitution function calling within structured prompts.
```csharp
result = kernel.InvokePromptAsync(
,
KernelArguments
{
[] = articleText,
[] =
});
```text
Handlebars templates support conditionals, loops, function calls:
```csharp
templateString = ;
factory = HandlebarsPromptTemplateFactory();
template = factory.Create( PromptTemplateConfig(templateString)
{
TemplateFormat = HandlebarsPromptTemplateFactory.HandlebarsTemplateFormat
});
result = template.RenderAsync(kernel, KernelArguments
{
[] = ,
[] = ,
[] = ,
[] = recentOrders
});
```text
Define prompts YAML files separation of concerns:
```yaml
name: Summarize
description: Summarizes text to a specified length
template_format: handlebars
template: |
<message role=>
Summarize the following text approximately {{maxWords}} words.
Focus key facts actionable items.
</message>
<message role=>{{input}}</message>
input_variables:
- name: input
description: The text to summarize
is_required:
- name: maxWords
description: Target word count
:
execution_settings:
:
temperature:
max_tokens:
```text
```csharp
yamlContent = File.ReadAllText();
function = kernel.CreateFunctionFromPromptYaml(yamlContent);
result = kernel.InvokeAsync(function, KernelArguments
{
[] = longText,
[] =
});
```text
---
Semantic Kernel provides abstractions vector storage, enabling retrieval-;
{
[]
Id { ; ; } = .Empty;
[]
Source { ; ; } = .Empty;
[]
Content { ; ; } = .Empty;
[]
ReadOnlyMemory<> Embedding { ; ; }
}
```text
```csharp
Microsoft.SemanticKernel.Connectors.Qdrant;
builder = Kernel.CreateBuilder();
builder.AddAzureOpenAITextEmbeddingGeneration(
deploymentName: ,
endpoint: endpoint,
apiKey: apiKey);
builder.Services.AddQdrantVectorStore(, );
```text
```csharp
{
IVectorStoreRecordCollection<, DocumentRecord> _collection;
ITextEmbeddingGenerationService _embeddingService;
IChatCompletionService _chatService;
{
_collection = vectorStore.GetCollection<, DocumentRecord>();
_embeddingService = embeddingService;
_chatService = chatService;
}
{
questionEmbedding = _embeddingService
.GenerateEmbeddingAsync(question, cancellationToken: ct);
searchResults = _collection.VectorizedSearchAsync(
questionEmbedding,
VectorSearchOptions { Top = },
ct);
contextBuilder = StringBuilder();
( result searchResults)
{
contextBuilder.AppendLine(result.Record.Content);
contextBuilder.AppendLine();
}
chatHistory = ChatHistory();
chatHistory.AddSystemMessage(
);
chatHistory.AddUserMessage(question);
response = _chatService
.GetChatMessageContentAsync(chatHistory, cancellationToken: ct);
response.Content ?? .Empty;
}
}
```text
```
{
_collection.CreateCollectionIfNotExistsAsync(ct);
embedding = _embeddingService
.GenerateEmbeddingAsync(content, cancellationToken: ct);
_collection.UpsertAsync( DocumentRecord
{
Id = documentId,
Content = content,
Source = source,
Embedding = embedding
}, cancellationToken: ct);
}
```text
---
The Semantic Kernel agents framework enables building multi-agent systems specialized agents collaborate tasks.
```csharp
Microsoft.SemanticKernel.Agents;
agent = ChatCompletionAgent
{
Name = ,
Instructions = ,
Kernel = kernel,
Arguments = KernelArguments( AzureOpenAIPromptExecutionSettings
{
FunctionChoiceBehavior = FunctionChoiceBehavior.Auto()
})
};
thread = ChatHistoryAgentThread();
( message agent.InvokeAsync(
, thread))
{
Console.WriteLine(message.Content);
}
```text
Multiple agents can collaborate a chat termination conditions:
```csharp
analyst = ChatCompletionAgent
{
Name = ,
Instructions = ,
Kernel = kernel
};
writer = ChatCompletionAgent
{
Name = ,
Instructions = ,
Kernel = kernel
};
chat = AgentGroupChat(analyst, writer)
{
ExecutionSettings = AgentGroupChatSettings
{
TerminationStrategy = ApprovalTerminationStrategy
{
MaximumIterations =
}
}
};
chat.AddChatMessage(
ChatMessageContent(AuthorRole.User, ));
( message chat.InvokeAsync())
{
Console.WriteLine();
}
```text
For stateful conversations built- = OpenAIAssistantAgent.CreateAsync(
kernel,
OpenAIAssistantDefinition()
{
Name = ,
Instructions = ,
EnableCodeInterpreter =
});
{
thread = agent.CreateThreadAsync();
( message agent.InvokeAsync(
, thread))
{
Console.WriteLine(message.Content);
}
}
{
agent.DeleteAsync();
}
```text
Note: = kernel.GetRequiredService<IChatCompletionService>();
chatHistory = ChatHistory();
chatHistory.AddUserMessage(userInput);
settings = AzureOpenAIPromptExecutionSettings
{
FunctionChoiceBehavior = FunctionChoiceBehavior.Auto()
};
( chunk chatService.GetStreamingChatMessageContentsAsync(
chatHistory, settings, kernel))
{
Console.Write(chunk.Content);
}
```text
---
- **Use function calling over prompt stuffing** -- the model call plugins to retrieve real-time data rather than injecting everything the prompt
- **Keep plugins focused** -- each plugin should represent a single domain; use `[Description]` attributes functions parameters so the model knows how to call them
- **Use YAML prompts production** -- separate prompt content code easier iteration non-developer editing
- **Do store API keys code** -- use environment variables, Azure Key Vault, the .