Initializing The Core Module
OobeCore Initialization and Usage
The OobeCore
class is a central component in our project, responsible for managing the core functionalities of the oobe-protocol system. Below, we will walk through the initialization process and how to use the OobeCore
class effectively.
import { OobeCore, ConfigManager, IConfiguration } from "oobe-protocol";
const configManager = new ConfigManager();
const config: IConfiguration = {...}
const overrideDefConfig = configManager.createDefaultConfig(config)
const oobe = new OobeCore(configManager.getDefaultConfig()) || new OobeCore(overrideDefConfig)
The configManager.
getDefaultConfig()
method returns the default configuration, which is then passed to the OobeCore
constructor.
The configManager.
createDefaultConfig()
method returns a custom configuration, which is then passed to the OobeCore
constructor to override the default configuration.
Constructor Details
The OobeCore
constructor performs several key tasks:
Logger Initialization: A
Logger
instance is created to handle logging throughout the lifecycle ofOobeCore
.Configuration Verification: The provided configuration is verified using the
verifyConfig
function. If the configuration is invalid, an error is logged, and an exception is thrown.Agent Initialization: If the configuration is valid, an
Agent
instance is created using the configuration details.Memory Saver Initialization: A
MemorySaver
instance is created to manage memory-related operations.
Reference Costructor Core:
*/
* @name OobeCore
* @description Core module for the OOBE protocol
* @example const core = new OobeCore(config)
* @author oobe-protocol
*/
export class OobeCore {
private agent: Agent;
private logger: Logger;
private memory: MemorySaver;
constructor(config: IConfiguration) {
this.logger = new Logger();
if (verifyConfig(config)) {
this.agent = new Agent(config.solanaEndpoint, config.private_key, config.openAiKey, this.logger);
} else {
this.logger.error("Invalid configuration");
throw new Error("Invalid configuration");
}
this.memory = new MemorySaver();
}
}
Usage
Once the instance is initialized, you can start using its various methods to interact with the system.
1. Starting the OobeCore
Use the start
method to initialize the core functionalities:
await oobe.start();
2. Creating and Executing the Agent
Register actions, create tools, setup memory, and initialize the agent loop using AgentExecution
:
await AgentExecution(oobe);
3. Accessing the Agent Instance
Retrieve the agent instance from the OobeCore:
const agent = oobe.getAgent();
4. Registering OOBE Actions
Register all predefined OOBE actions with the agent:
agent.registerActions(Actions.map((action) => action.action));
5. Creating Solana Tools
Generate the toolset to enable on-chain capabilities:
const tools = await createSolanaTools(agent);
6. Setting up Agent Memory
Use MemorySaver
to provide persistent memory to the agent:
const memory = new MemorySaver();
7. Creating a React Agent
Build the interactive agent with tool access and custom personality instructions:
const oobe_agent = createReactAgent({
llm: agent.genAi(),
tools: tools as ToolNode<any>,
checkpointSaver: memory,
messageModifier: `You are a person with this personality "${JSON.stringify(await agent.getDefaultPersonality())}"...`,
});
8. Sending Human Messages
Interact with the agent using user input through streaming:
const stream = await oobe_agent.stream(
{ messages: [new HumanMessage("Your prompt here")] },
{ configurable: { thread_id: "OOBE AGENT BUILDER!" } }
);
9. Merkle Validation and On-Chain Inscription
After tool execution, validate and inscribe the result on-chain:
const data_merkle = agent.merkleValidate(toolsRes, agentRes as Record<string, any>);
await agent.merkle.onChainMerkleInscription(data_merkle);
10. Stopping the OobeCore
Gracefully shut down the system when done:
await oobe.stop();
Last updated