@aigne/core 1.3.1 → 1.4.1-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 +12 -0
- package/lib/cjs/agents/agent.d.ts +7 -4
- package/lib/cjs/agents/agent.js +25 -8
- package/lib/cjs/agents/ai-agent.d.ts +49 -1
- package/lib/cjs/agents/ai-agent.js +27 -1
- package/lib/cjs/agents/mcp-agent.js +30 -4
- package/lib/cjs/agents/memory.js +7 -0
- package/lib/cjs/execution-engine/execution-engine.d.ts +1 -1
- package/lib/cjs/execution-engine/execution-engine.js +48 -0
- package/lib/cjs/execution-engine/utils.d.ts +1 -1
- package/lib/cjs/execution-engine/utils.js +6 -0
- package/lib/cjs/index.d.ts +3 -0
- package/lib/cjs/index.js +3 -0
- package/lib/cjs/models/chat-model.d.ts +1 -0
- package/lib/cjs/models/chat-model.js +1 -0
- package/lib/cjs/models/claude-chat-model.d.ts +58 -9
- package/lib/cjs/models/claude-chat-model.js +78 -42
- package/lib/cjs/models/openai-chat-model.d.ts +62 -9
- package/lib/cjs/models/openai-chat-model.js +38 -11
- package/lib/cjs/models/xai-chat-model.d.ts +12 -0
- package/lib/cjs/models/xai-chat-model.js +18 -0
- package/lib/cjs/package.json +1 -0
- package/lib/cjs/prompt/prompt-builder.d.ts +2 -2
- package/lib/cjs/utils/json-schema.d.ts +9 -1
- package/lib/cjs/utils/json-schema.js +14 -0
- package/lib/cjs/utils/run-chat-loop.js +10 -5
- package/lib/cjs/utils/type-utils.d.ts +2 -0
- package/lib/cjs/utils/type-utils.js +44 -0
- package/lib/dts/agents/agent.d.ts +7 -4
- package/lib/dts/agents/ai-agent.d.ts +49 -1
- package/lib/dts/execution-engine/execution-engine.d.ts +1 -1
- package/lib/dts/execution-engine/utils.d.ts +1 -1
- package/lib/dts/index.d.ts +3 -0
- package/lib/dts/models/chat-model.d.ts +1 -0
- package/lib/dts/models/claude-chat-model.d.ts +58 -9
- package/lib/dts/models/openai-chat-model.d.ts +62 -9
- package/lib/dts/models/xai-chat-model.d.ts +12 -0
- package/lib/dts/prompt/prompt-builder.d.ts +2 -2
- package/lib/dts/utils/json-schema.d.ts +9 -1
- package/lib/dts/utils/type-utils.d.ts +2 -0
- package/lib/esm/agents/agent.d.ts +7 -4
- package/lib/esm/agents/agent.js +25 -8
- package/lib/esm/agents/ai-agent.d.ts +49 -1
- package/lib/esm/agents/ai-agent.js +26 -0
- package/lib/esm/agents/mcp-agent.js +31 -5
- package/lib/esm/agents/memory.js +8 -1
- package/lib/esm/execution-engine/execution-engine.d.ts +1 -1
- package/lib/esm/execution-engine/execution-engine.js +48 -0
- package/lib/esm/execution-engine/utils.d.ts +1 -1
- package/lib/esm/execution-engine/utils.js +6 -0
- package/lib/esm/index.d.ts +3 -0
- package/lib/esm/index.js +3 -0
- package/lib/esm/models/chat-model.d.ts +1 -0
- package/lib/esm/models/chat-model.js +1 -0
- package/lib/esm/models/claude-chat-model.d.ts +58 -9
- package/lib/esm/models/claude-chat-model.js +78 -42
- package/lib/esm/models/openai-chat-model.d.ts +62 -9
- package/lib/esm/models/openai-chat-model.js +38 -11
- package/lib/esm/models/xai-chat-model.d.ts +12 -0
- package/lib/esm/models/xai-chat-model.js +14 -0
- package/lib/esm/package.json +1 -0
- package/lib/esm/prompt/prompt-builder.d.ts +2 -2
- package/lib/esm/utils/json-schema.d.ts +9 -1
- package/lib/esm/utils/json-schema.js +13 -0
- package/lib/esm/utils/run-chat-loop.js +10 -5
- package/lib/esm/utils/type-utils.d.ts +2 -0
- package/lib/esm/utils/type-utils.js +43 -0
- package/package.json +7 -6
package/CHANGELOG.md
CHANGED
|
@@ -22,6 +22,18 @@
|
|
|
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.4.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.3.1...core-v1.4.0) (2025-03-26)
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
### Features
|
|
29
|
+
|
|
30
|
+
* **core:** add xAI chat model adapter ([#34](https://github.com/AIGNE-io/aigne-framework/issues/34)) ([b228d22](https://github.com/AIGNE-io/aigne-framework/commit/b228d22b550535ab8e511f13de9e4a65dd73e3c0))
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
### Bug Fixes
|
|
34
|
+
|
|
35
|
+
* **orchestrator:** refactor and enhance orchestrator with step synthesis ([#31](https://github.com/AIGNE-io/aigne-framework/issues/31)) ([ba9fca0](https://github.com/AIGNE-io/aigne-framework/commit/ba9fca04fad71d49c8f4f52172b56668a94ea714))
|
|
36
|
+
|
|
25
37
|
## [1.3.1](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.3.0...core-v1.3.1) (2025-03-25)
|
|
26
38
|
|
|
27
39
|
|
|
@@ -11,8 +11,8 @@ export interface AgentOptions<I extends Message = Message, O extends Message = M
|
|
|
11
11
|
publishTopic?: PublishTopic<O>;
|
|
12
12
|
name?: string;
|
|
13
13
|
description?: string;
|
|
14
|
-
inputSchema?:
|
|
15
|
-
outputSchema?:
|
|
14
|
+
inputSchema?: AgentInputOutputSchema<I>;
|
|
15
|
+
outputSchema?: AgentInputOutputSchema<O>;
|
|
16
16
|
includeInputInOutput?: boolean;
|
|
17
17
|
tools?: (Agent | FunctionAgentFn)[];
|
|
18
18
|
disableLogging?: boolean;
|
|
@@ -27,8 +27,10 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
|
|
|
27
27
|
*/
|
|
28
28
|
get topic(): string;
|
|
29
29
|
readonly description?: string;
|
|
30
|
-
readonly
|
|
31
|
-
readonly
|
|
30
|
+
private readonly _inputSchema?;
|
|
31
|
+
private readonly _outputSchema?;
|
|
32
|
+
get inputSchema(): ZodType<I>;
|
|
33
|
+
get outputSchema(): ZodType<O>;
|
|
32
34
|
readonly includeInputInOutput?: boolean;
|
|
33
35
|
readonly subscribeTopic?: SubscribeTopic;
|
|
34
36
|
readonly publishTopic?: PublishTopic<Message>;
|
|
@@ -49,6 +51,7 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
|
|
|
49
51
|
abstract process(input: I, context?: Context): Promise<O | TransferAgentOutput>;
|
|
50
52
|
shutdown(): Promise<void>;
|
|
51
53
|
}
|
|
54
|
+
export type AgentInputOutputSchema<I extends Message = Message> = ZodType<I> | ((agent: Agent) => ZodType<I>);
|
|
52
55
|
export interface FunctionAgentOptions<I extends Message = Message, O extends Message = Message> extends AgentOptions<I, O> {
|
|
53
56
|
fn?: FunctionAgentFn<I, O>;
|
|
54
57
|
}
|
package/lib/cjs/agents/agent.js
CHANGED
|
@@ -11,12 +11,12 @@ class Agent {
|
|
|
11
11
|
constructor({ inputSchema, outputSchema, ...options }) {
|
|
12
12
|
this.name = options.name || this.constructor.name;
|
|
13
13
|
this.description = options.description;
|
|
14
|
-
if (
|
|
15
|
-
(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
this.
|
|
19
|
-
this.
|
|
14
|
+
if (inputSchema)
|
|
15
|
+
checkAgentInputOutputSchema(inputSchema);
|
|
16
|
+
if (outputSchema)
|
|
17
|
+
checkAgentInputOutputSchema(outputSchema);
|
|
18
|
+
this._inputSchema = inputSchema;
|
|
19
|
+
this._outputSchema = outputSchema;
|
|
20
20
|
this.includeInputInOutput = options.includeInputInOutput;
|
|
21
21
|
this.subscribeTopic = options.subscribeTopic;
|
|
22
22
|
this.publishTopic = options.publishTopic;
|
|
@@ -41,8 +41,20 @@ class Agent {
|
|
|
41
41
|
return `$agent_${this.name}`;
|
|
42
42
|
}
|
|
43
43
|
description;
|
|
44
|
-
|
|
45
|
-
|
|
44
|
+
_inputSchema;
|
|
45
|
+
_outputSchema;
|
|
46
|
+
get inputSchema() {
|
|
47
|
+
const s = this._inputSchema;
|
|
48
|
+
const schema = typeof s === "function" ? s(this) : s || zod_1.z.object({});
|
|
49
|
+
checkAgentInputOutputSchema(schema);
|
|
50
|
+
return schema.passthrough();
|
|
51
|
+
}
|
|
52
|
+
get outputSchema() {
|
|
53
|
+
const s = this._outputSchema;
|
|
54
|
+
const schema = typeof s === "function" ? s(this) : s || zod_1.z.object({});
|
|
55
|
+
checkAgentInputOutputSchema(schema);
|
|
56
|
+
return schema.passthrough();
|
|
57
|
+
}
|
|
46
58
|
includeInputInOutput;
|
|
47
59
|
subscribeTopic;
|
|
48
60
|
publishTopic;
|
|
@@ -98,6 +110,11 @@ class Agent {
|
|
|
98
110
|
}
|
|
99
111
|
}
|
|
100
112
|
exports.Agent = Agent;
|
|
113
|
+
function checkAgentInputOutputSchema(schema) {
|
|
114
|
+
if (!(schema instanceof zod_1.ZodObject) && typeof schema !== "function") {
|
|
115
|
+
throw new Error("schema must be a zod object or function return a zod object ");
|
|
116
|
+
}
|
|
117
|
+
}
|
|
101
118
|
class FunctionAgent extends Agent {
|
|
102
119
|
static from(options) {
|
|
103
120
|
return typeof options === "function" ? functionToAgent(options) : new FunctionAgent(options);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
1
2
|
import type { Context } from "../execution-engine/context.js";
|
|
2
|
-
import
|
|
3
|
+
import { ChatModel } from "../models/chat-model.js";
|
|
3
4
|
import { PromptBuilder } from "../prompt/prompt-builder.js";
|
|
4
5
|
import { Agent, type AgentOptions, type Message } from "./agent.js";
|
|
5
6
|
export interface AIAgentOptions<I extends Message = Message, O extends Message = Message> extends AgentOptions<I, O> {
|
|
@@ -9,6 +10,53 @@ export interface AIAgentOptions<I extends Message = Message, O extends Message =
|
|
|
9
10
|
toolChoice?: AIAgentToolChoice;
|
|
10
11
|
}
|
|
11
12
|
export type AIAgentToolChoice = "auto" | "none" | "required" | "router" | Agent;
|
|
13
|
+
export declare const aiAgentToolChoiceSchema: z.ZodUnion<[z.ZodLiteral<"auto">, z.ZodLiteral<"none">, z.ZodLiteral<"required">, z.ZodLiteral<"router">, z.ZodType<Agent<Message, Message>, z.ZodTypeDef, Agent<Message, Message>>]>;
|
|
14
|
+
export declare const aiAgentOptionsSchema: z.ZodObject<{
|
|
15
|
+
model: z.ZodOptional<z.ZodType<ChatModel, z.ZodTypeDef, ChatModel>>;
|
|
16
|
+
instructions: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodType<PromptBuilder, z.ZodTypeDef, PromptBuilder>]>>;
|
|
17
|
+
outputKey: z.ZodOptional<z.ZodString>;
|
|
18
|
+
toolChoice: z.ZodOptional<z.ZodUnion<[z.ZodLiteral<"auto">, z.ZodLiteral<"none">, z.ZodLiteral<"required">, z.ZodLiteral<"router">, z.ZodType<Agent<Message, Message>, z.ZodTypeDef, Agent<Message, Message>>]>>;
|
|
19
|
+
enableHistory: z.ZodOptional<z.ZodBoolean>;
|
|
20
|
+
maxHistoryMessages: z.ZodOptional<z.ZodNumber>;
|
|
21
|
+
includeInputInOutput: z.ZodOptional<z.ZodBoolean>;
|
|
22
|
+
subscribeTopic: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
|
|
23
|
+
publishTopic: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">, z.ZodFunction<z.ZodTuple<[], z.ZodUnknown>, z.ZodUnknown>]>>;
|
|
24
|
+
name: z.ZodOptional<z.ZodString>;
|
|
25
|
+
description: z.ZodOptional<z.ZodString>;
|
|
26
|
+
tools: 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">>;
|
|
27
|
+
disableLogging: z.ZodOptional<z.ZodBoolean>;
|
|
28
|
+
memory: z.ZodOptional<z.ZodUnion<[z.ZodBoolean, z.ZodAny, z.ZodAny]>>;
|
|
29
|
+
}, "strip", z.ZodTypeAny, {
|
|
30
|
+
tools?: (Agent<Message, Message> | ((...args: unknown[]) => unknown))[] | undefined;
|
|
31
|
+
toolChoice?: "auto" | "none" | "required" | Agent<Message, Message> | "router" | undefined;
|
|
32
|
+
name?: string | undefined;
|
|
33
|
+
description?: string | undefined;
|
|
34
|
+
model?: ChatModel | undefined;
|
|
35
|
+
instructions?: string | PromptBuilder | undefined;
|
|
36
|
+
outputKey?: string | undefined;
|
|
37
|
+
enableHistory?: boolean | undefined;
|
|
38
|
+
maxHistoryMessages?: number | undefined;
|
|
39
|
+
includeInputInOutput?: boolean | undefined;
|
|
40
|
+
subscribeTopic?: string | string[] | undefined;
|
|
41
|
+
publishTopic?: string | string[] | ((...args: unknown[]) => unknown) | undefined;
|
|
42
|
+
disableLogging?: boolean | undefined;
|
|
43
|
+
memory?: any;
|
|
44
|
+
}, {
|
|
45
|
+
tools?: (Agent<Message, Message> | ((...args: unknown[]) => unknown))[] | undefined;
|
|
46
|
+
toolChoice?: "auto" | "none" | "required" | Agent<Message, Message> | "router" | undefined;
|
|
47
|
+
name?: string | undefined;
|
|
48
|
+
description?: string | undefined;
|
|
49
|
+
model?: ChatModel | undefined;
|
|
50
|
+
instructions?: string | PromptBuilder | undefined;
|
|
51
|
+
outputKey?: string | undefined;
|
|
52
|
+
enableHistory?: boolean | undefined;
|
|
53
|
+
maxHistoryMessages?: number | undefined;
|
|
54
|
+
includeInputInOutput?: boolean | undefined;
|
|
55
|
+
subscribeTopic?: string | string[] | undefined;
|
|
56
|
+
publishTopic?: string | string[] | ((...args: unknown[]) => unknown) | undefined;
|
|
57
|
+
disableLogging?: boolean | undefined;
|
|
58
|
+
memory?: any;
|
|
59
|
+
}>;
|
|
12
60
|
export declare class AIAgent<I extends Message = Message, O extends Message = Message> extends Agent<I, O> {
|
|
13
61
|
static from<I extends Message, O extends Message>(options: AIAgentOptions<I, O>): AIAgent<I, O>;
|
|
14
62
|
constructor(options: AIAgentOptions<I, O>);
|
|
@@ -1,15 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.AIAgent = void 0;
|
|
3
|
+
exports.AIAgent = exports.aiAgentOptionsSchema = exports.aiAgentToolChoiceSchema = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
5
|
+
const chat_model_js_1 = require("../models/chat-model.js");
|
|
4
6
|
const prompt_builder_js_1 = require("../prompt/prompt-builder.js");
|
|
5
7
|
const template_js_1 = require("../prompt/template.js");
|
|
6
8
|
const agent_js_1 = require("./agent.js");
|
|
7
9
|
const types_js_1 = require("./types.js");
|
|
10
|
+
exports.aiAgentToolChoiceSchema = zod_1.z.union([
|
|
11
|
+
zod_1.z.literal("auto"),
|
|
12
|
+
zod_1.z.literal("none"),
|
|
13
|
+
zod_1.z.literal("required"),
|
|
14
|
+
zod_1.z.literal("router"),
|
|
15
|
+
zod_1.z.instanceof(agent_js_1.Agent),
|
|
16
|
+
], { message: "aiAgentToolChoice must be 'auto', 'none', 'required', 'router', or an Agent" });
|
|
17
|
+
exports.aiAgentOptionsSchema = zod_1.z.object({
|
|
18
|
+
model: zod_1.z.instanceof(chat_model_js_1.ChatModel).optional(),
|
|
19
|
+
instructions: zod_1.z.union([zod_1.z.string(), zod_1.z.instanceof(prompt_builder_js_1.PromptBuilder)]).optional(),
|
|
20
|
+
outputKey: zod_1.z.string().optional(),
|
|
21
|
+
toolChoice: exports.aiAgentToolChoiceSchema.optional(),
|
|
22
|
+
enableHistory: zod_1.z.boolean().optional(),
|
|
23
|
+
maxHistoryMessages: zod_1.z.number().optional(),
|
|
24
|
+
includeInputInOutput: zod_1.z.boolean().optional(),
|
|
25
|
+
subscribeTopic: zod_1.z.union([zod_1.z.string(), zod_1.z.array(zod_1.z.string())]).optional(),
|
|
26
|
+
publishTopic: zod_1.z.union([zod_1.z.string(), zod_1.z.array(zod_1.z.string()), zod_1.z.function()]).optional(),
|
|
27
|
+
name: zod_1.z.string().optional(),
|
|
28
|
+
description: zod_1.z.string().optional(),
|
|
29
|
+
tools: zod_1.z.array(zod_1.z.union([zod_1.z.instanceof(agent_js_1.Agent), zod_1.z.function()])).optional(),
|
|
30
|
+
disableLogging: zod_1.z.boolean().optional(),
|
|
31
|
+
memory: zod_1.z.union([zod_1.z.boolean(), zod_1.z.any(), zod_1.z.any()]).optional(),
|
|
32
|
+
});
|
|
8
33
|
class AIAgent extends agent_js_1.Agent {
|
|
9
34
|
static from(options) {
|
|
10
35
|
return new AIAgent(options);
|
|
11
36
|
}
|
|
12
37
|
constructor(options) {
|
|
38
|
+
exports.aiAgentOptionsSchema.parse(options);
|
|
13
39
|
super(options);
|
|
14
40
|
this.model = options.model;
|
|
15
41
|
this.instructions =
|
|
@@ -5,6 +5,7 @@ const index_js_1 = require("@modelcontextprotocol/sdk/client/index.js");
|
|
|
5
5
|
const sse_js_1 = require("@modelcontextprotocol/sdk/client/sse.js");
|
|
6
6
|
const stdio_js_1 = require("@modelcontextprotocol/sdk/client/stdio.js");
|
|
7
7
|
const uriTemplate_js_1 = require("@modelcontextprotocol/sdk/shared/uriTemplate.js");
|
|
8
|
+
const zod_1 = require("zod");
|
|
8
9
|
const logger_js_1 = require("../utils/logger.js");
|
|
9
10
|
const mcp_utils_js_1 = require("../utils/mcp-utils.js");
|
|
10
11
|
const type_utils_js_1 = require("../utils/type-utils.js");
|
|
@@ -18,11 +19,21 @@ function isSSEServerParameters(options) {
|
|
|
18
19
|
function isStdioServerParameters(options) {
|
|
19
20
|
return "command" in options && typeof options.command === "string";
|
|
20
21
|
}
|
|
22
|
+
function getMCPServerString(options) {
|
|
23
|
+
if (isSSEServerParameters(options)) {
|
|
24
|
+
return options.url;
|
|
25
|
+
}
|
|
26
|
+
if (isStdioServerParameters(options)) {
|
|
27
|
+
return `${options.command} ${options.args?.join(" ") || ""}`;
|
|
28
|
+
}
|
|
29
|
+
return "unknown";
|
|
30
|
+
}
|
|
21
31
|
class MCPAgent extends agent_js_1.Agent {
|
|
22
32
|
static from(options) {
|
|
33
|
+
(0, type_utils_js_1.checkArguments)("MCPAgent.from", mcpAgentOptionsSchema, options);
|
|
23
34
|
if (isSSEServerParameters(options)) {
|
|
24
35
|
const transport = new sse_js_1.SSEClientTransport(new URL(options.url));
|
|
25
|
-
return MCPAgent.fromTransport(transport);
|
|
36
|
+
return MCPAgent.fromTransport(transport, options);
|
|
26
37
|
}
|
|
27
38
|
if (isStdioServerParameters(options)) {
|
|
28
39
|
const transport = new stdio_js_1.StdioClientTransport({
|
|
@@ -33,16 +44,16 @@ class MCPAgent extends agent_js_1.Agent {
|
|
|
33
44
|
},
|
|
34
45
|
stderr: "pipe",
|
|
35
46
|
});
|
|
36
|
-
return MCPAgent.fromTransport(transport);
|
|
47
|
+
return MCPAgent.fromTransport(transport, options);
|
|
37
48
|
}
|
|
38
49
|
return new MCPAgent(options);
|
|
39
50
|
}
|
|
40
|
-
static async fromTransport(transport) {
|
|
51
|
+
static async fromTransport(transport, options) {
|
|
41
52
|
const client = new index_js_1.Client({
|
|
42
53
|
name: MCP_AGENT_CLIENT_NAME,
|
|
43
54
|
version: MCP_AGENT_CLIENT_VERSION,
|
|
44
55
|
});
|
|
45
|
-
await debug.spinner(client.connect(transport),
|
|
56
|
+
await debug.spinner(client.connect(transport), `Connecting to MCP server: ${getMCPServerString(options)}`);
|
|
46
57
|
const mcpServer = getMCPServerName(client);
|
|
47
58
|
const { tools: isToolsAvailable, prompts: isPromptsAvailable, resources: isResourcesAvailable, } = client.getServerCapabilities() ?? {};
|
|
48
59
|
const tools = isToolsAvailable
|
|
@@ -142,3 +153,18 @@ function getMCPServerName(client) {
|
|
|
142
153
|
const { name, version } = info;
|
|
143
154
|
return `${name}@${version}`;
|
|
144
155
|
}
|
|
156
|
+
const mcpAgentOptionsSchema = zod_1.z.union([
|
|
157
|
+
zod_1.z.object({
|
|
158
|
+
client: zod_1.z.instanceof(index_js_1.Client),
|
|
159
|
+
prompts: zod_1.z.array(zod_1.z.instanceof(MCPPrompt)).optional(),
|
|
160
|
+
resources: zod_1.z.array(zod_1.z.instanceof(MCPResource)).optional(),
|
|
161
|
+
}),
|
|
162
|
+
zod_1.z.object({
|
|
163
|
+
url: zod_1.z.string(),
|
|
164
|
+
}),
|
|
165
|
+
zod_1.z.object({
|
|
166
|
+
command: zod_1.z.string(),
|
|
167
|
+
args: zod_1.z.array(zod_1.z.string()).optional(),
|
|
168
|
+
env: zod_1.z.record(zod_1.z.string()).optional(),
|
|
169
|
+
}),
|
|
170
|
+
]);
|
package/lib/cjs/agents/memory.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.AgentMemory = void 0;
|
|
4
|
+
const zod_1 = require("zod");
|
|
4
5
|
const type_utils_js_1 = require("../utils/type-utils.js");
|
|
5
6
|
class AgentMemory {
|
|
6
7
|
constructor(options) {
|
|
8
|
+
(0, type_utils_js_1.checkArguments)("AgentMemory", agentMemoryOptionsSchema, options);
|
|
7
9
|
this.enabled = options.enabled ?? true;
|
|
8
10
|
this.subscribeTopic = options.subscribeTopic;
|
|
9
11
|
this.maxMemoriesInChat = options.maxMemoriesInChat;
|
|
@@ -36,3 +38,8 @@ class AgentMemory {
|
|
|
36
38
|
}
|
|
37
39
|
}
|
|
38
40
|
exports.AgentMemory = AgentMemory;
|
|
41
|
+
const agentMemoryOptionsSchema = zod_1.z.object({
|
|
42
|
+
enabled: zod_1.z.boolean().optional(),
|
|
43
|
+
subscribeTopic: zod_1.z.union([zod_1.z.string(), zod_1.z.array(zod_1.z.string())]).optional(),
|
|
44
|
+
maxMemoriesInChat: zod_1.z.number().optional(),
|
|
45
|
+
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import EventEmitter from "node:events";
|
|
2
2
|
import { Agent, type Message } from "../agents/agent.js";
|
|
3
3
|
import { UserAgent } from "../agents/user-agent.js";
|
|
4
|
-
import
|
|
4
|
+
import { ChatModel } from "../models/chat-model.js";
|
|
5
5
|
import type { Context, Runnable } from "./context.js";
|
|
6
6
|
import { type MessagePayload, MessageQueue, type MessageQueueListener, type Unsubscribe } from "./message-queue.js";
|
|
7
7
|
export interface ExecutionEngineOptions {
|
|
@@ -6,13 +6,18 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
6
6
|
exports.ExecutionEngine = void 0;
|
|
7
7
|
const node_events_1 = __importDefault(require("node:events"));
|
|
8
8
|
const lodash_es_1 = require("lodash-es");
|
|
9
|
+
const zod_1 = require("zod");
|
|
9
10
|
const agent_js_1 = require("../agents/agent.js");
|
|
10
11
|
const types_js_1 = require("../agents/types.js");
|
|
11
12
|
const user_agent_js_1 = require("../agents/user-agent.js");
|
|
13
|
+
const chat_model_js_1 = require("../models/chat-model.js");
|
|
12
14
|
const prompt_builder_js_1 = require("../prompt/prompt-builder.js");
|
|
15
|
+
const type_utils_js_1 = require("../utils/type-utils.js");
|
|
13
16
|
const message_queue_js_1 = require("./message-queue.js");
|
|
14
17
|
class ExecutionEngine extends node_events_1.default {
|
|
15
18
|
constructor(options) {
|
|
19
|
+
if (options)
|
|
20
|
+
(0, type_utils_js_1.checkArguments)("ExecutionEngine", executionEngineOptionsSchema, options);
|
|
16
21
|
super();
|
|
17
22
|
this.model = options?.model;
|
|
18
23
|
this.tools = options?.tools ?? [];
|
|
@@ -25,6 +30,7 @@ class ExecutionEngine extends node_events_1.default {
|
|
|
25
30
|
tools;
|
|
26
31
|
agents = [];
|
|
27
32
|
addAgent(...agents) {
|
|
33
|
+
(0, type_utils_js_1.checkArguments)("ExecutionEngine.addAgent", executionEngineAddAgentArgsSchema, agents);
|
|
28
34
|
for (const agent of agents) {
|
|
29
35
|
this.agents.push(agent);
|
|
30
36
|
agent.attach(this);
|
|
@@ -40,6 +46,11 @@ class ExecutionEngine extends node_events_1.default {
|
|
|
40
46
|
* @param from the agent who publish the message, if not provided, it will be treated as a user message
|
|
41
47
|
*/
|
|
42
48
|
publish(topic, message, from) {
|
|
49
|
+
(0, type_utils_js_1.checkArguments)("ExecutionEngine.publish", executionEnginePublishArgsSchema, {
|
|
50
|
+
topic,
|
|
51
|
+
message,
|
|
52
|
+
from,
|
|
53
|
+
});
|
|
43
54
|
const request = {
|
|
44
55
|
role: !from || from instanceof user_agent_js_1.UserAgent ? "user" : "agent",
|
|
45
56
|
source: from?.name,
|
|
@@ -48,6 +59,11 @@ class ExecutionEngine extends node_events_1.default {
|
|
|
48
59
|
this.messageQueue.publish(topic, request);
|
|
49
60
|
}
|
|
50
61
|
call(agent, message, options) {
|
|
62
|
+
(0, type_utils_js_1.checkArguments)("ExecutionEngine.call", executionEngineCallArgsSchema, {
|
|
63
|
+
agent,
|
|
64
|
+
message,
|
|
65
|
+
options,
|
|
66
|
+
});
|
|
51
67
|
if ((0, lodash_es_1.isNil)(message)) {
|
|
52
68
|
let activeAgent = agent;
|
|
53
69
|
return user_agent_js_1.UserAgent.from({
|
|
@@ -82,9 +98,17 @@ class ExecutionEngine extends node_events_1.default {
|
|
|
82
98
|
return { output, agent: activeAgent };
|
|
83
99
|
}
|
|
84
100
|
subscribe(topic, listener) {
|
|
101
|
+
(0, type_utils_js_1.checkArguments)("ExecutionEngine.subscribe", executionEngineSubscribeArgsSchema, {
|
|
102
|
+
topic,
|
|
103
|
+
listener,
|
|
104
|
+
});
|
|
85
105
|
return this.messageQueue.subscribe(topic, listener);
|
|
86
106
|
}
|
|
87
107
|
unsubscribe(topic, listener) {
|
|
108
|
+
(0, type_utils_js_1.checkArguments)("ExecutionEngine.unsubscribe", executionEngineUnsubscribeArgsSchema, {
|
|
109
|
+
topic,
|
|
110
|
+
listener,
|
|
111
|
+
});
|
|
88
112
|
this.messageQueue.unsubscribe(topic, listener);
|
|
89
113
|
}
|
|
90
114
|
async callAgent(agent, input) {
|
|
@@ -134,3 +158,27 @@ class ExecutionEngine extends node_events_1.default {
|
|
|
134
158
|
}
|
|
135
159
|
}
|
|
136
160
|
exports.ExecutionEngine = ExecutionEngine;
|
|
161
|
+
const executionEngineOptionsSchema = zod_1.z.object({
|
|
162
|
+
model: zod_1.z.instanceof(chat_model_js_1.ChatModel).optional(),
|
|
163
|
+
tools: zod_1.z.array(zod_1.z.instanceof(agent_js_1.Agent)).optional(),
|
|
164
|
+
agents: zod_1.z.array(zod_1.z.instanceof(agent_js_1.Agent)).optional(),
|
|
165
|
+
});
|
|
166
|
+
const executionEngineAddAgentArgsSchema = zod_1.z.array(zod_1.z.instanceof(agent_js_1.Agent));
|
|
167
|
+
const executionEnginePublishArgsSchema = zod_1.z.object({
|
|
168
|
+
topic: zod_1.z.union([zod_1.z.string(), zod_1.z.array(zod_1.z.string())]),
|
|
169
|
+
message: zod_1.z.union([zod_1.z.string(), zod_1.z.record(zod_1.z.unknown())]),
|
|
170
|
+
from: zod_1.z.instanceof(agent_js_1.Agent).optional(),
|
|
171
|
+
});
|
|
172
|
+
const executionEngineCallArgsSchema = zod_1.z.object({
|
|
173
|
+
agent: zod_1.z.union([zod_1.z.function(), zod_1.z.instanceof(agent_js_1.Agent)]),
|
|
174
|
+
message: zod_1.z.union([zod_1.z.record(zod_1.z.unknown()), zod_1.z.string()]).optional(),
|
|
175
|
+
options: zod_1.z.object({ returnActiveAgent: zod_1.z.boolean().optional() }).optional(),
|
|
176
|
+
});
|
|
177
|
+
const executionEngineSubscribeArgsSchema = zod_1.z.object({
|
|
178
|
+
topic: zod_1.z.string(),
|
|
179
|
+
listener: zod_1.z.function(zod_1.z.tuple([zod_1.z.any()]), zod_1.z.any()).optional(),
|
|
180
|
+
});
|
|
181
|
+
const executionEngineUnsubscribeArgsSchema = zod_1.z.object({
|
|
182
|
+
topic: zod_1.z.string(),
|
|
183
|
+
listener: zod_1.z.function(zod_1.z.tuple([zod_1.z.any()]), zod_1.z.any()),
|
|
184
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type FunctionAgentFn } from "../agents/agent.js";
|
|
2
2
|
import type { Runnable } from "./context.js";
|
|
3
3
|
export declare function sequential(..._agents: [Runnable, ...Runnable[]]): FunctionAgentFn;
|
|
4
4
|
export declare function parallel(..._agents: [Runnable, ...Runnable[]]): FunctionAgentFn;
|
|
@@ -2,7 +2,11 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.sequential = sequential;
|
|
4
4
|
exports.parallel = parallel;
|
|
5
|
+
const zod_1 = require("zod");
|
|
6
|
+
const agent_js_1 = require("../agents/agent.js");
|
|
7
|
+
const type_utils_js_1 = require("../utils/type-utils.js");
|
|
5
8
|
function sequential(..._agents) {
|
|
9
|
+
(0, type_utils_js_1.checkArguments)("sequential", agentArraySchema, _agents);
|
|
6
10
|
let agents = [..._agents];
|
|
7
11
|
return async (input, context) => {
|
|
8
12
|
if (!context)
|
|
@@ -20,6 +24,7 @@ function sequential(..._agents) {
|
|
|
20
24
|
};
|
|
21
25
|
}
|
|
22
26
|
function parallel(..._agents) {
|
|
27
|
+
(0, type_utils_js_1.checkArguments)("parallel", agentArraySchema, _agents);
|
|
23
28
|
let agents = [..._agents];
|
|
24
29
|
return async (input, context) => {
|
|
25
30
|
if (!context)
|
|
@@ -30,3 +35,4 @@ function parallel(..._agents) {
|
|
|
30
35
|
return Object.assign({}, ...outputs);
|
|
31
36
|
};
|
|
32
37
|
}
|
|
38
|
+
const agentArraySchema = zod_1.z.array(zod_1.z.union([zod_1.z.function(), zod_1.z.instanceof(agent_js_1.Agent)]));
|
package/lib/cjs/index.d.ts
CHANGED
|
@@ -8,7 +8,10 @@ export * from "./execution-engine/index.js";
|
|
|
8
8
|
export * from "./models/chat-model.js";
|
|
9
9
|
export * from "./models/claude-chat-model.js";
|
|
10
10
|
export * from "./models/openai-chat-model.js";
|
|
11
|
+
export * from "./models/xai-chat-model.js";
|
|
11
12
|
export * from "./prompt/prompt-builder.js";
|
|
12
13
|
export * from "./prompt/template.js";
|
|
14
|
+
export * from "./utils/json-schema.js";
|
|
13
15
|
export * from "./utils/logger.js";
|
|
14
16
|
export * from "./utils/run-chat-loop.js";
|
|
17
|
+
export * from "./utils/type-utils.js";
|
package/lib/cjs/index.js
CHANGED
|
@@ -24,7 +24,10 @@ __exportStar(require("./execution-engine/index.js"), exports);
|
|
|
24
24
|
__exportStar(require("./models/chat-model.js"), exports);
|
|
25
25
|
__exportStar(require("./models/claude-chat-model.js"), exports);
|
|
26
26
|
__exportStar(require("./models/openai-chat-model.js"), exports);
|
|
27
|
+
__exportStar(require("./models/xai-chat-model.js"), exports);
|
|
27
28
|
__exportStar(require("./prompt/prompt-builder.js"), exports);
|
|
28
29
|
__exportStar(require("./prompt/template.js"), exports);
|
|
30
|
+
__exportStar(require("./utils/json-schema.js"), exports);
|
|
29
31
|
__exportStar(require("./utils/logger.js"), exports);
|
|
30
32
|
__exportStar(require("./utils/run-chat-loop.js"), exports);
|
|
33
|
+
__exportStar(require("./utils/type-utils.js"), exports);
|
|
@@ -68,6 +68,7 @@ const chatModelOptionsSchema = zod_1.z.object({
|
|
|
68
68
|
topP: zod_1.z.number().optional(),
|
|
69
69
|
frequencyPenalty: zod_1.z.number().optional(),
|
|
70
70
|
presencePenalty: zod_1.z.number().optional(),
|
|
71
|
+
parallelToolCalls: zod_1.z.boolean().optional().default(true),
|
|
71
72
|
});
|
|
72
73
|
const chatModelInputSchema = zod_1.z.object({
|
|
73
74
|
messages: zod_1.z.array(chatModelInputMessageSchema),
|
|
@@ -1,16 +1,65 @@
|
|
|
1
1
|
import Anthropic from "@anthropic-ai/sdk";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { ChatModel, type ChatModelInput, type ChatModelOptions, type ChatModelOutput } from "./chat-model.js";
|
|
4
|
+
export interface ClaudeChatModelOptions {
|
|
5
|
+
apiKey?: string;
|
|
6
|
+
model?: string;
|
|
7
|
+
modelOptions?: ChatModelOptions;
|
|
8
|
+
}
|
|
9
|
+
export declare const claudeChatModelOptionsSchema: z.ZodObject<{
|
|
10
|
+
apiKey: z.ZodOptional<z.ZodString>;
|
|
11
|
+
model: z.ZodOptional<z.ZodString>;
|
|
12
|
+
modelOptions: z.ZodOptional<z.ZodObject<{
|
|
13
|
+
model: z.ZodOptional<z.ZodString>;
|
|
14
|
+
temperature: z.ZodOptional<z.ZodNumber>;
|
|
15
|
+
topP: z.ZodOptional<z.ZodNumber>;
|
|
16
|
+
frequencyPenalty: z.ZodOptional<z.ZodNumber>;
|
|
17
|
+
presencePenalty: z.ZodOptional<z.ZodNumber>;
|
|
18
|
+
parallelToolCalls: z.ZodDefault<z.ZodOptional<z.ZodBoolean>>;
|
|
19
|
+
}, "strip", z.ZodTypeAny, {
|
|
20
|
+
parallelToolCalls: boolean;
|
|
21
|
+
model?: string | undefined;
|
|
22
|
+
temperature?: number | undefined;
|
|
23
|
+
topP?: number | undefined;
|
|
24
|
+
frequencyPenalty?: number | undefined;
|
|
25
|
+
presencePenalty?: number | undefined;
|
|
26
|
+
}, {
|
|
27
|
+
model?: string | undefined;
|
|
28
|
+
temperature?: number | undefined;
|
|
29
|
+
topP?: number | undefined;
|
|
30
|
+
frequencyPenalty?: number | undefined;
|
|
31
|
+
presencePenalty?: number | undefined;
|
|
32
|
+
parallelToolCalls?: boolean | undefined;
|
|
33
|
+
}>>;
|
|
34
|
+
}, "strip", z.ZodTypeAny, {
|
|
35
|
+
modelOptions?: {
|
|
36
|
+
parallelToolCalls: boolean;
|
|
37
|
+
model?: string | undefined;
|
|
38
|
+
temperature?: number | undefined;
|
|
39
|
+
topP?: number | undefined;
|
|
40
|
+
frequencyPenalty?: number | undefined;
|
|
41
|
+
presencePenalty?: number | undefined;
|
|
7
42
|
} | undefined;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
43
|
+
model?: string | undefined;
|
|
44
|
+
apiKey?: string | undefined;
|
|
45
|
+
}, {
|
|
46
|
+
modelOptions?: {
|
|
47
|
+
model?: string | undefined;
|
|
48
|
+
temperature?: number | undefined;
|
|
49
|
+
topP?: number | undefined;
|
|
50
|
+
frequencyPenalty?: number | undefined;
|
|
51
|
+
presencePenalty?: number | undefined;
|
|
52
|
+
parallelToolCalls?: boolean | undefined;
|
|
53
|
+
} | undefined;
|
|
54
|
+
model?: string | undefined;
|
|
55
|
+
apiKey?: string | undefined;
|
|
56
|
+
}>;
|
|
57
|
+
export declare class ClaudeChatModel extends ChatModel {
|
|
58
|
+
options?: ClaudeChatModelOptions | undefined;
|
|
59
|
+
constructor(options?: ClaudeChatModelOptions | undefined);
|
|
12
60
|
private _client?;
|
|
13
61
|
get client(): Anthropic;
|
|
62
|
+
get modelOptions(): ChatModelOptions | undefined;
|
|
14
63
|
process(input: ChatModelInput): Promise<ChatModelOutput>;
|
|
15
64
|
private extractResultFromClaudeStream;
|
|
16
65
|
private requestStructuredOutput;
|