# Creating a Smart NPC

To create a smart NPC, use the AIAgentManager's CreateAgent method. This method initializes an AI agent and binds it to an NPC model, enabling it to act based on AI decisions.

***

#### Required Parameters

* `GetGameState():` A function that returns the current game state as a table when called. This is passed to the AI for contextual decision-making.<br>
* `NPC Model:` The NPC model instance in the game. It must contain a Humanoid, HumanoidRootPart, and a valid PrimaryPart.<br>
* `PersonalityId:` A string representing the selected personality profile for the AI agent (e.g., "clown", "fortune-teller", etc.).<br>
* `ExecutableCommands:` A table that lists the commands the agent is allowed to execute. Each command can optionally include context or conditions under which it should be used. This will be sent to the AI server so the AI can determine appropriate actions.<br>
* [`ContinuousBehaviorScripts[]`](/build-with-sovrun/readygamer/roblox-integration/roblox-ai-agent-module/creating-a-continuous-behaviour-script.md)`:` An array of behavior modules to assign to the NPC. Each module defines recurring logic such as patrols, scanning, or idle checks.<br>
* `Frequency:` A number that determines how often the continuous behavior scripts should be executed.

Sample Usage:

`local replicatedStorage = game:GetService("ReplicatedStorage")`\
&#x20;`local aiAgentManager = require(replicatedStorage.AIAgentModule.AIAgentManager)`\
&#x20;`local customBehaviorScript = require(replicatedStorage.CustomScript)`\
&#x20;`local clownSmartNpc = aiAgentManager:CreateAgent(`\
&#x20;   `gameState, -- Function that returns the game state`\
&#x20;   `workspace.NPCs:WaitForChild("Clown"), -- NPC Model`\
&#x20;   `"clown", -- Personality ID`\
&#x20;   `{ "MoveTo", "FollowTarget" }, -- Executable commands`\
&#x20;   `{ customBehaviorScript }, -- Behavior scripts`\
&#x20;   `100 -- Behavior execution frequency`\
&#x20;`)`


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.sovrun.org/build-with-sovrun/readygamer/roblox-integration/roblox-ai-agent-module/creating-a-smart-npc.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
