@mozaik-ai/core 4.0.3 → 4.0.4
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 +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +17 -17
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +17 -17
- 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
|
@@ -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
|
@@ -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
|
@@ -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";
|
|
@@ -885,11 +885,11 @@ var EventPublisherLoopVisitor = class {
|
|
|
885
885
|
this.runtime = runtime;
|
|
886
886
|
this.cloud = (0, import_cloud_sdk.createCloudClient)();
|
|
887
887
|
}
|
|
888
|
-
|
|
889
|
-
this.publish("
|
|
888
|
+
visitMessageReceivedStarted(input) {
|
|
889
|
+
this.publish("message_received.started", input);
|
|
890
890
|
}
|
|
891
|
-
|
|
892
|
-
this.publish("
|
|
891
|
+
visitMessageReceivedCompleted(output) {
|
|
892
|
+
this.publish("message_received.completed", output);
|
|
893
893
|
}
|
|
894
894
|
visitInferenceStarted(input) {
|
|
895
895
|
this.publish("inference.started", input);
|
|
@@ -985,7 +985,7 @@ function createRunLoop(resolveRuntime) {
|
|
|
985
985
|
new ModelMessageToIdleRule()
|
|
986
986
|
]);
|
|
987
987
|
const stateExecutor = new LoopStateExecutor(
|
|
988
|
-
new
|
|
988
|
+
new MessageReceivedState(),
|
|
989
989
|
new InferenceState(inferenceRunner),
|
|
990
990
|
new InferenceStreamingState(inferenceRunner),
|
|
991
991
|
new FunctionCallState(functionCallRunner),
|