feat(tools/looker): Report field suggestions to agent (#1267)

## Description
---
Report the LookML suggestions array or the suggst_explore and
suggest_dimension to the caller so
that the caller can use those suggestions to improve filtering.

## PR Checklist
---
> Thank you for opening a Pull Request! Before submitting your PR, there
are a
> few things you can do to make sure it goes smoothly:
- [x] Make sure you reviewed

[CONTRIBUTING.md](https://github.com/googleapis/genai-toolbox/blob/main/CONTRIBUTING.md)
- [x] Make sure to open an issue as a

[bug/issue](https://github.com/googleapis/langchain-google-alloydb-pg-python/issues/new/choose)
before writing your code! That way we can discuss the change, evaluate
  designs, and agree on the general idea
- [x] Ensure the tests and linter pass
- [x] Code coverage does not decrease (if any source code was changed)
- [x] Appropriate docs were updated (if necessary)
- [x] Make sure to add `!` if this involve a breaking change

🛠️ Fixes #1247
This commit is contained in:
Dr. Strangelove
2025-09-03 14:17:22 -04:00
committed by GitHub
parent 3ae2526e0f
commit 2cad82e510
8 changed files with 74 additions and 22 deletions

View File

@@ -33,6 +33,12 @@ tools:
It takes two parameters, the model_name looked up from get_models and the
explore_name looked up from get_explores.
If this returns a suggestions field for a dimension, the contents of suggestions
can be used as filters for this field. If this returns a suggest_explore and
suggest_dimension, a query against that explore and dimension can be used to find
valid filters for this field.
```
The response is a json array with the following elements:
@@ -45,7 +51,10 @@ The response is a json array with the following elements:
"label": "field label",
"label_short": "field short label",
"tags": ["tags", ...],
"synonyms": ["synonyms", ...]
"synonyms": ["synonyms", ...],
"suggestions": ["suggestion", ...],
"suggest_explore": "explore",
"suggest_dimension": "dimension"
}
```

View File

@@ -45,7 +45,10 @@ The response is a json array with the following elements:
"label": "field label",
"label_short": "field short label",
"tags": ["tags", ...],
"synonyms": ["synonyms", ...]
"synonyms": ["synonyms", ...],
"suggestions": ["suggestion", ...],
"suggest_explore": "explore",
"suggest_dimension": "dimension"
}
```

View File

@@ -33,6 +33,12 @@ tools:
It takes two parameters, the model_name looked up from get_models and the
explore_name looked up from get_explores.
If this returns a suggestions field for a measure, the contents of suggestions
can be used as filters for this field. If this returns a suggest_explore and
suggest_dimension, a query against that explore and dimension can be used to find
valid filters for this field.
```
The response is a json array with the following elements:
@@ -45,7 +51,10 @@ The response is a json array with the following elements:
"label": "field label",
"label_short": "field short label",
"tags": ["tags", ...],
"synonyms": ["synonyms", ...]
"synonyms": ["synonyms", ...],
"suggestions": ["suggestion", ...],
"suggest_explore": "explore",
"suggest_dimension": "dimension"
}
```

View File

@@ -45,7 +45,10 @@ The response is a json array with the following elements:
"label": "field label",
"label_short": "field short label",
"tags": ["tags", ...],
"synonyms": ["synonyms", ...]
"synonyms": ["synonyms", ...],
"suggestions": ["suggestion", ...],
"suggest_explore": "explore",
"suggest_dimension": "dimension"
}
```

View File

@@ -53,6 +53,11 @@ tools:
It takes two parameters, the model_name looked up from get_models and the
explore_name looked up from get_explores.
If this returns a suggestions field for a dimension, the contents of suggestions
can be used as filters for this field. If this returns a suggest_explore and
suggest_dimension, a query against that explore and dimension can be used to find
valid filters for this field.
get_measures:
kind: looker-get-measures
source: looker-source
@@ -63,6 +68,11 @@ tools:
It takes two parameters, the model_name looked up from get_models and the
explore_name looked up from get_explores.
If this returns a suggestions field for a measure, the contents of suggestions
can be used as filters for this field. If this returns a suggest_explore and
suggest_dimension, a query against that explore and dimension can be used to find
valid filters for this field.
get_filters:
kind: looker-get-filters
source: looker-source

View File

@@ -72,10 +72,10 @@ func GetLookerSDK(useClientOAuth bool, config *rtl.ApiSettings, client *v4.Looke
}
const (
DimensionsFields = "fields(dimensions(name,type,label,label_short,description,synonyms,tags,hidden))"
FiltersFields = "fields(filters(name,type,label,label_short,description,synonyms,tags,hidden))"
MeasuresFields = "fields(measures(name,type,label,label_short,description,synonyms,tags,hidden))"
ParametersFields = "fields(parameters(name,type,label,label_short,description,synonyms,tags,hidden))"
DimensionsFields = "fields(dimensions(name,type,label,label_short,description,synonyms,tags,hidden,suggestable,suggestions,suggest_dimension,suggest_explore))"
FiltersFields = "fields(filters(name,type,label,label_short,description,synonyms,tags,hidden,suggestable,suggestions,suggest_dimension,suggest_explore))"
MeasuresFields = "fields(measures(name,type,label,label_short,description,synonyms,tags,hidden,suggestable,suggestions,suggest_dimension,suggest_explore))"
ParametersFields = "fields(parameters(name,type,label,label_short,description,synonyms,tags,hidden,suggestable,suggestions,suggest_dimension,suggest_explore))"
)
// ExtractLookerFieldProperties extracts common properties from Looker field objects.
@@ -118,12 +118,21 @@ func ExtractLookerFieldProperties(ctx context.Context, fields *[]v4.LookmlModelE
if v.Description != nil {
vMap["description"] = *v.Description
}
if v.Tags != nil {
if v.Tags != nil && len(*v.Tags) > 0 {
vMap["tags"] = *v.Tags
}
if v.Synonyms != nil {
if v.Synonyms != nil && len(*v.Synonyms) > 0 {
vMap["synonyms"] = *v.Synonyms
}
if v.Suggestable != nil && *v.Suggestable {
if v.Suggestions != nil && len(*v.Suggestions) > 0 {
vMap["suggestions"] = *v.Suggestions
}
if v.SuggestExplore != nil && v.SuggestDimension != nil {
vMap["suggest_explore"] = *v.SuggestExplore
vMap["suggest_dimension"] = *v.SuggestDimension
}
}
logger.DebugContext(ctx, "Converted to %v\n", vMap)
data = append(data, vMap)
}

View File

@@ -31,6 +31,8 @@ func TestExtractLookerFieldProperties(t *testing.T) {
// Helper function to create string pointers
stringPtr := func(s string) *string { return &s }
stringArrayPtr := func(s []string) *[]string { return &s }
boolPtr := func(b bool) *bool { return &b }
tcs := []struct {
desc string
@@ -41,20 +43,27 @@ func TestExtractLookerFieldProperties(t *testing.T) {
desc: "field with all properties including description",
fields: []v4.LookmlModelExploreField{
{
Name: stringPtr("dimension_name"),
Type: stringPtr("string"),
Label: stringPtr("Dimension Label"),
LabelShort: stringPtr("Dim Label"),
Description: stringPtr("This is a dimension description"),
Name: stringPtr("dimension_name"),
Type: stringPtr("string"),
Label: stringPtr("Dimension Label"),
LabelShort: stringPtr("Dim Label"),
Description: stringPtr("This is a dimension description"),
Suggestable: boolPtr(true),
SuggestExplore: stringPtr("explore"),
SuggestDimension: stringPtr("dimension"),
Suggestions: stringArrayPtr([]string{"foo", "bar", "baz"}),
},
},
want: []any{
map[string]any{
"name": "dimension_name",
"type": "string",
"label": "Dimension Label",
"label_short": "Dim Label",
"description": "This is a dimension description",
"name": "dimension_name",
"type": "string",
"label": "Dimension Label",
"label_short": "Dim Label",
"description": "This is a dimension description",
"suggest_explore": "explore",
"suggest_dimension": "dimension",
"suggestions": []string{"foo", "bar", "baz"},
},
},
},

View File

@@ -624,10 +624,10 @@ func TestLooker(t *testing.T) {
wantResult = "{\"description\":\"Data about Look and dashboard usage, including frequency of views, favoriting, scheduling, embedding, and access via the API. Also includes details about individual Looks and dashboards.\",\"group_label\":\"System Activity\",\"label\":\"Content Usage\",\"name\":\"content_usage\"}"
tests.RunToolInvokeParametersTest(t, "get_explores", []byte(`{"model": "system__activity"}`), wantResult)
wantResult = "{\"description\":\"Number of times this content has been viewed via the Looker API\",\"label\":\"Content Usage API Count\",\"label_short\":\"API Count\",\"name\":\"content_usage.api_count\",\"synonyms\":[],\"tags\":[],\"type\":\"number\"}"
wantResult = "{\"description\":\"Number of times this content has been viewed via the Looker API\",\"label\":\"Content Usage API Count\",\"label_short\":\"API Count\",\"name\":\"content_usage.api_count\",\"type\":\"number\"}"
tests.RunToolInvokeParametersTest(t, "get_dimensions", []byte(`{"model": "system__activity", "explore": "content_usage"}`), wantResult)
wantResult = "{\"description\":\"The total number of views via the Looker API\",\"label\":\"Content Usage API Total\",\"label_short\":\"API Total\",\"name\":\"content_usage.api_total\",\"synonyms\":[],\"tags\":[],\"type\":\"sum\"}"
wantResult = "{\"description\":\"The total number of views via the Looker API\",\"label\":\"Content Usage API Total\",\"label_short\":\"API Total\",\"name\":\"content_usage.api_total\",\"type\":\"sum\"}"
tests.RunToolInvokeParametersTest(t, "get_measures", []byte(`{"model": "system__activity", "explore": "content_usage"}`), wantResult)
wantResult = "[]"