There is currently no way to express chained filter queries, such as "how many stadiums are there in towns of less than 2000 inhabitants in Oise?". Indeed, this requires:
- Getting the geometry of Oise.
- Getting all the towns of less than 2000 inhabitants within (using a single
intersect_feature_filter, because Oise yields a single geometry).
- Counting the stadiums that intersect the last obtained geometry... But there is no way to do this currently except doing one query per obtained feature, because the
feature_ref are per-feature.
I propose adding a feature_ref field to the whole FeatureCollection. Since the LLM might confuse the feature_ref of the collection with that of a single Feature within, I would suggest only adding this new field to the output of the _layer tools, and adapting their description so the LLM knows that it should do a _layer query to obtain the feature_ref for the whole collection of results, that can be reused within a filter.
Implementation-wise, I imagine the feature_ref could be composed of:
typename: INTERNAL or PROXY or some other keyword that makes it clear that it is not a queryable typename.
feature_id: the proxy token of the query.
When queried with such a feature_ref, we could then simply decode the token and fetch the geometry to pass to the filter.
This approach would also enable the possibility to remove the GpfGetFeatures tool, in favor of GpfGetFeaturesLayer + GpfGetFeatureById on the obtained feature_ref, which would remove duplication in the tool definitions. I don't know whether that part is a good idea but we can think about it independently from the current issue anyway.
There is currently no way to express chained filter queries, such as "how many stadiums are there in towns of less than 2000 inhabitants in Oise?". Indeed, this requires:
intersect_feature_filter, because Oise yields a single geometry).feature_refare per-feature.I propose adding a
feature_reffield to the whole FeatureCollection. Since the LLM might confuse thefeature_refof the collection with that of a single Feature within, I would suggest only adding this new field to the output of the_layertools, and adapting their description so the LLM knows that it should do a_layerquery to obtain thefeature_reffor the whole collection of results, that can be reused within a filter.Implementation-wise, I imagine the
feature_refcould be composed of:typename: INTERNALorPROXYor some other keyword that makes it clear that it is not a queryable typename.feature_id: the proxy token of the query.When queried with such a
feature_ref, we could then simply decode the token and fetch the geometry to pass to the filter.This approach would also enable the possibility to remove the
GpfGetFeaturestool, in favor ofGpfGetFeaturesLayer+GpfGetFeatureByIdon the obtainedfeature_ref, which would remove duplication in the tool definitions. I don't know whether that part is a good idea but we can think about it independently from the current issue anyway.