///
import { MemoryManager } from "./memory";
import { Content, Goal, Provider, State, type Action, type Evaluator, type Message } from "./types";
import { UUID } from "crypto";
import { DatabaseAdapter } from "./database";
import { type Actor, type Memory } from "./types";
/**
* Represents the runtime environment for an agent, handling message processing,
* action registration, and interaction with external services like OpenAI and Supabase.
*/
export declare class BgentRuntime {
#private;
/**
* The ID of the agent
*/
agentId: UUID;
/**
* The base URL of the server where the agent's requests are processed.
*/
serverUrl: string;
/**
* The database adapter used for interacting with the database.
*/
databaseAdapter: DatabaseAdapter;
/**
* Authentication token used for securing requests.
*/
token: string | null;
/**
* Indicates if debug messages should be logged.
*/
debugMode: boolean;
/**
* Custom actions that the agent can perform.
*/
actions: Action[];
/**
* Evaluators used to assess and guide the agent's responses.
*/
evaluators: Evaluator[];
/**
* Context providers used to provide context for message generation.
*/
providers: Provider[];
/**
* The model to use for completion.
*/
model: string;
/**
* The model to use for embedding.
*/
embeddingModel: string;
/**
* Fetch function to use
* Some environments may not have access to the global fetch function and need a custom fetch override.
*/
fetch: typeof fetch;
/**
* Store messages that are sent and received by the agent.
*/
messageManager: MemoryManager;
/**
* Store and recall descriptions of users based on conversations.
*/
descriptionManager: MemoryManager;
/**
* Manage the fact and recall of facts.
*/
factManager: MemoryManager;
/**
* Manage the creation and recall of static information (documents, historical game lore, etc)
*/
loreManager: MemoryManager;
/**
* Creates an instance of BgentRuntime.
* @param opts - The options for configuring the BgentRuntime.
* @param opts.conversationLength - The number of messages to hold in the recent message cache.
* @param opts.token - The JWT token, can be a JWT token if outside worker, or an OpenAI token if inside worker.
* @param opts.debugMode - If true, debug messages will be logged.
* @param opts.serverUrl - The URL of the worker.
* @param opts.actions - Optional custom actions.
* @param opts.evaluators - Optional custom evaluators.
* @param opts.providers - Optional context providers.
* @param opts.model - The model to use for completion.
* @param opts.embeddingModel - The model to use for embedding.
* @param opts.agentId - Optional ID of the agent.
* @param opts.databaseAdapter - The database adapter used for interacting with the database.
* @param opts.fetch - Custom fetch function to use for making requests.
*/
constructor(opts: {
conversationLength?: number;
agentId?: UUID;
token: string;
debugMode?: boolean;
serverUrl?: string;
actions?: Action[];
evaluators?: Evaluator[];
providers?: Provider[];
model?: string;
embeddingModel?: string;
databaseAdapter: DatabaseAdapter;
fetch?: typeof fetch | unknown;
});
/**
* Get the number of messages that are kept in the conversation buffer.
* @returns The number of recent messages to be kept in memory.
*/
getConversationLength(): number;
/**
* Register an action for the agent to perform.
* @param action The action to register.
*/
registerAction(action: Action): void;
/**
* Register an evaluator to assess and guide the agent's responses.
* @param evaluator The evaluator to register.
*/
registerEvaluator(evaluator: Evaluator): void;
/**
* Register a context provider to provide context for message generation.
* @param provider The context provider to register.
*/
registerContextProvider(provider: Provider): void;
/**
* Send a message to the OpenAI API for completion.
* @param opts - The options for the completion request.
* @param opts.context The context of the message to be completed.
* @param opts.stop A list of strings to stop the completion at.
* @param opts.model The model to use for completion.
* @param opts.frequency_penalty The frequency penalty to apply to the completion.
* @param opts.presence_penalty The presence penalty to apply to the completion.
* @param opts.temperature The temperature to apply to the completion.
* @returns The completed message.
*/
completion({ context, stop, model, frequency_penalty, presence_penalty, temperature, }: {
context?: string | undefined;
stop?: never[] | undefined;
model?: string | undefined;
frequency_penalty?: number | undefined;
presence_penalty?: number | undefined;
temperature?: number | undefined;
}): Promise;
/**
* Send a message to the OpenAI API for embedding.
* @param input The input to be embedded.
* @returns The embedding of the input.
*/
embed(input: string): Promise;
retrieveCachedEmbedding(input: string): Promise;
/**
* Process the actions of a message.
* @param message The message to process.
* @param content The content of the message to process actions from.
*/
processActions(message: Message, content: Content, state?: State): Promise;
/**
* Evaluate the message and state using the registered evaluators.
* @param message The message to evaluate.
* @param state The state of the agent.
* @returns The results of the evaluation.
*/
evaluate(message: Message, state?: State): Promise;
/**
* Ensure the existence of a participant in the room. If the participant does not exist, they are added to the room.
* @param user_id - The user ID to ensure the existence of.
* @throws An error if the participant cannot be added.
*/
ensureParticipantExists(user_id: UUID, room_id: UUID): Promise;
/**
* 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.
* @param user_id - The user ID to create a room with.
* @returns The room ID of the room between the agent and the user.
* @throws An error if the room cannot be created.
*/
ensureRoomExists(user_id: UUID, room_id?: UUID): Promise<`${string}-${string}-${string}-${string}-${string}`>;
/**
* Compose the state of the agent into an object that can be passed or used for response generation.
* @param message The message to compose the state from.
* @returns The state of the agent.
*/
composeState(message: Message, additionalKeys?: {
[key: string]: unknown;
}): Promise<{
actionNames: string;
actionConditions: string;
actions: string;
actionExamples: string;
evaluatorsData: Evaluator[];
evaluators: string;
evaluatorNames: string;
evaluatorConditions: string;
evaluatorExamples: string;
providers: string;
agentId: `${string}-${string}-${string}-${string}-${string}`;
agentName: string | undefined;
senderName: string | undefined;
actors: string;
actorsData: Actor[];
room_id: `${string}-${string}-${string}-${string}-${string}`;
goals: string;
lore: string;
loreData: Memory[];
goalsData: Goal[];
recentMessages: string;
recentMessagesData: Memory[];
recentFacts: string;
recentFactsData: Memory[];
relevantFacts: string;
relevantFactsData: Memory[];
}>;
}