Skip to content

@memberjunction/ai-core-plus

Shared type definitions and extended entity classes for the MemberJunction AI Framework. This package bridges the gap between the standalone @memberjunction/ai core and the full MJ entity system, providing types that are usable on both server and client. It defines prompt execution result types, agent execution types, system placeholder management, conversation utilities, and extended entity classes with additional computed properties.

graph TD
    AI["@memberjunction/ai"]
    style AI fill:#2d6a9f,stroke:#1a4971,color:#fff

    CORE["@memberjunction/core"]
    style CORE fill:#2d6a9f,stroke:#1a4971,color:#fff

    CE["@memberjunction/core-entities"]
    style CE fill:#2d6a9f,stroke:#1a4971,color:#fff

    ACP["@memberjunction/ai-core-plus"]
    style ACP fill:#2d8659,stroke:#1a5c3a,color:#fff

    subgraph "ai-core-plus Modules"
        PT["Prompt Types<br/>AIPromptParams, AIPromptRunResult"]
        style PT fill:#7c5295,stroke:#563a6b,color:#fff

        AT["Agent Types<br/>ExecuteAgentParams, ExecuteAgentResult"]
        style AT fill:#7c5295,stroke:#563a6b,color:#fff

        SP["System Placeholders<br/>Date/Time, User Context"]
        style SP fill:#b8762f,stroke:#8a5722,color:#fff

        EXT["Extended Entities<br/>AIPrompt, AIModel, AIAgent"]
        style EXT fill:#2d6a9f,stroke:#1a4971,color:#fff

        CU["ConversationUtility"]
        style CU fill:#b8762f,stroke:#8a5722,color:#fff

        RF["Response Forms<br/>& UI Commands"]
        style RF fill:#7c5295,stroke:#563a6b,color:#fff
    end

    AI --> ACP
    CORE --> ACP
    CE --> ACP
    ACP --> PT
    ACP --> AT
    ACP --> SP
    ACP --> EXT
    ACP --> CU
    ACP --> RF
Terminal window
npm install @memberjunction/ai-core-plus
Type / ClassPurpose
AIPromptParamsFull parameter set for prompt execution: prompt reference, data context, configuration, child prompts, streaming callbacks, cancellation, credential overrides, effort level, and more
AIPromptRunResult<T>Generic result from prompt execution including raw/parsed output, token usage, cost, validation attempts, model selection info, and media references
ChildPromptParamLinks a child prompt to a placeholder in a parent template for hierarchical composition
AIModelSelectionInfoDebugging info about which models were considered and why one was selected
ExecutionProgressCallbackCallback for real-time execution progress (template rendering, model selection, execution, validation)
ExecutionStreamingCallbackCallback for streaming content chunks during execution
ValidationAttemptDetailed record of each validation attempt with attempt number, errors, and raw/parsed output
PromptRunMediaReferenceReference to generated media (image, audio, video) with metadata
ExecutionStatusStatus enum: 'Pending', 'Running', 'Completed', 'Failed', 'Cancelled'
Type / ClassPurpose
ExecuteAgentParamsParameters for agent execution: agent reference, messages, conversation context, user scope, configuration presets, effort level, action changes, and callbacks
ExecuteAgentResultAgent execution result with success status, output messages, actions performed, sub-agent requests, and model selection info
AgentContextDataContextual data injected into agent prompts (notes, examples, data sources)
AgentConfigurationRuntime configuration for an agent run (model overrides, effort level, max iterations)
UserScopeMulti-tenant scoping for agent memory with primary/secondary dimensions
AgentActionDescription of an action an agent wants to execute
AgentSubAgentRequestRequest from one agent to delegate work to a sub-agent
AgentChatMessage / AgentChatMessageMetadataChat messages with lifecycle metadata (expiration, compaction)
MediaOutputMedia generated by an agent (modality, MIME type, data)
ActionChange / ActionChangeScopeRuntime action customization for multi-tenant scenarios

Consolidation Observability in ExecuteAgentResult

Section titled “Consolidation Observability in ExecuteAgentResult”

ExecuteAgentResult surfaces the agent run’s step list. As of v5.30.x, MemoryManagerAgent runs emit two new step types when its consolidation pipeline executes:

Step nameCardinalityNotable payload fields
Process Consolidation ClusterOne per cluster identifiedclusterSize, noteIds, shouldConsolidate, consolidatedNoteId, sourceNotesArchived, verificationPassed, entitiesChecked, entitiesMissing
Verify Consolidation OutputOne per maintenance runPhase-level summary of post-consolidation entity coverage check

Run-level payload additions include scoreDistribution, entityTriplesExtracted, decayScoreDistribution, protectedPreserved, ephemeralAccelerated, and triggerType ('forced' / 'time' / 'event' / 'count'). These flow through unchanged via ExecuteAgentResult.steps[*].outputData — consumers that already deserialize step output data will pick them up without code changes.

For pipeline mechanics, see @memberjunction/ai-agents.

System Placeholders (prompt.system-placeholders.ts)

Section titled “System Placeholders (prompt.system-placeholders.ts)”

The SystemPlaceholderManager automatically injects common values into all prompt templates:

  • {{CurrentDate}}, {{CurrentTime}}, {{CurrentDateTime}} — Current date/time in user’s timezone
  • {{CurrentTimezone}} — User’s timezone identifier
  • {{UserName}}, {{UserEmail}}, {{UserFirstName}}, {{UserLastName}} — User context
  • Custom placeholders can be registered at runtime
ClassExtendsAdditional Properties
AIPromptEntityExtendedAIPromptEntityPrompt category associations, template relationships
AIPromptCategoryEntityExtendedAIPromptCategoryEntityPrompts array of child prompts
AIModelEntityExtendedAIModelEntityModelVendors array, vendor association helpers
AIAgentEntityExtendedAIAgentEntityActions, Notes arrays, agent relationships
AIAgentRunEntityExtendedAIAgentRunEntityExtended run tracking
AIAgentRunStepEntityExtendedAIAgentRunStepEntityExtended step tracking
AIPromptRunEntityExtendedAIPromptRunEntityExtended prompt run tracking
ExportPurpose
ConversationUtilityHelper for creating, loading, and managing conversation records
AgentResponseFormStructured response format definitions for agent outputs
ActionableCommand / AutomaticCommandUI command types for agent-driven interfaces
AgentPayloadChangeRequestRequest to modify agent payload data during execution
ForEachOperation / WhileOperationLoop operation definitions for flow-based agents
import { AIPromptParams, ChildPromptParam } from '@memberjunction/ai-core-plus';
const params = new AIPromptParams();
params.prompt = myPromptEntity;
params.data = { customerName: 'Acme Corp', orderCount: 42 };
params.contextUser = currentUser;
params.effortLevel = 75;
// Hierarchical prompt composition
params.childPrompts = [
new ChildPromptParam(analysisParams, 'analysis'),
new ChildPromptParam(summaryParams, 'summary')
];
// Model override at runtime
params.override = {
modelId: 'specific-model-id',
vendorId: 'specific-vendor-id'
};
// Force the runner to credential-check EVERY candidate model-vendor combination
// instead of short-circuiting at the first usable one. Default false — only enable
// for diagnostics that need a complete per-candidate availability report, since it
// runs a credential lookup for every configured model on the run.
params.forceFullModelEvaluation = true;
FieldTypePurpose
promptMJAIPromptEntityExtendedRequired. The prompt to execute.
dataRecord<string, unknown>Data context merged into the template (user data overrides system placeholders).
templateDataRecord<string, unknown>Highest-priority template data (overrides data).
contextUserUserInfoRequired server-side. The user the run executes as (security/audit).
configurationIdstringAI Configuration scoping model selection (supports inheritance chains).
conversationMessagesChatMessage[]Prior conversation turns appended after the rendered prompt.
templateMessageRole'system' | 'user' | 'none'Where the rendered prompt lands in the message array.
override{ modelId?, vendorId? }Runtime model/vendor override (highest selection precedence).
modelSelectionPromptMJAIPromptEntityExtendedUse a different prompt’s model config for selection.
forceFullModelEvaluationbooleanProbe credentials for every candidate instead of short-circuiting (default false).
childPromptsChildPromptParam[]Hierarchical template composition (children render first).
parentPromptRunId / agentRunIdstringLink this run to a parent prompt run / agent run.
rerunFromPromptRunIDstringMark this run as a re-run of a prior one.
effortLevelnumberReasoning effort override (highest precedence — see Effort Level Control).
additionalParametersRecord<string, any>Override inference params (temperature/topP/seed/stopSequences/…) per request.
systemPromptOverridestringBypass template rendering and use this system prompt verbatim.
skipValidationbooleanSkip output validation/parsing.
cleanValidationSyntaxbooleanStrip ?/*/:type markers from result keys (auto-on when OutputExample set).
attemptJSONRepairbooleanRepair malformed JSON object output via JSON5 then LLM repair.
credentialIdstringPer-request credential override (highest credential precedence).
apiKeysAIAPIKey[]Legacy per-request API keys (used only if no credential bindings resolve).
nativeFileInputsNativeFileInput[]Files attached natively when the driver supports the modality (else text fallback).
cancellationTokenAbortSignalCooperative cancellation, checked at each phase.
onProgress / onStreamingcallbacksProgress updates / streamed output chunks.
onPromptRunCreated(promptRunId) => voidFired with the AIPromptRun.ID as soon as the record is created (ID available immediately; the save is fire-and-forget).
verbosebooleanVerbose status logging for this run.
maxErrorLengthnumberTruncate long error messages (e.g. provider failed-generation dumps).
providerIMetadataProviderMetadata provider for multi-provider scenarios.
import { ExecuteAgentParams, UserScope } from '@memberjunction/ai-core-plus';
const params: ExecuteAgentParams = {
agent: myAgent,
conversationMessages: [{ role: 'user', content: 'Analyze this data' }],
contextUser: currentUser,
userScope: {
primaryEntityName: 'Organizations',
primaryRecordId: orgId,
secondary: { TeamID: teamId }
},
onProgress: (step) => console.log(`${step.step}: ${step.message}`)
};
import { ExecuteAgentParams, ActionChange } from '@memberjunction/ai-core-plus';
const params: ExecuteAgentParams = {
agent: myAgent,
conversationMessages: messages,
actionChanges: [
{ scope: 'global', mode: 'add', actionIds: ['crm-action-id'] },
{ scope: 'all-subagents', mode: 'remove', actionIds: ['dangerous-action-id'] }
]
};
import { ExecuteAgentParams, MessageLifecycleEvent } from '@memberjunction/ai-core-plus';
const params: ExecuteAgentParams = {
agent: myAgent,
conversationMessages: messages,
messageExpirationOverride: {
expirationTurns: 2,
expirationMode: 'Compact',
compactMode: 'First N Chars',
compactLength: 500
},
onMessageLifecycle: (event: MessageLifecycleEvent) => {
console.log(`[Turn ${event.turn}] ${event.type}: ${event.reason}`);
}
};

MemberJunction supports a 1-100 scale for AI model reasoning effort. The resolution precedence is:

  1. ExecuteAgentParams.effortLevel (runtime override, highest priority)
  2. AIAgent.DefaultPromptEffortLevel (agent default)
  3. AIPrompt.EffortLevel (prompt default)
  4. Provider default behavior (lowest priority)

Provider mappings:

  • OpenAI: 1-33 = low, 34-66 = medium, 67-100 = high
  • Anthropic: Thinking mode with 25K-2M token budgets
  • Groq: Experimental reasoning_effort parameter
  • Gemini: Reasoning mode intensity
  • @memberjunction/ai — Core AI abstractions
  • @memberjunction/core — MJ framework core (Metadata, RunView, UserInfo)
  • @memberjunction/core-entities — Generated entity classes
  • @memberjunction/global — Class factory and global utilities
  • @memberjunction/actions-base — Action framework base types
  • @memberjunction/templates-base-types — Template engine base types
  • date-fns / date-fns-tz — Date/time formatting and timezone support