Skip to main content

@elizaos/core v1.0.0-beta.51 / AgentRuntime

Class: AgentRuntime

AgentRuntime provides the core runtime environment and lifecycle management for agents.

Implements the IAgentRuntime interface, managing agent state, actions, plugins, providers, and database interaction.

implements IAgentRuntime

Implements​

Accessors​

db​

Get Signature​

get db(): any

Database instance

Returns​

any

Database instance

Implementation of​

IAgentRuntime.db

Defined in​

packages/core/src/runtime.ts:2264

Methods​

startSpan()​

startSpan<T>(name, fn, parentContext?): Promise<T>

Starts a span for the given operation and executes the provided function with the span.

Type Parameters​

• T

Parameters​

• name: string

The name of the span to create

• fn

The function to execute with the span

• parentContext?: Context

Optional parent context for the span

Returns​

Promise<T>

The result of the provided function

Defined in​

packages/core/src/runtime.ts:234


endSpan()​

endSpan(ctx, name): void

Ends a span with the provided name in the given context

Parameters​

• ctx: Context

Context containing the span to end

• name: string

Name to record in the end event

Returns​

void

Defined in​

packages/core/src/runtime.ts:294


startActiveSpan()​

startActiveSpan(name, options): Span

Start an active span that can be used as a parent for other spans

Parameters​

• name: string

Name of the span

• options: any = {}

Span options

Returns​

Span

Defined in​

packages/core/src/runtime.ts:304


registerPlugin()​

registerPlugin(plugin): Promise<void>

Registers a plugin with the runtime and initializes its components

Parameters​

• plugin: Plugin

The plugin to register

Returns​

Promise<void>

Implementation of​

IAgentRuntime.registerPlugin

Defined in​

packages/core/src/runtime.ts:330


getConversationLength()​

getConversationLength(): number

Get the number of messages that are kept in the conversation buffer.

Returns​

number

The number of recent messages to be kept in memory.

Implementation of​

IAgentRuntime.getConversationLength

Defined in​

packages/core/src/runtime.ts:997


registerProvider()​

registerProvider(provider): void

Register a provider for the agent to use.

Parameters​

• provider: Provider

The provider to register.

Returns​

void

Implementation of​

IAgentRuntime.registerProvider

Defined in​

packages/core/src/runtime.ts:1016


registerAction()​

registerAction(action): void

Register an action for the agent to perform.

Parameters​

• action: Action

The action to register.

Returns​

void

Implementation of​

IAgentRuntime.registerAction

Defined in​

packages/core/src/runtime.ts:1025


registerEvaluator()​

registerEvaluator(evaluator): void

Register an evaluator to assess and guide the agent's responses.

Parameters​

• evaluator: Evaluator

The evaluator to register.

Returns​

void

Implementation of​

IAgentRuntime.registerEvaluator

Defined in​

packages/core/src/runtime.ts:1046


registerContextProvider()​

registerContextProvider(provider): void

Register a context provider to provide context for message generation.

Parameters​

• provider: Provider

The context provider to register.

Returns​

void

Defined in​

packages/core/src/runtime.ts:1054


processActions()​

processActions(message, responses, state?, callback?): Promise<void>

Process the actions of a message.

Parameters​

• message: Memory

The message to process.

• responses: Memory[]

The array of response memories to process actions from.

• state?: State

Optional state object for the action processing.

• callback?: HandlerCallback

Optional callback handler for action results.

Returns​

Promise<void>

Implementation of​

IAgentRuntime.processActions

Defined in​

packages/core/src/runtime.ts:1065


evaluate()​

evaluate(message, state, didRespond?, callback?, responses?): Promise<Evaluator[]>

Evaluate the message and state using the registered evaluators.

Parameters​

• message: Memory

The message to evaluate.

• state: State

The state of the agent.

• didRespond?: boolean

Whether the agent responded to the message.~

• callback?: HandlerCallback

The handler callback

• responses?: Memory[]

Returns​

Promise<Evaluator[]>

The results of the evaluation.

Implementation of​

IAgentRuntime.evaluate

Defined in​

packages/core/src/runtime.ts:1283


ensureParticipantInRoom()​

ensureParticipantInRoom(entityId, roomId): Promise<void>

Ensures a participant is added to a room, checking that the entity exists first

Parameters​

• entityId: `${string}-${string}-${string}-${string}-${string}`

• roomId: `${string}-${string}-${string}-${string}-${string}`

Returns​

Promise<void>

Implementation of​

IAgentRuntime.ensureParticipantInRoom

Defined in​

packages/core/src/runtime.ts:1512


ensureWorldExists()​

ensureWorldExists(__namedParameters): Promise<void>

Ensure the existence of a world.

Parameters​

• __namedParameters: World

Returns​

Promise<void>

Implementation of​

IAgentRuntime.ensureWorldExists

Defined in​

packages/core/src/runtime.ts:1567


ensureRoomExists()​

ensureRoomExists(entityId): Promise<void>

Ensure the existence of a room between the agent and a user. If no room exists, a new room is created and the user and agent are added as participants. The room ID is returned.

Parameters​

• entityId: Room

The user ID to create a room with.

Returns​

Promise<void>

The room ID of the room between the agent and the user.

Throws​

An error if the room cannot be created.

Implementation of​

IAgentRuntime.ensureRoomExists

Defined in​

packages/core/src/runtime.ts:1603


composeState()​

composeState(message, includeList, onlyInclude, skipCache): Promise<State>

Composes the agent's state by gathering data from enabled providers.

Parameters​

• message: Memory

The message to use as context for state composition

• includeList: string[] = null

• onlyInclude: boolean = false

If true, only include providers that are in the includeList, don't get other registered providers

• skipCache: boolean = false

If true, skip the cache and get the latest data from the providers

Returns​

Promise<State>

A State object containing provider data, values, and text

Implementation of​

IAgentRuntime.composeState

Defined in​

packages/core/src/runtime.ts:1630


useModel()​

useModel<T, R>(modelType, params, provider?): Promise<R>

Use a model with strongly typed parameters and return values based on model type

Type Parameters​

• T extends string

The model type to use

• R = ModelResultMap[T]

The expected return type, defaults to the type defined in ModelResultMap[T]

Parameters​

• modelType: T

The type of model to use

• params: any

The parameters for the model, typed based on model type

• provider?: string

Returns​

Promise<R>

  • The model result, typed based on the provided generic type parameter

Implementation of​

IAgentRuntime.useModel

Defined in​

packages/core/src/runtime.ts:1975


getTaskWorker()​

getTaskWorker(name): TaskWorker

Get a task worker by name

Parameters​

• name: string

Returns​

TaskWorker

Implementation of​

IAgentRuntime.getTaskWorker

Defined in​

packages/core/src/runtime.ts:2258


init()​

init(): Promise<void>

Initialize database connection

Returns​

Promise<void>

Implementation of​

IAgentRuntime.init

Defined in​

packages/core/src/runtime.ts:2268


close()​

close(): Promise<void>

Close database connection

Returns​

Promise<void>

Implementation of​

IAgentRuntime.close

Defined in​

packages/core/src/runtime.ts:2272


getAgents()​

getAgents(): Promise<Partial<Agent>[]>

Get all agents

Returns​

Promise<Partial<Agent>[]>

Implementation of​

IAgentRuntime.getAgents

Defined in​

packages/core/src/runtime.ts:2280


getEntityById()​

getEntityById(entityId): Promise<Entity>

Get entity by ID

Parameters​

• entityId: `${string}-${string}-${string}-${string}-${string}`

Returns​

Promise<Entity>

Implementation of​

IAgentRuntime.getEntityById

Defined in​

packages/core/src/runtime.ts:2300


getEntitiesForRoom()​

getEntitiesForRoom(roomId, includeComponents?): Promise<Entity[]>

Get entities for room

Parameters​

• roomId: `${string}-${string}-${string}-${string}-${string}`

• includeComponents?: boolean

Returns​

Promise<Entity[]>

Implementation of​

IAgentRuntime.getEntitiesForRoom

Defined in​

packages/core/src/runtime.ts:2304


createEntity()​

createEntity(entity): Promise<boolean>

Create new entity

Parameters​

• entity: Entity

Returns​

Promise<boolean>

Implementation of​

IAgentRuntime.createEntity

Defined in​

packages/core/src/runtime.ts:2308


updateEntity()​

updateEntity(entity): Promise<void>

Update entity

Parameters​

• entity: Entity

Returns​

Promise<void>

Implementation of​

IAgentRuntime.updateEntity

Defined in​

packages/core/src/runtime.ts:2315


getComponent()​

getComponent(entityId, type, worldId?, sourceEntityId?): Promise<Component>

Get component by ID

Parameters​

• entityId: `${string}-${string}-${string}-${string}-${string}`

• type: string

• worldId?: `${string}-${string}-${string}-${string}-${string}`

• sourceEntityId?: `${string}-${string}-${string}-${string}-${string}`

Returns​

Promise<Component>

Implementation of​

IAgentRuntime.getComponent

Defined in​

packages/core/src/runtime.ts:2319


getComponents()​

getComponents(entityId, worldId?, sourceEntityId?): Promise<Component[]>

Get all components for an entity

Parameters​

• entityId: `${string}-${string}-${string}-${string}-${string}`

• worldId?: `${string}-${string}-${string}-${string}-${string}`

• sourceEntityId?: `${string}-${string}-${string}-${string}-${string}`

Returns​

Promise<Component[]>

Implementation of​

IAgentRuntime.getComponents

Defined in​

packages/core/src/runtime.ts:2328


createComponent()​

createComponent(component): Promise<boolean>

Create component

Parameters​

• component: Component

Returns​

Promise<boolean>

Implementation of​

IAgentRuntime.createComponent

Defined in​

packages/core/src/runtime.ts:2332


updateComponent()​

updateComponent(component): Promise<void>

Update component

Parameters​

• component: Component

Returns​

Promise<void>

Implementation of​

IAgentRuntime.updateComponent

Defined in​

packages/core/src/runtime.ts:2336


deleteComponent()​

deleteComponent(componentId): Promise<void>

Delete component

Parameters​

• componentId: `${string}-${string}-${string}-${string}-${string}`

Returns​

Promise<void>

Implementation of​

IAgentRuntime.deleteComponent

Defined in​

packages/core/src/runtime.ts:2340


getMemories()​

getMemories(params): Promise<Memory[]>

Get memories matching criteria

Parameters​

• params

• params.entityId?: `${string}-${string}-${string}-${string}-${string}`

• params.agentId?: `${string}-${string}-${string}-${string}-${string}`

• params.roomId?: `${string}-${string}-${string}-${string}-${string}`

• params.count?: number

• params.unique?: boolean

• params.tableName: string

• params.start?: number

• params.end?: number

Returns​

Promise<Memory[]>

Implementation of​

IAgentRuntime.getMemories

Defined in​

packages/core/src/runtime.ts:2371


createRelationship()​

createRelationship(params): Promise<boolean>

Creates a new relationship between two entities.

Parameters​

• params

Object containing the relationship details

• params.sourceEntityId: `${string}-${string}-${string}-${string}-${string}`

• params.targetEntityId: `${string}-${string}-${string}-${string}-${string}`

• params.tags?: string[]

• params.metadata?

Returns​

Promise<boolean>

Promise resolving to boolean indicating success

Implementation of​

IAgentRuntime.createRelationship

Defined in​

packages/core/src/runtime.ts:2566


updateRelationship()​

updateRelationship(relationship): Promise<void>

Updates an existing relationship between two entities.

Parameters​

• relationship: Relationship

The relationship object with updated data

Returns​

Promise<void>

Promise resolving to void

Implementation of​

IAgentRuntime.updateRelationship

Defined in​

packages/core/src/runtime.ts:2575


getRelationship()​

getRelationship(params): Promise<Relationship>

Retrieves a relationship between two entities if it exists.

Parameters​

• params

Object containing the entity IDs and agent ID

• params.sourceEntityId: `${string}-${string}-${string}-${string}-${string}`

• params.targetEntityId: `${string}-${string}-${string}-${string}-${string}`

Returns​

Promise<Relationship>

Promise resolving to the Relationship object or null if not found

Implementation of​

IAgentRuntime.getRelationship

Defined in​

packages/core/src/runtime.ts:2579


getRelationships()​

getRelationships(params): Promise<Relationship[]>

Retrieves all relationships for a specific entity.

Parameters​

• params

Object containing the user ID, agent ID and optional tags to filter by

• params.entityId: `${string}-${string}-${string}-${string}-${string}`

• params.tags?: string[]

Returns​

Promise<Relationship[]>

Promise resolving to an array of Relationship objects

Implementation of​

IAgentRuntime.getRelationships

Defined in​

packages/core/src/runtime.ts:2586


sendControlMessage()​

sendControlMessage(params): Promise<void>

Sends a control message to the frontend to enable or disable input

Parameters​

• params

Parameters for the control message

• params.roomId: `${string}-${string}-${string}-${string}-${string}`

The ID of the room to send the control message to

• params.action: "disable_input" | "enable_input"

The action to perform

• params.target?: string

Optional target element identifier

Returns​

Promise<void>

Defined in​

packages/core/src/runtime.ts:2662


registerSendHandler()​

registerSendHandler(source, handler): void

Registers a handler function for sending messages to a specific source.

Parameters​

• source: string

The unique identifier for the source.

• handler: SendHandlerFunction

The SendHandlerFunction to register.

Returns​

void

Implementation of​

IAgentRuntime.registerSendHandler

Defined in​

packages/core/src/runtime.ts:2698


sendMessageToTarget()​

sendMessageToTarget(target, content): Promise<void>

Sends a message to a target using the registered handler for the target's source.

Parameters​

• target: TargetInfo

Information about the message target.

• content: Content

The message content.

Returns​

Promise<void>

Implementation of​

IAgentRuntime.sendMessageToTarget

Defined in​

packages/core/src/runtime.ts:2713