-
Notifications
You must be signed in to change notification settings - Fork 1.4k
feat(tools/looker): Looker agent management from MCP #2830
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 13 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
33e0a57
feat(tools/looker): add looker-agent tool
hiracky16 089ad98
fix(tools/looker): address copilot review feedback
hiracky16 afd8cde
fix(tools/looker): update error status codes to 400 for client errors
hiracky16 5df7717
docs(tools/looker): remove duplicate documentation file
hiracky16 bdf0205
fix(tools/looker): Minor fixes to docs and lookeragent.go
drstrangelooker 8905e5b
fix(tools/looker): address feedback for agent tool (#2834)
hiracky16 e2c5ced
Merge remote-tracking branch 'origin/main' into looker-agent
drstrangelooker 900e7c3
fix(tools/looker): support instructions, sources, and code interprete…
hiracky16 1c9944a
fix(tools/looker): address CI failures and enhance agent tool functio…
hiracky16 a93cb6b
Merge branch 'main' into looker-agent
drstrangelooker 877e1b0
docs: fix location of looker-agent in docs
drstrangelooker 7a08114
docs: fix looker-agent.md
drstrangelooker f571e9e
docs: fix looker-agent.md
drstrangelooker 88926dc
Merge remote-tracking branch 'origin/main' into looker-agent
drstrangelooker 12f5de2
docs: remove aliases from looker-agent.md
drstrangelooker 8887deb
Merge branch 'main' into looker-agent
drstrangelooker 8ef8780
Merge branch 'main' into looker-agent
drstrangelooker e1e295f
Merge branch 'main' into looker-agent
drstrangelooker 5b35207
Merge remote-tracking branch 'origin/main' into looker-agent
drstrangelooker b487ff3
feat(tools/looker): refactor into five tools
drstrangelooker a05e0e8
fix(tool/looker): fix tests
drstrangelooker 0f1314a
Merge remote-tracking branch 'origin/main' into looker-agent
drstrangelooker 0d100d2
fix(tools/looker): refine datatypes and tests for create-agent and up…
drstrangelooker 5fd2693
docs(tools/looker): updated docs for the looker agent management tools.
drstrangelooker b8f37da
fix(tools/looker): enforce critical safety annotations for agent tool…
hiracky16 7bacd2e
Merge branch 'main' into looker-agent
drstrangelooker a75185c
chore: revert change to go.mod
drstrangelooker 9bbfd93
chore: Apply suggestions from gemini code review
drstrangelooker 1890701
chore: added integration tests and improved some logic base on integr…
drstrangelooker be6f5f3
Merge branch 'main' into looker-agent
drstrangelooker File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| --- | ||
| title: "looker-agent" | ||
| type: docs | ||
| weight: 1 | ||
| description: > | ||
| Manage Looker Agents | ||
| aliases: | ||
| - /resources/tools/looker-agent | ||
| --- | ||
|
|
||
| ## About | ||
|
|
||
| The `looker-agent` tool allows LLMs to manage Looker Agents. It supports listing, retrieving, creating, updating, and deleting agents using the Looker Go SDK. | ||
|
|
||
| ## Compatible Sources | ||
|
|
||
| {{< compatible-sources >}} | ||
|
|
||
| ## Requirements | ||
|
|
||
| This tool requires the underlying Looker Go SDK to support the `Agent` API resource (v0.26.6+). | ||
|
|
||
| ## Parameters | ||
|
|
||
| | **Parameter** | **Type** | **Required** | **Description** | | ||
| |:-------------|:--------:|:------------:|:----------------| | ||
| | `operation` | `string` | Yes | The operation to perform. Must be one of: `list`, `get`, `create`, `update`, or `delete`. | | ||
| | `agent_id` | `string` | No | The ID of the agent. Required for `get`, `update`, and `delete` operations. | | ||
| | `name` | `string` | No | The name of the agent. Required for `create` operation. | | ||
| | `instructions` | `string` | No | The instructions (system prompt) for the agent. Used for `create` and `update` operations. | | ||
| | sources | array | No | Optional. A list of JSON-encoded data sources, where each is a string with 'model' and 'explore' keys. | | ||
| | `code_interpreter` | `boolean` | No | Optional. Enables Code Interpreter for this Agent. | | ||
|
|
||
| ## Example | ||
|
|
||
| To use the `looker-agent` tool, you must define it in your `server.yaml` file. | ||
|
|
||
| ```yaml | ||
| kind: tools | ||
| name: agent_manage | ||
| type: looker-agent | ||
| source: my_looker_source | ||
| description: | | ||
| Manage Looker AI Agents. This tool allows you to perform various operations on Looker Agents, | ||
| including listing all available agents, retrieving details for a specific agent, | ||
| creating a new agent, updating an existing one, and deleting an agent. | ||
|
|
||
| Parameters: | ||
| - operation (required): The action to perform. | ||
| - 'list': Returns a list of all existing agents. | ||
| - 'get': Retrieves detailed information about a specific agent. Requires 'agent_id'. | ||
| - 'create': Creates a new Looker AI Agent. Requires 'name'. Optional 'instructions', 'sources', 'code_interpreter'. | ||
| - 'update': Updates an existing Looker AI Agent. Requires 'agent_id'. Optional 'name', 'instructions', 'sources', 'code_interpreter'. | ||
| - 'delete': Removes an existing agent. Requires 'agent_id'. | ||
| - agent_id (optional): The unique identifier of the agent. Required for 'get', 'update', and 'delete' operations. | ||
| - name (optional): The display name for the agent. Required for 'create' operation. | ||
| - instructions (optional): The system prompt or instructions for the agent. Used for 'create' and 'update' operations. | ||
| - sources (optional): A list of JSON-encoded data sources for the agent. Each source should be a JSON string with 'model' and 'explore' keys. | ||
| - code_interpreter (optional): A boolean value to enable or disable Code Interpreter for this Agent. | ||
| ``` | ||
|
|
||
| ## Reference | ||
|
|
||
| ### List Agents | ||
| Retrieve a list of all agents. | ||
| ```json | ||
| { | ||
| "operation": "list" | ||
| } | ||
| ``` | ||
|
|
||
| ### Get Agent | ||
| Retrieve details of a specific agent by its ID. | ||
| ```json | ||
| { | ||
| "operation": "get", | ||
| "agent_id": "12345" | ||
| } | ||
| ``` | ||
|
|
||
| ### Create Agent | ||
| Create a new agent with a name, instructions, data sources, and Code Interpreter enabled. | ||
| ```json | ||
| { | ||
| "operation": "create", | ||
| "name": "My AI Assistant", | ||
| "instructions": "You are a helpful data analyst. Always provide clear summaries.", | ||
| "sources": [ | ||
| "{\"model\": \"thelook\", \"explore\": \"orders\"}" | ||
| ], | ||
| "code_interpreter": true | ||
| } | ||
| ``` | ||
|
|
||
| ### Update Agent | ||
| Update an existing agent's instructions and disable Code Interpreter. | ||
| ```json | ||
| { | ||
| "operation": "update", | ||
| "agent_id": "12345", | ||
| "instructions": "New updated instructions for the agent.", | ||
| "code_interpreter": false | ||
| } | ||
| ``` | ||
|
|
||
| ### Delete Agent | ||
| Delete an agent by its ID. | ||
| ```json | ||
| { | ||
| "operation": "delete", | ||
| "agent_id": "12345" | ||
| } | ||
| ``` | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,272 @@ | ||
| // Copyright 2026 Google LLC | ||
| // | ||
| // Licensed under the Apache License, Version 2.0 (the "License"); | ||
| // you may not use this file except in compliance with the License. | ||
| // You may obtain a copy of the License at | ||
| // | ||
| // http://www.apache.org/licenses/LICENSE-2.0 | ||
| // | ||
| // Unless required by applicable law or agreed to in writing, software | ||
| // distributed under the License is distributed on an "AS IS" BASIS, | ||
| // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| // See the License for the specific language governing permissions and | ||
| // limitations under the License. | ||
| package lookeragent | ||
|
|
||
| import ( | ||
| "context" | ||
| "encoding/json" | ||
| "fmt" | ||
| "net/http" | ||
|
|
||
| yaml "github.com/goccy/go-yaml" | ||
| "github.com/googleapis/genai-toolbox/internal/embeddingmodels" | ||
| "github.com/googleapis/genai-toolbox/internal/sources" | ||
| "github.com/googleapis/genai-toolbox/internal/tools" | ||
| "github.com/googleapis/genai-toolbox/internal/util" | ||
| "github.com/googleapis/genai-toolbox/internal/util/parameters" | ||
|
|
||
| "github.com/looker-open-source/sdk-codegen/go/rtl" | ||
| v4 "github.com/looker-open-source/sdk-codegen/go/sdk/v4" | ||
| ) | ||
|
|
||
| const resourceType string = "looker-agent" | ||
|
|
||
| func init() { | ||
| if !tools.Register(resourceType, newConfig) { | ||
| panic(fmt.Sprintf("tool type %q already registered", resourceType)) | ||
| } | ||
| } | ||
|
|
||
| func newConfig(ctx context.Context, name string, decoder *yaml.Decoder) (tools.ToolConfig, error) { | ||
| actual := Config{Name: name} | ||
| if err := decoder.DecodeContext(ctx, &actual); err != nil { | ||
| return nil, err | ||
| } | ||
| return actual, nil | ||
| } | ||
|
|
||
| type compatibleSource interface { | ||
| UseClientAuthorization() bool | ||
| GetAuthTokenHeaderName() string | ||
| LookerApiSettings() *rtl.ApiSettings | ||
| GetLookerSDK(string) (*v4.LookerSDK, error) | ||
| } | ||
|
|
||
| type Config struct { | ||
| Name string `yaml:"name" validate:"required"` | ||
| Type string `yaml:"type" validate:"required"` | ||
| Source string `yaml:"source" validate:"required"` | ||
| Description string `yaml:"description" validate:"required"` | ||
| AuthRequired []string `yaml:"authRequired"` | ||
| Annotations *tools.ToolAnnotations `yaml:"annotations,omitempty"` | ||
| } | ||
|
|
||
| // validate interface | ||
| var _ tools.ToolConfig = Config{} | ||
|
|
||
| func (cfg Config) ToolConfigType() string { | ||
| return resourceType | ||
| } | ||
|
|
||
| func (cfg Config) Initialize(srcs map[string]sources.Source) (tools.Tool, error) { | ||
| operationParameter := parameters.NewStringParameterWithAllowedValues("operation", "The operation to perform. Must be one of: `list`, `get`, `create`, `update`, or `delete`.", []any{"list", "get", "create", "update", "delete"}) | ||
| agentIdParameter := parameters.NewStringParameterWithDefault("agent_id", "", "The ID of the agent. Required for `get`, `update`, and `delete` operations.") | ||
| nameParameter := parameters.NewStringParameterWithDefault("name", "", "The name of the agent. Required for `create` operation.") | ||
| instructionsParameter := parameters.NewStringParameterWithDefault("instructions", "", "The instructions (system prompt) for the agent. Used for `create` and `update` operations.") | ||
| sourcesParameter := parameters.NewArrayParameterWithDefault("sources", []any{}, "Optional. A list of JSON-encoded data sources for the agent (e.g., ['{\"model\": \"my_model\", \"explore\": \"my_explore\"}']).", parameters.NewStringParameter("source", "A JSON-encoded source object with 'model' and 'explore' keys.")) | ||
| codeInterpreterParameter := parameters.NewBooleanParameterWithDefault("code_interpreter", false, "Optional. Enables Code Interpreter for this Agent. Used for `create` and `update` operations.") | ||
| params := parameters.Parameters{operationParameter, agentIdParameter, nameParameter, instructionsParameter, sourcesParameter, codeInterpreterParameter} | ||
|
|
||
| annotations := cfg.Annotations | ||
|
|
||
| mcpManifest := tools.GetMcpManifest(cfg.Name, cfg.Description, cfg.AuthRequired, params, annotations) | ||
|
|
||
| return Tool{ | ||
| Config: cfg, | ||
| Parameters: params, | ||
| manifest: tools.Manifest{ | ||
| Description: cfg.Description, | ||
| Parameters: params.Manifest(), | ||
| AuthRequired: cfg.AuthRequired, | ||
| }, | ||
| mcpManifest: mcpManifest, | ||
| }, nil | ||
| } | ||
|
|
||
| // validate interface | ||
| var _ tools.Tool = Tool{} | ||
|
|
||
| type Tool struct { | ||
| Config | ||
| Parameters parameters.Parameters `yaml:"parameters"` | ||
| manifest tools.Manifest | ||
| mcpManifest tools.McpManifest | ||
| } | ||
|
|
||
| func (t Tool) ToConfig() tools.ToolConfig { | ||
| return t.Config | ||
| } | ||
|
|
||
| func (t Tool) Invoke(ctx context.Context, resourceMgr tools.SourceProvider, params parameters.ParamValues, accessToken tools.AccessToken) (any, util.ToolboxError) { | ||
| source, err := tools.GetCompatibleSource[compatibleSource](resourceMgr, t.Source, t.Name, t.Type) | ||
| if err != nil { | ||
| return nil, util.NewClientServerError("source used is not compatible with the tool", http.StatusInternalServerError, err) | ||
| } | ||
|
|
||
| logger, err := util.LoggerFromContext(ctx) | ||
| if err != nil { | ||
| return nil, util.NewClientServerError("unable to get logger from ctx", http.StatusInternalServerError, err) | ||
| } | ||
|
|
||
| sdk, err := source.GetLookerSDK(string(accessToken)) | ||
| if err != nil { | ||
| return nil, util.NewClientServerError(fmt.Sprintf("error getting sdk: %v", err), http.StatusInternalServerError, err) | ||
| } | ||
|
|
||
| mapParams := params.AsMap() | ||
| logger.DebugContext(ctx, fmt.Sprintf("%s params = ", t.Name), mapParams) | ||
|
|
||
| var operation, agentId, name, instructions string | ||
| if v, ok := mapParams["operation"].(string); ok { | ||
| operation = v | ||
| } | ||
| if v, ok := mapParams["agent_id"].(string); ok { | ||
| agentId = v | ||
| } | ||
| if v, ok := mapParams["name"].(string); ok { | ||
| name = v | ||
| } | ||
| if v, ok := mapParams["instructions"].(string); ok { | ||
| instructions = v | ||
| } | ||
|
|
||
| var agentSources []v4.Source | ||
| if raw, ok := mapParams["sources"].([]any); ok { | ||
| for _, rs := range raw { | ||
| sStr, ok := rs.(string) | ||
| if !ok { | ||
| return nil, util.NewClientServerError("invalid source format: expected string", http.StatusBadRequest, nil) | ||
| } | ||
| var s v4.Source | ||
| if err := json.Unmarshal([]byte(sStr), &s); err != nil { | ||
| return nil, util.NewClientServerError(fmt.Sprintf("error parsing source JSON %q: %v", sStr, err), http.StatusBadRequest, err) | ||
| } | ||
| agentSources = append(agentSources, s) | ||
| } | ||
| } | ||
|
|
||
| codeInterpreter, hasCodeInterpreter := mapParams["code_interpreter"].(bool) | ||
|
|
||
| switch operation { | ||
| case "list": | ||
| resp, err := sdk.SearchAgents(v4.RequestSearchAgents{}, source.LookerApiSettings()) | ||
| if err != nil { | ||
| return nil, util.NewClientServerError(fmt.Sprintf("error making search_agents request: %s", err), http.StatusInternalServerError, err) | ||
| } | ||
| return resp, nil | ||
| case "get": | ||
| if agentId == "" { | ||
| return nil, util.NewClientServerError(fmt.Sprintf("%s operation: agent_id must be specified", operation), http.StatusBadRequest, nil) | ||
| } | ||
| resp, err := sdk.GetAgent(agentId, "", source.LookerApiSettings()) | ||
| if err != nil { | ||
| return nil, util.NewClientServerError(fmt.Sprintf("error making get_agent request: %s", err), http.StatusInternalServerError, err) | ||
| } | ||
| return resp, nil | ||
| case "create": | ||
| if name == "" { | ||
| return nil, util.NewClientServerError(fmt.Sprintf("%s operation: name must be specified", operation), http.StatusBadRequest, nil) | ||
| } | ||
| body := v4.WriteAgent{ | ||
| Name: &name, | ||
| } | ||
| if instructions != "" { | ||
| body.Context = &v4.Context{ | ||
| Instructions: &instructions, | ||
| } | ||
| } | ||
| if len(agentSources) > 0 { | ||
| body.Sources = &agentSources | ||
| } | ||
| if hasCodeInterpreter { | ||
| body.CodeInterpreter = &codeInterpreter | ||
| } | ||
| resp, err := sdk.CreateAgent(body, "", source.LookerApiSettings()) | ||
| if err != nil { | ||
| return nil, util.NewClientServerError(fmt.Sprintf("error making create_agent request: %s", err), http.StatusInternalServerError, err) | ||
| } | ||
| return resp, nil | ||
| case "update": | ||
| if agentId == "" { | ||
| return nil, util.NewClientServerError(fmt.Sprintf("%s operation: agent_id must be specified", operation), http.StatusBadRequest, nil) | ||
| } | ||
| body := v4.WriteAgent{} | ||
| if name != "" { | ||
| body.Name = &name | ||
| } | ||
| if instructions != "" { | ||
| body.Context = &v4.Context{ | ||
| Instructions: &instructions, | ||
| } | ||
| } | ||
| if len(agentSources) > 0 { | ||
| body.Sources = &agentSources | ||
| } | ||
| if hasCodeInterpreter { | ||
| body.CodeInterpreter = &codeInterpreter | ||
| } | ||
| resp, err := sdk.UpdateAgent(agentId, body, "", source.LookerApiSettings()) | ||
| if err != nil { | ||
| return nil, util.NewClientServerError(fmt.Sprintf("error making update_agent request: %s", err), http.StatusInternalServerError, err) | ||
| } | ||
| return resp, nil | ||
| case "delete": | ||
| if agentId == "" { | ||
| return nil, util.NewClientServerError(fmt.Sprintf("%s operation: agent_id must be specified", operation), http.StatusBadRequest, nil) | ||
| } | ||
| resp, err := sdk.DeleteAgent(agentId, "", source.LookerApiSettings()) | ||
| if err != nil { | ||
| return nil, util.NewClientServerError(fmt.Sprintf("error making delete_agent request: %s", err), http.StatusInternalServerError, err) | ||
| } | ||
| return resp, nil | ||
| default: | ||
| return nil, util.NewClientServerError(fmt.Sprintf("unknown operation: %s. Must be one of `list`, `get`, `create`, `update`, or `delete`", operation), http.StatusBadRequest, nil) | ||
| } | ||
| } | ||
|
|
||
| func (t Tool) EmbedParams(ctx context.Context, paramValues parameters.ParamValues, embeddingModelsMap map[string]embeddingmodels.EmbeddingModel) (parameters.ParamValues, error) { | ||
| return parameters.EmbedParams(ctx, t.Parameters, paramValues, embeddingModelsMap, nil) | ||
| } | ||
|
|
||
| func (t Tool) Manifest() tools.Manifest { | ||
| return t.manifest | ||
| } | ||
|
|
||
| func (t Tool) McpManifest() tools.McpManifest { | ||
| return t.mcpManifest | ||
| } | ||
|
|
||
| func (t Tool) RequiresClientAuthorization(resourceMgr tools.SourceProvider) (bool, error) { | ||
| source, err := tools.GetCompatibleSource[compatibleSource](resourceMgr, t.Source, t.Name, t.Type) | ||
| if err != nil { | ||
| return false, err | ||
| } | ||
| return source.UseClientAuthorization(), nil | ||
| } | ||
|
|
||
| func (t Tool) Authorized(verifiedAuthServices []string) bool { | ||
| return tools.IsAuthorized(t.AuthRequired, verifiedAuthServices) | ||
| } | ||
|
|
||
| func (t Tool) GetAuthTokenHeaderName(resourceMgr tools.SourceProvider) (string, error) { | ||
| source, err := tools.GetCompatibleSource[compatibleSource](resourceMgr, t.Source, t.Name, t.Type) | ||
| if err != nil { | ||
| return "", err | ||
| } | ||
| return source.GetAuthTokenHeaderName(), nil | ||
| } | ||
|
|
||
| func (t Tool) GetParameters() parameters.Parameters { | ||
| return t.Parameters | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.