Skip to content

Reference

Kotlin SDK reference

ItemValue
Packagecom.surrealdb.kotlin.memory
DistributionBundled in com.surrealdb:kotlin
Modelscom.surrealdb.kotlin.memory.model
Sub-clientscom.surrealdb.kotlin.memory.ns

The SurrealDB Agent Memory client ships inside the SurrealDB Kotlin SDK - there is no separate artifact. It is independent of the SurrealDB RPC engine and speaks SurrealDB Agent Memory's HTTP API directly.

import com.surrealdb.kotlin.memory.AgentMemory
import kotlin.time.Duration.Companion.seconds

val memory = AgentMemory(
    contextId = "acme-prod",
    apiKey = "sk-spec-...",
    endpoint = "https://api.memory.example",
    timeout = 30.seconds,
    maxRetries = 3,
)
ParameterTypeDefaultNotes
contextIdStringrequiredThe context to operate in.
apiKeyStringrequiredBearer token; mutable var, applied on next request.
endpointStringrequiredBase URL; mutable var.
timeoutDuration30sPer-request timeout.
maxRetriesInt3GET-only retries.
httpClientHttpClient?nullInject a Ktor client.
jsonJsonlenientignoreUnknownKeys = true, explicitNulls = false.

Authentication uses the Authorization: Bearer header. Call close() to release the HTTP client.

Top-level suspend verbs on AgentMemory: remember, rememberMany, recall, queryContext, state, profile, reflect, forget, chat, consolidate, elaborate, inspect, audit, whoami, health.

Namespaced sub-clients:

PropertyTypePurpose
documentsDocumentsNamespaceUpload, query, chunk, and manage documents (plus documents.keywords).
sessionsSessionsNamespaceCreate and drive chat sessions.
entitiesEntitiesNamespaceList, fetch, and delete extracted entities.
lifecycleLifecycleNamespaceExpire, decay, and fsck maintenance.
tracesTracesNamespaceInspect decision traces and stats.
principalsPrincipalsNamespaceList grants and grant/revoke access.
scopesScopesNamespaceRegister and manage scope nodes.
keysKeysNamespaceSelf-service API key creation and rotation.

Scopes are hierarchical key/value slash-paths passed as a List<String>; an empty list targets the caller's default write region. Build them with scopePaths:

import com.surrealdb.kotlin.memory.scopePaths

scopePaths(listOf("org/acme"))                 // ["org/acme"]
scopePaths(mapOf("org" to "acme"))             // ["org/acme"]
scopePaths("team" to "eng", "org" to "acme")   // ["team/eng", "org/acme"]

Every method takes an optional onBehalfOf: String?, sent as the X-Spectron-On-Behalf-Of header so a privileged caller acts as another principal.

GET requests retry on connection errors and 5xx responses with 250 ms / 500 ms / 1 s backoff, capped at maxRetries (default 3). Writes are never retried.

All failures throw a subclass of the sealed AgentMemoryException, modelled on RFC 7807 problem details. Each carries status, title, detail, typeUri, instance, and extensions: Map<String, JsonElement>.

ExceptionHTTP status
AgentMemoryAuthException401
AgentMemoryScopeException403
AgentMemoryNotFoundException404
AgentMemoryValidationException400, 422
AgentMemoryRateLimitException429 (with retryAfter: Duration?)
AgentMemoryServerException5xx and unmatched
AgentMemoryTransportException0 (connection or parse failure)

Response and request types live under com.surrealdb.kotlin.memory.model, all @Serializable:

  • Enums - QueryMode, DocumentStatus, TurnRole, MemoryCategory, InferMode, GraphEdgeKind, and others.

  • Facts - Triple, TripleEntity, BatchMessage, FactsResponseJson, FactsBatchResponseJson.

  • Documents - DocumentJson, ChunkJson, KeywordJson, QueryFilter, UploadResponse, QueryResponseJson.

  • Memory - ChatResponseJson, QueryMemoryResponseJson, ContextQueryResponseJson, StateResponseJson, ProfileResponseJson.

  • Governance - PrincipalJson, EffectiveGrantsJson, WhoamiResponse, ScopeNodeJson, AuditRowJson.

  • Maintenance - ConsolidateResponseJson, ElaborateResponseJson, InspectResponseJson, FsckReportJson.

  • Keys - MintedKey (secret returned once), KeyDetail.

Kotlin SDK

Was this page helpful?