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.actions?: Action
[]
Optional custom actions.
• opts.agentId?: `${string}-${string}-${string}-${string}-${string}`
Optional ID of the agent.
• opts.character?: Character
• opts.conversationLength?: number
The number of messages to hold in the recent message cache.
• opts.databaseAdapter: IDatabaseAdapter
The database adapter used for interacting with the database.
• opts.evaluators?: Evaluator
[]
Optional custom evaluators.
• opts.fetch?: unknown
Custom fetch function to use for making requests.
• opts.managers?: IMemoryManager
[]
• opts.modelProvider: ModelProviderName
• opts.plugins?: Plugin
[]
• opts.providers?: Provider
[]
Optional context providers.
• opts.serverUrl?: string
The URL of the worker.
• opts.services?: Service
[]
Optional custom services.
• opts.speechModelPath?: string
• opts.token: string
The JWT token, can be a JWT token if outside worker, or an OpenAI token if inside worker.
Returns
Defined in
packages/core/src/runtime.ts:192
Properties
actions
actions:
Action
[] =[]
Custom actions that the agent can perform.
Implementation of
Defined in
packages/core/src/runtime.ts:78
agentId
agentId: `${string}-${string}-${string}-${string}-${string}`
The ID of the agent
Implementation of
Defined in
packages/core/src/runtime.ts:59
character
character:
Character
The character to use for the agent
Implementation of
Defined in
packages/core/src/runtime.ts:104
databaseAdapter
databaseAdapter:
IDatabaseAdapter
The database adapter used for interacting with the database.
Implementation of
Defined in
packages/core/src/runtime.ts:68
descriptionManager
descriptionManager:
IMemoryManager
Store and recall descriptions of users based on conversations.
Implementation of
IAgentRuntime
.descriptionManager
Defined in
packages/core/src/runtime.ts:114
documentsManager
documentsManager:
IMemoryManager
Hold large documents that can be referenced
Defined in
packages/core/src/runtime.ts:124
evaluators
evaluators:
Evaluator
[] =[]
Evaluators used to assess and guide the agent's responses.
Implementation of
Defined in
packages/core/src/runtime.ts:83
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.
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:99
knowledgeManager
knowledgeManager:
IMemoryManager
Searchable document fragments
Defined in
packages/core/src/runtime.ts:129
loreManager
loreManager:
IMemoryManager
Manage the creation and recall of static information (documents, historical game lore, etc)
Implementation of
Defined in
packages/core/src/runtime.ts:119
memoryManagers
memoryManagers:
Map
<string
,IMemoryManager
>
Defined in
packages/core/src/runtime.ts:132
messageManager
messageManager:
IMemoryManager
Store messages that are sent and received by the agent.
Implementation of
Defined in
packages/core/src/runtime.ts:109
modelProvider
modelProvider:
ModelProviderName
The model to use for generateText.
Implementation of
Defined in
packages/core/src/runtime.ts:93
providers
providers:
Provider
[] =[]
Context providers used to provide context for message generation.
Implementation of
Defined in
packages/core/src/runtime.ts:88
serverUrl
serverUrl:
string
="http://localhost:7998"
The base URL of the server where the agent's requests are processed.
Implementation of
Defined in
packages/core/src/runtime.ts:63
services
services:
Map
<ServiceType
,Service
>
Implementation of
Defined in
packages/core/src/runtime.ts:131
token
token:
string
Authentication token used for securing requests.
Implementation of
Defined in
packages/core/src/runtime.ts:73
Methods
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
Defined in
packages/core/src/runtime.ts:667
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:618
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:571
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:607
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:654
ensureUserExists()
ensureUserExists(
userId
,userName
,name
,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:587
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
Defined in
packages/core/src/runtime.ts:501
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:394
getMemoryManager()
getMemoryManager(
tableName
):IMemoryManager
Parameters
• tableName: string
Returns
Implementation of
IAgentRuntime
.getMemoryManager
Defined in
packages/core/src/runtime.ts:149
getService()
getService(
service
): typeofService
Parameters
• service: ServiceType
Returns
typeof Service
Implementation of
Defined in
packages/core/src/runtime.ts:153
getSetting()
getSetting(
key
):any
Parameters
• key: string
Returns
any
Implementation of
Defined in
packages/core/src/runtime.ts:372
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
Defined in
packages/core/src/runtime.ts:428
registerAction()
registerAction(
action
):void
Register an action for the agent to perform.
Parameters
• action: Action
The action to register.
Returns
void
Implementation of
Defined in
packages/core/src/runtime.ts:402
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:419
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:411
registerMemoryManager()
registerMemoryManager(
manager
):void
Parameters
• manager: IMemoryManager
Returns
void
Implementation of
IAgentRuntime
.registerMemoryManager
Defined in
packages/core/src/runtime.ts:134
registerService()
registerService(
service
):void
Parameters
• service: Service
Returns
void
Implementation of
Defined in
packages/core/src/runtime.ts:161
updateRecentMessageState()
updateRecentMessageState(
state
):Promise
<State
>
Parameters
• state: State
Returns
Promise
<State
>
Implementation of
IAgentRuntime
.updateRecentMessageState