-
Notifications
You must be signed in to change notification settings - Fork 176
Improve tool selection with additional tool descriptions #1718
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 all commits
Commits
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
15 changes: 15 additions & 0 deletions
15
packages/server/api/src/app/ai/mcp/external-tool-descriptions-data.ts
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,15 @@ | ||
| export type ToolDescription = { | ||
| note: string; | ||
| mcpServer?: string; | ||
| }; | ||
|
|
||
| export const MCP_TOOL_ADDITIONAL_DESCRIPTIONS: Record<string, ToolDescription> = | ||
| { | ||
| 'session-sql': { | ||
| note: `### Tool Usage Note for 'session-sql' | ||
| - The 'session-sql' tool from AWS billing and cost management MCP server does NOT work with OpenOps tables. | ||
| - When the user asks about OpenOps tables, table schema, or table operations, DO NOT use 'session-sql'. | ||
| - This tool is only for AWS billing and cost management related SQL queries.`, | ||
| mcpServer: 'aws-billing-cost-management', | ||
| }, | ||
| }; | ||
22 changes: 22 additions & 0 deletions
22
packages/server/api/src/app/ai/mcp/external-tool-descriptions.ts
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,22 @@ | ||
| import { ToolSet } from 'ai'; | ||
| import { MCP_TOOL_ADDITIONAL_DESCRIPTIONS } from './external-tool-descriptions-data'; | ||
|
|
||
| export function getAdditionalToolDescriptions( | ||
| tools: ToolSet | string[] | undefined, | ||
| ): string[] { | ||
| if (!tools) { | ||
| return []; | ||
| } | ||
|
|
||
| const toolNames = Array.isArray(tools) ? tools : Object.keys(tools); | ||
| const descriptions: string[] = []; | ||
|
|
||
| for (const toolName of toolNames) { | ||
| const description = MCP_TOOL_ADDITIONAL_DESCRIPTIONS[toolName]; | ||
| if (description?.note) { | ||
| descriptions.push(description.note); | ||
| } | ||
| } | ||
|
|
||
| return descriptions; | ||
| } |
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 |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ import { projectService } from '../../project/project-service'; | |
| import { getChatTools } from '../chat/ai-chat.service'; | ||
| import { buildUIContextSection } from '../chat/prompts.service'; | ||
| import { getAdditionalQueryClassificationDescriptions } from './extensions'; | ||
| import { getAdditionalToolDescriptions } from './external-tool-descriptions'; | ||
| import { sanitizeMessages } from './tool-utils'; | ||
| import { QueryClassification } from './types'; | ||
|
|
||
|
|
@@ -202,6 +203,16 @@ const getSystemPrompt = async ( | |
| const toolsMessage = toolList | ||
| .map((t) => `- ${t.name}: ${t.description}`) | ||
| .join('\n'); | ||
| const additionalToolNotes = getAdditionalToolDescriptions( | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| toolList.map((t) => t.name), | ||
| ); | ||
|
|
||
| const additionalToolNotesSection = | ||
| additionalToolNotes.length > 0 | ||
| ? `\n\n### IMPORTANT TOOL USAGE NOTES:\n\n${additionalToolNotes.join( | ||
| '\n\n', | ||
| )}\n` | ||
| : ''; | ||
| return ( | ||
| "Given the following conversation history and the list of available tools, select the tools that are most relevant to answer the user's request. " + | ||
| `IMPORTANT: Tables tools should always be included in the output if the user asks a question involving those table names: ${openopsTablesNames.join( | ||
|
|
@@ -211,7 +222,7 @@ const getSystemPrompt = async ( | |
| 'Include ALL relevant categories that apply. ' + | ||
| `${ | ||
| uiContext ? `${await buildUIContextSection(uiContext)}\n` : '' | ||
| } Tools: ${toolsMessage}` | ||
| } Tools: ${toolsMessage}${additionalToolNotesSection}` | ||
| ); | ||
| }; | ||
|
|
||
|
|
||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
style: The
mcpServerfield 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
There was a problem hiding this comment.
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