Add agent system with Core and Librarian agent implementations

Define IAgent interface and implement CoreAgent (main conversational
agent) and LibrarianAgent (knowledge retrieval agent). Includes DI
service collection extensions for agent registration.
This commit is contained in:
2026-04-04 04:10:51 +02:00
parent 1c42c8c006
commit 29eb3851c9
6 changed files with 206 additions and 0 deletions
+55
View File
@@ -0,0 +1,55 @@
using System.Text.Json;
using Luna.Agents.Abstractions;
using Luna.Configuration;
using Luna.Providers.Abstractions;
using Microsoft.Extensions.AI;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.Extensions.Options;
namespace Luna.Agents.Core;
public class CoreAgent(
[FromKeyedServices("Mistral")] IProvider provider,
IOptionsMonitor<AgentOptions> options,
ILogger<CoreAgent> logger)
: IAgent
{
private readonly IChatClient chatClient = provider.GetChatClient(options.Get(Name).ModelId);
public static string Name => "Core";
public string DisplayName => Options.DisplayName ?? Name;
public string Description => Options.Description ?? string.Empty;
public AgentOptions Options { get; init; } = options.Get(Name);
public async Task<IEnumerable<ChatMessage>> ProcessAsync(
IReadOnlyList<ChatMessage> messages,
CancellationToken ct = default)
{
var messagesJson = JsonSerializer.Serialize(messages);
logger.LogInformation("Processing messages: {MessagesJson}", messagesJson);
var chatOptions = new ChatOptions
{
Instructions = Options.Instructions
};
var response = await chatClient.GetResponseAsync(messages, chatOptions, ct);
logger.LogInformation("Response: {ResponseJson}", JsonSerializer.Serialize(response));
return response.Messages;
}
public IAsyncEnumerable<ChatResponseUpdate> ProcessStreamingAsync(
IReadOnlyList<ChatMessage> messages,
CancellationToken ct = default)
{
var chatOptions = new ChatOptions
{
Instructions = Options.Instructions
};
return chatClient.GetStreamingResponseAsync(messages, chatOptions, ct);
}
}