mirror of
https://github.com/danny-avila/LibreChat.git
synced 2026-08-04 14:57:42 +00:00
fix: Deduplicate scoped request context
This commit is contained in:
parent
13bbd7f930
commit
04701fe5c1
2 changed files with 37 additions and 1 deletions
|
|
@ -272,10 +272,17 @@ class AgentClient extends BaseClient {
|
|||
}))
|
||||
: []),
|
||||
];
|
||||
const sharedRunAttachmentIds = new Set();
|
||||
if (this.options.attachments) {
|
||||
const attachments = await this.options.attachments;
|
||||
const latestMessage = orderedMessages[orderedMessages.length - 1];
|
||||
|
||||
for (const file of attachments) {
|
||||
if (file?.file_id) {
|
||||
sharedRunAttachmentIds.add(file.file_id);
|
||||
}
|
||||
}
|
||||
|
||||
if (this.message_file_map) {
|
||||
this.message_file_map[latestMessage.messageId] = attachments;
|
||||
} else {
|
||||
|
|
@ -417,7 +424,9 @@ class AgentClient extends BaseClient {
|
|||
|
||||
const agentScopedContextEntries = await Promise.all(
|
||||
allAgents.map(async ({ agentId }) => {
|
||||
const attachments = getAgentContextAttachments(agentId);
|
||||
const attachments = getAgentContextAttachments(agentId).filter(
|
||||
(file) => !file?.file_id || !sharedRunAttachmentIds.has(file.file_id),
|
||||
);
|
||||
if (!attachments || attachments.length === 0) {
|
||||
return [agentId, ''];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1551,6 +1551,33 @@ describe('AgentClient - titleConvo', () => {
|
|||
expect(handoffAgent.additional_instructions).not.toContain('Primary private context');
|
||||
});
|
||||
|
||||
it('does not duplicate a file that is both request context and scoped context', async () => {
|
||||
const sharedFile = makeTextFile('shared-file', 'shared.txt', 'Shared duplicate context');
|
||||
|
||||
client.options.attachments = [sharedFile];
|
||||
client.options.agentContextAttachmentsByAgentId = new Map([['primary-agent', [sharedFile]]]);
|
||||
client.agentConfigs = new Map();
|
||||
|
||||
await client.buildMessages(
|
||||
[
|
||||
{
|
||||
messageId: 'msg-1',
|
||||
parentMessageId: null,
|
||||
sender: 'User',
|
||||
text: 'Use the available context.',
|
||||
isCreatedByUser: true,
|
||||
},
|
||||
],
|
||||
'msg-1',
|
||||
{},
|
||||
);
|
||||
|
||||
const occurrences = (
|
||||
mockAgent.additional_instructions.match(/Shared duplicate context/g) ?? []
|
||||
).length;
|
||||
expect(occurrences).toBe(1);
|
||||
});
|
||||
|
||||
it('keeps direct chats with context-doc agents working without request attachments', async () => {
|
||||
const primaryContext = makeTextFile(
|
||||
'primary-context',
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue