@mozaik-ai/core 4.0.3 → 4.0.5
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/README.md +15 -15
- package/dist/index.d.mts +3 -3
- package/dist/index.d.ts +3 -3
- package/dist/index.js +20 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +20 -19
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -218,18 +218,18 @@ Participants never poll. Custom events go through `sendEvent(event, senderId)` w
|
|
|
218
218
|
|
|
219
219
|
Producer is the agent whose loop is running:
|
|
220
220
|
|
|
221
|
-
| Event
|
|
222
|
-
|
|
|
223
|
-
| `
|
|
224
|
-
| `
|
|
225
|
-
| `inference.started`
|
|
226
|
-
| `inference.stream`
|
|
227
|
-
| `inference.completed`
|
|
228
|
-
| `function_call.started`
|
|
229
|
-
| `function_call.completed`
|
|
230
|
-
| `model.answer`
|
|
231
|
-
| `interception.started`
|
|
232
|
-
| `interception.finished`
|
|
221
|
+
| Event | Published when | Payload |
|
|
222
|
+
| ---------------------------- | -------------------------------------------------- | -------------------------------------------------------- |
|
|
223
|
+
| `message_received.started` | The loop begins appending the user message | Received message plus `loopId` |
|
|
224
|
+
| `message_received.completed` | Context is ready for inference | `InferenceInput` plus `loopId` |
|
|
225
|
+
| `inference.started` | The model call begins | `InferenceInput` |
|
|
226
|
+
| `inference.stream` | Each streaming chunk (only when `streaming: true`) | The inner provider event |
|
|
227
|
+
| `inference.completed` | The model call finished | `InferenceOutput` (`items`, `tokenUsage`, `rowResponse`) |
|
|
228
|
+
| `function_call.started` | A tool is about to run | `{ call, inferenceInput }` |
|
|
229
|
+
| `function_call.completed` | The tool returned | `FunctionCallOutputItem` |
|
|
230
|
+
| `model.answer` | The assistant message is committed | `{ answer: ModelMessageItem }` |
|
|
231
|
+
| `interception.started` | An `InterceptionHandler` matched a transition | The pending `LoopTransition` |
|
|
232
|
+
| `interception.finished` | The handler returned (possibly rewritten) | The transition that will execute |
|
|
233
233
|
|
|
234
234
|
### Streaming
|
|
235
235
|
|
|
@@ -345,13 +345,13 @@ Three things to note:
|
|
|
345
345
|
|
|
346
346
|
## The agent loop
|
|
347
347
|
|
|
348
|
-
`runLoop(agentId, message, inferenceInput, interceptionHandler?)` drives one agent turn as a state machine. It starts at `
|
|
348
|
+
`runLoop(agentId, message, inferenceInput, interceptionHandler?)` drives one agent turn as a state machine. It starts at `message_received` and runs until `idle`. Tool execution and the follow-up inference live inside the loop — you do not call a separate function-call runner.
|
|
349
349
|
|
|
350
350
|
Each step: optionally intercept the pending transition, execute the state, then resolve the next transition.
|
|
351
351
|
|
|
352
352
|
```mermaid
|
|
353
353
|
flowchart TD
|
|
354
|
-
Start([runLoop]) --> CU[
|
|
354
|
+
Start([runLoop]) --> CU[message_received]
|
|
355
355
|
CU --> INF[inference]
|
|
356
356
|
INF -->|function_call item| FC[function_call]
|
|
357
357
|
INF -->|assistant message| MM[model_message]
|
|
@@ -361,7 +361,7 @@ flowchart TD
|
|
|
361
361
|
|
|
362
362
|
| State | What it does |
|
|
363
363
|
| --------------------- | ------------------------------------------------------------------------------------------------ |
|
|
364
|
-
| `
|
|
364
|
+
| `message_received` | Appends the user message to the agent's context. |
|
|
365
365
|
| `inference` | Calls the model and waits for the full response. |
|
|
366
366
|
| `inference_streaming` | Same call, streaming; each chunk is published as `inference.stream`. |
|
|
367
367
|
| `function_call` | Runs the matching tool, writes the call and output back into context, then returns to inference. |
|
package/dist/index.d.mts
CHANGED
|
@@ -77,7 +77,7 @@ declare class ModelContext {
|
|
|
77
77
|
constructor(id: string, items: ContextItem[]);
|
|
78
78
|
getItems(): ContextItem[];
|
|
79
79
|
addContextItems(contextItems: ContextItem[]): ModelContext;
|
|
80
|
-
|
|
80
|
+
addContextItem(item: ContextItem): ModelContext;
|
|
81
81
|
static create(): ModelContext;
|
|
82
82
|
static rehydrate(data: {
|
|
83
83
|
id: string;
|
|
@@ -204,7 +204,7 @@ interface InterceptionParams {
|
|
|
204
204
|
pendingTransition: LoopTransition;
|
|
205
205
|
}
|
|
206
206
|
|
|
207
|
-
type LoopStateId = "
|
|
207
|
+
type LoopStateId = "message_received" | "inference" | "inference_streaming" | "function_call" | "model_message" | "idle";
|
|
208
208
|
type ReceivedMessage = {
|
|
209
209
|
content: string;
|
|
210
210
|
input: InferenceInput;
|
|
@@ -216,7 +216,7 @@ interface ModelMessageParams {
|
|
|
216
216
|
answer: ModelMessageItem;
|
|
217
217
|
}
|
|
218
218
|
interface LoopStateContract {
|
|
219
|
-
|
|
219
|
+
message_received: {
|
|
220
220
|
input: ReceivedMessage;
|
|
221
221
|
output: InferenceInput;
|
|
222
222
|
};
|
package/dist/index.d.ts
CHANGED
|
@@ -77,7 +77,7 @@ declare class ModelContext {
|
|
|
77
77
|
constructor(id: string, items: ContextItem[]);
|
|
78
78
|
getItems(): ContextItem[];
|
|
79
79
|
addContextItems(contextItems: ContextItem[]): ModelContext;
|
|
80
|
-
|
|
80
|
+
addContextItem(item: ContextItem): ModelContext;
|
|
81
81
|
static create(): ModelContext;
|
|
82
82
|
static rehydrate(data: {
|
|
83
83
|
id: string;
|
|
@@ -204,7 +204,7 @@ interface InterceptionParams {
|
|
|
204
204
|
pendingTransition: LoopTransition;
|
|
205
205
|
}
|
|
206
206
|
|
|
207
|
-
type LoopStateId = "
|
|
207
|
+
type LoopStateId = "message_received" | "inference" | "inference_streaming" | "function_call" | "model_message" | "idle";
|
|
208
208
|
type ReceivedMessage = {
|
|
209
209
|
content: string;
|
|
210
210
|
input: InferenceInput;
|
|
@@ -216,7 +216,7 @@ interface ModelMessageParams {
|
|
|
216
216
|
answer: ModelMessageItem;
|
|
217
217
|
}
|
|
218
218
|
interface LoopStateContract {
|
|
219
|
-
|
|
219
|
+
message_received: {
|
|
220
220
|
input: ReceivedMessage;
|
|
221
221
|
output: InferenceInput;
|
|
222
222
|
};
|
package/dist/index.js
CHANGED
|
@@ -75,7 +75,7 @@ var ModelContext = class _ModelContext {
|
|
|
75
75
|
this.items.push(...contextItems);
|
|
76
76
|
return this;
|
|
77
77
|
}
|
|
78
|
-
|
|
78
|
+
addContextItem(item) {
|
|
79
79
|
this.items.push(item);
|
|
80
80
|
return this;
|
|
81
81
|
}
|
|
@@ -465,7 +465,7 @@ var Agent = class _Agent extends Participant {
|
|
|
465
465
|
const memory = Memory.create();
|
|
466
466
|
const manifest = { id, name, capabilities, role: "agent" };
|
|
467
467
|
const developerMessage = DeveloperMessageItem.create(instruction);
|
|
468
|
-
memory.getContext().
|
|
468
|
+
memory.getContext().addContextItem(developerMessage);
|
|
469
469
|
return new _Agent(manifest, instruction, tools, memory, handlers);
|
|
470
470
|
}
|
|
471
471
|
getTools() {
|
|
@@ -624,7 +624,7 @@ var AgentLoop = class _AgentLoop {
|
|
|
624
624
|
async run(message, loopVisitor) {
|
|
625
625
|
var _a;
|
|
626
626
|
let transition = {
|
|
627
|
-
nextStateId: "
|
|
627
|
+
nextStateId: "message_received",
|
|
628
628
|
input: message
|
|
629
629
|
};
|
|
630
630
|
while (transition.nextStateId !== "idle") {
|
|
@@ -649,8 +649,8 @@ var AgentLoop = class _AgentLoop {
|
|
|
649
649
|
|
|
650
650
|
// src/domain/agentic-environment/loop/state-executor.ts
|
|
651
651
|
var LoopStateExecutor = class {
|
|
652
|
-
constructor(
|
|
653
|
-
this.
|
|
652
|
+
constructor(messageReceivedState, inferenceState, inferenceStreamingState, functionCallState, modelMessageState) {
|
|
653
|
+
this.messageReceivedState = messageReceivedState;
|
|
654
654
|
this.inferenceState = inferenceState;
|
|
655
655
|
this.inferenceStreamingState = inferenceStreamingState;
|
|
656
656
|
this.functionCallState = functionCallState;
|
|
@@ -658,8 +658,8 @@ var LoopStateExecutor = class {
|
|
|
658
658
|
}
|
|
659
659
|
async execute(transition, loopVisitor) {
|
|
660
660
|
switch (transition.nextStateId) {
|
|
661
|
-
case "
|
|
662
|
-
return await this.
|
|
661
|
+
case "message_received":
|
|
662
|
+
return await this.messageReceivedState.run(transition.input, loopVisitor);
|
|
663
663
|
case "inference":
|
|
664
664
|
return await this.inferenceState.run(transition.input, loopVisitor);
|
|
665
665
|
case "inference_streaming":
|
|
@@ -704,19 +704,19 @@ var FunctionCallState = class {
|
|
|
704
704
|
}
|
|
705
705
|
};
|
|
706
706
|
|
|
707
|
-
// src/application/states/
|
|
708
|
-
var
|
|
707
|
+
// src/application/states/message-received.ts
|
|
708
|
+
var MessageReceivedState = class {
|
|
709
709
|
constructor() {
|
|
710
|
-
this.id = "
|
|
710
|
+
this.id = "message_received";
|
|
711
711
|
}
|
|
712
712
|
async run(input, loopVisitor) {
|
|
713
|
-
loopVisitor.
|
|
713
|
+
loopVisitor.visitMessageReceivedStarted(input);
|
|
714
714
|
const userMessage = UserMessageItem.create(input.content);
|
|
715
715
|
const output = {
|
|
716
716
|
...input.input,
|
|
717
717
|
context: input.input.context.addContextItems([userMessage])
|
|
718
718
|
};
|
|
719
|
-
loopVisitor.
|
|
719
|
+
loopVisitor.visitMessageReceivedCompleted(output);
|
|
720
720
|
return {
|
|
721
721
|
stateId: this.id,
|
|
722
722
|
input,
|
|
@@ -757,7 +757,7 @@ var TransitionResolver = class {
|
|
|
757
757
|
// src/domain/agentic-environment/loop/transition-specification.ts
|
|
758
758
|
var MessageReceivedSpecification = class {
|
|
759
759
|
isSatisfiedBy(execution) {
|
|
760
|
-
return execution.stateId === "
|
|
760
|
+
return execution.stateId === "message_received";
|
|
761
761
|
}
|
|
762
762
|
};
|
|
763
763
|
function isInferenceExecution(execution) {
|
|
@@ -790,7 +790,7 @@ var ContextPreparationToInferenceRule = class {
|
|
|
790
790
|
this.specification = new MessageReceivedSpecification();
|
|
791
791
|
}
|
|
792
792
|
createTransition(execution) {
|
|
793
|
-
if (execution.stateId !== "
|
|
793
|
+
if (execution.stateId !== "message_received") {
|
|
794
794
|
throw new Error("Expected context_preparation execution");
|
|
795
795
|
}
|
|
796
796
|
const nextStateId = execution.output.streaming ? "inference_streaming" : "inference";
|
|
@@ -835,6 +835,7 @@ var InferenceToModelMessageRule = class {
|
|
|
835
835
|
if (!modelMessageItem) {
|
|
836
836
|
throw new Error("Expected inference model-message output");
|
|
837
837
|
}
|
|
838
|
+
execution.input.context.addContextItem(modelMessageItem);
|
|
838
839
|
return {
|
|
839
840
|
nextStateId: "model_message",
|
|
840
841
|
input: {
|
|
@@ -885,11 +886,11 @@ var EventPublisherLoopVisitor = class {
|
|
|
885
886
|
this.runtime = runtime;
|
|
886
887
|
this.cloud = (0, import_cloud_sdk.createCloudClient)();
|
|
887
888
|
}
|
|
888
|
-
|
|
889
|
-
this.publish("
|
|
889
|
+
visitMessageReceivedStarted(input) {
|
|
890
|
+
this.publish("message_received.started", input);
|
|
890
891
|
}
|
|
891
|
-
|
|
892
|
-
this.publish("
|
|
892
|
+
visitMessageReceivedCompleted(output) {
|
|
893
|
+
this.publish("message_received.completed", output);
|
|
893
894
|
}
|
|
894
895
|
visitInferenceStarted(input) {
|
|
895
896
|
this.publish("inference.started", input);
|
|
@@ -985,7 +986,7 @@ function createRunLoop(resolveRuntime) {
|
|
|
985
986
|
new ModelMessageToIdleRule()
|
|
986
987
|
]);
|
|
987
988
|
const stateExecutor = new LoopStateExecutor(
|
|
988
|
-
new
|
|
989
|
+
new MessageReceivedState(),
|
|
989
990
|
new InferenceState(inferenceRunner),
|
|
990
991
|
new InferenceStreamingState(inferenceRunner),
|
|
991
992
|
new FunctionCallState(functionCallRunner),
|