@elizaos/core v0.1.7 / DatabaseAdapter
An abstract class representing a database adapter for managing various entities like accounts, memories, actors, goals, and rooms.
• DB = any
new DatabaseAdapter<
DB>(circuitBreakerConfig?):DatabaseAdapter<DB>
Creates a new DatabaseAdapter instance with optional circuit breaker configuration.
• circuitBreakerConfig?
Configuration options for the circuit breaker
• circuitBreakerConfig.failureThreshold?: number
Number of failures before circuit opens (defaults to 5)
• circuitBreakerConfig.resetTimeout?: number
Time in ms before attempting to close circuit (defaults to 60000)
• circuitBreakerConfig.halfOpenMaxAttempts?: number
Number of successful attempts needed to close circuit (defaults to 3)
DatabaseAdapter<DB>
packages/core/src/database.ts:46
db:
DB
The database instance.
packages/core/src/database.ts:23
protectedcircuitBreaker:CircuitBreaker
Circuit breaker instance used to handle fault tolerance and prevent cascading failures. Implements the Circuit Breaker pattern to temporarily disable operations when a failure threshold is reached.
The circuit breaker has three states:
- CLOSED: Normal operation, requests pass through
- OPEN: Failure threshold exceeded, requests are blocked
- HALF_OPEN: Testing if service has recovered
packages/core/src/database.ts:36
abstractinit():Promise<void>
Optional initialization method for the database adapter.
Promise<void>
A Promise that resolves when initialization is complete.
packages/core/src/database.ts:58
abstractclose():Promise<void>
Optional close method for the database adapter.
Promise<void>
A Promise that resolves when closing is complete.
packages/core/src/database.ts:64
abstractgetAccountById(userId):Promise<Account>
Retrieves an account by its ID.
• userId: `${string}-${string}-${string}-${string}-${string}`
The UUID of the user account to retrieve.
Promise<Account>
A Promise that resolves to the Account object or null if not found.
IDatabaseAdapter.getAccountById
packages/core/src/database.ts:71
abstractcreateAccount(account):Promise<boolean>
Creates a new account in the database.
• account: Account
The account object to create.
Promise<boolean>
A Promise that resolves when the account creation is complete.
IDatabaseAdapter.createAccount
packages/core/src/database.ts:78
abstractgetMemories(params):Promise<Memory[]>
Retrieves memories based on the specified parameters.
• params
An object containing parameters for memory retrieval.
• params.agentId: `${string}-${string}-${string}-${string}-${string}`
• params.roomId: `${string}-${string}-${string}-${string}-${string}`
• params.count?: number
• params.unique?: boolean
• params.tableName: string
Promise<Memory[]>
A Promise that resolves to an array of Memory objects.
packages/core/src/database.ts:85
abstractgetMemoriesByRoomIds(params):Promise<Memory[]>
• params
• params.agentId: `${string}-${string}-${string}-${string}-${string}`
• params.roomIds: `${string}-${string}-${string}-${string}-${string}`[]
• params.tableName: string
Promise<Memory[]>
IDatabaseAdapter.getMemoriesByRoomIds
packages/core/src/database.ts:93
abstractgetMemoryById(id):Promise<Memory>
• id: `${string}-${string}-${string}-${string}-${string}`
Promise<Memory>
IDatabaseAdapter.getMemoryById
packages/core/src/database.ts:99
abstractgetCachedEmbeddings(params):Promise<object[]>
Retrieves cached embeddings based on the specified query parameters.
• params
An object containing parameters for the embedding retrieval.
• params.query_table_name: string
• params.query_threshold: number
• params.query_input: string
• params.query_field_name: string
• params.query_field_sub_name: string
• params.query_match_count: number
Promise<object[]>
A Promise that resolves to an array of objects containing embeddings and Levenshtein scores.
IDatabaseAdapter.getCachedEmbeddings
packages/core/src/database.ts:106
abstractlog(params):Promise<void>
Logs an event or action with the specified details.
• params
An object containing parameters for the log entry.
• params.body
• params.userId: `${string}-${string}-${string}-${string}-${string}`
• params.roomId: `${string}-${string}-${string}-${string}-${string}`
• params.type: string
Promise<void>
A Promise that resolves when the log entry has been saved.
packages/core/src/database.ts:132
abstractgetActorDetails(params):Promise<Actor[]>
Retrieves details of actors in a given room.
• params
An object containing the roomId to search for actors.
• params.roomId: `${string}-${string}-${string}-${string}-${string}`
Promise<Actor[]>
A Promise that resolves to an array of Actor objects.
IDatabaseAdapter.getActorDetails
packages/core/src/database.ts:144
abstractsearchMemories(params):Promise<Memory[]>
Searches for memories based on embeddings and other specified parameters.
• params
An object containing parameters for the memory search.
• params.tableName: string
• params.agentId: `${string}-${string}-${string}-${string}-${string}`
• params.roomId: `${string}-${string}-${string}-${string}-${string}`
• params.embedding: number[]
• params.match_threshold: number
• params.match_count: number
• params.unique: boolean
Promise<Memory[]>
A Promise that resolves to an array of Memory objects.
IDatabaseAdapter.searchMemories
packages/core/src/database.ts:151
abstractupdateGoalStatus(params):Promise<void>
Updates the status of a specific goal.
• params
An object containing the goalId and the new status.
• params.goalId: `${string}-${string}-${string}-${string}-${string}`
• params.status: GoalStatus
Promise<void>
A Promise that resolves when the goal status has been updated.
IDatabaseAdapter.updateGoalStatus
packages/core/src/database.ts:166
abstractsearchMemoriesByEmbedding(embedding,params):Promise<Memory[]>
Searches for memories by embedding and other specified parameters.
• embedding: number[]
The embedding vector to search with.
• params
Additional parameters for the search.
• params.match_threshold?: number
• params.count?: number
• params.roomId?: `${string}-${string}-${string}-${string}-${string}`
• params.agentId?: `${string}-${string}-${string}-${string}-${string}`
• params.unique?: boolean
• params.tableName: string
Promise<Memory[]>
A Promise that resolves to an array of Memory objects.
IDatabaseAdapter.searchMemoriesByEmbedding
packages/core/src/database.ts:177
abstractcreateMemory(memory,tableName,unique?):Promise<void>
Creates a new memory in the database.
• memory: Memory
The memory object to create.
• tableName: string
The table where the memory should be stored.
• unique?: boolean
Indicates if the memory should be unique.
Promise<void>
A Promise that resolves when the memory has been created.
packages/core/src/database.ts:196
abstractremoveMemory(memoryId,tableName):Promise<void>
Removes a specific memory from the database.
• memoryId: `${string}-${string}-${string}-${string}-${string}`
The UUID of the memory to remove.
• tableName: string
The table from which the memory should be removed.
Promise<void>
A Promise that resolves when the memory has been removed.
packages/core/src/database.ts:208
abstractremoveAllMemories(roomId,tableName):Promise<void>
Removes all memories associated with a specific room.
• roomId: `${string}-${string}-${string}-${string}-${string}`
The UUID of the room whose memories should be removed.
• tableName: string
The table from which the memories should be removed.
Promise<void>
A Promise that resolves when all memories have been removed.
IDatabaseAdapter.removeAllMemories
packages/core/src/database.ts:216
abstractcountMemories(roomId,unique?,tableName?):Promise<number>
Counts the number of memories in a specific room.
• roomId: `${string}-${string}-${string}-${string}-${string}`
The UUID of the room for which to count memories.
• unique?: boolean
Specifies whether to count only unique memories.
• tableName?: string
Optional table name to count memories from.
Promise<number>
A Promise that resolves to the number of memories.
IDatabaseAdapter.countMemories
packages/core/src/database.ts:225
abstractgetGoals(params):Promise<Goal[]>
Retrieves goals based on specified parameters.
• params
An object containing parameters for goal retrieval.
• params.agentId: `${string}-${string}-${string}-${string}-${string}`
• params.roomId: `${string}-${string}-${string}-${string}-${string}`
• params.userId?: `${string}-${string}-${string}-${string}-${string}`
• params.onlyInProgress?: boolean
• params.count?: number
Promise<Goal[]>
A Promise that resolves to an array of Goal objects.
packages/core/src/database.ts:236
abstractupdateGoal(goal):Promise<void>
Updates a specific goal in the database.
• goal: Goal
The goal object with updated properties.
Promise<void>
A Promise that resolves when the goal has been updated.
packages/core/src/database.ts:249
abstractcreateGoal(goal):Promise<void>
Creates a new goal in the database.
• goal: Goal
The goal object to create.
Promise<void>
A Promise that resolves when the goal has been created.
packages/core/src/database.ts:256
abstractremoveGoal(goalId):Promise<void>
Removes a specific goal from the database.
• goalId: `${string}-${string}-${string}-${string}-${string}`
The UUID of the goal to remove.
Promise<void>
A Promise that resolves when the goal has been removed.
packages/core/src/database.ts:263
abstractremoveAllGoals(roomId):Promise<void>
Removes all goals associated with a specific room.
• roomId: `${string}-${string}-${string}-${string}-${string}`
The UUID of the room whose goals should be removed.
Promise<void>
A Promise that resolves when all goals have been removed.
IDatabaseAdapter.removeAllGoals
packages/core/src/database.ts:270
abstractgetRoom(roomId):Promise<`${string}-${string}-${string}-${string}-${string}`>
Retrieves the room ID for a given room, if it exists.
• roomId: `${string}-${string}-${string}-${string}-${string}`
The UUID of the room to retrieve.
Promise<`${string}-${string}-${string}-${string}-${string}`>
A Promise that resolves to the room ID or null if not found.
packages/core/src/database.ts:277
abstractcreateRoom(roomId?):Promise<`${string}-${string}-${string}-${string}-${string}`>
Creates a new room with an optional specified ID.
• roomId?: `${string}-${string}-${string}-${string}-${string}`
Optional UUID to assign to the new room.
Promise<`${string}-${string}-${string}-${string}-${string}`>
A Promise that resolves to the UUID of the created room.
packages/core/src/database.ts:284
abstractremoveRoom(roomId):Promise<void>
Removes a specific room from the database.
• roomId: `${string}-${string}-${string}-${string}-${string}`
The UUID of the room to remove.
Promise<void>
A Promise that resolves when the room has been removed.
packages/core/src/database.ts:291
abstractgetRoomsForParticipant(userId):Promise<`${string}-${string}-${string}-${string}-${string}`[]>
Retrieves room IDs for which a specific user is a participant.
• userId: `${string}-${string}-${string}-${string}-${string}`
The UUID of the user.
Promise<`${string}-${string}-${string}-${string}-${string}`[]>
A Promise that resolves to an array of room IDs.
IDatabaseAdapter.getRoomsForParticipant
packages/core/src/database.ts:298
abstractgetRoomsForParticipants(userIds):Promise<`${string}-${string}-${string}-${string}-${string}`[]>
Retrieves room IDs for which specific users are participants.
• userIds: `${string}-${string}-${string}-${string}-${string}`[]
An array of UUIDs of the users.
Promise<`${string}-${string}-${string}-${string}-${string}`[]>
A Promise that resolves to an array of room IDs.
IDatabaseAdapter.getRoomsForParticipants
packages/core/src/database.ts:305
abstractaddParticipant(userId,roomId):Promise<boolean>
Adds a user as a participant to a specific room.
• userId: `${string}-${string}-${string}-${string}-${string}`
The UUID of the user to add as a participant.
• roomId: `${string}-${string}-${string}-${string}-${string}`
The UUID of the room to which the user will be added.
Promise<boolean>
A Promise that resolves to a boolean indicating success or failure.
IDatabaseAdapter.addParticipant
packages/core/src/database.ts:313
abstractremoveParticipant(userId,roomId):Promise<boolean>
Removes a user as a participant from a specific room.
• userId: `${string}-${string}-${string}-${string}-${string}`
The UUID of the user to remove as a participant.
• roomId: `${string}-${string}-${string}-${string}-${string}`
The UUID of the room from which the user will be removed.
Promise<boolean>
A Promise that resolves to a boolean indicating success or failure.
IDatabaseAdapter.removeParticipant
packages/core/src/database.ts:321
abstractgetParticipantsForAccount(userId):Promise<Participant[]>
Retrieves participants associated with a specific account.
• userId: `${string}-${string}-${string}-${string}-${string}`
The UUID of the account.
Promise<Participant[]>
A Promise that resolves to an array of Participant objects.
IDatabaseAdapter.getParticipantsForAccount
packages/core/src/database.ts:328
abstractgetParticipantsForAccount(userId):Promise<Participant[]>
Retrieves participants associated with a specific account.
• userId: `${string}-${string}-${string}-${string}-${string}`
The UUID of the account.
Promise<Participant[]>
A Promise that resolves to an array of Participant objects.
IDatabaseAdapter.getParticipantsForAccount
packages/core/src/database.ts:335
abstractgetParticipantsForRoom(roomId):Promise<`${string}-${string}-${string}-${string}-${string}`[]>
Retrieves participants for a specific room.
• roomId: `${string}-${string}-${string}-${string}-${string}`
The UUID of the room for which to retrieve participants.
Promise<`${string}-${string}-${string}-${string}-${string}`[]>
A Promise that resolves to an array of UUIDs representing the participants.
IDatabaseAdapter.getParticipantsForRoom
packages/core/src/database.ts:342
abstractgetParticipantUserState(roomId,userId):Promise<"FOLLOWED"|"MUTED">
• roomId: `${string}-${string}-${string}-${string}-${string}`
• userId: `${string}-${string}-${string}-${string}-${string}`
Promise<"FOLLOWED" | "MUTED">
IDatabaseAdapter.getParticipantUserState
packages/core/src/database.ts:344
abstractsetParticipantUserState(roomId,userId,state):Promise<void>
• roomId: `${string}-${string}-${string}-${string}-${string}`
• userId: `${string}-${string}-${string}-${string}-${string}`
• state: "FOLLOWED" | "MUTED"
Promise<void>
IDatabaseAdapter.setParticipantUserState
packages/core/src/database.ts:348
abstractcreateRelationship(params):Promise<boolean>
Creates a new relationship between two users.
• params
An object containing the UUIDs of the two users (userA and userB).
• params.userA: `${string}-${string}-${string}-${string}-${string}`
• params.userB: `${string}-${string}-${string}-${string}-${string}`
Promise<boolean>
A Promise that resolves to a boolean indicating success or failure of the creation.
IDatabaseAdapter.createRelationship
packages/core/src/database.ts:359
abstractgetRelationship(params):Promise<Relationship>
Retrieves a relationship between two users if it exists.
• params
An object containing the UUIDs of the two users (userA and userB).
• params.userA: `${string}-${string}-${string}-${string}-${string}`
• params.userB: `${string}-${string}-${string}-${string}-${string}`
Promise<Relationship>
A Promise that resolves to the Relationship object or null if not found.
IDatabaseAdapter.getRelationship
packages/core/src/database.ts:369
abstractgetRelationships(params):Promise<Relationship[]>
Retrieves all relationships for a specific user.
• params
An object containing the UUID of the user.
• params.userId: `${string}-${string}-${string}-${string}-${string}`
Promise<Relationship[]>
A Promise that resolves to an array of Relationship objects.
IDatabaseAdapter.getRelationships
packages/core/src/database.ts:379
protectedwithCircuitBreaker<T>(operation,context):Promise<T>
Executes an operation with circuit breaker protection.
• T
• operation
A function that returns a Promise to be executed with circuit breaker protection
• context: string
A string describing the context/operation being performed for logging purposes
Promise<T>
A Promise that resolves to the result of the operation
Will throw an error if the circuit breaker is open or if the operation fails