@aigne/core 1.20.1 → 1.22.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 (75) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/lib/cjs/agents/agent.d.ts +6 -4
  3. package/lib/cjs/agents/agent.js +2 -0
  4. package/lib/cjs/agents/ai-agent.d.ts +8 -10
  5. package/lib/cjs/agents/ai-agent.js +6 -5
  6. package/lib/cjs/agents/chat-model.d.ts +1 -0
  7. package/lib/cjs/agents/chat-model.js +1 -0
  8. package/lib/cjs/agents/mcp-agent.d.ts +5 -0
  9. package/lib/cjs/agents/mcp-agent.js +5 -0
  10. package/lib/cjs/agents/team-agent.d.ts +1 -0
  11. package/lib/cjs/agents/team-agent.js +1 -0
  12. package/lib/cjs/agents/user-agent.d.ts +1 -0
  13. package/lib/cjs/agents/user-agent.js +6 -3
  14. package/lib/cjs/aigne/aigne.d.ts +15 -6
  15. package/lib/cjs/aigne/aigne.js +19 -2
  16. package/lib/cjs/aigne/context.d.ts +31 -10
  17. package/lib/cjs/aigne/context.js +86 -14
  18. package/lib/cjs/loader/agent-js.d.ts +2 -2
  19. package/lib/cjs/loader/agent-js.js +3 -0
  20. package/lib/cjs/loader/agent-yaml.d.ts +23 -6
  21. package/lib/cjs/loader/agent-yaml.js +38 -2
  22. package/lib/cjs/loader/index.d.ts +1 -1
  23. package/lib/cjs/loader/index.js +16 -4
  24. package/lib/cjs/memory/memory.d.ts +1 -0
  25. package/lib/cjs/memory/memory.js +1 -0
  26. package/lib/cjs/memory/recorder.d.ts +1 -0
  27. package/lib/cjs/memory/recorder.js +1 -0
  28. package/lib/cjs/memory/retriever.d.ts +1 -0
  29. package/lib/cjs/memory/retriever.js +1 -0
  30. package/lib/cjs/prompt/prompt-builder.d.ts +1 -1
  31. package/lib/dts/agents/agent.d.ts +6 -4
  32. package/lib/dts/agents/ai-agent.d.ts +8 -10
  33. package/lib/dts/agents/chat-model.d.ts +1 -0
  34. package/lib/dts/agents/mcp-agent.d.ts +5 -0
  35. package/lib/dts/agents/team-agent.d.ts +1 -0
  36. package/lib/dts/agents/user-agent.d.ts +1 -0
  37. package/lib/dts/aigne/aigne.d.ts +15 -6
  38. package/lib/dts/aigne/context.d.ts +31 -10
  39. package/lib/dts/loader/agent-js.d.ts +2 -2
  40. package/lib/dts/loader/agent-yaml.d.ts +23 -6
  41. package/lib/dts/loader/index.d.ts +1 -1
  42. package/lib/dts/memory/memory.d.ts +1 -0
  43. package/lib/dts/memory/recorder.d.ts +1 -0
  44. package/lib/dts/memory/retriever.d.ts +1 -0
  45. package/lib/dts/prompt/prompt-builder.d.ts +1 -1
  46. package/lib/esm/agents/agent.d.ts +6 -4
  47. package/lib/esm/agents/agent.js +2 -0
  48. package/lib/esm/agents/ai-agent.d.ts +8 -10
  49. package/lib/esm/agents/ai-agent.js +3 -2
  50. package/lib/esm/agents/chat-model.d.ts +1 -0
  51. package/lib/esm/agents/chat-model.js +1 -0
  52. package/lib/esm/agents/mcp-agent.d.ts +5 -0
  53. package/lib/esm/agents/mcp-agent.js +5 -0
  54. package/lib/esm/agents/team-agent.d.ts +1 -0
  55. package/lib/esm/agents/team-agent.js +1 -0
  56. package/lib/esm/agents/user-agent.d.ts +1 -0
  57. package/lib/esm/agents/user-agent.js +6 -3
  58. package/lib/esm/aigne/aigne.d.ts +15 -6
  59. package/lib/esm/aigne/aigne.js +19 -2
  60. package/lib/esm/aigne/context.d.ts +31 -10
  61. package/lib/esm/aigne/context.js +86 -14
  62. package/lib/esm/loader/agent-js.d.ts +2 -2
  63. package/lib/esm/loader/agent-js.js +3 -0
  64. package/lib/esm/loader/agent-yaml.d.ts +23 -6
  65. package/lib/esm/loader/agent-yaml.js +38 -2
  66. package/lib/esm/loader/index.d.ts +1 -1
  67. package/lib/esm/loader/index.js +17 -5
  68. package/lib/esm/memory/memory.d.ts +1 -0
  69. package/lib/esm/memory/memory.js +1 -0
  70. package/lib/esm/memory/recorder.d.ts +1 -0
  71. package/lib/esm/memory/recorder.js +1 -0
  72. package/lib/esm/memory/retriever.d.ts +1 -0
  73. package/lib/esm/memory/retriever.js +1 -0
  74. package/lib/esm/prompt/prompt-builder.d.ts +1 -1
  75. package/package.json +2 -1
@@ -1,3 +1,4 @@
1
+ import { AIGNEObserver } from "@aigne/observability";
1
2
  import { Agent, type AgentResponse, type AgentResponseStream, type Message } from "../agents/agent.js";
2
3
  import { ChatModel } from "../agents/chat-model.js";
3
4
  import type { UserAgent } from "../agents/user-agent.js";
@@ -33,6 +34,10 @@ export interface AIGNEOptions {
33
34
  * Limits for the AIGNE instance, such as timeout, max tokens, max invocations, etc.
34
35
  */
35
36
  limits?: ContextLimits;
37
+ /**
38
+ * Observer for the AIGNE instance.
39
+ */
40
+ observer?: AIGNEObserver;
36
41
  }
37
42
  /**
38
43
  * AIGNE is a class that orchestrates multiple agents to build complex AI applications.
@@ -98,6 +103,10 @@ export declare class AIGNE<U extends UserContext = UserContext> {
98
103
  readonly agents: Agent<Message, Message>[] & {
99
104
  [key: string]: Agent<Message, Message>;
100
105
  };
106
+ /**
107
+ * Observer for the AIGNE instance.
108
+ */
109
+ readonly observer?: AIGNEObserver;
101
110
  /**
102
111
  * Adds one or more agents to this AIGNE instance.
103
112
  * Each agent is attached to this AIGNE instance, allowing it to access the AIGNE's resources.
@@ -111,7 +120,7 @@ export declare class AIGNE<U extends UserContext = UserContext> {
111
120
  *
112
121
  * @returns A new AIGNEContext instance bound to this AIGNE.
113
122
  */
114
- newContext(options?: Partial<Context>): AIGNEContext;
123
+ newContext(options?: Partial<Pick<Context, "userContext" | "memories">>): AIGNEContext;
115
124
  /**
116
125
  * Creates a user agent for consistent interactions with a specified agent.
117
126
  * This method allows you to create a wrapper around an agent for repeated invocations.
@@ -134,7 +143,7 @@ export declare class AIGNE<U extends UserContext = UserContext> {
134
143
  * @param options.streaming - Must be false to return a response stream
135
144
  * @returns A promise resolving to a tuple containing the agent's response and the final active agent
136
145
  */
137
- invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I, options: InvokeOptions<U> & {
146
+ invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I & Message, options: InvokeOptions<U> & {
138
147
  returnActiveAgent: true;
139
148
  streaming?: false;
140
149
  }): Promise<[O, Agent]>;
@@ -148,7 +157,7 @@ export declare class AIGNE<U extends UserContext = UserContext> {
148
157
  * @param options.streaming - Must be true to return a response stream
149
158
  * @returns A promise resolving to a tuple containing the agent's response stream and a promise for the final agent
150
159
  */
151
- invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I, options: InvokeOptions<U> & {
160
+ invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I & Message, options: InvokeOptions<U> & {
152
161
  returnActiveAgent: true;
153
162
  streaming: true;
154
163
  }): Promise<[AgentResponseStream<O>, Promise<Agent>]>;
@@ -165,7 +174,7 @@ export declare class AIGNE<U extends UserContext = UserContext> {
165
174
  * Here's a simple example of how to invoke an agent:
166
175
  * {@includeCode ../../test/aigne/aigne.test.ts#example-simple}
167
176
  */
168
- invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I, options?: InvokeOptions<U> & {
177
+ invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I & Message, options?: InvokeOptions<U> & {
169
178
  returnActiveAgent?: false;
170
179
  streaming?: false;
171
180
  }): Promise<O>;
@@ -182,7 +191,7 @@ export declare class AIGNE<U extends UserContext = UserContext> {
182
191
  * Here's an example of how to invoke an agent with streaming response:
183
192
  * {@includeCode ../../test/aigne/aigne.test.ts#example-streaming}
184
193
  */
185
- invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I, options: InvokeOptions<U> & {
194
+ invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I & Message, options: InvokeOptions<U> & {
186
195
  returnActiveAgent?: false;
187
196
  streaming: true;
188
197
  }): Promise<AgentResponseStream<O>>;
@@ -196,7 +205,7 @@ export declare class AIGNE<U extends UserContext = UserContext> {
196
205
  * @returns Either a UserAgent (when no message provided) or a promise resolving to the agent's response
197
206
  * with optional active agent information based on the provided options
198
207
  */
199
- invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message?: I, options?: InvokeOptions<U>): UserAgent<I, O> | Promise<AgentResponse<O> | [AgentResponse<O>, Agent]>;
208
+ invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message?: I & Message, options?: InvokeOptions<U>): UserAgent<I, O> | Promise<AgentResponse<O> | [AgentResponse<O>, Agent]>;
200
209
  /**
201
210
  * Publishes a message to the message queue for inter-agent communication.
202
211
  * This method broadcasts a message to all subscribers of the specified topic(s).
@@ -1,3 +1,5 @@
1
+ import type { AIGNEObserver } from "@aigne/observability";
2
+ import type { Span } from "@opentelemetry/api";
1
3
  import { Emitter } from "strict-event-emitter";
2
4
  import { Agent, type AgentInvokeOptions, type AgentProcessAsyncGenerator, type AgentResponse, type AgentResponseStream, type Message } from "../agents/agent.js";
3
5
  import type { ChatModel } from "../agents/chat-model.js";
@@ -45,6 +47,13 @@ export interface InvokeOptions<U extends UserContext = UserContext> extends Part
45
47
  returnMetadata?: boolean;
46
48
  disableTransfer?: boolean;
47
49
  sourceAgent?: Agent;
50
+ /**
51
+ * Whether to create a new context for this invocation.
52
+ * If false, the invocation will use the current context.
53
+ *
54
+ * @default true
55
+ */
56
+ newContext?: boolean;
48
57
  }
49
58
  /**
50
59
  * @hidden
@@ -57,8 +66,11 @@ export interface UserContext extends Record<string, unknown> {
57
66
  export interface Context<U extends UserContext = UserContext> extends TypedEventEmitter<ContextEventMap, ContextEmitEventMap> {
58
67
  id: string;
59
68
  parentId?: string;
69
+ rootId: string;
60
70
  model?: ChatModel;
61
71
  skills?: Agent[];
72
+ observer?: AIGNEObserver;
73
+ span?: Span;
62
74
  usage: ContextUsage;
63
75
  limits?: ContextLimits;
64
76
  status?: "normal" | "timeout";
@@ -78,11 +90,11 @@ export interface Context<U extends UserContext = UserContext> extends TypedEvent
78
90
  * @param options.streaming return a stream of the output
79
91
  * @returns the output of the agent and the final active agent
80
92
  */
81
- invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I, options: InvokeOptions & {
93
+ invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I & Message, options: InvokeOptions & {
82
94
  returnActiveAgent: true;
83
95
  streaming?: false;
84
96
  }): Promise<[O, Agent]>;
85
- invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I, options: InvokeOptions & {
97
+ invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I & Message, options: InvokeOptions & {
86
98
  returnActiveAgent: true;
87
99
  streaming: true;
88
100
  }): Promise<[AgentResponseStream<O>, Promise<Agent>]>;
@@ -92,13 +104,13 @@ export interface Context<U extends UserContext = UserContext> extends TypedEvent
92
104
  * @param message Message to pass to the agent
93
105
  * @returns the output of the agent
94
106
  */
95
- invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I, options?: InvokeOptions & {
107
+ invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I & Message, options?: InvokeOptions & {
96
108
  streaming?: false;
97
109
  }): Promise<O>;
98
- invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I, options: InvokeOptions & {
110
+ invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message: I & Message, options: InvokeOptions & {
99
111
  streaming: true;
100
112
  }): Promise<AgentResponseStream<O>>;
101
- invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message?: I, options?: InvokeOptions): UserAgent<I, O> | Promise<AgentResponse<O> | [AgentResponse<O>, Agent]>;
113
+ invoke<I extends Message, O extends Message>(agent: Agent<I, O>, message?: I & Message, options?: InvokeOptions): UserAgent<I, O> | Promise<AgentResponse<O> | [AgentResponse<O>, Agent]>;
102
114
  /**
103
115
  * Publish a message to a topic, the aigne will invoke the listeners of the topic
104
116
  * @param topic topic name, or an array of topic names
@@ -126,12 +138,18 @@ export interface Context<U extends UserContext = UserContext> extends TypedEvent
126
138
  * @hidden
127
139
  */
128
140
  export declare class AIGNEContext implements Context {
129
- constructor(...[parent, ...args]: ConstructorParameters<typeof AIGNEContextShared>);
130
- parentId?: string;
141
+ constructor(parent?: ConstructorParameters<typeof AIGNEContextShared>[0], { reset }?: {
142
+ reset?: boolean;
143
+ });
131
144
  id: string;
145
+ parentId?: string;
146
+ rootId: string;
147
+ span?: Span;
132
148
  readonly internal: AIGNEContextShared;
149
+ get messageQueue(): MessageQueue;
133
150
  get model(): ChatModel | undefined;
134
151
  get skills(): Agent<Message, Message>[] | undefined;
152
+ get observer(): AIGNEObserver | undefined;
135
153
  get limits(): ContextLimits | undefined;
136
154
  get status(): "normal" | "timeout";
137
155
  get usage(): ContextUsage;
@@ -148,19 +166,22 @@ export declare class AIGNEContext implements Context {
148
166
  subscribe: Context["subscribe"];
149
167
  unsubscribe: Context["unsubscribe"];
150
168
  emit<K extends keyof ContextEmitEventMap>(eventName: K, ...args: Args<K, ContextEmitEventMap>): boolean;
169
+ private trace;
151
170
  on<K extends keyof ContextEventMap>(eventName: K, listener: Listener<K, ContextEventMap>): this;
152
171
  once<K extends keyof ContextEventMap>(eventName: K, listener: Listener<K, ContextEventMap>): this;
153
172
  off<K extends keyof ContextEventMap>(eventName: K, listener: Listener<K, ContextEventMap>): this;
154
173
  }
155
174
  declare class AIGNEContextShared {
156
175
  private readonly parent?;
157
- constructor(parent?: (Pick<Context, "model" | "skills" | "limits"> & {
176
+ span?: Span;
177
+ constructor(parent?: (Pick<Context, "model" | "skills" | "limits" | "observer"> & {
158
178
  messageQueue?: MessageQueue;
159
- }) | undefined, overrides?: Partial<Context>);
179
+ }) | undefined);
160
180
  readonly messageQueue: MessageQueue;
161
181
  readonly events: Emitter<any>;
162
182
  get model(): ChatModel | undefined;
163
183
  get skills(): Agent<Message, Message>[] | undefined;
184
+ get observer(): AIGNEObserver | undefined;
164
185
  get limits(): ContextLimits | undefined;
165
186
  usage: ContextUsage;
166
187
  userContext: Context["userContext"];
@@ -169,7 +190,7 @@ declare class AIGNEContextShared {
169
190
  private timer?;
170
191
  private initTimeout;
171
192
  get status(): "normal" | "timeout";
172
- invoke<I extends Message, O extends Message>(agent: Agent<I, O>, input: I, context: Context, options?: InvokeOptions): AgentProcessAsyncGenerator<O & {
193
+ invoke<I extends Message, O extends Message>(agent: Agent<I, O>, input: I & Message, context: Context, options?: InvokeOptions): AgentProcessAsyncGenerator<O & {
173
194
  __activeAgent__: Agent;
174
195
  }>;
175
196
  private invokeAgent;
@@ -1,6 +1,6 @@
1
1
  import { type ZodObject, type ZodType, z } from "zod";
2
- import type { Message } from "../agents/agent.js";
3
- export declare function loadAgentFromJsFile(path: string): Promise<{
2
+ import { Agent, type Message } from "../agents/agent.js";
3
+ export declare function loadAgentFromJsFile(path: string): Promise<Agent<any, any> | {
4
4
  process: (args_0: Message) => Message;
5
5
  name: string;
6
6
  description?: string | undefined;
@@ -1,6 +1,29 @@
1
1
  import { type ZodObject, type ZodType, z } from "zod";
2
2
  import { AIAgentToolChoice } from "../agents/ai-agent.js";
3
+ import { ProcessMode } from "../agents/team-agent.js";
3
4
  export declare function loadAgentFromYamlFile(path: string): Promise<{
5
+ type: "mcp";
6
+ url?: string | undefined;
7
+ command?: string | undefined;
8
+ args?: string[] | undefined;
9
+ } | {
10
+ type: "team";
11
+ name: string;
12
+ description?: string | undefined;
13
+ skills?: string[] | undefined;
14
+ mode?: ProcessMode | undefined;
15
+ inputSchema?: ZodObject<Record<string, ZodType<any, z.ZodTypeDef, any>>, z.UnknownKeysParam, z.ZodTypeAny, {
16
+ [x: string]: any;
17
+ }, {
18
+ [x: string]: any;
19
+ }> | undefined;
20
+ outputSchema?: ZodObject<Record<string, ZodType<any, z.ZodTypeDef, any>>, z.UnknownKeysParam, z.ZodTypeAny, {
21
+ [x: string]: any;
22
+ }, {
23
+ [x: string]: any;
24
+ }> | undefined;
25
+ } | {
26
+ instructions: string | undefined;
4
27
  type: "ai";
5
28
  name: string;
6
29
  description?: string | undefined;
@@ -9,7 +32,6 @@ export declare function loadAgentFromYamlFile(path: string): Promise<{
9
32
  provider: string;
10
33
  subscribeTopic?: string[] | undefined;
11
34
  } | undefined;
12
- instructions?: string | undefined;
13
35
  inputSchema?: ZodObject<Record<string, ZodType<any, z.ZodTypeDef, any>>, z.UnknownKeysParam, z.ZodTypeAny, {
14
36
  [x: string]: any;
15
37
  }, {
@@ -23,9 +45,4 @@ export declare function loadAgentFromYamlFile(path: string): Promise<{
23
45
  inputKey?: string | undefined;
24
46
  outputKey?: string | undefined;
25
47
  toolChoice?: AIAgentToolChoice | undefined;
26
- } | {
27
- type: "mcp";
28
- url?: string | undefined;
29
- args?: string[] | undefined;
30
- command?: string | undefined;
31
48
  }>;
@@ -1,6 +1,6 @@
1
1
  import type { Camelize } from "camelize-ts";
2
2
  import { z } from "zod";
3
- import { type Agent } from "../agents/agent.js";
3
+ import { Agent } from "../agents/agent.js";
4
4
  import type { ChatModel, ChatModelOptions } from "../agents/chat-model.js";
5
5
  import type { MemoryAgent, MemoryAgentOptions } from "../memory/memory.js";
6
6
  export interface LoadOptions {
@@ -21,6 +21,7 @@ export interface MemoryAgentOptions extends Partial<Pick<MemoryAgent, "recorder"
21
21
  * instead provides memory management capabilities to the system.
22
22
  */
23
23
  export declare class MemoryAgent extends Agent {
24
+ tag: string;
24
25
  /**
25
26
  * Creates a new MemoryAgent instance.
26
27
  */
@@ -77,6 +77,7 @@ export declare const memoryRecorderOutputSchema: z.ZodObject<{
77
77
  * implementations of the process method to handle the actual storage logic.
78
78
  */
79
79
  export declare abstract class MemoryRecorder extends Agent<MemoryRecorderInput, MemoryRecorderOutput> {
80
+ tag: string;
80
81
  /**
81
82
  * Creates a new MemoryRecorder instance with predefined input and output schemas.
82
83
  *
@@ -90,6 +90,7 @@ export declare const memoryRetrieverOutputSchema: z.ZodObject<{
90
90
  * implementations of the process method to handle the actual retrieval logic.
91
91
  */
92
92
  export declare abstract class MemoryRetriever extends Agent<MemoryRetrieverInput, MemoryRetrieverOutput> {
93
+ tag: string;
93
94
  /**
94
95
  * Creates a new MemoryRetriever instance with predefined input and output schemas.
95
96
  *
@@ -7,7 +7,7 @@ export interface PromptBuilderOptions {
7
7
  instructions?: string | ChatMessagesTemplate;
8
8
  }
9
9
  export interface PromptBuildOptions extends Pick<AgentInvokeOptions, "context"> {
10
- agent?: AIAgent<any, any, any>;
10
+ agent?: AIAgent;
11
11
  input?: Message;
12
12
  model?: ChatModel;
13
13
  outputSchema?: Agent["outputSchema"];
@@ -176,6 +176,7 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
176
176
  * List of memories this agent can use
177
177
  */
178
178
  readonly memories: MemoryAgent[];
179
+ tag?: string;
179
180
  /**
180
181
  * Maximum number of memory items to retrieve
181
182
  */
@@ -341,7 +342,7 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
341
342
  * Here's an example of invoking an agent with regular mode:
342
343
  * {@includeCode ../../test/agents/agent.test.ts#example-invoke}
343
344
  */
344
- invoke(input: I, options?: Partial<AgentInvokeOptions> & {
345
+ invoke(input: I & Message, options?: Partial<AgentInvokeOptions> & {
345
346
  streaming?: false;
346
347
  }): Promise<O>;
347
348
  /**
@@ -359,7 +360,7 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
359
360
  * Here's an example of invoking an agent with streaming response:
360
361
  * {@includeCode ../../test/agents/agent.test.ts#example-invoke-streaming}
361
362
  */
362
- invoke(input: I, options: Partial<AgentInvokeOptions> & {
363
+ invoke(input: I & Message, options: Partial<AgentInvokeOptions> & {
363
364
  streaming: true;
364
365
  }): Promise<AgentResponseStream<O>>;
365
366
  /**
@@ -371,8 +372,8 @@ export declare abstract class Agent<I extends Message = Message, O extends Messa
371
372
  * @param options Invocation options
372
373
  * @returns Agent response (streaming or regular)
373
374
  */
374
- invoke(input: I, options?: Partial<AgentInvokeOptions>): Promise<AgentResponse<O>>;
375
- protected invokeSkill<I extends Message, O extends Message>(skill: Agent<I, O>, input: I, options: AgentInvokeOptions): Promise<O>;
375
+ invoke(input: I & Message, options?: Partial<AgentInvokeOptions>): Promise<AgentResponse<O>>;
376
+ protected invokeSkill<I extends Message, O extends Message>(skill: Agent<I, O>, input: I & Message, options: AgentInvokeOptions): Promise<O>;
376
377
  /**
377
378
  * Process agent output
378
379
  *
@@ -723,6 +724,7 @@ export interface FunctionAgentOptions<I extends Message = Message, O extends Mes
723
724
  * {@includeCode ../../test/agents/agent.test.ts#example-function-agent}
724
725
  */
725
726
  export declare class FunctionAgent<I extends Message = Message, O extends Message = Message> extends Agent<I, O> {
727
+ tag: string;
726
728
  /**
727
729
  * Create a function agent from a function or options
728
730
  *
@@ -83,6 +83,7 @@ export class Agent {
83
83
  * List of memories this agent can use
84
84
  */
85
85
  memories = [];
86
+ tag;
86
87
  /**
87
88
  * Maximum number of memory items to retrieve
88
89
  */
@@ -596,6 +597,7 @@ function checkAgentInputOutputSchema(schema) {
596
597
  * {@includeCode ../../test/agents/agent.test.ts#example-function-agent}
597
598
  */
598
599
  export class FunctionAgent extends Agent {
600
+ tag = "FunctionAgent";
599
601
  /**
600
602
  * Create a function agent from a function or options
601
603
  *
@@ -3,6 +3,7 @@ import { PromptBuilder } from "../prompt/prompt-builder.js";
3
3
  import { Agent, type AgentInvokeOptions, type AgentOptions, type AgentProcessAsyncGenerator, type Message } from "./agent.js";
4
4
  import { ChatModel, type ChatModelInput } from "./chat-model.js";
5
5
  import type { GuideRailAgentOutput } from "./guide-rail-agent.js";
6
+ export declare const DEFAULT_OUTPUT_KEY = "message";
6
7
  /**
7
8
  * Configuration options for an AI Agent
8
9
  *
@@ -12,7 +13,7 @@ import type { GuideRailAgentOutput } from "./guide-rail-agent.js";
12
13
  * @template I The input message type the agent accepts
13
14
  * @template O The output message type the agent returns
14
15
  */
15
- export interface AIAgentOptions<InputKey extends string = string, I extends Message & InputMessage<InputKey> = Message & InputMessage<InputKey>, O extends Message = Message> extends AgentOptions<Omit<I, InputKey> & Partial<InputMessage<InputKey>>, O> {
16
+ export interface AIAgentOptions<I extends Message = Message, O extends Message = Message> extends AgentOptions<I, O> {
16
17
  /**
17
18
  * The language model to use for this agent
18
19
  *
@@ -29,7 +30,7 @@ export interface AIAgentOptions<InputKey extends string = string, I extends Mess
29
30
  /**
30
31
  * Pick a message from input to use as the user's message
31
32
  */
32
- inputKey?: InputKey;
33
+ inputKey?: string;
33
34
  /**
34
35
  * Custom key to use for text output in the response
35
36
  *
@@ -110,9 +111,6 @@ export declare const aiAgentToolChoiceSchema: z.ZodUnion<[z.ZodNativeEnum<typeof
110
111
  export declare const aiAgentOptionsSchema: ZodObject<{
111
112
  [key in keyof AIAgentOptions]: ZodType<AIAgentOptions[key]>;
112
113
  }>;
113
- type InputMessage<K> = K extends string ? {
114
- [key in K]: string;
115
- } : Message;
116
114
  /**
117
115
  * AI-powered agent that leverages language models
118
116
  *
@@ -133,7 +131,8 @@ type InputMessage<K> = K extends string ? {
133
131
  * Basic AIAgent creation:
134
132
  * {@includeCode ../../test/agents/ai-agent.test.ts#example-ai-agent-basic}
135
133
  */
136
- export declare class AIAgent<InputKey extends string = string, I extends Message & InputMessage<InputKey> = Message & InputMessage<InputKey>, O extends Message = Message> extends Agent<I, O> {
134
+ export declare class AIAgent<I extends Message = Message, O extends Message = Message> extends Agent<I, O> {
135
+ tag: string;
137
136
  /**
138
137
  * Create an AIAgent with the specified options
139
138
  *
@@ -146,13 +145,13 @@ export declare class AIAgent<InputKey extends string = string, I extends Message
146
145
  * AI agent with custom instructions:
147
146
  * {@includeCode ../../test/agents/ai-agent.test.ts#example-ai-agent-instructions}
148
147
  */
149
- static from<InputKey extends string, I extends Message & InputMessage<InputKey>, O extends Message>(options: AIAgentOptions<InputKey, I, O>): AIAgent<InputKey, I, O>;
148
+ static from<I extends Message, O extends Message>(options: AIAgentOptions<I, O>): AIAgent<I, O>;
150
149
  /**
151
150
  * Create an AIAgent instance
152
151
  *
153
152
  * @param options Configuration options for the AI agent
154
153
  */
155
- constructor(options: AIAgentOptions<InputKey, I, O>);
154
+ constructor(options: AIAgentOptions<I, O>);
156
155
  /**
157
156
  * The language model used by this agent
158
157
  *
@@ -173,7 +172,7 @@ export declare class AIAgent<InputKey extends string = string, I extends Message
173
172
  /**
174
173
  * Pick a message from input to use as the user's message
175
174
  */
176
- inputKey?: InputKey;
175
+ inputKey?: string;
177
176
  /**
178
177
  * Custom key to use for text output in the response
179
178
  *
@@ -235,4 +234,3 @@ export declare class AIAgent<InputKey extends string = string, I extends Message
235
234
  */
236
235
  _processRouter(input: I, model: ChatModel, modelInput: ChatModelInput, options: AgentInvokeOptions, toolsMap: Map<string, Agent>): AgentProcessAsyncGenerator<O>;
237
236
  }
238
- export {};
@@ -5,7 +5,7 @@ import { checkArguments, isEmpty } from "../utils/type-utils.js";
5
5
  import { Agent, agentOptionsSchema, isAgentResponseDelta, } from "./agent.js";
6
6
  import { ChatModel, } from "./chat-model.js";
7
7
  import { isTransferAgentOutput } from "./types.js";
8
- const DEFAULT_OUTPUT_KEY = "message";
8
+ export const DEFAULT_OUTPUT_KEY = "message";
9
9
  /**
10
10
  * Tool choice options for AI agents
11
11
  *
@@ -77,6 +77,7 @@ export const aiAgentOptionsSchema = agentOptionsSchema.extend({
77
77
  * {@includeCode ../../test/agents/ai-agent.test.ts#example-ai-agent-basic}
78
78
  */
79
79
  export class AIAgent extends Agent {
80
+ tag = "AIAgent";
80
81
  /**
81
82
  * Create an AIAgent with the specified options
82
83
  *
@@ -98,7 +99,7 @@ export class AIAgent extends Agent {
98
99
  * @param options Configuration options for the AI agent
99
100
  */
100
101
  constructor(options) {
101
- super({ ...options, inputSchema: options.inputSchema });
102
+ super(options);
102
103
  checkArguments("AIAgent", aiAgentOptionsSchema, options);
103
104
  this.model = options.model;
104
105
  this.instructions =
@@ -24,6 +24,7 @@ import { Agent, type AgentInvokeOptions, type AgentProcessResult, type Message }
24
24
  * {@includeCode ../../test/agents/chat-model.test.ts#example-chat-model-tools}
25
25
  */
26
26
  export declare abstract class ChatModel extends Agent<ChatModelInput, ChatModelOutput> {
27
+ tag: string;
27
28
  constructor();
28
29
  /**
29
30
  * Indicates whether the model supports parallel tool calls
@@ -24,6 +24,7 @@ import { Agent } from "./agent.js";
24
24
  * {@includeCode ../../test/agents/chat-model.test.ts#example-chat-model-tools}
25
25
  */
26
26
  export class ChatModel extends Agent {
27
+ tag = "ChatModelAgent";
27
28
  constructor() {
28
29
  super({
29
30
  inputSchema: chatModelInputSchema,
@@ -57,6 +57,7 @@ export type SSEServerParameters = {
57
57
  * {@includeCode ../../test/agents/mcp-agent.test.ts#example-mcp-agent-from-sse}
58
58
  */
59
59
  export declare class MCPAgent extends Agent {
60
+ tag: string;
60
61
  /**
61
62
  * Create an MCPAgent from a connection to an SSE server.
62
63
  *
@@ -186,22 +187,26 @@ export interface MCPBaseOptions<I extends Message = Message, O extends Message =
186
187
  client: ClientWithReconnect;
187
188
  }
188
189
  export declare abstract class MCPBase<I extends Message, O extends Message> extends Agent<I, O> {
190
+ tag: string;
189
191
  constructor(options: MCPBaseOptions<I, O>);
190
192
  protected client: ClientWithReconnect;
191
193
  }
192
194
  export declare class MCPTool extends MCPBase<Message, CallToolResult> {
195
+ tag: string;
193
196
  process(input: Message): Promise<CallToolResult>;
194
197
  }
195
198
  export interface MCPPromptInput extends Record<string, unknown> {
196
199
  [key: string]: string;
197
200
  }
198
201
  export declare class MCPPrompt extends MCPBase<MCPPromptInput, GetPromptResult> {
202
+ tag: string;
199
203
  process(input: MCPPromptInput): Promise<GetPromptResult>;
200
204
  }
201
205
  export interface MCPResourceOptions extends MCPBaseOptions<MCPPromptInput, ReadResourceResult> {
202
206
  uri: string;
203
207
  }
204
208
  export declare class MCPResource extends MCPBase<MCPPromptInput, ReadResourceResult> {
209
+ tag: string;
205
210
  constructor(options: MCPResourceOptions);
206
211
  uri: string;
207
212
  process(input: MCPPromptInput): Promise<ReadResourceResult>;
@@ -49,6 +49,7 @@ function getMCPServerString(options) {
49
49
  * {@includeCode ../../test/agents/mcp-agent.test.ts#example-mcp-agent-from-sse}
50
50
  */
51
51
  export class MCPAgent extends Agent {
52
+ tag = "MCPAgent";
52
53
  static from(options) {
53
54
  checkArguments("MCPAgent.from", mcpAgentOptionsSchema, options);
54
55
  if (isSSEServerParameters(options)) {
@@ -244,6 +245,7 @@ class ClientWithReconnect extends Client {
244
245
  }
245
246
  }
246
247
  export class MCPBase extends Agent {
248
+ tag = "MCPBase";
247
249
  constructor(options) {
248
250
  super(options);
249
251
  this.client = options.client;
@@ -251,18 +253,21 @@ export class MCPBase extends Agent {
251
253
  client;
252
254
  }
253
255
  export class MCPTool extends MCPBase {
256
+ tag = "MCPTool";
254
257
  async process(input) {
255
258
  const result = await this.client.callTool({ name: this.name, arguments: input });
256
259
  return result;
257
260
  }
258
261
  }
259
262
  export class MCPPrompt extends MCPBase {
263
+ tag = "MCPPrompt";
260
264
  async process(input) {
261
265
  const result = await this.client.getPrompt({ name: this.name, arguments: input });
262
266
  return result;
263
267
  }
264
268
  }
265
269
  export class MCPResource extends MCPBase {
270
+ tag = "MCPResource";
266
271
  constructor(options) {
267
272
  super(options);
268
273
  this.uri = options.uri;
@@ -52,6 +52,7 @@ export interface TeamAgentOptions<I extends Message, O extends Message> extends
52
52
  * {@includeCode ../../test/agents/team-agent.test.ts#example-team-agent-sequential}
53
53
  */
54
54
  export declare class TeamAgent<I extends Message, O extends Message> extends Agent<I, O> {
55
+ tag: string;
55
56
  /**
56
57
  * Create a TeamAgent from the provided options.
57
58
  *
@@ -42,6 +42,7 @@ export var ProcessMode;
42
42
  * {@includeCode ../../test/agents/team-agent.test.ts#example-team-agent-sequential}
43
43
  */
44
44
  export class TeamAgent extends Agent {
45
+ tag = "TeamAgent";
45
46
  /**
46
47
  * Create a TeamAgent from the provided options.
47
48
  *
@@ -7,6 +7,7 @@ export interface UserAgentOptions<I extends Message = Message, O extends Message
7
7
  activeAgent?: Agent;
8
8
  }
9
9
  export declare class UserAgent<I extends Message = Message, O extends Message = Message> extends Agent<I, O> {
10
+ tag: string;
10
11
  static from<I extends Message, O extends Message>(options: UserAgentOptions<I, O>): UserAgent<I, O>;
11
12
  constructor(options: UserAgentOptions<I, O>);
12
13
  context: Context;
@@ -2,6 +2,7 @@ import { toMessagePayload } from "../aigne/message-queue.js";
2
2
  import { orArrayToArray } from "../utils/type-utils.js";
3
3
  import { Agent, } from "./agent.js";
4
4
  export class UserAgent extends Agent {
5
+ tag = "UserAgent";
5
6
  static from(options) {
6
7
  return new UserAgent(options);
7
8
  }
@@ -23,9 +24,8 @@ export class UserAgent extends Agent {
23
24
  super.publishToTopics(output, options);
24
25
  }
25
26
  invoke = ((input, options = {}) => {
26
- if (!options.context)
27
- this.context = this.context.newContext({ reset: true });
28
- return super.invoke(input, { ...options, context: this.context });
27
+ options.context ??= this.context.newContext({ reset: true });
28
+ return super.invoke(input, options);
29
29
  });
30
30
  async process(input, options) {
31
31
  if (this._process) {
@@ -35,6 +35,9 @@ export class UserAgent extends Agent {
35
35
  const [output, agent] = await options.context.invoke(this.activeAgent, input, {
36
36
  returnActiveAgent: true,
37
37
  streaming: true,
38
+ // Do not create a new context for the nested agent invocation,
39
+ // We are resetting the context in the override invoke method
40
+ newContext: false,
38
41
  });
39
42
  agent.then((agent) => {
40
43
  this.activeAgent = agent;