Crestapps core ai templates

From CrestApps/CrestApps.AgentSkills · View interactive version

Crestapps core ai templates is an AI agent skill from the GitHub repository CrestApps/CrestApps.AgentSkills. Skill for Liquid prompt templates in CrestApps.Core 2.0. Covers AddCoreAITemplating and AddTemplating registration, Markdown templates with front matter under Templates and Templates Prompts, AddTemplatesFromAssembly, code and discovery-path templates through TemplateOptions, ITemplateService ListAs

How to use this skill

Skill file

CrestApps.Core AI Templates

Prompts are Markdown files with YAML front matter, rendered with Liquid (Fluid) and discovered from embedded resources, the file system, code, or custom providers.

Guidelines

Registration

using CrestApps.Core.Templates.Extensions;

builder.Services.AddCoreAITemplating(options =>
{
    options.AddDiscoveryPath("/app/templates");
});

// Embedded .md resources under Templates/ in an assembly.
builder.Services.AddTemplatesFromAssembly(typeof(Program).Assembly, source: "MyApp");

AddCoreAITemplating() builds on AddTemplating() and adds the Profile and SystemPrompt template sources, the AI profile template manager, and AIProfileSystemPromptTemplateProvider.

| Service | Purpose |

|---|---|

| ITemplateService (DefaultTemplateService) | Discover, render and merge |

| ITemplateEngine (FluidTemplateEngine) | Render and validate Liquid |

| ITemplateParser | Parse Markdown front matter |

| OptionsTemplateProvider, FileSystemTemplateProvider, PromptsFileSystemTemplateProvider | Code, Templates/, Templates/Prompts/ |

| AIProfileSystemPromptTemplateProvider | SystemPrompt AI profile templates from the profile template store |

Template Example

---
Title: Customer Support Assistant
Description: Prompt for a customer support chatbot
Category: Support
IsListable: true
---
You are a customer support assistant for {{ company_name | default: "our company" }}.

{% if support_hours %}
Support hours are {{ support_hours }}.
{% endif %}

Front matter fields are Title, Description, Category, IsListable (default true) and Kind. The file name without extension is the template id. ITemplateParser.Parse(content) returns a TemplateParseResult with Metadata and Body.

Using Templates

using CrestApps.Core.Templates.Services;

var templates = await templateService.ListAsync(cancellationToken);

var prompt = await templateService.RenderAsync(
    "customer-support",
    new Dictionary<string, object> { ["company_name"] = "Contoso" },
    cancellationToken);

var systemPrompt = await templateService.MergeAsync(
    ["base-personality", "safety-rules", "rag-instructions"],
    new Dictionary<string, object> { ["user_name"] = userName },
    separator: "\n\n---\n\n",
    cancellationToken);

Validate user-authored Liquid before saving:

using CrestApps.Core.Templates.Rendering;

if (!templateEngine.TryValidate(content, out var errors))
{
    // errors is IList<string>
}

Selecting Templates on a Profile

profile.Put(new PromptTemplateMetadata
{
    Templates =
    [
        new PromptTemplateSelectionEntry
        {
            TemplateId = "customer-support",
            Parameters = new Dictionary<string, object> { ["company_name"] = "Contoso" },
        },
    ],
});

The profile context handler renders the selections into the system message. A linked persona's block is placed before them, and the profile's own system message after them.

Seeded System Prompt Defaults

Speaking styles and guardrail topics are System Prompt templates in their own category (Speaking style, Guardrail topic). Their defaults are not served read-only: they ship as Markdown embedded under SystemPromptDefaults and are copied once into the saved AI profile templates, where users can edit or delete them. AddSpeakingStyles() and AddGuardrails() register the framework's defaults.

using CrestApps.Core.AI.Services;

// Once, from a migration or a setup step, with the AI profile template store registered.
var seeder = serviceProvider.GetRequiredService<IAISystemPromptTemplateSeeder>();
IReadOnlyList<string> created = await seeder.SeedAsync(); // or SeedAsync(AISpeakingStyles.Category)
---
Title: Echo Verification
Description: Reads back what the customer gave before acting on it
IsListable: false
Category: Speaking style
---

## Read back what you are given

When the customer gives you something you will act on or record, repeat it back once and ask them to confirm.

Fill a picker from one category, file-based and saved templates together, deduplicated by id and ordered by title:

using CrestApps.Core.AI.Models;
using CrestApps.Core.AI.Services;
using CrestApps.Core.Templates.Models;

IReadOnlyList<AITemplateOption> styles = await templateService.ListOptionsByCategoryAsync(AISpeakingStyles.Category, cancellationToken);
IReadOnlyList<Template> topics = await templateService.ListByCategoryAsync(AIGuardrailTopics.Category, cancellationToken);

AITemplateOption is (Id, Title, Description); AITemplateCategoryExtensions.GetTitle(template) falls back to the id.

Custom Providers

using CrestApps.Core.Templates.Models;
using CrestApps.Core.Templates.Parsing;
using CrestApps.Core.Templates.Providers;

public sealed class DatabaseTemplateProvider : IDynamicTemplateProvider
{
    private readonly IPromptRecordStore _store;
    private readonly ITemplateParser _parser;

    public DatabaseTemplateProvider(IPromptRecordStore store, ITemplateParser parser)
    {
        _store = store;
        _parser = parser;
    }

    public async Task<IReadOnlyList<Template>> GetTemplatesAsync(CancellationToken cancellationToken = default)
    {
        var templates = new List<Template>();

        foreach (var record in await _store.ListAsync(cancellationToken))
        {
            var parsed = _parser.Parse(record.Content);

            templates.Add(new Template
            {
                Id = record.Name,
                Aliases = [$"legacy:{record.Id}"],
                Metadata = parsed.Metadata,
                Content = parsed.Body,
                Kind = "SystemPrompt",
                Source = "Database",
            });
        }

        return templates;
    }
}
builder.Services.AddScoped<ITemplateProvider, DatabaseTemplateProvider>();

IPromptRecordStore stands for the application's own storage. Use plain ITemplateProvider for templates that never change while the app runs.

Troubleshooting

Upgrading from 1.x

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.