# Callback functions

The module has several colback functions that are called as they are initialized:

* `def on_init` - Called after Stage2, due to the peculiarities of asynchronous programming the availability of the database is not guaranteed
* `async def on_db_ready` - Called immediately after full database initialization, useful to use if you need to work with the database immediately after startup

Example usage:

```
async def on_db_ready(self):
    async with self.db.session_maker() as session:
        # load chat states from database
```


---

# 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://pbmodular-docs.gitbook.io/eng-docs/extended-usage/callback-functions.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.
