MCPcopy
hub / github.com/coder/mux / resolveMemoryContext

Method resolveMemoryContext

src/node/services/agentSession.ts:5539–5562  ·  view source on GitHub ↗

* Resolve the memory session context (index snapshot + optional hot block) * for the current session segment. * * Computed lazily on the first stream for each model. The first pass is * index-only so final tool policy can strip memory without paying hot-set * tokenization cost; if mem

(
    modelString: string,
    options?: { includeHotMemories?: boolean }
  )

Source from the content-addressed store, hash-verified

5537 * empty/partial context for the whole segment.
5538 */
5539 private async resolveMemoryContext(
5540 modelString: string,
5541 options?: { includeHotMemories?: boolean }
5542 ): Promise<MemorySessionContext | undefined> {
5543 assert(modelString.length > 0, "resolveMemoryContext requires a model string");
5544 const includeHotMemories = options?.includeHotMemories !== false;
5545 const cached = this.memoryContextByModelString.get(modelString);
5546 if (cached && (cached.includesHotMemories || !includeHotMemories)) {
5547 return cached.context ?? undefined;
5548 }
5549
5550 // Guard for test mocks that may not implement buildMemorySessionContext.
5551 const context =
5552 typeof this.aiService.buildMemorySessionContext === "function"
5553 ? await this.aiService.buildMemorySessionContext(this.workspaceId, modelString, {
5554 includeHotMemories,
5555 })
5556 : null;
5557 this.memoryContextByModelString.set(modelString, {
5558 context,
5559 includesHotMemories: includeHotMemories,
5560 });
5561 return context ?? undefined;
5562 }
5563
5564 /**
5565 * Get post-compaction attachments if they should be injected this turn.

Callers 2

streamWithHistoryMethod · 0.95

Calls 4

setMethod · 0.80
getMethod · 0.65
assertFunction · 0.50

Tested by

no test coverage detected