@aigne/core 1.11.0 → 1.13.0
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/CHANGELOG.md +28 -0
- package/README.md +11 -10
- package/README.zh.md +7 -6
- package/lib/cjs/agents/agent.d.ts +20 -20
- package/lib/cjs/agents/agent.js +25 -26
- package/lib/cjs/agents/ai-agent.d.ts +17 -18
- package/lib/cjs/agents/ai-agent.js +6 -6
- package/lib/cjs/agents/mcp-agent.d.ts +10 -4
- package/lib/cjs/agents/mcp-agent.js +12 -6
- package/lib/cjs/agents/memory.d.ts +1 -1
- package/lib/cjs/agents/team-agent.d.ts +28 -0
- package/lib/cjs/agents/team-agent.js +93 -0
- package/lib/cjs/agents/user-agent.d.ts +9 -10
- package/lib/cjs/agents/user-agent.js +10 -13
- package/lib/{esm/execution-engine/execution-engine.d.ts → cjs/aigne/aigne.d.ts} +9 -12
- package/lib/cjs/{execution-engine/execution-engine.js → aigne/aigne.js} +19 -19
- package/lib/cjs/{execution-engine → aigne}/context.d.ts +31 -32
- package/lib/cjs/{execution-engine → aigne}/context.js +30 -40
- package/lib/cjs/aigne/index.d.ts +4 -0
- package/lib/cjs/{execution-engine → aigne}/index.js +2 -2
- package/lib/cjs/{execution-engine → aigne}/usage.d.ts +1 -1
- package/lib/cjs/client/client.d.ts +19 -0
- package/lib/cjs/client/client.js +49 -0
- package/lib/cjs/index.d.ts +2 -1
- package/lib/cjs/index.js +2 -1
- package/lib/cjs/loader/agent-yaml.d.ts +3 -3
- package/lib/cjs/loader/agent-yaml.js +10 -3
- package/lib/cjs/loader/index.d.ts +9 -9
- package/lib/cjs/loader/index.js +8 -6
- package/lib/cjs/models/bedrock-chat-model.d.ts +70 -0
- package/lib/cjs/models/bedrock-chat-model.js +273 -0
- package/lib/cjs/models/chat-model.d.ts +2 -1
- package/lib/cjs/models/chat-model.js +8 -0
- package/lib/cjs/models/claude-chat-model.d.ts +3 -3
- package/lib/cjs/models/gemini-chat-model.d.ts +1 -0
- package/lib/cjs/models/gemini-chat-model.js +1 -0
- package/lib/cjs/models/openai-chat-model.d.ts +6 -3
- package/lib/cjs/models/openai-chat-model.js +100 -100
- package/lib/cjs/prompt/prompt-builder.d.ts +1 -1
- package/lib/cjs/prompt/prompt-builder.js +3 -3
- package/lib/cjs/server/error.d.ts +4 -0
- package/lib/cjs/server/error.js +11 -0
- package/lib/cjs/server/server.d.ts +54 -0
- package/lib/cjs/server/server.js +130 -0
- package/lib/cjs/utils/event-stream.d.ts +11 -0
- package/lib/cjs/utils/event-stream.js +91 -0
- package/lib/cjs/utils/mcp-utils.js +4 -1
- package/lib/cjs/utils/prompts.js +1 -1
- package/lib/cjs/utils/stream-utils.d.ts +7 -2
- package/lib/cjs/utils/stream-utils.js +43 -34
- package/lib/cjs/utils/type-utils.d.ts +5 -2
- package/lib/cjs/utils/type-utils.js +22 -2
- package/lib/dts/agents/agent.d.ts +20 -20
- package/lib/dts/agents/ai-agent.d.ts +17 -18
- package/lib/dts/agents/mcp-agent.d.ts +10 -4
- package/lib/dts/agents/memory.d.ts +1 -1
- package/lib/dts/agents/team-agent.d.ts +28 -0
- package/lib/dts/agents/user-agent.d.ts +9 -10
- package/lib/dts/{execution-engine/execution-engine.d.ts → aigne/aigne.d.ts} +9 -12
- package/lib/dts/{execution-engine → aigne}/context.d.ts +31 -32
- package/lib/dts/aigne/index.d.ts +4 -0
- package/lib/dts/{execution-engine → aigne}/usage.d.ts +1 -1
- package/lib/dts/client/client.d.ts +19 -0
- package/lib/dts/index.d.ts +2 -1
- package/lib/dts/loader/agent-yaml.d.ts +3 -3
- package/lib/dts/loader/index.d.ts +9 -9
- package/lib/dts/models/bedrock-chat-model.d.ts +70 -0
- package/lib/dts/models/chat-model.d.ts +2 -1
- package/lib/dts/models/claude-chat-model.d.ts +3 -3
- package/lib/dts/models/gemini-chat-model.d.ts +1 -0
- package/lib/dts/models/openai-chat-model.d.ts +6 -3
- package/lib/dts/prompt/prompt-builder.d.ts +1 -1
- package/lib/dts/server/error.d.ts +4 -0
- package/lib/dts/server/server.d.ts +54 -0
- package/lib/dts/utils/event-stream.d.ts +11 -0
- package/lib/dts/utils/stream-utils.d.ts +7 -2
- package/lib/dts/utils/type-utils.d.ts +5 -2
- package/lib/esm/agents/agent.d.ts +20 -20
- package/lib/esm/agents/agent.js +25 -26
- package/lib/esm/agents/ai-agent.d.ts +17 -18
- package/lib/esm/agents/ai-agent.js +6 -6
- package/lib/esm/agents/mcp-agent.d.ts +10 -4
- package/lib/esm/agents/mcp-agent.js +12 -6
- package/lib/esm/agents/memory.d.ts +1 -1
- package/lib/esm/agents/team-agent.d.ts +28 -0
- package/lib/esm/agents/team-agent.js +89 -0
- package/lib/esm/agents/user-agent.d.ts +9 -10
- package/lib/esm/agents/user-agent.js +11 -14
- package/lib/{cjs/execution-engine/execution-engine.d.ts → esm/aigne/aigne.d.ts} +9 -12
- package/lib/esm/{execution-engine/execution-engine.js → aigne/aigne.js} +18 -18
- package/lib/esm/{execution-engine → aigne}/context.d.ts +31 -32
- package/lib/esm/{execution-engine → aigne}/context.js +28 -38
- package/lib/esm/aigne/index.d.ts +4 -0
- package/lib/esm/aigne/index.js +4 -0
- package/lib/esm/{execution-engine → aigne}/usage.d.ts +1 -1
- package/lib/esm/client/client.d.ts +19 -0
- package/lib/esm/client/client.js +45 -0
- package/lib/esm/index.d.ts +2 -1
- package/lib/esm/index.js +2 -1
- package/lib/esm/loader/agent-yaml.d.ts +3 -3
- package/lib/esm/loader/agent-yaml.js +10 -3
- package/lib/esm/loader/index.d.ts +9 -9
- package/lib/esm/loader/index.js +8 -6
- package/lib/esm/models/bedrock-chat-model.d.ts +70 -0
- package/lib/esm/models/bedrock-chat-model.js +268 -0
- package/lib/esm/models/chat-model.d.ts +2 -1
- package/lib/esm/models/chat-model.js +8 -0
- package/lib/esm/models/claude-chat-model.d.ts +3 -3
- package/lib/esm/models/gemini-chat-model.d.ts +1 -0
- package/lib/esm/models/gemini-chat-model.js +1 -0
- package/lib/esm/models/openai-chat-model.d.ts +6 -3
- package/lib/esm/models/openai-chat-model.js +100 -100
- package/lib/esm/prompt/prompt-builder.d.ts +1 -1
- package/lib/esm/prompt/prompt-builder.js +4 -4
- package/lib/esm/server/error.d.ts +4 -0
- package/lib/esm/server/error.js +7 -0
- package/lib/esm/server/server.d.ts +54 -0
- package/lib/esm/server/server.js +123 -0
- package/lib/esm/utils/event-stream.d.ts +11 -0
- package/lib/esm/utils/event-stream.js +85 -0
- package/lib/esm/utils/mcp-utils.js +4 -1
- package/lib/esm/utils/prompts.js +1 -1
- package/lib/esm/utils/stream-utils.d.ts +7 -2
- package/lib/esm/utils/stream-utils.js +42 -33
- package/lib/esm/utils/type-utils.d.ts +5 -2
- package/lib/esm/utils/type-utils.js +20 -2
- package/package.json +20 -4
- package/lib/cjs/execution-engine/index.d.ts +0 -4
- package/lib/cjs/execution-engine/utils.d.ts +0 -4
- package/lib/cjs/execution-engine/utils.js +0 -34
- package/lib/dts/execution-engine/index.d.ts +0 -4
- package/lib/dts/execution-engine/utils.d.ts +0 -4
- package/lib/esm/execution-engine/index.d.ts +0 -4
- package/lib/esm/execution-engine/index.js +0 -4
- package/lib/esm/execution-engine/utils.d.ts +0 -4
- package/lib/esm/execution-engine/utils.js +0 -30
- /package/lib/cjs/{execution-engine → aigne}/message-queue.d.ts +0 -0
- /package/lib/cjs/{execution-engine → aigne}/message-queue.js +0 -0
- /package/lib/cjs/{execution-engine → aigne}/usage.js +0 -0
- /package/lib/dts/{execution-engine → aigne}/message-queue.d.ts +0 -0
- /package/lib/esm/{execution-engine → aigne}/message-queue.d.ts +0 -0
- /package/lib/esm/{execution-engine → aigne}/message-queue.js +0 -0
- /package/lib/esm/{execution-engine → aigne}/usage.js +0 -0
package/CHANGELOG.md
CHANGED
|
@@ -22,6 +22,34 @@
|
|
|
22
22
|
* rename @aigne/core-next to @aigne/core ([3a81009](https://github.com/AIGNE-io/aigne-framework/commit/3a8100962c81813217b687ae28e8de604419c622))
|
|
23
23
|
* use text resource from MCP correctly ([8b9eba8](https://github.com/AIGNE-io/aigne-framework/commit/8b9eba83352ec096a2a5d4f410d4c4bde7420bce))
|
|
24
24
|
|
|
25
|
+
## [1.13.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.12.0...core-v1.13.0) (2025-04-30)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Features
|
|
29
|
+
|
|
30
|
+
* **core:** add BedrockChatModel support ([#101](https://github.com/AIGNE-io/aigne-framework/issues/101)) ([a0b98f0](https://github.com/AIGNE-io/aigne-framework/commit/a0b98f01bd78a135232226548848fa35a64982d1))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
### Bug Fixes
|
|
34
|
+
|
|
35
|
+
* **core:** deduplicate tools for chat model ([#103](https://github.com/AIGNE-io/aigne-framework/issues/103)) ([570be6d](https://github.com/AIGNE-io/aigne-framework/commit/570be6d8620ab5b9a0149f835ecd4641009a8654))
|
|
36
|
+
* export server/client api types ([93e5341](https://github.com/AIGNE-io/aigne-framework/commit/93e5341dde7a6851f08a3d4e2f6c1a1db91765e9))
|
|
37
|
+
|
|
38
|
+
## [1.12.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.11.0...core-v1.12.0) (2025-04-27)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
### Features
|
|
42
|
+
|
|
43
|
+
* add AIGNEServer/AIGNEClient api to serve agents via network ([#96](https://github.com/AIGNE-io/aigne-framework/issues/96)) ([1f2dfa3](https://github.com/AIGNE-io/aigne-framework/commit/1f2dfa3a6a2568373063cea3c874b573d0a248d3))
|
|
44
|
+
* **core:** support streamable http transport for mcp agents ([#92](https://github.com/AIGNE-io/aigne-framework/issues/92)) ([37da490](https://github.com/AIGNE-io/aigne-framework/commit/37da490538298d882ec328e4b3304395a6cd8cf7))
|
|
45
|
+
* support TeamAgent and finalize API naming ([#91](https://github.com/AIGNE-io/aigne-framework/issues/91)) ([033d1b6](https://github.com/AIGNE-io/aigne-framework/commit/033d1b6a7dc5460807476abb35a413ba89a2a664))
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
### Bug Fixes
|
|
49
|
+
|
|
50
|
+
* **core:** prioritize self model before falling back to context ([#97](https://github.com/AIGNE-io/aigne-framework/issues/97)) ([2a3d067](https://github.com/AIGNE-io/aigne-framework/commit/2a3d067442200657d8ef3b5314930cc14302f6bf))
|
|
51
|
+
* upgrade to streamable api for serve mcp command ([#98](https://github.com/AIGNE-io/aigne-framework/issues/98)) ([ae32bda](https://github.com/AIGNE-io/aigne-framework/commit/ae32bda20e57c2a2eb8b49fad034b0b2a5ebb15e))
|
|
52
|
+
|
|
25
53
|
## [1.11.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.10.0...core-v1.11.0) (2025-04-23)
|
|
26
54
|
|
|
27
55
|
|
package/README.md
CHANGED
|
@@ -12,13 +12,13 @@ Core library of [AIGNE Framework](https://github.com/AIGNE-io/aigne-framework) f
|
|
|
12
12
|
|
|
13
13
|
## Introduction
|
|
14
14
|
|
|
15
|
-
`@aigne/core` is the foundation component of [AIGNE Framework](https://github.com/AIGNE-io/aigne-framework), providing the essential modules and tools needed to build AI-driven applications. This package implements the core functionalities of the framework, including agent systems,
|
|
15
|
+
`@aigne/core` is the foundation component of [AIGNE Framework](https://github.com/AIGNE-io/aigne-framework), providing the essential modules and tools needed to build AI-driven applications. This package implements the core functionalities of the framework, including agent systems, aigne environment, model integrations, and workflow pattern support.
|
|
16
16
|
|
|
17
17
|
## Features
|
|
18
18
|
|
|
19
19
|
- **Multiple AI Model Support**: Built-in support for OpenAI, Gemini, Claude, and other mainstream AI models, easily extensible to support additional models
|
|
20
20
|
- **Agent System**: Powerful agent abstractions supporting AI agents, function agents, MCP agents, and more
|
|
21
|
-
- **
|
|
21
|
+
- **AIGNE Environment**: Flexible handling communication between agents and workflow execution
|
|
22
22
|
- **Workflow Patterns**: Support for sequential, concurrent, routing, handoff, and other workflow patterns
|
|
23
23
|
- **MCP Protocol Integration**: Seamless integration with external systems through the Model Context Protocol
|
|
24
24
|
- **TypeScript Support**: Comprehensive type definitions providing an excellent development experience
|
|
@@ -39,7 +39,7 @@ pnpm add @aigne/core
|
|
|
39
39
|
## Basic Usage
|
|
40
40
|
|
|
41
41
|
```typescript
|
|
42
|
-
import { AIAgent,
|
|
42
|
+
import { AIAgent, AIGNE } from "@aigne/core";
|
|
43
43
|
import { OpenAIChatModel } from "@aigne/core/models/openai-chat-model.js";
|
|
44
44
|
|
|
45
45
|
// Create AI model instance
|
|
@@ -54,21 +54,21 @@ const agent = AIAgent.from({
|
|
|
54
54
|
instructions: "You are a helpful assistant.",
|
|
55
55
|
});
|
|
56
56
|
|
|
57
|
-
// Create
|
|
58
|
-
const
|
|
57
|
+
// Create AIGNE
|
|
58
|
+
const aigne = new AIGNE({ model });
|
|
59
59
|
|
|
60
|
-
// Use the
|
|
61
|
-
const userAgent = await
|
|
60
|
+
// Use the AIGNE to invoke the agent
|
|
61
|
+
const userAgent = await aigne.invoke(agent);
|
|
62
62
|
|
|
63
63
|
// Send a message to the agent
|
|
64
|
-
const response = await userAgent.
|
|
64
|
+
const response = await userAgent.invoke("Hello, can you help me write a short article?");
|
|
65
65
|
console.log(response);
|
|
66
66
|
```
|
|
67
67
|
|
|
68
68
|
## Module Structure
|
|
69
69
|
|
|
70
70
|
- `agents/`: Agent implementations, including AI agents, function agents, MCP agents, etc.
|
|
71
|
-
- `
|
|
71
|
+
- `aigne/`: AIGNE is agents execution environment
|
|
72
72
|
- `loader/`: Loader-related functionality
|
|
73
73
|
- `models/`: Integration with various AI models
|
|
74
74
|
- `prompt/`: Prompt handling functionality
|
|
@@ -82,7 +82,8 @@ For more detailed API documentation, please refer to:
|
|
|
82
82
|
- [AI Agent API](../../docs/apis/ai-agent-api.md)
|
|
83
83
|
- [Function Agent API](../../docs/apis/function-agent-api.md)
|
|
84
84
|
- [MCP Agent API](../../docs/apis/mcp-agent-api.md)
|
|
85
|
-
- [
|
|
85
|
+
- [AIGNE API](../../docs/apis/aigne-api.md)
|
|
86
|
+
- [Server/Client API](../../docs/apis/server-client-api.md)
|
|
86
87
|
|
|
87
88
|
## License
|
|
88
89
|
|
package/README.zh.md
CHANGED
|
@@ -39,7 +39,7 @@ pnpm add @aigne/core
|
|
|
39
39
|
## 基本用法
|
|
40
40
|
|
|
41
41
|
```typescript
|
|
42
|
-
import { AIAgent,
|
|
42
|
+
import { AIAgent, AIGNE } from "@aigne/core";
|
|
43
43
|
import { OpenAIChatModel } from "@aigne/core/models/openai-chat-model.js";
|
|
44
44
|
|
|
45
45
|
// 创建 AI 模型实例
|
|
@@ -55,20 +55,20 @@ const agent = AIAgent.from({
|
|
|
55
55
|
});
|
|
56
56
|
|
|
57
57
|
// 创建执行引擎
|
|
58
|
-
const
|
|
58
|
+
const aigne = new AIGNE({ model });
|
|
59
59
|
|
|
60
60
|
// 使用执行引擎调用代理
|
|
61
|
-
const userAgent = await
|
|
61
|
+
const userAgent = await aigne.invoke(agent);
|
|
62
62
|
|
|
63
63
|
// 向代理发送消息
|
|
64
|
-
const response = await userAgent.
|
|
64
|
+
const response = await userAgent.invoke("你好,能帮我写一篇短文吗?");
|
|
65
65
|
console.log(response);
|
|
66
66
|
```
|
|
67
67
|
|
|
68
68
|
## 模块结构
|
|
69
69
|
|
|
70
70
|
- `agents/`: 代理相关的实现,包括 AI 代理、函数代理、MCP 代理等
|
|
71
|
-
- `
|
|
71
|
+
- `aigne/`: AIGNE 提供 Agents 执行环境
|
|
72
72
|
- `loader/`: 加载器相关功能
|
|
73
73
|
- `models/`: 各种 AI 模型的集成
|
|
74
74
|
- `prompt/`: 提示词处理相关功能
|
|
@@ -82,7 +82,8 @@ console.log(response);
|
|
|
82
82
|
- [AI Agent API](../../docs/apis/ai-agent-api.zh.md)
|
|
83
83
|
- [Function Agent API](../../docs/apis/function-agent-api.zh.md)
|
|
84
84
|
- [MCP Agent API](../../docs/apis/mcp-agent-api.zh.md)
|
|
85
|
-
- [
|
|
85
|
+
- [AIGNE API](../../docs/apis/aigne-api.zh.md)
|
|
86
|
+
- [服务器/客户端 API](../../docs/apis/server-client-api.zh.md)
|
|
86
87
|
|
|
87
88
|
## 协议
|
|
88
89
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { inspect } from "node:util";
|
|
2
2
|
import { type ZodType } from "zod";
|
|
3
|
-
import type { Context } from "../
|
|
3
|
+
import type { Context } from "../aigne/context.js";
|
|
4
4
|
import { type Nullish, type PromiseOrValue } from "../utils/type-utils.js";
|
|
5
5
|
import { AgentMemory, type AgentMemoryOptions } from "./memory.js";
|
|
6
6
|
import { type TransferAgentOutput } from "./types.js";
|
|
@@ -15,11 +15,11 @@ export interface AgentOptions<I extends Message = Message, O extends Message = M
|
|
|
15
15
|
inputSchema?: AgentInputOutputSchema<I>;
|
|
16
16
|
outputSchema?: AgentInputOutputSchema<O>;
|
|
17
17
|
includeInputInOutput?: boolean;
|
|
18
|
-
|
|
18
|
+
skills?: (Agent | FunctionAgentFn)[];
|
|
19
19
|
disableEvents?: boolean;
|
|
20
20
|
memory?: AgentMemory | AgentMemoryOptions | true;
|
|
21
21
|
}
|
|
22
|
-
export interface
|
|
22
|
+
export interface AgentInvokeOptions {
|
|
23
23
|
streaming?: boolean;
|
|
24
24
|
}
|
|
25
25
|
export declare abstract class Agent<I extends Message = Message, O extends Message = Message> {
|
|
@@ -38,38 +38,38 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
|
|
|
38
38
|
readonly includeInputInOutput?: boolean;
|
|
39
39
|
readonly subscribeTopic?: SubscribeTopic;
|
|
40
40
|
readonly publishTopic?: PublishTopic<Message>;
|
|
41
|
-
readonly
|
|
41
|
+
readonly skills: Agent<Message, Message>[] & {
|
|
42
42
|
[key: string]: Agent<Message, Message>;
|
|
43
43
|
};
|
|
44
44
|
private disableEvents?;
|
|
45
45
|
/**
|
|
46
46
|
* Attach agent to context:
|
|
47
|
-
* - subscribe to topic and
|
|
47
|
+
* - subscribe to topic and invoke process method when message received
|
|
48
48
|
* - subscribe to memory topic if memory is enabled
|
|
49
49
|
* @param context Context to attach
|
|
50
50
|
*/
|
|
51
51
|
attach(context: Pick<Context, "subscribe">): void;
|
|
52
|
-
|
|
53
|
-
get
|
|
52
|
+
addSkill(...skills: (Agent | FunctionAgentFn)[]): void;
|
|
53
|
+
get isInvokable(): boolean;
|
|
54
54
|
private checkContextStatus;
|
|
55
55
|
private newDefaultContext;
|
|
56
|
-
|
|
56
|
+
invoke(input: I | string, context: Context | undefined, options: AgentInvokeOptions & {
|
|
57
57
|
streaming: true;
|
|
58
58
|
}): Promise<AgentResponseStream<O>>;
|
|
59
|
-
|
|
59
|
+
invoke(input: I | string, context?: Context, options?: AgentInvokeOptions & {
|
|
60
60
|
streaming?: false;
|
|
61
61
|
}): Promise<O>;
|
|
62
|
-
|
|
62
|
+
invoke(input: I | string, context?: Context, options?: AgentInvokeOptions): Promise<AgentResponse<O>>;
|
|
63
63
|
private processAgentOutput;
|
|
64
64
|
private processAgentError;
|
|
65
|
-
protected
|
|
65
|
+
protected checkAgentInvokesUsage(context: Context): void;
|
|
66
66
|
protected preprocess(_: I, context: Context): void;
|
|
67
67
|
protected postprocess(input: I, output: O, context: Context): void;
|
|
68
|
-
abstract process(input: I, context: Context, options?:
|
|
68
|
+
abstract process(input: I, context: Context, options?: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<O>>;
|
|
69
69
|
shutdown(): Promise<void>;
|
|
70
70
|
[inspect.custom](): string;
|
|
71
71
|
}
|
|
72
|
-
export type AgentResponse<T> = T | AgentResponseStream<T>;
|
|
72
|
+
export type AgentResponse<T> = T | TransferAgentOutput | AgentResponseStream<T>;
|
|
73
73
|
export type AgentResponseStream<T> = ReadableStream<AgentResponseChunk<T>>;
|
|
74
74
|
export type AgentResponseChunk<T> = AgentResponseDelta<T>;
|
|
75
75
|
export declare function isEmptyChunk<T>(chunk: AgentResponseChunk<T>): boolean;
|
|
@@ -77,14 +77,14 @@ export interface AgentResponseDelta<T> {
|
|
|
77
77
|
delta: {
|
|
78
78
|
text?: Partial<{
|
|
79
79
|
[key in keyof T as Extract<T[key], string> extends string ? key : never]: string;
|
|
80
|
-
}> | {
|
|
80
|
+
}> | Partial<{
|
|
81
81
|
[key: string]: string;
|
|
82
|
-
}
|
|
83
|
-
json?: Partial<T>;
|
|
82
|
+
}>;
|
|
83
|
+
json?: Partial<T | TransferAgentOutput>;
|
|
84
84
|
};
|
|
85
85
|
}
|
|
86
|
-
export type AgentProcessAsyncGenerator<O extends Message> = AsyncGenerator<AgentResponseChunk<O>, Partial<O> | undefined | void>;
|
|
87
|
-
export type AgentProcessResult<O extends Message> =
|
|
86
|
+
export type AgentProcessAsyncGenerator<O extends Message> = AsyncGenerator<AgentResponseChunk<O>, Partial<O | TransferAgentOutput> | undefined | void>;
|
|
87
|
+
export type AgentProcessResult<O extends Message> = AgentResponse<O> | AgentProcessAsyncGenerator<O> | Agent;
|
|
88
88
|
export type AgentInputOutputSchema<I extends Message = Message> = ZodType<I> | ((agent: Agent) => ZodType<I>);
|
|
89
89
|
export interface FunctionAgentOptions<I extends Message = Message, O extends Message = Message> extends AgentOptions<I, O> {
|
|
90
90
|
fn?: FunctionAgentFn<I, O>;
|
|
@@ -93,6 +93,6 @@ export declare class FunctionAgent<I extends Message = Message, O extends Messag
|
|
|
93
93
|
static from<I extends Message, O extends Message>(options: FunctionAgentOptions<I, O> | FunctionAgentFn<I, O>): FunctionAgent<I, O>;
|
|
94
94
|
constructor(options: FunctionAgentOptions<I, O>);
|
|
95
95
|
fn: FunctionAgentFn<I, O>;
|
|
96
|
-
process(input: I, context: Context
|
|
96
|
+
process(input: I, context: Context): PromiseOrValue<AgentProcessResult<O>>;
|
|
97
97
|
}
|
|
98
|
-
export type FunctionAgentFn<I extends Message =
|
|
98
|
+
export type FunctionAgentFn<I extends Message = any, O extends Message = any> = (input: I, context: Context) => PromiseOrValue<AgentProcessResult<O>>;
|
package/lib/cjs/agents/agent.js
CHANGED
|
@@ -56,8 +56,8 @@ class Agent {
|
|
|
56
56
|
this.includeInputInOutput = options.includeInputInOutput;
|
|
57
57
|
this.subscribeTopic = options.subscribeTopic;
|
|
58
58
|
this.publishTopic = options.publishTopic;
|
|
59
|
-
if (options.
|
|
60
|
-
this.
|
|
59
|
+
if (options.skills?.length)
|
|
60
|
+
this.skills.push(...options.skills.map(functionToAgent));
|
|
61
61
|
this.disableEvents = options.disableEvents;
|
|
62
62
|
if (options.memory) {
|
|
63
63
|
this.memory =
|
|
@@ -94,11 +94,11 @@ class Agent {
|
|
|
94
94
|
includeInputInOutput;
|
|
95
95
|
subscribeTopic;
|
|
96
96
|
publishTopic;
|
|
97
|
-
|
|
97
|
+
skills = (0, type_utils_js_1.createAccessorArray)([], (arr, name) => arr.find((t) => t.name === name));
|
|
98
98
|
disableEvents;
|
|
99
99
|
/**
|
|
100
100
|
* Attach agent to context:
|
|
101
|
-
* - subscribe to topic and
|
|
101
|
+
* - subscribe to topic and invoke process method when message received
|
|
102
102
|
* - subscribe to memory topic if memory is enabled
|
|
103
103
|
* @param context Context to attach
|
|
104
104
|
*/
|
|
@@ -107,7 +107,7 @@ class Agent {
|
|
|
107
107
|
for (const topic of (0, type_utils_js_1.orArrayToArray)(this.subscribeTopic).concat(this.topic)) {
|
|
108
108
|
context.subscribe(topic, async ({ message, context }) => {
|
|
109
109
|
try {
|
|
110
|
-
await context.
|
|
110
|
+
await context.invoke(this, message);
|
|
111
111
|
}
|
|
112
112
|
catch (error) {
|
|
113
113
|
context.emit("agentFailed", { agent: this, error });
|
|
@@ -115,34 +115,37 @@ class Agent {
|
|
|
115
115
|
});
|
|
116
116
|
}
|
|
117
117
|
}
|
|
118
|
-
|
|
119
|
-
this.
|
|
118
|
+
addSkill(...skills) {
|
|
119
|
+
this.skills.push(...skills.map((skill) => (typeof skill === "function" ? functionToAgent(skill) : skill)));
|
|
120
120
|
}
|
|
121
|
-
get
|
|
121
|
+
get isInvokable() {
|
|
122
122
|
return !!this.process;
|
|
123
123
|
}
|
|
124
124
|
checkContextStatus(context) {
|
|
125
125
|
if (context) {
|
|
126
126
|
const { status } = context;
|
|
127
127
|
if (status === "timeout") {
|
|
128
|
-
throw new Error(`
|
|
128
|
+
throw new Error(`AIGNE for agent ${this.name} has timed out`);
|
|
129
129
|
}
|
|
130
130
|
}
|
|
131
131
|
}
|
|
132
132
|
async newDefaultContext() {
|
|
133
|
-
return Promise.resolve().then(() => __importStar(require("../
|
|
133
|
+
return Promise.resolve().then(() => __importStar(require("../aigne/context.js"))).then((m) => new m.AIGNEContext());
|
|
134
134
|
}
|
|
135
|
-
async
|
|
135
|
+
async invoke(input, context, options) {
|
|
136
136
|
const ctx = context ?? (await this.newDefaultContext());
|
|
137
137
|
const message = typeof input === "string" ? (0, prompt_builder_js_1.createMessage)(input) : input;
|
|
138
|
-
logger_js_1.logger.core("
|
|
138
|
+
logger_js_1.logger.core("Invoke agent %s started with input: %O", this.name, input);
|
|
139
139
|
if (!this.disableEvents)
|
|
140
140
|
ctx.emit("agentStarted", { agent: this, input: message });
|
|
141
141
|
try {
|
|
142
142
|
const parsedInput = (0, type_utils_js_1.checkArguments)(`Agent ${this.name} input`, this.inputSchema, message);
|
|
143
143
|
this.preprocess(parsedInput, ctx);
|
|
144
144
|
this.checkContextStatus(ctx);
|
|
145
|
-
|
|
145
|
+
let response = await this.process(parsedInput, ctx, options);
|
|
146
|
+
if (response instanceof Agent) {
|
|
147
|
+
response = (0, types_js_1.transferToAgentOutput)(response);
|
|
148
|
+
}
|
|
146
149
|
if (options?.streaming) {
|
|
147
150
|
const stream = response instanceof ReadableStream
|
|
148
151
|
? response
|
|
@@ -176,27 +179,27 @@ class Agent {
|
|
|
176
179
|
const parsedOutput = (0, type_utils_js_1.checkArguments)(`Agent ${this.name} output`, this.outputSchema, output);
|
|
177
180
|
const finalOutput = this.includeInputInOutput ? { ...input, ...parsedOutput } : parsedOutput;
|
|
178
181
|
this.postprocess(input, finalOutput, context);
|
|
179
|
-
logger_js_1.logger.core("
|
|
182
|
+
logger_js_1.logger.core("Invoke agent %s succeed with output: %O", this.name, finalOutput);
|
|
180
183
|
if (!this.disableEvents)
|
|
181
184
|
context.emit("agentSucceed", { agent: this, output: finalOutput });
|
|
182
185
|
return finalOutput;
|
|
183
186
|
}
|
|
184
187
|
processAgentError(error, context) {
|
|
185
|
-
logger_js_1.logger.core("
|
|
188
|
+
logger_js_1.logger.core("Invoke agent %s failed with error: %O", this.name, error);
|
|
186
189
|
if (!this.disableEvents)
|
|
187
190
|
context.emit("agentFailed", { agent: this, error });
|
|
188
191
|
throw error;
|
|
189
192
|
}
|
|
190
|
-
|
|
193
|
+
checkAgentInvokesUsage(context) {
|
|
191
194
|
const { limits, usage } = context;
|
|
192
|
-
if (limits?.
|
|
193
|
-
throw new Error(`Exceeded max agent
|
|
195
|
+
if (limits?.maxAgentInvokes && usage.agentCalls >= limits.maxAgentInvokes) {
|
|
196
|
+
throw new Error(`Exceeded max agent invokes ${usage.agentCalls}/${limits.maxAgentInvokes}`);
|
|
194
197
|
}
|
|
195
198
|
usage.agentCalls++;
|
|
196
199
|
}
|
|
197
200
|
preprocess(_, context) {
|
|
198
201
|
this.checkContextStatus(context);
|
|
199
|
-
this.
|
|
202
|
+
this.checkAgentInvokesUsage(context);
|
|
200
203
|
}
|
|
201
204
|
postprocess(input, output, context) {
|
|
202
205
|
this.checkContextStatus(context);
|
|
@@ -220,7 +223,7 @@ function isEmptyChunk(chunk) {
|
|
|
220
223
|
}
|
|
221
224
|
function checkAgentInputOutputSchema(schema) {
|
|
222
225
|
if (!(schema instanceof zod_1.ZodObject) && typeof schema !== "function") {
|
|
223
|
-
throw new Error(
|
|
226
|
+
throw new Error(`schema must be a zod object or function return a zod object, got: ${typeof schema}`);
|
|
224
227
|
}
|
|
225
228
|
}
|
|
226
229
|
class FunctionAgent extends Agent {
|
|
@@ -232,12 +235,8 @@ class FunctionAgent extends Agent {
|
|
|
232
235
|
this.fn = options.fn ?? (() => ({}));
|
|
233
236
|
}
|
|
234
237
|
fn;
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
if (result instanceof Agent) {
|
|
238
|
-
result = (0, types_js_1.transferToAgentOutput)(result);
|
|
239
|
-
}
|
|
240
|
-
return options?.streaming ? (0, stream_utils_js_1.objectToAgentResponseStream)(result) : result;
|
|
238
|
+
process(input, context) {
|
|
239
|
+
return this.fn(input, context);
|
|
241
240
|
}
|
|
242
241
|
}
|
|
243
242
|
exports.FunctionAgent = FunctionAgent;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
-
import type { Context } from "../
|
|
2
|
+
import type { Context } from "../aigne/context.js";
|
|
3
3
|
import { ChatModel } from "../models/chat-model.js";
|
|
4
4
|
import type { ChatModelInput } from "../models/chat-model.js";
|
|
5
5
|
import { PromptBuilder } from "../prompt/prompt-builder.js";
|
|
6
6
|
import { Agent, type AgentOptions, type AgentProcessAsyncGenerator, type Message } from "./agent.js";
|
|
7
|
-
import { type TransferAgentOutput } from "./types.js";
|
|
8
7
|
export interface AIAgentOptions<I extends Message = Message, O extends Message = Message> extends AgentOptions<I, O> {
|
|
9
8
|
model?: ChatModel;
|
|
10
9
|
instructions?: string | PromptBuilder;
|
|
@@ -25,39 +24,39 @@ export declare const aiAgentOptionsSchema: z.ZodObject<{
|
|
|
25
24
|
publishTopic: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">, z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>]>>;
|
|
26
25
|
name: z.ZodOptional<z.ZodString>;
|
|
27
26
|
description: z.ZodOptional<z.ZodString>;
|
|
28
|
-
|
|
27
|
+
skills: z.ZodOptional<z.ZodArray<z.ZodUnion<[z.ZodType<Agent<Message, Message>, z.ZodTypeDef, Agent<Message, Message>>, z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>]>, "many">>;
|
|
29
28
|
disableLogging: z.ZodOptional<z.ZodBoolean>;
|
|
30
29
|
memory: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodAny, z.ZodAny]>>;
|
|
31
30
|
}, "strip", z.ZodTypeAny, {
|
|
32
|
-
tools?: (Agent<Message, Message> | ((...args: unknown[]) => unknown))[] | undefined;
|
|
33
|
-
toolChoice?: Agent<Message, Message> | "auto" | "none" | "required" | "router" | undefined;
|
|
34
|
-
name?: string | undefined;
|
|
35
31
|
description?: string | undefined;
|
|
32
|
+
memory?: any;
|
|
33
|
+
name?: string | undefined;
|
|
34
|
+
includeInputInOutput?: boolean | undefined;
|
|
35
|
+
subscribeTopic?: string | string[] | undefined;
|
|
36
|
+
publishTopic?: string | string[] | ((...args: unknown[]) => unknown) | undefined;
|
|
37
|
+
skills?: (Agent<Message, Message> | ((...args: unknown[]) => unknown))[] | undefined;
|
|
38
|
+
toolChoice?: Agent<Message, Message> | "auto" | "none" | "required" | "router" | undefined;
|
|
36
39
|
model?: ChatModel | undefined;
|
|
37
40
|
instructions?: string | PromptBuilder | undefined;
|
|
38
41
|
outputKey?: string | undefined;
|
|
39
42
|
enableHistory?: boolean | undefined;
|
|
40
43
|
maxHistoryMessages?: number | undefined;
|
|
44
|
+
disableLogging?: boolean | undefined;
|
|
45
|
+
}, {
|
|
46
|
+
description?: string | undefined;
|
|
47
|
+
memory?: any;
|
|
48
|
+
name?: string | undefined;
|
|
41
49
|
includeInputInOutput?: boolean | undefined;
|
|
42
50
|
subscribeTopic?: string | string[] | undefined;
|
|
43
51
|
publishTopic?: string | string[] | ((...args: unknown[]) => unknown) | undefined;
|
|
44
|
-
|
|
45
|
-
memory?: any;
|
|
46
|
-
}, {
|
|
47
|
-
tools?: (Agent<Message, Message> | ((...args: unknown[]) => unknown))[] | undefined;
|
|
52
|
+
skills?: (Agent<Message, Message> | ((...args: unknown[]) => unknown))[] | undefined;
|
|
48
53
|
toolChoice?: Agent<Message, Message> | "auto" | "none" | "required" | "router" | undefined;
|
|
49
|
-
name?: string | undefined;
|
|
50
|
-
description?: string | undefined;
|
|
51
54
|
model?: ChatModel | undefined;
|
|
52
55
|
instructions?: string | PromptBuilder | undefined;
|
|
53
56
|
outputKey?: string | undefined;
|
|
54
57
|
enableHistory?: boolean | undefined;
|
|
55
58
|
maxHistoryMessages?: number | undefined;
|
|
56
|
-
includeInputInOutput?: boolean | undefined;
|
|
57
|
-
subscribeTopic?: string | string[] | undefined;
|
|
58
|
-
publishTopic?: string | string[] | ((...args: unknown[]) => unknown) | undefined;
|
|
59
59
|
disableLogging?: boolean | undefined;
|
|
60
|
-
memory?: any;
|
|
61
60
|
}>;
|
|
62
61
|
export declare class AIAgent<I extends Message = Message, O extends Message = Message> extends Agent<I, O> {
|
|
63
62
|
static from<I extends Message, O extends Message>(options: AIAgentOptions<I, O>): AIAgent<I, O>;
|
|
@@ -66,6 +65,6 @@ export declare class AIAgent<I extends Message = Message, O extends Message = Me
|
|
|
66
65
|
instructions: PromptBuilder;
|
|
67
66
|
outputKey?: string;
|
|
68
67
|
toolChoice?: AIAgentToolChoice;
|
|
69
|
-
process(input: I, context: Context): AgentProcessAsyncGenerator<O
|
|
70
|
-
processRouter(input: I, model: ChatModel, modelInput: ChatModelInput, context: Context, toolsMap: Map<string, Agent>): AgentProcessAsyncGenerator<O
|
|
68
|
+
process(input: I, context: Context): AgentProcessAsyncGenerator<O>;
|
|
69
|
+
processRouter(input: I, model: ChatModel, modelInput: ChatModelInput, context: Context, toolsMap: Map<string, Agent>): AgentProcessAsyncGenerator<O>;
|
|
71
70
|
}
|
|
@@ -28,7 +28,7 @@ exports.aiAgentOptionsSchema = zod_1.z.object({
|
|
|
28
28
|
publishTopic: zod_1.z.union([zod_1.z.string(), zod_1.z.array(zod_1.z.string()), zod_1.z.function()]).optional(),
|
|
29
29
|
name: zod_1.z.string().optional(),
|
|
30
30
|
description: zod_1.z.string().optional(),
|
|
31
|
-
|
|
31
|
+
skills: zod_1.z.array(zod_1.z.union([zod_1.z.instanceof(agent_js_1.Agent), zod_1.z.function()])).optional(),
|
|
32
32
|
disableLogging: zod_1.z.boolean().optional(),
|
|
33
33
|
memory: zod_1.z.union([zod_1.z.boolean(), zod_1.z.any(), zod_1.z.any()]).optional(),
|
|
34
34
|
});
|
|
@@ -52,7 +52,7 @@ class AIAgent extends agent_js_1.Agent {
|
|
|
52
52
|
outputKey;
|
|
53
53
|
toolChoice;
|
|
54
54
|
async *process(input, context) {
|
|
55
|
-
const model =
|
|
55
|
+
const model = this.model ?? context.model;
|
|
56
56
|
if (!model)
|
|
57
57
|
throw new Error("model is required to run AIAgent");
|
|
58
58
|
const { toolAgents, ...modelInput } = await this.instructions.build({
|
|
@@ -70,7 +70,7 @@ class AIAgent extends agent_js_1.Agent {
|
|
|
70
70
|
const outputKey = this.outputKey || prompt_builder_js_1.MESSAGE_KEY;
|
|
71
71
|
for (;;) {
|
|
72
72
|
const modelOutput = {};
|
|
73
|
-
const stream = await context.
|
|
73
|
+
const stream = await context.invoke(model, { ...modelInput, messages: modelInput.messages.concat(toolCallMessages) }, { streaming: true });
|
|
74
74
|
for await (const value of (0, stream_utils_js_1.readableStreamToAsyncIterator)(stream)) {
|
|
75
75
|
if (value.delta.text?.text) {
|
|
76
76
|
yield { delta: { text: { [outputKey]: value.delta.text.text } } };
|
|
@@ -88,7 +88,7 @@ class AIAgent extends agent_js_1.Agent {
|
|
|
88
88
|
if (!tool)
|
|
89
89
|
throw new Error(`Tool not found: ${call.function.name}`);
|
|
90
90
|
// NOTE: should pass both arguments (model generated) and input (user provided) to the tool
|
|
91
|
-
const output = await context.
|
|
91
|
+
const output = await context.invoke(tool, { ...call.function.arguments, ...input }, { disableTransfer: true });
|
|
92
92
|
// NOTE: Return transfer output immediately
|
|
93
93
|
if ((0, types_js_1.isTransferAgentOutput)(output)) {
|
|
94
94
|
return output;
|
|
@@ -115,14 +115,14 @@ class AIAgent extends agent_js_1.Agent {
|
|
|
115
115
|
}
|
|
116
116
|
}
|
|
117
117
|
async *processRouter(input, model, modelInput, context, toolsMap) {
|
|
118
|
-
const { toolCalls: [call] = [], } = await context.
|
|
118
|
+
const { toolCalls: [call] = [], } = await context.invoke(model, modelInput);
|
|
119
119
|
if (!call) {
|
|
120
120
|
throw new Error("Router toolChoice requires exactly one tool to be executed");
|
|
121
121
|
}
|
|
122
122
|
const tool = toolsMap.get(call.function.name);
|
|
123
123
|
if (!tool)
|
|
124
124
|
throw new Error(`Tool not found: ${call.function.name}`);
|
|
125
|
-
const stream = await context.
|
|
125
|
+
const stream = await context.invoke(tool, { ...call.function.arguments, ...input }, { streaming: true });
|
|
126
126
|
yield* (0, stream_utils_js_1.readableStreamToAsyncIterator)(stream);
|
|
127
127
|
}
|
|
128
128
|
}
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import { Client, type ClientOptions } from "@modelcontextprotocol/sdk/client/index.js";
|
|
2
2
|
import { type SSEClientTransportOptions } from "@modelcontextprotocol/sdk/client/sse.js";
|
|
3
3
|
import { type StdioServerParameters } from "@modelcontextprotocol/sdk/client/stdio.js";
|
|
4
|
+
import { type StreamableHTTPClientTransportOptions } from "@modelcontextprotocol/sdk/client/streamableHttp.js";
|
|
4
5
|
import type { RequestOptions } from "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
5
6
|
import type { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
|
|
6
7
|
import type { CallToolResult, GetPromptResult, Implementation, ReadResourceResult, Request } from "@modelcontextprotocol/sdk/types.js";
|
|
7
8
|
import { type ZodType, z } from "zod";
|
|
8
|
-
import type { Context } from "../
|
|
9
|
+
import type { Context } from "../aigne/context.js";
|
|
9
10
|
import { type PromiseOrValue } from "../utils/type-utils.js";
|
|
10
11
|
import { Agent, type AgentOptions, type Message } from "./agent.js";
|
|
11
12
|
export interface MCPAgentOptions extends AgentOptions {
|
|
@@ -17,9 +18,14 @@ export type MCPServerOptions = SSEServerParameters | StdioServerParameters;
|
|
|
17
18
|
export type SSEServerParameters = {
|
|
18
19
|
url: string;
|
|
19
20
|
/**
|
|
20
|
-
*
|
|
21
|
+
* Whether to use the StreamableHTTPClientTransport instead of the SSEClientTransport.
|
|
22
|
+
* @default "sse"
|
|
21
23
|
*/
|
|
22
|
-
|
|
24
|
+
transport?: "sse" | "streamableHttp";
|
|
25
|
+
/**
|
|
26
|
+
* Additional options to pass to the SSEClientTransport or StreamableHTTPClientTransport.
|
|
27
|
+
*/
|
|
28
|
+
opts?: SSEClientTransportOptions | StreamableHTTPClientTransportOptions;
|
|
23
29
|
/**
|
|
24
30
|
* The timeout for requests to the server, in milliseconds.
|
|
25
31
|
* @default 60000
|
|
@@ -48,7 +54,7 @@ export declare class MCPAgent extends Agent {
|
|
|
48
54
|
readonly resources: MCPResource[] & {
|
|
49
55
|
[key: string]: MCPResource;
|
|
50
56
|
};
|
|
51
|
-
get
|
|
57
|
+
get isInvokable(): boolean;
|
|
52
58
|
process(_input: Message, _context?: Context): Promise<Message>;
|
|
53
59
|
shutdown(): Promise<void>;
|
|
54
60
|
}
|
|
@@ -7,6 +7,7 @@ exports.MCPResource = exports.MCPPrompt = exports.MCPTool = exports.MCPBase = ex
|
|
|
7
7
|
const index_js_1 = require("@modelcontextprotocol/sdk/client/index.js");
|
|
8
8
|
const sse_js_1 = require("@modelcontextprotocol/sdk/client/sse.js");
|
|
9
9
|
const stdio_js_1 = require("@modelcontextprotocol/sdk/client/stdio.js");
|
|
10
|
+
const streamableHttp_js_1 = require("@modelcontextprotocol/sdk/client/streamableHttp.js");
|
|
10
11
|
const uriTemplate_js_1 = require("@modelcontextprotocol/sdk/shared/uriTemplate.js");
|
|
11
12
|
const p_retry_1 = __importDefault(require("p-retry"));
|
|
12
13
|
const zod_1 = require("zod");
|
|
@@ -14,8 +15,8 @@ const logger_js_1 = require("../utils/logger.js");
|
|
|
14
15
|
const mcp_utils_js_1 = require("../utils/mcp-utils.js");
|
|
15
16
|
const type_utils_js_1 = require("../utils/type-utils.js");
|
|
16
17
|
const agent_js_1 = require("./agent.js");
|
|
17
|
-
const MCP_AGENT_CLIENT_NAME = "MCPAgent";
|
|
18
|
-
const MCP_AGENT_CLIENT_VERSION = "
|
|
18
|
+
const MCP_AGENT_CLIENT_NAME = "AIGNE/MCPAgent";
|
|
19
|
+
const MCP_AGENT_CLIENT_VERSION = "1.10.0"; // This should match the version in package.json
|
|
19
20
|
const DEFAULT_MAX_RECONNECTS = 10;
|
|
20
21
|
const DEFAULT_TIMEOUT = () => zod_1.z.coerce
|
|
21
22
|
.number()
|
|
@@ -41,7 +42,12 @@ class MCPAgent extends agent_js_1.Agent {
|
|
|
41
42
|
static from(options) {
|
|
42
43
|
(0, type_utils_js_1.checkArguments)("MCPAgent.from", mcpAgentOptionsSchema, options);
|
|
43
44
|
if (isSSEServerParameters(options)) {
|
|
44
|
-
const transport = () =>
|
|
45
|
+
const transport = () => {
|
|
46
|
+
if (options.transport === "streamableHttp") {
|
|
47
|
+
return new streamableHttp_js_1.StreamableHTTPClientTransport(new URL(options.url), options.opts);
|
|
48
|
+
}
|
|
49
|
+
return new sse_js_1.SSEClientTransport(new URL(options.url), options.opts);
|
|
50
|
+
};
|
|
45
51
|
return MCPAgent.fromTransport(transport, options);
|
|
46
52
|
}
|
|
47
53
|
if (isStdioServerParameters(options)) {
|
|
@@ -68,7 +74,7 @@ class MCPAgent extends agent_js_1.Agent {
|
|
|
68
74
|
const mcpServer = getMCPServerName(client);
|
|
69
75
|
const { tools: isToolsAvailable, prompts: isPromptsAvailable, resources: isResourcesAvailable, } = client.getServerCapabilities() ?? {};
|
|
70
76
|
logger_js_1.logger.mcp(`Listing tools from ${mcpServer}`);
|
|
71
|
-
const
|
|
77
|
+
const skills = isToolsAvailable
|
|
72
78
|
? await client.listTools().then(({ tools }) => {
|
|
73
79
|
logger_js_1.logger.mcp(`Listing tools from ${mcpServer} completed %O`, tools?.map((i) => i.name));
|
|
74
80
|
return tools.map((tool) => (0, mcp_utils_js_1.toolFromMCPTool)(tool, { client }));
|
|
@@ -97,7 +103,7 @@ class MCPAgent extends agent_js_1.Agent {
|
|
|
97
103
|
return new MCPAgent({
|
|
98
104
|
name: client.getServerVersion()?.name,
|
|
99
105
|
client,
|
|
100
|
-
|
|
106
|
+
skills,
|
|
101
107
|
prompts,
|
|
102
108
|
resources,
|
|
103
109
|
});
|
|
@@ -113,7 +119,7 @@ class MCPAgent extends agent_js_1.Agent {
|
|
|
113
119
|
client;
|
|
114
120
|
prompts = (0, type_utils_js_1.createAccessorArray)([], (arr, name) => arr.find((i) => i.name === name));
|
|
115
121
|
resources = (0, type_utils_js_1.createAccessorArray)([], (arr, name) => arr.find((i) => i.name === name));
|
|
116
|
-
get
|
|
122
|
+
get isInvokable() {
|
|
117
123
|
return false;
|
|
118
124
|
}
|
|
119
125
|
async process(_input, _context) {
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import type { Context } from "../aigne/context.js";
|
|
2
|
+
import { type PromiseOrValue } from "../utils/type-utils.js";
|
|
3
|
+
import { Agent, type AgentOptions, type AgentProcessResult, type Message } from "./agent.js";
|
|
4
|
+
export declare enum ProcessMode {
|
|
5
|
+
/**
|
|
6
|
+
* Process the agents one by one, passing the output of each agent to the next.
|
|
7
|
+
*/
|
|
8
|
+
sequential = "sequential",
|
|
9
|
+
/**
|
|
10
|
+
* Process all agents in parallel, merging the output of all agents.
|
|
11
|
+
*/
|
|
12
|
+
parallel = "parallel"
|
|
13
|
+
}
|
|
14
|
+
export interface TeamAgentOptions<I extends Message, O extends Message> extends AgentOptions<I, O> {
|
|
15
|
+
/**
|
|
16
|
+
* The method to process the agents in the team.
|
|
17
|
+
* @default {ProcessMode.sequential}
|
|
18
|
+
*/
|
|
19
|
+
mode?: ProcessMode;
|
|
20
|
+
}
|
|
21
|
+
export declare class TeamAgent<I extends Message, O extends Message> extends Agent<I, O> {
|
|
22
|
+
static from<I extends Message, O extends Message>(options: TeamAgentOptions<I, O>): TeamAgent<I, O>;
|
|
23
|
+
constructor(options: TeamAgentOptions<I, O>);
|
|
24
|
+
mode: ProcessMode;
|
|
25
|
+
process(input: I, context: Context): PromiseOrValue<AgentProcessResult<O>>;
|
|
26
|
+
_processSequential(input: I, context: Context): PromiseOrValue<AgentProcessResult<O>>;
|
|
27
|
+
_processParallel(input: I, context: Context): PromiseOrValue<AgentProcessResult<O>>;
|
|
28
|
+
}
|