@mozaik-ai/core 3.8.0 → 3.8.1
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 +41 -24
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
  
|
|
6
6
|
|
|
7
|
-
In Mozaik, humans, agents, observers, and tools are all `Participant`s of the same `AgenticEnvironment`. Each participant runs **non-blocking** and produces typed
|
|
7
|
+
In Mozaik, humans, agents, observers, and tools are all `Participant`s of the same `AgenticEnvironment`. Each participant runs **non-blocking** and produces events into the environment: plain-text **messages** for conversational input/output, and typed `ContextItem`s for model internals (function calls, function call outputs, reasoning, model messages). Every other participant sees those events in real time and can react, intercept, or stay silent — without any central scheduler.
|
|
8
8
|
|
|
9
9
|
---
|
|
10
10
|
|
|
@@ -27,13 +27,13 @@ OPENAI_API_KEY=your-openai-key-here
|
|
|
27
27
|
|
|
28
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:
|
|
29
29
|
|
|
30
|
-
| Producer call
|
|
31
|
-
|
|
|
32
|
-
| `deliverFunctionCall(source, item)`
|
|
33
|
-
| `deliverFunctionCallOutput(source, item)
|
|
34
|
-
| `deliverReasoning(source, item)`
|
|
35
|
-
| `deliverModelMessage(source, item)`
|
|
36
|
-
| `deliverMessage(source, message)`
|
|
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)` |
|
|
37
37
|
|
|
38
38
|
Messages are plain `string`s exchanged between participants. Every other event flows as a typed `ContextItem` (`FunctionCallItem`, `FunctionCallOutputItem`, `ReasoningItem`, `ModelMessageItem`).
|
|
39
39
|
|
|
@@ -53,14 +53,29 @@ flowchart LR
|
|
|
53
53
|
|
|
54
54
|
Mozaik ships two ready-to-use participants:
|
|
55
55
|
|
|
56
|
-
| Participant | Capabilities | Pulls from
|
|
57
|
-
| ---------------------- | --------------------------------------------------------- |
|
|
58
|
-
| `BaseHumanParticipant` | `InputCapable` | `InputStream`
|
|
59
|
-
| `BaseAgentParticipant` | `InputCapable`, `InferenceCapable`, `FunctionCallCapable` | `InputStream`, `InferenceRunner`, `FunctionCallRunner
|
|
56
|
+
| Participant | Capabilities | Pulls from |
|
|
57
|
+
| ---------------------- | --------------------------------------------------------- | ------------------------------------------------------ |
|
|
58
|
+
| `BaseHumanParticipant` | `InputCapable` | `InputStream` |
|
|
59
|
+
| `BaseAgentParticipant` | `InputCapable`, `InferenceCapable`, `FunctionCallCapable` | `InputStream`, `InferenceRunner`, `FunctionCallRunner` |
|
|
60
60
|
|
|
61
|
-
Each capability method is **non-blocking**: it returns `Promise<void>`, and as the underlying generator yields,
|
|
61
|
+
Each capability method is **non-blocking**: it returns `Promise<void>`, and as the underlying generator yields, every yielded value is forwarded into the environment through the matching typed `deliverX` method.
|
|
62
62
|
|
|
63
|
-
|
|
63
|
+
`streamInput` pulls plain-text messages from an `InputStream` and routes each one to `deliverMessage` — participants exchange raw text on the wire, not `UserMessageItem` / `DeveloperMessageItem` / `SystemMessageItem` envelopes:
|
|
64
|
+
|
|
65
|
+
```ts
|
|
66
|
+
async streamInput(environment: AgenticEnvironment): Promise<void> {
|
|
67
|
+
if (!this.isJoinedTo(environment)) return
|
|
68
|
+
|
|
69
|
+
const stream = this.inputSource.stream()
|
|
70
|
+
for await (const message of stream) {
|
|
71
|
+
await environment.deliverMessage(this, message)
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
`runInference` does the same for model output, dispatching each yielded item to `deliverReasoning`, `deliverFunctionCall`, or `deliverModelMessage`:
|
|
77
|
+
|
|
78
|
+
```ts
|
|
64
79
|
async runInference(
|
|
65
80
|
environment: AgenticEnvironment,
|
|
66
81
|
context: ModelContext,
|
|
@@ -126,7 +141,7 @@ Instead of a single catch-all callback, `Participant` exposes **one typed handle
|
|
|
126
141
|
|
|
127
142
|
The intercept surface, taken from `Participant`:
|
|
128
143
|
|
|
129
|
-
```
|
|
144
|
+
```ts
|
|
130
145
|
abstract onFunctionCall(item: FunctionCallItem): Promise<void>
|
|
131
146
|
|
|
132
147
|
abstract onExternalFunctionCall(source: Participant, item: FunctionCallItem): Promise<void>
|
|
@@ -158,13 +173,7 @@ Plain conversational input flows as a `string` through `onMessage` — participa
|
|
|
158
173
|
A passive observer subclasses `Participant` and overrides only the handlers it cares about:
|
|
159
174
|
|
|
160
175
|
```ts
|
|
161
|
-
import {
|
|
162
|
-
Participant,
|
|
163
|
-
FunctionCallItem,
|
|
164
|
-
FunctionCallOutputItem,
|
|
165
|
-
ReasoningItem,
|
|
166
|
-
ModelMessageItem,
|
|
167
|
-
} from "@mozaik-ai/core"
|
|
176
|
+
import { Participant, FunctionCallItem, FunctionCallOutputItem, ReasoningItem, ModelMessageItem } from "@mozaik-ai/core"
|
|
168
177
|
|
|
169
178
|
export class TranscriptLogger extends Participant {
|
|
170
179
|
async onMessage(message: string): Promise<void> {
|
|
@@ -296,7 +305,15 @@ const response = await runtime.infer(new InferenceRequest(new Gpt54(), context))
|
|
|
296
305
|
|
|
297
306
|
### Custom `InputStream`
|
|
298
307
|
|
|
299
|
-
An `InputStream`
|
|
308
|
+
An `InputStream` is the minimal text-source contract a participant uses to feed messages into the environment:
|
|
309
|
+
|
|
310
|
+
```ts
|
|
311
|
+
export interface InputStream {
|
|
312
|
+
stream(signal?: AbortSignal): AsyncIterable<string>
|
|
313
|
+
}
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
Each yielded string is delivered to every other participant through `onMessage(message: string)`. This keeps the wire format dead simple: participants exchange text, and each one decides how to turn that text into a `ContextItem` for its own `ModelContext`.
|
|
300
317
|
|
|
301
318
|
```ts
|
|
302
319
|
import { InputStream } from "@mozaik-ai/core"
|
|
@@ -322,7 +339,7 @@ export class QueueInputStream implements InputStream {
|
|
|
322
339
|
}
|
|
323
340
|
```
|
|
324
341
|
|
|
325
|
-
Use it for stdin, websockets, an HTTP queue, or anything that produces
|
|
342
|
+
Use it for stdin, websockets, an HTTP queue, or anything that produces text over time. A reactive agent typically wraps the incoming string in a `UserMessageItem` inside `onMessage` before adding it to its `ModelContext` — see the [Reactive agent](#reactive-agent) example above.
|
|
326
343
|
|
|
327
344
|
### Custom `InferenceRunner`
|
|
328
345
|
|