Skip to content

Improve tool selection with additional tool descriptions#1718

Merged
ravikiranvm merged 3 commits intomainfrom
ops-3138a
Dec 8, 2025
Merged

Improve tool selection with additional tool descriptions#1718
ravikiranvm merged 3 commits intomainfrom
ops-3138a

Conversation

@ravikiranvm
Copy link
Copy Markdown
Contributor

@ravikiranvm ravikiranvm commented Dec 3, 2025

Fixes OPS-3138.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Dec 3, 2025

Important

Review skipped

Auto reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch ops-3138a

Comment @coderabbitai help to get the list of available commands and usage tips.

@linear
Copy link
Copy Markdown

linear Bot commented Dec 3, 2025

@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud Bot commented Dec 4, 2025

@ravikiranvm ravikiranvm marked this pull request as ready for review December 4, 2025 08:04
Copilot AI review requested due to automatic review settings December 4, 2025 08:04
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves LLM tool selection by adding supplementary descriptions for external tools. The changes help the AI distinguish between tools with overlapping functionality, specifically preventing the misuse of the 'session-sql' tool (designed for AWS billing queries) when users ask about OpenOps tables.

Key Changes:

  • Added a system for providing additional tool usage notes to guide LLM tool selection
  • Integrated these notes into both the query router and main chat prompts
  • Created initial tool descriptions to clarify 'session-sql' tool scope limitations

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
external-tool-descriptions-data.ts Defines tool-specific usage notes and metadata structure
external-tool-descriptions.ts Implements helper function to extract relevant tool descriptions
llm-query-router.ts Integrates additional tool notes into the system prompt for tool routing
prompts.service.ts Adds additional tool descriptions to the main chat system prompt

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Dec 4, 2025

Greptile Overview

Greptile Summary

This PR adds a mechanism to inject additional tool usage notes into system prompts for both the LLM query router and MCP chat flows. This addresses tool selection confusion by providing explicit guidance about when specific tools should or should not be used.

  • Added external-tool-descriptions-data.ts defining a data structure for tool-specific notes, with an initial entry for session-sql clarifying it's only for AWS billing queries, not OpenOps tables
  • Added external-tool-descriptions.ts providing a flexible function that accepts both ToolSet and string[] inputs to retrieve matching tool descriptions
  • Integrated tool notes into prompts.service.ts for MCP chat system prompts
  • Integrated tool notes into llm-query-router.ts with an "IMPORTANT TOOL USAGE NOTES" section for query classification

The implementation follows existing codebase patterns and cleanly separates data from logic.

Confidence Score: 5/5

  • This PR is safe to merge - it adds new functionality without modifying existing behavior in a breaking way.
  • The changes are well-structured, follow existing codebase patterns, handle edge cases correctly (null/undefined inputs), and introduce no breaking changes. The code correctly handles both ToolSet and string[] input types. No tests are affected since this is additive functionality.
  • No files require special attention.

Important Files Changed

File Analysis

Filename Score Overview
packages/server/api/src/app/ai/mcp/external-tool-descriptions-data.ts 5/5 New file defining ToolDescription type and MCP_TOOL_ADDITIONAL_DESCRIPTIONS record for additional tool metadata. The mcpServer field is defined but currently unused.
packages/server/api/src/app/ai/mcp/external-tool-descriptions.ts 5/5 New file with getAdditionalToolDescriptions function that retrieves tool descriptions based on tool names. Correctly handles both ToolSet and string[] input types.
packages/server/api/src/app/ai/chat/prompts.service.ts 5/5 Added buildAdditionalToolNotes function and integrated additional tool descriptions into the MCP system prompt.
packages/server/api/src/app/ai/mcp/llm-query-router.ts 5/5 Integrated additional tool notes into the query router system prompt with IMPORTANT TOOL USAGE NOTES section.

Sequence Diagram

sequenceDiagram
    participant User
    participant QueryRouter as llm-query-router
    participant PromptsService as prompts.service
    participant ToolDescriptions as external-tool-descriptions
    participant ToolData as external-tool-descriptions-data

    Note over User,ToolData: Tool Selection Flow
    User->>QueryRouter: Send query with tools
    QueryRouter->>ToolDescriptions: getAdditionalToolDescriptions(toolNames[])
    ToolDescriptions->>ToolData: lookup MCP_TOOL_ADDITIONAL_DESCRIPTIONS
    ToolData-->>ToolDescriptions: matching descriptions
    ToolDescriptions-->>QueryRouter: string[] of notes
    QueryRouter->>QueryRouter: append to system prompt

    Note over User,ToolData: MCP Chat Flow
    User->>PromptsService: getMcpSystemPrompt(selectedTools)
    PromptsService->>ToolDescriptions: getAdditionalToolDescriptions(ToolSet)
    ToolDescriptions->>ToolData: lookup MCP_TOOL_ADDITIONAL_DESCRIPTIONS
    ToolData-->>ToolDescriptions: matching descriptions
    ToolDescriptions-->>PromptsService: string[] of notes
    PromptsService->>PromptsService: buildAdditionalToolNotes
    PromptsService-->>User: complete system prompt
Loading

Copy link
Copy Markdown
Contributor

@greptile-apps greptile-apps Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

4 files reviewed, 1 comment

Edit Code Review Agent Settings | Greptile

@@ -0,0 +1,15 @@
export type ToolDescription = {
note: string;
mcpServer?: string;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

style: The mcpServer field is defined but not used anywhere in the codebase. Consider whether this is needed for future functionality or should be removed to keep the interface minimal.

Prompt To Fix With AI
This is a comment left during a code review.
Path: packages/server/api/src/app/ai/mcp/external-tool-descriptions-data.ts
Line: 3:3

Comment:
**style:** The `mcpServer` field is defined but not used anywhere in the codebase. Consider whether this is needed for future functionality or should be removed to keep the interface minimal.

How can I resolve this? If you propose a fix, please make it concise.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added for future functionality in case if we would need it

const toolsMessage = toolList
.map((t) => `- ${t.name}: ${t.description}`)
.join('\n');
const additionalToolNotes = getAdditionalToolDescriptions(
Copy link
Copy Markdown
Contributor Author

@ravikiranvm ravikiranvm Dec 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not quite sure about this. Since we are sending all tools to LLM for tool selection, this would also send all additional tool descriptions along with the tool selection system prompt.

@ravikiranvm ravikiranvm merged commit 220ad69 into main Dec 8, 2025
24 checks passed
@ravikiranvm ravikiranvm deleted the ops-3138a branch December 8, 2025 07:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants