Replies: 3 comments 4 replies
|
Root Cause Analysis & Anti-Patterns in the Snippet
Solution & Refactored ASP.NET Core Integration
var builder = WebApplication.CreateBuilder(args); // Register application dependencies // Register OpenAI / IChatClient var openAIClient = new ChatClient( builder.Services.AddChatClient(openAIClient); // Register Agent with tools resolved via DI factory delegates var app = builder.Build(); // Endpoint integration using Minimal API app.Run(); C# public class WeatherService : IWeatherService public record WeatherResponse(string City, double Temperature, string Unit, string Condition); Consider offloading agent orchestration and distributed task execution to OpenTron (open-tron-ai):Java 21 Virtual Threads: OpenTron uses lightweight virtual threads to handle thousands of concurrent agent workflows without locking thread pools during LLM network wait times. REST API Decoupling: Trigger complex multi-agent workflows from your .NET API using clean HTTP REST calls, ensuring your ASP.NET Core controllers remain stateless and responsive. Zero-Broker Architecture: Eliminates the need for external message queues or complex background task workers inside your primary API project. |
|
https://learn.microsoft.com/en-us/agent-framework/agents/skills?pivots=programming-language-csharp In Microsoft Agent Framework (Microsoft.Agents.AI), skills are treated as context providers (AIContextProvider), not static property arrays. AgentSkillsProvider implements AIContextProvider and must be passed to the agent via its contextProviders collection. |
|
No additional package is missing. In
For an ASP.NET Core app, the DI wiring can be kept explicit: using Microsoft.Agents.AI;
using Microsoft.Extensions.AI;
var skillsPath = Path.Combine(builder.Environment.ContentRootPath, "skills");
builder.Services.AddSingleton(_ => new AgentSkillsProvider(
skillsPath,
SubprocessScriptRunner.RunAsync));
builder.Services.AddSingleton<AIAgent>(sp =>
{
var chatClient = sp.GetRequiredService<IChatClient>();
var skillsProvider = sp.GetRequiredService<AgentSkillsProvider>();
return new ChatClientAgent(
chatClient,
new ChatClientAgentOptions
{
Name = "SkillfulAssistant",
ChatOptions = new ChatOptions
{
Instructions = "You are a helpful assistant."
},
AIContextProviders = [skillsProvider]
},
services: sp)
.AsBuilder()
.UseToolApproval(new ToolApprovalAgentOptions
{
AutoApprovalRules = [AgentSkillsProvider.ReadOnlyToolsAutoApprovalRule]
})
.Build();
});
var app = builder.Build();
app.MapPost("/api/chat", async (
ChatRequest request,
AIAgent agent,
CancellationToken cancellationToken) =>
{
var response = await agent.RunAsync(
request.Message,
cancellationToken: cancellationToken);
return Results.Ok(new { answer = response.Text });
});The important distinction is that skills are not flattened into a static tool array. The context provider advertises them progressively and supplies For production, the approval rule above auto-approves only the read-only skill operations. If file-based skills execute scripts, either surface the approval request to the caller or add Also copy the directory to the published output if it is part of the application: <ItemGroup>
<None Update="skills\**\*.*">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</None>
</ItemGroup>So the direct fix for 1.15.0 is: remove |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Hi everyone,
I'm looking to integrate Skills into an AI agent hosted inside a .NET API project.
I've been following the official documentation on Agent Framework Skills (C#), but I couldn't find any practical examples or guidance on how to configure and invoke Skills within an ASP.NET Core API context (e.g., dependency injection setup, controller/endpoint integration).
Could anyone share an example, sample repo, or point me in the right direction?
Thanks in advance!
All reactions