@eko-ai/eko 3.0.4 → 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/config/index.d.ts +1 -0
- package/dist/config/index.d.ts.map +1 -1
- package/dist/index.cjs.js +75 -58
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.esm.js +75 -58
- package/dist/index.esm.js.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 { Tool, IMcpClient, LLMRequest,
|
|
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,EAAE,CAAC;IAChB,SAAS,CAAC,EAAE,UAAU,CAAC;IACvB,eAAe,CAAC,EAAE,MAAM,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AG,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"}
|
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
|
};
|
|
@@ -35434,8 +35435,8 @@ class Agent {
|
|
|
35434
35435
|
this.requestHandler = params.requestHandler;
|
|
35435
35436
|
}
|
|
35436
35437
|
async run(context, agentChain) {
|
|
35437
|
-
|
|
35438
|
-
|
|
35438
|
+
const mcpClient = this.mcpClient || context.config.defaultMcpClient;
|
|
35439
|
+
const agentContext = new AgentContext(context, this, agentChain);
|
|
35439
35440
|
try {
|
|
35440
35441
|
this.agentContext = agentContext;
|
|
35441
35442
|
mcpClient &&
|
|
@@ -35510,67 +35511,28 @@ class Agent {
|
|
|
35510
35511
|
return "Unfinished";
|
|
35511
35512
|
}
|
|
35512
35513
|
async handleCallResult(agentContext, messages, agentTools, results) {
|
|
35513
|
-
|
|
35514
|
-
|
|
35515
|
-
let user_messages = [];
|
|
35516
|
-
let toolResults = [];
|
|
35514
|
+
const user_messages = [];
|
|
35515
|
+
const toolResults = [];
|
|
35517
35516
|
// results = memory.removeDuplicateToolUse(results);
|
|
35518
35517
|
if (results.length == 0) {
|
|
35519
35518
|
return null;
|
|
35520
35519
|
}
|
|
35521
|
-
|
|
35522
|
-
|
|
35523
|
-
|
|
35524
|
-
|
|
35525
|
-
|
|
35526
|
-
|
|
35527
|
-
let
|
|
35528
|
-
|
|
35529
|
-
agentContext.agentChain.push(toolChain);
|
|
35530
|
-
try {
|
|
35531
|
-
let args = typeof result.input == "string"
|
|
35532
|
-
? JSON.parse(result.input || "{}")
|
|
35533
|
-
: result.input || {};
|
|
35534
|
-
toolChain.params = args;
|
|
35535
|
-
let tool = getTool(agentTools, result.toolName);
|
|
35536
|
-
if (!tool) {
|
|
35537
|
-
throw new Error(result.toolName + " tool does not exist");
|
|
35538
|
-
}
|
|
35539
|
-
toolResult = await tool.execute(args, agentContext, result);
|
|
35540
|
-
toolChain.updateToolResult(toolResult);
|
|
35541
|
-
agentContext.consecutiveErrorNum = 0;
|
|
35542
|
-
}
|
|
35543
|
-
catch (e) {
|
|
35544
|
-
Log.error("tool call error: ", result.toolName, result.input, e);
|
|
35545
|
-
toolResult = {
|
|
35546
|
-
content: [
|
|
35547
|
-
{
|
|
35548
|
-
type: "text",
|
|
35549
|
-
text: e + "",
|
|
35550
|
-
},
|
|
35551
|
-
],
|
|
35552
|
-
isError: true,
|
|
35553
|
-
};
|
|
35554
|
-
toolChain.updateToolResult(toolResult);
|
|
35555
|
-
if (++agentContext.consecutiveErrorNum >= 10) {
|
|
35556
|
-
throw e;
|
|
35557
|
-
}
|
|
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]);
|
|
35558
35528
|
}
|
|
35559
|
-
|
|
35560
|
-
|
|
35561
|
-
|
|
35562
|
-
|
|
35563
|
-
|
|
35564
|
-
|
|
35565
|
-
type: "tool_result",
|
|
35566
|
-
toolId: result.toolCallId,
|
|
35567
|
-
toolName: result.toolName,
|
|
35568
|
-
params: result.input || {},
|
|
35569
|
-
toolResult: toolResult,
|
|
35570
|
-
}, 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);
|
|
35571
35535
|
}
|
|
35572
|
-
const llmToolResult = convertToolResult(result, toolResult, user_messages);
|
|
35573
|
-
toolResults.push(llmToolResult);
|
|
35574
35536
|
}
|
|
35575
35537
|
messages.push({
|
|
35576
35538
|
role: "assistant",
|
|
@@ -35585,9 +35547,61 @@ class Agent {
|
|
|
35585
35547
|
return null;
|
|
35586
35548
|
}
|
|
35587
35549
|
else {
|
|
35588
|
-
return
|
|
35550
|
+
return results
|
|
35551
|
+
.filter((s) => s.type == "text")
|
|
35552
|
+
.map((s) => s.text)
|
|
35553
|
+
.join("\n\n");
|
|
35589
35554
|
}
|
|
35590
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
|
+
}
|
|
35591
35605
|
system_auto_tools(agentNode) {
|
|
35592
35606
|
let tools = [];
|
|
35593
35607
|
let agentNodeXml = agentNode.xml;
|
|
@@ -35706,6 +35720,9 @@ class Agent {
|
|
|
35706
35720
|
this.agentContext?.variables.clear();
|
|
35707
35721
|
}
|
|
35708
35722
|
}
|
|
35723
|
+
canParallelToolCalls(toolCalls) {
|
|
35724
|
+
return config$1.parallelToolCalls;
|
|
35725
|
+
}
|
|
35709
35726
|
get Llms() {
|
|
35710
35727
|
return this.llms;
|
|
35711
35728
|
}
|