Files
Termind/Frameworks/TermindApplication/MemoryPersisting.swift
T
Kaede Akino 3a59d89c52 feat(memory): retrieve on demand and learn from activity
Review every 10 turns or 15 non-memory tool calls and save explicit corrections promptly. Invalidate outdated learning after lifecycle and history changes, and prevent older correction retries from overwriting newer corrections.

Replace capacity bars with entry and character counts, retain per-entry and model-input budgets, and migrate away from frozen snapshots. Upgrade the AgentKit package and submodule to signed release 0.15.0.
2026-09-25 17:38:28 +08:00

53 lines
2.1 KiB
Swift

import AgentKit
import Foundation
public nonisolated protocol MemoryPersisting: AgentMemoryAccessing {
func prepareSession(_ conversationID: UUID) async throws
func replaceHistory(_ conversations: [StoredAgentConversation]) async throws
func rebuildHistoryIndex() async throws
func lastReviewedMessage(_ conversationID: UUID) async throws -> UUID?
func recordActivity(_ id: UUID, sourceMessageID: UUID, kind: MemoryActivityKind, conversationID: UUID) async throws
-> MemoryLearningProgress
func learningProgress(_ conversationID: UUID) async throws -> MemoryLearningProgress
func correctionWasReviewed(_ messageID: UUID, conversationID: UUID) async throws -> Bool
func applyCorrection(
_ operations: [AgentMemoryOperation], expected: AgentMemoryState, messageID: UUID, conversationID: UUID
) async throws -> AgentMemoryState?
func applyReview(
_ operations: [AgentMemoryOperation], expected: AgentMemoryState, messageID: UUID, conversationID: UUID,
reviewedActivityIDs: [UUID]
) async throws -> AgentMemoryState?
func replaceTarget(_ target: AgentMemoryTarget, text: String) async throws -> AgentMemoryState
func close() async throws
func destroy() async throws
}
public nonisolated enum MemoryActivityKind: String, Equatable, Sendable { case turn, tool }
public nonisolated struct MemoryLearningEvent: Sendable {
public var id: UUID
public var sourceMessageID: UUID
public var kind: MemoryActivityKind
public init(id: UUID, sourceMessageID: UUID, kind: MemoryActivityKind) {
self.id = id
self.sourceMessageID = sourceMessageID
self.kind = kind
}
}
public nonisolated struct MemoryLearningProgress: Sendable {
public var lastReviewedMessage: UUID?
public var turns: Int
public var tools: Int
public var events: [MemoryLearningEvent]
public init(
lastReviewedMessage: UUID? = nil, turns: Int = 0, tools: Int = 0,
events: [MemoryLearningEvent] = []
) {
self.lastReviewedMessage = lastReviewedMessage
self.turns = turns
self.tools = tools
self.events = events
}
}