> For the complete documentation index, see [llms.txt](https://docs.openmind.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.openmind.com/build/modes_lifecycle/lifecycle.md).

# Lifecycle

Introducing Lifecycle

### Overview

A lifecycle defines the operational boundaries of a mode, from its activation to its completion or transition to another mode. It is responsible for initializing, managing, and safely terminating a mode's operation, ensuring predictable transitions, consistent state handling, and controlled execution of mode-specific logic.

A mode represents a functional state of the robot, such as Guard, SLAM, or Navigation, and each mode runs within a lifecycle that determines how and when it starts, executes, and ends.

![](https://2120135774-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Ft8vMsruGqqhYpVx9qhd5%2Fuploads%2Fgit-blob-504979dedd445aaa901da518a4cd55b4c006f301%2Flifecycle.png?alt=media)

### Conceptual Model

| Concept       | Description                                                                          |
| ------------- | ------------------------------------------------------------------------------------ |
| **Lifecycle** | Defines the start, execution, and end of a mode                                      |
| **Stage**     | Represents a logical phase within the lifecycle (e.g., startup, entry, active, exit) |
| **Hook**      | A programmable event point that executes specific actions at key stages              |
| **Mode**      | The operational context governed by the lifecycle                                    |

> **In short:** Lifecycle controls the flow → Stages define phases → Hooks perform actions → Mode defines behavior.

### Stages and Hooks

Each lifecycle is composed of several stages. Hooks are executed at specific points in these stages to perform initialization, cleanup, or handling tasks.

| Stage       | Hook         | Description                                                                                   |
| ----------- | ------------ | --------------------------------------------------------------------------------------------- |
| **Startup** | `ON_STARTUP` | Executes system-level initialization before any mode begins                                   |
| **Entry**   | `ON_ENTRY`   | Runs when entering a mode; prepares mode-specific resources and context                       |
| **Active**  | —            | Main operational phase; mode logic runs continuously (no fixed hook)                          |
| **Exit**    | `ON_EXIT`    | Executes cleanup, saves state, and prepares for the next transition                           |
| **Timeout** | `ON_TIMEOUT` | Handles cases where a mode exceeds its defined duration or fails to complete expected actions |

#### Startup Stage

Triggered by `ON_STARTUP`. Executes system-level initialization before any mode begins.

#### Entry Stage

Triggered by `ON_ENTRY`. Runs when entering a mode; prepares mode-specific resources and context.

#### Active Stage

Represents the main operational phase of the mode. No fixed hook; mode logic runs continuously during this stage.

#### Exit Stage

Triggered by `ON_EXIT`. Executes cleanup, saves state, and prepares for the next transition.

#### Timeout Stage

Triggered by `ON_TIMEOUT`. Handles cases where a mode exceeds its defined duration or fails to complete expected actions.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

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

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.openmind.com/build/modes_lifecycle/lifecycle.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

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.
