@mozaik-ai/core 3.8.3 → 3.8.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.
Files changed (2) hide show
  1. package/README.md +49 -20
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Mozaik
2
2
 
3
- **Mozaik** is an open-source TypeScript framework for building reactive AI agents that share an **agentic environment** instead of being orchestrated through rigid workflows.
3
+ **Mozaik** is TypeScript framework for building reactive agents. It provides the easiest way to build collaborative, **event-driven agents** that can work together in parallel.
4
4
 
5
5
  ![npm downloads](https://img.shields.io/npm/dt/@mozaik-ai/core) ![npm downloads weekly](https://img.shields.io/npm/dw/@mozaik-ai/core) ![npm version](https://img.shields.io/npm/v/@mozaik-ai/core)
6
6
 
@@ -25,17 +25,21 @@ OPENAI_API_KEY=your-openai-key-here
25
25
 
26
26
  ## The agentic environment
27
27
 
28
- `AgenticEnvironment` is a broadcast bus for typed events. `Participant`s `join()` it, and anything produced by one participant is delivered to every subscriber through a **dedicated typed callback** — one per event kind, with separate handlers for items the participant emitted itself versus items emitted by someone else:
28
+ `AgenticEnvironment` is where everything happens. `Participant`s `join()` it, and from that moment on they can **listen to messages and events** flowing through the environment by overriding any of the handlers below:
29
29
 
30
- | Producer call | Self handler | External handler |
31
- | ----------------------------------------- | ---------------------- | ----------------------------------------- |
32
- | `deliverFunctionCall(source, item)` | `onFunctionCall` | `onExternalFunctionCall(source, …)` |
33
- | `deliverFunctionCallOutput(source, item)` | `onFunctionCallOutput` | `onExternalFunctionCallOutput(source, …)` |
34
- | `deliverReasoning(source, item)` | `onReasoning` | `onExternalReasoning(source, …)` |
35
- | `deliverModelMessage(source, item)` | `onModelMessage` | `onExternalModelMessage(source, …)` |
36
- | `deliverMessage(source, message)` | _(not delivered)_ | `onMessage(message)` |
30
+ | Handler | Triggered when… |
31
+ | ------------------------------ | ------------------------------------------------------ |
32
+ | `onMessage` | any participant sends a message |
33
+ | `onFunctionCall` | its own inference returns a function call |
34
+ | `onExternalFunctionCall` | another agent's inference returns a function call |
35
+ | `onFunctionCallOutput` | its own function call runner returns a result |
36
+ | `onExternalFunctionCallOutput` | another agent's function call runner returns a result |
37
+ | `onReasoning` | its own inference returns a reasoning item |
38
+ | `onExternalReasoning` | another agent's inference returns a reasoning item |
39
+ | `onModelMessage` | its own inference returns an assistant message |
40
+ | `onExternalModelMessage` | another agent's inference returns an assistant message |
37
41
 
38
- Messages are plain `string`s exchanged between participants. Every other event flows as a typed `ContextItem` (`FunctionCallItem`, `FunctionCallOutputItem`, `ReasoningItem`, `ModelMessageItem`).
42
+ Every handler defaults to a no-op — override only the ones you care about.
39
43
 
40
44
  ```mermaid
41
45
  flowchart LR
@@ -89,24 +93,49 @@ The environment fans every item out to every subscriber synchronously and withou
89
93
 
90
94
  ---
91
95
 
92
- ## Intercepting events from other participants
96
+ ## Agent Loop Implementation
93
97
 
94
- Instead of a single catch-all callback, `Participant` exposes **one typed handler per event kind**, with a clear split between events the participant emitted itself and events emitted by someone else. A participant can:
98
+ The easiest way to build **and control** an agent loop is to override three handlers on `BaseAgentParticipant`:
95
99
 
96
- - **Observe** events from other participants via the `onExternal*` family (telemetry, audit, UI streaming) and `onMessage` for plain-text messages.
97
- - **React** to its own outputs via the self handlers (e.g. execute a `FunctionCallItem` it just produced), or to others' outputs via the external handlers.
98
- - **Ignore** events it doesn't care about — every handler defaults to a no-op in the bundled participants.
100
+ ```ts
101
+ export class CustomAgent extends BaseAgentParticipant {
102
+ constructor(
103
+ inputSource: InputStream,
104
+ inferenceRunner: InferenceRunner,
105
+ functionCallRunner: FunctionCallRunner,
106
+ private readonly environment: AgenticEnvironment,
107
+ private readonly context: ModelContext,
108
+ private readonly model: GenerativeModel,
109
+ ) {
110
+ super(inputSource, inferenceRunner, functionCallRunner)
111
+ }
99
112
 
100
- The typed `ContextItem`s involved are defined in [src/domain/model-context/context-item](src/domain/model-context/context-item):
113
+ async onMessage(message: string): Promise<void> {
114
+ this.context.addContextItem(UserMessageItem.create(message))
115
+ this.runInference(this.environment, this.context, this.model)
116
+ }
117
+
118
+ async onFunctionCall(item: FunctionCallItem): Promise<void> {
119
+ this.context.addContextItem(item)
120
+ this.executeFunctionCall(this.environment, item)
121
+ }
122
+
123
+ async onFunctionCallOutput(item: FunctionCallOutputItem): Promise<void> {
124
+ this.context.addContextItem(item)
125
+ this.runInference(this.environment, this.context, this.model)
126
+ }
127
+ }
128
+ ```
129
+
130
+ ---
101
131
 
102
- - Client-produced: `FunctionCallOutputItem` (and `UserMessageItem` / `DeveloperMessageItem` / `SystemMessageItem` when building a `ModelContext` directly)
103
- - Model-produced: `ModelMessageItem`, `FunctionCallItem`, `ReasoningItem`
132
+ ## Reacting to external events
104
133
 
105
- Plain conversational input flows as a `string` through `onMessage` — participants exchange messages without committing to a specific `ContextItem` shape on the wire.
134
+ Participants can listen to external events and react by overriding methods like `onMessage`, `onExternalFunctionCall`, `onExternalFunctionCallOutput`, `onExternalReasoning`, and `onExternalModelMessage`.
106
135
 
107
136
  ### Passive observer
108
137
 
109
- A passive observer subclasses `Participant` and overrides only the handlers it cares about:
138
+ You can create observers that don't run inference themselves but watch what's happening in the conversation and take side actions (logging, metrics, persistence, etc.). Subclass `Participant` and override only the handlers you care about:
110
139
 
111
140
  ```ts
112
141
  import { Participant, FunctionCallItem, FunctionCallOutputItem, ReasoningItem, ModelMessageItem } from "@mozaik-ai/core"
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mozaik-ai/core",
3
- "version": "3.8.3",
3
+ "version": "3.8.4",
4
4
  "description": "A TypeScript framework for building reactive agents",
5
5
  "main": "dist/index.js",
6
6
  "module": "dist/index.mjs",