mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-08-04 14:57:42 +00:00
🪵 chore: Log Subagent Limit Hits (#13068)
This commit is contained in:
parent
70b6bb69d3
commit
7631366f52
4 changed files with 92 additions and 1 deletions
|
|
@ -647,6 +647,12 @@ const initializeClient = async ({ req, res, signal, endpointOption }) => {
|
|||
return;
|
||||
}
|
||||
if (subagentGraphIds.size >= MAX_SUBAGENT_GRAPH_NODES) {
|
||||
logger.warn('[initializeClient] Subagent graph node limit exceeded', {
|
||||
agentId,
|
||||
primaryAgentId: primaryConfig.id,
|
||||
loadedSubagentCount: subagentGraphIds.size,
|
||||
maxSubagentGraphNodes: MAX_SUBAGENT_GRAPH_NODES,
|
||||
});
|
||||
throw new Error(
|
||||
`Subagent graph exceeds the maximum of ${MAX_SUBAGENT_GRAPH_NODES} unique agents.`,
|
||||
);
|
||||
|
|
@ -670,6 +676,13 @@ const initializeClient = async ({ req, res, signal, endpointOption }) => {
|
|||
|
||||
if (loadedSubagentConfigIds.has(config.id)) {
|
||||
if ((config.subagentAgentConfigs?.length ?? 0) > 0 && depth >= MAX_SUBAGENT_DEPTH) {
|
||||
logger.warn('[initializeClient] Subagent graph depth limit exceeded', {
|
||||
agentId: config.id,
|
||||
primaryAgentId: primaryConfig.id,
|
||||
depth,
|
||||
maxSubagentDepth: MAX_SUBAGENT_DEPTH,
|
||||
childCount: config.subagentAgentConfigs.length,
|
||||
});
|
||||
throw new Error(
|
||||
`Subagent graph exceeds the maximum depth of ${MAX_SUBAGENT_DEPTH} at agent ${config.id}.`,
|
||||
);
|
||||
|
|
@ -690,6 +703,13 @@ const initializeClient = async ({ req, res, signal, endpointOption }) => {
|
|||
);
|
||||
|
||||
if (explicitSubagentIds.length > 0 && depth >= MAX_SUBAGENT_DEPTH) {
|
||||
logger.warn('[initializeClient] Subagent graph depth limit exceeded', {
|
||||
agentId: config.id,
|
||||
primaryAgentId: primaryConfig.id,
|
||||
depth,
|
||||
maxSubagentDepth: MAX_SUBAGENT_DEPTH,
|
||||
childCount: explicitSubagentIds.length,
|
||||
});
|
||||
throw new Error(
|
||||
`Subagent graph exceeds the maximum depth of ${MAX_SUBAGENT_DEPTH} at agent ${config.id}.`,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -68,9 +68,12 @@ jest.mock('~/cache', () => ({
|
|||
}));
|
||||
|
||||
const { initializeClient } = require('./initialize');
|
||||
const { logger } = require('@librechat/data-schemas');
|
||||
const { User, AclEntry } = require('~/db/models');
|
||||
const { createAgent } = require('~/models');
|
||||
|
||||
jest.spyOn(logger, 'warn').mockImplementation(() => {});
|
||||
|
||||
const PRIMARY_ID = 'agent_primary';
|
||||
const TARGET_ID = 'agent_target';
|
||||
const AUTHORIZED_ID = 'agent_authorized';
|
||||
|
|
@ -504,6 +507,16 @@ describe('initializeClient — subagent loading', () => {
|
|||
endpointOption: makeEndpointOption(),
|
||||
}),
|
||||
).rejects.toThrow(`maximum depth of ${MAX_SUBAGENT_DEPTH}`);
|
||||
expect(logger.warn).toHaveBeenCalledWith(
|
||||
'[initializeClient] Subagent graph depth limit exceeded',
|
||||
expect.objectContaining({
|
||||
agentId: `agent_depth_${MAX_SUBAGENT_DEPTH - 1}`,
|
||||
primaryAgentId: PRIMARY_ID,
|
||||
depth: MAX_SUBAGENT_DEPTH,
|
||||
maxSubagentDepth: MAX_SUBAGENT_DEPTH,
|
||||
childCount: 1,
|
||||
}),
|
||||
);
|
||||
expect(agentClientArgs).toBeUndefined();
|
||||
});
|
||||
|
||||
|
|
@ -542,6 +555,15 @@ describe('initializeClient — subagent loading', () => {
|
|||
endpointOption: makeEndpointOption(),
|
||||
}),
|
||||
).rejects.toThrow(`maximum depth of ${MAX_SUBAGENT_DEPTH}`);
|
||||
expect(logger.warn).toHaveBeenCalledWith(
|
||||
'[initializeClient] Subagent graph depth limit exceeded',
|
||||
expect.objectContaining({
|
||||
primaryAgentId: PRIMARY_ID,
|
||||
depth: MAX_SUBAGENT_DEPTH,
|
||||
maxSubagentDepth: MAX_SUBAGENT_DEPTH,
|
||||
childCount: 1,
|
||||
}),
|
||||
);
|
||||
expect(agentClientArgs).toBeUndefined();
|
||||
});
|
||||
|
||||
|
|
@ -581,6 +603,14 @@ describe('initializeClient — subagent loading', () => {
|
|||
endpointOption: makeEndpointOption(),
|
||||
}),
|
||||
).rejects.toThrow(`maximum of ${MAX_SUBAGENT_GRAPH_NODES} unique agents`);
|
||||
expect(logger.warn).toHaveBeenCalledWith(
|
||||
'[initializeClient] Subagent graph node limit exceeded',
|
||||
expect.objectContaining({
|
||||
primaryAgentId: PRIMARY_ID,
|
||||
loadedSubagentCount: MAX_SUBAGENT_GRAPH_NODES,
|
||||
maxSubagentGraphNodes: MAX_SUBAGENT_GRAPH_NODES,
|
||||
}),
|
||||
);
|
||||
expect(agentClientArgs).toBeUndefined();
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue