feat: add createSequentialChainEdges function to add back agent chaining via multi-agents

This commit is contained in:
Danny Avila 2025-09-04 21:25:13 -04:00
parent 25afe0c4c9
commit 6235ad21fe
No known key found for this signature in database
GPG key ID: BF31EEB2C5CA0956
3 changed files with 69 additions and 10 deletions

View file

@ -1,6 +1,10 @@
const { logger } = require('@librechat/data-schemas');
const { createContentAggregator } = require('@librechat/agents');
const { validateAgentModel, getCustomEndpointConfig } = require('@librechat/api');
const {
validateAgentModel,
getCustomEndpointConfig,
createSequentialChainEdges,
} = require('@librechat/api');
const {
Constants,
EModelEndpoint,
@ -156,15 +160,9 @@ const initializeClient = async ({ req, res, signal, endpointOption }) => {
agentConfigs.set(agentId, config);
}
if (agent_ids?.length) {
for (const agentId of agent_ids) {
await processAgent(agentId);
}
}
if ((primaryConfig.edges?.length ?? 0) > 0) {
const edges = primaryConfig.edges;
const checkAgentInit = (agentId) => agentId === primaryConfig.id || agentConfigs.has(agentId);
let edges = primaryConfig.edges;
const checkAgentInit = (agentId) => agentId === primaryConfig.id || agentConfigs.has(agentId);
if ((edges?.length ?? 0) > 0) {
for (const edge of edges) {
if (Array.isArray(edge.to)) {
for (const to of edge.to) {
@ -194,6 +192,20 @@ const initializeClient = async ({ req, res, signal, endpointOption }) => {
}
}
if (agent_ids?.length) {
for (const agentId of agent_ids) {
if (checkAgentInit(agentId)) {
continue;
}
await processAgent(agentId);
}
const chain = await createSequentialChainEdges([primaryConfig.id].concat(agent_ids));
edges = edges ? edges.concat(chain) : chain;
}
primaryConfig.edges = edges;
let endpointConfig = appConfig.endpoints?.[primaryConfig.endpoint];
if (!isAgentsEndpoint(primaryConfig.endpoint) && !endpointConfig) {
try {