diff --git a/api/server/controllers/agents/__tests__/openai.spec.js b/api/server/controllers/agents/__tests__/openai.spec.js index 835343e798..a55804d5b2 100644 --- a/api/server/controllers/agents/__tests__/openai.spec.js +++ b/api/server/controllers/agents/__tests__/openai.spec.js @@ -160,6 +160,20 @@ describe('OpenAIChatCompletionController', () => { }; }); + describe('processStream config', () => { + it('should pass agent_id and dynamic runName in config.configurable', async () => { + const api = require('@librechat/api'); + await OpenAIChatCompletionController(req, res); + + const run = await api.createRun.mock.results[0].value; + const config = run.processStream.mock.calls[0][1]; + + expect(config.runName).toBe('gpt-4'); + expect(config.configurable.agent_id).toBe('agent-123'); + expect(config.configurable).not.toHaveProperty('agent_name'); + }); + }); + describe('token usage recording', () => { it('should call recordCollectedUsage after successful non-streaming completion', async () => { await OpenAIChatCompletionController(req, res); diff --git a/api/server/controllers/agents/__tests__/responses.unit.spec.js b/api/server/controllers/agents/__tests__/responses.unit.spec.js index 45ec31fc68..47e1f0529e 100644 --- a/api/server/controllers/agents/__tests__/responses.unit.spec.js +++ b/api/server/controllers/agents/__tests__/responses.unit.spec.js @@ -189,6 +189,20 @@ describe('createResponse controller', () => { }; }); + describe('processStream config', () => { + it('should pass agent_id, agent_name, and dynamic runName in config.configurable', async () => { + const api = require('@librechat/api'); + await createResponse(req, res); + + const run = await api.createRun.mock.results[0].value; + const config = run.processStream.mock.calls[0][1]; + + expect(config.runName).toBe('Test Agent'); + expect(config.configurable.agent_id).toBe('agent-123'); + expect(config.configurable.agent_name).toBe('Test Agent'); + }); + }); + describe('token usage recording - non-streaming', () => { it('should call recordCollectedUsage after successful non-streaming completion', async () => { await createResponse(req, res); diff --git a/api/server/controllers/agents/client.js b/api/server/controllers/agents/client.js index d17d3333ab..60e125a16b 100644 --- a/api/server/controllers/agents/client.js +++ b/api/server/controllers/agents/client.js @@ -732,7 +732,7 @@ class AgentClient extends BaseClient { user_id: this.user ?? this.options.req.user?.id, hide_sequential_outputs: this.options.agent.hide_sequential_outputs, agent_id: this.options.agent.id, - agent_name: this.options.agent.name, + ...(this.options.agent.name != null && { agent_name: this.options.agent.name }), requestBody: { messageId: this.responseMessageId, conversationId: this.conversationId, diff --git a/api/server/controllers/agents/openai.js b/api/server/controllers/agents/openai.js index 14d77b7295..6181e1b92a 100644 --- a/api/server/controllers/agents/openai.js +++ b/api/server/controllers/agents/openai.js @@ -471,7 +471,7 @@ const OpenAIChatCompletionController = async (req, res) => { thread_id: conversationId, user_id: userId, agent_id: agent.id, - agent_name: agent.name, + ...(agent.name != null && { agent_name: agent.name }), user: createSafeUser(req.user), requestBody: { messageId: responseId, diff --git a/api/server/controllers/agents/responses.js b/api/server/controllers/agents/responses.js index b64715efb2..0144ebaa53 100644 --- a/api/server/controllers/agents/responses.js +++ b/api/server/controllers/agents/responses.js @@ -487,7 +487,7 @@ const createResponse = async (req, res) => { thread_id: conversationId, user_id: userId, agent_id: agent.id, - agent_name: agent.name, + ...(agent.name != null && { agent_name: agent.name }), user: createSafeUser(req.user), requestBody: { messageId: responseId, @@ -643,7 +643,7 @@ const createResponse = async (req, res) => { thread_id: conversationId, user_id: userId, agent_id: agent.id, - agent_name: agent.name, + ...(agent.name != null && { agent_name: agent.name }), user: createSafeUser(req.user), requestBody: { messageId: responseId,