@aigne/agent-library 1.3.1 → 1.4.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 CHANGED
@@ -2,6 +2,22 @@
2
2
 
3
3
  - chore: release 1.2.0
4
4
 
5
+ ## [1.4.0](https://github.com/AIGNE-io/aigne-framework/compare/agent-library-v1.3.2...agent-library-v1.4.0) (2025-04-08)
6
+
7
+
8
+ ### Features
9
+
10
+ * add `serve` command for @aigne/cli ([#54](https://github.com/AIGNE-io/aigne-framework/issues/54)) ([1cca843](https://github.com/AIGNE-io/aigne-framework/commit/1cca843f1760abe832b6651108fa858130f47355))
11
+ * add agent library support ([#51](https://github.com/AIGNE-io/aigne-framework/issues/51)) ([1f0d34d](https://github.com/AIGNE-io/aigne-framework/commit/1f0d34ddda3154283a4bc958ddb9b68b4ac106b0))
12
+ * support token/call/time limits for ExecutionEngine ([#44](https://github.com/AIGNE-io/aigne-framework/issues/44)) ([5a2ca0a](https://github.com/AIGNE-io/aigne-framework/commit/5a2ca0a033267dd4765f574b53dca71e932e53d4))
13
+
14
+ ## [1.3.2](https://github.com/AIGNE-io/aigne-framework/compare/agent-library-v1.3.1...agent-library-v1.3.2) (2025-03-27)
15
+
16
+
17
+ ### Bug Fixes
18
+
19
+ * **dx:** export models/utils in submodules ([#43](https://github.com/AIGNE-io/aigne-framework/issues/43)) ([bd561b3](https://github.com/AIGNE-io/aigne-framework/commit/bd561b397de816f04c2d63d58538e81fba82fc7f))
20
+
5
21
  ## [1.3.1](https://github.com/AIGNE-io/aigne-framework/compare/agent-library-v1.3.0...agent-library-v1.3.1) (2025-03-26)
6
22
 
7
23
 
@@ -1 +1 @@
1
- export * from "./orchestrator/index.js";
1
+ export {};
package/lib/cjs/index.js CHANGED
@@ -1,17 +1,2 @@
1
1
  "use strict";
2
- var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
- if (k2 === undefined) k2 = k;
4
- var desc = Object.getOwnPropertyDescriptor(m, k);
5
- if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
- desc = { enumerable: true, get: function() { return m[k]; } };
7
- }
8
- Object.defineProperty(o, k2, desc);
9
- }) : (function(o, m, k, k2) {
10
- if (k2 === undefined) k2 = k;
11
- o[k2] = m[k];
12
- }));
13
- var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
- for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
- };
16
2
  Object.defineProperty(exports, "__esModule", { value: true });
17
- __exportStar(require("./orchestrator/index.js"), exports);
@@ -19,7 +19,7 @@ export declare class OrchestratorAgent<I extends Message = Message, O extends Me
19
19
  private completer;
20
20
  maxIterations?: number;
21
21
  tasksConcurrency?: number;
22
- process(input: I, context?: Context): Promise<O>;
22
+ process(input: I, context: Context): Promise<O>;
23
23
  private getFullPlanInput;
24
24
  private getFullPlan;
25
25
  private synthesizePlanResult;
@@ -19,7 +19,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
19
19
  Object.defineProperty(exports, "__esModule", { value: true });
20
20
  exports.OrchestratorAgent = void 0;
21
21
  const core_1 = require("@aigne/core");
22
+ const type_utils_js_1 = require("@aigne/core/utils/type-utils.js");
22
23
  const fastq_1 = __importDefault(require("fastq"));
24
+ const zod_1 = require("zod");
23
25
  const orchestrator_prompts_js_1 = require("./orchestrator-prompts.js");
24
26
  const DEFAULT_MAX_ITERATIONS = 30;
25
27
  const DEFAULT_TASK_CONCURRENCY = 5;
@@ -29,6 +31,7 @@ class OrchestratorAgent extends core_1.Agent {
29
31
  return new OrchestratorAgent(options);
30
32
  }
31
33
  constructor(options) {
34
+ (0, type_utils_js_1.checkArguments)("OrchestratorAgent", orchestratorAgentOptionsSchema, options);
32
35
  super({ ...options });
33
36
  this.maxIterations = options.maxIterations;
34
37
  this.tasksConcurrency = options.tasksConcurrency;
@@ -48,7 +51,7 @@ class OrchestratorAgent extends core_1.Agent {
48
51
  maxIterations;
49
52
  tasksConcurrency;
50
53
  async process(input, context) {
51
- const model = context?.model;
54
+ const { model } = context;
52
55
  if (!model)
53
56
  throw new Error("model is required to run OrchestratorAgent");
54
57
  const objective = (0, core_1.getMessage)(input);
@@ -99,7 +102,7 @@ class OrchestratorAgent extends core_1.Agent {
99
102
  }
100
103
  async executeStep(planResult, step, context) {
101
104
  const concurrency = this.tasksConcurrency ?? DEFAULT_TASK_CONCURRENCY;
102
- const model = context?.model;
105
+ const { model } = context;
103
106
  if (!model)
104
107
  throw new Error("model is required to run OrchestratorAgent");
105
108
  const queue = fastq_1.default.promise(async (task) => {
@@ -156,3 +159,7 @@ function getMessageOrJsonString(output) {
156
159
  }
157
160
  return JSON.stringify(output);
158
161
  }
162
+ const orchestratorAgentOptionsSchema = zod_1.z.object({
163
+ maxIterations: zod_1.z.number().optional(),
164
+ tasksConcurrency: zod_1.z.number().optional(),
165
+ });
@@ -1,4 +1,4 @@
1
- import { type Agent, type Message } from "@aigne/core";
1
+ import type { Agent, Message } from "@aigne/core";
2
2
  import { z } from "zod";
3
3
  export declare const SYNTHESIZE_PLAN_USER_PROMPT_TEMPLATE = "Synthesize the results of executing all steps in the plan into a cohesive result\n";
4
4
  export declare function getFullPlanSchema(agents: Agent[]): z.ZodObject<{
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SYNTHESIZE_STEP_PROMPT_TEMPLATE = exports.TASK_PROMPT_TEMPLATE = exports.FULL_PLAN_PROMPT_TEMPLATE = exports.SYNTHESIZE_PLAN_USER_PROMPT_TEMPLATE = void 0;
4
4
  exports.getFullPlanSchema = getFullPlanSchema;
5
- const core_1 = require("@aigne/core");
6
- const lodash_es_1 = require("lodash-es");
5
+ const json_schema_js_1 = require("@aigne/core/utils/json-schema.js");
6
+ const type_utils_js_1 = require("@aigne/core/utils/type-utils.js");
7
7
  const zod_1 = require("zod");
8
8
  exports.SYNTHESIZE_PLAN_USER_PROMPT_TEMPLATE = `\
9
9
  Synthesize the results of executing all steps in the plan into a cohesive result
@@ -11,13 +11,13 @@ Synthesize the results of executing all steps in the plan into a cohesive result
11
11
  function getFullPlanSchema(agents) {
12
12
  const agentNames = agents.map((i) => i.name);
13
13
  if (new Set(agentNames).size !== agentNames.length) {
14
- const duplicates = (0, lodash_es_1.pickBy)((0, lodash_es_1.groupBy)(agentNames), (x) => x.length > 1);
15
- throw new Error(`Tools name must be unique for orchestrator: ${Object.keys(duplicates).join(",")}`);
14
+ const dup = (0, type_utils_js_1.duplicates)(agentNames);
15
+ throw new Error(`Duplicate agent names found in orchestrator: ${dup.join(",")}`);
16
16
  }
17
17
  const TaskSchema = zod_1.z.object({
18
18
  description: zod_1.z.string().describe("Detailed description of the task"),
19
19
  agent: zod_1.z
20
- .union((0, core_1.ensureZodUnionArray)(agents.map((i) => zod_1.z.literal(i.name))))
20
+ .union((0, json_schema_js_1.ensureZodUnionArray)(agents.map((i) => zod_1.z.literal(i.name))))
21
21
  .describe("Name of the agent to execute the task"),
22
22
  });
23
23
  const StepSchema = zod_1.z.object({
@@ -1 +1 @@
1
- export * from "./orchestrator/index.js";
1
+ export {};
@@ -19,7 +19,7 @@ export declare class OrchestratorAgent<I extends Message = Message, O extends Me
19
19
  private completer;
20
20
  maxIterations?: number;
21
21
  tasksConcurrency?: number;
22
- process(input: I, context?: Context): Promise<O>;
22
+ process(input: I, context: Context): Promise<O>;
23
23
  private getFullPlanInput;
24
24
  private getFullPlan;
25
25
  private synthesizePlanResult;
@@ -1,4 +1,4 @@
1
- import { type Agent, type Message } from "@aigne/core";
1
+ import type { Agent, Message } from "@aigne/core";
2
2
  import { z } from "zod";
3
3
  export declare const SYNTHESIZE_PLAN_USER_PROMPT_TEMPLATE = "Synthesize the results of executing all steps in the plan into a cohesive result\n";
4
4
  export declare function getFullPlanSchema(agents: Agent[]): z.ZodObject<{
@@ -1 +1 @@
1
- export * from "./orchestrator/index.js";
1
+ export {};
package/lib/esm/index.js CHANGED
@@ -1 +1 @@
1
- export * from "./orchestrator/index.js";
1
+ export {};
@@ -19,7 +19,7 @@ export declare class OrchestratorAgent<I extends Message = Message, O extends Me
19
19
  private completer;
20
20
  maxIterations?: number;
21
21
  tasksConcurrency?: number;
22
- process(input: I, context?: Context): Promise<O>;
22
+ process(input: I, context: Context): Promise<O>;
23
23
  private getFullPlanInput;
24
24
  private getFullPlan;
25
25
  private synthesizePlanResult;
@@ -1,5 +1,7 @@
1
1
  import { AIAgent, Agent, PromptTemplate, createMessage, getMessage, } from "@aigne/core";
2
+ import { checkArguments } from "@aigne/core/utils/type-utils.js";
2
3
  import fastq from "fastq";
4
+ import { z } from "zod";
3
5
  import { FULL_PLAN_PROMPT_TEMPLATE, SYNTHESIZE_PLAN_USER_PROMPT_TEMPLATE, SYNTHESIZE_STEP_PROMPT_TEMPLATE, TASK_PROMPT_TEMPLATE, getFullPlanSchema, } from "./orchestrator-prompts.js";
4
6
  const DEFAULT_MAX_ITERATIONS = 30;
5
7
  const DEFAULT_TASK_CONCURRENCY = 5;
@@ -9,6 +11,7 @@ export class OrchestratorAgent extends Agent {
9
11
  return new OrchestratorAgent(options);
10
12
  }
11
13
  constructor(options) {
14
+ checkArguments("OrchestratorAgent", orchestratorAgentOptionsSchema, options);
12
15
  super({ ...options });
13
16
  this.maxIterations = options.maxIterations;
14
17
  this.tasksConcurrency = options.tasksConcurrency;
@@ -28,7 +31,7 @@ export class OrchestratorAgent extends Agent {
28
31
  maxIterations;
29
32
  tasksConcurrency;
30
33
  async process(input, context) {
31
- const model = context?.model;
34
+ const { model } = context;
32
35
  if (!model)
33
36
  throw new Error("model is required to run OrchestratorAgent");
34
37
  const objective = getMessage(input);
@@ -79,7 +82,7 @@ export class OrchestratorAgent extends Agent {
79
82
  }
80
83
  async executeStep(planResult, step, context) {
81
84
  const concurrency = this.tasksConcurrency ?? DEFAULT_TASK_CONCURRENCY;
82
- const model = context?.model;
85
+ const { model } = context;
83
86
  if (!model)
84
87
  throw new Error("model is required to run OrchestratorAgent");
85
88
  const queue = fastq.promise(async (task) => {
@@ -135,3 +138,7 @@ function getMessageOrJsonString(output) {
135
138
  }
136
139
  return JSON.stringify(output);
137
140
  }
141
+ const orchestratorAgentOptionsSchema = z.object({
142
+ maxIterations: z.number().optional(),
143
+ tasksConcurrency: z.number().optional(),
144
+ });
@@ -1,4 +1,4 @@
1
- import { type Agent, type Message } from "@aigne/core";
1
+ import type { Agent, Message } from "@aigne/core";
2
2
  import { z } from "zod";
3
3
  export declare const SYNTHESIZE_PLAN_USER_PROMPT_TEMPLATE = "Synthesize the results of executing all steps in the plan into a cohesive result\n";
4
4
  export declare function getFullPlanSchema(agents: Agent[]): z.ZodObject<{
@@ -1,5 +1,5 @@
1
- import { ensureZodUnionArray } from "@aigne/core";
2
- import { groupBy, pickBy } from "lodash-es";
1
+ import { ensureZodUnionArray } from "@aigne/core/utils/json-schema.js";
2
+ import { duplicates } from "@aigne/core/utils/type-utils.js";
3
3
  import { z } from "zod";
4
4
  export const SYNTHESIZE_PLAN_USER_PROMPT_TEMPLATE = `\
5
5
  Synthesize the results of executing all steps in the plan into a cohesive result
@@ -7,8 +7,8 @@ Synthesize the results of executing all steps in the plan into a cohesive result
7
7
  export function getFullPlanSchema(agents) {
8
8
  const agentNames = agents.map((i) => i.name);
9
9
  if (new Set(agentNames).size !== agentNames.length) {
10
- const duplicates = pickBy(groupBy(agentNames), (x) => x.length > 1);
11
- throw new Error(`Tools name must be unique for orchestrator: ${Object.keys(duplicates).join(",")}`);
10
+ const dup = duplicates(agentNames);
11
+ throw new Error(`Duplicate agent names found in orchestrator: ${dup.join(",")}`);
12
12
  }
13
13
  const TaskSchema = z.object({
14
14
  description: z.string().describe("Detailed description of the task"),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/agent-library",
3
- "version": "1.3.1",
3
+ "version": "1.4.0",
4
4
  "description": "Collection of agent libraries for AIGNE framework",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -25,20 +25,26 @@
25
25
  "module": "./lib/esm/index.js",
26
26
  "types": "./lib/dts/index.d.ts",
27
27
  "exports": {
28
- ".": {
29
- "import": "./lib/esm/index.js",
30
- "require": "./lib/cjs/index.js",
31
- "types": "./lib/dts/index.d.ts"
28
+ "./*": {
29
+ "import": "./lib/esm/*",
30
+ "require": "./lib/cjs/*",
31
+ "types": "./lib/dts/*"
32
+ }
33
+ },
34
+ "typesVersions": {
35
+ "*": {
36
+ "*": [
37
+ "./lib/dts/*"
38
+ ]
32
39
  }
33
40
  },
34
41
  "dependencies": {
35
42
  "fastq": "^1.19.1",
36
- "lodash-es": "^4.17.21",
37
43
  "zod": "^3.24.2",
38
- "@aigne/core": "^1.4.0"
44
+ "@aigne/core": "^1.6.0"
39
45
  },
40
46
  "devDependencies": {
41
- "@types/bun": "^1.2.5",
47
+ "@types/bun": "^1.2.8",
42
48
  "npm-run-all": "^4.1.5",
43
49
  "rimraf": "^6.0.1",
44
50
  "typescript": "^5.8.2"
@@ -46,9 +52,9 @@
46
52
  "scripts": {
47
53
  "lint": "tsc --noEmit",
48
54
  "build": "tsc --build scripts/tsconfig.build.json",
49
- "clean": "rimraf lib coverage",
50
- "test": "bun test",
51
- "test:coverage": "bun test --coverage --coverage-reporter=lcov --coverage-reporter=text",
55
+ "clean": "rimraf lib test/coverage",
56
+ "test": "bun --cwd test test",
57
+ "test:coverage": "bun --cwd test test --coverage --coverage-reporter=lcov --coverage-reporter=text",
52
58
  "postbuild": "echo '{\"type\": \"module\"}' > lib/esm/package.json && echo '{\"type\": \"commonjs\"}' > lib/cjs/package.json"
53
59
  }
54
60
  }