WIP: code ptc

This commit is contained in:
Danny Avila 2025-12-07 23:17:45 -05:00
parent 4d7e6b4a58
commit 3588929c70
No known key found for this signature in database
GPG key ID: BF31EEB2C5CA0956
8 changed files with 454 additions and 12 deletions

View file

@ -6,6 +6,7 @@ const {
hasCustomUserVars,
getUserMCPAuthMap,
isActionDomainAllowed,
buildToolClassification,
} = require('@librechat/api');
const {
Tools,
@ -36,6 +37,7 @@ const { recordUsage } = require('~/server/services/Threads');
const { loadTools } = require('~/app/clients/tools/util');
const { redactMessage } = require('~/config/parsers');
const { findPluginAuthsByKeys } = require('~/models');
const { loadAuthValues } = require('~/server/services/Tools/credentials');
/**
* Processes the required actions by calling the appropriate tools and returning the outputs.
* @param {OpenAIClient} client - OpenAI or StreamRunManager Client.
@ -367,7 +369,12 @@ async function processRequiredActions(client, requiredActions) {
* @param {AbortSignal} params.signal
* @param {Pick<Agent, 'id' | 'provider' | 'model' | 'tools'} params.agent - The agent to load tools for.
* @param {string | undefined} [params.openAIApiKey] - The OpenAI API key.
* @returns {Promise<{ tools?: StructuredTool[]; userMCPAuthMap?: Record<string, Record<string, string>> }>} The agent tools.
* @returns {Promise<{
* tools?: StructuredTool[];
* toolContextMap?: Record<string, unknown>;
* userMCPAuthMap?: Record<string, Record<string, string>>;
* toolRegistry?: Map<string, import('~/utils/toolClassification').LCTool>;
* }>} The agent tools and registry.
*/
async function loadAgentTools({ req, res, agent, signal, tool_resources, openAIApiKey }) {
if (!agent.tools || agent.tools.length === 0) {
@ -502,11 +509,21 @@ async function loadAgentTools({ req, res, agent, signal, tool_resources, openAIA
return map;
}, {});
/** Build tool registry from MCP tools and create PTC/tool search tools if configured */
const { toolRegistry, additionalTools } = await buildToolClassification({
loadedTools,
userId: req.user.id,
agentId: agent.id,
loadAuthValues,
});
agentTools.push(...additionalTools);
if (!checkCapability(AgentCapabilities.actions)) {
return {
tools: agentTools,
userMCPAuthMap,
toolContextMap,
toolRegistry,
};
}
@ -519,6 +536,7 @@ async function loadAgentTools({ req, res, agent, signal, tool_resources, openAIA
tools: agentTools,
userMCPAuthMap,
toolContextMap,
toolRegistry,
};
}
@ -645,6 +663,7 @@ async function loadAgentTools({ req, res, agent, signal, tool_resources, openAIA
tools: agentTools,
toolContextMap,
userMCPAuthMap,
toolRegistry,
};
}