@ai16z/eliza v0.1.5-alpha.3 / 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
protected
circuitBreaker: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
abstract
init():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
abstract
close():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
abstract
getAccountById(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
abstract
createAccount(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
abstract
getMemories(params
):Promise
<Memory
[]>
Retrieves memories based on the specified parameters.
• params
An object containing parameters for the 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
abstract
getMemoriesByRoomIds(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
abstract
getMemoryById(id
):Promise
<Memory
>
• id: `${string}-${string}-${string}-${string}-${string}`
Promise
<Memory
>
IDatabaseAdapter
.getMemoryById
packages/core/src/database.ts:99
abstract
getCachedEmbeddings(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
abstract
log(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
abstract
getActorDetails(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
abstract
searchMemories(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
abstract
updateGoalStatus(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
abstract
searchMemoriesByEmbedding(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
abstract
createMemory(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
abstract
removeMemory(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
abstract
removeAllMemories(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
abstract
countMemories(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
abstract
getGoals(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
abstract
updateGoal(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
abstract
createGoal(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
abstract
removeGoal(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
abstract
removeAllGoals(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
abstract
getRoom(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
abstract
createRoom(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
abstract
removeRoom(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
abstract
getRoomsForParticipant(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
abstract
getRoomsForParticipants(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
abstract
addParticipant(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
abstract
removeParticipant(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
abstract
getParticipantsForAccount(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
abstract
getParticipantsForAccount(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
abstract
getParticipantsForRoom(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
abstract
getParticipantUserState(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
abstract
setParticipantUserState(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
abstract
createRelationship(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
abstract
getRelationship(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
abstract
getRelationships(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
protected
withCircuitBreaker<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