Skip to content

Allow agents to be associated with tools

What does this MR do and why?

This MR allows agents to be associated with tools.

How to set up and validate locally

In rails console enable the global_ai_catalog feature flag:

Feature.enable(:global_ai_catalog)

Visit http://gdk.test:3000/-/graphql-explorer to execute the following mutations:

Create a new agent with 2 tools:

 mutation {
   aiCatalogAgentCreate(input: {
     name: "name"
     description: "A pirate doing a sum"
     projectId: "gid://gitlab/Project/1000000"
     public: true
     systemPrompt: "System prompt"
     userPrompt: "User prompt",
     tools: ["gid://gitlab/Ai::Catalog::BuiltInTool/1", "gid://gitlab/Ai::Catalog::BuiltInTool/25"]
   }) {
    errors
    item {
      id
      versions {
        nodes {
          ...on AiCatalogAgentVersion {
            tools {
              nodes {
                id
              }
            }
          }
        }
      }
    }
  }
}

You should see a response like:

{
  "data": {
    "aiCatalogAgentCreate": {
      "errors": [],
      "item": {
        "id": "gid://gitlab/Ai::Catalog::Item/20",
        "versions": {
          "nodes": [
            {
              "tools": {
                "nodes": [
                  {
                    "id": "gid://gitlab/Ai::Catalog::BuiltInTool/1"
                  },
                  {
                    "id": "gid://gitlab/Ai::Catalog::BuiltInTool/25"
                  }
                ]
              }
            }
          ]
        }
      }
    }
  },
  "correlationId": "01K0DMPHZKMS5P6TJN7YJ050QQ"
}

Update the agent you just created, replacing <GLOBAL_ID> with the value of id returned in the create mutation above, and choosing tools with a different ID from when you created it.

 mutation {
   aiCatalogAgentUpdate(input: {
     id: <GLOBAL_ID>,
     tools: ["gid://gitlab/Ai::Catalog::BuiltInTool/1", "gid://gitlab/Ai::Catalog::BuiltInTool/21"]
   }) {
    errors
    item {
      id
      versions {
        nodes {
          ...on AiCatalogAgentVersion {
            tools {
              nodes {
                id
              }
            }
          }
        }
      }
    }
  }
}

You should see a response like:

{
  "data": {
    "aiCatalogAgentUpdate": {
      "errors": [],
      "item": {
        "id": "gid://gitlab/Ai::Catalog::Item/19",
        "versions": {
          "nodes": [
            {
              "tools": {
                "nodes": [
                  {
                    "id": "gid://gitlab/Ai::Catalog::BuiltInTool/1"
                  },
                  {
                    "id": "gid://gitlab/Ai::Catalog::BuiltInTool/21"
                  }
                ]
              }
            }
          ]
        }
      }
    }
  },
  "correlationId": "01K0DHM47E3QFH9NRP442R5RWN"
}

Update the agent's name, and notice the tools are not changed:

 mutation {
   aiCatalogAgentUpdate(input: {
     id: <GLOBAL_ID>,
     name: "My new name"
   }) {
    errors
    item {
      id
      versions {
        nodes {
          ...on AiCatalogAgentVersion {
            tools {
              nodes {
                id
              }
            }
          }
        }
      }
    }
  }
}

You should see a response like:

{
  "data": {
    "aiCatalogAgentUpdate": {
      "errors": [],
      "item": {
        "id": "gid://gitlab/Ai::Catalog::Item/19",
        "versions": {
          "nodes": [
            {
              "tools": {
                "nodes": [
                  {
                    "id": "gid://gitlab/Ai::Catalog::BuiltInTool/1"
                  },
                  {
                    "id": "gid://gitlab/Ai::Catalog::BuiltInTool/21"
                  }
                ]
              }
            }
          ]
        }
      }
    }
  },
  "correlationId": "01K0DHM47E3QFH9NRP442R5RWN"
}

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #556299 (closed)

Edited by Luke Duncalfe

Merge request reports

Loading