🗂️ fix: Scope Handoff Agent Context Docs (#13167)

* fix: Scope agent context docs to handoff agents

* fix: Deduplicate scoped request context

* refactor: Extract agent attachment helpers
This commit is contained in:
Danny Avila 2026-05-18 15:36:22 -04:00 committed by GitHub
parent 394839a76b
commit 68eac104ad
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
12 changed files with 529 additions and 17 deletions

View file

@ -10,6 +10,7 @@ const {
getCustomEndpointConfig,
discoverConnectedAgents,
resolveAgentScopedSkillIds,
buildAgentContextAttachmentsByAgentId,
} = require('@librechat/api');
const {
ResourceType,
@ -796,6 +797,11 @@ const initializeClient = async ({ req, res, signal, endpointOption }) => {
}
}
const agentContextAttachmentsByAgentId = buildAgentContextAttachmentsByAgentId([
primaryConfig,
...agentConfigs.values(),
]);
let endpointConfig = appConfig.endpoints?.[primaryConfig.endpoint];
if (!isAgentsEndpoint(primaryConfig.endpoint) && !endpointConfig) {
try {
@ -851,7 +857,8 @@ const initializeClient = async ({ req, res, signal, endpointOption }) => {
agent: primaryConfig,
spec: endpointOption.spec,
iconURL: endpointOption.iconURL,
attachments: primaryConfig.attachments,
attachments: primaryConfig.requestAttachments ?? primaryConfig.attachments,
agentContextAttachmentsByAgentId,
endpointType: endpointOption.endpointType,
resendFiles: primaryConfig.resendFiles ?? true,
maxContextTokens: primaryConfig.maxContextTokens,

View file

@ -183,6 +183,15 @@ describe('initializeClient — processAgent ACL gate', () => {
});
const edges = [{ from: PRIMARY_ID, to: AUTHORIZED_ID, edgeType: 'handoff' }];
const requestAttachment = { file_id: 'request_file', filename: 'request.txt' };
const primaryContextAttachment = { file_id: 'primary_context', filename: 'primary.txt' };
const handoffContextAttachment = { file_id: 'handoff_context', filename: 'handoff.txt' };
const primaryConfig = {
...makePrimaryConfig(edges),
attachments: [primaryContextAttachment, requestAttachment],
requestAttachments: [requestAttachment],
agentContextAttachments: [primaryContextAttachment],
};
const handoffConfig = {
id: AUTHORIZED_ID,
edges: [],
@ -190,14 +199,13 @@ describe('initializeClient — processAgent ACL gate', () => {
toolRegistry: new Map(),
userMCPAuthMap: null,
tool_resources: {},
agentContextAttachments: [handoffContextAttachment],
};
let callCount = 0;
mockInitializeAgent.mockImplementation(() => {
callCount++;
return callCount === 1
? Promise.resolve(makePrimaryConfig(edges))
: Promise.resolve(handoffConfig);
return callCount === 1 ? Promise.resolve(primaryConfig) : Promise.resolve(handoffConfig);
});
await initializeClient({
@ -210,6 +218,13 @@ describe('initializeClient — processAgent ACL gate', () => {
expect(mockInitializeAgent).toHaveBeenCalledTimes(2);
expect(agentClientArgs.agent.edges).toHaveLength(1);
expect(agentClientArgs.agent.edges[0].to).toBe(AUTHORIZED_ID);
expect(agentClientArgs.attachments).toEqual([requestAttachment]);
expect(agentClientArgs.agentContextAttachmentsByAgentId.get(PRIMARY_ID)).toEqual([
primaryContextAttachment,
]);
expect(agentClientArgs.agentContextAttachmentsByAgentId.get(AUTHORIZED_ID)).toEqual([
handoffContextAttachment,
]);
});
});