# Live Queries

{% hint style="success" %}
This is the official documentation of the `forestadmin-agent-django` and `forestadmin-agent-flask` Python agents.
{% endhint %}

{% hint style="info" %}
Due to popular demand, Live Query Charts and Live Query Segments are reintroduced in ForestAdmin agents since version `agent-python>=1.19.1`
{% endhint %}

ForestAdmin still recommends using [smart charts](/developer-guide-agents-python/getting-started/migrating/code-transformations/api-charts.md) and [smart segments](/developer-guide-agents-python/getting-started/migrating/code-transformations/smart-segments.md) over LiveQueries.

As new agents support multiple datasources, a new property is required when defining a LiveQuery component in the UI. This property will allow the agent to reconcile the query with the proper execution context.

### Enabling the feature on the datasources

To make use of LiveQuery feature, you will need to enable the nativeQuery on your datasource. This ensures a coherent naming scheme for your native query connections as well as only enabling LiveQuery on a restricted set of datasources. Refer to the following documentation to enable nativeQuery on your desired datasources.

* [Django Datasource](/developer-guide-agents-python/data-sources/provided-data-sources/django.md#enable-support-of-live-queries)

### Migrate your UI components

You will have to configure the native query connection on each Live Query component defined in `collection segments`, `analytics chart`, `dashboard charts` and `workspace charts`.

![Select connection on chart](/files/TUz4TgrzeaLwYFP8lIxx) *Select connection on chart*

![Select connection on segments](/files/NueL5PhwiMUrjD65Fgcm) *Select connection on segments*

### Changes in the SQL requests

#### Segments

Previously the segment query must return a list of fields named `id`.Now the field must be named by the `primary key` field.

#### Analytics charts

Previously the analytics charts could use `?` in the request, which will be replaced by the value of the current record id. Now you must use `{{recordId}}` instead.


---

# 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.forestadmin.com/developer-guide-agents-python/getting-started/migrating/code-transformations/live-queries.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.
