[Agentic Chat] Add Codebase Search Tool - workspace active project
## Context As part of supporting "Chat with your codebase" in Agentic Chat, we need to introduce the Codebase Search Tool into it. This search tool must be able to support codebase search on: 1. **the implicitly included project: the active project in the user's workspace** - THIS ISSUE 2. explicitly included projects: projects included through `/include <repository>` - addressed https://gitlab.com/gitlab-org/gitlab/-/issues/569625+ For the sake of iteration, we will only concern ourselves with the first item in this issue. ## References - See links in https://gitlab.com/groups/gitlab-org/-/epics/18193+ - See Codebase Search in Classic Chat: - MR: https://gitlab.com/gitlab-org/gitlab/-/merge_requests/192086 - [Codebase Search Tool Executor class](https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/lib/gitlab/llm/chain/tools/codebase_search/executor.rb) ## Proposal ### Step 1: Add `CodebaseSearch` as an MCP tool Add [a new MCP tool definition for `CodebaseSemanticSearch`](https://docs.gitlab.com/development/mcp_server/#adding-a-new-tool) **Codebase Semantic Search invocation** - **Option 1:** Make use of the API introduced in https://gitlab.com/gitlab-org/gitlab/-/issues/555843+ - **Option 2:** Directly call the [`Ai::ActiveContext::Queries::Code`](https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/lib/ai/active_context/queries/code.rb) _Note: the feasibility of the above approaches are still under discussion. There are a few concerns including security. Please refer to the discussions in https://gitlab.com/gitlab-org/gitlab/-/issues/569206+_ ### Step 2: Make sure that the `CodebaseSearch` tool is correctly invoked by Agentic Chat Given a user question, Agentic Chat should be able to correctly invoke the CodebaseSearch tool for the **workspace's active project**. This includes testing that: - the `CodebaseSearch` tool is invoked for questions related to the project code - the `CodebaseSearch` tool is NOT invoked for questions unrelated to the project code ### Further considerations **Tool call / parameters** As indicated in the title, we will only support a query on a single project for this issue. **For further exploration:** - Consider making use of the AI model to extract the best `search_term` for the API from the user's question. For example, if the user question is "How do I create an ActiveRecord migration?", the tool may extract "create an ActiveRecord migration" as the `search_term` to send to the API - Consider making use of the AI model to determine the `knn` and `limit` needed for the search
issue