@okcashpro/okai v0.1.7-alpha.1 / 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
Defined in
packages/core/src/runtime.ts:209
Properties
agentId
agentId: `${string}-${string}-${string}-${string}-${string}`
The ID of the agent
Implementation of
Defined in
packages/core/src/runtime.ts:63
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:67
databaseAdapter
databaseAdapter:
IDatabaseAdapter
The database adapter used for interacting with the database.
Implementation of
Defined in
packages/core/src/runtime.ts:72
token
token:
string
Authentication token used for securing requests.
Implementation of
Defined in
packages/core/src/runtime.ts:77
actions
actions:
Action
[] =[]
Custom actions that the agent can perform.
Implementation of
Defined in
packages/core/src/runtime.ts:82
evaluators
evaluators:
Evaluator
[] =[]
Evaluators used to assess and guide the agent's responses.
Implementation of
Defined in
packages/core/src/runtime.ts:87
providers
providers:
Provider
[] =[]
Context providers used to provide context for message generation.
Implementation of
Defined in
packages/core/src/runtime.ts:92
plugins
plugins:
Plugin
[] =[]
Implementation of
Defined in
packages/core/src/runtime.ts:94
modelProvider
modelProvider:
ModelProviderName
The model to use for generateText.
Implementation of
Defined in
packages/core/src/runtime.ts:99
imageModelProvider
imageModelProvider:
ModelProviderName
The model to use for generateImage.
Implementation of
IAgentRuntime
.imageModelProvider
Defined in
packages/core/src/runtime.ts:104
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
>
Implementation of
Defined in
packages/core/src/runtime.ts:110
character
character:
Character
The character to use for the agent
Implementation of
Defined in
packages/core/src/runtime.ts:115
messageManager
messageManager:
IMemoryManager
Store messages that are sent and received by the agent.
Implementation of
Defined in
packages/core/src/runtime.ts:120
descriptionManager
descriptionManager:
IMemoryManager
Store and recall descriptions of users based on conversations.
Implementation of
IAgentRuntime
.descriptionManager
Defined in
packages/core/src/runtime.ts:125
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:130
documentsManager
documentsManager:
IMemoryManager
Hold large documents that can be referenced
Implementation of
IAgentRuntime
.documentsManager
Defined in
packages/core/src/runtime.ts:135
knowledgeManager
knowledgeManager:
IMemoryManager
Searchable document fragments
Implementation of
IAgentRuntime
.knowledgeManager
Defined in
packages/core/src/runtime.ts:140
services
services:
Map
<ServiceType
,Service
>
Implementation of
Defined in
packages/core/src/runtime.ts:142
memoryManagers
memoryManagers:
Map
<string
,IMemoryManager
>
Defined in
packages/core/src/runtime.ts:143
cacheManager
cacheManager:
ICacheManager
Implementation of
Defined in
packages/core/src/runtime.ts:144
clients
clients:
Record
<string
,any
>
any could be EventEmitter but I think the real solution is forthcoming as a base client interface
Implementation of
Defined in
packages/core/src/runtime.ts:145
Methods
registerMemoryManager()
registerMemoryManager(
manager
):void
Parameters
• manager: IMemoryManager
Returns
void
Implementation of
IAgentRuntime
.registerMemoryManager
Defined in
packages/core/src/runtime.ts:147
getMemoryManager()
getMemoryManager(
tableName
):IMemoryManager
Parameters
• tableName: string
Returns
Implementation of
IAgentRuntime
.getMemoryManager
Defined in
packages/core/src/runtime.ts:162
getService()
getService<
T
>(service
):T
Type Parameters
• T extends Service
Parameters
• service: ServiceType
Returns
T
Implementation of
Defined in
packages/core/src/runtime.ts:166
registerService()
registerService(
service
):Promise
<void
>
Parameters
• service: Service
Returns
Promise
<void
>
Implementation of
Defined in
packages/core/src/runtime.ts:175
initialize()
initialize():
Promise
<void
>
Returns
Promise
<void
>
Implementation of
Defined in
packages/core/src/runtime.ts:376
stop()
stop():
Promise
<void
>
Returns
Promise
<void
>
Defined in
packages/core/src/runtime.ts:409
getSetting()
getSetting(
key
):any
Parameters
• key: string
Returns
any
Implementation of
Defined in
packages/core/src/runtime.ts:459
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:481
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:489
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:498
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:506
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:515
evaluate()
evaluate(
message
,state
?,didRespond
?,callback
?):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.~
• callback?: HandlerCallback
The handler callback
Returns
Promise
<string
[]>
The results of the evaluation.
Implementation of
Defined in
packages/core/src/runtime.ts:599
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:666
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:682
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:702
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:719
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:755
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:768
updateRecentMessageState()
updateRecentMessageState(
state
):Promise
<State
>
Parameters
• state: State
Returns
Promise
<State
>
Implementation of
IAgentRuntime
.updateRecentMessageState