@aigne/core 1.51.0 → 1.53.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.
Files changed (60) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/lib/cjs/agents/agent.d.ts +2 -0
  3. package/lib/cjs/agents/agent.js +8 -1
  4. package/lib/cjs/agents/chat-model.d.ts +17 -3
  5. package/lib/cjs/agents/chat-model.js +8 -4
  6. package/lib/cjs/agents/image-agent.d.ts +21 -0
  7. package/lib/cjs/agents/image-agent.js +43 -0
  8. package/lib/cjs/agents/image-model.d.ts +115 -0
  9. package/lib/cjs/agents/image-model.js +60 -0
  10. package/lib/cjs/aigne/aigne.d.ts +10 -1
  11. package/lib/cjs/aigne/aigne.js +10 -6
  12. package/lib/cjs/aigne/context.d.ts +5 -1
  13. package/lib/cjs/aigne/context.js +6 -0
  14. package/lib/cjs/index.d.ts +2 -0
  15. package/lib/cjs/index.js +2 -0
  16. package/lib/cjs/loader/agent-yaml.d.ts +6 -1
  17. package/lib/cjs/loader/agent-yaml.js +18 -9
  18. package/lib/cjs/loader/index.d.ts +46 -44
  19. package/lib/cjs/loader/index.js +35 -12
  20. package/lib/cjs/prompt/prompt-builder.d.ts +3 -0
  21. package/lib/cjs/prompt/prompt-builder.js +8 -0
  22. package/lib/cjs/utils/camelize.d.ts +7 -1
  23. package/lib/cjs/utils/camelize.js +30 -13
  24. package/lib/cjs/utils/type-utils.d.ts +1 -1
  25. package/lib/dts/agents/agent.d.ts +2 -0
  26. package/lib/dts/agents/chat-model.d.ts +17 -3
  27. package/lib/dts/agents/image-agent.d.ts +21 -0
  28. package/lib/dts/agents/image-model.d.ts +115 -0
  29. package/lib/dts/aigne/aigne.d.ts +10 -1
  30. package/lib/dts/aigne/context.d.ts +5 -1
  31. package/lib/dts/index.d.ts +2 -0
  32. package/lib/dts/loader/agent-yaml.d.ts +6 -1
  33. package/lib/dts/loader/index.d.ts +46 -44
  34. package/lib/dts/prompt/prompt-builder.d.ts +3 -0
  35. package/lib/dts/utils/camelize.d.ts +7 -1
  36. package/lib/dts/utils/type-utils.d.ts +1 -1
  37. package/lib/esm/agents/agent.d.ts +2 -0
  38. package/lib/esm/agents/agent.js +8 -1
  39. package/lib/esm/agents/chat-model.d.ts +17 -3
  40. package/lib/esm/agents/chat-model.js +7 -3
  41. package/lib/esm/agents/image-agent.d.ts +21 -0
  42. package/lib/esm/agents/image-agent.js +36 -0
  43. package/lib/esm/agents/image-model.d.ts +115 -0
  44. package/lib/esm/agents/image-model.js +56 -0
  45. package/lib/esm/aigne/aigne.d.ts +10 -1
  46. package/lib/esm/aigne/aigne.js +10 -6
  47. package/lib/esm/aigne/context.d.ts +5 -1
  48. package/lib/esm/aigne/context.js +6 -0
  49. package/lib/esm/index.d.ts +2 -0
  50. package/lib/esm/index.js +2 -0
  51. package/lib/esm/loader/agent-yaml.d.ts +6 -1
  52. package/lib/esm/loader/agent-yaml.js +18 -9
  53. package/lib/esm/loader/index.d.ts +46 -44
  54. package/lib/esm/loader/index.js +36 -13
  55. package/lib/esm/prompt/prompt-builder.d.ts +3 -0
  56. package/lib/esm/prompt/prompt-builder.js +8 -0
  57. package/lib/esm/utils/camelize.d.ts +7 -1
  58. package/lib/esm/utils/camelize.js +29 -13
  59. package/lib/esm/utils/type-utils.d.ts +1 -1
  60. package/package.json +3 -3
package/CHANGELOG.md CHANGED
@@ -1,5 +1,26 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.53.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.52.0...core-v1.53.0) (2025-08-20)
4
+
5
+
6
+ ### Features
7
+
8
+ * add ImageModel/ImageAgent support ([#383](https://github.com/AIGNE-io/aigne-framework/issues/383)) ([96a2093](https://github.com/AIGNE-io/aigne-framework/commit/96a209368d91d98f47db6de1e404640368a86fa8))
9
+
10
+ ## [1.52.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.51.0...core-v1.52.0) (2025-08-20)
11
+
12
+
13
+ ### Features
14
+
15
+ * **agents:** add async memory recording option ([#385](https://github.com/AIGNE-io/aigne-framework/issues/385)) ([573acdb](https://github.com/AIGNE-io/aigne-framework/commit/573acdb617434e6699b2e07db942e6336706d27f))
16
+
17
+
18
+ ### Dependencies
19
+
20
+ * The following workspace dependencies were updated
21
+ * dependencies
22
+ * @aigne/observability-api bumped to 0.9.1
23
+
3
24
  ## [1.51.0](https://github.com/AIGNE-io/aigne-framework/compare/core-v1.50.1...core-v1.51.0) (2025-08-18)
4
25
 
5
26
 
@@ -116,6 +116,7 @@ export interface AgentOptions<I extends Message = Message, O extends Message = M
116
116
  * One or more memory agents this agent can use
117
117
  */
118
118
  memory?: MemoryAgent | MemoryAgent[];
119
+ asyncMemoryRecord?: boolean;
119
120
  /**
120
121
  * Maximum number of memory items to retrieve
121
122
  */
@@ -199,6 +200,7 @@ export declare abstract class Agent<I extends Message = any, O extends Message =
199
200
  * List of memories this agent can use
200
201
  */
201
202
  readonly memories: MemoryAgent[];
203
+ asyncMemoryRecord?: boolean;
202
204
  tag?: string;
203
205
  /**
204
206
  * Maximum number of memory items to retrieve
@@ -78,6 +78,7 @@ exports.agentOptionsSchema = zod_1.z.object({
78
78
  skills: zod_1.z.array(zod_1.z.union([zod_1.z.custom(), zod_1.z.custom()])).optional(),
79
79
  disableEvents: zod_1.z.boolean().optional(),
80
80
  memory: zod_1.z.union([zod_1.z.custom(), zod_1.z.array(zod_1.z.custom())]).optional(),
81
+ asyncMemoryRecord: zod_1.z.boolean().optional(),
81
82
  maxRetrieveMemoryCount: zod_1.z.number().optional(),
82
83
  hooks: zod_1.z.union([zod_1.z.array(hooksSchema), hooksSchema]).optional(),
83
84
  guideRails: zod_1.z.array(zod_1.z.custom()).optional(),
@@ -131,6 +132,7 @@ class Agent {
131
132
  else if (options.memory) {
132
133
  this.memories.push(options.memory);
133
134
  }
135
+ this.asyncMemoryRecord = options.asyncMemoryRecord;
134
136
  this.maxRetrieveMemoryCount = options.maxRetrieveMemoryCount;
135
137
  this.hooks = (0, type_utils_js_1.flat)(options.hooks);
136
138
  this.guideRails = options.guideRails;
@@ -139,6 +141,7 @@ class Agent {
139
141
  * List of memories this agent can use
140
142
  */
141
143
  memories = [];
144
+ asyncMemoryRecord;
142
145
  tag;
143
146
  /**
144
147
  * Maximum number of memory items to retrieve
@@ -600,7 +603,11 @@ class Agent {
600
603
  async postprocess(input, output, options) {
601
604
  this.checkContextStatus(options);
602
605
  this.publishToTopics(output, options);
603
- await this.recordMemories({ content: [{ input, output: (0, types_js_1.replaceTransferAgentToName)(output), source: this.name }] }, options);
606
+ const memory = this.recordMemories({ content: [{ input, output: (0, types_js_1.replaceTransferAgentToName)(output), source: this.name }] }, options).catch((error) => {
607
+ logger_js_1.logger.error(`Agent ${this.name} failed to record memories:`, error);
608
+ });
609
+ if (!this.asyncMemoryRecord)
610
+ await memory;
604
611
  }
605
612
  async publishToTopics(output, options) {
606
613
  const publishTopics = typeof this.publishTopic === "function" ? await this.publishTopic(output) : this.publishTopic;
@@ -1,5 +1,6 @@
1
+ import { z } from "zod";
1
2
  import type { PromiseOrValue } from "../utils/type-utils.js";
2
- import { Agent, type AgentInvokeOptions, type AgentProcessResult, type Message } from "./agent.js";
3
+ import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessResult, type Message } from "./agent.js";
3
4
  /**
4
5
  * ChatModel is an abstract base class for interacting with Large Language Models (LLMs).
5
6
  *
@@ -25,8 +26,8 @@ import { Agent, type AgentInvokeOptions, type AgentProcessResult, type Message }
25
26
  */
26
27
  export declare abstract class ChatModel extends Agent<ChatModelInput, ChatModelOutput> {
27
28
  tag: string;
28
- constructor();
29
- abstract getCredential(): Promise<{
29
+ constructor(options?: Omit<AgentOptions<ChatModelInput, ChatModelOutput>, "inputSchema" | "outputSchema">);
30
+ get credential(): PromiseOrValue<{
30
31
  url?: string;
31
32
  apiKey?: string;
32
33
  model?: string;
@@ -391,3 +392,16 @@ export interface ChatModelOutputUsage {
391
392
  */
392
393
  aigneHubCredits?: number;
393
394
  }
395
+ export declare const chatModelOutputUsageSchema: z.ZodObject<{
396
+ inputTokens: z.ZodNumber;
397
+ outputTokens: z.ZodNumber;
398
+ aigneHubCredits: z.ZodOptional<z.ZodNumber>;
399
+ }, "strip", z.ZodTypeAny, {
400
+ inputTokens: number;
401
+ outputTokens: number;
402
+ aigneHubCredits?: number | undefined;
403
+ }, {
404
+ inputTokens: number;
405
+ outputTokens: number;
406
+ aigneHubCredits?: number | undefined;
407
+ }>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ChatModel = void 0;
3
+ exports.chatModelOutputUsageSchema = exports.ChatModel = void 0;
4
4
  const zod_1 = require("zod");
5
5
  const agent_js_1 = require("./agent.js");
6
6
  /**
@@ -28,12 +28,16 @@ const agent_js_1 = require("./agent.js");
28
28
  */
29
29
  class ChatModel extends agent_js_1.Agent {
30
30
  tag = "ChatModelAgent";
31
- constructor() {
31
+ constructor(options) {
32
32
  super({
33
+ ...options,
33
34
  inputSchema: chatModelInputSchema,
34
35
  outputSchema: chatModelOutputSchema,
35
36
  });
36
37
  }
38
+ get credential() {
39
+ return {};
40
+ }
37
41
  /**
38
42
  * Indicates whether the model supports parallel tool calls
39
43
  *
@@ -217,7 +221,7 @@ const chatModelOutputToolCallSchema = zod_1.z.object({
217
221
  arguments: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()),
218
222
  }),
219
223
  });
220
- const chatModelOutputUsageSchema = zod_1.z.object({
224
+ exports.chatModelOutputUsageSchema = zod_1.z.object({
221
225
  inputTokens: zod_1.z.number(),
222
226
  outputTokens: zod_1.z.number(),
223
227
  aigneHubCredits: zod_1.z.number().optional(),
@@ -226,6 +230,6 @@ const chatModelOutputSchema = zod_1.z.object({
226
230
  text: zod_1.z.string().optional(),
227
231
  json: zod_1.z.record(zod_1.z.string(), zod_1.z.unknown()).optional(),
228
232
  toolCalls: zod_1.z.array(chatModelOutputToolCallSchema).optional(),
229
- usage: chatModelOutputUsageSchema.optional(),
233
+ usage: exports.chatModelOutputUsageSchema.optional(),
230
234
  model: zod_1.z.string().optional(),
231
235
  });
@@ -0,0 +1,21 @@
1
+ import { type ZodObject, type ZodType } from "zod";
2
+ import { PromptBuilder } from "../prompt/prompt-builder.js";
3
+ import { Agent, type AgentInvokeOptions, type AgentOptions, type Message } from "./agent.js";
4
+ import { type ImageModel, type ImageModelOutput } from "./image-model.js";
5
+ export interface ImageAgentOptions<I extends Message = any, O extends ImageModelOutput = any> extends Omit<AgentOptions<I, O>, "outputSchema"> {
6
+ model?: ImageModel;
7
+ instructions: string | PromptBuilder;
8
+ modelOptions?: Record<string, any>;
9
+ }
10
+ export declare const imageAgentOptionsSchema: ZodObject<{
11
+ [key in keyof ImageAgentOptions]: ZodType<ImageAgentOptions[key]>;
12
+ }>;
13
+ export declare class ImageAgent<I extends Message = any, O extends ImageModelOutput = any> extends Agent<I, O> {
14
+ tag: string;
15
+ static from<I extends Message = any, O extends ImageModelOutput = any>(options: ImageAgentOptions<I, O>): ImageAgent<I, O>;
16
+ constructor(options: ImageAgentOptions<I, O>);
17
+ model?: ImageModel;
18
+ instructions: PromptBuilder;
19
+ modelOptions?: Record<string, any>;
20
+ process(input: I, options: AgentInvokeOptions): Promise<O>;
21
+ }
@@ -0,0 +1,43 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.ImageAgent = exports.imageAgentOptionsSchema = void 0;
7
+ const zod_1 = __importDefault(require("zod"));
8
+ const prompt_builder_js_1 = require("../prompt/prompt-builder.js");
9
+ const type_utils_js_1 = require("../utils/type-utils.js");
10
+ const agent_js_1 = require("./agent.js");
11
+ const image_model_js_1 = require("./image-model.js");
12
+ exports.imageAgentOptionsSchema = agent_js_1.agentOptionsSchema.extend({
13
+ model: zod_1.default.custom().optional(),
14
+ instructions: zod_1.default.union([zod_1.default.string(), zod_1.default.custom()]),
15
+ modelOptions: zod_1.default.record(zod_1.default.any()).optional(),
16
+ });
17
+ class ImageAgent extends agent_js_1.Agent {
18
+ tag = "ImageAgent";
19
+ static from(options) {
20
+ return new ImageAgent(options);
21
+ }
22
+ constructor(options) {
23
+ super({ ...options, outputSchema: image_model_js_1.imageModelOutputSchema });
24
+ (0, type_utils_js_1.checkArguments)("ImageAgent", exports.imageAgentOptionsSchema, options);
25
+ this.model = options.model;
26
+ this.instructions =
27
+ typeof options.instructions === "string"
28
+ ? prompt_builder_js_1.PromptBuilder.from(options.instructions)
29
+ : options.instructions;
30
+ this.modelOptions = options.modelOptions;
31
+ }
32
+ model;
33
+ instructions;
34
+ modelOptions;
35
+ async process(input, options) {
36
+ const model = this.model ?? options.context.imageModel;
37
+ if (!model)
38
+ throw new Error("image model is required to run ImageAgent");
39
+ const { prompt } = await this.instructions.buildImagePrompt({ input });
40
+ return (await options.context.invoke(model, { ...input, ...this.modelOptions, prompt }, { ...options, streaming: false }));
41
+ }
42
+ }
43
+ exports.ImageAgent = ImageAgent;
@@ -0,0 +1,115 @@
1
+ import { z } from "zod";
2
+ import type { PromiseOrValue } from "../utils/type-utils.js";
3
+ import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessResult, type Message } from "./agent.js";
4
+ import { type ChatModelOutputUsage } from "./chat-model.js";
5
+ export interface ImageModelOptions<I extends ImageModelInput = ImageModelInput, O extends ImageModelOutput = ImageModelOutput> extends AgentOptions<I, O> {
6
+ }
7
+ export declare abstract class ImageModel<I extends ImageModelInput = ImageModelInput, O extends ImageModelOutput = ImageModelOutput> extends Agent<I, O> {
8
+ tag: string;
9
+ constructor(options?: ImageModelOptions<I, O>);
10
+ get credential(): PromiseOrValue<{
11
+ url?: string;
12
+ apiKey?: string;
13
+ model?: string;
14
+ }>;
15
+ protected preprocess(input: I, options: AgentInvokeOptions): Promise<void>;
16
+ protected postprocess(input: I, output: O, options: AgentInvokeOptions): Promise<void>;
17
+ abstract process(input: I, options: AgentInvokeOptions): PromiseOrValue<AgentProcessResult<O>>;
18
+ }
19
+ export interface ImageModelInput extends Message {
20
+ model?: string;
21
+ image?: string | string[];
22
+ prompt: string;
23
+ n?: number;
24
+ responseFormat?: "url" | "base64";
25
+ }
26
+ export declare const imageModelInputSchema: z.ZodObject<{
27
+ model: z.ZodOptional<z.ZodString>;
28
+ image: z.ZodOptional<z.ZodUnion<[z.ZodString, z.ZodArray<z.ZodString, "many">]>>;
29
+ prompt: z.ZodString;
30
+ n: z.ZodOptional<z.ZodNumber>;
31
+ responseFormat: z.ZodOptional<z.ZodEnum<["url", "base64"]>>;
32
+ }, "strip", z.ZodTypeAny, {
33
+ prompt: string;
34
+ model?: string | undefined;
35
+ responseFormat?: "url" | "base64" | undefined;
36
+ image?: string | string[] | undefined;
37
+ n?: number | undefined;
38
+ }, {
39
+ prompt: string;
40
+ model?: string | undefined;
41
+ responseFormat?: "url" | "base64" | undefined;
42
+ image?: string | string[] | undefined;
43
+ n?: number | undefined;
44
+ }>;
45
+ export interface ImageModelOutput extends Message {
46
+ images: ImageModelOutputImage[];
47
+ /**
48
+ * Token usage statistics
49
+ */
50
+ usage?: ChatModelOutputUsage;
51
+ /**
52
+ * Model name or version used
53
+ */
54
+ model?: string;
55
+ }
56
+ export type ImageModelOutputImage = ImageModelOutputImageUrl | ImageModelOutputImageBase64;
57
+ export interface ImageModelOutputImageUrl {
58
+ url: string;
59
+ }
60
+ export interface ImageModelOutputImageBase64 {
61
+ base64: string;
62
+ }
63
+ export declare const imageModelOutputSchema: z.ZodObject<{
64
+ images: z.ZodArray<z.ZodUnion<[z.ZodObject<{
65
+ url: z.ZodString;
66
+ }, "strip", z.ZodTypeAny, {
67
+ url: string;
68
+ }, {
69
+ url: string;
70
+ }>, z.ZodObject<{
71
+ base64: z.ZodString;
72
+ }, "strip", z.ZodTypeAny, {
73
+ base64: string;
74
+ }, {
75
+ base64: string;
76
+ }>]>, "many">;
77
+ usage: z.ZodOptional<z.ZodObject<{
78
+ inputTokens: z.ZodNumber;
79
+ outputTokens: z.ZodNumber;
80
+ aigneHubCredits: z.ZodOptional<z.ZodNumber>;
81
+ }, "strip", z.ZodTypeAny, {
82
+ inputTokens: number;
83
+ outputTokens: number;
84
+ aigneHubCredits?: number | undefined;
85
+ }, {
86
+ inputTokens: number;
87
+ outputTokens: number;
88
+ aigneHubCredits?: number | undefined;
89
+ }>>;
90
+ model: z.ZodOptional<z.ZodString>;
91
+ }, "strip", z.ZodTypeAny, {
92
+ images: ({
93
+ url: string;
94
+ } | {
95
+ base64: string;
96
+ })[];
97
+ model?: string | undefined;
98
+ usage?: {
99
+ inputTokens: number;
100
+ outputTokens: number;
101
+ aigneHubCredits?: number | undefined;
102
+ } | undefined;
103
+ }, {
104
+ images: ({
105
+ url: string;
106
+ } | {
107
+ base64: string;
108
+ })[];
109
+ model?: string | undefined;
110
+ usage?: {
111
+ inputTokens: number;
112
+ outputTokens: number;
113
+ aigneHubCredits?: number | undefined;
114
+ } | undefined;
115
+ }>;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.imageModelOutputSchema = exports.imageModelInputSchema = exports.ImageModel = void 0;
4
+ const zod_1 = require("zod");
5
+ const agent_js_1 = require("./agent.js");
6
+ const chat_model_js_1 = require("./chat-model.js");
7
+ class ImageModel extends agent_js_1.Agent {
8
+ tag = "ImageModelAgent";
9
+ constructor(options) {
10
+ super({
11
+ inputSchema: exports.imageModelInputSchema,
12
+ outputSchema: exports.imageModelOutputSchema,
13
+ ...options,
14
+ });
15
+ }
16
+ get credential() {
17
+ return {};
18
+ }
19
+ async preprocess(input, options) {
20
+ super.preprocess(input, options);
21
+ const { limits, usage } = options.context;
22
+ const usedTokens = usage.outputTokens + usage.inputTokens;
23
+ if (limits?.maxTokens && usedTokens >= limits.maxTokens) {
24
+ throw new Error(`Exceeded max tokens ${usedTokens}/${limits.maxTokens}`);
25
+ }
26
+ }
27
+ async postprocess(input, output, options) {
28
+ super.postprocess(input, output, options);
29
+ const { usage } = output;
30
+ if (usage) {
31
+ options.context.usage.outputTokens += usage.outputTokens;
32
+ options.context.usage.inputTokens += usage.inputTokens;
33
+ if (usage.aigneHubCredits)
34
+ options.context.usage.aigneHubCredits += usage.aigneHubCredits;
35
+ }
36
+ }
37
+ }
38
+ exports.ImageModel = ImageModel;
39
+ exports.imageModelInputSchema = zod_1.z.object({
40
+ model: zod_1.z.string().optional(),
41
+ image: zod_1.z
42
+ .union([zod_1.z.string(), zod_1.z.array(zod_1.z.string())])
43
+ .optional()
44
+ .describe("Image URL or base64 string(s) used for editing"),
45
+ prompt: zod_1.z.string(),
46
+ n: zod_1.z.number().int().min(1).optional(),
47
+ responseFormat: zod_1.z.enum(["url", "base64"]).optional(),
48
+ });
49
+ exports.imageModelOutputSchema = zod_1.z.object({
50
+ images: zod_1.z.array(zod_1.z.union([
51
+ zod_1.z.object({
52
+ url: zod_1.z.string(),
53
+ }),
54
+ zod_1.z.object({
55
+ base64: zod_1.z.string(),
56
+ }),
57
+ ])),
58
+ usage: chat_model_js_1.chatModelOutputUsageSchema.optional(),
59
+ model: zod_1.z.string().optional(),
60
+ });
@@ -1,6 +1,7 @@
1
1
  import { AIGNEObserver } from "@aigne/observability-api";
2
2
  import type { Agent, AgentResponse, AgentResponseStream, Message } from "../agents/agent.js";
3
3
  import type { ChatModel } from "../agents/chat-model.js";
4
+ import type { ImageModel } from "../agents/image-model.js";
4
5
  import type { UserAgent } from "../agents/user-agent.js";
5
6
  import { type LoadOptions } from "../loader/index.js";
6
7
  import { AIGNEContext, type Context, type InvokeOptions, type UserContext } from "./context.js";
@@ -27,6 +28,10 @@ export interface AIGNEOptions {
27
28
  * Global model to use for all agents not specifying a model.
28
29
  */
29
30
  model?: ChatModel;
31
+ /**
32
+ * Optional image model to use for image processing tasks.
33
+ */
34
+ imageModel?: ImageModel;
30
35
  /**
31
36
  * Skills to use for the AIGNE instance.
32
37
  */
@@ -71,7 +76,7 @@ export declare class AIGNE<U extends UserContext = UserContext> {
71
76
  * @param options - Options to override the loaded configuration.
72
77
  * @returns A fully initialized AIGNE instance with configured agents and skills.
73
78
  */
74
- static load(path: string, options: AIGNEOptions & Omit<LoadOptions, "path">): Promise<AIGNE>;
79
+ static load(path: string, options?: Omit<AIGNEOptions, keyof LoadOptions> & LoadOptions): Promise<AIGNE>;
75
80
  /**
76
81
  * Creates a new AIGNE instance with the specified options.
77
82
  *
@@ -94,6 +99,10 @@ export declare class AIGNE<U extends UserContext = UserContext> {
94
99
  * Global model to use for all agents that don't specify their own model.
95
100
  */
96
101
  model?: ChatModel;
102
+ /**
103
+ * Optional image model to use for image processing tasks.
104
+ */
105
+ imageModel?: ImageModel;
97
106
  /**
98
107
  * Usage limits applied to this AIGNE instance's execution.
99
108
  */
@@ -28,15 +28,13 @@ class AIGNE {
28
28
  * @param options - Options to override the loaded configuration.
29
29
  * @returns A fully initialized AIGNE instance with configured agents and skills.
30
30
  */
31
- static async load(path, options) {
32
- const { model, agents = [], skills = [], ...aigne } = await (0, index_js_1.load)({ ...options, path });
31
+ static async load(path, options = {}) {
32
+ const { agents = [], skills = [], model, imageModel, ...aigne } = await (0, index_js_1.load)(path, options);
33
33
  return new AIGNE({
34
34
  ...aigne,
35
35
  ...options,
36
- rootDir: aigne.rootDir,
37
- model: options?.model || model,
38
- name: options?.name || aigne.name || undefined,
39
- description: options?.description || aigne.description || undefined,
36
+ model,
37
+ imageModel,
40
38
  agents: agents.concat(options?.agents ?? []),
41
39
  skills: skills.concat(options?.skills ?? []),
42
40
  });
@@ -53,6 +51,7 @@ class AIGNE {
53
51
  this.name = options?.name;
54
52
  this.description = options?.description;
55
53
  this.model = options?.model;
54
+ this.imageModel = options?.imageModel;
56
55
  this.limits = options?.limits;
57
56
  this.observer =
58
57
  process.env.AIGNE_OBSERVABILITY_DISABLED === "true"
@@ -85,6 +84,10 @@ class AIGNE {
85
84
  * Global model to use for all agents that don't specify their own model.
86
85
  */
87
86
  model;
87
+ /**
88
+ * Optional image model to use for image processing tasks.
89
+ */
90
+ imageModel;
88
91
  /**
89
92
  * Usage limits applied to this AIGNE instance's execution.
90
93
  */
@@ -223,6 +226,7 @@ class AIGNE {
223
226
  exports.AIGNE = AIGNE;
224
227
  const aigneOptionsSchema = zod_1.z.object({
225
228
  model: zod_1.z.custom().optional(),
229
+ imageModel: zod_1.z.custom().optional(),
226
230
  skills: zod_1.z.array(zod_1.z.custom()).optional(),
227
231
  agents: zod_1.z.array(zod_1.z.custom()).optional(),
228
232
  observer: zod_1.z.custom().optional(),
@@ -3,6 +3,7 @@ import type { Span } from "@opentelemetry/api";
3
3
  import { Emitter } from "strict-event-emitter";
4
4
  import { type Agent, type AgentHooks, type AgentInvokeOptions, type AgentProcessAsyncGenerator, type AgentResponse, type AgentResponseStream, type Message } from "../agents/agent.js";
5
5
  import type { ChatModel } from "../agents/chat-model.js";
6
+ import type { ImageModel } from "../agents/image-model.js";
6
7
  import { UserAgent } from "../agents/user-agent.js";
7
8
  import type { Memory } from "../memory/memory.js";
8
9
  import { type OmitPropertiesFromArrayFirstElement } from "../utils/type-utils.js";
@@ -73,6 +74,7 @@ export interface Context<U extends UserContext = UserContext> extends TypedEvent
73
74
  parentId?: string;
74
75
  rootId: string;
75
76
  model?: ChatModel;
77
+ imageModel?: ImageModel;
76
78
  skills?: Agent[];
77
79
  agents: Agent[];
78
80
  observer?: AIGNEObserver;
@@ -155,6 +157,7 @@ export declare class AIGNEContext implements Context {
155
157
  readonly internal: AIGNEContextShared;
156
158
  get messageQueue(): MessageQueue;
157
159
  get model(): ChatModel | undefined;
160
+ get imageModel(): ImageModel<import("../agents/image-model.js").ImageModelInput, import("../agents/image-model.js").ImageModelOutput> | undefined;
158
161
  get skills(): Agent<any, any>[] | undefined;
159
162
  get agents(): Agent<any, any>[];
160
163
  get observer(): AIGNEObserver | undefined;
@@ -187,13 +190,14 @@ export declare class AIGNEContext implements Context {
187
190
  declare class AIGNEContextShared {
188
191
  private readonly parent?;
189
192
  spans: Span[];
190
- constructor(parent?: (Pick<Context, "model" | "agents" | "skills" | "limits" | "observer"> & {
193
+ constructor(parent?: (Pick<Context, "model" | "imageModel" | "agents" | "skills" | "limits" | "observer"> & {
191
194
  messageQueue?: MessageQueue;
192
195
  events?: Emitter<any>;
193
196
  }) | undefined);
194
197
  readonly messageQueue: MessageQueue;
195
198
  readonly events: Emitter<any>;
196
199
  get model(): ChatModel | undefined;
200
+ get imageModel(): ImageModel<import("../agents/image-model.js").ImageModelInput, import("../agents/image-model.js").ImageModelOutput> | undefined;
197
201
  get skills(): Agent<any, any>[] | undefined;
198
202
  get agents(): Agent<any, any>[];
199
203
  get observer(): AIGNEObserver | undefined;
@@ -61,6 +61,9 @@ class AIGNEContext {
61
61
  get model() {
62
62
  return this.internal.model;
63
63
  }
64
+ get imageModel() {
65
+ return this.internal.imageModel;
66
+ }
64
67
  get skills() {
65
68
  return this.internal.skills;
66
69
  }
@@ -306,6 +309,9 @@ class AIGNEContextShared {
306
309
  get model() {
307
310
  return this.parent?.model;
308
311
  }
312
+ get imageModel() {
313
+ return this.parent?.imageModel;
314
+ }
309
315
  get skills() {
310
316
  return this.parent?.skills;
311
317
  }
@@ -2,6 +2,8 @@ export * from "./agents/agent.js";
2
2
  export * from "./agents/ai-agent.js";
3
3
  export * from "./agents/chat-model.js";
4
4
  export * from "./agents/guide-rail-agent.js";
5
+ export * from "./agents/image-agent.js";
6
+ export * from "./agents/image-model.js";
5
7
  export * from "./agents/mcp-agent.js";
6
8
  export * from "./agents/team-agent.js";
7
9
  export * from "./agents/transform-agent.js";
package/lib/cjs/index.js CHANGED
@@ -18,6 +18,8 @@ __exportStar(require("./agents/agent.js"), exports);
18
18
  __exportStar(require("./agents/ai-agent.js"), exports);
19
19
  __exportStar(require("./agents/chat-model.js"), exports);
20
20
  __exportStar(require("./agents/guide-rail-agent.js"), exports);
21
+ __exportStar(require("./agents/image-agent.js"), exports);
22
+ __exportStar(require("./agents/image-model.js"), exports);
21
23
  __exportStar(require("./agents/mcp-agent.js"), exports);
22
24
  __exportStar(require("./agents/team-agent.js"), exports);
23
25
  __exportStar(require("./agents/transform-agent.js"), exports);
@@ -39,6 +39,11 @@ export interface AIAgentSchema extends BaseAgentSchema {
39
39
  outputKey?: string;
40
40
  toolChoice?: AIAgentToolChoice;
41
41
  }
42
+ export interface ImageAgentSchema extends BaseAgentSchema {
43
+ type: "image";
44
+ instructions: string;
45
+ modelOptions?: Record<string, any>;
46
+ }
42
47
  export interface MCPAgentSchema extends BaseAgentSchema {
43
48
  type: "mcp";
44
49
  url?: string;
@@ -64,6 +69,6 @@ export interface FunctionAgentSchema extends BaseAgentSchema {
64
69
  type: "function";
65
70
  process: FunctionAgentFn;
66
71
  }
67
- export type AgentSchema = AIAgentSchema | MCPAgentSchema | TeamAgentSchema | TransformAgentSchema | FunctionAgentSchema;
72
+ export type AgentSchema = AIAgentSchema | ImageAgentSchema | MCPAgentSchema | TeamAgentSchema | TransformAgentSchema | FunctionAgentSchema;
68
73
  export declare function parseAgentFile(path: string, data: object): Promise<AgentSchema>;
69
74
  export declare function loadAgentFromYamlFile(path: string): Promise<AgentSchema>;
@@ -50,24 +50,33 @@ async function parseAgentFile(path, data) {
50
50
  })),
51
51
  ])),
52
52
  });
53
+ const instructionsSchema = zod_1.z
54
+ .union([
55
+ zod_1.z.string(),
56
+ zod_1.z.object({
57
+ url: zod_1.z.string(),
58
+ }),
59
+ ])
60
+ .transform((v) => typeof v === "string"
61
+ ? v
62
+ : v && index_js_1.nodejs.fs.readFile(index_js_1.nodejs.path.join(index_js_1.nodejs.path.dirname(path), v.url), "utf8"));
53
63
  return (0, schema_js_1.camelizeSchema)(zod_1.z.discriminatedUnion("type", [
54
64
  zod_1.z
55
65
  .object({
56
66
  type: zod_1.z.literal("ai"),
57
- instructions: (0, schema_js_1.optionalize)(zod_1.z.union([
58
- zod_1.z.string(),
59
- zod_1.z.object({
60
- url: zod_1.z.string(),
61
- }),
62
- ])).transform((v) => typeof v === "string"
63
- ? v
64
- : v &&
65
- index_js_1.nodejs.fs.readFile(index_js_1.nodejs.path.join(index_js_1.nodejs.path.dirname(path), v.url), "utf8")),
67
+ instructions: (0, schema_js_1.optionalize)(instructionsSchema),
66
68
  inputKey: (0, schema_js_1.optionalize)(zod_1.z.string()),
67
69
  outputKey: (0, schema_js_1.optionalize)(zod_1.z.string()),
68
70
  toolChoice: (0, schema_js_1.optionalize)(zod_1.z.nativeEnum(ai_agent_js_1.AIAgentToolChoice)),
69
71
  })
70
72
  .extend(baseAgentSchema.shape),
73
+ zod_1.z
74
+ .object({
75
+ type: zod_1.z.literal("image"),
76
+ instructions: instructionsSchema,
77
+ modelOptions: (0, schema_js_1.optionalize)((0, schema_js_1.camelizeSchema)(zod_1.z.record(zod_1.z.any()))),
78
+ })
79
+ .extend(baseAgentSchema.shape),
71
80
  zod_1.z
72
81
  .object({
73
82
  type: zod_1.z.literal("mcp"),