@librechat/agents 3.0.1 → 3.0.2
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 +5 -3
- 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.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
package/src/scripts/cli.ts
CHANGED
|
@@ -3,12 +3,10 @@
|
|
|
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 { ModelEndHandler, ToolEndHandler } from '@/events';
|
|
9
8
|
import { ChatModelStreamHandler } from '@/stream';
|
|
10
9
|
|
|
11
|
-
|
|
12
10
|
import { getArgs } from '@/scripts/args';
|
|
13
11
|
import { Run } from '@/run';
|
|
14
12
|
import { GraphEvents, Callback } from '@/common';
|
|
@@ -25,31 +23,35 @@ async function testStandardStreaming(): Promise<void> {
|
|
|
25
23
|
handle: (_event: string, data: t.StreamEventData): void => {
|
|
26
24
|
console.log('====== ON_RUN_STEP_COMPLETED ======');
|
|
27
25
|
console.dir(data, { depth: null });
|
|
28
|
-
}
|
|
26
|
+
},
|
|
29
27
|
},
|
|
30
28
|
[GraphEvents.ON_RUN_STEP]: {
|
|
31
29
|
handle: (_event: string, data: t.StreamEventData): void => {
|
|
32
30
|
console.log('====== ON_RUN_STEP ======');
|
|
33
31
|
console.dir(data, { depth: null });
|
|
34
|
-
}
|
|
32
|
+
},
|
|
35
33
|
},
|
|
36
34
|
[GraphEvents.ON_RUN_STEP_DELTA]: {
|
|
37
35
|
handle: (_event: string, data: t.StreamEventData): void => {
|
|
38
36
|
console.log('====== ON_RUN_STEP_DELTA ======');
|
|
39
37
|
console.dir(data, { depth: null });
|
|
40
|
-
}
|
|
38
|
+
},
|
|
41
39
|
},
|
|
42
40
|
[GraphEvents.ON_MESSAGE_DELTA]: {
|
|
43
41
|
handle: (_event: string, data: t.StreamEventData): void => {
|
|
44
42
|
console.log('====== ON_MESSAGE_DELTA ======');
|
|
45
43
|
console.dir(data, { depth: null });
|
|
46
|
-
}
|
|
44
|
+
},
|
|
47
45
|
},
|
|
48
46
|
[GraphEvents.TOOL_START]: {
|
|
49
|
-
handle: (
|
|
47
|
+
handle: (
|
|
48
|
+
_event: string,
|
|
49
|
+
data: t.StreamEventData,
|
|
50
|
+
metadata?: Record<string, unknown>
|
|
51
|
+
): void => {
|
|
50
52
|
console.log('====== TOOL_START ======');
|
|
51
53
|
console.dir(data, { depth: null });
|
|
52
|
-
}
|
|
54
|
+
},
|
|
53
55
|
},
|
|
54
56
|
// [GraphEvents.LLM_STREAM]: new LLMStreamHandler(),
|
|
55
57
|
// [GraphEvents.LLM_START]: {
|
|
@@ -94,8 +96,9 @@ async function testStandardStreaming(): Promise<void> {
|
|
|
94
96
|
graphConfig: {
|
|
95
97
|
type: 'standard',
|
|
96
98
|
llmConfig,
|
|
97
|
-
tools: [
|
|
98
|
-
instructions:
|
|
99
|
+
tools: [],
|
|
100
|
+
instructions:
|
|
101
|
+
'You are a friendly AI assistant. Always address the user by their name.',
|
|
99
102
|
additional_instructions: `The user's name is ${userName} and they are located in ${location}.`,
|
|
100
103
|
},
|
|
101
104
|
customHandlers,
|
|
@@ -116,16 +119,18 @@ async function testStandardStreaming(): Promise<void> {
|
|
|
116
119
|
let inputs = {
|
|
117
120
|
messages: conversationHistory,
|
|
118
121
|
};
|
|
119
|
-
const contentParts = await run.processStream(
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
122
|
+
const contentParts = await run.processStream(
|
|
123
|
+
inputs,
|
|
124
|
+
config
|
|
125
|
+
// {
|
|
126
|
+
// [Callback.TOOL_START]: (graph, ...args) => {
|
|
127
|
+
// console.log('TOOL_START callback');
|
|
128
|
+
// },
|
|
129
|
+
// [Callback.TOOL_END]: (graph, ...args) => {
|
|
130
|
+
// console.log('TOOL_END callback');
|
|
131
|
+
// },
|
|
132
|
+
// }
|
|
133
|
+
);
|
|
129
134
|
const finalMessages = run.getRunMessages();
|
|
130
135
|
if (finalMessages) {
|
|
131
136
|
conversationHistory.push(...finalMessages);
|
package/src/scripts/cli2.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 } from '@/stream';
|
|
9
8
|
import { TestLLMStreamHandler } from '@/events';
|
|
@@ -17,7 +16,7 @@ const conversationHistory: BaseMessage[] = [];
|
|
|
17
16
|
|
|
18
17
|
async function executePersonalizedQuerySuite(): Promise<void> {
|
|
19
18
|
const { userName, location, provider, currentDate } = await getArgs();
|
|
20
|
-
|
|
19
|
+
|
|
21
20
|
const customHandlers = {
|
|
22
21
|
[GraphEvents.LLM_STREAM]: new TestLLMStreamHandler(),
|
|
23
22
|
[GraphEvents.CHAT_MODEL_STREAM]: new ChatModelStreamHandler(),
|
|
@@ -25,37 +24,37 @@ async function executePersonalizedQuerySuite(): Promise<void> {
|
|
|
25
24
|
handle: (_event: string, data: t.StreamEventData): void => {
|
|
26
25
|
console.log('====== LLM_START ======');
|
|
27
26
|
console.dir(data, { depth: null });
|
|
28
|
-
}
|
|
27
|
+
},
|
|
29
28
|
},
|
|
30
29
|
[GraphEvents.LLM_END]: {
|
|
31
30
|
handle: (_event: string, data: t.StreamEventData): void => {
|
|
32
31
|
console.log('====== LLM_END ======');
|
|
33
32
|
console.dir(data, { depth: null });
|
|
34
|
-
}
|
|
33
|
+
},
|
|
35
34
|
},
|
|
36
35
|
[GraphEvents.CHAT_MODEL_START]: {
|
|
37
36
|
handle: (_event: string, _data: t.StreamEventData): void => {
|
|
38
37
|
console.log('====== CHAT_MODEL_START ======');
|
|
39
38
|
console.dir(_data, { depth: null });
|
|
40
|
-
}
|
|
39
|
+
},
|
|
41
40
|
},
|
|
42
41
|
[GraphEvents.CHAT_MODEL_END]: {
|
|
43
42
|
handle: (_event: string, _data: t.StreamEventData): void => {
|
|
44
43
|
console.log('====== CHAT_MODEL_END ======');
|
|
45
44
|
console.dir(_data, { depth: null });
|
|
46
|
-
}
|
|
45
|
+
},
|
|
47
46
|
},
|
|
48
47
|
[GraphEvents.TOOL_START]: {
|
|
49
48
|
handle: (_event: string, data: t.StreamEventData): void => {
|
|
50
49
|
console.log('====== TOOL_START ======');
|
|
51
50
|
console.dir(data, { depth: null });
|
|
52
|
-
}
|
|
51
|
+
},
|
|
53
52
|
},
|
|
54
53
|
[GraphEvents.TOOL_END]: {
|
|
55
54
|
handle: (_event: string, data: t.StreamEventData): void => {
|
|
56
55
|
console.log('====== TOOL_END ======');
|
|
57
56
|
console.dir(data, { depth: null });
|
|
58
|
-
}
|
|
57
|
+
},
|
|
59
58
|
},
|
|
60
59
|
};
|
|
61
60
|
|
|
@@ -66,7 +65,7 @@ async function executePersonalizedQuerySuite(): Promise<void> {
|
|
|
66
65
|
graphConfig: {
|
|
67
66
|
type: 'standard',
|
|
68
67
|
llmConfig,
|
|
69
|
-
tools: [
|
|
68
|
+
tools: [],
|
|
70
69
|
},
|
|
71
70
|
customHandlers,
|
|
72
71
|
});
|
|
@@ -76,7 +75,7 @@ async function executePersonalizedQuerySuite(): Promise<void> {
|
|
|
76
75
|
provider,
|
|
77
76
|
thread_id: `${userName}-session-${Date.now()}`,
|
|
78
77
|
instructions: `You are a knowledgeable and friendly AI assistant. Tailor your responses to ${userName}'s interests in ${location}.`,
|
|
79
|
-
additional_instructions: `Ensure each topic is thoroughly researched. Today is ${currentDate}. Maintain a warm, personalized tone throughout
|
|
78
|
+
additional_instructions: `Ensure each topic is thoroughly researched. Today is ${currentDate}. Maintain a warm, personalized tone throughout.`,
|
|
80
79
|
},
|
|
81
80
|
streamMode: 'values',
|
|
82
81
|
version: 'v2' as const,
|
|
@@ -85,9 +84,18 @@ async function executePersonalizedQuerySuite(): Promise<void> {
|
|
|
85
84
|
console.log(`Initiating personalized query suite for ${userName}`);
|
|
86
85
|
|
|
87
86
|
const queryTopics = [
|
|
88
|
-
{
|
|
89
|
-
|
|
90
|
-
|
|
87
|
+
{
|
|
88
|
+
task: 'current weather',
|
|
89
|
+
description: 'Provide a detailed weather forecast',
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
task: 'popular tourist attraction',
|
|
93
|
+
description: 'Describe a notable sight',
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
task: 'upcoming events',
|
|
97
|
+
description: 'List major events or festivals this week',
|
|
98
|
+
},
|
|
91
99
|
// { task: "famous local dish", description: "Share a recipe for a regional specialty" },
|
|
92
100
|
// { task: "local humor", description: "Tell a joke related to the area or findings" }
|
|
93
101
|
];
|
|
@@ -118,8 +126,8 @@ async function executePersonalizedQuerySuite(): Promise<void> {
|
|
|
118
126
|
}
|
|
119
127
|
|
|
120
128
|
executePersonalizedQuerySuite().catch((error) => {
|
|
121
|
-
console.error(
|
|
122
|
-
console.log(
|
|
129
|
+
console.error('An error occurred during the query suite execution:', error);
|
|
130
|
+
console.log('Final conversation state:');
|
|
123
131
|
console.dir(conversationHistory, { depth: null });
|
|
124
132
|
process.exit(1);
|
|
125
133
|
});
|
package/src/scripts/cli3.ts
CHANGED
|
@@ -2,16 +2,14 @@
|
|
|
2
2
|
// src/scripts/cli.ts
|
|
3
3
|
import { config } from 'dotenv';
|
|
4
4
|
config();
|
|
5
|
-
import { z } from
|
|
5
|
+
import { z } from 'zod';
|
|
6
6
|
import { HumanMessage, BaseMessage } from '@langchain/core/messages';
|
|
7
7
|
import type { RunnableConfig } from '@langchain/core/runnables';
|
|
8
|
-
import {
|
|
9
|
-
import { tool } from "@langchain/core/tools";
|
|
8
|
+
import { tool } from '@langchain/core/tools';
|
|
10
9
|
import type * as t from '@/types';
|
|
11
10
|
import { ModelEndHandler, ToolEndHandler } from '@/events';
|
|
12
11
|
import { ChatModelStreamHandler } from '@/stream';
|
|
13
12
|
|
|
14
|
-
|
|
15
13
|
import { getArgs } from '@/scripts/args';
|
|
16
14
|
import { Run } from '@/run';
|
|
17
15
|
import { GraphEvents, Callback } from '@/common';
|
|
@@ -28,25 +26,29 @@ async function testStandardStreaming(): Promise<void> {
|
|
|
28
26
|
handle: (_event: string, data: t.StreamEventData): void => {
|
|
29
27
|
console.log('====== ON_RUN_STEP ======');
|
|
30
28
|
console.dir(data, { depth: null });
|
|
31
|
-
}
|
|
29
|
+
},
|
|
32
30
|
},
|
|
33
31
|
[GraphEvents.ON_RUN_STEP_DELTA]: {
|
|
34
32
|
handle: (_event: string, data: t.StreamEventData): void => {
|
|
35
33
|
console.log('====== ON_RUN_STEP_DELTA ======');
|
|
36
34
|
console.dir(data, { depth: null });
|
|
37
|
-
}
|
|
35
|
+
},
|
|
38
36
|
},
|
|
39
37
|
[GraphEvents.ON_MESSAGE_DELTA]: {
|
|
40
38
|
handle: (_event: string, data: t.StreamEventData): void => {
|
|
41
39
|
console.log('====== ON_MESSAGE_DELTA ======');
|
|
42
40
|
console.dir(data, { depth: null });
|
|
43
|
-
}
|
|
41
|
+
},
|
|
44
42
|
},
|
|
45
43
|
[GraphEvents.TOOL_START]: {
|
|
46
|
-
handle: (
|
|
44
|
+
handle: (
|
|
45
|
+
_event: string,
|
|
46
|
+
data: t.StreamEventData,
|
|
47
|
+
metadata?: Record<string, unknown>
|
|
48
|
+
): void => {
|
|
47
49
|
console.log('====== TOOL_START ======');
|
|
48
50
|
console.dir(data, { depth: null });
|
|
49
|
-
}
|
|
51
|
+
},
|
|
50
52
|
},
|
|
51
53
|
// [GraphEvents.LLM_STREAM]: new LLMStreamHandler(),
|
|
52
54
|
// [GraphEvents.LLM_START]: {
|
|
@@ -86,21 +88,24 @@ async function testStandardStreaming(): Promise<void> {
|
|
|
86
88
|
|
|
87
89
|
const llmConfig = getLLMConfig(provider);
|
|
88
90
|
|
|
89
|
-
const getWeather = tool(
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
91
|
+
const getWeather = tool(
|
|
92
|
+
async ({ location }) => {
|
|
93
|
+
if (location === 'SAN FRANCISCO') {
|
|
94
|
+
return "It's 60 degrees and foggy";
|
|
95
|
+
} else if (location.toLowerCase() === 'san francisco') {
|
|
96
|
+
throw new Error('Input queries must be all capitals');
|
|
97
|
+
} else {
|
|
98
|
+
throw new Error('Invalid input.');
|
|
99
|
+
}
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
name: 'get_weather',
|
|
103
|
+
description: 'Call to get the current weather',
|
|
104
|
+
schema: z.object({
|
|
105
|
+
location: z.string(),
|
|
106
|
+
}),
|
|
96
107
|
}
|
|
97
|
-
|
|
98
|
-
name: "get_weather",
|
|
99
|
-
description: "Call to get the current weather",
|
|
100
|
-
schema: z.object({
|
|
101
|
-
location: z.string(),
|
|
102
|
-
}),
|
|
103
|
-
});
|
|
108
|
+
);
|
|
104
109
|
|
|
105
110
|
const run = await Run.create<t.IState>({
|
|
106
111
|
runId: 'test-run-id',
|
|
@@ -108,7 +113,7 @@ async function testStandardStreaming(): Promise<void> {
|
|
|
108
113
|
type: 'standard',
|
|
109
114
|
llmConfig,
|
|
110
115
|
tools: [getWeather],
|
|
111
|
-
// tools: [
|
|
116
|
+
// tools: [],
|
|
112
117
|
},
|
|
113
118
|
customHandlers,
|
|
114
119
|
});
|
|
@@ -117,8 +122,9 @@ async function testStandardStreaming(): Promise<void> {
|
|
|
117
122
|
configurable: {
|
|
118
123
|
provider,
|
|
119
124
|
thread_id: 'conversation-num-1',
|
|
120
|
-
instructions:
|
|
121
|
-
|
|
125
|
+
instructions:
|
|
126
|
+
'You are a friendly AI assistant. Always address the user by their name.',
|
|
127
|
+
additional_instructions: `The user's name is ${userName} and they are located in ${location}.`,
|
|
122
128
|
},
|
|
123
129
|
streamMode: 'values',
|
|
124
130
|
version: 'v2' as const,
|
|
@@ -132,10 +138,10 @@ async function testStandardStreaming(): Promise<void> {
|
|
|
132
138
|
};
|
|
133
139
|
const contentParts = await run.processStream(inputs, config, {
|
|
134
140
|
callbacks: {
|
|
135
|
-
|
|
136
|
-
|
|
141
|
+
[Callback.TOOL_ERROR]: (graph, error, toolId) => {
|
|
142
|
+
console.error(`Tool ${toolId} failed with error: ${error.message}`);
|
|
143
|
+
},
|
|
137
144
|
},
|
|
138
|
-
},
|
|
139
145
|
});
|
|
140
146
|
const finalMessages = run.getRunMessages();
|
|
141
147
|
if (finalMessages) {
|
package/src/scripts/cli4.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 { ModelEndHandler, ToolEndHandler } from '@/events';
|
|
9
8
|
import { ChatModelStreamHandler } from '@/stream';
|
|
@@ -96,7 +95,7 @@ async function testStandardStreaming(): Promise<void> {
|
|
|
96
95
|
const graphConfig: t.LegacyGraphConfig = {
|
|
97
96
|
type: 'standard',
|
|
98
97
|
llmConfig,
|
|
99
|
-
tools: [
|
|
98
|
+
tools: [],
|
|
100
99
|
instructions:
|
|
101
100
|
'You are a friendly AI assistant. Always address the user by their name.',
|
|
102
101
|
additional_instructions: `The user's name is ${userName} and they are located in ${location}.`,
|
package/src/scripts/cli5.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 { ModelEndHandler, ToolEndHandler } from '@/events';
|
|
9
8
|
import { ChatModelStreamHandler } from '@/stream';
|
|
@@ -96,7 +95,7 @@ async function testStandardStreaming(): Promise<void> {
|
|
|
96
95
|
const graphConfig: t.LegacyGraphConfig = {
|
|
97
96
|
type: 'standard',
|
|
98
97
|
llmConfig,
|
|
99
|
-
tools: [
|
|
98
|
+
tools: [],
|
|
100
99
|
instructions:
|
|
101
100
|
'You are a friendly AI assistant. Always address the user by their name.',
|
|
102
101
|
additional_instructions: `The user's name is ${userName} and they are located in ${location}.`,
|
package/src/scripts/code_exec.ts
CHANGED
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
import { config } from 'dotenv';
|
|
3
3
|
config();
|
|
4
4
|
import { HumanMessage, AIMessage, BaseMessage } from '@langchain/core/messages';
|
|
5
|
-
import { TavilySearchResults } from '@langchain/community/tools/tavily_search';
|
|
6
5
|
import type { RunnableConfig } from '@langchain/core/runnables';
|
|
7
6
|
import type * as t from '@/types';
|
|
8
7
|
import { ChatModelStreamHandler, createContentAggregator } from '@/stream';
|
|
@@ -88,7 +87,7 @@ async function testCodeExecution(): Promise<void> {
|
|
|
88
87
|
graphConfig: {
|
|
89
88
|
type: 'standard',
|
|
90
89
|
llmConfig,
|
|
91
|
-
tools: [
|
|
90
|
+
tools: [createCodeExecutionTool()],
|
|
92
91
|
instructions:
|
|
93
92
|
'You are a friendly AI assistant with coding capabilities. Always address the user by their name.',
|
|
94
93
|
additional_instructions: `The user's name is ${userName} and they are located in ${location}.`,
|
|
@@ -2,7 +2,6 @@
|
|
|
2
2
|
import { config } from 'dotenv';
|
|
3
3
|
config();
|
|
4
4
|
import { HumanMessage, BaseMessage } from '@langchain/core/messages';
|
|
5
|
-
import { TavilySearchResults } from '@langchain/community/tools/tavily_search';
|
|
6
5
|
import type * as t from '@/types';
|
|
7
6
|
import { ChatModelStreamHandler, createContentAggregator } from '@/stream';
|
|
8
7
|
import { createCodeExecutionTool } from '@/tools/CodeExecutor';
|
|
@@ -96,7 +95,7 @@ async function testCodeExecution(): Promise<void> {
|
|
|
96
95
|
graphConfig: {
|
|
97
96
|
type: 'standard',
|
|
98
97
|
llmConfig,
|
|
99
|
-
tools: [
|
|
98
|
+
tools: [createCodeExecutionTool()],
|
|
100
99
|
instructions,
|
|
101
100
|
additional_instructions,
|
|
102
101
|
maxContextTokens: 8000,
|
package/src/scripts/content.ts
CHANGED
|
@@ -3,12 +3,10 @@
|
|
|
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 } from '@/events';
|
|
10
9
|
|
|
11
|
-
|
|
12
10
|
import { getArgs } from '@/scripts/args';
|
|
13
11
|
import { Run } from '@/run';
|
|
14
12
|
import { GraphEvents, Callback } from '@/common';
|
|
@@ -23,38 +21,57 @@ async function testStandardStreaming(): Promise<void> {
|
|
|
23
21
|
// [GraphEvents.CHAT_MODEL_END]: new ModelEndHandler(),
|
|
24
22
|
[GraphEvents.CHAT_MODEL_STREAM]: new ChatModelStreamHandler(),
|
|
25
23
|
[GraphEvents.ON_RUN_STEP_COMPLETED]: {
|
|
26
|
-
handle: (
|
|
24
|
+
handle: (
|
|
25
|
+
event: GraphEvents.ON_RUN_STEP_COMPLETED,
|
|
26
|
+
data: t.StreamEventData
|
|
27
|
+
): void => {
|
|
27
28
|
console.log('====== ON_RUN_STEP_COMPLETED ======');
|
|
28
29
|
// console.dir(data, { depth: null });
|
|
29
|
-
aggregateContent({
|
|
30
|
-
|
|
30
|
+
aggregateContent({
|
|
31
|
+
event,
|
|
32
|
+
data: data as unknown as { result: t.ToolEndEvent },
|
|
33
|
+
});
|
|
34
|
+
},
|
|
31
35
|
},
|
|
32
36
|
[GraphEvents.ON_RUN_STEP]: {
|
|
33
|
-
handle: (
|
|
37
|
+
handle: (
|
|
38
|
+
event: GraphEvents.ON_RUN_STEP,
|
|
39
|
+
data: t.StreamEventData
|
|
40
|
+
): void => {
|
|
34
41
|
console.log('====== ON_RUN_STEP ======');
|
|
35
42
|
console.dir(data, { depth: null });
|
|
36
43
|
aggregateContent({ event, data: data as t.RunStep });
|
|
37
|
-
}
|
|
44
|
+
},
|
|
38
45
|
},
|
|
39
46
|
[GraphEvents.ON_RUN_STEP_DELTA]: {
|
|
40
|
-
handle: (
|
|
47
|
+
handle: (
|
|
48
|
+
event: GraphEvents.ON_RUN_STEP_DELTA,
|
|
49
|
+
data: t.StreamEventData
|
|
50
|
+
): void => {
|
|
41
51
|
console.log('====== ON_RUN_STEP_DELTA ======');
|
|
42
52
|
console.dir(data, { depth: null });
|
|
43
53
|
aggregateContent({ event, data: data as t.RunStepDeltaEvent });
|
|
44
|
-
}
|
|
54
|
+
},
|
|
45
55
|
},
|
|
46
56
|
[GraphEvents.ON_MESSAGE_DELTA]: {
|
|
47
|
-
handle: (
|
|
57
|
+
handle: (
|
|
58
|
+
event: GraphEvents.ON_MESSAGE_DELTA,
|
|
59
|
+
data: t.StreamEventData
|
|
60
|
+
): void => {
|
|
48
61
|
console.log('====== ON_MESSAGE_DELTA ======');
|
|
49
62
|
console.dir(data, { depth: null });
|
|
50
63
|
aggregateContent({ event, data: data as t.MessageDeltaEvent });
|
|
51
|
-
}
|
|
64
|
+
},
|
|
52
65
|
},
|
|
53
66
|
[GraphEvents.TOOL_START]: {
|
|
54
|
-
handle: (
|
|
67
|
+
handle: (
|
|
68
|
+
_event: string,
|
|
69
|
+
data: t.StreamEventData,
|
|
70
|
+
metadata?: Record<string, unknown>
|
|
71
|
+
): void => {
|
|
55
72
|
console.log('====== TOOL_START ======');
|
|
56
73
|
// console.dir(data, { depth: null });
|
|
57
|
-
}
|
|
74
|
+
},
|
|
58
75
|
},
|
|
59
76
|
};
|
|
60
77
|
|
|
@@ -65,8 +82,9 @@ async function testStandardStreaming(): Promise<void> {
|
|
|
65
82
|
graphConfig: {
|
|
66
83
|
type: 'standard',
|
|
67
84
|
llmConfig,
|
|
68
|
-
tools: [
|
|
69
|
-
instructions:
|
|
85
|
+
tools: [],
|
|
86
|
+
instructions:
|
|
87
|
+
'You are a friendly AI assistant. Always address the user by their name.',
|
|
70
88
|
additional_instructions: `The user's name is ${userName} and they are located in ${location}.`,
|
|
71
89
|
},
|
|
72
90
|
returnContent: true,
|
package/src/scripts/simple.ts
CHANGED
|
@@ -7,7 +7,6 @@ import {
|
|
|
7
7
|
BaseMessage,
|
|
8
8
|
UsageMetadata,
|
|
9
9
|
} from '@langchain/core/messages';
|
|
10
|
-
import { TavilySearchResults } from '@langchain/community/tools/tavily_search';
|
|
11
10
|
import type * as t from '@/types';
|
|
12
11
|
import { ChatModelStreamHandler, createContentAggregator } from '@/stream';
|
|
13
12
|
import {
|
|
@@ -135,7 +134,7 @@ async function testStandardStreaming(): Promise<void> {
|
|
|
135
134
|
graphConfig: {
|
|
136
135
|
type: 'standard',
|
|
137
136
|
llmConfig,
|
|
138
|
-
// tools: [
|
|
137
|
+
// tools: [],
|
|
139
138
|
// reasoningKey: 'reasoning',
|
|
140
139
|
instructions:
|
|
141
140
|
'You are a friendly AI assistant. Always address the user by their name.',
|
package/src/scripts/stream.ts
CHANGED
|
@@ -3,12 +3,10 @@
|
|
|
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 } from '@/events';
|
|
10
9
|
|
|
11
|
-
|
|
12
10
|
import { getArgs } from '@/scripts/args';
|
|
13
11
|
import { Run } from '@/run';
|
|
14
12
|
import { GraphEvents, Callback } from '@/common';
|
|
@@ -23,38 +21,57 @@ async function testStandardStreaming(): Promise<void> {
|
|
|
23
21
|
// [GraphEvents.CHAT_MODEL_END]: new ModelEndHandler(),
|
|
24
22
|
[GraphEvents.CHAT_MODEL_STREAM]: new ChatModelStreamHandler(),
|
|
25
23
|
[GraphEvents.ON_RUN_STEP_COMPLETED]: {
|
|
26
|
-
handle: (
|
|
24
|
+
handle: (
|
|
25
|
+
event: GraphEvents.ON_RUN_STEP_COMPLETED,
|
|
26
|
+
data: t.StreamEventData
|
|
27
|
+
): void => {
|
|
27
28
|
console.log('====== ON_RUN_STEP_COMPLETED ======');
|
|
28
29
|
// console.dir(data, { depth: null });
|
|
29
|
-
aggregateContent({
|
|
30
|
-
|
|
30
|
+
aggregateContent({
|
|
31
|
+
event,
|
|
32
|
+
data: data as unknown as { result: t.ToolEndEvent },
|
|
33
|
+
});
|
|
34
|
+
},
|
|
31
35
|
},
|
|
32
36
|
[GraphEvents.ON_RUN_STEP]: {
|
|
33
|
-
handle: (
|
|
37
|
+
handle: (
|
|
38
|
+
event: GraphEvents.ON_RUN_STEP,
|
|
39
|
+
data: t.StreamEventData
|
|
40
|
+
): void => {
|
|
34
41
|
console.log('====== ON_RUN_STEP ======');
|
|
35
42
|
console.dir(data, { depth: null });
|
|
36
43
|
aggregateContent({ event, data: data as t.RunStep });
|
|
37
|
-
}
|
|
44
|
+
},
|
|
38
45
|
},
|
|
39
46
|
[GraphEvents.ON_RUN_STEP_DELTA]: {
|
|
40
|
-
handle: (
|
|
47
|
+
handle: (
|
|
48
|
+
event: GraphEvents.ON_RUN_STEP_DELTA,
|
|
49
|
+
data: t.StreamEventData
|
|
50
|
+
): void => {
|
|
41
51
|
console.log('====== ON_RUN_STEP_DELTA ======');
|
|
42
52
|
console.dir(data, { depth: null });
|
|
43
53
|
aggregateContent({ event, data: data as t.RunStepDeltaEvent });
|
|
44
|
-
}
|
|
54
|
+
},
|
|
45
55
|
},
|
|
46
56
|
[GraphEvents.ON_MESSAGE_DELTA]: {
|
|
47
|
-
handle: (
|
|
57
|
+
handle: (
|
|
58
|
+
event: GraphEvents.ON_MESSAGE_DELTA,
|
|
59
|
+
data: t.StreamEventData
|
|
60
|
+
): void => {
|
|
48
61
|
console.log('====== ON_MESSAGE_DELTA ======');
|
|
49
62
|
console.dir(data, { depth: null });
|
|
50
63
|
aggregateContent({ event, data: data as t.MessageDeltaEvent });
|
|
51
|
-
}
|
|
64
|
+
},
|
|
52
65
|
},
|
|
53
66
|
[GraphEvents.TOOL_START]: {
|
|
54
|
-
handle: (
|
|
67
|
+
handle: (
|
|
68
|
+
_event: string,
|
|
69
|
+
data: t.StreamEventData,
|
|
70
|
+
metadata?: Record<string, unknown>
|
|
71
|
+
): void => {
|
|
55
72
|
console.log('====== TOOL_START ======');
|
|
56
73
|
// console.dir(data, { depth: null });
|
|
57
|
-
}
|
|
74
|
+
},
|
|
58
75
|
},
|
|
59
76
|
};
|
|
60
77
|
|
|
@@ -65,8 +82,9 @@ async function testStandardStreaming(): Promise<void> {
|
|
|
65
82
|
graphConfig: {
|
|
66
83
|
type: 'standard',
|
|
67
84
|
llmConfig,
|
|
68
|
-
tools: [
|
|
69
|
-
instructions:
|
|
85
|
+
tools: [],
|
|
86
|
+
instructions:
|
|
87
|
+
'You are a friendly AI assistant. Always address the user by their name.',
|
|
70
88
|
additional_instructions: `The user's name is ${userName} and they are located in ${location}.`,
|
|
71
89
|
streamBuffer: 3000,
|
|
72
90
|
},
|