# Creating a Continuous Behaviour Script

A `ContinuousBehaviorScript` is a module that defines recurring behavior logic for an AI agent. This logic is executed based on a specified frequency set when initializing the agent.

When the behavior runs, the aiAgent instance is passed as a parameter to allow access to its methods and data.

***

#### Requirements

The behavior module **must implement** the following structure:

`local replicatedStorage = game:GetService("ReplicatedStorage")`\
&#x20;`local aiCommandMap = require(replicatedStorage.AIAgentModule.AICommandMap)` &#x20;

&#x20;`local module = {}`

&#x20;`-- Called before the behavior is run`\
&#x20;`function module.InitializeBehavior()`\
&#x20;`-- Perform any setup required before the behavior starts`\
&#x20;`end`

`-- Called before each behavior execution cycle`\
&#x20;`-- Return true to run the behavior, false to skip`\
&#x20;`function module.BehaviorConditionsCheck(aiAgent: AIAgent): boolean`\
&#x20;   `-- Add logic to determine if behavior should run`\
&#x20;`return true`\
&#x20;`end`<br>

`-- Called when conditions pass; executes behavior logic`\
`function module.RunContinuousBehavior(aiAgent: AIAgent)`\
&#x20;   `-- Add your custom behavior script here` \
&#x20;   `-- Sends current game state to the AI server`\
&#x20;   `-- Expects a response which may include a message or command`\
&#x20;   `local response, status = aiAgent.SendQueryToAgent({ aiAgent.GetGameState() })`\
&#x20;   `if not response then`\
&#x20;       `return false`\
&#x20;   `end`\
\
&#x20;   `-- Executes command based on AI response`\
&#x20;   `if response.command then`\
&#x20;       `local commandResponse = aiCommandMap[response.command.functionName](response.command.parameters)`\
&#x20;   `end`\
`end`\
`return module`


---

# 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-continuous-behaviour-script.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.
