@mozaik-ai/core 3.7.0 → 3.8.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/README.md CHANGED
@@ -1,10 +1,10 @@
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 pipelines.
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.
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
 
7
- In Mozaik, humans, agents, observers, and tools are all `Participant`s of the same `AgenticEnvironment`. Each participant runs **non-blocking** and streams typed `ContextItem`s into the environment. Every other participant sees those items in real time and can react, intercept, or stay silent — without any central scheduler.
7
+ In Mozaik, humans, agents, observers, and tools are all `Participant`s of the same `AgenticEnvironment`. Each participant runs **non-blocking** and produces typed events — function calls, function call outputs, reasoning, model messages, and plain-text messages — into the environment. 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
 
@@ -25,16 +25,26 @@ OPENAI_API_KEY=your-openai-key-here
25
25
 
26
26
  ## The agentic environment
27
27
 
28
- `AgenticEnvironment` is a broadcast bus for typed context items. `Participant`s `join()` it, and any item produced by one participant is delivered to every subscriber's `onContextItem(source, item)` callback.
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
+
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
+
38
+ Messages are plain `string`s exchanged between participants. Every other event flows as a typed `ContextItem` (`FunctionCallItem`, `FunctionCallOutputItem`, `ReasoningItem`, `ModelMessageItem`).
29
39
 
30
40
  ```mermaid
31
41
  flowchart LR
32
42
  Human[BaseHumanParticipant] -->|streamInput| Env(("AgenticEnvironment"))
33
43
  Agent[BaseAgentParticipant] -->|"runInference / executeFunctionCall"| Env
34
44
  Observer[Custom Participant] -->|join| Env
35
- Env -->|onContextItem| Human
36
- Env -->|onContextItem| Agent
37
- Env -->|onContextItem| Observer
45
+ Env -->|"onMessage / onExternal*"| Human
46
+ Env -->|"onFunctionCall / onReasoning / …"| Agent
47
+ Env -->|"onExternal*"| Observer
38
48
  ```
39
49
 
40
50
  ---
@@ -43,24 +53,34 @@ flowchart LR
43
53
 
44
54
  Mozaik ships two ready-to-use participants:
45
55
 
46
- | Participant | Capabilities | Pulls from |
47
- | ---------------------- | --------------------------------------------------------- | ---------------------------------------------------------- |
48
- | `BaseHumanParticipant` | `InputCapable` | `InputItemSource` |
49
- | `BaseAgentParticipant` | `InputCapable`, `InferenceCapable`, `FunctionCallCapable` | `InputItemSource`, `InferenceRunner`, `FunctionCallRunner` |
50
-
51
- Each capability method is **non-blocking**: it returns `Promise<void>`, and as the underlying generator yields items they are streamed into the environment one-by-one through the `deliverStream` helper:
52
-
53
- ```5:14:src/application/deliver-stream.ts
54
- export async function deliverStream<T extends ContextItem>(
55
- environment: AgenticEnvironment,
56
- initiator: Participant,
57
- stream: AsyncIterable<T>,
58
- ): Promise<void> {
59
-
60
- for await (const item of stream) {
61
- await environment.deliverContextItem(initiator, item);
62
- }
63
- }
56
+ | Participant | Capabilities | Pulls from |
57
+ | ---------------------- | --------------------------------------------------------- | ----------------------------------------------------- |
58
+ | `BaseHumanParticipant` | `InputCapable` | `InputStream` |
59
+ | `BaseAgentParticipant` | `InputCapable`, `InferenceCapable`, `FunctionCallCapable` | `InputStream`, `InferenceRunner`, `FunctionCallRunner`|
60
+
61
+ Each capability method is **non-blocking**: it returns `Promise<void>`, and as the underlying generator yields, items are streamed into the environment one-by-one through the matching typed `deliverX` method. For example, `runInference` dispatches each yielded item to `deliverReasoning`, `deliverFunctionCall`, or `deliverModelMessage`:
62
+
63
+ ```81:100:src/application/agent.ts
64
+ async runInference(
65
+ environment: AgenticEnvironment,
66
+ context: ModelContext,
67
+ model: GenerativeModel,
68
+ signal?: AbortSignal,
69
+ ): Promise<void> {
70
+ if (!this.isJoinedTo(environment)) return
71
+
72
+ const stream = this.inferenceRunner.run(context, model, signal)
73
+
74
+ for await (const item of stream) {
75
+ if (item.type === "reasoning") {
76
+ await environment.deliverReasoning(this, item)
77
+ } else if (item.type === "function_call") {
78
+ await environment.deliverFunctionCall(this, item)
79
+ } else if (item.type === "message" && item.role === "assistant") {
80
+ await environment.deliverModelMessage(this, item)
81
+ }
82
+ }
83
+ }
64
84
  ```
65
85
 
66
86
  Because each call is a fresh promise that wraps an async iterable, multiple participants can act on the same environment **concurrently**:
@@ -96,53 +116,106 @@ The environment fans every item out to every subscriber synchronously and withou
96
116
 
97
117
  ---
98
118
 
99
- ## Intercepting items from other participants
119
+ ## Intercepting events from other participants
120
+
121
+ 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:
122
+
123
+ - **Observe** events from other participants via the `onExternal*` family (telemetry, audit, UI streaming) and `onMessage` for plain-text messages.
124
+ - **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.
125
+ - **Ignore** events it doesn't care about — every handler defaults to a no-op in the bundled participants.
126
+
127
+ The intercept surface, taken from `Participant`:
128
+
129
+ ```38:54:src/domain/agentic-environment/participant.ts
130
+ abstract onFunctionCall(item: FunctionCallItem): Promise<void>
100
131
 
101
- `onContextItem(source, item)` is the single intercept point. A participant can:
132
+ abstract onExternalFunctionCall(source: Participant, item: FunctionCallItem): Promise<void>
102
133
 
103
- - **Observe** items from other participants (telemetry, audit, UI streaming).
104
- - **React** to items by triggering its own capabilities (turn a `UserMessageItem` into an inference run, turn a `FunctionCallItem` into a tool execution).
105
- - **Ignore** items it doesn't care about — it is just a method call.
134
+ abstract onFunctionCallOutput(item: FunctionCallOutputItem): Promise<void>
106
135
 
107
- Items are discriminated by the `ContextItem` subclass and, for messages, the `role` field. The full taxonomy is in [src/domain/model-context/context-item](src/domain/model-context/context-item):
136
+ abstract onExternalFunctionCallOutput(source: Participant, item: FunctionCallOutputItem): Promise<void>
108
137
 
109
- - Client-produced: `UserMessageItem`, `DeveloperMessageItem`, `SystemMessageItem`, `FunctionCallOutputItem`
138
+ abstract onReasoning(item: ReasoningItem): Promise<void>
139
+
140
+ abstract onExternalReasoning(source: Participant, item: ReasoningItem): Promise<void>
141
+
142
+ abstract onModelMessage(item: ModelMessageItem): Promise<void>
143
+
144
+ abstract onExternalModelMessage(source: Participant, item: ModelMessageItem): Promise<void>
145
+
146
+ abstract onMessage(message: string): Promise<void>
147
+ ```
148
+
149
+ The typed `ContextItem`s involved are defined in [src/domain/model-context/context-item](src/domain/model-context/context-item):
150
+
151
+ - Client-produced: `FunctionCallOutputItem` (and `UserMessageItem` / `DeveloperMessageItem` / `SystemMessageItem` when building a `ModelContext` directly)
110
152
  - Model-produced: `ModelMessageItem`, `FunctionCallItem`, `ReasoningItem`
111
153
 
154
+ Plain conversational input flows as a `string` through `onMessage` — participants exchange messages without committing to a specific `ContextItem` shape on the wire.
155
+
112
156
  ### Passive observer
113
157
 
158
+ A passive observer subclasses `Participant` and overrides only the handlers it cares about:
159
+
114
160
  ```ts
115
- import { Participant, ContextItem } from "@mozaik-ai/core"
161
+ import {
162
+ Participant,
163
+ FunctionCallItem,
164
+ FunctionCallOutputItem,
165
+ ReasoningItem,
166
+ ModelMessageItem,
167
+ } from "@mozaik-ai/core"
116
168
 
117
169
  export class TranscriptLogger extends Participant {
118
- async onContextItem(source: Participant, item: ContextItem): Promise<void> {
119
- console.log(`[${source.constructor.name}]`, item.toJSON())
170
+ async onMessage(message: string): Promise<void> {
171
+ console.log("[message]", message)
172
+ }
173
+
174
+ async onExternalFunctionCall(source: Participant, item: FunctionCallItem): Promise<void> {
175
+ console.log(`[${source.constructor.name}] function_call`, item.toJSON())
176
+ }
177
+
178
+ async onExternalFunctionCallOutput(source: Participant, item: FunctionCallOutputItem): Promise<void> {
179
+ console.log(`[${source.constructor.name}] function_call_output`, item.toJSON())
180
+ }
181
+
182
+ async onExternalReasoning(source: Participant, item: ReasoningItem): Promise<void> {
183
+ console.log(`[${source.constructor.name}] reasoning`, item.toJSON())
120
184
  }
185
+
186
+ async onExternalModelMessage(source: Participant, item: ModelMessageItem): Promise<void> {
187
+ console.log(`[${source.constructor.name}] model_message`, item.toJSON())
188
+ }
189
+
190
+ // Self-emitted handlers (onFunctionCall, onReasoning, …) can be no-ops for a pure observer.
191
+ async onFunctionCall(): Promise<void> {}
192
+ async onFunctionCallOutput(): Promise<void> {}
193
+ async onReasoning(): Promise<void> {}
194
+ async onModelMessage(): Promise<void> {}
121
195
  }
122
196
  ```
123
197
 
124
198
  ### Reactive agent
125
199
 
126
- A reactive agent extends `BaseAgentParticipant` and uses incoming items from _other_ participants to decide when to run inference or execute a tool call:
200
+ A reactive agent extends `BaseAgentParticipant` and overrides the handlers it wants to react on. Each handler is already a no-op in the base class, so only the relevant ones need bodies:
127
201
 
128
202
  ```ts
129
203
  import {
130
204
  BaseAgentParticipant,
131
205
  Participant,
132
- ContextItem,
133
206
  UserMessageItem,
134
207
  FunctionCallItem,
135
208
  AgenticEnvironment,
136
209
  ModelContext,
137
210
  GenerativeModel,
138
- InputItemSource,
211
+ InputStream,
139
212
  InferenceRunner,
140
213
  FunctionCallRunner,
141
214
  } from "@mozaik-ai/core"
142
215
 
143
216
  export class ReactiveAgent extends BaseAgentParticipant {
144
217
  constructor(
145
- inputSource: InputItemSource,
218
+ inputSource: InputStream,
146
219
  inferenceRunner: InferenceRunner,
147
220
  functionCallRunner: FunctionCallRunner,
148
221
  private readonly environment: AgenticEnvironment,
@@ -152,28 +225,40 @@ export class ReactiveAgent extends BaseAgentParticipant {
152
225
  super(inputSource, inferenceRunner, functionCallRunner)
153
226
  }
154
227
 
155
- async onContextItem(source: Participant, item: ContextItem): Promise<void> {
156
- if (source === this) return
228
+ // A message from a human (or any other participant) → record it and think.
229
+ async onMessage(message: string): Promise<void> {
230
+ this.context.addContextItem(UserMessageItem.create(message))
231
+ this.runInference(this.environment, this.context, this.model)
232
+ }
157
233
 
234
+ // The agent just produced a function call → execute it.
235
+ async onFunctionCall(item: FunctionCallItem): Promise<void> {
158
236
  this.context.addContextItem(item)
237
+ this.executeFunctionCall(this.environment, item)
238
+ }
159
239
 
160
- if (item instanceof UserMessageItem) {
161
- this.runInference(this.environment, this.context, this.model)
162
- return
163
- }
240
+ // The tool just produced an output → feed it back and run inference again.
241
+ async onFunctionCallOutput(item: FunctionCallOutputItem): Promise<void> {
242
+ this.context.addContextItem(item)
243
+ this.runInference(this.environment, this.context, this.model)
244
+ }
164
245
 
165
- if (item instanceof FunctionCallItem) {
166
- this.executeFunctionCall(this.environment, item)
167
- return
168
- }
246
+ // Keep the local context in sync with model-emitted reasoning and replies.
247
+ async onReasoning(item: ReasoningItem): Promise<void> {
248
+ this.context.addContextItem(item)
249
+ }
250
+
251
+ async onModelMessage(item: ModelMessageItem): Promise<void> {
252
+ this.context.addContextItem(item)
169
253
  }
170
254
  }
171
255
  ```
172
256
 
173
- Two things to note:
257
+ Three things to note:
174
258
 
175
- 1. The agent never `await`s its own capability calls inside `onContextItem` — the methods are non-blocking, so the environment keeps delivering items while inference and tool execution run in the background.
176
- 2. Behaviors compose by **reaction**, not orchestration. Add a second agent that listens for `ModelMessageItem`s and you get a critique loop. Add a `TranscriptLogger` and you get a UI stream. Neither change touches the existing participants.
259
+ 1. The split between self handlers and `onExternal*` handlers means a participant can encode "act on my own outputs" separately from "observe others", without inspecting `source` by hand.
260
+ 2. The agent never `await`s its own capability calls inside the handlers — those methods are non-blocking, so the environment keeps delivering events while inference and tool execution run in the background.
261
+ 3. Behaviors compose by **reaction**, not orchestration. Add a second agent that overrides `onExternalModelMessage` and you get a critique loop. Add a `TranscriptLogger` and you get a UI stream. Neither change touches the existing participants.
177
262
 
178
263
  ---
179
264
 
@@ -194,7 +279,7 @@ await repo.save(context)
194
279
 
195
280
  Implement `ModelContextRepository` to plug in any storage backend.
196
281
 
197
- The default OpenAI provider is `OpenAIResponses`, implementing the [OpenResponses](https://www.openresponses.org/) spec. It maps `ModelContext` to the OpenAI Responses API and back into typed `ContextItem`s. Bundled models: `Gpt54`, `Gpt54Mini`, `Gpt54Nano`.
282
+ The default OpenAI provider is `OpenAIResponses`, implementing the [OpenResponses](https://www.openresponses.org/) spec. It maps `ModelContext` to the OpenAI Responses API and back into typed `ContextItem`s. Bundled models: `Gpt54`, `Gpt54Mini`, `Gpt54Nano`, `Gpt55`.
198
283
 
199
284
  ```ts
200
285
  import { OpenAIResponses, InferenceRequest, Gpt54 } from "@mozaik-ai/core"
@@ -207,26 +292,26 @@ const response = await runtime.infer(new InferenceRequest(new Gpt54(), context))
207
292
 
208
293
  ## Advanced: overriding generators
209
294
 
210
- `BaseAgentParticipant` and `BaseHumanParticipant` are deliberately thin shells around three generator interfaces. Swap any of them to change _how_ items are produced without touching the environment, the participants, or any consumers.
295
+ `BaseAgentParticipant` and `BaseHumanParticipant` are deliberately thin shells around three generator interfaces. Swap any of them to change _how_ events are produced without touching the environment, the participants, or any consumers.
211
296
 
212
- ### Custom `InputItemSource`
297
+ ### Custom `InputStream`
213
298
 
214
- ```ts
215
- import { InputItemSource, UserMessageItem, DeveloperMessageItem, SystemMessageItem } from "@mozaik-ai/core"
299
+ An `InputStream` yields plain `string` messages, which are then broadcast to every other participant through `onMessage`:
216
300
 
217
- type InputItem = UserMessageItem | DeveloperMessageItem | SystemMessageItem
301
+ ```ts
302
+ import { InputStream } from "@mozaik-ai/core"
218
303
 
219
- export class QueueInputSource implements InputItemSource {
220
- private readonly queue: InputItem[] = []
304
+ export class QueueInputStream implements InputStream {
305
+ private readonly queue: string[] = []
221
306
  private resolveNext?: () => void
222
307
 
223
- push(item: InputItem) {
224
- this.queue.push(item)
308
+ push(message: string) {
309
+ this.queue.push(message)
225
310
  this.resolveNext?.()
226
311
  this.resolveNext = undefined
227
312
  }
228
313
 
229
- async *stream(signal?: AbortSignal): AsyncIterable<InputItem> {
314
+ async *stream(signal?: AbortSignal): AsyncIterable<string> {
230
315
  while (!signal?.aborted) {
231
316
  while (this.queue.length > 0) {
232
317
  yield this.queue.shift()!
@@ -237,7 +322,7 @@ export class QueueInputSource implements InputItemSource {
237
322
  }
238
323
  ```
239
324
 
240
- Use it for stdin, websockets, an HTTP queue, or anything that produces user/developer/system messages over time.
325
+ Use it for stdin, websockets, an HTTP queue, or anything that produces messages over time. Participants decide for themselves what to do with the string — e.g. wrap it in a `UserMessageItem` before adding it to a `ModelContext`.
241
326
 
242
327
  ### Custom `InferenceRunner`
243
328
 
@@ -297,7 +382,7 @@ export class ToolRegistryFunctionCallRunner implements FunctionCallRunner {
297
382
  import { BaseAgentParticipant, AgenticEnvironment } from "@mozaik-ai/core"
298
383
 
299
384
  const agent = new BaseAgentParticipant(
300
- new QueueInputSource(),
385
+ new QueueInputStream(),
301
386
  new OpenAIInferenceRunner(),
302
387
  new ToolRegistryFunctionCallRunner(tools),
303
388
  )
package/dist/index.d.mts CHANGED
@@ -298,7 +298,11 @@ declare class AgenticEnvironment {
298
298
  private isActive;
299
299
  subscribe(subscriber: Participant): void;
300
300
  unsubscribe(user: Participant): void;
301
- deliverContextItem(source: Participant, item: ContextItem): void;
301
+ deliverFunctionCall(source: Participant, item: FunctionCallItem): void;
302
+ deliverModelMessage(source: Participant, item: ModelMessageItem): void;
303
+ deliverReasoning(source: Participant, item: ReasoningItem): void;
304
+ deliverFunctionCallOutput(source: Participant, item: FunctionCallOutputItem): void;
305
+ deliverMessage(source: Participant, message: string): void;
302
306
  start(): Promise<void>;
303
307
  stop(): void;
304
308
  }
@@ -309,8 +313,15 @@ declare abstract class Participant {
309
313
  leave(environment: AgenticEnvironment): void;
310
314
  protected isJoinedTo(environment: AgenticEnvironment): boolean;
311
315
  getEnvironments(): AgenticEnvironment[];
312
- abstract onInternalContextItem(item: ContextItem): Promise<void>;
313
- abstract onExternalContextItem(source: Participant, item: ContextItem): Promise<void>;
316
+ abstract onFunctionCall(item: FunctionCallItem): Promise<void>;
317
+ abstract onExternalFunctionCall(source: Participant, item: FunctionCallItem): Promise<void>;
318
+ abstract onFunctionCallOutput(item: FunctionCallOutputItem): Promise<void>;
319
+ abstract onExternalFunctionCallOutput(source: Participant, item: FunctionCallOutputItem): Promise<void>;
320
+ abstract onReasoning(item: ReasoningItem): Promise<void>;
321
+ abstract onExternalReasoning(source: Participant, item: ReasoningItem): Promise<void>;
322
+ abstract onModelMessage(item: ModelMessageItem): Promise<void>;
323
+ abstract onExternalModelMessage(source: Participant, item: ModelMessageItem): Promise<void>;
324
+ abstract onMessage(message: string): Promise<void>;
314
325
  }
315
326
 
316
327
  interface InputCapable {
@@ -331,17 +342,25 @@ interface FunctionCallRunner {
331
342
  run(functionCallItem: FunctionCallItem, signal?: AbortSignal): AsyncIterable<FunctionCallOutputItem>;
332
343
  }
333
344
 
334
- interface InputItemSource {
335
- stream(signal?: AbortSignal): AsyncIterable<UserMessageItem | DeveloperMessageItem | SystemMessageItem>;
345
+ interface InputStream {
346
+ stream(signal?: AbortSignal): AsyncIterable<string>;
336
347
  }
337
348
 
338
349
  declare class BaseAgentParticipant extends Participant implements InputCapable, InferenceCapable, FunctionCallCapable {
339
350
  private inputSource;
340
351
  private inferenceRunner;
341
352
  private functionCallRunner;
342
- constructor(inputSource: InputItemSource, inferenceRunner: InferenceRunner, functionCallRunner: FunctionCallRunner);
353
+ constructor(inputSource: InputStream, inferenceRunner: InferenceRunner, functionCallRunner: FunctionCallRunner);
343
354
  onInternalContextItem(item: ContextItem): Promise<void>;
344
- onExternalContextItem(source: Participant, item: ContextItem): Promise<void>;
355
+ onFunctionCall(item: FunctionCallItem): Promise<void>;
356
+ onExternalFunctionCall(source: Participant, item: FunctionCallItem): Promise<void>;
357
+ onFunctionCallOutput(item: FunctionCallOutputItem): Promise<void>;
358
+ onExternalFunctionCallOutput(source: Participant, item: FunctionCallOutputItem): Promise<void>;
359
+ onReasoning(item: ReasoningItem): Promise<void>;
360
+ onExternalReasoning(source: Participant, item: ReasoningItem): Promise<void>;
361
+ onModelMessage(item: ModelMessageItem): Promise<void>;
362
+ onExternalModelMessage(source: Participant, item: ModelMessageItem): Promise<void>;
363
+ onMessage(message: string): Promise<void>;
345
364
  executeFunctionCall(environment: AgenticEnvironment, functionCallItem: FunctionCallItem, signal?: AbortSignal): Promise<void>;
346
365
  runInference(environment: AgenticEnvironment, context: ModelContext, model: GenerativeModel, signal?: AbortSignal): Promise<void>;
347
366
  streamInput(environment: AgenticEnvironment): Promise<void>;
@@ -349,9 +368,17 @@ declare class BaseAgentParticipant extends Participant implements InputCapable,
349
368
 
350
369
  declare class BaseHumanParticipant extends Participant implements InputCapable {
351
370
  private inputSource;
352
- constructor(inputSource: InputItemSource);
353
- onInternalContextItem(item: ContextItem): Promise<void>;
354
- onExternalContextItem(source: Participant, item: ContextItem): Promise<void>;
371
+ constructor(inputSource: InputStream);
372
+ onFunctionCall(item: FunctionCallItem): Promise<void>;
373
+ onExternalFunctionCall(source: Participant, item: FunctionCallItem): Promise<void>;
374
+ onContextItem(source: Participant, item: ContextItem): Promise<void>;
375
+ onFunctionCallOutput(item: FunctionCallOutputItem): Promise<void>;
376
+ onExternalFunctionCallOutput(source: Participant, item: FunctionCallOutputItem): Promise<void>;
377
+ onReasoning(item: ReasoningItem): Promise<void>;
378
+ onExternalReasoning(source: Participant, item: ReasoningItem): Promise<void>;
379
+ onModelMessage(item: ModelMessageItem): Promise<void>;
380
+ onExternalModelMessage(source: Participant, item: ModelMessageItem): Promise<void>;
381
+ onMessage(message: string): Promise<void>;
355
382
  streamInput(environment: AgenticEnvironment): Promise<void>;
356
383
  }
357
384
 
@@ -385,4 +412,4 @@ declare class Gpt55 implements GenerativeModel, ReasoningEffort<OpenAIReasoningE
385
412
  getReasoningEffort(): OpenAIReasoningEffortType;
386
413
  }
387
414
 
388
- export { AgenticEnvironment, BaseAgentParticipant, BaseHumanParticipant, ContextItem, DefaultFunctionCallRunner, DeveloperMessageItem, FunctionCallItem, FunctionCallOutputItem, type FunctionCallRunner, type GenerativeModel, Gpt54, Gpt54Mini, Gpt54Nano, Gpt55, InMemoryModelContextRepository, InferenceRequest, InferenceResponse, type InferenceRunner, type InputItemSource, InputTokenDetails, ModelContext, type ModelContextRepository, ModelMessageItem, OpenAIInferenceRunner, OpenAIResponses, OutputTokenDetails, Participant, ReasoningItem, SystemMessageItem, TokenUsage, type Tool, UserMessageItem };
415
+ export { AgenticEnvironment, BaseAgentParticipant, BaseHumanParticipant, ContextItem, DefaultFunctionCallRunner, DeveloperMessageItem, FunctionCallItem, FunctionCallOutputItem, type FunctionCallRunner, type GenerativeModel, Gpt54, Gpt54Mini, Gpt54Nano, Gpt55, InMemoryModelContextRepository, InferenceRequest, InferenceResponse, type InferenceRunner, type InputStream, InputTokenDetails, ModelContext, type ModelContextRepository, ModelMessageItem, OpenAIInferenceRunner, OpenAIResponses, OutputTokenDetails, Participant, ReasoningItem, SystemMessageItem, TokenUsage, type Tool, UserMessageItem };
package/dist/index.d.ts CHANGED
@@ -298,7 +298,11 @@ declare class AgenticEnvironment {
298
298
  private isActive;
299
299
  subscribe(subscriber: Participant): void;
300
300
  unsubscribe(user: Participant): void;
301
- deliverContextItem(source: Participant, item: ContextItem): void;
301
+ deliverFunctionCall(source: Participant, item: FunctionCallItem): void;
302
+ deliverModelMessage(source: Participant, item: ModelMessageItem): void;
303
+ deliverReasoning(source: Participant, item: ReasoningItem): void;
304
+ deliverFunctionCallOutput(source: Participant, item: FunctionCallOutputItem): void;
305
+ deliverMessage(source: Participant, message: string): void;
302
306
  start(): Promise<void>;
303
307
  stop(): void;
304
308
  }
@@ -309,8 +313,15 @@ declare abstract class Participant {
309
313
  leave(environment: AgenticEnvironment): void;
310
314
  protected isJoinedTo(environment: AgenticEnvironment): boolean;
311
315
  getEnvironments(): AgenticEnvironment[];
312
- abstract onInternalContextItem(item: ContextItem): Promise<void>;
313
- abstract onExternalContextItem(source: Participant, item: ContextItem): Promise<void>;
316
+ abstract onFunctionCall(item: FunctionCallItem): Promise<void>;
317
+ abstract onExternalFunctionCall(source: Participant, item: FunctionCallItem): Promise<void>;
318
+ abstract onFunctionCallOutput(item: FunctionCallOutputItem): Promise<void>;
319
+ abstract onExternalFunctionCallOutput(source: Participant, item: FunctionCallOutputItem): Promise<void>;
320
+ abstract onReasoning(item: ReasoningItem): Promise<void>;
321
+ abstract onExternalReasoning(source: Participant, item: ReasoningItem): Promise<void>;
322
+ abstract onModelMessage(item: ModelMessageItem): Promise<void>;
323
+ abstract onExternalModelMessage(source: Participant, item: ModelMessageItem): Promise<void>;
324
+ abstract onMessage(message: string): Promise<void>;
314
325
  }
315
326
 
316
327
  interface InputCapable {
@@ -331,17 +342,25 @@ interface FunctionCallRunner {
331
342
  run(functionCallItem: FunctionCallItem, signal?: AbortSignal): AsyncIterable<FunctionCallOutputItem>;
332
343
  }
333
344
 
334
- interface InputItemSource {
335
- stream(signal?: AbortSignal): AsyncIterable<UserMessageItem | DeveloperMessageItem | SystemMessageItem>;
345
+ interface InputStream {
346
+ stream(signal?: AbortSignal): AsyncIterable<string>;
336
347
  }
337
348
 
338
349
  declare class BaseAgentParticipant extends Participant implements InputCapable, InferenceCapable, FunctionCallCapable {
339
350
  private inputSource;
340
351
  private inferenceRunner;
341
352
  private functionCallRunner;
342
- constructor(inputSource: InputItemSource, inferenceRunner: InferenceRunner, functionCallRunner: FunctionCallRunner);
353
+ constructor(inputSource: InputStream, inferenceRunner: InferenceRunner, functionCallRunner: FunctionCallRunner);
343
354
  onInternalContextItem(item: ContextItem): Promise<void>;
344
- onExternalContextItem(source: Participant, item: ContextItem): Promise<void>;
355
+ onFunctionCall(item: FunctionCallItem): Promise<void>;
356
+ onExternalFunctionCall(source: Participant, item: FunctionCallItem): Promise<void>;
357
+ onFunctionCallOutput(item: FunctionCallOutputItem): Promise<void>;
358
+ onExternalFunctionCallOutput(source: Participant, item: FunctionCallOutputItem): Promise<void>;
359
+ onReasoning(item: ReasoningItem): Promise<void>;
360
+ onExternalReasoning(source: Participant, item: ReasoningItem): Promise<void>;
361
+ onModelMessage(item: ModelMessageItem): Promise<void>;
362
+ onExternalModelMessage(source: Participant, item: ModelMessageItem): Promise<void>;
363
+ onMessage(message: string): Promise<void>;
345
364
  executeFunctionCall(environment: AgenticEnvironment, functionCallItem: FunctionCallItem, signal?: AbortSignal): Promise<void>;
346
365
  runInference(environment: AgenticEnvironment, context: ModelContext, model: GenerativeModel, signal?: AbortSignal): Promise<void>;
347
366
  streamInput(environment: AgenticEnvironment): Promise<void>;
@@ -349,9 +368,17 @@ declare class BaseAgentParticipant extends Participant implements InputCapable,
349
368
 
350
369
  declare class BaseHumanParticipant extends Participant implements InputCapable {
351
370
  private inputSource;
352
- constructor(inputSource: InputItemSource);
353
- onInternalContextItem(item: ContextItem): Promise<void>;
354
- onExternalContextItem(source: Participant, item: ContextItem): Promise<void>;
371
+ constructor(inputSource: InputStream);
372
+ onFunctionCall(item: FunctionCallItem): Promise<void>;
373
+ onExternalFunctionCall(source: Participant, item: FunctionCallItem): Promise<void>;
374
+ onContextItem(source: Participant, item: ContextItem): Promise<void>;
375
+ onFunctionCallOutput(item: FunctionCallOutputItem): Promise<void>;
376
+ onExternalFunctionCallOutput(source: Participant, item: FunctionCallOutputItem): Promise<void>;
377
+ onReasoning(item: ReasoningItem): Promise<void>;
378
+ onExternalReasoning(source: Participant, item: ReasoningItem): Promise<void>;
379
+ onModelMessage(item: ModelMessageItem): Promise<void>;
380
+ onExternalModelMessage(source: Participant, item: ModelMessageItem): Promise<void>;
381
+ onMessage(message: string): Promise<void>;
355
382
  streamInput(environment: AgenticEnvironment): Promise<void>;
356
383
  }
357
384
 
@@ -385,4 +412,4 @@ declare class Gpt55 implements GenerativeModel, ReasoningEffort<OpenAIReasoningE
385
412
  getReasoningEffort(): OpenAIReasoningEffortType;
386
413
  }
387
414
 
388
- export { AgenticEnvironment, BaseAgentParticipant, BaseHumanParticipant, ContextItem, DefaultFunctionCallRunner, DeveloperMessageItem, FunctionCallItem, FunctionCallOutputItem, type FunctionCallRunner, type GenerativeModel, Gpt54, Gpt54Mini, Gpt54Nano, Gpt55, InMemoryModelContextRepository, InferenceRequest, InferenceResponse, type InferenceRunner, type InputItemSource, InputTokenDetails, ModelContext, type ModelContextRepository, ModelMessageItem, OpenAIInferenceRunner, OpenAIResponses, OutputTokenDetails, Participant, ReasoningItem, SystemMessageItem, TokenUsage, type Tool, UserMessageItem };
415
+ export { AgenticEnvironment, BaseAgentParticipant, BaseHumanParticipant, ContextItem, DefaultFunctionCallRunner, DeveloperMessageItem, FunctionCallItem, FunctionCallOutputItem, type FunctionCallRunner, type GenerativeModel, Gpt54, Gpt54Mini, Gpt54Nano, Gpt55, InMemoryModelContextRepository, InferenceRequest, InferenceResponse, type InferenceRunner, type InputStream, InputTokenDetails, ModelContext, type ModelContextRepository, ModelMessageItem, OpenAIInferenceRunner, OpenAIResponses, OutputTokenDetails, Participant, ReasoningItem, SystemMessageItem, TokenUsage, type Tool, UserMessageItem };