@mozaik-ai/core 3.4.1 → 3.5.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/dist/index.d.mts CHANGED
@@ -449,45 +449,44 @@ interface ToolExecutor {
449
449
  produce(functionCallItem: FunctionCallItem, signal?: AbortSignal): AsyncIterable<FunctionCallOutputItem>;
450
450
  }
451
451
 
452
- interface InferenceHandler {
453
- produce(context: ModelContext, model: GenerativeModel, signal?: AbortSignal): AsyncIterable<ReasoningItem | FunctionCallItem | ModelMessageItem>;
454
- }
455
-
456
452
  interface MessageSender {
457
453
  stream(message: string, signal?: AbortSignal): AsyncIterable<string>;
458
454
  }
459
455
 
460
- declare abstract class Participant {
461
- abstract onFunctionCallOutput(participant: Participant, item: FunctionCallOutputItem): Promise<void>;
462
- abstract onMessage(participant: Participant, message: string): Promise<void>;
463
- abstract onFunctionCall(participant: Participant, item: FunctionCallItem): Promise<void>;
464
- abstract onReasoning(participant: Participant, item: ReasoningItem): Promise<void>;
465
- abstract onOutputMessage(participant: Participant, item: ModelMessageItem): Promise<void>;
456
+ interface InferenceHandler {
457
+ produce(context: ModelContext, model: GenerativeModel, signal?: AbortSignal): AsyncIterable<ReasoningItem | FunctionCallItem | ModelMessageItem>;
466
458
  }
467
459
 
468
460
  declare abstract class AgenticEnvironment {
469
- protected toolExecutor: ToolExecutor;
470
- protected messageSender: MessageSender;
471
- protected inferenceHandler: InferenceHandler;
472
- protected participants: Participant[];
473
- constructor(toolExecutor: ToolExecutor, messageSender: MessageSender, inferenceHandler: InferenceHandler);
474
- join(user: Participant): void;
475
- leave(user: Participant): void;
461
+ protected subscribers: Participant[];
462
+ private isActive;
463
+ start(): Promise<void>;
464
+ stop(): void;
465
+ subscribe(subscriber: Participant): void;
466
+ unsubscribe(user: Participant): void;
476
467
  notifyFunctionCallOutput(user: Participant, item: FunctionCallOutputItem): void;
477
468
  notifyMessage(user: Participant, message: string): void;
478
- abstract executeFunctionCall(user: Participant, functionCallItem: FunctionCallItem): Promise<void>;
479
- abstract sendMessage(user: Participant, message: string): Promise<void>;
480
- abstract runInference(user: Participant, context: ModelContext, model: GenerativeModel, signal?: AbortSignal): Promise<void>;
481
469
  notifyFunctionCall(user: Participant, item: FunctionCallItem): void;
482
470
  notifyReasoning(user: Participant, item: ReasoningItem): void;
483
471
  notifyOutputMessage(user: Participant, item: ModelMessageItem): void;
484
472
  }
485
473
 
486
- declare class Environment extends AgenticEnvironment {
474
+ declare abstract class Participant {
475
+ protected toolExecutor: ToolExecutor;
476
+ protected messageSender: MessageSender;
477
+ protected inferenceHandler: InferenceHandler;
478
+ protected environments: AgenticEnvironment[];
487
479
  constructor(toolExecutor: ToolExecutor, messageSender: MessageSender, inferenceHandler: InferenceHandler);
488
- executeFunctionCall(user: Participant, functionCallItem: FunctionCallItem): Promise<void>;
489
- sendMessage(user: Participant, message: string): Promise<void>;
490
- runInference(user: Participant, context: ModelContext, model: GenerativeModel, signal?: AbortSignal): Promise<void>;
480
+ abstract onFunctionCallOutput(participant: Participant, item: FunctionCallOutputItem): Promise<void>;
481
+ abstract onMessage(participant: Participant, message: string): Promise<void>;
482
+ abstract onFunctionCall(participant: Participant, item: FunctionCallItem): Promise<void>;
483
+ abstract onReasoning(participant: Participant, item: ReasoningItem): Promise<void>;
484
+ abstract onOutputMessage(participant: Participant, item: ModelMessageItem): Promise<void>;
485
+ sendMessage(message: string, environment: AgenticEnvironment): Promise<void>;
486
+ executeFunctionCall(functionCallItem: FunctionCallItem, environment: AgenticEnvironment): Promise<void>;
487
+ runInference(environment: AgenticEnvironment, context: ModelContext, model: GenerativeModel, signal?: AbortSignal): Promise<void>;
488
+ join(environment: AgenticEnvironment): void;
489
+ leave(environment: AgenticEnvironment): void;
491
490
  }
492
491
 
493
- export { type Action, Agent, AgentSociety, type AsyncAction, type AsyncRule, BaseSpecification, ContextItem, DeveloperMessageItem, Environment, FunctionCallItem, FunctionCallOutputItem, type GenerativeModel, Gpt54, Gpt54Mini, Gpt54Nano, If, InMemoryModelContextRepository, type InferenceHandler, InferenceRequest, InferenceResponse, type InferenceVisitor, InputTokenDetails, Loop, type MessageSender, ModelContext, type ModelContextRepository, ModelMessageItem, OpenAIResponses, OutputTokenDetails, Participant, ReasoningItem, type RuntimeContext, type Specification, SystemMessageItem, TokenUsage, type Tool, type ToolExecutor, UserMessageItem };
492
+ export { type Action, Agent, AgentSociety, AgenticEnvironment, type AsyncAction, type AsyncRule, BaseSpecification, ContextItem, DeveloperMessageItem, FunctionCallItem, FunctionCallOutputItem, type GenerativeModel, Gpt54, Gpt54Mini, Gpt54Nano, If, InMemoryModelContextRepository, type InferenceHandler, InferenceRequest, InferenceResponse, type InferenceVisitor, InputTokenDetails, Loop, type MessageSender, ModelContext, type ModelContextRepository, ModelMessageItem, OpenAIResponses, OutputTokenDetails, Participant, ReasoningItem, type RuntimeContext, type Specification, SystemMessageItem, TokenUsage, type Tool, type ToolExecutor, UserMessageItem };
package/dist/index.d.ts CHANGED
@@ -449,45 +449,44 @@ interface ToolExecutor {
449
449
  produce(functionCallItem: FunctionCallItem, signal?: AbortSignal): AsyncIterable<FunctionCallOutputItem>;
450
450
  }
451
451
 
452
- interface InferenceHandler {
453
- produce(context: ModelContext, model: GenerativeModel, signal?: AbortSignal): AsyncIterable<ReasoningItem | FunctionCallItem | ModelMessageItem>;
454
- }
455
-
456
452
  interface MessageSender {
457
453
  stream(message: string, signal?: AbortSignal): AsyncIterable<string>;
458
454
  }
459
455
 
460
- declare abstract class Participant {
461
- abstract onFunctionCallOutput(participant: Participant, item: FunctionCallOutputItem): Promise<void>;
462
- abstract onMessage(participant: Participant, message: string): Promise<void>;
463
- abstract onFunctionCall(participant: Participant, item: FunctionCallItem): Promise<void>;
464
- abstract onReasoning(participant: Participant, item: ReasoningItem): Promise<void>;
465
- abstract onOutputMessage(participant: Participant, item: ModelMessageItem): Promise<void>;
456
+ interface InferenceHandler {
457
+ produce(context: ModelContext, model: GenerativeModel, signal?: AbortSignal): AsyncIterable<ReasoningItem | FunctionCallItem | ModelMessageItem>;
466
458
  }
467
459
 
468
460
  declare abstract class AgenticEnvironment {
469
- protected toolExecutor: ToolExecutor;
470
- protected messageSender: MessageSender;
471
- protected inferenceHandler: InferenceHandler;
472
- protected participants: Participant[];
473
- constructor(toolExecutor: ToolExecutor, messageSender: MessageSender, inferenceHandler: InferenceHandler);
474
- join(user: Participant): void;
475
- leave(user: Participant): void;
461
+ protected subscribers: Participant[];
462
+ private isActive;
463
+ start(): Promise<void>;
464
+ stop(): void;
465
+ subscribe(subscriber: Participant): void;
466
+ unsubscribe(user: Participant): void;
476
467
  notifyFunctionCallOutput(user: Participant, item: FunctionCallOutputItem): void;
477
468
  notifyMessage(user: Participant, message: string): void;
478
- abstract executeFunctionCall(user: Participant, functionCallItem: FunctionCallItem): Promise<void>;
479
- abstract sendMessage(user: Participant, message: string): Promise<void>;
480
- abstract runInference(user: Participant, context: ModelContext, model: GenerativeModel, signal?: AbortSignal): Promise<void>;
481
469
  notifyFunctionCall(user: Participant, item: FunctionCallItem): void;
482
470
  notifyReasoning(user: Participant, item: ReasoningItem): void;
483
471
  notifyOutputMessage(user: Participant, item: ModelMessageItem): void;
484
472
  }
485
473
 
486
- declare class Environment extends AgenticEnvironment {
474
+ declare abstract class Participant {
475
+ protected toolExecutor: ToolExecutor;
476
+ protected messageSender: MessageSender;
477
+ protected inferenceHandler: InferenceHandler;
478
+ protected environments: AgenticEnvironment[];
487
479
  constructor(toolExecutor: ToolExecutor, messageSender: MessageSender, inferenceHandler: InferenceHandler);
488
- executeFunctionCall(user: Participant, functionCallItem: FunctionCallItem): Promise<void>;
489
- sendMessage(user: Participant, message: string): Promise<void>;
490
- runInference(user: Participant, context: ModelContext, model: GenerativeModel, signal?: AbortSignal): Promise<void>;
480
+ abstract onFunctionCallOutput(participant: Participant, item: FunctionCallOutputItem): Promise<void>;
481
+ abstract onMessage(participant: Participant, message: string): Promise<void>;
482
+ abstract onFunctionCall(participant: Participant, item: FunctionCallItem): Promise<void>;
483
+ abstract onReasoning(participant: Participant, item: ReasoningItem): Promise<void>;
484
+ abstract onOutputMessage(participant: Participant, item: ModelMessageItem): Promise<void>;
485
+ sendMessage(message: string, environment: AgenticEnvironment): Promise<void>;
486
+ executeFunctionCall(functionCallItem: FunctionCallItem, environment: AgenticEnvironment): Promise<void>;
487
+ runInference(environment: AgenticEnvironment, context: ModelContext, model: GenerativeModel, signal?: AbortSignal): Promise<void>;
488
+ join(environment: AgenticEnvironment): void;
489
+ leave(environment: AgenticEnvironment): void;
491
490
  }
492
491
 
493
- export { type Action, Agent, AgentSociety, type AsyncAction, type AsyncRule, BaseSpecification, ContextItem, DeveloperMessageItem, Environment, FunctionCallItem, FunctionCallOutputItem, type GenerativeModel, Gpt54, Gpt54Mini, Gpt54Nano, If, InMemoryModelContextRepository, type InferenceHandler, InferenceRequest, InferenceResponse, type InferenceVisitor, InputTokenDetails, Loop, type MessageSender, ModelContext, type ModelContextRepository, ModelMessageItem, OpenAIResponses, OutputTokenDetails, Participant, ReasoningItem, type RuntimeContext, type Specification, SystemMessageItem, TokenUsage, type Tool, type ToolExecutor, UserMessageItem };
492
+ export { type Action, Agent, AgentSociety, AgenticEnvironment, type AsyncAction, type AsyncRule, BaseSpecification, ContextItem, DeveloperMessageItem, FunctionCallItem, FunctionCallOutputItem, type GenerativeModel, Gpt54, Gpt54Mini, Gpt54Nano, If, InMemoryModelContextRepository, type InferenceHandler, InferenceRequest, InferenceResponse, type InferenceVisitor, InputTokenDetails, Loop, type MessageSender, ModelContext, type ModelContextRepository, ModelMessageItem, OpenAIResponses, OutputTokenDetails, Participant, ReasoningItem, type RuntimeContext, type Specification, SystemMessageItem, TokenUsage, type Tool, type ToolExecutor, UserMessageItem };
package/dist/index.js CHANGED
@@ -32,10 +32,10 @@ var index_exports = {};
32
32
  __export(index_exports, {
33
33
  Agent: () => Agent,
34
34
  AgentSociety: () => AgentSociety,
35
+ AgenticEnvironment: () => AgenticEnvironment,
35
36
  BaseSpecification: () => BaseSpecification,
36
37
  ContextItem: () => ContextItem,
37
38
  DeveloperMessageItem: () => DeveloperMessageItem,
38
- Environment: () => Environment,
39
39
  FunctionCallItem: () => FunctionCallItem,
40
40
  FunctionCallOutputItem: () => FunctionCallOutputItem,
41
41
  Gpt54: () => Gpt54,
@@ -1089,89 +1089,118 @@ var SystemMessageItem = class _SystemMessageItem extends ContextItem {
1089
1089
  }
1090
1090
  };
1091
1091
 
1092
- // src/domain/agentic-environment/agentic-environment.ts
1093
- var AgenticEnvironment = class {
1092
+ // src/domain/agentic-environment/participant.ts
1093
+ var Participant = class {
1094
1094
  constructor(toolExecutor, messageSender, inferenceHandler) {
1095
- this.participants = [];
1095
+ this.environments = [];
1096
1096
  this.toolExecutor = toolExecutor;
1097
1097
  this.messageSender = messageSender;
1098
1098
  this.inferenceHandler = inferenceHandler;
1099
1099
  }
1100
- join(user) {
1101
- this.participants.push(user);
1102
- }
1103
- leave(user) {
1104
- this.participants = this.participants.filter((p) => p !== user);
1105
- }
1106
- notifyFunctionCallOutput(user, item) {
1107
- for (const participant of this.participants) {
1108
- participant.onFunctionCallOutput(user, item);
1100
+ async sendMessage(message, environment) {
1101
+ if (!this.environments.includes(environment)) {
1102
+ return;
1103
+ }
1104
+ for await (const messagePart of this.messageSender.stream(message)) {
1105
+ environment.notifyMessage(this, messagePart);
1109
1106
  }
1110
1107
  }
1111
- notifyMessage(user, message) {
1112
- for (const participant of this.participants) {
1113
- if (participant === user) {
1114
- continue;
1115
- }
1116
- participant.onMessage(user, message);
1108
+ async executeFunctionCall(functionCallItem, environment) {
1109
+ if (!this.environments.includes(environment)) {
1110
+ return;
1111
+ }
1112
+ for await (const item of this.toolExecutor.produce(functionCallItem)) {
1113
+ environment.notifyFunctionCallOutput(this, item);
1117
1114
  }
1118
1115
  }
1119
- notifyFunctionCall(user, item) {
1120
- for (const participant of this.participants) {
1121
- participant.onFunctionCall(user, item);
1116
+ async runInference(environment, context, model, signal) {
1117
+ if (!this.environments.includes(environment)) {
1118
+ return;
1119
+ }
1120
+ for await (const item of this.inferenceHandler.produce(context, model, signal)) {
1121
+ if (item instanceof FunctionCallItem) {
1122
+ environment.notifyFunctionCall(this, item);
1123
+ } else if (item instanceof ReasoningItem) {
1124
+ environment.notifyReasoning(this, item);
1125
+ } else if (item instanceof ModelMessageItem) {
1126
+ environment.notifyOutputMessage(this, item);
1127
+ }
1122
1128
  }
1123
1129
  }
1124
- notifyReasoning(user, item) {
1125
- for (const participant of this.participants) {
1126
- participant.onReasoning(user, item);
1130
+ join(environment) {
1131
+ if (this.environments.includes(environment)) {
1132
+ return;
1127
1133
  }
1134
+ environment.subscribe(this);
1135
+ this.environments.push(environment);
1128
1136
  }
1129
- notifyOutputMessage(user, item) {
1130
- for (const participant of this.participants) {
1131
- participant.onOutputMessage(user, item);
1137
+ leave(environment) {
1138
+ if (!this.environments.includes(environment)) {
1139
+ return;
1132
1140
  }
1141
+ environment.unsubscribe(this);
1142
+ this.environments = this.environments.filter((e) => e !== environment);
1133
1143
  }
1134
1144
  };
1135
1145
 
1136
- // src/application/environment.ts
1137
- var Environment = class extends AgenticEnvironment {
1138
- constructor(toolExecutor, messageSender, inferenceHandler) {
1139
- super(toolExecutor, messageSender, inferenceHandler);
1146
+ // src/domain/agentic-environment/agentic-environment.ts
1147
+ var AgenticEnvironment = class {
1148
+ constructor() {
1149
+ this.subscribers = [];
1150
+ this.isActive = false;
1140
1151
  }
1141
- async executeFunctionCall(user, functionCallItem) {
1142
- for await (const item of this.toolExecutor.produce(functionCallItem)) {
1143
- this.notifyFunctionCallOutput(user, item);
1152
+ async start() {
1153
+ this.isActive = true;
1154
+ while (this.isActive) {
1155
+ await new Promise((resolve) => setTimeout(resolve, 100));
1144
1156
  }
1145
1157
  }
1146
- async sendMessage(user, message) {
1147
- for await (const messagePart of this.messageSender.stream(message)) {
1148
- this.notifyMessage(user, messagePart);
1158
+ stop() {
1159
+ this.isActive = false;
1160
+ }
1161
+ subscribe(subscriber) {
1162
+ this.subscribers.push(subscriber);
1163
+ }
1164
+ unsubscribe(user) {
1165
+ this.subscribers = this.subscribers.filter((p) => p !== user);
1166
+ }
1167
+ notifyFunctionCallOutput(user, item) {
1168
+ for (const subscriber of this.subscribers) {
1169
+ subscriber.onFunctionCallOutput(subscriber, item);
1149
1170
  }
1150
1171
  }
1151
- async runInference(user, context, model, signal) {
1152
- for await (const item of this.inferenceHandler.produce(context, model, signal)) {
1153
- if (item instanceof FunctionCallItem) {
1154
- this.notifyFunctionCall(user, item);
1155
- } else if (item instanceof ReasoningItem) {
1156
- this.notifyReasoning(user, item);
1157
- } else if (item instanceof ModelMessageItem) {
1158
- this.notifyOutputMessage(user, item);
1172
+ notifyMessage(user, message) {
1173
+ for (const subscriber of this.subscribers) {
1174
+ if (subscriber === user) {
1175
+ continue;
1159
1176
  }
1177
+ subscriber.onMessage(subscriber, message);
1178
+ }
1179
+ }
1180
+ notifyFunctionCall(user, item) {
1181
+ for (const subscriber of this.subscribers) {
1182
+ subscriber.onFunctionCall(user, item);
1183
+ }
1184
+ }
1185
+ notifyReasoning(user, item) {
1186
+ for (const subscriber of this.subscribers) {
1187
+ subscriber.onReasoning(user, item);
1188
+ }
1189
+ }
1190
+ notifyOutputMessage(user, item) {
1191
+ for (const subscriber of this.subscribers) {
1192
+ subscriber.onOutputMessage(user, item);
1160
1193
  }
1161
1194
  }
1162
- };
1163
-
1164
- // src/domain/agentic-environment/participant.ts
1165
- var Participant = class {
1166
1195
  };
1167
1196
  // Annotate the CommonJS export names for ESM import in node:
1168
1197
  0 && (module.exports = {
1169
1198
  Agent,
1170
1199
  AgentSociety,
1200
+ AgenticEnvironment,
1171
1201
  BaseSpecification,
1172
1202
  ContextItem,
1173
1203
  DeveloperMessageItem,
1174
- Environment,
1175
1204
  FunctionCallItem,
1176
1205
  FunctionCallOutputItem,
1177
1206
  Gpt54,