Skip to content

DynamicQueries

relationalai.agent.cortex.queries
DynamicQueries(model: rai.Model, *)

Queries provider that lets agents author ad-hoc queries against a PyRel model.

Discovery returns a queryable-schema view derived from schema. At runtime the agent constructs and executes queries directly — the deployer only wires up the model.

Errors raised during validation or execution arrive as a structured envelope (see DynamicQuerySpecError) so the agent can self-correct on retry without a round-trip to a human.

PRIVATE PREVIEW: ships under QUERY (preview-gated). Dynamic queries are intentionally a small-result, exploratory surface that complements rather than replaces catalog queries — narrow filters, counts, and simple aggregations.

  • model

    (relationalai.semantics.Model) - The model to query against. Its queryable schema (via schema) is what the agent sees at discovery time.
DynamicQueries.get_available_queries() -> dict

Return queryable-schema metadata and instructions for dynamic queries.

Returns:

  • dict - Dict with "query_mode", "queries" (single entry for the reserved id), "schema", "spec_format", and "query_instructions" keys.
DynamicQueries.explain(query_id: str) -> Optional[str]

Return the full dynamic-mode reference when query_id is "dynamic".

Bundles the instructions and the per-model queryable schema. This is the content the agent needs to author a valid dynamic query spec for this model.

Parameters:

  • query_id

    (str) - Must be "dynamic" for this provider.

Returns:

  • str or None - Instructions plus the queryable schema as a single string, or None if query_id is anything other than "dynamic".
DynamicQueries.execute(query_id: str, args: dict) -> pandas.DataFrame

Execute the spec carried in args["spec"] against the bound model.

Parameters:

  • query_id

    (str) - Must be "dynamic" for this provider.
  • args

    (dict) - Must include "spec" — the validated dynamic-query spec.

Returns:

  • pandas.DataFrame - Rows produced by executing the spec against the bound model.

Raises:

  • KeyError - If query_id is not "dynamic".
  • DynamicQuerySpecError - If args does not carry a spec key.
DynamicQueriesQueriesabc.ABC