@librechat/agents 2.3.94 → 2.3.95
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/messages/format.cjs +36 -16
- package/dist/cjs/messages/format.cjs.map +1 -1
- package/dist/esm/messages/format.mjs +36 -16
- package/dist/esm/messages/format.mjs.map +1 -1
- package/dist/types/messages/format.d.ts +3 -3
- package/package.json +1 -1
- package/src/messages/format.ts +97 -30
- package/src/messages/formatAgentMessages.test.ts +337 -49
- package/src/messages/formatAgentMessages.tools.test.ts +61 -10
|
@@ -74,7 +74,9 @@ describe('formatAgentMessages with tools parameter', () => {
|
|
|
74
74
|
|
|
75
75
|
// The content should be a string representation of both messages
|
|
76
76
|
expect(typeof result.messages[1].content).toBe('string');
|
|
77
|
-
expect(result.messages[1].content).toEqual(
|
|
77
|
+
expect(result.messages[1].content).toEqual(
|
|
78
|
+
'AI: Let me check the weather for you.\nTool: check_weather, Sunny, 75°F'
|
|
79
|
+
);
|
|
78
80
|
});
|
|
79
81
|
|
|
80
82
|
it('should convert tool messages to string when tool is not in the allowed set', () => {
|
|
@@ -113,7 +115,9 @@ describe('formatAgentMessages with tools parameter', () => {
|
|
|
113
115
|
|
|
114
116
|
// The content should be a string representation of both messages
|
|
115
117
|
expect(typeof result.messages[1].content).toBe('string');
|
|
116
|
-
expect(result.messages[1].content).toEqual(
|
|
118
|
+
expect(result.messages[1].content).toEqual(
|
|
119
|
+
'AI: Let me check the weather for you.\nTool: check_weather, Sunny, 75°F'
|
|
120
|
+
);
|
|
117
121
|
});
|
|
118
122
|
|
|
119
123
|
it('should not convert tool messages when tool is in the allowed set', () => {
|
|
@@ -154,7 +158,10 @@ describe('formatAgentMessages with tools parameter', () => {
|
|
|
154
158
|
|
|
155
159
|
it('should handle multiple tool calls with mixed allowed/disallowed tools', () => {
|
|
156
160
|
const payload: TPayload = [
|
|
157
|
-
{
|
|
161
|
+
{
|
|
162
|
+
role: 'user',
|
|
163
|
+
content: 'Tell me about the weather and calculate something',
|
|
164
|
+
},
|
|
158
165
|
{
|
|
159
166
|
role: 'assistant',
|
|
160
167
|
content: [
|
|
@@ -202,9 +209,13 @@ describe('formatAgentMessages with tools parameter', () => {
|
|
|
202
209
|
|
|
203
210
|
// The content should include all parts
|
|
204
211
|
expect(typeof result.messages[1].content).toBe('string');
|
|
205
|
-
expect(result.messages[1].content).toContain(
|
|
212
|
+
expect(result.messages[1].content).toContain(
|
|
213
|
+
'Let me check the weather first.'
|
|
214
|
+
);
|
|
206
215
|
expect(result.messages[1].content).toContain('Sunny, 75°F');
|
|
207
|
-
expect(result.messages[1].content).toContain(
|
|
216
|
+
expect(result.messages[1].content).toContain(
|
|
217
|
+
'Now let me calculate something for you.'
|
|
218
|
+
);
|
|
208
219
|
expect(result.messages[1].content).toContain('2');
|
|
209
220
|
});
|
|
210
221
|
|
|
@@ -233,14 +244,18 @@ describe('formatAgentMessages with tools parameter', () => {
|
|
|
233
244
|
];
|
|
234
245
|
|
|
235
246
|
const indexTokenCountMap = {
|
|
236
|
-
0: 10,
|
|
237
|
-
1: 40,
|
|
247
|
+
0: 10, // 10 tokens for user message
|
|
248
|
+
1: 40, // 40 tokens for assistant message with tool call
|
|
238
249
|
};
|
|
239
250
|
|
|
240
251
|
// Provide a set of allowed tools that doesn't include 'check_weather'
|
|
241
252
|
const allowedTools = new Set(['search', 'calculator']);
|
|
242
253
|
|
|
243
|
-
const result = formatAgentMessages(
|
|
254
|
+
const result = formatAgentMessages(
|
|
255
|
+
payload,
|
|
256
|
+
indexTokenCountMap,
|
|
257
|
+
allowedTools
|
|
258
|
+
);
|
|
244
259
|
|
|
245
260
|
// Should have 2 messages and 2 entries in the token count map
|
|
246
261
|
expect(result.messages).toHaveLength(2);
|
|
@@ -253,6 +268,39 @@ describe('formatAgentMessages with tools parameter', () => {
|
|
|
253
268
|
expect(result.indexTokenCountMap?.[1]).toBe(40);
|
|
254
269
|
});
|
|
255
270
|
|
|
271
|
+
it('should heal invalid tool call structure when converting to string', () => {
|
|
272
|
+
const payload: TPayload = [
|
|
273
|
+
{
|
|
274
|
+
role: 'assistant',
|
|
275
|
+
content: [
|
|
276
|
+
{
|
|
277
|
+
type: ContentTypes.TOOL_CALL,
|
|
278
|
+
tool_call: {
|
|
279
|
+
id: 'tool_1',
|
|
280
|
+
name: 'check_weather',
|
|
281
|
+
args: '{"location":"New York"}',
|
|
282
|
+
output: 'Sunny, 75°F',
|
|
283
|
+
},
|
|
284
|
+
},
|
|
285
|
+
],
|
|
286
|
+
},
|
|
287
|
+
];
|
|
288
|
+
|
|
289
|
+
// Provide a set of allowed tools that doesn't include 'check_weather'
|
|
290
|
+
const allowedTools = new Set(['search', 'calculator']);
|
|
291
|
+
|
|
292
|
+
const result = formatAgentMessages(payload, undefined, allowedTools);
|
|
293
|
+
|
|
294
|
+
// Should convert to a single AIMessage with string content
|
|
295
|
+
expect(result.messages).toHaveLength(1);
|
|
296
|
+
expect(result.messages[0]).toBeInstanceOf(AIMessage);
|
|
297
|
+
|
|
298
|
+
// The content should be a string representation of the tool message
|
|
299
|
+
expect(typeof result.messages[0].content).toBe('string');
|
|
300
|
+
expect(result.messages[0].content).toContain('check_weather');
|
|
301
|
+
expect(result.messages[0].content).toContain('Sunny, 75°F');
|
|
302
|
+
});
|
|
303
|
+
|
|
256
304
|
it('should handle complex sequences with multiple tool calls', () => {
|
|
257
305
|
const payload: TPayload = [
|
|
258
306
|
{ role: 'user', content: 'Help me with a complex task' },
|
|
@@ -313,7 +361,10 @@ describe('formatAgentMessages with tools parameter', () => {
|
|
|
313
361
|
},
|
|
314
362
|
],
|
|
315
363
|
},
|
|
316
|
-
{
|
|
364
|
+
{
|
|
365
|
+
role: 'assistant',
|
|
366
|
+
content: 'Here\'s your answer based on all that information.',
|
|
367
|
+
},
|
|
317
368
|
];
|
|
318
369
|
|
|
319
370
|
// Allow search and calculator but not check_weather
|
|
@@ -328,7 +379,7 @@ describe('formatAgentMessages with tools parameter', () => {
|
|
|
328
379
|
|
|
329
380
|
// Check the types of messages
|
|
330
381
|
expect(result.messages[0]).toBeInstanceOf(HumanMessage);
|
|
331
|
-
expect(result.messages[1]).toBeInstanceOf(AIMessage);
|
|
382
|
+
expect(result.messages[1]).toBeInstanceOf(AIMessage); // Search message
|
|
332
383
|
expect(result.messages[2]).toBeInstanceOf(ToolMessage); // Search tool response
|
|
333
384
|
expect(result.messages[3]).toBeInstanceOf(AIMessage); // Converted weather+calculator message
|
|
334
385
|
expect(result.messages[4]).toBeInstanceOf(AIMessage); // Final message
|