@librechat/agents 3.0.1 ā 3.0.3
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/common/enum.cjs +0 -1
- package/dist/cjs/common/enum.cjs.map +1 -1
- package/dist/cjs/llm/providers.cjs +0 -2
- package/dist/cjs/llm/providers.cjs.map +1 -1
- package/dist/cjs/main.cjs +2 -0
- package/dist/cjs/main.cjs.map +1 -1
- package/dist/cjs/tools/Calculator.cjs +45 -0
- package/dist/cjs/tools/Calculator.cjs.map +1 -0
- package/dist/esm/common/enum.mjs +0 -1
- package/dist/esm/common/enum.mjs.map +1 -1
- package/dist/esm/llm/providers.mjs +0 -2
- package/dist/esm/llm/providers.mjs.map +1 -1
- package/dist/esm/main.mjs +1 -0
- package/dist/esm/main.mjs.map +1 -1
- package/dist/esm/tools/Calculator.mjs +24 -0
- package/dist/esm/tools/Calculator.mjs.map +1 -0
- package/dist/types/common/enum.d.ts +0 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/tools/Calculator.d.ts +8 -0
- package/dist/types/types/llm.d.ts +1 -6
- package/package.json +6 -4
- package/src/common/enum.ts +0 -1
- package/src/index.ts +1 -0
- package/src/llm/providers.ts +0 -2
- package/src/scripts/abort.ts +34 -15
- package/src/scripts/cli.ts +25 -20
- package/src/scripts/cli2.ts +23 -15
- package/src/scripts/cli3.ts +35 -29
- package/src/scripts/cli4.ts +1 -2
- package/src/scripts/cli5.ts +1 -2
- package/src/scripts/code_exec.ts +1 -2
- package/src/scripts/code_exec_simple.ts +1 -2
- package/src/scripts/content.ts +33 -15
- package/src/scripts/simple.ts +1 -2
- package/src/scripts/stream.ts +33 -15
- package/src/scripts/test-tools-before-handoff.ts +17 -28
- package/src/scripts/tools.ts +4 -6
- package/src/specs/anthropic.simple.test.ts +1 -1
- package/src/specs/azure.simple.test.ts +1 -1
- package/src/specs/openai.simple.test.ts +1 -1
- package/src/specs/openrouter.simple.test.ts +1 -1
- package/src/tools/Calculator.test.ts +278 -0
- package/src/tools/Calculator.ts +25 -0
- package/src/types/llm.ts +0 -6
- package/dist/types/tools/example.d.ts +0 -78
- package/src/proto/CollabGraph.ts +0 -269
- package/src/proto/TaskManager.ts +0 -243
- package/src/proto/collab.ts +0 -200
- package/src/proto/collab_design.ts +0 -184
- package/src/proto/collab_design_v2.ts +0 -224
- package/src/proto/collab_design_v3.ts +0 -255
- package/src/proto/collab_design_v4.ts +0 -220
- package/src/proto/collab_design_v5.ts +0 -251
- package/src/proto/collab_graph.ts +0 -181
- package/src/proto/collab_original.ts +0 -123
- package/src/proto/example.ts +0 -93
- package/src/proto/example_new.ts +0 -68
- package/src/proto/example_old.ts +0 -201
- package/src/proto/example_test.ts +0 -152
- package/src/proto/example_test_anthropic.ts +0 -100
- package/src/proto/log_stream.ts +0 -202
- package/src/proto/main_collab_community_event.ts +0 -133
- package/src/proto/main_collab_design_v2.ts +0 -96
- package/src/proto/main_collab_design_v4.ts +0 -100
- package/src/proto/main_collab_design_v5.ts +0 -135
- package/src/proto/main_collab_global_analysis.ts +0 -122
- package/src/proto/main_collab_hackathon_event.ts +0 -153
- package/src/proto/main_collab_space_mission.ts +0 -153
- package/src/proto/main_philosophy.ts +0 -210
- package/src/proto/original_script.ts +0 -126
- package/src/proto/standard.ts +0 -100
- package/src/proto/stream.ts +0 -56
- package/src/proto/tasks.ts +0 -118
- package/src/proto/tools/global_analysis_tools.ts +0 -86
- package/src/proto/tools/space_mission_tools.ts +0 -60
- package/src/proto/vertexai.ts +0 -54
- package/src/tools/example.ts +0 -129
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { config } from 'dotenv';
|
|
2
2
|
config();
|
|
3
3
|
|
|
4
|
-
import { TavilySearch } from '@langchain/tavily';
|
|
5
4
|
import { HumanMessage, BaseMessage } from '@langchain/core/messages';
|
|
6
5
|
import { Run } from '@/run';
|
|
7
6
|
import { Providers, GraphEvents } from '@/common';
|
|
@@ -78,10 +77,7 @@ async function testToolsBeforeHandoff() {
|
|
|
78
77
|
console.log(`\nš§ Tool started:`);
|
|
79
78
|
console.dir({ toolData, metadata }, { depth: null });
|
|
80
79
|
|
|
81
|
-
if (toolData?.output?.name
|
|
82
|
-
toolCallCount++;
|
|
83
|
-
console.log(`š Search #${toolCallCount} initiated`);
|
|
84
|
-
} else if (toolData?.output?.name?.includes('transfer_to_')) {
|
|
80
|
+
if (toolData?.output?.name?.includes('transfer_to_')) {
|
|
85
81
|
handoffOccurred = true;
|
|
86
82
|
const specialist = toolData.name.replace('transfer_to_', '');
|
|
87
83
|
console.log(`\nš Handoff initiated to: ${specialist}`);
|
|
@@ -100,21 +96,17 @@ async function testToolsBeforeHandoff() {
|
|
|
100
96
|
modelName: 'gpt-4.1-mini',
|
|
101
97
|
apiKey: process.env.OPENAI_API_KEY,
|
|
102
98
|
},
|
|
103
|
-
tools: [
|
|
104
|
-
instructions: `You are a Research Coordinator with access to
|
|
99
|
+
tools: [],
|
|
100
|
+
instructions: `You are a Research Coordinator with access to a report writer specialist.
|
|
105
101
|
|
|
106
102
|
Your workflow MUST follow these steps IN ORDER:
|
|
107
|
-
1. FIRST: Write an initial response acknowledging the request
|
|
108
|
-
- Explain what
|
|
109
|
-
-
|
|
110
|
-
2.
|
|
111
|
-
-
|
|
112
|
-
- Search 2: Get specific details, recent updates, or complementary data
|
|
113
|
-
- Note: Even if your searches are unsuccessful, you MUST still proceed to handoff after EXACTLY 2 searches
|
|
114
|
-
3. FINALLY: After completing both searches, transfer to the report writer
|
|
115
|
-
- Provide the report writer with a summary of your findings
|
|
103
|
+
1. FIRST: Write an initial response acknowledging the request
|
|
104
|
+
- Explain what you understand about the topic
|
|
105
|
+
- Provide any general knowledge you have
|
|
106
|
+
2. FINALLY: Transfer to the report writer
|
|
107
|
+
- Provide the report writer with a summary of the information
|
|
116
108
|
|
|
117
|
-
CRITICAL: You MUST write your initial response before
|
|
109
|
+
CRITICAL: You MUST write your initial response before transferring to the report writer.`,
|
|
118
110
|
maxContextTokens: 8000,
|
|
119
111
|
},
|
|
120
112
|
{
|
|
@@ -159,10 +151,10 @@ async function testToolsBeforeHandoff() {
|
|
|
159
151
|
}
|
|
160
152
|
|
|
161
153
|
try {
|
|
162
|
-
// Single test query that requires
|
|
163
|
-
const query = `
|
|
154
|
+
// Single test query that requires handoff to report writer
|
|
155
|
+
const query = `Tell me about quantum computing developments,
|
|
164
156
|
including major breakthroughs and commercial applications.
|
|
165
|
-
I need a comprehensive report
|
|
157
|
+
I need a comprehensive report.`;
|
|
166
158
|
|
|
167
159
|
console.log('='.repeat(60));
|
|
168
160
|
console.log(`USER QUERY: "${query}"`);
|
|
@@ -173,10 +165,9 @@ async function testToolsBeforeHandoff() {
|
|
|
173
165
|
const run = await Run.create(runConfig);
|
|
174
166
|
|
|
175
167
|
console.log('\nExpected behavior:');
|
|
176
|
-
console.log('1. Research Coordinator writes initial response
|
|
177
|
-
console.log('2. Research Coordinator
|
|
178
|
-
console.log('3.
|
|
179
|
-
console.log('4. Report Writer creates final report\n');
|
|
168
|
+
console.log('1. Research Coordinator writes initial response');
|
|
169
|
+
console.log('2. Research Coordinator hands off to Report Writer');
|
|
170
|
+
console.log('3. Report Writer creates final report\n');
|
|
180
171
|
|
|
181
172
|
// Process with streaming
|
|
182
173
|
conversationHistory.push(new HumanMessage(query));
|
|
@@ -204,11 +195,9 @@ async function testToolsBeforeHandoff() {
|
|
|
204
195
|
console.log('EDGE CASE TEST RESULTS:');
|
|
205
196
|
console.log('ā'.repeat(60));
|
|
206
197
|
console.log(`Tool calls before handoff: ${toolCallCount}`);
|
|
207
|
-
console.log(`Expected tool calls:
|
|
198
|
+
console.log(`Expected tool calls: 0 (no web search available)`);
|
|
208
199
|
console.log(`Handoff occurred: ${handoffOccurred ? 'Yes ā
' : 'No ā'}`);
|
|
209
|
-
console.log(
|
|
210
|
-
`Test status: ${toolCallCount === 2 && handoffOccurred ? 'PASSED ā
' : 'FAILED ā'}`
|
|
211
|
-
);
|
|
200
|
+
console.log(`Test status: ${handoffOccurred ? 'PASSED ā
' : 'FAILED ā'}`);
|
|
212
201
|
console.log('ā'.repeat(60));
|
|
213
202
|
|
|
214
203
|
// Display conversation history
|
package/src/scripts/tools.ts
CHANGED
|
@@ -3,7 +3,6 @@
|
|
|
3
3
|
import { config } from 'dotenv';
|
|
4
4
|
config();
|
|
5
5
|
import { HumanMessage, BaseMessage } from '@langchain/core/messages';
|
|
6
|
-
import { TavilySearchResults } from '@langchain/community/tools/tavily_search';
|
|
7
6
|
import type * as t from '@/types';
|
|
8
7
|
import { ChatModelStreamHandler, createContentAggregator } from '@/stream';
|
|
9
8
|
import { ToolEndHandler, ModelEndHandler } from '@/events';
|
|
@@ -95,11 +94,13 @@ async function testStandardStreaming(): Promise<void> {
|
|
|
95
94
|
graphConfig: {
|
|
96
95
|
type: 'standard',
|
|
97
96
|
llmConfig,
|
|
98
|
-
tools: [
|
|
97
|
+
tools: [],
|
|
99
98
|
instructions:
|
|
100
99
|
'You are a friendly AI assistant. Always address the user by their name.',
|
|
101
100
|
additional_instructions: `The user's name is ${userName} and they are located in ${location}.`,
|
|
101
|
+
maxContextTokens: 89000,
|
|
102
102
|
},
|
|
103
|
+
indexTokenCountMap: { 0: 35 },
|
|
103
104
|
returnContent: true,
|
|
104
105
|
customHandlers,
|
|
105
106
|
});
|
|
@@ -126,10 +127,7 @@ async function testStandardStreaming(): Promise<void> {
|
|
|
126
127
|
const inputs = {
|
|
127
128
|
messages: conversationHistory,
|
|
128
129
|
};
|
|
129
|
-
const finalContentParts = await run.processStream(inputs, config
|
|
130
|
-
indexTokenCountMap: { 0: 35 },
|
|
131
|
-
maxContextTokens: 89000,
|
|
132
|
-
});
|
|
130
|
+
const finalContentParts = await run.processStream(inputs, config);
|
|
133
131
|
const finalMessages = run.getRunMessages();
|
|
134
132
|
if (finalMessages) {
|
|
135
133
|
conversationHistory.push(...finalMessages);
|
|
@@ -0,0 +1,278 @@
|
|
|
1
|
+
import { Calculator } from './Calculator';
|
|
2
|
+
|
|
3
|
+
describe('Calculator', () => {
|
|
4
|
+
let calculator: Calculator;
|
|
5
|
+
|
|
6
|
+
beforeEach(() => {
|
|
7
|
+
calculator = new Calculator();
|
|
8
|
+
});
|
|
9
|
+
|
|
10
|
+
describe('basic properties', () => {
|
|
11
|
+
it('should have correct name', () => {
|
|
12
|
+
expect(calculator.name).toBe('calculator');
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it('should have correct description', () => {
|
|
16
|
+
expect(calculator.description).toBe(
|
|
17
|
+
'Useful for getting the result of a math expression. The input to this tool should be a valid mathematical expression that could be executed by a simple calculator.'
|
|
18
|
+
);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
it('should have correct lc_name', () => {
|
|
22
|
+
expect(Calculator.lc_name()).toBe('Calculator');
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('should have correct lc_namespace', () => {
|
|
26
|
+
const namespace = calculator.lc_namespace;
|
|
27
|
+
expect(namespace).toContain('calculator');
|
|
28
|
+
});
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
describe('basic arithmetic operations', () => {
|
|
32
|
+
it('should add two numbers', async () => {
|
|
33
|
+
const result = await calculator._call('2 + 3');
|
|
34
|
+
expect(result).toBe('5');
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it('should subtract two numbers', async () => {
|
|
38
|
+
const result = await calculator._call('10 - 4');
|
|
39
|
+
expect(result).toBe('6');
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it('should multiply two numbers', async () => {
|
|
43
|
+
const result = await calculator._call('6 * 7');
|
|
44
|
+
expect(result).toBe('42');
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it('should divide two numbers', async () => {
|
|
48
|
+
const result = await calculator._call('15 / 3');
|
|
49
|
+
expect(result).toBe('5');
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it('should handle modulo operation', async () => {
|
|
53
|
+
const result = await calculator._call('17 % 5');
|
|
54
|
+
expect(result).toBe('2');
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
it('should handle exponentiation', async () => {
|
|
58
|
+
const result = await calculator._call('2 ^ 3');
|
|
59
|
+
expect(result).toBe('8');
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
describe('complex expressions', () => {
|
|
64
|
+
it('should handle order of operations', async () => {
|
|
65
|
+
const result = await calculator._call('2 + 3 * 4');
|
|
66
|
+
expect(result).toBe('14');
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('should handle parentheses', async () => {
|
|
70
|
+
const result = await calculator._call('(2 + 3) * 4');
|
|
71
|
+
expect(result).toBe('20');
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('should handle nested parentheses', async () => {
|
|
75
|
+
const result = await calculator._call('((2 + 3) * 4) / 5');
|
|
76
|
+
expect(result).toBe('4');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('should handle multiple operations', async () => {
|
|
80
|
+
const result = await calculator._call('(10 + 5) * 2 - 8 / 4');
|
|
81
|
+
expect(result).toBe('28');
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
describe('decimal numbers', () => {
|
|
86
|
+
it('should handle decimal addition', async () => {
|
|
87
|
+
const result = await calculator._call('2.5 + 3.7');
|
|
88
|
+
expect(result).toBe('6.2');
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('should handle decimal multiplication', async () => {
|
|
92
|
+
const result = await calculator._call('2.5 * 4');
|
|
93
|
+
expect(result).toBe('10');
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it('should handle decimal division', async () => {
|
|
97
|
+
const result = await calculator._call('7.5 / 2.5');
|
|
98
|
+
expect(result).toBe('3');
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
describe('negative numbers', () => {
|
|
103
|
+
it('should handle negative numbers in addition', async () => {
|
|
104
|
+
const result = await calculator._call('-5 + 3');
|
|
105
|
+
expect(result).toBe('-2');
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('should handle negative numbers in subtraction', async () => {
|
|
109
|
+
const result = await calculator._call('10 - (-5)');
|
|
110
|
+
expect(result).toBe('15');
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('should handle negative numbers in multiplication', async () => {
|
|
114
|
+
const result = await calculator._call('-4 * -3');
|
|
115
|
+
expect(result).toBe('12');
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it('should handle negative numbers in division', async () => {
|
|
119
|
+
const result = await calculator._call('-12 / 4');
|
|
120
|
+
expect(result).toBe('-3');
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
describe('mathematical functions', () => {
|
|
125
|
+
it('should handle square root', async () => {
|
|
126
|
+
const result = await calculator._call('sqrt(16)');
|
|
127
|
+
expect(result).toBe('4');
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
it('should handle absolute value', async () => {
|
|
131
|
+
const result = await calculator._call('abs(-42)');
|
|
132
|
+
expect(result).toBe('42');
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it('should handle sine function', async () => {
|
|
136
|
+
const result = await calculator._call('sin(0)');
|
|
137
|
+
expect(result).toBe('0');
|
|
138
|
+
});
|
|
139
|
+
|
|
140
|
+
it('should handle cosine function', async () => {
|
|
141
|
+
const result = await calculator._call('cos(0)');
|
|
142
|
+
expect(result).toBe('1');
|
|
143
|
+
});
|
|
144
|
+
|
|
145
|
+
it('should handle logarithm', async () => {
|
|
146
|
+
const result = await calculator._call('log(10)');
|
|
147
|
+
expect(parseFloat(result)).toBeCloseTo(2.302585, 5);
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
it('should handle exponential', async () => {
|
|
151
|
+
const result = await calculator._call('exp(0)');
|
|
152
|
+
expect(result).toBe('1');
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it('should handle floor function', async () => {
|
|
156
|
+
const result = await calculator._call('floor(4.7)');
|
|
157
|
+
expect(result).toBe('4');
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it('should handle ceil function', async () => {
|
|
161
|
+
const result = await calculator._call('ceil(4.3)');
|
|
162
|
+
expect(result).toBe('5');
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
it('should handle round function', async () => {
|
|
166
|
+
const result = await calculator._call('round(4.5)');
|
|
167
|
+
expect(result).toBe('5');
|
|
168
|
+
});
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
describe('constants', () => {
|
|
172
|
+
it('should handle pi constant', async () => {
|
|
173
|
+
const result = await calculator._call('pi');
|
|
174
|
+
expect(parseFloat(result)).toBeCloseTo(3.14159, 5);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it('should handle e constant', async () => {
|
|
178
|
+
const result = await calculator._call('e');
|
|
179
|
+
expect(parseFloat(result)).toBeCloseTo(2.71828, 5);
|
|
180
|
+
});
|
|
181
|
+
|
|
182
|
+
it('should use pi in calculations', async () => {
|
|
183
|
+
const result = await calculator._call('2 * pi');
|
|
184
|
+
expect(parseFloat(result)).toBeCloseTo(6.28318, 4);
|
|
185
|
+
});
|
|
186
|
+
});
|
|
187
|
+
|
|
188
|
+
describe('error handling', () => {
|
|
189
|
+
it('should return error message for invalid expression', async () => {
|
|
190
|
+
const result = await calculator._call('invalid expression');
|
|
191
|
+
expect(result).toBe('I don\'t know how to do that.');
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it('should handle division by zero', async () => {
|
|
195
|
+
const result = await calculator._call('5 / 0');
|
|
196
|
+
expect(result).toBe('Infinity');
|
|
197
|
+
});
|
|
198
|
+
|
|
199
|
+
it('should return error message for incomplete expression', async () => {
|
|
200
|
+
const result = await calculator._call('5 +');
|
|
201
|
+
expect(result).toBe('I don\'t know how to do that.');
|
|
202
|
+
});
|
|
203
|
+
|
|
204
|
+
it('should return error message for mismatched parentheses', async () => {
|
|
205
|
+
const result = await calculator._call('(5 + 3');
|
|
206
|
+
expect(result).toBe('I don\'t know how to do that.');
|
|
207
|
+
});
|
|
208
|
+
|
|
209
|
+
it('should return error message for empty input', async () => {
|
|
210
|
+
const result = await calculator._call('');
|
|
211
|
+
expect(result).toBe('I don\'t know how to do that.');
|
|
212
|
+
});
|
|
213
|
+
|
|
214
|
+
it('should return error message for only whitespace', async () => {
|
|
215
|
+
const result = await calculator._call(' ');
|
|
216
|
+
expect(result).toBe('I don\'t know how to do that.');
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it('should return error message for undefined variable', async () => {
|
|
220
|
+
const result = await calculator._call('x + 5');
|
|
221
|
+
expect(result).toBe('I don\'t know how to do that.');
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
|
|
225
|
+
describe('edge cases', () => {
|
|
226
|
+
it('should handle very large numbers', async () => {
|
|
227
|
+
const result = await calculator._call('999999999 * 999999999');
|
|
228
|
+
expect(parseFloat(result)).toBeCloseTo(999999998000000000, -10);
|
|
229
|
+
});
|
|
230
|
+
|
|
231
|
+
it('should handle very small decimal numbers', async () => {
|
|
232
|
+
const result = await calculator._call('0.0001 + 0.0002');
|
|
233
|
+
expect(parseFloat(result)).toBeCloseTo(0.0003, 10);
|
|
234
|
+
});
|
|
235
|
+
|
|
236
|
+
it('should handle expressions with spaces', async () => {
|
|
237
|
+
const result = await calculator._call(' 5 + 3 ');
|
|
238
|
+
expect(result).toBe('8');
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
it('should handle zero in calculations', async () => {
|
|
242
|
+
const result = await calculator._call('0 + 0');
|
|
243
|
+
expect(result).toBe('0');
|
|
244
|
+
});
|
|
245
|
+
|
|
246
|
+
it('should handle power of zero', async () => {
|
|
247
|
+
const result = await calculator._call('5 ^ 0');
|
|
248
|
+
expect(result).toBe('1');
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
it('should handle zero to the power', async () => {
|
|
252
|
+
const result = await calculator._call('0 ^ 5');
|
|
253
|
+
expect(result).toBe('0');
|
|
254
|
+
});
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
describe('complex real-world calculations', () => {
|
|
258
|
+
it('should calculate area of circle', async () => {
|
|
259
|
+
const result = await calculator._call('pi * 5^2');
|
|
260
|
+
expect(parseFloat(result)).toBeCloseTo(78.53981, 4);
|
|
261
|
+
});
|
|
262
|
+
|
|
263
|
+
it('should calculate compound interest formula component', async () => {
|
|
264
|
+
const result = await calculator._call('(1 + 0.05/12)^(12*5)');
|
|
265
|
+
expect(parseFloat(result)).toBeCloseTo(1.28336, 4);
|
|
266
|
+
});
|
|
267
|
+
|
|
268
|
+
it('should calculate percentage', async () => {
|
|
269
|
+
const result = await calculator._call('(25 / 200) * 100');
|
|
270
|
+
expect(result).toBe('12.5');
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
it('should calculate average', async () => {
|
|
274
|
+
const result = await calculator._call('(10 + 20 + 30 + 40 + 50) / 5');
|
|
275
|
+
expect(result).toBe('30');
|
|
276
|
+
});
|
|
277
|
+
});
|
|
278
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { Tool } from '@langchain/core/tools';
|
|
2
|
+
import * as math from 'mathjs';
|
|
3
|
+
|
|
4
|
+
export class Calculator extends Tool {
|
|
5
|
+
static lc_name(): string {
|
|
6
|
+
return 'Calculator';
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
get lc_namespace(): string[] {
|
|
10
|
+
return [...super.lc_namespace, 'calculator'];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
name = 'calculator';
|
|
14
|
+
|
|
15
|
+
async _call(input: string): Promise<string> {
|
|
16
|
+
try {
|
|
17
|
+
return math.evaluate(input).toString();
|
|
18
|
+
} catch {
|
|
19
|
+
return 'I don\'t know how to do that.';
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
description =
|
|
24
|
+
'Useful for getting the result of a math expression. The input to this tool should be a valid mathematical expression that could be executed by a simple calculator.';
|
|
25
|
+
}
|
package/src/types/llm.ts
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
import { ChatOllama } from '@langchain/ollama';
|
|
3
3
|
import { ChatMistralAI } from '@langchain/mistralai';
|
|
4
4
|
import { ChatBedrockConverse } from '@langchain/aws';
|
|
5
|
-
import { BedrockChat } from '@langchain/community/chat_models/bedrock/web';
|
|
6
5
|
import type {
|
|
7
6
|
BindToolsInput,
|
|
8
7
|
BaseChatModelParams,
|
|
@@ -13,7 +12,6 @@ import type {
|
|
|
13
12
|
AzureOpenAIInput,
|
|
14
13
|
ClientOptions as OAIClientOptions,
|
|
15
14
|
} from '@langchain/openai';
|
|
16
|
-
import type { BedrockChatFields } from '@langchain/community/chat_models/bedrock/web';
|
|
17
15
|
import type { GoogleGenerativeAIChatInput } from '@langchain/google-genai';
|
|
18
16
|
import type { GeminiGenerationConfig } from '@langchain/google-common';
|
|
19
17
|
import type { ChatVertexAIInput } from '@langchain/google-vertexai';
|
|
@@ -65,7 +63,6 @@ export type MistralAIClientOptions = ChatMistralAIInput;
|
|
|
65
63
|
export type VertexAIClientOptions = ChatVertexAIInput & {
|
|
66
64
|
includeThoughts?: boolean;
|
|
67
65
|
};
|
|
68
|
-
export type BedrockClientOptions = BedrockChatFields;
|
|
69
66
|
export type BedrockAnthropicInput = ChatBedrockConverseInput & {
|
|
70
67
|
additionalModelRequestFields?: ChatBedrockConverseInput['additionalModelRequestFields'] &
|
|
71
68
|
AnthropicReasoning;
|
|
@@ -85,7 +82,6 @@ export type ClientOptions =
|
|
|
85
82
|
| AnthropicClientOptions
|
|
86
83
|
| MistralAIClientOptions
|
|
87
84
|
| VertexAIClientOptions
|
|
88
|
-
| BedrockClientOptions
|
|
89
85
|
| BedrockConverseClientOptions
|
|
90
86
|
| GoogleClientOptions
|
|
91
87
|
| DeepSeekClientOptions
|
|
@@ -113,7 +109,6 @@ export type ProviderOptionsMap = {
|
|
|
113
109
|
[Providers.MISTRALAI]: MistralAIClientOptions;
|
|
114
110
|
[Providers.MISTRAL]: MistralAIClientOptions;
|
|
115
111
|
[Providers.OPENROUTER]: ChatOpenRouterCallOptions;
|
|
116
|
-
[Providers.BEDROCK_LEGACY]: BedrockClientOptions;
|
|
117
112
|
[Providers.BEDROCK]: BedrockConverseClientOptions;
|
|
118
113
|
[Providers.XAI]: XAIClientOptions;
|
|
119
114
|
};
|
|
@@ -129,7 +124,6 @@ export type ChatModelMap = {
|
|
|
129
124
|
[Providers.MISTRALAI]: ChatMistralAI;
|
|
130
125
|
[Providers.MISTRAL]: ChatMistralAI;
|
|
131
126
|
[Providers.OPENROUTER]: ChatOpenRouter;
|
|
132
|
-
[Providers.BEDROCK_LEGACY]: BedrockChat;
|
|
133
127
|
[Providers.BEDROCK]: ChatBedrockConverse;
|
|
134
128
|
[Providers.GOOGLE]: CustomChatGoogleGenerativeAI;
|
|
135
129
|
};
|
|
@@ -1,78 +0,0 @@
|
|
|
1
|
-
import { TavilySearchResults } from '@langchain/community/tools/tavily_search';
|
|
2
|
-
import { DynamicStructuredTool } from '@langchain/core/tools';
|
|
3
|
-
import { z } from 'zod';
|
|
4
|
-
export declare const fetchRandomImageTool: DynamicStructuredTool<z.ZodObject<{
|
|
5
|
-
input: z.ZodOptional<z.ZodString>;
|
|
6
|
-
}, "strip", z.ZodTypeAny, {
|
|
7
|
-
input?: string | undefined;
|
|
8
|
-
}, {
|
|
9
|
-
input?: string | undefined;
|
|
10
|
-
}>, {
|
|
11
|
-
input?: string | undefined;
|
|
12
|
-
}, {
|
|
13
|
-
input?: string | undefined;
|
|
14
|
-
}, (string | undefined)[] | ({
|
|
15
|
-
type: string;
|
|
16
|
-
text: string;
|
|
17
|
-
}[] | {
|
|
18
|
-
content: {
|
|
19
|
-
type: string;
|
|
20
|
-
image_url: {
|
|
21
|
-
url: string;
|
|
22
|
-
};
|
|
23
|
-
}[];
|
|
24
|
-
})[]>;
|
|
25
|
-
export declare const fetchRandomImageURL: DynamicStructuredTool<z.ZodObject<{
|
|
26
|
-
input: z.ZodOptional<z.ZodString>;
|
|
27
|
-
}, "strip", z.ZodTypeAny, {
|
|
28
|
-
input?: string | undefined;
|
|
29
|
-
}, {
|
|
30
|
-
input?: string | undefined;
|
|
31
|
-
}>, {
|
|
32
|
-
input?: string | undefined;
|
|
33
|
-
}, {
|
|
34
|
-
input?: string | undefined;
|
|
35
|
-
}, (string | undefined)[] | ({
|
|
36
|
-
type: string;
|
|
37
|
-
text: string;
|
|
38
|
-
}[] | {
|
|
39
|
-
content: {
|
|
40
|
-
type: string;
|
|
41
|
-
image_url: {
|
|
42
|
-
url: string;
|
|
43
|
-
};
|
|
44
|
-
}[];
|
|
45
|
-
})[]>;
|
|
46
|
-
export declare const chartTool: DynamicStructuredTool<z.ZodObject<{
|
|
47
|
-
data: z.ZodArray<z.ZodObject<{
|
|
48
|
-
label: z.ZodString;
|
|
49
|
-
value: z.ZodNumber;
|
|
50
|
-
}, "strip", z.ZodTypeAny, {
|
|
51
|
-
value: number;
|
|
52
|
-
label: string;
|
|
53
|
-
}, {
|
|
54
|
-
value: number;
|
|
55
|
-
label: string;
|
|
56
|
-
}>, "many">;
|
|
57
|
-
}, "strip", z.ZodTypeAny, {
|
|
58
|
-
data: {
|
|
59
|
-
value: number;
|
|
60
|
-
label: string;
|
|
61
|
-
}[];
|
|
62
|
-
}, {
|
|
63
|
-
data: {
|
|
64
|
-
value: number;
|
|
65
|
-
label: string;
|
|
66
|
-
}[];
|
|
67
|
-
}>, {
|
|
68
|
-
data: {
|
|
69
|
-
value: number;
|
|
70
|
-
label: string;
|
|
71
|
-
}[];
|
|
72
|
-
}, {
|
|
73
|
-
data: {
|
|
74
|
-
value: number;
|
|
75
|
-
label: string;
|
|
76
|
-
}[];
|
|
77
|
-
}, string>;
|
|
78
|
-
export declare const tavilyTool: TavilySearchResults;
|