Crestapps core ai memory

From CrestApps/CrestApps.AgentSkills · View interactive version

Crestapps core ai memory is an AI agent skill from the GitHub repository CrestApps/CrestApps.AgentSkills. Skill for AI memory in CrestApps.Core. Covers AddAIMemory, AddCoreAIMemory and AddCoreAIMemoryIndexing, Entity Framework Core and YesSql memory stores, the AIMemory index profile on the Elasticsearch, Azure AI Search and PostgreSQL backends, AIMemoryOptions, the store fallback when no index is usabl

How to use this skill

Skill file

CrestApps.Core AI Memory

Three kinds of memory share one registration:

| Kind | Remembers | Switch | Covers |

|---|---|---|---|

| Session memory | the earlier part of a long conversation | MemoryMetadata.EnableSessionMemory; ChatInteractionMemoryOptions.EnableSessionMemory (default true) | the conversation itself, including anonymous visitors |

| Past conversations | the user's earlier conversations with the same profile | MemoryMetadata.EnablePastConversations | signed-in users only |

| User memory | durable facts (preferences, projects, roles) | MemoryMetadata.EnableUserMemory; ChatInteractionMemoryOptions.EnableUserMemory (default true) | signed-in users only |

Registration

builder.Services.AddCrestAppsCore(crestApps => crestApps
    .AddAISuite(ai => ai
        .AddOpenAI()
        .AddAIMemory(memory => memory
            .AddEntityCoreStores()))   // or .AddYesSqlStores()
    .AddIndexingServices(indexing => indexing
        .AddEntityCoreStores()
        .AddElasticsearch(
            builder.Configuration.GetSection("CrestApps:Elasticsearch"),
            elasticsearch => elasticsearch.AddAIMemory()))
    .AddEntityCoreSqliteDataStore("Data Source=app.db"));

builder.Services.Configure<AIMemoryOptions>(options =>
{
    options.IndexProfileName = "user-memories"; // an index profile of type AIMemory
    options.TopN = 5;
});

Turning Memory On

using CrestApps.Core.AI.Models;

profile.Put(new MemoryMetadata
{
    EnableUserMemory = true,
    EnableSessionMemory = true,
    EnablePastConversations = true,
});

Search Without an Index

IAIMemorySearchService falls back to the memory store when no index profile is configured, the configured one is missing, is not an AIMemory profile, has no vector-search provider or no resolvable embedding deployment (one warning per profile name), or the index holds nothing for the user. The fallback reads up to 200 of the user's memories and ranks them by the share of query terms found in name, description and content, then by most recently updated.

Session Memory

With a positive past-messages count, messages that fall outside the window are no longer simply dropped:

Past Conversations

search_past_conversations and list_recent_conversations search the signed-in user's own conversations with the same profile, newest first, matching title, stored summary and transcript. The store query filters with AIChatSessionQueryContext.UserId, and every result is checked again against the user and profile, so a store that ignores the filter leaks nothing and logs a warning. They are not offered to anonymous visitors. Tool purposes: AIToolPurposes.ConversationMemory and AIToolPurposes.PastConversations.

Session Ownership

AIChatHubCore calls AuthorizeSessionAsync before it loads, continues, rates or acts on a session by id. By default only the signed-in user who started it, or the same visitor, gets in; another id is reported as not found, and a message sent to it starts a new session. Override it to let staff open other users' conversations (see crestapps-core-chat-interactions).

Tools

| Tool | Use |

|---|---|

| save_user_memory | create or update a memory by name |

| search_user_memories | semantic search over the user's memories (store fallback without an index) |

| list_user_memories | list what is already known |

| remove_user_memory | forget a memory |

| search_conversation | search the earlier part of the current conversation (session memory) |

| search_past_conversations | search the user's earlier conversations with the profile |

| list_recent_conversations | list the user's most recent earlier conversations with the profile |

The conversation tools are offered only when their feature is on and there is something to read.

Contracts

| Contract | Role |

|---|---|

| IAIMemoryStore | ICatalog<AIMemoryEntry> plus CountByUserAsync, FindByUserAndNameAsync, GetByUserAsync |

| IAIMemorySearchService | shared semantic retrieval |

| IMemoryVectorSearchService | provider-keyed vector search adapter |

| IAIMemorySafetyService | TryValidate(name, description, content, out errorMessage) before a write |

AIMemoryEntry holds UserId, Name, Description, Content, CreatedUtc and UpdatedUtc.

Custom Safety Rules

using CrestApps.Core.AI.Memory;

public sealed class StrictMemorySafetyService : IAIMemorySafetyService
{
    private static readonly string[] _blockedWords = ["password", "api key", "secret"];

    public bool TryValidate(string name, string description, string content, out string errorMessage)
    {
        var text = $"{name} {description} {content}";

        foreach (var word in _blockedWords)
        {
            if (text.Contains(word, StringComparison.OrdinalIgnoreCase))
            {
                errorMessage = "Memories cannot contain credentials or secrets.";

                return false;
            }
        }

        errorMessage = null;

        return true;
    }
}

builder.Services.AddScoped<IAIMemorySafetyService, StrictMemorySafetyService>();

The default registration is a TryAdd, so register your implementation before or after AddAIMemory(...); a plain AddScoped registered later wins for single resolution.

Custom Vector Backend

Implement IMemoryVectorSearchService.SearchAsync(SearchIndexProfile indexProfile, float[] embedding, string userId, int topN, CancellationToken) and register it keyed by the provider name of the memory index profile. Always filter by userId so one user can never retrieve another user's memories.

Upgrading Within 2.0 Previews

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.