diff --git a/api/server/controllers/agents/callbacks.js b/api/server/controllers/agents/callbacks.js index 4742495fc7..de1f1ef831 100644 --- a/api/server/controllers/agents/callbacks.js +++ b/api/server/controllers/agents/callbacks.js @@ -1,5 +1,6 @@ const { nanoid } = require('nanoid'); const { sendEvent } = require('@librechat/api'); +const { Constants } = require('@librechat/agents'); const { logger } = require('@librechat/data-schemas'); const { Tools, StepTypes, FileContext, ErrorTypes } = require('librechat-data-provider'); const { @@ -406,9 +407,11 @@ function createToolEndCallback({ req, res, artifactPromises }) { } return; } - + // Constants.PROGRAMMATIC_TOOL_CALLING { - if (output.name !== Tools.execute_code) { + const isCodeTool = + output.name === Tools.execute_code || output.name === Constants.PROGRAMMATIC_TOOL_CALLING; + if (!isCodeTool) { return; } } diff --git a/client/src/components/Chat/Messages/Content/Part.tsx b/client/src/components/Chat/Messages/Content/Part.tsx index 16de45d476..5dfb1702a9 100644 --- a/client/src/components/Chat/Messages/Content/Part.tsx +++ b/client/src/components/Chat/Messages/Content/Part.tsx @@ -91,7 +91,11 @@ const Part = memo( const isToolCall = 'args' in toolCall && (!toolCall.type || toolCall.type === ToolCallTypes.TOOL_CALL); - if (isToolCall && toolCall.name === Tools.execute_code) { + if ( + isToolCall && + (toolCall.name === Tools.execute_code || + toolCall.name === Constants.PROGRAMMATIC_TOOL_CALLING) + ) { return ( (0); const prevShowCodeRef = useRef(showCode); - const { lang, code } = useParseArgs(args) ?? ({} as ParsedArgs); + const { lang = 'py', code } = useParseArgs(args) ?? ({} as ParsedArgs); const progress = useProgress(initialProgress); useEffect(() => { diff --git a/client/src/locales/en/translation.json b/client/src/locales/en/translation.json index e97f74ad68..96bf818325 100644 --- a/client/src/locales/en/translation.json +++ b/client/src/locales/en/translation.json @@ -701,7 +701,7 @@ "com_ui_mcp_servers_allow_use": "Allow users to use MCP servers", "com_ui_all": "all", "com_ui_all_proper": "All", - "com_ui_analyzing": "Analyzing", + "com_ui_analyzing": "Running tools with code", "com_ui_analyzing_finished": "Finished analyzing", "com_ui_api_key": "API Key", "com_ui_api_key_source": "API Key Source", diff --git a/packages/api/src/tools/classification.ts b/packages/api/src/tools/classification.ts index 4dccb61a04..8044917381 100644 --- a/packages/api/src/tools/classification.ts +++ b/packages/api/src/tools/classification.ts @@ -282,8 +282,10 @@ export interface BuildToolClassificationResult { /** * Checks if an agent is allowed to have classification features based on TOOL_CLASSIFICATION_AGENT_IDS. + * If TOOL_CLASSIFICATION_AGENT_IDS is not set, all agents are allowed (including when no agentId). + * If set, requires agentId to be in the list. * @param agentId - The agent ID to check - * @returns Whether the agent is allowed (true if no restriction set, or agent is in the list) + * @returns Whether the agent is allowed */ export function isAgentAllowedForClassification(agentId?: string): boolean { const allowedAgentIds = parseToolList(process.env.TOOL_CLASSIFICATION_AGENT_IDS); @@ -344,6 +346,14 @@ export async function buildToolClassification( const { loadedTools, userId, agentId, loadAuthValues } = params; const additionalTools: GenericTool[] = []; + /** Check if this agent is allowed to have classification features (requires agentId) */ + if (!isAgentAllowedForClassification(agentId)) { + logger.debug( + `[buildToolClassification] Agent ${agentId ?? 'undefined'} not allowed for classification, skipping`, + ); + return { toolRegistry: undefined, additionalTools }; + } + const mcpTools = loadedTools.filter(isMCPTool); if (mcpTools.length === 0) { return { toolRegistry: undefined, additionalTools }; @@ -355,14 +365,6 @@ export async function buildToolClassification( /** Clean up temporary mcpJsonSchema property from tools now that registry is populated */ cleanupMCPToolSchemas(mcpTools); - /** Check if this agent is allowed to have classification features */ - if (!isAgentAllowedForClassification(agentId)) { - logger.debug( - `[buildToolClassification] Agent ${agentId} not in TOOL_CLASSIFICATION_AGENT_IDS, skipping PTC/ToolSearch`, - ); - return { toolRegistry, additionalTools }; - } - /** * Check if this agent actually has tools that match the patterns. * Only enable PTC if the agent has programmatic tools. diff --git a/packages/data-provider/src/config.ts b/packages/data-provider/src/config.ts index bcbcb58cc2..6aac2ea828 100644 --- a/packages/data-provider/src/config.ts +++ b/packages/data-provider/src/config.ts @@ -1643,6 +1643,8 @@ export enum Constants { LC_TRANSFER_TO_ = 'lc_transfer_to_', /** Placeholder Agent ID for Ephemeral Agents */ EPHEMERAL_AGENT_ID = 'ephemeral', + /** Programmatic Tool Calling tool name */ + PROGRAMMATIC_TOOL_CALLING = 'run_tools_with_code', } export enum LocalStorageKeys {