# Inference with a custom Onnx policy using the AI Agents Plugin

**URL:** <https://forums.unrealengine.com/t/inference-with-a-custom-onnx-policy-using-the-ai-agents-plugin/2125276>\
**Category:** AI\
**Tags:** unreal-engine, question\
**Created:** [November 15, 2024, 5:30pm UTC](https://forums.unrealengine.com/t/inference-with-a-custom-onnx-policy-using-the-ai-agents-plugin/2125276 "2024-11-15T17:30:14Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dr.shixo](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@dr.shixo](https://forums.unrealengine.com/u/dr.shixo)\
**Post date:** [November 15, 2024, 5:30pm UTC](https://forums.unrealengine.com/t/inference-with-a-custom-onnx-policy-using-the-ai-agents-plugin/2125276/1 "2024-11-15T17:30:14Z")

</div>

Hi @Deathcalibur, I wonder if the new “bring your own model” functionality introduced in the Agents plugin 5.5 version would allow inference with an Onnx model for the policy by loading from the file system. If so, would you mind clarifying the steps?

To note, I am after doing that from the Agents plugin as it could be packaged with the game as far as I understand, compared to other Unreal options that would only run using the editor without the ability to package with the game.

Thanks,

---

<div class="post-metadata">

**Author:** ![Deathcalibur](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/deathcalibur/32/1037610_2.png) [@Deathcalibur](https://forums.unrealengine.com/u/Deathcalibur)\
**Post date:** [November 15, 2024, 5:55pm UTC](https://forums.unrealengine.com/t/inference-with-a-custom-onnx-policy-using-the-ai-agents-plugin/2125276/2 "2024-11-15T17:55:10Z")

</div>

I can write up the steps to get it working, but it might be best for me to focus on making it easier to do directly for 5.6. I was able to get ONNX working purely in game project without having to modify the library but obviously this is easier said than done. I’ll see if we can’t sneak it in for 5.6.

BTW, the existing CPU runtime absolutely can be deployed to any end user device (PC, mobile, Switch)… Just want to clear up any potential confusion there. Python is only used at editor time. At game time there is no python.

Thanks!

---

<div class="post-metadata">

**Author:** ![BeauMS24](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BeauMS24](https://forums.unrealengine.com/u/BeauMS24)\
**Post date:** [November 15, 2024, 6:56pm UTC](https://forums.unrealengine.com/t/inference-with-a-custom-onnx-policy-using-the-ai-agents-plugin/2125276/3 "2024-11-15T18:56:07Z")

</div>

Hi @Deathcalibur, in regard to the question posted by @dr.shixo, I was successful in creating a package using the NNE, but it crashes on startup due to an “Assertion failed” error. I tracked it down to a null reference when creating the NNE Runtime object on line 97 (see screenshot). In the editor Runtime is populated successfully but in the package, it fails to be created. Do you know of any way to fix that?

 ![image](https://d3kjluh73b9h9o.cloudfront.net/original/4X/b/0/c/b0cfb295828cc85d59d45b2836c93b4856b1d41a.png)

---

<div class="post-metadata">

**Author:** ![Deathcalibur](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/deathcalibur/32/1037610_2.png) [@Deathcalibur](https://forums.unrealengine.com/u/Deathcalibur)\
**Post date:** [November 15, 2024, 9:53pm UTC](https://forums.unrealengine.com/t/inference-with-a-custom-onnx-policy-using-the-ai-agents-plugin/2125276/4 "2024-11-15T21:53:55Z")

</div>

I’ll try to take a look at this next week. Thanks for investigating!

---

<div class="post-metadata">

**Author:** ![Deathcalibur](https://d1ap1mz92jnks1.cloudfront.net/user_avatar/forums.unrealengine.com/deathcalibur/32/1037610_2.png) [@Deathcalibur](https://forums.unrealengine.com/u/Deathcalibur)\
**Post date:** [November 18, 2024, 3:57pm UTC](https://forums.unrealengine.com/t/inference-with-a-custom-onnx-policy-using-the-ai-agents-plugin/2125276/5 "2024-11-18T15:57:02Z")

</div>

> [@How to use custom model in Learning Agents?](https://forums.unrealengine.com/t/how-to-use-custom-model-in-learning-agents/1947225/8):
>
> I forgot I did a write-up over here with how to use ONNX if you want. The code I provided should be thought of as pseudo-code. I wrote it up in a notepad and did not try to compile it. The idea is you make a sub-class of Policy and add some bits which let LA work with NNE & ONNX: [https://forums.unrealengine.com/t/background-neural-networks-for-leaning-agents-neural-network-data-assets/2080575/2?u=deathcalibur](https://forums.unrealengine.com/t/background-neural-networks-for-leaning-agents-neural-network-data-assets/2080575/2) We haven’t made this part of the LA “official” yet because it has a lot of rough edge…

Let me know if this chain of messages meets your needs or not!

---

<div class="post-metadata">

**Author:** ![BeauMS24](https://d3kjluh73b9h9o.cloudfront.net/original/4X/2/8/5/28502927f1d97ba1051b3b47ccfe17233bf41ef0.png) [@BeauMS24](https://forums.unrealengine.com/u/BeauMS24)\
**Post date:** [November 18, 2024, 4:31pm UTC](https://forums.unrealengine.com/t/inference-with-a-custom-onnx-policy-using-the-ai-agents-plugin/2125276/6 "2024-11-18T16:31:24Z")

</div>

Ok, I will see if I can get this working. Thank you for your help!
