---
title: "Stateful NPC"
slug: plugins/unity/Samples~/StatefulNpc
---

<a id="stateful-npc"></a>

Attach `StatefulNpcExample` and `AstralRuntimeInitializer` to a GameObject. Call
`Ask` from a UI button or gameplay interaction. Configure a generation model
before starting the agent.

The component keeps system prompt, summary, and retrieved memory context in the
native agent. It saves history under `Application.persistentDataPath`, restores
that history on the next run, and releases the assigned executor slot after a
chat finishes. The `move_to` tool demonstrates how generated structured actions
cross into gameplay code.

Use `ClearHistory` when starting a new save game. For real dialogue, set the
model path and backend and replace the log calls with your subtitle and action
dispatch systems.

Source: [View the pinned source](https://github.com/Cosmin-B/astral-runtime/blob/f2d13b77c70624ede5bc06823d4a794a4b955e10/plugins/unity/Samples~/StatefulNpc/README.md) · [Edit this source](https://github.com/Cosmin-B/astral-runtime/edit/main/plugins/unity/Samples~/StatefulNpc/README.md)
