Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,26 @@ name: ask_data_insights
type: bigquery-conversational-analytics
source: my-bigquery-source
description: |
Use this tool to perform data analysis, get insights, or answer complex
Use this tool to perform data analysis, get insights, or answer complex
questions about the contents of specific BigQuery tables.
```

### Using a Data Agent

You can optionally configure a
[data agent](https://cloud.google.com/gemini/docs/conversational-analytics-api/reference/rest/v1beta/projects.locations/chat#DataAgentContext)
to provide additional context for the conversational analytics API. When a
`dataAgent` is specified, the tool uses the data agent context instead of inline
context.

```yaml
kind: tools
name: ask_data_insights
type: bigquery-conversational-analytics
source: my-bigquery-source
dataAgent: projects/my-project/locations/us/dataAgents/my-agent-id
description: |
Use this tool to perform data analysis, get insights, or answer complex
questions about the contents of specific BigQuery tables.
```

Expand All @@ -69,3 +88,4 @@ description: |
| type | string | true | Must be "bigquery-conversational-analytics". |
| source | string | true | Name of the source for chat. |
| description | string | true | Description of the tool that is passed to the LLM. |
| dataAgent | string | false | Full resource name of a data agent (e.g. `projects/{project}/locations/{location}/dataAgents/{dataAgentId}`). When set, the tool uses data agent context instead of inline context. |
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,31 @@ description: |
Use the 'get_models' and 'get_explores' tools to discover available models and explores.
```

### Using a Data Agent

You can optionally configure a
[data agent](https://cloud.google.com/gemini/docs/conversational-analytics-api/reference/rest/v1beta/projects.locations/chat#DataAgentContext)
to provide additional context for the conversational analytics API. When a
`dataAgent` is specified, the tool uses the data agent context instead of inline
context.

```yaml
kind: tools
name: ask_data_insights
type: looker-conversational-analytics
source: looker-source
dataAgent: projects/my-project/locations/us/dataAgents/my-agent-id
description: |
Use this tool to ask questions about your data using the Looker Conversational
Analytics API. You must provide a natural language query and a list of
1 to 5 model and explore combinations (e.g. [{'model': 'the_model', 'explore': 'the_explore'}]).
```

## Reference

| **field** | **type** | **required** | **description** |
|-------------|:--------:|:------------:|----------------------------------------------------|
| type | string | true | Must be "lookerca-conversational-analytics". |
| type | string | true | Must be "looker-conversational-analytics". |
| source | string | true | Name of the source the SQL should execute on. |
| description | string | true | Description of the tool that is passed to the LLM. |
| dataAgent | string | false | Full resource name of a data agent (e.g. `projects/{project}/locations/{location}/dataAgents/{dataAgentId}`). When set, the tool uses data agent context instead of inline context. |
Original file line number Diff line number Diff line change
Expand Up @@ -98,15 +98,21 @@ type Options struct {
Chart ChartOptions `json:"chart"`
}
type InlineContext struct {
SystemInstruction string `json:"systemInstruction"`
DatasourceReferences DatasourceReferences `json:"datasourceReferences"`
Options Options `json:"options"`
}

type DataAgentContext struct {
DataAgent string `json:"dataAgent"`
}

type CAPayload struct {
Project string `json:"project"`
Messages []Message `json:"messages"`
InlineContext InlineContext `json:"inlineContext"`
ClientIdEnum string `json:"clientIdEnum"`
Project string `json:"project"`
Messages []Message `json:"messages"`
InlineContext *InlineContext `json:"inlineContext,omitempty"`
DataAgentContext *DataAgentContext `json:"dataAgentContext,omitempty"`
ClientIdEnum string `json:"clientIdEnum"`
}

type Config struct {
Expand All @@ -115,6 +121,7 @@ type Config struct {
Source string `yaml:"source" validate:"required"`
Description string `yaml:"description" validate:"required"`
AuthRequired []string `yaml:"authRequired"`
DataAgent string `yaml:"dataAgent,omitempty"`
}

// validate interface
Expand Down Expand Up @@ -216,8 +223,6 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
mapParams := params.AsMap()
userQuery, _ := mapParams["user_query_with_context"].(string)

finalQueryText := fmt.Sprintf("%s\n**User Query and Context:**\n%s", instructions, userQuery)

tableRefsJSON, _ := mapParams["table_references"].(string)
var tableRefs []BQTableReference
if tableRefsJSON != "" {
Expand Down Expand Up @@ -249,15 +254,23 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
}

payload := CAPayload{
Project: fmt.Sprintf("projects/%s", projectID),
Messages: []Message{{UserMessage: UserMessage{Text: finalQueryText}}},
InlineContext: InlineContext{
Project: fmt.Sprintf("projects/%s", projectID),
Messages: []Message{{UserMessage: UserMessage{Text: userQuery}}},
ClientIdEnum: util.GDAClientID,
}

if t.DataAgent != "" {
payload.DataAgentContext = &DataAgentContext{
DataAgent: t.DataAgent,
}
} else {
payload.InlineContext = &InlineContext{
SystemInstruction: instructions,
DatasourceReferences: DatasourceReferences{
BQ: BQDatasource{TableReferences: tableRefs},
},
Options: Options{Chart: ChartOptions{Image: ImageOptions{NoImage: map[string]any{}}}},
},
ClientIdEnum: util.GDAClientID,
}
}

// Call the streaming API
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,15 @@ type InlineContext struct {
DatasourceReferences DatasourceReferences `json:"datasourceReferences"`
Options ConversationOptions `json:"options"`
}
type DataAgentContext struct {
DataAgent string `json:"dataAgent"`
}

type CAPayload struct {
Messages []Message `json:"messages"`
InlineContext InlineContext `json:"inlineContext"`
ClientIdEnum string `json:"clientIdEnum"`
Messages []Message `json:"messages"`
InlineContext *InlineContext `json:"inlineContext,omitempty"`
DataAgentContext *DataAgentContext `json:"dataAgentContext,omitempty"`
ClientIdEnum string `json:"clientIdEnum"`
}

type Config struct {
Expand All @@ -131,6 +136,7 @@ type Config struct {
Description string `yaml:"description" validate:"required"`
AuthRequired []string `yaml:"authRequired"`
Annotations *tools.ToolAnnotations `yaml:"annotations,omitempty"`
DataAgent string `yaml:"dataAgent,omitempty"`
}

// validate interface
Expand Down Expand Up @@ -273,15 +279,22 @@ func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, para
}

payload := CAPayload{
Messages: []Message{{UserMessage: UserMessage{Text: userQuery}}},
InlineContext: InlineContext{
Messages: []Message{{UserMessage: UserMessage{Text: userQuery}}},
ClientIdEnum: util.GDAClientID,
}

if t.DataAgent != "" {
payload.DataAgentContext = &DataAgentContext{
DataAgent: t.DataAgent,
}
} else {
payload.InlineContext = &InlineContext{
SystemInstruction: instructions,
DatasourceReferences: DatasourceReferences{
Looker: lers,
},
Options: ConversationOptions{Chart: ChartOptions{Image: ImageOptions{NoImage: map[string]any{}}}},
},
ClientIdEnum: util.GDAClientID,
}
}

// Call the streaming API
Expand Down