Crestapps core ai personas

From CrestApps/CrestApps.AgentSkills · View interactive version

Crestapps core ai personas is an AI agent skill from the GitHub repository CrestApps/CrestApps.AgentSkills. Skill for AI personas in CrestApps.Core 2.0, reusable characters with instructions, an assistant name, language, voice and avatar that AI profiles, chat interactions and profile templates link to by name. Covers opting in with AddPersonas and AddYesSqlStores or AddEntityCoreStores, CreateAIPersonaIn

How to use this skill

Skill file

CrestApps.Core AI Personas

A persona says who the assistant is: its instructions, the name it uses, its language, voice and avatar. The profile's system message and prompt templates still say what it does. A resource links to one optional persona by its technical name, so editing the persona changes every profile, interaction and template that links to it from the next message. Personas are not AI templates: a template is copied when used, a persona stays linked.

Guidelines

Registration

builder.Services.AddCrestAppsCore(crestApps => crestApps
    .AddAISuite(ai => ai
        .AddOpenAI()
        .AddPersonas(personas => personas
            .AddYesSqlStores()          // or .AddEntityCoreStores()
            .AddEmbeddedPersonas(typeof(Program).Assembly))
    )
);

AddPersonas (or services.AddCoreAIPersonas()) registers IAIPersonaManager, IAIPersonaResolver, the persona catalog handler, AIPersonaCompletionContextBuilderHandler and AIPersonaFileSystemProvider, which reads Templates/Personas in the content root. A YesSql host also creates the index table once with schemaBuilder.CreateAIPersonaIndexSchemaAsync(yesSqlStoreOptions) next to its other index tables.

What a Persona Holds

| AIPersona property | Purpose |

|---|---|

| Name | Technical name links point to; fixed after save |

| DisplayText, Description | Editor display |

| Instructions | Required persona prompt, rendered as Liquid |

| AssistantName | Name the assistant uses; shown on assistant messages |

| Language | BCP-47 tag used as the speech language when the caller names none |

| VoiceName, VoiceDeploymentName | Provider-specific voice and the deployment it was chosen from |

| AvatarUrl | Optional avatar image |

Managing Personas

IAIPersonaManager is an INamedCatalogManager<AIPersona>. Reads merge saved personas with every IAIPersonaProvider; a saved persona replaces a provided one with the same name. Only saved personas can be updated or deleted.

using System.Text.Json.Nodes;
using CrestApps.Core.AI.Profiles;

var persona = await personaManager.NewAsync("friendly-assistant", new JsonObject
{
    ["DisplayText"] = "Friendly assistant",
    ["Instructions"] = "You are a warm, patient assistant for {{ company }}. Keep answers short.",
    ["AssistantName"] = "Ava",
    ["Language"] = "en-US",
});

var validation = await personaManager.ValidateAsync(persona);

if (validation.Succeeded)
{
    await personaManager.CreateAsync(persona);
}

Validation requires a unique name and instructions.

Persona Files

---
Title: Friendly assistant
Description: Warm, patient and plain-spoken.
AssistantName: Ava
Language: en-US
---

You are Ava, a warm and patient assistant. Use plain words, keep answers short,
and ask one question at a time when you need more detail.

Place files in Templates/Personas under the content root, or embed them under Templates/Personas in an assembly and call AddEmbeddedPersonas(assembly) (or services.AddCoreAIPersonasFromAssembly(assembly)). The path below that folder, without extension, becomes the technical name.

Linking a Persona

using CrestApps.Core.AI.Models;

profile.Put(new AIPersonaMetadata
{
    PersonaId = "friendly-assistant",
    Parameters = new Dictionary<string, object>
    {
        ["company"] = "Contoso",
    },
});

await profileManager.UpdateAsync(profile);

How It Is Applied

AIPersonaCompletionContextBuilderHandler runs in BuiltAsync, after the profile or interaction handlers produced the system message. It resolves the persona and calls ResolvedAIPersona.PrependTo(systemMessage):

Your name is Ava.
persona instructions (Liquid, with link Parameters and assistant_name)

selected prompt templates

the profile's or interaction's own system message

The resolved persona is also stored under AICompletionContextKeys.Persona in AICompletionContext.AdditionalProperties, and realtime sessions read their instructions from the same completion context. A link parameter named assistant_name overrides the persona's name in the Liquid variables. A Liquid error drops the instructions but keeps the rest of the persona. A deleted or unknown persona is logged and the request carries on without it.

Voice

The chat hubs pick a voice in one order: the explicit voice (the caller's, or the profile's or interaction's own), then the persona's, then the deployment default.

var persona = await serviceProvider.ResolvePersonaAsync(profile, cancellationToken);

var voice = await serviceProvider.SelectPersonaVoiceAsync(
    persona,
    explicitVoice: requestedVoice,
    speakingDeploymentName: speakingDeployment.Name,
    defaultVoice: defaultVoice,
    cancellationToken);

The persona's voice is skipped, with a warning, when its VoiceDeploymentName belongs to a different provider than the speaking deployment; for a cascaded realtime deployment the text-to-speech leg is compared. The persona's Language becomes the speech language when the caller names none. The IServiceProvider helpers return null (or the explicit and default voice) when personas are not registered, so shared code works in either kind of host.

Assistant Name and Avatar in Chat

using CrestApps.Core.AI.Profiles;

AIChatAssistantDisplay display = await serviceProvider.ResolveChatAssistantDisplayAsync(profile, cancellationToken);

var label = display.GetAssistantLabel("Assistant");
var avatarUrl = display.AvatarUrl;

Pass the values to @crestapps/ai-chat-ui as assistantLabel and assistantAvatarUrl (data-coreai-chat-assistant-avatar-url). A custom message template calls getAssistantAvatarUrl(message); a custom typing indicator can use the {{ assistantIcon }} token. Without a persona the chat keeps its label and robot icon. IAIPersonaResolver.ResolveChatAssistantDisplayAsync(resource) and ResolvedAIPersona.ToChatAssistantDisplay() return the same shape.

Custom Persona Source

using CrestApps.Core.AI.Models;
using CrestApps.Core.AI.Profiles;

public sealed class BrandPersonaProvider : IAIPersonaProvider
{
    public Task<IReadOnlyList<AIPersona>> GetPersonasAsync(CancellationToken cancellationToken = default)
    {
        IReadOnlyList<AIPersona> personas =
        [
            new AIPersona
            {
                Name = "brand-voice",
                DisplayText = "Brand voice",
                Instructions = "You speak for Contoso: friendly, concise, never salesy.",
                AssistantName = "Contoso Assistant",
                Language = "en-US",
            },
        ];

        return Task.FromResult(personas);
    }
}
builder.Services.AddSingleton<IAIPersonaProvider, BrandPersonaProvider>();

Provided personas are read-only; saving one with the same name in the persona store replaces it.

Related Skills

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.