Design an agentic AI system with a custom API data endpoint and custom database implementation to process data and present the user a query interface to ask questions about the processed data from the API data source.
Implement the deterministic query core as query_api_data(records, queries). Each record is a dictionary with an integer id; queries use field=value, field~term, AND, OR, parentheses, optional SORT field ASC|DESC, and optional LIMIT n. Return matching record IDs for each query, using indexes rather than scanning every record for each request.
def query_api_data(records, queries):