[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:
- the implicitly included project: the active project in the user's workspace - THIS ISSUE
- explicitly included projects: projects included through
/include <repository>- addressed [Agentic Chat] Codebase Search Tool - support e... (#569625)
For the sake of iteration, we will only concern ourselves with the first item in this issue.
References
- See links in [Semantic Code Search] Agentic Chat Integration (&18193)
- See Codebase Search in Classic Chat:
Proposal
Step 1: Add CodebaseSearch as an MCP tool
Add a new MCP tool definition for CodebaseSemanticSearch
Codebase Semantic Search invocation
- Option 1: Make use of the API introduced in Add a new API endpoint for the Codebase Search ... (#555843 - closed)
-
Option 2: Directly call the
Ai::ActiveContext::Queries::Code
Note: the feasibility of the above approaches are still under discussion. There are a few concerns including security. Please refer to the discussions in SPIKE: Discuss API tool design for MCP tool (#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
CodebaseSearchtool is invoked for questions related to the project code - the
CodebaseSearchtool 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_termfor 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 thesearch_termto send to the API - Consider making use of the AI model to determine the
knnandlimitneeded for the search