@aigne/core 1.37.0 → 1.38.1

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
@@ -12,6 +12,28 @@
12
12
  * dependencies
13
13
  * @aigne/observability bumped to 0.1.0
14
14
 
15
+ ## [1.38.1](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.38.0...core-v1.38.1) (2025-07-24)
16
+
17
+
18
+ ### Bug Fixes
19
+
20
+ * add missing dependencies ([#280](https://github.com/AIGNE-io/aigne-framework/issues/280)) ([5da315e](https://github.com/AIGNE-io/aigne-framework/commit/5da315e29dc02818293e74ad159294f137e2c7f7))
21
+
22
+
23
+ ### Dependencies
24
+
25
+ * The following workspace dependencies were updated
26
+ * dependencies
27
+ * @aigne/observability-api bumped to 0.8.1
28
+
29
+ ## [1.38.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.37.0...core-v1.38.0) (2025-07-24)
30
+
31
+
32
+ ### Features
33
+
34
+ * **cli:** support aigne hub connect and model use ([#267](https://github.com/AIGNE-io/aigne-framework/issues/267)) ([8e5a32a](https://github.com/AIGNE-io/aigne-framework/commit/8e5a32afc64593137153d7407bde13837312ac70))
35
+ * **core:** support config reflection for TeamAgent in yaml file ([#276](https://github.com/AIGNE-io/aigne-framework/issues/276)) ([e6296a8](https://github.com/AIGNE-io/aigne-framework/commit/e6296a8aff313e8209c4fbb2878e7869cc672576))
36
+
15
37
  ## [1.37.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.36.0...core-v1.37.0) (2025-07-22)
16
38
 
17
39
 
@@ -45,19 +45,24 @@ export interface ReflectionMode {
45
45
  */
46
46
  reviewer: Agent;
47
47
  /**
48
- * Function that determines whether the reviewer's output indicates approval.
48
+ * Function or field name that determines whether the reviewer's output indicates approval.
49
49
  *
50
- * This function receives the reviewer agent's output message and should return:
51
- * - `true` or truthy value: The output is approved and processing should stop
52
- * - `false` or falsy value: The output needs improvement and another iteration should run
50
+ * This can be either:
51
+ * - A function that receives the reviewer agent's output message and should return:
52
+ * - `true` or truthy value: The output is approved and processing should stop
53
+ * - `false` or falsy value: The output needs improvement and another iteration should run
54
+ * - A string representing a field name in the reviewer's output message to check for approval
53
55
  *
54
- * The function can be synchronous or asynchronous, allowing for complex approval logic
56
+ * When using a function, it can be synchronous or asynchronous, allowing for complex approval logic
55
57
  * including external validation, scoring systems, or human-in-the-loop approval.
56
58
  *
57
- * @param output - The message output from the reviewer agent
58
- * @returns A boolean or truthy/falsy value indicating approval status
59
+ * When using a string, the specified field in the reviewer's output will be evaluated for truthiness
60
+ * to determine approval status.
61
+ *
62
+ * @param output - The message output from the reviewer agent (when using function form)
63
+ * @returns A boolean or truthy/falsy value indicating approval status (when using function form)
59
64
  */
60
- isApproved: (output: Message) => PromiseOrValue<boolean | unknown>;
65
+ isApproved: ((output: Message) => PromiseOrValue<boolean | unknown>) | string;
61
66
  /**
62
67
  * Maximum number of reflection iterations before giving up.
63
68
  *
@@ -151,7 +151,8 @@ class TeamAgent extends agent_js_1.Agent {
151
151
  Object.assign(previousOutput, output);
152
152
  const reviewOutput = await options.context.invoke(this.reflection.reviewer, previousOutput);
153
153
  Object.assign(previousOutput, reviewOutput);
154
- const approved = await this.reflection.isApproved(reviewOutput);
154
+ const { isApproved } = this.reflection;
155
+ const approved = typeof isApproved === "string" ? reviewOutput[isApproved] : await isApproved(reviewOutput);
155
156
  if (approved)
156
157
  return output;
157
158
  if (++iterations >= this.reflection.maxIterations) {
@@ -1,7 +1,7 @@
1
1
  import { type ZodType } from "zod";
2
2
  import type { FunctionAgentFn } from "../agents/agent.js";
3
3
  import { AIAgentToolChoice } from "../agents/ai-agent.js";
4
- import { ProcessMode } from "../agents/team-agent.js";
4
+ import { ProcessMode, type ReflectionMode } from "../agents/team-agent.js";
5
5
  export interface HooksSchema {
6
6
  onStart?: NestAgentSchema;
7
7
  onSuccess?: NestAgentSchema;
@@ -46,6 +46,9 @@ export interface TeamAgentSchema extends BaseAgentSchema {
46
46
  type: "team";
47
47
  mode?: ProcessMode;
48
48
  iterateOn?: string;
49
+ reflection?: Omit<ReflectionMode, "reviewer"> & {
50
+ reviewer: NestAgentSchema;
51
+ };
49
52
  }
50
53
  export interface TransformAgentSchema extends BaseAgentSchema {
51
54
  type: "transform";
@@ -77,6 +77,12 @@ async function parseAgentFile(path, data) {
77
77
  type: zod_1.z.literal("team"),
78
78
  mode: (0, schema_js_1.optionalize)(zod_1.z.nativeEnum(team_agent_js_1.ProcessMode)),
79
79
  iterateOn: (0, schema_js_1.optionalize)(zod_1.z.string()),
80
+ reflection: (0, schema_js_1.camelizeSchema)((0, schema_js_1.optionalize)(zod_1.z.object({
81
+ reviewer: nestAgentSchema,
82
+ isApproved: zod_1.z.string(),
83
+ maxIterations: (0, schema_js_1.optionalize)(zod_1.z.number().int().min(1)),
84
+ returnLastOnMaxIterations: (0, schema_js_1.optionalize)(zod_1.z.boolean()),
85
+ }))),
80
86
  })
81
87
  .extend(baseAgentSchema.shape),
82
88
  zod_1.z
@@ -12,9 +12,12 @@ interface LoadableModelClass {
12
12
  }
13
13
  export interface LoadableModel {
14
14
  name: string;
15
+ apiKeyEnvName?: string;
15
16
  create: (options: {
16
17
  model?: string;
17
18
  modelOptions?: ChatModelOptions;
19
+ accessKey?: string;
20
+ url?: string;
18
21
  }) => ChatModel;
19
22
  }
20
23
  export interface LoadOptions {
@@ -26,7 +29,10 @@ export interface LoadOptions {
26
29
  }
27
30
  export declare function load(options: LoadOptions): Promise<AIGNEOptions>;
28
31
  export declare function loadAgent(path: string, options?: LoadOptions, agentOptions?: AgentOptions): Promise<Agent>;
29
- export declare function loadModel(models: LoadableModel[], model?: Camelize<z.infer<typeof aigneFileSchema>["model"]>, modelOptions?: ChatModelOptions): Promise<ChatModel | undefined>;
32
+ export declare function loadModel(models: LoadableModel[], model?: Camelize<z.infer<typeof aigneFileSchema>["model"]>, modelOptions?: ChatModelOptions, accessKeyOptions?: {
33
+ accessKey?: string;
34
+ url?: string;
35
+ }): Promise<ChatModel | undefined>;
30
36
  declare const aigneFileSchema: z.ZodObject<{
31
37
  name: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
32
38
  description: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
@@ -125,6 +125,12 @@ async function parseAgent(path, agent, options, agentOptions) {
125
125
  case "team": {
126
126
  return team_agent_js_1.TeamAgent.from({
127
127
  ...baseOptions,
128
+ mode: agent.mode,
129
+ iterateOn: agent.iterateOn,
130
+ reflection: agent.reflection && {
131
+ ...agent.reflection,
132
+ reviewer: await loadNestAgent(path, agent.reflection.reviewer, options),
133
+ },
128
134
  });
129
135
  }
130
136
  case "transform": {
@@ -151,7 +157,7 @@ async function loadMemory(memories, provider, options) {
151
157
  }
152
158
  const { MODEL_PROVIDER, MODEL_NAME } = index_js_1.nodejs.env;
153
159
  const DEFAULT_MODEL_PROVIDER = "openai";
154
- async function loadModel(models, model, modelOptions) {
160
+ async function loadModel(models, model, modelOptions, accessKeyOptions) {
155
161
  const params = {
156
162
  model: MODEL_NAME ?? model?.name ?? undefined,
157
163
  temperature: model?.temperature ?? undefined,
@@ -159,12 +165,13 @@ async function loadModel(models, model, modelOptions) {
159
165
  frequencyPenalty: model?.frequencyPenalty ?? undefined,
160
166
  presencePenalty: model?.presencePenalty ?? undefined,
161
167
  };
162
- const m = models.find((m) => m.name
163
- .toLowerCase()
164
- .includes((MODEL_PROVIDER ?? model?.provider ?? DEFAULT_MODEL_PROVIDER).toLowerCase()));
168
+ const providerName = MODEL_PROVIDER ?? model?.provider ?? DEFAULT_MODEL_PROVIDER;
169
+ const provider = providerName.replace(/-/g, "");
170
+ const m = models.find((m) => m.name.toLowerCase().includes(provider.toLowerCase()));
165
171
  if (!m)
166
172
  throw new Error(`Unsupported model: ${model?.provider} ${model?.name}`);
167
173
  return m.create({
174
+ ...(accessKeyOptions || {}),
168
175
  model: params.model,
169
176
  modelOptions: { ...params, ...modelOptions },
170
177
  });
@@ -45,19 +45,24 @@ export interface ReflectionMode {
45
45
  */
46
46
  reviewer: Agent;
47
47
  /**
48
- * Function that determines whether the reviewer's output indicates approval.
48
+ * Function or field name that determines whether the reviewer's output indicates approval.
49
49
  *
50
- * This function receives the reviewer agent's output message and should return:
51
- * - `true` or truthy value: The output is approved and processing should stop
52
- * - `false` or falsy value: The output needs improvement and another iteration should run
50
+ * This can be either:
51
+ * - A function that receives the reviewer agent's output message and should return:
52
+ * - `true` or truthy value: The output is approved and processing should stop
53
+ * - `false` or falsy value: The output needs improvement and another iteration should run
54
+ * - A string representing a field name in the reviewer's output message to check for approval
53
55
  *
54
- * The function can be synchronous or asynchronous, allowing for complex approval logic
56
+ * When using a function, it can be synchronous or asynchronous, allowing for complex approval logic
55
57
  * including external validation, scoring systems, or human-in-the-loop approval.
56
58
  *
57
- * @param output - The message output from the reviewer agent
58
- * @returns A boolean or truthy/falsy value indicating approval status
59
+ * When using a string, the specified field in the reviewer's output will be evaluated for truthiness
60
+ * to determine approval status.
61
+ *
62
+ * @param output - The message output from the reviewer agent (when using function form)
63
+ * @returns A boolean or truthy/falsy value indicating approval status (when using function form)
59
64
  */
60
- isApproved: (output: Message) => PromiseOrValue<boolean | unknown>;
65
+ isApproved: ((output: Message) => PromiseOrValue<boolean | unknown>) | string;
61
66
  /**
62
67
  * Maximum number of reflection iterations before giving up.
63
68
  *
@@ -1,7 +1,7 @@
1
1
  import { type ZodType } from "zod";
2
2
  import type { FunctionAgentFn } from "../agents/agent.js";
3
3
  import { AIAgentToolChoice } from "../agents/ai-agent.js";
4
- import { ProcessMode } from "../agents/team-agent.js";
4
+ import { ProcessMode, type ReflectionMode } from "../agents/team-agent.js";
5
5
  export interface HooksSchema {
6
6
  onStart?: NestAgentSchema;
7
7
  onSuccess?: NestAgentSchema;
@@ -46,6 +46,9 @@ export interface TeamAgentSchema extends BaseAgentSchema {
46
46
  type: "team";
47
47
  mode?: ProcessMode;
48
48
  iterateOn?: string;
49
+ reflection?: Omit<ReflectionMode, "reviewer"> & {
50
+ reviewer: NestAgentSchema;
51
+ };
49
52
  }
50
53
  export interface TransformAgentSchema extends BaseAgentSchema {
51
54
  type: "transform";
@@ -12,9 +12,12 @@ interface LoadableModelClass {
12
12
  }
13
13
  export interface LoadableModel {
14
14
  name: string;
15
+ apiKeyEnvName?: string;
15
16
  create: (options: {
16
17
  model?: string;
17
18
  modelOptions?: ChatModelOptions;
19
+ accessKey?: string;
20
+ url?: string;
18
21
  }) => ChatModel;
19
22
  }
20
23
  export interface LoadOptions {
@@ -26,7 +29,10 @@ export interface LoadOptions {
26
29
  }
27
30
  export declare function load(options: LoadOptions): Promise<AIGNEOptions>;
28
31
  export declare function loadAgent(path: string, options?: LoadOptions, agentOptions?: AgentOptions): Promise<Agent>;
29
- export declare function loadModel(models: LoadableModel[], model?: Camelize<z.infer<typeof aigneFileSchema>["model"]>, modelOptions?: ChatModelOptions): Promise<ChatModel | undefined>;
32
+ export declare function loadModel(models: LoadableModel[], model?: Camelize<z.infer<typeof aigneFileSchema>["model"]>, modelOptions?: ChatModelOptions, accessKeyOptions?: {
33
+ accessKey?: string;
34
+ url?: string;
35
+ }): Promise<ChatModel | undefined>;
30
36
  declare const aigneFileSchema: z.ZodObject<{
31
37
  name: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
32
38
  description: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
@@ -45,19 +45,24 @@ export interface ReflectionMode {
45
45
  */
46
46
  reviewer: Agent;
47
47
  /**
48
- * Function that determines whether the reviewer's output indicates approval.
48
+ * Function or field name that determines whether the reviewer's output indicates approval.
49
49
  *
50
- * This function receives the reviewer agent's output message and should return:
51
- * - `true` or truthy value: The output is approved and processing should stop
52
- * - `false` or falsy value: The output needs improvement and another iteration should run
50
+ * This can be either:
51
+ * - A function that receives the reviewer agent's output message and should return:
52
+ * - `true` or truthy value: The output is approved and processing should stop
53
+ * - `false` or falsy value: The output needs improvement and another iteration should run
54
+ * - A string representing a field name in the reviewer's output message to check for approval
53
55
  *
54
- * The function can be synchronous or asynchronous, allowing for complex approval logic
56
+ * When using a function, it can be synchronous or asynchronous, allowing for complex approval logic
55
57
  * including external validation, scoring systems, or human-in-the-loop approval.
56
58
  *
57
- * @param output - The message output from the reviewer agent
58
- * @returns A boolean or truthy/falsy value indicating approval status
59
+ * When using a string, the specified field in the reviewer's output will be evaluated for truthiness
60
+ * to determine approval status.
61
+ *
62
+ * @param output - The message output from the reviewer agent (when using function form)
63
+ * @returns A boolean or truthy/falsy value indicating approval status (when using function form)
59
64
  */
60
- isApproved: (output: Message) => PromiseOrValue<boolean | unknown>;
65
+ isApproved: ((output: Message) => PromiseOrValue<boolean | unknown>) | string;
61
66
  /**
62
67
  * Maximum number of reflection iterations before giving up.
63
68
  *
@@ -145,7 +145,8 @@ export class TeamAgent extends Agent {
145
145
  Object.assign(previousOutput, output);
146
146
  const reviewOutput = await options.context.invoke(this.reflection.reviewer, previousOutput);
147
147
  Object.assign(previousOutput, reviewOutput);
148
- const approved = await this.reflection.isApproved(reviewOutput);
148
+ const { isApproved } = this.reflection;
149
+ const approved = typeof isApproved === "string" ? reviewOutput[isApproved] : await isApproved(reviewOutput);
149
150
  if (approved)
150
151
  return output;
151
152
  if (++iterations >= this.reflection.maxIterations) {
@@ -1,7 +1,7 @@
1
1
  import { type ZodType } from "zod";
2
2
  import type { FunctionAgentFn } from "../agents/agent.js";
3
3
  import { AIAgentToolChoice } from "../agents/ai-agent.js";
4
- import { ProcessMode } from "../agents/team-agent.js";
4
+ import { ProcessMode, type ReflectionMode } from "../agents/team-agent.js";
5
5
  export interface HooksSchema {
6
6
  onStart?: NestAgentSchema;
7
7
  onSuccess?: NestAgentSchema;
@@ -46,6 +46,9 @@ export interface TeamAgentSchema extends BaseAgentSchema {
46
46
  type: "team";
47
47
  mode?: ProcessMode;
48
48
  iterateOn?: string;
49
+ reflection?: Omit<ReflectionMode, "reviewer"> & {
50
+ reviewer: NestAgentSchema;
51
+ };
49
52
  }
50
53
  export interface TransformAgentSchema extends BaseAgentSchema {
51
54
  type: "transform";
@@ -73,6 +73,12 @@ export async function parseAgentFile(path, data) {
73
73
  type: z.literal("team"),
74
74
  mode: optionalize(z.nativeEnum(ProcessMode)),
75
75
  iterateOn: optionalize(z.string()),
76
+ reflection: camelizeSchema(optionalize(z.object({
77
+ reviewer: nestAgentSchema,
78
+ isApproved: z.string(),
79
+ maxIterations: optionalize(z.number().int().min(1)),
80
+ returnLastOnMaxIterations: optionalize(z.boolean()),
81
+ }))),
76
82
  })
77
83
  .extend(baseAgentSchema.shape),
78
84
  z
@@ -12,9 +12,12 @@ interface LoadableModelClass {
12
12
  }
13
13
  export interface LoadableModel {
14
14
  name: string;
15
+ apiKeyEnvName?: string;
15
16
  create: (options: {
16
17
  model?: string;
17
18
  modelOptions?: ChatModelOptions;
19
+ accessKey?: string;
20
+ url?: string;
18
21
  }) => ChatModel;
19
22
  }
20
23
  export interface LoadOptions {
@@ -26,7 +29,10 @@ export interface LoadOptions {
26
29
  }
27
30
  export declare function load(options: LoadOptions): Promise<AIGNEOptions>;
28
31
  export declare function loadAgent(path: string, options?: LoadOptions, agentOptions?: AgentOptions): Promise<Agent>;
29
- export declare function loadModel(models: LoadableModel[], model?: Camelize<z.infer<typeof aigneFileSchema>["model"]>, modelOptions?: ChatModelOptions): Promise<ChatModel | undefined>;
32
+ export declare function loadModel(models: LoadableModel[], model?: Camelize<z.infer<typeof aigneFileSchema>["model"]>, modelOptions?: ChatModelOptions, accessKeyOptions?: {
33
+ accessKey?: string;
34
+ url?: string;
35
+ }): Promise<ChatModel | undefined>;
30
36
  declare const aigneFileSchema: z.ZodObject<{
31
37
  name: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
32
38
  description: z.ZodType<string | undefined, z.ZodTypeDef, string | undefined>;
@@ -116,6 +116,12 @@ async function parseAgent(path, agent, options, agentOptions) {
116
116
  case "team": {
117
117
  return TeamAgent.from({
118
118
  ...baseOptions,
119
+ mode: agent.mode,
120
+ iterateOn: agent.iterateOn,
121
+ reflection: agent.reflection && {
122
+ ...agent.reflection,
123
+ reviewer: await loadNestAgent(path, agent.reflection.reviewer, options),
124
+ },
119
125
  });
120
126
  }
121
127
  case "transform": {
@@ -142,7 +148,7 @@ async function loadMemory(memories, provider, options) {
142
148
  }
143
149
  const { MODEL_PROVIDER, MODEL_NAME } = nodejs.env;
144
150
  const DEFAULT_MODEL_PROVIDER = "openai";
145
- export async function loadModel(models, model, modelOptions) {
151
+ export async function loadModel(models, model, modelOptions, accessKeyOptions) {
146
152
  const params = {
147
153
  model: MODEL_NAME ?? model?.name ?? undefined,
148
154
  temperature: model?.temperature ?? undefined,
@@ -150,12 +156,13 @@ export async function loadModel(models, model, modelOptions) {
150
156
  frequencyPenalty: model?.frequencyPenalty ?? undefined,
151
157
  presencePenalty: model?.presencePenalty ?? undefined,
152
158
  };
153
- const m = models.find((m) => m.name
154
- .toLowerCase()
155
- .includes((MODEL_PROVIDER ?? model?.provider ?? DEFAULT_MODEL_PROVIDER).toLowerCase()));
159
+ const providerName = MODEL_PROVIDER ?? model?.provider ?? DEFAULT_MODEL_PROVIDER;
160
+ const provider = providerName.replace(/-/g, "");
161
+ const m = models.find((m) => m.name.toLowerCase().includes(provider.toLowerCase()));
156
162
  if (!m)
157
163
  throw new Error(`Unsupported model: ${model?.provider} ${model?.name}`);
158
164
  return m.create({
165
+ ...(accessKeyOptions || {}),
159
166
  model: params.model,
160
167
  modelOptions: { ...params, ...modelOptions },
161
168
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@aigne/core",
3
- "version": "1.37.0",
3
+ "version": "1.38.1",
4
4
  "description": "AIGNE core library for building AI-powered applications",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -64,6 +64,8 @@
64
64
  "dependencies": {
65
65
  "@aigne/json-schema-to-zod": "^1.3.3",
66
66
  "@modelcontextprotocol/sdk": "^1.15.0",
67
+ "@opentelemetry/api": "^1.9.0",
68
+ "@opentelemetry/sdk-trace-base": "^2.0.1",
67
69
  "@types/debug": "^4.1.12",
68
70
  "camelize-ts": "^3.0.0",
69
71
  "content-type": "^1.0.5",
@@ -83,7 +85,7 @@
83
85
  "yaml": "^2.8.0",
84
86
  "zod": "^3.25.67",
85
87
  "zod-to-json-schema": "^3.24.6",
86
- "@aigne/observability-api": "^0.8.0",
88
+ "@aigne/observability-api": "^0.8.1",
87
89
  "@aigne/platform-helpers": "^0.4.0"
88
90
  },
89
91
  "devDependencies": {