mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-09-01 03:27:01 +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
|
|
@ -1,3 +1,4 @@
|
|||
import { logger } from '@librechat/data-schemas';
|
||||
import type { AppConfig } from '@librechat/data-schemas';
|
||||
import type { SummarizationConfig, TEndpoint } from 'librechat-data-provider';
|
||||
import {
|
||||
|
|
@ -26,6 +27,16 @@ jest.mock('~/utils/env', () => ({
|
|||
createSafeUser: jest.fn(() => ({})),
|
||||
}));
|
||||
|
||||
jest.mock('@librechat/data-schemas', () => ({
|
||||
...jest.requireActual('@librechat/data-schemas'),
|
||||
logger: {
|
||||
debug: jest.fn(),
|
||||
warn: jest.fn(),
|
||||
error: jest.fn(),
|
||||
info: jest.fn(),
|
||||
},
|
||||
}));
|
||||
|
||||
// Mock Run.create to capture the graphConfig it receives
|
||||
jest.mock('@librechat/agents', () => {
|
||||
const actual = jest.requireActual('@librechat/agents');
|
||||
|
|
@ -1007,6 +1018,14 @@ describe('subagentConfigs', () => {
|
|||
}),
|
||||
).rejects.toThrow(`maximum depth of ${MAX_SUBAGENT_DEPTH}`);
|
||||
|
||||
expect(logger.warn).toHaveBeenCalledWith(
|
||||
'[createRun] Subagent graph depth limit exceeded',
|
||||
expect.objectContaining({
|
||||
agentId: `agent_chain_${MAX_SUBAGENT_DEPTH + 1}`,
|
||||
depth: MAX_SUBAGENT_DEPTH + 1,
|
||||
maxSubagentDepth: MAX_SUBAGENT_DEPTH,
|
||||
}),
|
||||
);
|
||||
expect(Run.create).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
|
|
@ -1020,6 +1039,14 @@ describe('subagentConfigs', () => {
|
|||
}),
|
||||
).rejects.toThrow(`maximum of ${MAX_SUBAGENT_RUN_CONFIGS} expanded entries`);
|
||||
|
||||
expect(logger.warn).toHaveBeenCalledWith(
|
||||
'[createRun] Subagent run configuration limit exceeded',
|
||||
expect.objectContaining({
|
||||
expandedConfigCount: MAX_SUBAGENT_RUN_CONFIGS + 1,
|
||||
maxSubagentRunConfigs: MAX_SUBAGENT_RUN_CONFIGS,
|
||||
rootAgentIds: ['agent_dag_root'],
|
||||
}),
|
||||
);
|
||||
expect(Run.create).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -551,11 +551,17 @@ const SELF_SUBAGENT_TYPE = 'self';
|
|||
|
||||
interface SubagentBuildState {
|
||||
configCount: number;
|
||||
rootAgentIds: string[];
|
||||
}
|
||||
|
||||
function countSubagentConfig(state: SubagentBuildState): void {
|
||||
state.configCount += 1;
|
||||
if (state.configCount > MAX_SUBAGENT_RUN_CONFIGS) {
|
||||
logger.warn('[createRun] Subagent run configuration limit exceeded', {
|
||||
expandedConfigCount: state.configCount,
|
||||
maxSubagentRunConfigs: MAX_SUBAGENT_RUN_CONFIGS,
|
||||
rootAgentIds: state.rootAgentIds,
|
||||
});
|
||||
throw new Error(
|
||||
`Subagent run configuration exceeds the maximum of ${MAX_SUBAGENT_RUN_CONFIGS} expanded entries.`,
|
||||
);
|
||||
|
|
@ -564,6 +570,11 @@ function countSubagentConfig(state: SubagentBuildState): void {
|
|||
|
||||
function assertSubagentDepth(depth: number, agentId: string): void {
|
||||
if (depth > MAX_SUBAGENT_DEPTH) {
|
||||
logger.warn('[createRun] Subagent graph depth limit exceeded', {
|
||||
agentId,
|
||||
depth,
|
||||
maxSubagentDepth: MAX_SUBAGENT_DEPTH,
|
||||
});
|
||||
throw new Error(
|
||||
`Subagent graph exceeds the maximum depth of ${MAX_SUBAGENT_DEPTH} at agent ${agentId}.`,
|
||||
);
|
||||
|
|
@ -922,7 +933,10 @@ export async function createRun({
|
|||
};
|
||||
|
||||
const agentInputs: AgentInputs[] = [];
|
||||
const subagentBuildState: SubagentBuildState = { configCount: 0 };
|
||||
const subagentBuildState: SubagentBuildState = {
|
||||
configCount: 0,
|
||||
rootAgentIds: agents.map((agent) => agent.id),
|
||||
};
|
||||
for (const agent of agents) {
|
||||
const agentInput = buildAgentInput(agent);
|
||||
const subagentConfigs = buildSubagentConfigs(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue