@eko-ai/eko 3.0.3 → 3.0.5
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 +4 -2
- package/dist/agent/base.d.ts.map +1 -1
- package/dist/agent/browser/browser_labels.d.ts.map +1 -1
- package/dist/config/index.d.ts +1 -0
- package/dist/config/index.d.ts.map +1 -1
- package/dist/index.cjs.js +121 -137
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +121 -137
- package/dist/index.esm.js.map +1 -1
- package/dist/prompt/agent.d.ts.map +1 -1
- package/dist/prompt/plan.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/agent/base.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { AgentChain } from "../core/chain";
|
|
2
2
|
import Context, { AgentContext } from "../core/context";
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
3
|
+
import { Tool, IMcpClient, LLMRequest, ToolResult, ToolExecuter, WorkflowAgent, HumanCallback, StreamCallback } from "../types";
|
|
4
|
+
import { LanguageModelV2Prompt, LanguageModelV2FilePart, LanguageModelV2TextPart, LanguageModelV2ToolCallPart, LanguageModelV2ToolResultPart } from "@ai-sdk/provider";
|
|
5
5
|
export type AgentParams = {
|
|
6
6
|
name: string;
|
|
7
7
|
description: string;
|
|
@@ -25,6 +25,7 @@ export declare class Agent {
|
|
|
25
25
|
run(context: Context, agentChain: AgentChain): Promise<string>;
|
|
26
26
|
runWithContext(agentContext: AgentContext, mcpClient?: IMcpClient, maxReactNum?: number, historyMessages?: LanguageModelV2Prompt): Promise<string>;
|
|
27
27
|
protected handleCallResult(agentContext: AgentContext, messages: LanguageModelV2Prompt, agentTools: Tool[], results: Array<LanguageModelV2TextPart | LanguageModelV2ToolCallPart>): Promise<string | null>;
|
|
28
|
+
protected callToolCall(agentContext: AgentContext, agentTools: Tool[], result: LanguageModelV2ToolCallPart, user_messages?: LanguageModelV2Prompt): Promise<LanguageModelV2ToolResultPart>;
|
|
28
29
|
protected system_auto_tools(agentNode: WorkflowAgent): Tool[];
|
|
29
30
|
protected buildSystemPrompt(agentContext: AgentContext, tools: Tool[]): Promise<string>;
|
|
30
31
|
protected buildUserPrompt(agentContext: AgentContext, tools: Tool[]): Promise<Array<LanguageModelV2TextPart | LanguageModelV2FilePart>>;
|
|
@@ -40,6 +41,7 @@ export declare class Agent {
|
|
|
40
41
|
loadTools(context: Context): Promise<Tool[]>;
|
|
41
42
|
addTool(tool: Tool): void;
|
|
42
43
|
protected onTaskStatus(status: "pause" | "abort" | "resume-pause", reason?: string): Promise<void>;
|
|
44
|
+
protected canParallelToolCalls(toolCalls: LanguageModelV2ToolCallPart[]): boolean;
|
|
43
45
|
get Llms(): string[] | undefined;
|
|
44
46
|
get Name(): string;
|
|
45
47
|
get Description(): string;
|
package/dist/agent/base.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/agent/base.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"base.d.ts","sourceRoot":"","sources":["../../src/agent/base.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,UAAU,EAAa,MAAM,eAAe,CAAC;AACtD,OAAO,OAAO,EAAE,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAOxD,OAAO,EACL,IAAI,EACJ,UAAU,EACV,UAAU,EACV,UAAU,EAEV,YAAY,EACZ,aAAa,EACb,aAAa,EACb,cAAc,EACf,MAAM,UAAU,CAAC;AAClB,OAAO,EACL,qBAAqB,EACrB,uBAAuB,EACvB,uBAAuB,EACvB,2BAA2B,EAC3B,6BAA6B,EAC9B,MAAM,kBAAkB,CAAC;AAY1B,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,EAAE,MAAM,CAAC;IACpB,KAAK,EAAE,IAAI,EAAE,CAAC;IACd,IAAI,CAAC,EAAE,MAAM,EAA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S,EAAE,2BAA2B,EAAE,GAAG,OAAO;IAIjF,IAAI,IAAI,IAAI,MAAM,EAAE,GAAG,SAAS,CAE/B;IAED,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,IAAI,WAAW,IAAI,MAAM,CAExB;IAED,IAAI,KAAK,IAAI,IAAI,EAAE,CAElB;IAED,IAAI,eAAe,uBAElB;IAED,IAAI,SAAS,2BAEZ;IAED,IAAI,YAAY,IAAI,YAAY,GAAG,SAAS,CAE3C;CACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"browser_labels.d.ts","sourceRoot":"","sources":["../../../src/agent/browser/browser_labels.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAE,gBAAgB,EAAc,MAAM,gBAAgB,CAAC;AAC9D,OAAO,
|
|
1
|
+
{"version":3,"file":"browser_labels.d.ts","sourceRoot":"","sources":["../../../src/agent/browser/browser_labels.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,OAAO,EAAE,gBAAgB,EAAc,MAAM,gBAAgB,CAAC;AAC9D,OAAO,EACL,qBAAqB,EAEtB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,IAAI,EAAc,UAAU,EAAE,MAAM,aAAa,CAAC;AAG3D,MAAM,CAAC,OAAO,CAAC,QAAQ,OAAO,sBAAuB,SAAQ,gBAAgB;gBAC/D,IAAI,CAAC,EAAE,MAAM,EAAE,EAAE,SAAS,CAAC,EAAE,IAAI,EAAE,EAAE,SAAS,CAAC,EAAE,UAAU;cA8CvD,UAAU,CACxB,YAAY,EAAE,YAAY,EAC1B,KAAK,EAAE,MAAM,EACb,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,OAAO,GACb,OAAO,CAAC,GAAG,CAAC;cAOC,aAAa,CAC3B,YAAY,EAAE,YAAY,EAC1B,KAAK,EAAE,MAAM,EACb,UA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AAC"}
|
package/dist/config/index.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,KAAK,YAAY,GAAG;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,SAAS,GAAG,KAAK,GAAG,OAAO,CAAC;IACtC,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,OAAO,CAAC;IACvB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,eAAe,EAAE,MAAM,CAAC;IACxB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,oBAAoB,EAAE,OAAO,CAAC;IAC9B,UAAU,EAAE,OAAO,CAAC;IACpB,qBAAqB,EAAE,MAAM,CAAC;CAC/B,CAAA;AAED,QAAA,MAAM,MAAM,EAAE,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/config/index.ts"],"names":[],"mappings":"AAAA,KAAK,YAAY,GAAG;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,QAAQ,EAAE,SAAS,GAAG,KAAK,GAAG,OAAO,CAAC;IACtC,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,CAAC;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,aAAa,EAAE,OAAO,CAAC;IACvB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,eAAe,EAAE,MAAM,CAAC;IACxB,iBAAiB,EAAE,MAAM,CAAC;IAC1B,qBAAqB,EAAE,MAAM,CAAC;IAC9B,oBAAoB,EAAE,OAAO,CAAC;IAC9B,iBAAiB,EAAE,OAAO,CAAC;IAC3B,UAAU,EAAE,OAAO,CAAC;IACpB,qBAAqB,EAAE,MAAM,CAAC;CAC/B,CAAA;AAED,QAAA,MAAM,MAAM,EAAE,YAeb,CAAC;AAEF,eAAe,MAAM,CAAC"}
|
package/dist/index.cjs.js
CHANGED
|
@@ -16,6 +16,7 @@ const config$1 = {
|
|
|
16
16
|
fileTextMaxLength: 20000,
|
|
17
17
|
maxDialogueImgFileNum: 1,
|
|
18
18
|
toolResultMultimodal: true,
|
|
19
|
+
parallelToolCalls: true,
|
|
19
20
|
expertMode: false,
|
|
20
21
|
expertModeTodoLoopNum: 10,
|
|
21
22
|
};
|
|
@@ -31396,28 +31397,6 @@ function extractUsedTool(messages, agentTools) {
|
|
|
31396
31397
|
}
|
|
31397
31398
|
return tools;
|
|
31398
31399
|
}
|
|
31399
|
-
function removeDuplicateToolUse(results) {
|
|
31400
|
-
if (results.length <= 1 ||
|
|
31401
|
-
results.filter((r) => r.type == "tool-call").length <= 1) {
|
|
31402
|
-
return results;
|
|
31403
|
-
}
|
|
31404
|
-
let _results = [];
|
|
31405
|
-
let tool_uniques = [];
|
|
31406
|
-
for (let i = 0; i < results.length; i++) {
|
|
31407
|
-
if (results[i].type === "tool-call") {
|
|
31408
|
-
let tool = results[i];
|
|
31409
|
-
let key = tool.toolName + tool.input;
|
|
31410
|
-
if (tool_uniques.indexOf(key) == -1) {
|
|
31411
|
-
_results.push(results[i]);
|
|
31412
|
-
tool_uniques.push(key);
|
|
31413
|
-
}
|
|
31414
|
-
}
|
|
31415
|
-
else {
|
|
31416
|
-
_results.push(results[i]);
|
|
31417
|
-
}
|
|
31418
|
-
}
|
|
31419
|
-
return _results;
|
|
31420
|
-
}
|
|
31421
31400
|
async function compressAgentMessages(agentContext, rlm, messages, tools) {
|
|
31422
31401
|
if (messages.length < 5) {
|
|
31423
31402
|
return;
|
|
@@ -32374,23 +32353,13 @@ You are {name}, an autonomous AI Agent Planner.
|
|
|
32374
32353
|
{example_prompt}
|
|
32375
32354
|
`;
|
|
32376
32355
|
const PLAN_TASK_DESCRIPTION = `Your task is to understand the user's requirements, dynamically plan the user's tasks based on the Agent list, and please follow the steps below:
|
|
32377
|
-
|
|
32378
|
-
|
|
32379
|
-
|
|
32380
|
-
|
|
32381
|
-
|
|
32382
|
-
|
|
32383
|
-
|
|
32384
|
-
const PLAN_CHAT_EXAMPLE = `User: hello.
|
|
32385
|
-
Output result:
|
|
32386
|
-
<root>
|
|
32387
|
-
<name>Chat</name>
|
|
32388
|
-
<thought>Alright, the user wrote "hello". That's pretty straightforward. I need to respond in a friendly and welcoming manner.</thought>
|
|
32389
|
-
<agents>
|
|
32390
|
-
<!-- Chat agents can exist without the <task> and <nodes> nodes. -->
|
|
32391
|
-
<agent name="Chat" id="0" dependsOn=""></agent>
|
|
32392
|
-
</agents>
|
|
32393
|
-
</root>`;
|
|
32356
|
+
- Analyze the Agents that need to be used based on the user's requirements.
|
|
32357
|
+
- Generate the Agent calling plan based on the analysis results.
|
|
32358
|
+
- About agent name, please do not arbitrarily fabricate non-existent agent names.
|
|
32359
|
+
- You only need to provide the steps to complete the user's task, key steps only, no need to be too detailed.
|
|
32360
|
+
- Try to break down tasks into independently completable subtasks, and for maximum efficiency, run multiple independent subtasks in parallel whenever possible.
|
|
32361
|
+
- Please strictly follow the output format and example output.
|
|
32362
|
+
- The output language should follow the language corresponding to the user's task.`;
|
|
32394
32363
|
const PLAN_EXAMPLE_LIST = [
|
|
32395
32364
|
`User: Open Boss Zhipin, find 10 operation positions in Chengdu, and send a personal introduction to the recruiters based on the page information.
|
|
32396
32365
|
Output result:
|
|
@@ -32571,13 +32540,9 @@ async function getPlanSystemPrompt(context, planTaskDescription, planExampleList
|
|
|
32571
32540
|
PLAN_TASK_DESCRIPTION;
|
|
32572
32541
|
const plan_example_list = context.variables.get("plan_example_list") ||
|
|
32573
32542
|
PLAN_EXAMPLE_LIST;
|
|
32574
|
-
const hasChatAgent = context.agents.filter((a) => a.Name == "Chat").length > 0;
|
|
32575
32543
|
let example_prompt = "";
|
|
32576
|
-
|
|
32577
|
-
|
|
32578
|
-
: [...plan_example_list];
|
|
32579
|
-
for (let i = 0; i < example_list.length; i++) {
|
|
32580
|
-
example_prompt += `## Example ${i + 1}\n${example_list[i]}\n\n`;
|
|
32544
|
+
for (let i = 0; i < plan_example_list.length; i++) {
|
|
32545
|
+
example_prompt += `## Example ${i + 1}\n${plan_example_list[i]}\n\n`;
|
|
32581
32546
|
}
|
|
32582
32547
|
return PLAN_SYSTEM_TEMPLATE.replace("{name}", config$1.name)
|
|
32583
32548
|
.replace("{task_description}", task_description)
|
|
@@ -35361,6 +35326,7 @@ You are {name}, an autonomous AI agent for {agent} agent.
|
|
|
35361
35326
|
</nodes>
|
|
35362
35327
|
</root>
|
|
35363
35328
|
|
|
35329
|
+
For maximum efficiency, whenever you need to perform multiple independent operations, invoke all relevant tools simultaneously rather than sequentially.
|
|
35364
35330
|
The output language should follow the language corresponding to the user's task.
|
|
35365
35331
|
`;
|
|
35366
35332
|
const HUMAN_PROMPT = `
|
|
@@ -35381,7 +35347,7 @@ const FOR_EACH_NODE = `
|
|
|
35381
35347
|
</forEach>`;
|
|
35382
35348
|
const FOR_EACH_PROMPT = `
|
|
35383
35349
|
* forEach node
|
|
35384
|
-
repetitive tasks, when executing
|
|
35350
|
+
For repetitive tasks, when executing a forEach node, the \`${TOOL_NAME$6}\` tool must be used. Loop tasks support parallel tool calls, and during parallel execution, this tool needs to be called interspersed throughout the process.
|
|
35385
35351
|
`;
|
|
35386
35352
|
const WATCH_NODE = `
|
|
35387
35353
|
<!-- monitor task node, the loop attribute specifies whether to listen in a loop or listen once -->
|
|
@@ -35469,8 +35435,8 @@ class Agent {
|
|
|
35469
35435
|
this.requestHandler = params.requestHandler;
|
|
35470
35436
|
}
|
|
35471
35437
|
async run(context, agentChain) {
|
|
35472
|
-
|
|
35473
|
-
|
|
35438
|
+
const mcpClient = this.mcpClient || context.config.defaultMcpClient;
|
|
35439
|
+
const agentContext = new AgentContext(context, this, agentChain);
|
|
35474
35440
|
try {
|
|
35475
35441
|
this.agentContext = agentContext;
|
|
35476
35442
|
mcpClient &&
|
|
@@ -35545,67 +35511,28 @@ class Agent {
|
|
|
35545
35511
|
return "Unfinished";
|
|
35546
35512
|
}
|
|
35547
35513
|
async handleCallResult(agentContext, messages, agentTools, results) {
|
|
35548
|
-
|
|
35549
|
-
|
|
35550
|
-
|
|
35551
|
-
let toolResults = [];
|
|
35552
|
-
results = removeDuplicateToolUse(results);
|
|
35514
|
+
const user_messages = [];
|
|
35515
|
+
const toolResults = [];
|
|
35516
|
+
// results = memory.removeDuplicateToolUse(results);
|
|
35553
35517
|
if (results.length == 0) {
|
|
35554
35518
|
return null;
|
|
35555
35519
|
}
|
|
35556
|
-
|
|
35557
|
-
|
|
35558
|
-
|
|
35559
|
-
|
|
35560
|
-
|
|
35561
|
-
|
|
35562
|
-
let
|
|
35563
|
-
|
|
35564
|
-
agentContext.agentChain.push(toolChain);
|
|
35565
|
-
try {
|
|
35566
|
-
let args = typeof result.input == "string"
|
|
35567
|
-
? JSON.parse(result.input || "{}")
|
|
35568
|
-
: result.input || {};
|
|
35569
|
-
toolChain.params = args;
|
|
35570
|
-
let tool = getTool(agentTools, result.toolName);
|
|
35571
|
-
if (!tool) {
|
|
35572
|
-
throw new Error(result.toolName + " tool does not exist");
|
|
35573
|
-
}
|
|
35574
|
-
toolResult = await tool.execute(args, agentContext, result);
|
|
35575
|
-
toolChain.updateToolResult(toolResult);
|
|
35576
|
-
agentContext.consecutiveErrorNum = 0;
|
|
35577
|
-
}
|
|
35578
|
-
catch (e) {
|
|
35579
|
-
Log.error("tool call error: ", result.toolName, result.input, e);
|
|
35580
|
-
toolResult = {
|
|
35581
|
-
content: [
|
|
35582
|
-
{
|
|
35583
|
-
type: "text",
|
|
35584
|
-
text: e + "",
|
|
35585
|
-
},
|
|
35586
|
-
],
|
|
35587
|
-
isError: true,
|
|
35588
|
-
};
|
|
35589
|
-
toolChain.updateToolResult(toolResult);
|
|
35590
|
-
if (++agentContext.consecutiveErrorNum >= 10) {
|
|
35591
|
-
throw e;
|
|
35592
|
-
}
|
|
35520
|
+
if (results.every((s) => s.type == "text")) {
|
|
35521
|
+
return results.map((s) => s.text).join("\n\n");
|
|
35522
|
+
}
|
|
35523
|
+
const toolCalls = results.filter((s) => s.type == "tool-call");
|
|
35524
|
+
if (toolCalls.length > 1 && this.canParallelToolCalls(toolCalls)) {
|
|
35525
|
+
const results = await Promise.all(toolCalls.map((toolCall) => this.callToolCall(agentContext, agentTools, toolCall, user_messages)));
|
|
35526
|
+
for (let i = 0; i < results.length; i++) {
|
|
35527
|
+
toolResults.push(results[i]);
|
|
35593
35528
|
}
|
|
35594
|
-
|
|
35595
|
-
|
|
35596
|
-
|
|
35597
|
-
|
|
35598
|
-
|
|
35599
|
-
|
|
35600
|
-
type: "tool_result",
|
|
35601
|
-
toolId: result.toolCallId,
|
|
35602
|
-
toolName: result.toolName,
|
|
35603
|
-
params: result.input || {},
|
|
35604
|
-
toolResult: toolResult,
|
|
35605
|
-
}, agentContext);
|
|
35529
|
+
}
|
|
35530
|
+
else {
|
|
35531
|
+
for (let i = 0; i < toolCalls.length; i++) {
|
|
35532
|
+
const toolCall = toolCalls[i];
|
|
35533
|
+
const toolResult = await this.callToolCall(agentContext, agentTools, toolCall, user_messages);
|
|
35534
|
+
toolResults.push(toolResult);
|
|
35606
35535
|
}
|
|
35607
|
-
const llmToolResult = convertToolResult(result, toolResult, user_messages);
|
|
35608
|
-
toolResults.push(llmToolResult);
|
|
35609
35536
|
}
|
|
35610
35537
|
messages.push({
|
|
35611
35538
|
role: "assistant",
|
|
@@ -35620,9 +35547,61 @@ class Agent {
|
|
|
35620
35547
|
return null;
|
|
35621
35548
|
}
|
|
35622
35549
|
else {
|
|
35623
|
-
return
|
|
35550
|
+
return results
|
|
35551
|
+
.filter((s) => s.type == "text")
|
|
35552
|
+
.map((s) => s.text)
|
|
35553
|
+
.join("\n\n");
|
|
35624
35554
|
}
|
|
35625
35555
|
}
|
|
35556
|
+
async callToolCall(agentContext, agentTools, result, user_messages = []) {
|
|
35557
|
+
const context = agentContext.context;
|
|
35558
|
+
const toolChain = new ToolChain(result, agentContext.agentChain.agentRequest);
|
|
35559
|
+
agentContext.agentChain.push(toolChain);
|
|
35560
|
+
let toolResult;
|
|
35561
|
+
try {
|
|
35562
|
+
const args = typeof result.input == "string"
|
|
35563
|
+
? JSON.parse(result.input || "{}")
|
|
35564
|
+
: result.input || {};
|
|
35565
|
+
toolChain.params = args;
|
|
35566
|
+
let tool = getTool(agentTools, result.toolName);
|
|
35567
|
+
if (!tool) {
|
|
35568
|
+
throw new Error(result.toolName + " tool does not exist");
|
|
35569
|
+
}
|
|
35570
|
+
toolResult = await tool.execute(args, agentContext, result);
|
|
35571
|
+
toolChain.updateToolResult(toolResult);
|
|
35572
|
+
agentContext.consecutiveErrorNum = 0;
|
|
35573
|
+
}
|
|
35574
|
+
catch (e) {
|
|
35575
|
+
Log.error("tool call error: ", result.toolName, result.input, e);
|
|
35576
|
+
toolResult = {
|
|
35577
|
+
content: [
|
|
35578
|
+
{
|
|
35579
|
+
type: "text",
|
|
35580
|
+
text: e + "",
|
|
35581
|
+
},
|
|
35582
|
+
],
|
|
35583
|
+
isError: true,
|
|
35584
|
+
};
|
|
35585
|
+
toolChain.updateToolResult(toolResult);
|
|
35586
|
+
if (++agentContext.consecutiveErrorNum >= 10) {
|
|
35587
|
+
throw e;
|
|
35588
|
+
}
|
|
35589
|
+
}
|
|
35590
|
+
const callback = this.callback || context.config.callback;
|
|
35591
|
+
if (callback) {
|
|
35592
|
+
await callback.onMessage({
|
|
35593
|
+
taskId: context.taskId,
|
|
35594
|
+
agentName: agentContext.agent.Name,
|
|
35595
|
+
nodeId: agentContext.agentChain.agent.id,
|
|
35596
|
+
type: "tool_result",
|
|
35597
|
+
toolId: result.toolCallId,
|
|
35598
|
+
toolName: result.toolName,
|
|
35599
|
+
params: result.input || {},
|
|
35600
|
+
toolResult: toolResult,
|
|
35601
|
+
}, agentContext);
|
|
35602
|
+
}
|
|
35603
|
+
return convertToolResult(result, toolResult, user_messages);
|
|
35604
|
+
}
|
|
35626
35605
|
system_auto_tools(agentNode) {
|
|
35627
35606
|
let tools = [];
|
|
35628
35607
|
let agentNodeXml = agentNode.xml;
|
|
@@ -35741,6 +35720,9 @@ class Agent {
|
|
|
35741
35720
|
this.agentContext?.variables.clear();
|
|
35742
35721
|
}
|
|
35743
35722
|
}
|
|
35723
|
+
canParallelToolCalls(toolCalls) {
|
|
35724
|
+
return config$1.parallelToolCalls;
|
|
35725
|
+
}
|
|
35744
35726
|
get Llms() {
|
|
35745
35727
|
return this.llms;
|
|
35746
35728
|
}
|
|
@@ -36073,7 +36055,7 @@ This is a computer GUI interface, observe the execution through screenshots, and
|
|
|
36073
36055
|
return [
|
|
36074
36056
|
{
|
|
36075
36057
|
name: "typing",
|
|
36076
|
-
description: "
|
|
36058
|
+
description: "Simulates keyboard typing to input text into the currently focused application or text field on the computer.",
|
|
36077
36059
|
parameters: {
|
|
36078
36060
|
type: "object",
|
|
36079
36061
|
properties: {
|
|
@@ -36090,27 +36072,27 @@ This is a computer GUI interface, observe the execution through screenshots, and
|
|
|
36090
36072
|
},
|
|
36091
36073
|
{
|
|
36092
36074
|
name: "click",
|
|
36093
|
-
description: "
|
|
36075
|
+
description: "Simulates mouse clicking at an absolute screen position (x, y) on the computer.",
|
|
36094
36076
|
parameters: {
|
|
36095
36077
|
type: "object",
|
|
36096
36078
|
properties: {
|
|
36097
36079
|
x: {
|
|
36098
36080
|
type: "number",
|
|
36099
|
-
description: "X coordinate",
|
|
36081
|
+
description: "Absolute X coordinate on the screen where the mouse will click",
|
|
36100
36082
|
},
|
|
36101
36083
|
y: {
|
|
36102
36084
|
type: "number",
|
|
36103
|
-
description: "Y coordinate",
|
|
36085
|
+
description: "Absolute Y coordinate on the screen where the mouse will click",
|
|
36104
36086
|
},
|
|
36105
36087
|
num_clicks: {
|
|
36106
36088
|
type: "number",
|
|
36107
|
-
description: "Number of
|
|
36089
|
+
description: "Number of times to click at the position",
|
|
36108
36090
|
enum: [1, 2, 3],
|
|
36109
36091
|
default: 1,
|
|
36110
36092
|
},
|
|
36111
36093
|
button: {
|
|
36112
36094
|
type: "string",
|
|
36113
|
-
description: "
|
|
36095
|
+
description: "Which mouse button to click",
|
|
36114
36096
|
enum: ["left", "right", "middle"],
|
|
36115
36097
|
default: "left",
|
|
36116
36098
|
},
|
|
@@ -36123,17 +36105,17 @@ This is a computer GUI interface, observe the execution through screenshots, and
|
|
|
36123
36105
|
},
|
|
36124
36106
|
{
|
|
36125
36107
|
name: "move_to",
|
|
36126
|
-
description: "
|
|
36108
|
+
description: "Moves the mouse cursor to the specified screen coordinates.",
|
|
36127
36109
|
parameters: {
|
|
36128
36110
|
type: "object",
|
|
36129
36111
|
properties: {
|
|
36130
36112
|
x: {
|
|
36131
36113
|
type: "number",
|
|
36132
|
-
description: "X coordinate",
|
|
36114
|
+
description: "Absolute X coordinate on the screen",
|
|
36133
36115
|
},
|
|
36134
36116
|
y: {
|
|
36135
36117
|
type: "number",
|
|
36136
|
-
description: "Y coordinate",
|
|
36118
|
+
description: "Absolute Y coordinate on the screen",
|
|
36137
36119
|
},
|
|
36138
36120
|
},
|
|
36139
36121
|
required: ["x", "y"],
|
|
@@ -36144,7 +36126,7 @@ This is a computer GUI interface, observe the execution through screenshots, and
|
|
|
36144
36126
|
},
|
|
36145
36127
|
{
|
|
36146
36128
|
name: "scroll",
|
|
36147
|
-
description: "Scroll the mouse wheel at current
|
|
36129
|
+
description: "Scroll the mouse wheel vertically at the current pointer location.",
|
|
36148
36130
|
parameters: {
|
|
36149
36131
|
type: "object",
|
|
36150
36132
|
properties: {
|
|
@@ -36170,13 +36152,13 @@ This is a computer GUI interface, observe the execution through screenshots, and
|
|
|
36170
36152
|
},
|
|
36171
36153
|
{
|
|
36172
36154
|
name: "press",
|
|
36173
|
-
description: "
|
|
36155
|
+
description: "Simulate pressing and releasing a specific keyboard key",
|
|
36174
36156
|
parameters: {
|
|
36175
36157
|
type: "object",
|
|
36176
36158
|
properties: {
|
|
36177
36159
|
key: {
|
|
36178
36160
|
type: "string",
|
|
36179
|
-
description: "
|
|
36161
|
+
description: "The keyboard key",
|
|
36180
36162
|
enum: keyboardKeys,
|
|
36181
36163
|
},
|
|
36182
36164
|
},
|
|
@@ -36188,13 +36170,13 @@ This is a computer GUI interface, observe the execution through screenshots, and
|
|
|
36188
36170
|
},
|
|
36189
36171
|
{
|
|
36190
36172
|
name: "hotkey",
|
|
36191
|
-
description: "
|
|
36173
|
+
description: "Simulate pressing one or more keyboard keys, including combinations.",
|
|
36192
36174
|
parameters: {
|
|
36193
36175
|
type: "object",
|
|
36194
36176
|
properties: {
|
|
36195
36177
|
keys: {
|
|
36196
36178
|
type: "string",
|
|
36197
|
-
description: "
|
|
36179
|
+
description: "A single key or a combination of keys to press. For combinations, use '+' to join keys.",
|
|
36198
36180
|
enum: keyboardKeys,
|
|
36199
36181
|
},
|
|
36200
36182
|
},
|
|
@@ -36206,25 +36188,25 @@ This is a computer GUI interface, observe the execution through screenshots, and
|
|
|
36206
36188
|
},
|
|
36207
36189
|
{
|
|
36208
36190
|
name: "drag_and_drop",
|
|
36209
|
-
description: "
|
|
36191
|
+
description: "Performs a mouse drag-and-drop operation from a starting point to a target point on the screen.",
|
|
36210
36192
|
parameters: {
|
|
36211
36193
|
type: "object",
|
|
36212
36194
|
properties: {
|
|
36213
36195
|
x1: {
|
|
36214
36196
|
type: "number",
|
|
36215
|
-
description: "
|
|
36197
|
+
description: "Absolute X coordinate of the starting point (in pixels).",
|
|
36216
36198
|
},
|
|
36217
36199
|
y1: {
|
|
36218
36200
|
type: "number",
|
|
36219
|
-
description: "
|
|
36201
|
+
description: "Absolute Y coordinate of the starting point (in pixels).",
|
|
36220
36202
|
},
|
|
36221
36203
|
x2: {
|
|
36222
36204
|
type: "number",
|
|
36223
|
-
description: "
|
|
36205
|
+
description: "Absolute X coordinate of the ending (target) point (in pixels).",
|
|
36224
36206
|
},
|
|
36225
36207
|
y2: {
|
|
36226
36208
|
type: "number",
|
|
36227
|
-
description: "
|
|
36209
|
+
description: "Absolute Y coordinate of the ending (target) point (in pixels).",
|
|
36228
36210
|
},
|
|
36229
36211
|
},
|
|
36230
36212
|
required: ["x1", "y1", "x2", "y2"],
|
|
@@ -36236,13 +36218,13 @@ This is a computer GUI interface, observe the execution through screenshots, and
|
|
|
36236
36218
|
{
|
|
36237
36219
|
name: "wait",
|
|
36238
36220
|
noPlan: true,
|
|
36239
|
-
description: "Wait for specified duration",
|
|
36221
|
+
description: "Wait/pause execution for a specified duration. Use this tool when you need to wait for data loading, or introduce delays between operations.",
|
|
36240
36222
|
parameters: {
|
|
36241
36223
|
type: "object",
|
|
36242
36224
|
properties: {
|
|
36243
36225
|
duration: {
|
|
36244
36226
|
type: "number",
|
|
36245
|
-
description: "
|
|
36227
|
+
description: "Wait duration in milliseconds",
|
|
36246
36228
|
default: 500,
|
|
36247
36229
|
minimum: 200,
|
|
36248
36230
|
maximum: 10000,
|
|
@@ -37212,6 +37194,8 @@ class BaseBrowserLabelsAgent extends BaseBrowserAgent {
|
|
|
37212
37194
|
* BROWSER OPERATION:
|
|
37213
37195
|
- 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
|
|
37214
37196
|
- 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
|
|
37197
|
+
* Parallelism:
|
|
37198
|
+
- When operating multiple independent steps, they should be executed in parallel as much as possible. For example, when filling out multiple form fields, they should be filled in parallel as much as possible to improve efficiency, rather than operating step by step.
|
|
37215
37199
|
* During execution, please output user-friendly step information. Do not output HTML-related element and index information to users, as this would cause user confusion.
|
|
37216
37200
|
`;
|
|
37217
37201
|
const _tools_ = [];
|
|
@@ -37331,13 +37315,13 @@ class BaseBrowserLabelsAgent extends BaseBrowserAgent {
|
|
|
37331
37315
|
return [
|
|
37332
37316
|
{
|
|
37333
37317
|
name: "navigate_to",
|
|
37334
|
-
description: "Navigate to a specific
|
|
37318
|
+
description: "Navigate to a specific URL in the browser. Use this tool when you need to visit a webpage or change the current page location.",
|
|
37335
37319
|
parameters: {
|
|
37336
37320
|
type: "object",
|
|
37337
37321
|
properties: {
|
|
37338
37322
|
url: {
|
|
37339
37323
|
type: "string",
|
|
37340
|
-
description: "The
|
|
37324
|
+
description: "The complete URL to navigate to",
|
|
37341
37325
|
},
|
|
37342
37326
|
},
|
|
37343
37327
|
required: ["url"],
|
|
@@ -37348,7 +37332,7 @@ class BaseBrowserLabelsAgent extends BaseBrowserAgent {
|
|
|
37348
37332
|
},
|
|
37349
37333
|
{
|
|
37350
37334
|
name: "current_page",
|
|
37351
|
-
description: "Get the
|
|
37335
|
+
description: "Get the currently active webpage information, return tabId, URL and title",
|
|
37352
37336
|
parameters: {
|
|
37353
37337
|
type: "object",
|
|
37354
37338
|
properties: {},
|
|
@@ -37359,7 +37343,7 @@ class BaseBrowserLabelsAgent extends BaseBrowserAgent {
|
|
|
37359
37343
|
},
|
|
37360
37344
|
{
|
|
37361
37345
|
name: "go_back",
|
|
37362
|
-
description: "
|
|
37346
|
+
description: "Go back to the previous page in browser history",
|
|
37363
37347
|
parameters: {
|
|
37364
37348
|
type: "object",
|
|
37365
37349
|
properties: {},
|
|
@@ -37370,7 +37354,7 @@ class BaseBrowserLabelsAgent extends BaseBrowserAgent {
|
|
|
37370
37354
|
},
|
|
37371
37355
|
{
|
|
37372
37356
|
name: "input_text",
|
|
37373
|
-
description: "
|
|
37357
|
+
description: "Inputs text into a element by first clicking to focus the element, then clearing any existing text and typing the new text. Optionally presses Enter after input completion.",
|
|
37374
37358
|
parameters: {
|
|
37375
37359
|
type: "object",
|
|
37376
37360
|
properties: {
|
|
@@ -37453,7 +37437,7 @@ class BaseBrowserLabelsAgent extends BaseBrowserAgent {
|
|
|
37453
37437
|
},
|
|
37454
37438
|
{
|
|
37455
37439
|
name: "hover_to_element",
|
|
37456
|
-
description: "
|
|
37440
|
+
description: "Hover the mouse over an element, use it when you need to hover to display more interactive information",
|
|
37457
37441
|
parameters: {
|
|
37458
37442
|
type: "object",
|
|
37459
37443
|
properties: {
|
|
@@ -37470,7 +37454,7 @@ class BaseBrowserLabelsAgent extends BaseBrowserAgent {
|
|
|
37470
37454
|
},
|
|
37471
37455
|
{
|
|
37472
37456
|
name: "extract_page_content",
|
|
37473
|
-
description: "
|
|
37457
|
+
description: "Extracts all content from the current webpage, including text and image links. Please use this tool when you need to retrieve webpage content.",
|
|
37474
37458
|
parameters: {
|
|
37475
37459
|
type: "object",
|
|
37476
37460
|
properties: {},
|
|
@@ -37519,7 +37503,7 @@ class BaseBrowserLabelsAgent extends BaseBrowserAgent {
|
|
|
37519
37503
|
},
|
|
37520
37504
|
{
|
|
37521
37505
|
name: "get_all_tabs",
|
|
37522
|
-
description: "Get all tabs of the current browser",
|
|
37506
|
+
description: "Get all tabs of the current browser, returns the tabId, URL, and title of all tab pages",
|
|
37523
37507
|
parameters: {
|
|
37524
37508
|
type: "object",
|
|
37525
37509
|
properties: {},
|
|
@@ -37530,7 +37514,7 @@ class BaseBrowserLabelsAgent extends BaseBrowserAgent {
|
|
|
37530
37514
|
},
|
|
37531
37515
|
{
|
|
37532
37516
|
name: "switch_tab",
|
|
37533
|
-
description: "Switch to the specified tab
|
|
37517
|
+
description: "Switch to the specified tab (based on tabId)",
|
|
37534
37518
|
parameters: {
|
|
37535
37519
|
type: "object",
|
|
37536
37520
|
properties: {
|
|
@@ -37548,13 +37532,13 @@ class BaseBrowserLabelsAgent extends BaseBrowserAgent {
|
|
|
37548
37532
|
{
|
|
37549
37533
|
name: "wait",
|
|
37550
37534
|
noPlan: true,
|
|
37551
|
-
description: "Wait for specified duration",
|
|
37535
|
+
description: "Wait/pause execution for a specified duration. Use this tool when you need to wait for data loading, page rendering, or introduce delays between operations.",
|
|
37552
37536
|
parameters: {
|
|
37553
37537
|
type: "object",
|
|
37554
37538
|
properties: {
|
|
37555
37539
|
duration: {
|
|
37556
37540
|
type: "number",
|
|
37557
|
-
description: "
|
|
37541
|
+
description: "Wait duration in milliseconds",
|
|
37558
37542
|
default: 500,
|
|
37559
37543
|
minimum: 200,
|
|
37560
37544
|
maximum: 10000,
|