@jarvis-agent/core 0.1.5 → 0.1.7
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/agent/base.d.ts +5 -3
- package/dist/agent/base.d.ts.map +1 -1
- package/dist/agent/browser/browser_labels.d.ts +1 -1
- package/dist/agent/browser/browser_labels.d.ts.map +1 -1
- package/dist/agent/browser/browser_screen.d.ts +1 -1
- package/dist/agent/browser/browser_screen.d.ts.map +1 -1
- package/dist/agent/computer.d.ts +1 -1
- package/dist/agent/computer.d.ts.map +1 -1
- package/dist/agent/file.d.ts +1 -1
- package/dist/agent/file.d.ts.map +1 -1
- package/dist/agent/shell.d.ts +1 -1
- package/dist/agent/shell.d.ts.map +1 -1
- package/dist/config/index.d.ts +5 -1
- package/dist/config/index.d.ts.map +1 -1
- package/dist/core/context.d.ts.map +1 -1
- package/dist/core/dialogue.d.ts.map +1 -1
- package/dist/core/plan.d.ts.map +1 -1
- package/dist/core/replan.d.ts.map +1 -1
- package/dist/index.cjs.js +141 -125
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +107 -90
- package/dist/index.esm.js.map +1 -1
- package/dist/memory/index.d.ts.map +1 -1
- package/dist/tools/human_interact.d.ts.map +1 -1
- package/dist/tools/watch_trigger.d.ts.map +1 -1
- package/dist/types/core.types.d.ts +19 -0
- package/dist/types/core.types.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs.js
CHANGED
|
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
4
4
|
|
|
5
5
|
var buffer = require('buffer');
|
|
6
6
|
|
|
7
|
-
const
|
|
7
|
+
const defaultConfig = {
|
|
8
8
|
name: "Eko",
|
|
9
9
|
platform: "mac",
|
|
10
10
|
maxReactNum: 500,
|
|
@@ -20,7 +20,18 @@ const config$1 = {
|
|
|
20
20
|
parallelToolCalls: true,
|
|
21
21
|
expertMode: false,
|
|
22
22
|
expertModeTodoLoopNum: 10,
|
|
23
|
+
streamFirstTimeout: 30000,
|
|
24
|
+
streamTokenTimeout: 180000,
|
|
23
25
|
};
|
|
26
|
+
exports.config = { ...defaultConfig };
|
|
27
|
+
function mergeGlobalConfig(userConfig) {
|
|
28
|
+
if (userConfig) {
|
|
29
|
+
exports.config = { ...defaultConfig, ...userConfig };
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
exports.config = { ...defaultConfig };
|
|
33
|
+
}
|
|
34
|
+
}
|
|
24
35
|
|
|
25
36
|
var LogLevel;
|
|
26
37
|
(function (LogLevel) {
|
|
@@ -23961,6 +23972,7 @@ class Context {
|
|
|
23961
23972
|
this.chain = chain;
|
|
23962
23973
|
this.variables = new Map();
|
|
23963
23974
|
this.controller = new AbortController();
|
|
23975
|
+
mergeGlobalConfig(config.globalConfig);
|
|
23964
23976
|
}
|
|
23965
23977
|
async checkAborted(noCheckPause) {
|
|
23966
23978
|
if (this.controller.signal.aborted) {
|
|
@@ -29841,8 +29853,7 @@ async function compressAgentMessages(agentContext, messages, tools) {
|
|
|
29841
29853
|
}
|
|
29842
29854
|
async function doCompressAgentMessages(agentContext, messages, tools) {
|
|
29843
29855
|
const ekoConfig = agentContext.context.config;
|
|
29844
|
-
const rlm = new RetryLanguageModel(ekoConfig.llms, ekoConfig.compressLlms);
|
|
29845
|
-
rlm.setContext(agentContext);
|
|
29856
|
+
const rlm = new RetryLanguageModel(ekoConfig.llms, ekoConfig.compressLlms, ekoConfig.globalConfig?.streamFirstTimeout, ekoConfig.globalConfig?.streamTokenTimeout, agentContext);
|
|
29846
29857
|
// extract used tool
|
|
29847
29858
|
const usedTools = extractUsedTool(messages, tools);
|
|
29848
29859
|
const snapshotTool = new TaskSnapshotTool();
|
|
@@ -29916,10 +29927,10 @@ function compressLargeContextMessages(messages) {
|
|
|
29916
29927
|
const message = messages[r];
|
|
29917
29928
|
if (message.role == "assistant") {
|
|
29918
29929
|
message.content = message.content.map((c) => {
|
|
29919
|
-
if (c.type == "text" && c.text.length > config
|
|
29930
|
+
if (c.type == "text" && c.text.length > exports.config.largeTextLength) {
|
|
29920
29931
|
return {
|
|
29921
29932
|
...c,
|
|
29922
|
-
text: sub(c.text, config
|
|
29933
|
+
text: sub(c.text, exports.config.largeTextLength, true),
|
|
29923
29934
|
};
|
|
29924
29935
|
}
|
|
29925
29936
|
return c;
|
|
@@ -29927,10 +29938,10 @@ function compressLargeContextMessages(messages) {
|
|
|
29927
29938
|
}
|
|
29928
29939
|
else if (message.role == "user") {
|
|
29929
29940
|
message.content = message.content.map((c) => {
|
|
29930
|
-
if (c.type == "text" && c.text.length > config
|
|
29941
|
+
if (c.type == "text" && c.text.length > exports.config.largeTextLength) {
|
|
29931
29942
|
return {
|
|
29932
29943
|
...c,
|
|
29933
|
-
text: sub(c.text, config
|
|
29944
|
+
text: sub(c.text, exports.config.largeTextLength, true),
|
|
29934
29945
|
};
|
|
29935
29946
|
}
|
|
29936
29947
|
return c;
|
|
@@ -29941,18 +29952,18 @@ function compressLargeContextMessages(messages) {
|
|
|
29941
29952
|
if (c.type == "tool-result" && c.output) {
|
|
29942
29953
|
const output = c.output;
|
|
29943
29954
|
if ((output.type == "text" || output.type == "error-text") &&
|
|
29944
|
-
output.value.length > config
|
|
29955
|
+
output.value.length > exports.config.largeTextLength) {
|
|
29945
29956
|
return {
|
|
29946
29957
|
...c,
|
|
29947
29958
|
output: {
|
|
29948
29959
|
...output,
|
|
29949
|
-
value: sub(output.value, config
|
|
29960
|
+
value: sub(output.value, exports.config.largeTextLength, true),
|
|
29950
29961
|
},
|
|
29951
29962
|
};
|
|
29952
29963
|
}
|
|
29953
29964
|
else if ((output.type == "json" || output.type == "error-json") &&
|
|
29954
|
-
JSON.stringify(output.value).length > config
|
|
29955
|
-
const json_str = sub(JSON.stringify(output.value), config
|
|
29965
|
+
JSON.stringify(output.value).length > exports.config.largeTextLength) {
|
|
29966
|
+
const json_str = sub(JSON.stringify(output.value), exports.config.largeTextLength, false);
|
|
29956
29967
|
const json_obj = fixJson(json_str);
|
|
29957
29968
|
if (JSON.stringify(json_obj).length < 10) {
|
|
29958
29969
|
return {
|
|
@@ -29978,8 +29989,8 @@ function compressLargeContextMessages(messages) {
|
|
|
29978
29989
|
for (let i = 0; i < output.value.length; i++) {
|
|
29979
29990
|
const content = output.value[i];
|
|
29980
29991
|
if (content.type == "text" &&
|
|
29981
|
-
content.text.length > config
|
|
29982
|
-
content.text = sub(content.text, config
|
|
29992
|
+
content.text.length > exports.config.largeTextLength) {
|
|
29993
|
+
content.text = sub(content.text, exports.config.largeTextLength, true);
|
|
29983
29994
|
}
|
|
29984
29995
|
}
|
|
29985
29996
|
}
|
|
@@ -29992,7 +30003,7 @@ function compressLargeContextMessages(messages) {
|
|
|
29992
30003
|
function handleLargeContextMessages(messages) {
|
|
29993
30004
|
let imageNum = 0;
|
|
29994
30005
|
let fileNum = 0;
|
|
29995
|
-
let maxNum = config
|
|
30006
|
+
let maxNum = exports.config.maxDialogueImgFileNum;
|
|
29996
30007
|
let longTextTools = {};
|
|
29997
30008
|
for (let i = messages.length - 1; i >= 0; i--) {
|
|
29998
30009
|
let message = messages[i];
|
|
@@ -30045,7 +30056,7 @@ function handleLargeContextMessages(messages) {
|
|
|
30045
30056
|
for (let r = 0; r < toolContent.value.length; r++) {
|
|
30046
30057
|
let _content = toolContent.value[r];
|
|
30047
30058
|
if (_content.type == "text" &&
|
|
30048
|
-
_content.text?.length > config
|
|
30059
|
+
_content.text?.length > exports.config.largeTextLength) {
|
|
30049
30060
|
if (!longTextTools[toolResult.toolName]) {
|
|
30050
30061
|
longTextTools[toolResult.toolName] = 1;
|
|
30051
30062
|
break;
|
|
@@ -30055,7 +30066,7 @@ function handleLargeContextMessages(messages) {
|
|
|
30055
30066
|
}
|
|
30056
30067
|
_content = {
|
|
30057
30068
|
type: "text",
|
|
30058
|
-
text: sub(_content.text, config
|
|
30069
|
+
text: sub(_content.text, exports.config.largeTextLength, true),
|
|
30059
30070
|
};
|
|
30060
30071
|
toolContent.value[r] = _content;
|
|
30061
30072
|
}
|
|
@@ -30166,7 +30177,7 @@ function convertToolResult(toolUse, toolResult, user_messages) {
|
|
|
30166
30177
|
});
|
|
30167
30178
|
}
|
|
30168
30179
|
else {
|
|
30169
|
-
if (config
|
|
30180
|
+
if (exports.config.toolResultMultimodal) {
|
|
30170
30181
|
// Support returning images from tool results
|
|
30171
30182
|
let mediaData = content.data;
|
|
30172
30183
|
if (mediaData.startsWith("data:")) {
|
|
@@ -30209,7 +30220,7 @@ function convertToolResult(toolUse, toolResult, user_messages) {
|
|
|
30209
30220
|
async function callAgentLLM(agentContext, rlm, messages, tools, noCompress, toolChoice, retryNum = 0, callback, requestHandler) {
|
|
30210
30221
|
await agentContext.context.checkAborted();
|
|
30211
30222
|
if (!noCompress &&
|
|
30212
|
-
(messages.length >= config
|
|
30223
|
+
(messages.length >= exports.config.compressThreshold || (messages.length >= 10 && estimatePromptTokens(messages, tools) >= exports.config.compressTokensThreshold))) {
|
|
30213
30224
|
// Compress messages
|
|
30214
30225
|
await compressAgentMessages(agentContext, messages, tools);
|
|
30215
30226
|
}
|
|
@@ -30447,7 +30458,7 @@ async function callAgentLLM(agentContext, rlm, messages, tools, noCompress, tool
|
|
|
30447
30458
|
else if (chunk.finishReason === "length" &&
|
|
30448
30459
|
messages.length >= 3 &&
|
|
30449
30460
|
!noCompress &&
|
|
30450
|
-
retryNum < config
|
|
30461
|
+
retryNum < exports.config.maxRetryNum) {
|
|
30451
30462
|
await compressAgentMessages(agentContext, messages, tools);
|
|
30452
30463
|
return callAgentLLM(agentContext, rlm, messages, tools, noCompress, toolChoice, ++retryNum, streamCallback);
|
|
30453
30464
|
}
|
|
@@ -30484,7 +30495,7 @@ async function callAgentLLM(agentContext, rlm, messages, tools, noCompress, tool
|
|
|
30484
30495
|
}
|
|
30485
30496
|
catch (e) {
|
|
30486
30497
|
await context.checkAborted();
|
|
30487
|
-
if (retryNum < config
|
|
30498
|
+
if (retryNum < exports.config.maxRetryNum) {
|
|
30488
30499
|
await sleep(300 * (retryNum + 1) * (retryNum + 1));
|
|
30489
30500
|
if ((e + "").indexOf("is too long") > -1) {
|
|
30490
30501
|
await compressAgentMessages(agentContext, messages, tools);
|
|
@@ -30660,7 +30671,7 @@ class RetryLanguageModel {
|
|
|
30660
30671
|
}
|
|
30661
30672
|
if (!maxTokens) {
|
|
30662
30673
|
options.maxOutputTokens =
|
|
30663
|
-
llmConfig.config?.maxTokens || config
|
|
30674
|
+
llmConfig.config?.maxTokens || exports.config.maxTokens;
|
|
30664
30675
|
}
|
|
30665
30676
|
if (!providerOptions) {
|
|
30666
30677
|
options.providerOptions = defaultLLMProviderOptions();
|
|
@@ -30723,7 +30734,7 @@ class RetryLanguageModel {
|
|
|
30723
30734
|
}
|
|
30724
30735
|
if (!maxTokens) {
|
|
30725
30736
|
options.maxOutputTokens =
|
|
30726
|
-
llmConfig.config?.maxTokens || config
|
|
30737
|
+
llmConfig.config?.maxTokens || exports.config.maxTokens;
|
|
30727
30738
|
}
|
|
30728
30739
|
if (!providerOptions) {
|
|
30729
30740
|
options.providerOptions = defaultLLMProviderOptions();
|
|
@@ -31181,7 +31192,7 @@ async function getPlanSystemPrompt(context, planTaskDescription, planExampleList
|
|
|
31181
31192
|
for (let i = 0; i < plan_example_list.length; i++) {
|
|
31182
31193
|
example_prompt += `## Example ${i + 1}\n${plan_example_list[i]}\n\n`;
|
|
31183
31194
|
}
|
|
31184
|
-
return PLAN_SYSTEM_TEMPLATE.replace("{name}", config
|
|
31195
|
+
return PLAN_SYSTEM_TEMPLATE.replace("{name}", exports.config.name)
|
|
31185
31196
|
.replace("{task_description}", task_description)
|
|
31186
31197
|
.replace("{agents}", agents_prompt.trim())
|
|
31187
31198
|
.replace("{example_prompt}", example_prompt)
|
|
@@ -31197,7 +31208,7 @@ function getPlanUserPrompt(task_prompt, task_website, ext_prompt) {
|
|
|
31197
31208
|
}
|
|
31198
31209
|
prompt = prompt
|
|
31199
31210
|
.replace("{task_prompt}", task_prompt)
|
|
31200
|
-
.replace("{platform}", config
|
|
31211
|
+
.replace("{platform}", exports.config.platform)
|
|
31201
31212
|
.replace("{datetime}", new Date().toLocaleString())
|
|
31202
31213
|
.trim();
|
|
31203
31214
|
if (ext_prompt) {
|
|
@@ -31260,8 +31271,7 @@ class Planner {
|
|
|
31260
31271
|
}
|
|
31261
31272
|
async doPlan(taskPrompt, messages, saveHistory, retryNum = 0) {
|
|
31262
31273
|
const config = this.context.config;
|
|
31263
|
-
const rlm = new RetryLanguageModel(config.llms, config.planLlms);
|
|
31264
|
-
rlm.setContext(this.context);
|
|
31274
|
+
const rlm = new RetryLanguageModel(config.llms, config.planLlms, config.globalConfig?.streamFirstTimeout, config.globalConfig?.streamTokenTimeout, this.context);
|
|
31265
31275
|
const request = {
|
|
31266
31276
|
maxTokens: 8192,
|
|
31267
31277
|
temperature: 0.7,
|
|
@@ -31718,8 +31728,7 @@ async function checkTaskReplan(agentContext) {
|
|
|
31718
31728
|
if (!chain.planRequest || !chain.planResult) {
|
|
31719
31729
|
return false;
|
|
31720
31730
|
}
|
|
31721
|
-
const rlm = new RetryLanguageModel(context.config.llms, context.config.planLlms);
|
|
31722
|
-
rlm.setContext(agentContext);
|
|
31731
|
+
const rlm = new RetryLanguageModel(context.config.llms, context.config.planLlms, context.config.globalConfig?.streamFirstTimeout, context.config.globalConfig?.streamTokenTimeout, agentContext);
|
|
31723
31732
|
const agentExecution = getAgentExecutionPrompt(agentContext);
|
|
31724
31733
|
const prompt = `# Task Execution Status
|
|
31725
31734
|
${agentExecution}
|
|
@@ -32057,7 +32066,7 @@ class Eko {
|
|
|
32057
32066
|
let agent_results = [];
|
|
32058
32067
|
let agentParallel = context.variables.get("agentParallel");
|
|
32059
32068
|
if (agentParallel === undefined) {
|
|
32060
|
-
agentParallel = config
|
|
32069
|
+
agentParallel = exports.config.agentParallel;
|
|
32061
32070
|
}
|
|
32062
32071
|
if (agentParallel) {
|
|
32063
32072
|
// parallel execution
|
|
@@ -32079,7 +32088,7 @@ class Eko {
|
|
|
32079
32088
|
results.push(agent_results.join("\n\n"));
|
|
32080
32089
|
}
|
|
32081
32090
|
context.conversation.splice(0, context.conversation.length);
|
|
32082
|
-
if (config
|
|
32091
|
+
if (exports.config.expertMode &&
|
|
32083
32092
|
!workflow.modified &&
|
|
32084
32093
|
agentTree.nextAgent &&
|
|
32085
32094
|
lastAgent?.AgentContext &&
|
|
@@ -32395,7 +32404,7 @@ async function callChatLLM(messageId, rlm, messages, tools, toolChoice, retryNum
|
|
|
32395
32404
|
}
|
|
32396
32405
|
}
|
|
32397
32406
|
catch (e) {
|
|
32398
|
-
if (retryNum < config
|
|
32407
|
+
if (retryNum < exports.config.maxRetryNum) {
|
|
32399
32408
|
await sleep(200 * (retryNum + 1) * (retryNum + 1));
|
|
32400
32409
|
return callChatLLM(messageId, rlm, messages, tools, toolChoice, ++retryNum, callback, signal);
|
|
32401
32410
|
}
|
|
@@ -32712,7 +32721,7 @@ The output language should match the user's conversation language.
|
|
|
32712
32721
|
function getDialogueSystemPrompt(extSysPrompt) {
|
|
32713
32722
|
let prompt = "";
|
|
32714
32723
|
prompt += "\nCurrent datetime: {datetime}";
|
|
32715
|
-
return DIALOGUE_SYSTEM_TEMPLATE.replace("{name}", config
|
|
32724
|
+
return DIALOGUE_SYSTEM_TEMPLATE.replace("{name}", exports.config.name)
|
|
32716
32725
|
.replace("{prompt}", "\n" + prompt.trim())
|
|
32717
32726
|
.replace("{datetime}", new Date().toLocaleString())
|
|
32718
32727
|
.trim();
|
|
@@ -32754,7 +32763,7 @@ class EkoDialogue {
|
|
|
32754
32763
|
params.messageId = params.messageId ?? this.memory.genMessageId();
|
|
32755
32764
|
await this.addUserMessage(params.user, params.messageId);
|
|
32756
32765
|
}
|
|
32757
|
-
const rlm = new RetryLanguageModel(this.config.llms, this.config.chatLlms);
|
|
32766
|
+
const rlm = new RetryLanguageModel(this.config.llms, this.config.chatLlms, this.config.globalConfig?.streamFirstTimeout, this.config.globalConfig?.streamTokenTimeout);
|
|
32758
32767
|
for (let i = 0; i < 15; i++) {
|
|
32759
32768
|
const messages = this.memory.buildMessages();
|
|
32760
32769
|
const chatTools = [...this.buildInnerTools(params), ...this.tools];
|
|
@@ -33520,8 +33529,7 @@ request_help: Request assistance from the user; for instance, when an operation
|
|
|
33520
33529
|
}
|
|
33521
33530
|
try {
|
|
33522
33531
|
let imageResult = (await screenshot.call(agentContext.agent, agentContext));
|
|
33523
|
-
let rlm = new RetryLanguageModel(agentContext.context.config.llms, agentContext.agent.Llms);
|
|
33524
|
-
rlm.setContext(agentContext);
|
|
33532
|
+
let rlm = new RetryLanguageModel(agentContext.context.config.llms, agentContext.agent.Llms, agentContext.context.config.globalConfig?.streamFirstTimeout, agentContext.context.config.globalConfig?.streamTokenTimeout, agentContext);
|
|
33525
33533
|
let image = toImage(imageResult.imageBase64);
|
|
33526
33534
|
let request = {
|
|
33527
33535
|
messages: [
|
|
@@ -33769,8 +33777,7 @@ class WatchTriggerTool {
|
|
|
33769
33777
|
const start = new Date().getTime();
|
|
33770
33778
|
const timeout = (args.timeout || 5) * 60000;
|
|
33771
33779
|
const frequency = Math.max(500, (args.frequency || 1) * 1000);
|
|
33772
|
-
const rlm = new RetryLanguageModel(agentContext.context.config.llms, agentContext.agent.Llms);
|
|
33773
|
-
rlm.setContext(agentContext);
|
|
33780
|
+
const rlm = new RetryLanguageModel(agentContext.context.config.llms, agentContext.agent.Llms, agentContext.context.config.globalConfig?.streamFirstTimeout, agentContext.context.config.globalConfig?.streamTokenTimeout, agentContext);
|
|
33774
33781
|
while (new Date().getTime() - start < timeout) {
|
|
33775
33782
|
await agentContext.context.checkAborted();
|
|
33776
33783
|
await new Promise((resolve) => setTimeout(resolve, frequency));
|
|
@@ -34230,7 +34237,7 @@ function getAgentSystemPrompt(agent, agentNode, context, tools, extSysPrompt) {
|
|
|
34230
34237
|
}
|
|
34231
34238
|
}
|
|
34232
34239
|
}
|
|
34233
|
-
let sysPrompt = AGENT_SYSTEM_TEMPLATE.replace("{name}", config
|
|
34240
|
+
let sysPrompt = AGENT_SYSTEM_TEMPLATE.replace("{name}", exports.config.name)
|
|
34234
34241
|
.replace("{agent}", agent.Name)
|
|
34235
34242
|
.replace("{description}", agent.Description)
|
|
34236
34243
|
.replace("{prompt}", "\n" + prompt.trim())
|
|
@@ -34261,25 +34268,31 @@ class Agent {
|
|
|
34261
34268
|
this.description = params.description;
|
|
34262
34269
|
this.tools = params.tools;
|
|
34263
34270
|
this.llms = params.llms;
|
|
34264
|
-
this.
|
|
34271
|
+
this.mcpClients = params.mcpClients || (params.mcpClient ? [params.mcpClient] : []);
|
|
34265
34272
|
this.planDescription = params.planDescription;
|
|
34266
34273
|
this.requestHandler = params.requestHandler;
|
|
34267
34274
|
}
|
|
34268
34275
|
async run(context, agentChain) {
|
|
34269
|
-
const
|
|
34276
|
+
const mcpClients = this.mcpClients.length > 0
|
|
34277
|
+
? this.mcpClients
|
|
34278
|
+
: (context.config.defaultMcpClient ? [context.config.defaultMcpClient] : []);
|
|
34270
34279
|
const agentContext = new AgentContext(context, this, agentChain);
|
|
34271
34280
|
try {
|
|
34272
34281
|
this.agentContext = agentContext;
|
|
34273
|
-
|
|
34274
|
-
!
|
|
34275
|
-
|
|
34276
|
-
|
|
34282
|
+
for (const client of mcpClients) {
|
|
34283
|
+
if (!client.isConnected()) {
|
|
34284
|
+
await client.connect(context.controller.signal);
|
|
34285
|
+
}
|
|
34286
|
+
}
|
|
34287
|
+
return await this.runWithContext(agentContext, mcpClients, exports.config.maxReactNum);
|
|
34277
34288
|
}
|
|
34278
34289
|
finally {
|
|
34279
|
-
|
|
34290
|
+
for (const client of mcpClients) {
|
|
34291
|
+
await client.close();
|
|
34292
|
+
}
|
|
34280
34293
|
}
|
|
34281
34294
|
}
|
|
34282
|
-
async runWithContext(agentContext,
|
|
34295
|
+
async runWithContext(agentContext, mcpClients, maxReactNum = 100, historyMessages = []) {
|
|
34283
34296
|
let loopNum = 0;
|
|
34284
34297
|
let checkNum = 0;
|
|
34285
34298
|
this.agentContext = agentContext;
|
|
@@ -34302,18 +34315,20 @@ class Agent {
|
|
|
34302
34315
|
},
|
|
34303
34316
|
];
|
|
34304
34317
|
agentContext.messages = messages;
|
|
34305
|
-
const rlm = new RetryLanguageModel(context.config.llms, this.llms);
|
|
34306
|
-
|
|
34318
|
+
const rlm = new RetryLanguageModel(context.config.llms, this.llms, context.config.globalConfig?.streamFirstTimeout, context.config.globalConfig?.streamTokenTimeout, agentContext);
|
|
34319
|
+
const resolvedMcpClients = Array.isArray(mcpClients)
|
|
34320
|
+
? mcpClients
|
|
34321
|
+
: (mcpClients ? [mcpClients] : []);
|
|
34307
34322
|
let agentTools = tools;
|
|
34308
34323
|
while (loopNum < maxReactNum) {
|
|
34309
34324
|
await context.checkAborted();
|
|
34310
|
-
if (
|
|
34325
|
+
if (resolvedMcpClients.length > 0) {
|
|
34311
34326
|
const controlMcp = await this.controlMcpTools(agentContext, messages, loopNum);
|
|
34312
34327
|
if (controlMcp.mcpTools) {
|
|
34313
|
-
const mcpTools = await this.
|
|
34328
|
+
const mcpTools = await this.listMcpTools(context, resolvedMcpClients, agentNode, controlMcp.mcpParams);
|
|
34314
34329
|
const usedTools = extractUsedTool(messages, agentTools);
|
|
34315
|
-
const
|
|
34316
|
-
agentTools = mergeTools(
|
|
34330
|
+
const mergedTools = mergeTools(tools, usedTools);
|
|
34331
|
+
agentTools = mergeTools(mergedTools, mcpTools);
|
|
34317
34332
|
}
|
|
34318
34333
|
}
|
|
34319
34334
|
await this.handleMessages(agentContext, messages, tools);
|
|
@@ -34326,12 +34341,12 @@ class Agent {
|
|
|
34326
34341
|
const finalResult = await this.handleCallResult(agentContext, messages, agentTools, results);
|
|
34327
34342
|
loopNum++;
|
|
34328
34343
|
if (!finalResult) {
|
|
34329
|
-
if (config
|
|
34344
|
+
if (exports.config.expertMode && loopNum % exports.config.expertModeTodoLoopNum == 0) {
|
|
34330
34345
|
await doTodoListManager(agentContext, rlm, messages, llm_tools);
|
|
34331
34346
|
}
|
|
34332
34347
|
continue;
|
|
34333
34348
|
}
|
|
34334
|
-
if (config
|
|
34349
|
+
if (exports.config.expertMode && checkNum == 0) {
|
|
34335
34350
|
checkNum++;
|
|
34336
34351
|
const { completionStatus } = await doTaskResultCheck(agentContext, rlm, messages, llm_tools);
|
|
34337
34352
|
if (completionStatus == "incomplete") {
|
|
@@ -34470,33 +34485,32 @@ class Agent {
|
|
|
34470
34485
|
async extSysPrompt(agentContext, tools) {
|
|
34471
34486
|
return "";
|
|
34472
34487
|
}
|
|
34473
|
-
async
|
|
34474
|
-
|
|
34475
|
-
|
|
34476
|
-
|
|
34488
|
+
async listMcpTools(context, clients, agentNode, mcpParams) {
|
|
34489
|
+
const allTools = [];
|
|
34490
|
+
for (const client of clients) {
|
|
34491
|
+
try {
|
|
34492
|
+
if (!client.isConnected()) {
|
|
34493
|
+
await client.connect(context.controller.signal);
|
|
34494
|
+
}
|
|
34495
|
+
const list = await client.listTools({
|
|
34496
|
+
taskId: context.taskId,
|
|
34497
|
+
nodeId: agentNode?.id,
|
|
34498
|
+
environment: exports.config.platform,
|
|
34499
|
+
agent_name: agentNode?.name || this.name,
|
|
34500
|
+
params: {},
|
|
34501
|
+
prompt: agentNode?.task || context.chain.taskPrompt,
|
|
34502
|
+
...(mcpParams || {}),
|
|
34503
|
+
}, context.controller.signal);
|
|
34504
|
+
for (const toolSchema of list) {
|
|
34505
|
+
const execute = this.toolExecuter(client, toolSchema.name);
|
|
34506
|
+
allTools.push(new McpTool(new ToolWrapper(toolSchema, execute)));
|
|
34507
|
+
}
|
|
34508
|
+
}
|
|
34509
|
+
catch (e) {
|
|
34510
|
+
Log.error("Mcp listTools error", e);
|
|
34477
34511
|
}
|
|
34478
|
-
let list = await mcpClient.listTools({
|
|
34479
|
-
taskId: context.taskId,
|
|
34480
|
-
nodeId: agentNode?.id,
|
|
34481
|
-
environment: config$1.platform,
|
|
34482
|
-
agent_name: agentNode?.name || this.name,
|
|
34483
|
-
params: {},
|
|
34484
|
-
prompt: agentNode?.task || context.chain.taskPrompt,
|
|
34485
|
-
...(mcpParams || {}),
|
|
34486
|
-
}, context.controller.signal);
|
|
34487
|
-
let mcpTools = [];
|
|
34488
|
-
for (let i = 0; i < list.length; i++) {
|
|
34489
|
-
let toolSchema = list[i];
|
|
34490
|
-
let execute = this.toolExecuter(mcpClient, toolSchema.name);
|
|
34491
|
-
let toolWrapper = new ToolWrapper(toolSchema, execute);
|
|
34492
|
-
mcpTools.push(new McpTool(toolWrapper));
|
|
34493
|
-
}
|
|
34494
|
-
return mcpTools;
|
|
34495
|
-
}
|
|
34496
|
-
catch (e) {
|
|
34497
|
-
Log.error("Mcp listTools error", e);
|
|
34498
|
-
return [];
|
|
34499
34512
|
}
|
|
34513
|
+
return allTools;
|
|
34500
34514
|
}
|
|
34501
34515
|
async controlMcpTools(agentContext, messages, loopNum) {
|
|
34502
34516
|
return {
|
|
@@ -34512,7 +34526,7 @@ class Agent {
|
|
|
34512
34526
|
extInfo: {
|
|
34513
34527
|
taskId: agentContext.context.taskId,
|
|
34514
34528
|
nodeId: agentContext.agentChain.agent.id,
|
|
34515
|
-
environment: config
|
|
34529
|
+
environment: exports.config.platform,
|
|
34516
34530
|
agent_name: agentContext.agent.Name,
|
|
34517
34531
|
},
|
|
34518
34532
|
}, agentContext.context.controller.signal);
|
|
@@ -34539,9 +34553,9 @@ class Agent {
|
|
|
34539
34553
|
};
|
|
34540
34554
|
}
|
|
34541
34555
|
async loadTools(context) {
|
|
34542
|
-
if (this.
|
|
34543
|
-
|
|
34544
|
-
if (mcpTools
|
|
34556
|
+
if (this.mcpClients.length > 0) {
|
|
34557
|
+
const mcpTools = await this.listMcpTools(context, this.mcpClients);
|
|
34558
|
+
if (mcpTools.length > 0) {
|
|
34545
34559
|
return mergeTools(this.tools, mcpTools);
|
|
34546
34560
|
}
|
|
34547
34561
|
}
|
|
@@ -34556,7 +34570,7 @@ class Agent {
|
|
|
34556
34570
|
}
|
|
34557
34571
|
}
|
|
34558
34572
|
canParallelToolCalls(toolCalls) {
|
|
34559
|
-
return config
|
|
34573
|
+
return exports.config.parallelToolCalls;
|
|
34560
34574
|
}
|
|
34561
34575
|
get Llms() {
|
|
34562
34576
|
return this.llms;
|
|
@@ -34573,8 +34587,11 @@ class Agent {
|
|
|
34573
34587
|
get PlanDescription() {
|
|
34574
34588
|
return this.planDescription;
|
|
34575
34589
|
}
|
|
34590
|
+
get McpClients() {
|
|
34591
|
+
return this.mcpClients;
|
|
34592
|
+
}
|
|
34576
34593
|
get McpClient() {
|
|
34577
|
-
return this.
|
|
34594
|
+
return this.mcpClients[0];
|
|
34578
34595
|
}
|
|
34579
34596
|
get AgentContext() {
|
|
34580
34597
|
return this.agentContext;
|
|
@@ -34583,8 +34600,8 @@ class Agent {
|
|
|
34583
34600
|
|
|
34584
34601
|
const AGENT_NAME$3 = "File";
|
|
34585
34602
|
class BaseFileAgent extends Agent {
|
|
34586
|
-
constructor(work_path, llms, ext_tools,
|
|
34587
|
-
const
|
|
34603
|
+
constructor(work_path, llms, ext_tools, mcpClients, planDescription) {
|
|
34604
|
+
const initTools = [];
|
|
34588
34605
|
const prompt = work_path
|
|
34589
34606
|
? `Your working directory is: ${work_path}
|
|
34590
34607
|
- When viewing file lists and outputting file paths, always include the working directory
|
|
@@ -34597,9 +34614,9 @@ class BaseFileAgent extends Agent {
|
|
|
34597
34614
|
super({
|
|
34598
34615
|
name: AGENT_NAME$3,
|
|
34599
34616
|
description: `You are a file agent, handling file-related tasks such as creating, finding, reading, modifying files, etc.${prompt}`,
|
|
34600
|
-
tools:
|
|
34617
|
+
tools: initTools,
|
|
34601
34618
|
llms: llms,
|
|
34602
|
-
|
|
34619
|
+
mcpClients: Array.isArray(mcpClients) ? mcpClients : (mcpClients ? [mcpClients] : []),
|
|
34603
34620
|
planDescription: planDescription ||
|
|
34604
34621
|
`File operation agent, handles file-related tasks such as creating, finding, reading, modifying files, etc. Only supports text file output
|
|
34605
34622
|
- Output file names must be in English
|
|
@@ -34607,16 +34624,16 @@ class BaseFileAgent extends Agent {
|
|
|
34607
34624
|
- For data-related content, combine with visualization tools for display
|
|
34608
34625
|
- For visualizations, generate charts first before page generation to minimize repetitive work`,
|
|
34609
34626
|
});
|
|
34610
|
-
let
|
|
34627
|
+
let builtTools = this.buildInitTools();
|
|
34611
34628
|
if (ext_tools && ext_tools.length > 0) {
|
|
34612
|
-
|
|
34629
|
+
builtTools = mergeTools(builtTools, ext_tools);
|
|
34613
34630
|
}
|
|
34614
|
-
|
|
34631
|
+
builtTools.forEach((tool) => initTools.push(tool));
|
|
34615
34632
|
}
|
|
34616
34633
|
async do_file_read(agentContext, path, write_variable) {
|
|
34617
34634
|
let file_context = await this.file_read(agentContext, path);
|
|
34618
|
-
if (file_context && file_context.length > config
|
|
34619
|
-
file_context = sub(file_context, config
|
|
34635
|
+
if (file_context && file_context.length > exports.config.fileTextMaxLength) {
|
|
34636
|
+
file_context = sub(file_context, exports.config.fileTextMaxLength, true);
|
|
34620
34637
|
}
|
|
34621
34638
|
if (write_variable) {
|
|
34622
34639
|
agentContext.context.variables.set(write_variable, file_context);
|
|
@@ -34766,24 +34783,24 @@ class BaseFileAgent extends Agent {
|
|
|
34766
34783
|
|
|
34767
34784
|
const AGENT_NAME$2 = "Shell";
|
|
34768
34785
|
class BaseShellAgent extends Agent {
|
|
34769
|
-
constructor(llms, ext_tools,
|
|
34770
|
-
const
|
|
34786
|
+
constructor(llms, ext_tools, mcpClients, planDescription) {
|
|
34787
|
+
const initTools = [];
|
|
34771
34788
|
super({
|
|
34772
34789
|
name: AGENT_NAME$2,
|
|
34773
34790
|
description: `Run commands in a bash shell,
|
|
34774
34791
|
* You must first call create_session to create a new session when using it for the first time.
|
|
34775
34792
|
* Please execute delete commands with caution, and never perform dangerous operations like \`rm -rf /\`.
|
|
34776
34793
|
* Please avoid commands that may produce a very large amount of output.`,
|
|
34777
|
-
tools:
|
|
34794
|
+
tools: initTools,
|
|
34778
34795
|
llms: llms,
|
|
34779
|
-
|
|
34796
|
+
mcpClients: Array.isArray(mcpClients) ? mcpClients : (mcpClients ? [mcpClients] : []),
|
|
34780
34797
|
planDescription: planDescription || "Shell command agent, use to execute shell commands.",
|
|
34781
34798
|
});
|
|
34782
|
-
let
|
|
34799
|
+
let builtTools = this.buildInitTools();
|
|
34783
34800
|
if (ext_tools && ext_tools.length > 0) {
|
|
34784
|
-
|
|
34801
|
+
builtTools = mergeTools(builtTools, ext_tools);
|
|
34785
34802
|
}
|
|
34786
|
-
|
|
34803
|
+
builtTools.forEach((tool) => initTools.push(tool));
|
|
34787
34804
|
}
|
|
34788
34805
|
buildInitTools() {
|
|
34789
34806
|
return [
|
|
@@ -34848,8 +34865,8 @@ class BaseShellAgent extends Agent {
|
|
|
34848
34865
|
|
|
34849
34866
|
const AGENT_NAME$1 = "Computer";
|
|
34850
34867
|
class BaseComputerAgent extends Agent {
|
|
34851
|
-
constructor(llms, ext_tools,
|
|
34852
|
-
const
|
|
34868
|
+
constructor(llms, ext_tools, mcpClients, keyboardKeys) {
|
|
34869
|
+
const initTools = [];
|
|
34853
34870
|
super({
|
|
34854
34871
|
name: AGENT_NAME$1,
|
|
34855
34872
|
description: `You are a computer operation agent, who interacts with the computer using mouse and keyboard, completing specified tasks step by step based on the given tasks and screenshots. After each of your operations, you will receive the latest computer screenshot to evaluate the task execution status.
|
|
@@ -34857,13 +34874,13 @@ This is a computer GUI interface, observe the execution through screenshots, and
|
|
|
34857
34874
|
* COMPUTER OPERATIONS:
|
|
34858
34875
|
- You can operate the application using shortcuts.
|
|
34859
34876
|
- If stuck, try alternative approaches`,
|
|
34860
|
-
tools:
|
|
34877
|
+
tools: initTools,
|
|
34861
34878
|
llms: llms,
|
|
34862
|
-
|
|
34879
|
+
mcpClients: Array.isArray(mcpClients) ? mcpClients : (mcpClients ? [mcpClients] : []),
|
|
34863
34880
|
planDescription: "Computer operation agent, interact with the computer using the mouse and keyboard."
|
|
34864
34881
|
});
|
|
34865
34882
|
if (!keyboardKeys) {
|
|
34866
|
-
if (config
|
|
34883
|
+
if (exports.config.platform == "windows") {
|
|
34867
34884
|
keyboardKeys = [
|
|
34868
34885
|
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm',
|
|
34869
34886
|
'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z',
|
|
@@ -34890,11 +34907,11 @@ This is a computer GUI interface, observe the execution through screenshots, and
|
|
|
34890
34907
|
];
|
|
34891
34908
|
}
|
|
34892
34909
|
}
|
|
34893
|
-
let
|
|
34910
|
+
let builtTools = this.buildInitTools(keyboardKeys);
|
|
34894
34911
|
if (ext_tools && ext_tools.length > 0) {
|
|
34895
|
-
|
|
34912
|
+
builtTools = mergeTools(builtTools, ext_tools);
|
|
34896
34913
|
}
|
|
34897
|
-
|
|
34914
|
+
builtTools.forEach((tool) => initTools.push(tool));
|
|
34898
34915
|
}
|
|
34899
34916
|
buildInitTools(keyboardKeys) {
|
|
34900
34917
|
return [
|
|
@@ -36021,7 +36038,7 @@ function run_build_dom_tree() {
|
|
|
36021
36038
|
}
|
|
36022
36039
|
|
|
36023
36040
|
class BaseBrowserLabelsAgent extends BaseBrowserAgent {
|
|
36024
|
-
constructor(llms, ext_tools,
|
|
36041
|
+
constructor(llms, ext_tools, mcpClients) {
|
|
36025
36042
|
let description = `You are a browser operation agent, use structured commands to interact with the browser.
|
|
36026
36043
|
* This is a browser GUI interface where you need to analyze webpages by taking screenshot and page element structures, and specify action sequences to complete designated tasks.
|
|
36027
36044
|
* For your first visit, please start by calling either the \`navigate_to\` or \`current_page\` tool. After each action you perform, I will provide you with updated information about the current state, including page screenshots and structured element data that has been specially processed for easier analysis.
|
|
@@ -36048,7 +36065,7 @@ class BaseBrowserLabelsAgent extends BaseBrowserAgent {
|
|
|
36048
36065
|
* Browser operation:
|
|
36049
36066
|
- Use scroll to find elements you are looking for, When extracting content, prioritize using extract_page_content, only scroll when you need to load more content
|
|
36050
36067
|
- Please follow user instructions and don't be lazy until the task is completed. For example, if a user asks you to find 30 people, don't just find 10 - keep searching until you find all 30.`;
|
|
36051
|
-
if (config
|
|
36068
|
+
if (exports.config.parallelToolCalls) {
|
|
36052
36069
|
description += `
|
|
36053
36070
|
* Parallelism:
|
|
36054
36071
|
- Do not call the navigate_to tool simultaneously
|
|
@@ -36056,20 +36073,20 @@ class BaseBrowserLabelsAgent extends BaseBrowserAgent {
|
|
|
36056
36073
|
- When filling out a form, fields that are not dependent on each other should be filled simultaneously
|
|
36057
36074
|
- Avoid parallel processing for dependent operations, such as those that need to wait for page loading, DOM changes, redirects, subsequent operations that depend on the results of previous operations, or operations that may interfere with each other and affect the same page elements. In these cases, please do not use parallelization.`;
|
|
36058
36075
|
}
|
|
36059
|
-
const
|
|
36076
|
+
const initTools = [];
|
|
36060
36077
|
super({
|
|
36061
36078
|
name: AGENT_NAME,
|
|
36062
36079
|
description: description,
|
|
36063
|
-
tools:
|
|
36080
|
+
tools: initTools,
|
|
36064
36081
|
llms: llms,
|
|
36065
|
-
|
|
36082
|
+
mcpClients: Array.isArray(mcpClients) ? mcpClients : (mcpClients ? [mcpClients] : []),
|
|
36066
36083
|
planDescription: "Browser operation agent, interact with the browser using the mouse and keyboard.",
|
|
36067
36084
|
});
|
|
36068
|
-
let
|
|
36085
|
+
let builtTools = this.buildInitTools();
|
|
36069
36086
|
if (ext_tools && ext_tools.length > 0) {
|
|
36070
|
-
|
|
36087
|
+
builtTools = mergeTools(builtTools, ext_tools);
|
|
36071
36088
|
}
|
|
36072
|
-
|
|
36089
|
+
builtTools.forEach((tool) => initTools.push(tool));
|
|
36073
36090
|
}
|
|
36074
36091
|
async input_text(agentContext, index, text, enter) {
|
|
36075
36092
|
await this.execute_script(agentContext, typing, [{ index, text, enter }]);
|
|
@@ -36774,7 +36791,7 @@ function scroll_by(params) {
|
|
|
36774
36791
|
}
|
|
36775
36792
|
|
|
36776
36793
|
class BaseBrowserScreenAgent extends BaseBrowserAgent {
|
|
36777
|
-
constructor(llms, ext_tools,
|
|
36794
|
+
constructor(llms, ext_tools, mcpClients) {
|
|
36778
36795
|
const description = `You are a browser operation agent, use a mouse and keyboard to interact with a browser.
|
|
36779
36796
|
* This is a browser GUI interface, observe the webpage execution through screenshots, and specify action sequences to complete designated tasks.
|
|
36780
36797
|
* For the first visit, please call the \`navigate_to\` or \`current_page\` tool first. After that, each of your actions will return a screenshot of the page.
|
|
@@ -36786,20 +36803,20 @@ class BaseBrowserScreenAgent extends BaseBrowserAgent {
|
|
|
36786
36803
|
- Wait for elements to load
|
|
36787
36804
|
- Scroll pages and handle infinite scroll
|
|
36788
36805
|
- YOU CAN DO ANYTHING ON THE BROWSER - including clicking on elements, filling forms, submitting data, etc.`;
|
|
36789
|
-
const
|
|
36806
|
+
const initTools = [];
|
|
36790
36807
|
super({
|
|
36791
36808
|
name: AGENT_NAME,
|
|
36792
36809
|
description: description,
|
|
36793
|
-
tools:
|
|
36810
|
+
tools: initTools,
|
|
36794
36811
|
llms: llms,
|
|
36795
|
-
|
|
36812
|
+
mcpClients: Array.isArray(mcpClients) ? mcpClients : (mcpClients ? [mcpClients] : []),
|
|
36796
36813
|
planDescription: "Browser operation agent, interact with the browser using the mouse and keyboard.",
|
|
36797
36814
|
});
|
|
36798
|
-
let
|
|
36815
|
+
let builtTools = this.buildInitTools();
|
|
36799
36816
|
if (ext_tools && ext_tools.length > 0) {
|
|
36800
|
-
|
|
36817
|
+
builtTools = mergeTools(builtTools, ext_tools);
|
|
36801
36818
|
}
|
|
36802
|
-
|
|
36819
|
+
builtTools.forEach((tool) => initTools.push(tool));
|
|
36803
36820
|
}
|
|
36804
36821
|
buildInitTools() {
|
|
36805
36822
|
return [
|
|
@@ -37103,7 +37120,6 @@ exports.WatchTriggerTool = WatchTriggerTool;
|
|
|
37103
37120
|
exports.buildAgentTree = buildAgentTree;
|
|
37104
37121
|
exports.buildSimpleAgentWorkflow = buildSimpleAgentWorkflow;
|
|
37105
37122
|
exports.call_timeout = call_timeout;
|
|
37106
|
-
exports.config = config$1;
|
|
37107
37123
|
exports.convertToolSchema = convertToolSchema;
|
|
37108
37124
|
exports.default = Eko;
|
|
37109
37125
|
exports.extract_page_content = extract_page_content;
|