/** * Compose memory — first-party 6-layer memory framework. * * working → Mongo `sessions` rolling per-thread context * scene → Mongo `session_transcripts` full transcripts * graph → Mongo `memory` (source:"fact") durable user facts * patterns → Mongo `patterns` mined tool sequences * archives → Mongo `archives` + Pinata cold storage * vectors → Mongo `memory` (source:"session"|"knowledge") hybrid recall * * One unified ranker (Cloudflare BAAI bge-reranker-base + temporal decay + * MMR) shortlists items across all layers into a budget-bounded prompt block. * * The 80%-case surface for agent loops is three calls: * - `sdk.memory.context({ query, agentWallet, userAddress })` → pre-turn block * - `sdk.memory.recordTurn({ messages, agentWallet, userAddress, threadId })` → post-turn persist * - `sdk.memory.remember({ content, agentWallet, userAddress })` → durable fact * * Or even simpler ergonomic shortcuts: * - `sdk.memory.recall("what's my favourite color?", { agentWallet, userAddress })` * - `sdk.memory.save("my favourite color is azure", { agentWallet, userAddress })` * * The runtime owns ranking, budget enforcement, layer selection, and fact * extraction. The SDK is a thin transport. */ import type { APIPromise, HttpClient } from "../http.js"; import type { NetworkId } from "../chains/index.js"; import type { AgentMemoryContextParams, AgentMemoryContextResponse, AgentMemoryLoopParams, AgentMemoryLoopResponse, AgentMemoryRecordTurnParams, AgentMemoryRecordTurnResponse, AgentMemoryRememberParams, AgentMemoryRememberResponse, LearnedSkill, LayeredSearchParams, LayeredSearchResult, MemoryEvalRunParams, MemoryEvalRunResponse, MemoryItemDeleteParams, MemoryItemQuery, MemoryItemUpdateParams, MemoryJobCreateParams, MemoryJobRecord, MemoryPatternValidation, MemoryScheduleStatus, MemoryVector, MemoryLoopManifest, ProceduralPattern, SessionMemory } from "../types/index.js"; export interface MemoryContext { getWalletMaybe: () => { address: string | null; network: NetworkId | null; }; getTokenMaybe: () => string | null; } export interface MemoryRequestOptions { signal?: AbortSignal; timeoutMs?: number; idempotencyKey?: string; } /** * Shorthand options for the ergonomic helpers `recall` and `save`. * Scope (`agentWallet` + `userAddress`) is required; everything else is * either auto-defaulted by the runtime or an opt-in tuning knob. */ export interface MemoryShorthandOptions { agentWallet: string; userAddress?: string; threadId?: string; scope?: "global" | "local"; haiId?: string; /** Recall: max items in the returned prompt block. Default 6. */ limit?: number; /** Recall: max characters in the returned prompt block. Default 900. */ budgetCharacters?: number; /** Remember: confidence override (default 1 for explicit saves). */ confidence?: number; /** Remember: durable-fact category. Default "context". */ type?: "preference" | "identity" | "context" | "skill" | "relationship" | "event"; request?: MemoryRequestOptions; } export declare class Memory { private readonly client; private readonly ctx; constructor(client: HttpClient, ctx: MemoryContext); /** * Pre-turn context retrieval. Returns a budget-bounded prompt block * shortlisting top items across all 6 layers. */ context(params: AgentMemoryContextParams, options?: MemoryRequestOptions): APIPromise; /** * Post-turn persistence. Persists transcript + working memory + per-turn * vector + extracts durable facts (graph layer). Idempotent on `turnId`. */ recordTurn(params: AgentMemoryRecordTurnParams, options?: MemoryRequestOptions): APIPromise; /** * Save an explicit durable fact. Indexed as a `source:"fact"` vector with * `metadata.layer:"graph"` so the cross-layer ranker surfaces it. */ remember(params: AgentMemoryRememberParams, options?: MemoryRequestOptions): APIPromise; /** * Unified loop dispatcher — same as calling `context`/`recordTurn`/`remember` * directly but lets you pass a discriminated union, useful when the * caller's step is dynamic. */ loop(params: AgentMemoryLoopParams, options?: MemoryRequestOptions): APIPromise; /** * Pre-turn recall in one call. Returns the rendered prompt block * directly (or `null` if no relevant memories). * * const block = await sdk.memory.recall( * "what's my favourite color?", * { agentWallet, userAddress }, * ); */ recall(query: string, options: MemoryShorthandOptions): Promise<{ prompt: string | null; items: AgentMemoryContextResponse["items"]; totals: Record; contextUsage: AgentMemoryContextResponse["contextUsage"]; }>; /** * Save a durable fact in one call. Returns whether it landed. * * await sdk.memory.save( * "my favourite color is azure", * { agentWallet, userAddress, type: "preference" }, * ); */ save(content: string, options: MemoryShorthandOptions): Promise<{ saved: boolean; id?: string; }>; search(params: LayeredSearchParams, options?: MemoryRequestOptions): APIPromise; getItem(id: string, params?: MemoryItemQuery, options?: MemoryRequestOptions): APIPromise<{ item: MemoryVector; }>; updateItem(id: string, params: MemoryItemUpdateParams, options?: MemoryRequestOptions): APIPromise<{ updated: boolean; item: MemoryVector; }>; deleteItem(id: string, params?: MemoryItemDeleteParams, options?: MemoryRequestOptions): APIPromise<{ deleted: boolean; hardDeleted: boolean; }>; resolveConflict(id: string, params: { agentWallet?: string; resolution: "supersede" | "keep" | "merge" | "ignore"; winningMemoryId?: string; reason?: string; }, options?: MemoryRequestOptions): APIPromise<{ resolved: boolean; memoryId: string; }>; createJob(params: MemoryJobCreateParams, options?: MemoryRequestOptions): APIPromise; getJob(jobId: string, options?: MemoryRequestOptions): APIPromise; runEval(params: MemoryEvalRunParams, options?: MemoryRequestOptions): APIPromise; listLoops(options?: MemoryRequestOptions): APIPromise<{ loops: MemoryLoopManifest[]; }>; getLoop(loopId: string, options?: MemoryRequestOptions): APIPromise<{ loop: MemoryLoopManifest; }>; listPatterns(params?: { agentWallet?: string; patternType?: ProceduralPattern["patternType"]; minSuccessRate?: number; limit?: number; }, options?: MemoryRequestOptions): APIPromise<{ patterns: ProceduralPattern[]; }>; getPattern(patternId: string, params?: { agentWallet?: string; }, options?: MemoryRequestOptions): APIPromise<{ pattern: ProceduralPattern; }>; validatePattern(patternId: string, options?: MemoryRequestOptions): APIPromise; promotePattern(patternId: string, params: { skillName: string; validationData: MemoryPatternValidation; }, options?: MemoryRequestOptions): APIPromise<{ skillId: string; promoted: boolean; }>; listSkills(params?: { agentWallet?: string; category?: string; limit?: number; }, options?: MemoryRequestOptions): APIPromise<{ skills: LearnedSkill[]; }>; getSkill(skillId: string, params?: { agentWallet?: string; }, options?: MemoryRequestOptions): APIPromise<{ skill: LearnedSkill; }>; indexTranscript(params: { sessionId: string; threadId: string; agentWallet: string; userAddress?: string; scope?: "global" | "local"; haiId?: string; messages: AgentMemoryRecordTurnParams["messages"]; modelUsed?: string; model?: string; totalTokens?: number; tokenCount?: number; rememberWorkingMemory?: boolean; }, options?: MemoryRequestOptions): APIPromise<{ indexed: boolean; messageCount: number; vectorCount: number; }>; getWorkingSession(sessionId: string, params: { agentWallet: string; }, options?: MemoryRequestOptions): APIPromise<{ session: SessionMemory; }>; updateWorkingSession(sessionId: string, params: { agentWallet: string; userAddress?: string; threadId?: string; scope?: "global" | "local"; haiId?: string; context?: string[]; entities?: Record; state?: Record; metadata?: Record; replace?: boolean; }, options?: MemoryRequestOptions): APIPromise<{ success: boolean; session: SessionMemory; }>; compressSession(sessionId: string, params: { agentWallet: string; coordinatorModel: string; }, options?: MemoryRequestOptions): APIPromise<{ summary: string; entitiesExtracted: number; }>; syncArchive(archiveId: string, params: { agentWallet: string; }, options?: MemoryRequestOptions): APIPromise<{ ipfsHash: string; pinned: boolean; }>; listSchedules(options?: MemoryRequestOptions): APIPromise<{ schedules: MemoryScheduleStatus[]; }>; createSchedules(params: { agentWallets: string[]; }, options?: MemoryRequestOptions): APIPromise<{ created: boolean; }>; deleteSchedules(options?: MemoryRequestOptions): APIPromise<{ deleted: boolean; }>; pauseSchedule(scheduleId: string, options?: MemoryRequestOptions): APIPromise<{ paused: boolean; }>; resumeSchedule(scheduleId: string, options?: MemoryRequestOptions): APIPromise<{ resumed: boolean; }>; triggerSchedule(scheduleId: string, options?: MemoryRequestOptions): APIPromise<{ triggered: boolean; }>; private request; } //# sourceMappingURL=memory.d.ts.map