← All source files

V13 / 7879e8b5740b

ProviderClient.Subagents.cs

Lilith/Core/Providers/ProviderClient.Subagents.cs

Unchanged from the preceding version
CS
using Lilith.Core.Scenarios;

namespace Lilith.Core.Providers;

public abstract partial class ProviderClient
{
    public SubagentRegistry Subagents { get; } = new();
    private volatile bool _showSubagentOutput;
    public bool ShowSubagentOutput { get => _showSubagentOutput; set => _showSubagentOutput = value; }
    public event Action<SubagentOutput>? SubagentOutput;

    private void ReportSubagent(ScenarioProgress progress)
    {
        var output = SubagentRegistry.Present(progress, Subagents.Observe(progress), ShowSubagentOutput);
        if (output is null) return;
        Logger.WriteLine("Subagent " + output.AgentId, output.IsSummary ? output.Text : output.Kind + ": " + output.Text, LogColors.Cyan);
        if (SubagentOutput is not { } handlers) return;
        foreach (var handler in handlers.GetInvocationList().Cast<Action<SubagentOutput>>())
            try { handler(output); }
            catch (Exception ex) { Logger.WriteWarning("Subagent", "Output observer failed: " + ex.Message); }
    }
}