summaryrefslogtreecommitdiff
path: root/src/Agent.Core/Prompts/PromptComposer.cs
blob: 69b18f3faefb9ac78b069e413804ec54c1969944 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
using Agent.Core.Ollama;
using Agent.Core.Sessions;
using Agent.Core.Skills;

namespace Agent.Core.Prompts;

public sealed record PromptContext(
    string FixedSystemPrompt,
    string UserSystemPrompt,
    string Locale,
    IReadOnlyList<AgentSkill> AvailableSkills,
    IReadOnlyList<AgentSkill> SelectedSkills,
    string SandboxCapabilitySummary,
    string TaskGraphSummary,
    string PreviousSummary,
    IReadOnlyList<ConversationMessage> Conversation,
    string Request,
    IReadOnlyList<string>? Images = null);

public static class PromptComposer
{
    public static IReadOnlyList<OllamaMessage> Compose(PromptContext context)
    {
        var messages = new List<OllamaMessage>
        {
            new("system", context.FixedSystemPrompt),
            new("system", context.UserSystemPrompt),
            new("system", $"Respond in locale: {context.Locale}."),
            new("system", ComposeSkillCatalog(context.AvailableSkills)),
            new("system", context.SandboxCapabilitySummary),
            new("system", context.TaskGraphSummary),
            new("system", context.PreviousSummary)
        };
        // Inject selected skill instructions (Progressive Disclosure Stage 3).
        foreach (AgentSkill skill in context.SelectedSkills)
            messages.Add(new("system", skill.Instructions));
        messages.AddRange(context.Conversation.Select(static item => new OllamaMessage(item.Role, item.Content)));
        messages.Add(new OllamaMessage("user", context.Request, context.Images));
        return messages;
    }

    /// <summary>
    /// Stage 1 Discovery: only name + description are included. Full instructions are NOT included.
    /// </summary>
    private static string ComposeSkillCatalog(IReadOnlyList<AgentSkill> skills)
    {
        if (skills.Count == 0) return "No skills available.";
        var lines = new List<string> { "Available skills:" };
        foreach (AgentSkill skill in skills)
            lines.Add($"- {skill.Name}: {skill.Description}");
        lines.Add("If a skill is relevant to the request, indicate which skills to use.");
        return string.Join("\n", lines);
    }
}