@aigne/core 1.32.2 → 1.33.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 +7 -0
- package/README.md +0 -2
- package/lib/cjs/loader/agent-js.js +8 -8
- package/lib/cjs/loader/agent-yaml.d.ts +2 -2
- package/lib/cjs/loader/agent-yaml.js +2 -2
- package/lib/cjs/loader/schema.d.ts +9 -2
- package/lib/cjs/loader/schema.js +43 -6
- package/lib/dts/loader/agent-yaml.d.ts +2 -2
- package/lib/dts/loader/schema.d.ts +9 -2
- package/lib/esm/loader/agent-js.js +8 -8
- package/lib/esm/loader/agent-yaml.d.ts +2 -2
- package/lib/esm/loader/agent-yaml.js +2 -2
- package/lib/esm/loader/schema.d.ts +9 -2
- package/lib/esm/loader/schema.js +42 -6
- package/package.json +1 -1
- package/README.zh.md +0 -79
package/CHANGELOG.md
CHANGED
|
@@ -12,6 +12,13 @@
|
|
|
12
12
|
* dependencies
|
|
13
13
|
* @aigne/observability bumped to 0.1.0
|
|
14
14
|
|
|
15
|
+
## [1.33.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.32.2...core-v1.33.0) (2025-07-10)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
### Features
|
|
19
|
+
|
|
20
|
+
* **core:** support external files as agent input/output schema ([#242](https://github.com/AIGNE-io/aigne-framework/issues/242)) ([58f8de6](https://github.com/AIGNE-io/aigne-framework/commit/58f8de63008b78ea1b404ba7721c3a242c330113))
|
|
21
|
+
|
|
15
22
|
## [1.32.2](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.32.1...core-v1.32.2) (2025-07-09)
|
|
16
23
|
|
|
17
24
|
|
package/README.md
CHANGED
|
@@ -6,8 +6,6 @@
|
|
|
6
6
|
[](https://www.npmjs.com/package/@aigne/core)
|
|
7
7
|
[](https://github.com/AIGNE-io/aigne-framework/blob/main/LICENSE)
|
|
8
8
|
|
|
9
|
-
**English** | [中文](./README.zh.md)
|
|
10
|
-
|
|
11
9
|
Core library of [AIGNE Framework](https://github.com/AIGNE-io/aigne-framework) for building AI-powered applications.
|
|
12
10
|
|
|
13
11
|
## Introduction
|
|
@@ -43,21 +43,21 @@ const zod_1 = require("zod");
|
|
|
43
43
|
const agent_js_1 = require("../agents/agent.js");
|
|
44
44
|
const type_utils_js_1 = require("../utils/type-utils.js");
|
|
45
45
|
const schema_js_1 = require("./schema.js");
|
|
46
|
-
const agentJsFileSchema = zod_1.z.object({
|
|
47
|
-
name: zod_1.z.string(),
|
|
48
|
-
description: (0, schema_js_1.optionalize)(zod_1.z.string()),
|
|
49
|
-
inputSchema: (0, schema_js_1.optionalize)(schema_js_1.inputOutputSchema).transform((v) => v ? (0, json_schema_to_zod_1.jsonSchemaToZod)(v) : undefined),
|
|
50
|
-
outputSchema: (0, schema_js_1.optionalize)(schema_js_1.inputOutputSchema).transform((v) => v ? (0, json_schema_to_zod_1.jsonSchemaToZod)(v) : undefined),
|
|
51
|
-
process: zod_1.z.custom(),
|
|
52
|
-
});
|
|
53
46
|
async function loadAgentFromJsFile(path) {
|
|
47
|
+
const agentJsFileSchema = zod_1.z.object({
|
|
48
|
+
name: zod_1.z.string(),
|
|
49
|
+
description: (0, schema_js_1.optionalize)(zod_1.z.string()),
|
|
50
|
+
inputSchema: (0, schema_js_1.optionalize)((0, schema_js_1.inputOutputSchema)({ path })).transform((v) => v ? (0, json_schema_to_zod_1.jsonSchemaToZod)(v) : undefined),
|
|
51
|
+
outputSchema: (0, schema_js_1.optionalize)((0, schema_js_1.inputOutputSchema)({ path })).transform((v) => v ? (0, json_schema_to_zod_1.jsonSchemaToZod)(v) : undefined),
|
|
52
|
+
process: zod_1.z.custom(),
|
|
53
|
+
});
|
|
54
54
|
const { default: agent } = await (0, type_utils_js_1.tryOrThrow)(() => Promise.resolve(`${path}`).then(s => __importStar(require(s))), (error) => new Error(`Failed to load agent definition from ${path}: ${error.message}`));
|
|
55
55
|
if (agent instanceof agent_js_1.Agent)
|
|
56
56
|
return agent;
|
|
57
57
|
if (typeof agent !== "function") {
|
|
58
58
|
throw new Error(`Agent file ${path} must export a default function, but got ${typeof agent}`);
|
|
59
59
|
}
|
|
60
|
-
return (0, type_utils_js_1.tryOrThrow)(() => agentJsFileSchema.
|
|
60
|
+
return (0, type_utils_js_1.tryOrThrow)(() => agentJsFileSchema.parseAsync((0, camelize_ts_1.default)({
|
|
61
61
|
...agent,
|
|
62
62
|
name: agent.agent_name || agent.agentName || agent.name,
|
|
63
63
|
process: agent,
|
|
@@ -4,8 +4,8 @@ import { ProcessMode } from "../agents/team-agent.js";
|
|
|
4
4
|
interface BaseAgentSchema {
|
|
5
5
|
name?: string;
|
|
6
6
|
description?: string;
|
|
7
|
-
inputSchema?: ZodType<Record<string,
|
|
8
|
-
outputSchema?: ZodType<Record<string,
|
|
7
|
+
inputSchema?: ZodType<Record<string, any>>;
|
|
8
|
+
outputSchema?: ZodType<Record<string, any>>;
|
|
9
9
|
skills?: (string | AgentSchema)[];
|
|
10
10
|
memory?: boolean | {
|
|
11
11
|
provider: string;
|
|
@@ -18,8 +18,8 @@ async function loadAgentFromYamlFile(path) {
|
|
|
18
18
|
const baseAgentSchema = zod_1.z.object({
|
|
19
19
|
name: (0, schema_js_1.optionalize)(zod_1.z.string()),
|
|
20
20
|
description: (0, schema_js_1.optionalize)(zod_1.z.string()),
|
|
21
|
-
inputSchema: (0, schema_js_1.optionalize)(schema_js_1.inputOutputSchema).transform((v) => v ? (0, json_schema_to_zod_1.jsonSchemaToZod)(v) : undefined),
|
|
22
|
-
outputSchema: (0, schema_js_1.optionalize)(schema_js_1.inputOutputSchema).transform((v) => v ? (0, json_schema_to_zod_1.jsonSchemaToZod)(v) : undefined),
|
|
21
|
+
inputSchema: (0, schema_js_1.optionalize)((0, schema_js_1.inputOutputSchema)({ path })).transform((v) => v ? (0, json_schema_to_zod_1.jsonSchemaToZod)(v) : undefined),
|
|
22
|
+
outputSchema: (0, schema_js_1.optionalize)((0, schema_js_1.inputOutputSchema)({ path })).transform((v) => v ? (0, json_schema_to_zod_1.jsonSchemaToZod)(v) : undefined),
|
|
23
23
|
skills: (0, schema_js_1.optionalize)(zod_1.z.array(zod_1.z.union([zod_1.z.string(), agentSchema]))),
|
|
24
24
|
memory: (0, schema_js_1.optionalize)(zod_1.z.union([
|
|
25
25
|
zod_1.z.boolean(),
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { type ZodType, z } from "zod";
|
|
2
|
-
export declare const inputOutputSchema:
|
|
2
|
+
export declare const inputOutputSchema: ({ path }: {
|
|
3
|
+
path: string;
|
|
4
|
+
}) => z.ZodUnion<[ZodType<any, z.ZodTypeDef, any>, z.ZodEffects<z.ZodObject<{
|
|
3
5
|
type: z.ZodLiteral<"object">;
|
|
4
6
|
properties: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
5
7
|
required: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
@@ -14,5 +16,10 @@ export declare const inputOutputSchema: z.ZodObject<{
|
|
|
14
16
|
properties: Record<string, any>;
|
|
15
17
|
required?: string[] | undefined;
|
|
16
18
|
additionalProperties?: boolean | undefined;
|
|
17
|
-
}
|
|
19
|
+
}>, any, {
|
|
20
|
+
type: "object";
|
|
21
|
+
properties: Record<string, any>;
|
|
22
|
+
required?: string[] | undefined;
|
|
23
|
+
additionalProperties?: boolean | undefined;
|
|
24
|
+
}>]>;
|
|
18
25
|
export declare function optionalize<T>(schema: ZodType<T>): ZodType<T | undefined>;
|
package/lib/cjs/loader/schema.js
CHANGED
|
@@ -2,13 +2,50 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.inputOutputSchema = void 0;
|
|
4
4
|
exports.optionalize = optionalize;
|
|
5
|
+
const index_js_1 = require("@aigne/platform-helpers/nodejs/index.js");
|
|
6
|
+
const yaml_1 = require("yaml");
|
|
5
7
|
const zod_1 = require("zod");
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
8
|
+
const inputOutputSchema = ({ path }) => {
|
|
9
|
+
const jsonSchemaSchema = zod_1.z
|
|
10
|
+
.object({
|
|
11
|
+
type: zod_1.z.literal("object"),
|
|
12
|
+
properties: zod_1.z.record(zod_1.z.any()),
|
|
13
|
+
required: zod_1.z.array(zod_1.z.string()).optional(),
|
|
14
|
+
additionalProperties: zod_1.z.boolean().optional(),
|
|
15
|
+
})
|
|
16
|
+
.transform((v) => {
|
|
17
|
+
const t = async (schema) => {
|
|
18
|
+
if (schema?.type === "object" && schema.properties) {
|
|
19
|
+
return {
|
|
20
|
+
...schema,
|
|
21
|
+
properties: Object.fromEntries(await Promise.all(Object.entries(schema.properties).map(async ([key, value]) => [
|
|
22
|
+
key,
|
|
23
|
+
await t(value),
|
|
24
|
+
]))),
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
if (schema?.type === "array" && schema.items) {
|
|
28
|
+
return { ...schema, items: await t(schema.items) };
|
|
29
|
+
}
|
|
30
|
+
// Load nested schemas from file
|
|
31
|
+
if (typeof schema === "string") {
|
|
32
|
+
const raw = await index_js_1.nodejs.fs.readFile(index_js_1.nodejs.path.join(index_js_1.nodejs.path.dirname(path), schema), "utf8");
|
|
33
|
+
return jsonSchemaSchema.parseAsync((0, yaml_1.parse)(raw));
|
|
34
|
+
}
|
|
35
|
+
return schema;
|
|
36
|
+
};
|
|
37
|
+
return t(v);
|
|
38
|
+
});
|
|
39
|
+
return zod_1.z.union([
|
|
40
|
+
zod_1.z
|
|
41
|
+
.string()
|
|
42
|
+
.transform((v) => index_js_1.nodejs.fs
|
|
43
|
+
.readFile(index_js_1.nodejs.path.join(index_js_1.nodejs.path.dirname(path), v), "utf8")
|
|
44
|
+
.then((raw) => jsonSchemaSchema.parseAsync((0, yaml_1.parse)(raw)))),
|
|
45
|
+
jsonSchemaSchema,
|
|
46
|
+
]);
|
|
47
|
+
};
|
|
48
|
+
exports.inputOutputSchema = inputOutputSchema;
|
|
12
49
|
function optionalize(schema) {
|
|
13
50
|
return schema.nullish().transform((v) => v ?? undefined);
|
|
14
51
|
}
|
|
@@ -4,8 +4,8 @@ import { ProcessMode } from "../agents/team-agent.js";
|
|
|
4
4
|
interface BaseAgentSchema {
|
|
5
5
|
name?: string;
|
|
6
6
|
description?: string;
|
|
7
|
-
inputSchema?: ZodType<Record<string,
|
|
8
|
-
outputSchema?: ZodType<Record<string,
|
|
7
|
+
inputSchema?: ZodType<Record<string, any>>;
|
|
8
|
+
outputSchema?: ZodType<Record<string, any>>;
|
|
9
9
|
skills?: (string | AgentSchema)[];
|
|
10
10
|
memory?: boolean | {
|
|
11
11
|
provider: string;
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { type ZodType, z } from "zod";
|
|
2
|
-
export declare const inputOutputSchema:
|
|
2
|
+
export declare const inputOutputSchema: ({ path }: {
|
|
3
|
+
path: string;
|
|
4
|
+
}) => z.ZodUnion<[ZodType<any, z.ZodTypeDef, any>, z.ZodEffects<z.ZodObject<{
|
|
3
5
|
type: z.ZodLiteral<"object">;
|
|
4
6
|
properties: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
5
7
|
required: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
@@ -14,5 +16,10 @@ export declare const inputOutputSchema: z.ZodObject<{
|
|
|
14
16
|
properties: Record<string, any>;
|
|
15
17
|
required?: string[] | undefined;
|
|
16
18
|
additionalProperties?: boolean | undefined;
|
|
17
|
-
}
|
|
19
|
+
}>, any, {
|
|
20
|
+
type: "object";
|
|
21
|
+
properties: Record<string, any>;
|
|
22
|
+
required?: string[] | undefined;
|
|
23
|
+
additionalProperties?: boolean | undefined;
|
|
24
|
+
}>]>;
|
|
18
25
|
export declare function optionalize<T>(schema: ZodType<T>): ZodType<T | undefined>;
|
|
@@ -4,21 +4,21 @@ import { z } from "zod";
|
|
|
4
4
|
import { Agent } from "../agents/agent.js";
|
|
5
5
|
import { tryOrThrow } from "../utils/type-utils.js";
|
|
6
6
|
import { inputOutputSchema, optionalize } from "./schema.js";
|
|
7
|
-
const agentJsFileSchema = z.object({
|
|
8
|
-
name: z.string(),
|
|
9
|
-
description: optionalize(z.string()),
|
|
10
|
-
inputSchema: optionalize(inputOutputSchema).transform((v) => v ? jsonSchemaToZod(v) : undefined),
|
|
11
|
-
outputSchema: optionalize(inputOutputSchema).transform((v) => v ? jsonSchemaToZod(v) : undefined),
|
|
12
|
-
process: z.custom(),
|
|
13
|
-
});
|
|
14
7
|
export async function loadAgentFromJsFile(path) {
|
|
8
|
+
const agentJsFileSchema = z.object({
|
|
9
|
+
name: z.string(),
|
|
10
|
+
description: optionalize(z.string()),
|
|
11
|
+
inputSchema: optionalize(inputOutputSchema({ path })).transform((v) => v ? jsonSchemaToZod(v) : undefined),
|
|
12
|
+
outputSchema: optionalize(inputOutputSchema({ path })).transform((v) => v ? jsonSchemaToZod(v) : undefined),
|
|
13
|
+
process: z.custom(),
|
|
14
|
+
});
|
|
15
15
|
const { default: agent } = await tryOrThrow(() => import(/* @vite-ignore */ path), (error) => new Error(`Failed to load agent definition from ${path}: ${error.message}`));
|
|
16
16
|
if (agent instanceof Agent)
|
|
17
17
|
return agent;
|
|
18
18
|
if (typeof agent !== "function") {
|
|
19
19
|
throw new Error(`Agent file ${path} must export a default function, but got ${typeof agent}`);
|
|
20
20
|
}
|
|
21
|
-
return tryOrThrow(() => agentJsFileSchema.
|
|
21
|
+
return tryOrThrow(() => agentJsFileSchema.parseAsync(camelize({
|
|
22
22
|
...agent,
|
|
23
23
|
name: agent.agent_name || agent.agentName || agent.name,
|
|
24
24
|
process: agent,
|
|
@@ -4,8 +4,8 @@ import { ProcessMode } from "../agents/team-agent.js";
|
|
|
4
4
|
interface BaseAgentSchema {
|
|
5
5
|
name?: string;
|
|
6
6
|
description?: string;
|
|
7
|
-
inputSchema?: ZodType<Record<string,
|
|
8
|
-
outputSchema?: ZodType<Record<string,
|
|
7
|
+
inputSchema?: ZodType<Record<string, any>>;
|
|
8
|
+
outputSchema?: ZodType<Record<string, any>>;
|
|
9
9
|
skills?: (string | AgentSchema)[];
|
|
10
10
|
memory?: boolean | {
|
|
11
11
|
provider: string;
|
|
@@ -12,8 +12,8 @@ export async function loadAgentFromYamlFile(path) {
|
|
|
12
12
|
const baseAgentSchema = z.object({
|
|
13
13
|
name: optionalize(z.string()),
|
|
14
14
|
description: optionalize(z.string()),
|
|
15
|
-
inputSchema: optionalize(inputOutputSchema).transform((v) => v ? jsonSchemaToZod(v) : undefined),
|
|
16
|
-
outputSchema: optionalize(inputOutputSchema).transform((v) => v ? jsonSchemaToZod(v) : undefined),
|
|
15
|
+
inputSchema: optionalize(inputOutputSchema({ path })).transform((v) => v ? jsonSchemaToZod(v) : undefined),
|
|
16
|
+
outputSchema: optionalize(inputOutputSchema({ path })).transform((v) => v ? jsonSchemaToZod(v) : undefined),
|
|
17
17
|
skills: optionalize(z.array(z.union([z.string(), agentSchema]))),
|
|
18
18
|
memory: optionalize(z.union([
|
|
19
19
|
z.boolean(),
|
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { type ZodType, z } from "zod";
|
|
2
|
-
export declare const inputOutputSchema:
|
|
2
|
+
export declare const inputOutputSchema: ({ path }: {
|
|
3
|
+
path: string;
|
|
4
|
+
}) => z.ZodUnion<[ZodType<any, z.ZodTypeDef, any>, z.ZodEffects<z.ZodObject<{
|
|
3
5
|
type: z.ZodLiteral<"object">;
|
|
4
6
|
properties: z.ZodRecord<z.ZodString, z.ZodAny>;
|
|
5
7
|
required: z.ZodOptional<z.ZodArray<z.ZodString, "many">>;
|
|
@@ -14,5 +16,10 @@ export declare const inputOutputSchema: z.ZodObject<{
|
|
|
14
16
|
properties: Record<string, any>;
|
|
15
17
|
required?: string[] | undefined;
|
|
16
18
|
additionalProperties?: boolean | undefined;
|
|
17
|
-
}
|
|
19
|
+
}>, any, {
|
|
20
|
+
type: "object";
|
|
21
|
+
properties: Record<string, any>;
|
|
22
|
+
required?: string[] | undefined;
|
|
23
|
+
additionalProperties?: boolean | undefined;
|
|
24
|
+
}>]>;
|
|
18
25
|
export declare function optionalize<T>(schema: ZodType<T>): ZodType<T | undefined>;
|
package/lib/esm/loader/schema.js
CHANGED
|
@@ -1,10 +1,46 @@
|
|
|
1
|
+
import { nodejs } from "@aigne/platform-helpers/nodejs/index.js";
|
|
2
|
+
import { parse } from "yaml";
|
|
1
3
|
import { z } from "zod";
|
|
2
|
-
export const inputOutputSchema =
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
4
|
+
export const inputOutputSchema = ({ path }) => {
|
|
5
|
+
const jsonSchemaSchema = z
|
|
6
|
+
.object({
|
|
7
|
+
type: z.literal("object"),
|
|
8
|
+
properties: z.record(z.any()),
|
|
9
|
+
required: z.array(z.string()).optional(),
|
|
10
|
+
additionalProperties: z.boolean().optional(),
|
|
11
|
+
})
|
|
12
|
+
.transform((v) => {
|
|
13
|
+
const t = async (schema) => {
|
|
14
|
+
if (schema?.type === "object" && schema.properties) {
|
|
15
|
+
return {
|
|
16
|
+
...schema,
|
|
17
|
+
properties: Object.fromEntries(await Promise.all(Object.entries(schema.properties).map(async ([key, value]) => [
|
|
18
|
+
key,
|
|
19
|
+
await t(value),
|
|
20
|
+
]))),
|
|
21
|
+
};
|
|
22
|
+
}
|
|
23
|
+
if (schema?.type === "array" && schema.items) {
|
|
24
|
+
return { ...schema, items: await t(schema.items) };
|
|
25
|
+
}
|
|
26
|
+
// Load nested schemas from file
|
|
27
|
+
if (typeof schema === "string") {
|
|
28
|
+
const raw = await nodejs.fs.readFile(nodejs.path.join(nodejs.path.dirname(path), schema), "utf8");
|
|
29
|
+
return jsonSchemaSchema.parseAsync(parse(raw));
|
|
30
|
+
}
|
|
31
|
+
return schema;
|
|
32
|
+
};
|
|
33
|
+
return t(v);
|
|
34
|
+
});
|
|
35
|
+
return z.union([
|
|
36
|
+
z
|
|
37
|
+
.string()
|
|
38
|
+
.transform((v) => nodejs.fs
|
|
39
|
+
.readFile(nodejs.path.join(nodejs.path.dirname(path), v), "utf8")
|
|
40
|
+
.then((raw) => jsonSchemaSchema.parseAsync(parse(raw)))),
|
|
41
|
+
jsonSchemaSchema,
|
|
42
|
+
]);
|
|
43
|
+
};
|
|
8
44
|
export function optionalize(schema) {
|
|
9
45
|
return schema.nullish().transform((v) => v ?? undefined);
|
|
10
46
|
}
|
package/package.json
CHANGED
package/README.zh.md
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
1
|
-
# @aigne/core
|
|
2
|
-
|
|
3
|
-
[](https://star-history.com/#AIGNE-io/aigne-framework)
|
|
4
|
-
[](https://github.com/AIGNE-io/aigne-framework/issues)
|
|
5
|
-
[](https://codecov.io/gh/AIGNE-io/aigne-framework)
|
|
6
|
-
[](https://www.npmjs.com/package/@aigne/core)
|
|
7
|
-
[](https://github.com/AIGNE-io/aigne-framework/blob/main/LICENSE)
|
|
8
|
-
|
|
9
|
-
[English](./README.md) | **中文**
|
|
10
|
-
|
|
11
|
-
[AIGNE Framework](https://github.com/AIGNE-io/aigne-framework) 的核心库,用于构建 AI 驱动的应用程序。
|
|
12
|
-
|
|
13
|
-
## 简介
|
|
14
|
-
|
|
15
|
-
`@aigne/core` 是 [AIGNE Framework](https://github.com/AIGNE-io/aigne-framework) 的基础组件,提供构建 AI 驱动应用程序所需的核心模块和工具。该包实现了框架的核心功能,包括代理系统、aigne 环境、模型集成和工作流模式支持。
|
|
16
|
-
|
|
17
|
-
## 特性
|
|
18
|
-
|
|
19
|
-
* **多 AI 模型支持**:内置支持 OpenAI、Gemini、Claude、Nova 等主流 AI 模型,可轻松扩展支持其他模型
|
|
20
|
-
* **代理系统**:强大的代理抽象,支持 AI 代理、功能代理、MCP 代理等
|
|
21
|
-
* **AIGNE 环境**:灵活处理代理之间的通信和工作流执行
|
|
22
|
-
* **工作流模式**:支持顺序、并发、路由、交接等多种工作流模式
|
|
23
|
-
* **MCP 协议集成**:通过模型上下文协议与外部系统无缝集成
|
|
24
|
-
* **TypeScript 支持**:全面的类型定义,提供出色的开发体验
|
|
25
|
-
|
|
26
|
-
## 安装
|
|
27
|
-
|
|
28
|
-
### 使用 npm
|
|
29
|
-
|
|
30
|
-
```bash
|
|
31
|
-
npm install @aigne/core
|
|
32
|
-
```
|
|
33
|
-
|
|
34
|
-
### 使用 yarn
|
|
35
|
-
|
|
36
|
-
```bash
|
|
37
|
-
yarn add @aigne/core
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
### 使用 pnpm
|
|
41
|
-
|
|
42
|
-
```bash
|
|
43
|
-
pnpm add @aigne/core
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
## 基本用法
|
|
47
|
-
|
|
48
|
-
```typescript
|
|
49
|
-
import { AIAgent, AIGNE } from "@aigne/core";
|
|
50
|
-
import { OpenAIChatModel } from "@aigne/core/models/openai-chat-model.js";
|
|
51
|
-
|
|
52
|
-
// 创建 AI 模型实例
|
|
53
|
-
const model = new OpenAIChatModel({
|
|
54
|
-
apiKey: process.env.OPENAI_API_KEY,
|
|
55
|
-
model: process.env.DEFAULT_CHAT_MODEL || "gpt-4-turbo",
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
// 创建 AI 代理
|
|
59
|
-
const agent = AIAgent.from({
|
|
60
|
-
name: "Assistant",
|
|
61
|
-
instructions: "You are a helpful assistant.",
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
// AIGNE: AIGNE Framework 的主要执行引擎
|
|
65
|
-
const aigne = new AIGNE({ model });
|
|
66
|
-
|
|
67
|
-
// 使用 AIGNE 调用代理
|
|
68
|
-
const userAgent = await aigne.invoke(agent);
|
|
69
|
-
|
|
70
|
-
// 向代理发送消息
|
|
71
|
-
const response = await userAgent.invoke(
|
|
72
|
-
"Hello, can you help me write a short article?",
|
|
73
|
-
);
|
|
74
|
-
console.log(response);
|
|
75
|
-
```
|
|
76
|
-
|
|
77
|
-
## 许可证
|
|
78
|
-
|
|
79
|
-
Elastic-2.0
|