Crestapps core extensible entities

From CrestApps/CrestApps.AgentSkills · View interactive version

Crestapps core extensible entities is an AI agent skill from the GitHub repository CrestApps/CrestApps.AgentSkills. Skill for storing typed extension data on CrestApps.Core extensible entities (ExtensibleEntity, CatalogItem, AIProfile, AIDeployment, ChatInteraction and others). Covers the Properties bag and JsonExtensionDataConverter, the Put, TryGet, GetOrCreate, Get, Alter, Has and Remove extension methods with

How to use this skill

Skill file

CrestApps.Core Extensible Entities

You are a CrestApps.Core expert. Generate code for typed metadata stored in ExtensibleEntity.Properties.

Guidelines

Methods

| Method | Constraint | Behavior |

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

| Put<T>(value) | T : new() | Stores under typeof(T).Name and returns the entity |

| Put(name, value) | none | Stores under an explicit key |

| TryGet<T>(out value) | T : class | Returns false when the key is missing or null; no allocation |

| GetOrCreate<T>() | T : new() | Returns the stored value or a new, unstored instance |

| Get<T>(name) | none | Reads an explicit key, or default |

| Alter<T>(action) | T : new() | Gets or creates, runs the action, and stores the result |

| Has<T>() | none | Checks for the type-name key |

| Remove<T>() | none | Removes the type-name key |

TryGet, GetOrCreate, Get and Alter accept an optional JsonSerializerOptions to override the shared options for one call.

Typed Metadata

using CrestApps.Core;

namespace MyApp.Metadata;

public sealed class BillingMetadata
{
    public string InvoicePrefix { get; set; }

    public decimal MonthlyBudget { get; set; }
}
profile.Put(new BillingMetadata
{
    InvoicePrefix = "INV",
    MonthlyBudget = 250m,
});

if (profile.TryGet<BillingMetadata>(out var billing))
{
    logger.LogInformation("Budget {Budget}", billing.MonthlyBudget);
}

profile.Alter<BillingMetadata>(metadata => metadata.MonthlyBudget = 300m);

// Persist the change through the manager or catalog; the bag is only in memory until saved.
await profileManager.UpdateAsync(profile);

GetOrCreate<T>() does not store the new instance. Call Put(...) after mutating it, or use Alter<T>(...).

Framework Metadata Uses the Same Bag

Framework features keep their settings in the bag. For example, deployment capabilities are an AIDeploymentMetadata entry:

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

deployment.Put(new AIDeploymentMetadata
{
    Features =
    [
        AIDeploymentFeatureNames.TextGeneration,
        AIDeploymentFeatureNames.ToolCalling,
        AIDeploymentFeatureNames.Streaming,
    ],
});

Because the key is the type name, configuration and recipes supply the same data under Properties:

{
  "Name": "gpt-4.1",
  "ConnectionName": "primary-openai",
  "ModelName": "gpt-4.1",
  "Properties": {
    "AIDeploymentMetadata": {
      "Features": [ "textGeneration", "toolCalling", "streaming" ]
    }
  }
}

Configured deployments also accept Features and Parameters directly on the entry as a shorter form of the same keys; see crestapps-core-ai-model-capabilities.

Configure Serialization

AddCrestAppsCore(...) registers ExtensibleEntityJsonOptions and an internal hosted service that copies ExtensibleEntityJsonOptions.SerializerOptions into the static ExtensibleEntityExtensions.JsonSerializerOptions when the host starts.

builder.Services.Configure<ExtensibleEntityJsonOptions>(options =>
{
    options.SerializerOptions.Converters.Add(new MoneyJsonConverter());
});

ExtensibleEntityJsonOptions.CreateDefaultSerializerOptions() sets WhenWritingNull, JsonObjectCreationHandling.Populate, case-insensitive names, skipped comments, trailing commas, number reading from strings, and JsonStringEnumConverter.

Without a started host (a console tool, a unit test that builds a ServiceProvider directly, or a host that does not call AddCrestAppsCore), assign the static options before the first read or write:

var options = ExtensibleEntityJsonOptions.CreateDefaultSerializerOptions();
options.Converters.Add(new MoneyJsonConverter());

ExtensibleEntityExtensions.JsonSerializerOptions = options;

JsonSerializerOptions becomes read-only after its first use, so configure it during startup only.

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.