In order to test out the SDK, users can create a demo agent that can start taking actions in their game! The purpose of the demo agent is to test out the entire flow of feeding in a state, taking actions, collecting data, and executing the actions in-game.
const { AgentFactory } = require('nrn-agents');
const modelData = {
config: {
modelType: "neural-network", // Type of model architecture
inputDim: 5, // Number of features for the state
neurons: [12, 6], // Number of neurons in each layer
actionOrder: ["up", "down", "idle"] // Order of action outputs
}
}
const agent = AgentFactory.createDemoAgent(modelData)
using NrnAgents.Agents;
using NrnAgents.MachineLearning;
ModelData modelData = new ()
{
Config = new ()
{
ModelType = "neural-network",
NFeatures = 5,
Neurons = new List<int> () { 12, 6 },
ActionMetadata = MetadataCreation.CreateActionMetadata(
new AgentActions () {
ActionOrder = new () { "Up", "Down", "Idle" }
}
)
}
};
DemoAgent Agent = AgentFactory.CreateDemoAgent(modelData);
Demo agents do not have the ability to learn
Production
When initializing a model in-game, we need to use the following inputs:
architectureId: A model architecture that has been registered
userId: Unique identifier for a specific player
slotIdx: Which model to use since each player may have multiple model slots
If NRN detects that there is already a model loaded for that user, it will load the trained model. In order to create a new randomly initialized model, developers can either input an unused slotIdx when creating the agent or call the reset method (currently only available in Javascript).
const { AgentFactory } = require('nrn-agents');
const agent= AgentFactory.createAgent(
"my-first-model", // architecture id
"user-id", // user id
0, // slot idx (default 0 if not provided)
)
await agent.initialize()
agent.reset() // To reset the agent
using NrnAgents.Agents;
IAgentRL Agent = AgentFactory.CreateAgent<IAgentRL>(
"reinforcement", // learning algorithm type
"my-first-model", // architecture id
"user-id", // user id
0, // slot idx
);