Skip to main content

@ai16z/eliza v0.1.3 / AgentRuntime

Class: AgentRuntime

Represents the runtime environment for an agent, handling message processing, action registration, and interaction with external services like OpenAI and Supabase.

Implements

Constructors

new AgentRuntime()

new AgentRuntime(opts): AgentRuntime

Creates an instance of AgentRuntime.

Parameters

opts

The options for configuring the AgentRuntime.

opts.conversationLength?: number

The number of messages to hold in the recent message cache.

opts.agentId?: `${string}-${string}-${string}-${string}-${string}`

Optional ID of the agent.

opts.character?: Character

opts.token: string

The JWT token, can be a JWT token if outside worker, or an OpenAI token if inside worker.

opts.serverUrl?: string

The URL of the worker.

opts.actions?: Action[]

Optional custom actions.

opts.evaluators?: Evaluator[]

Optional custom evaluators.

opts.plugins?: Plugin[]

opts.providers?: Provider[]

Optional context providers.

opts.modelProvider: ModelProviderName

opts.services?: Service[]

Optional custom services.

opts.managers?: IMemoryManager[]

opts.databaseAdapter: IDatabaseAdapter

The database adapter used for interacting with the database.

opts.fetch?: unknown

Custom fetch function to use for making requests.

opts.speechModelPath?: string

opts.cacheManager: ICacheManager

opts.logging?: boolean

Returns

AgentRuntime

Defined in

packages/core/src/runtime.ts:197

Properties

agentId

agentId: `${string}-${string}-${string}-${string}-${string}`

The ID of the agent

Implementation of

IAgentRuntime.agentId

Defined in

packages/core/src/runtime.ts:61


serverUrl

serverUrl: string = "http://localhost:7998"

The base URL of the server where the agent's requests are processed.

Implementation of

IAgentRuntime.serverUrl

Defined in

packages/core/src/runtime.ts:65


databaseAdapter

databaseAdapter: IDatabaseAdapter

The database adapter used for interacting with the database.

Implementation of

IAgentRuntime.databaseAdapter

Defined in

packages/core/src/runtime.ts:70


token

token: string

Authentication token used for securing requests.

Implementation of

IAgentRuntime.token

Defined in

packages/core/src/runtime.ts:75


actions

actions: Action[] = []

Custom actions that the agent can perform.

Implementation of

IAgentRuntime.actions

Defined in

packages/core/src/runtime.ts:80


evaluators

evaluators: Evaluator[] = []

Evaluators used to assess and guide the agent's responses.

Implementation of

IAgentRuntime.evaluators

Defined in

packages/core/src/runtime.ts:85


providers

providers: Provider[] = []

Context providers used to provide context for message generation.

Implementation of

IAgentRuntime.providers

Defined in

packages/core/src/runtime.ts:90


plugins

plugins: Plugin[] = []

Implementation of

IAgentRuntime.plugins

Defined in

packages/core/src/runtime.ts:92


modelProvider

modelProvider: ModelProviderName

The model to use for generateText.

Implementation of

IAgentRuntime.modelProvider

Defined in

packages/core/src/runtime.ts:97


fetch()

fetch: (input, init?) => Promise<Response>(input, init?) => Promise<Response>

Fetch function to use Some environments may not have access to the global fetch function and need a custom fetch override.

MDN Reference

Parameters

input: RequestInfo | URL

init?: RequestInit

Returns

Promise<Response>

Parameters

input: string | Request | URL

init?: RequestInit

Returns

Promise<Response>

Defined in

packages/core/src/runtime.ts:103


character

character: Character

The character to use for the agent

Implementation of

IAgentRuntime.character

Defined in

packages/core/src/runtime.ts:108


messageManager

messageManager: IMemoryManager

Store messages that are sent and received by the agent.

Implementation of

IAgentRuntime.messageManager

Defined in

packages/core/src/runtime.ts:113


descriptionManager

descriptionManager: IMemoryManager

Store and recall descriptions of users based on conversations.

Implementation of

IAgentRuntime.descriptionManager

Defined in

packages/core/src/runtime.ts:118


loreManager

loreManager: IMemoryManager

Manage the creation and recall of static information (documents, historical game lore, etc)

Implementation of

IAgentRuntime.loreManager

Defined in

packages/core/src/runtime.ts:123


documentsManager

documentsManager: IMemoryManager

Hold large documents that can be referenced

Defined in

packages/core/src/runtime.ts:128


knowledgeManager

knowledgeManager: IMemoryManager

Searchable document fragments

Defined in

packages/core/src/runtime.ts:133


services

services: Map<ServiceType, Service>

Implementation of

IAgentRuntime.services

Defined in

packages/core/src/runtime.ts:135


memoryManagers

memoryManagers: Map<string, IMemoryManager>

Defined in

packages/core/src/runtime.ts:136


cacheManager

cacheManager: ICacheManager

Implementation of

IAgentRuntime.cacheManager

Defined in

packages/core/src/runtime.ts:137

Methods

registerMemoryManager()

registerMemoryManager(manager): void

Parameters

manager: IMemoryManager

Returns

void

Implementation of

IAgentRuntime.registerMemoryManager

Defined in

packages/core/src/runtime.ts:139


getMemoryManager()

getMemoryManager(tableName): IMemoryManager

Parameters

tableName: string

Returns

IMemoryManager

Implementation of

IAgentRuntime.getMemoryManager

Defined in

packages/core/src/runtime.ts:154


getService()

getService<T>(service): T

Type Parameters

T extends Service

Parameters

service: ServiceType

Returns

T

Implementation of

IAgentRuntime.getService

Defined in

packages/core/src/runtime.ts:158


registerService()

registerService(service): Promise<void>

Parameters

service: Service

Returns

Promise<void>

Implementation of

IAgentRuntime.registerService

Defined in

packages/core/src/runtime.ts:167


initialize()

initialize(): Promise<void>

Returns

Promise<void>

Implementation of

IAgentRuntime.initialize

Defined in

packages/core/src/runtime.ts:312


getSetting()

getSetting(key): any

Parameters

key: string

Returns

any

Implementation of

IAgentRuntime.getSetting

Defined in

packages/core/src/runtime.ts:408


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:430


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:438


registerEvaluator()

registerEvaluator(evaluator): void

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

Parameters

evaluator: Evaluator

The evaluator to register.

Returns

void

Defined in

packages/core/src/runtime.ts:447


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:455


processActions()

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

Process the actions of a message.

Parameters

message: Memory

The message to process.

responses: Memory[]

state?: State

callback?: HandlerCallback

Returns

Promise<void>

Implementation of

IAgentRuntime.processActions

Defined in

packages/core/src/runtime.ts:464


evaluate()

evaluate(message, state?, didRespond?): Promise<string[]>

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.

Returns

Promise<string[]>

The results of the evaluation.

Implementation of

IAgentRuntime.evaluate

Defined in

packages/core/src/runtime.ts:537


ensureParticipantExists()

ensureParticipantExists(userId, roomId): Promise<void>

Ensure the existence of a participant in the room. If the participant does not exist, they are added to the room.

Parameters

userId: `${string}-${string}-${string}-${string}-${string}`

The user ID to ensure the existence of.

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

Returns

Promise<void>

Throws

An error if the participant cannot be added.

Implementation of

IAgentRuntime.ensureParticipantExists

Defined in

packages/core/src/runtime.ts:607


ensureUserExists()

ensureUserExists(userId, userName, name, email?, source?): Promise<void>

Ensure the existence of a user in the database. If the user does not exist, they are added to the database.

Parameters

userId: `${string}-${string}-${string}-${string}-${string}`

The user ID to ensure the existence of.

userName: string

The user name to ensure the existence of.

name: string

email?: string

source?: string

Returns

Promise<void>

Implementation of

IAgentRuntime.ensureUserExists

Defined in

packages/core/src/runtime.ts:623


ensureParticipantInRoom()

ensureParticipantInRoom(userId, roomId): Promise<void>

Parameters

userId: `${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:643


ensureConnection()

ensureConnection(userId, roomId, userName?, userScreenName?, source?): Promise<void>

Parameters

userId: `${string}-${string}-${string}-${string}-${string}`

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

userName?: string

userScreenName?: string

source?: string

Returns

Promise<void>

Implementation of

IAgentRuntime.ensureConnection

Defined in

packages/core/src/runtime.ts:660


ensureRoomExists()

ensureRoomExists(roomId): 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

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

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:696


composeState()

composeState(message, additionalKeys): Promise<State>

Compose the state of the agent into an object that can be passed or used for response generation.

Parameters

message: Memory

The message to compose the state from.

additionalKeys = {}

Returns

Promise<State>

The state of the agent.

Implementation of

IAgentRuntime.composeState

Defined in

packages/core/src/runtime.ts:709


updateRecentMessageState()

updateRecentMessageState(state): Promise<State>

Parameters

state: State

Returns

Promise<State>

Implementation of

IAgentRuntime.updateRecentMessageState

Defined in

packages/core/src/runtime.ts:1181