ignition-monorepo / backend-onnx/src / OnnxAgent
Class: OnnxAgent
Defined in: backend-onnx/src/agents/onnx-agent.ts:20
Inference-only RL agent that loads a pre-trained .onnx model and runs forward passes.
Implements AgentInterface — remember() and train() are no-ops since this agent is meant for production inference, not training.
Usage:
const agent = new OnnxAgent({ modelPath: './model.onnx', actionSize: 4 });
await agent.load();
const action = await agent.getAction([0.1, -0.3, 0.5, 0.2]);
agent.dispose();Implements
Constructors
Constructor
new OnnxAgent(
config):OnnxAgent
Defined in: backend-onnx/src/agents/onnx-agent.ts:24
Parameters
config
modelPath
string | Uint8Array<ArrayBuffer> | Buffer<ArrayBufferLike> = ...
Path to the .onnx model file, or a Buffer/Uint8Array for in-memory usage
actionSize
number = ...
Number of discrete actions the agent can take
executionProviders?
string[] = ...
ONNX execution providers in priority order
inputName?
string = ...
Name of the input tensor in the ONNX graph
outputName?
string = ...
Name of the output tensor in the ONNX graph (Q-values)
Returns
OnnxAgent
Methods
load()
load():
Promise<void>
Defined in: backend-onnx/src/agents/onnx-agent.ts:32
Loads the ONNX model and creates the inference session. Must be called before getAction().
Returns
Promise<void>
Implementation of
getAction()
getAction(
observation):Promise<number>
Defined in: backend-onnx/src/agents/onnx-agent.ts:44
Runs a forward pass through the ONNX model and returns the greedy action (argmax of Q-values).
Parameters
observation
number[]
State vector as number array
Returns
Promise<number>
Discrete action index in [0, actionSize)
Implementation of
remember()
remember(
_experience):void
Defined in: backend-onnx/src/agents/onnx-agent.ts:64
No-op — ONNX agents do not accumulate experience
Parameters
_experience
Returns
void
Implementation of
train()
train():
Promise<void>
Defined in: backend-onnx/src/agents/onnx-agent.ts:67
No-op — ONNX agents do not train
Returns
Promise<void>
Implementation of
inspect()
inspect():
object
Defined in: backend-onnx/src/agents/onnx-agent.ts:73
Returns input/output tensor names for debugging. Useful when the default inputName/outputName don’t match your ONNX model.
Returns
object
inputs
inputs:
string[]
outputs
outputs:
string[]
loadFromHub()
loadFromHub(
repoId,filename?):Promise<void>
Defined in: backend-onnx/src/agents/onnx-agent.ts:85
Downloads a .onnx file from HF Hub and loads it as the inference session.
Parameters
repoId
string
HF Hub repo (e.g. “salim4n/my-dqn-model”)
filename?
string = 'model.onnx'
Filename in the repo (default: “model.onnx”)
Returns
Promise<void>
dispose()
dispose():
void
Defined in: backend-onnx/src/agents/onnx-agent.ts:91
Releases the ONNX inference session
Returns
void