@mozaik-ai/core 3.7.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 +162 -60
- package/dist/index.d.mts +38 -11
- package/dist/index.d.ts +38 -11
- package/dist/index.js +109 -19
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +109 -19
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
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
|
|
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
|
  
|
|
6
6
|
|
|
7
|
-
In Mozaik, humans, agents, observers, and tools are all `Participant`s of the same `AgenticEnvironment`. Each participant runs **non-blocking** and
|
|
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
|
|
|
@@ -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
|
|
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 -->|
|
|
36
|
-
Env -->|
|
|
37
|
-
Env -->|
|
|
45
|
+
Env -->|"onMessage / onExternal*"| Human
|
|
46
|
+
Env -->|"onFunctionCall / onReasoning / …"| Agent
|
|
47
|
+
Env -->|"onExternal*"| Observer
|
|
38
48
|
```
|
|
39
49
|
|
|
40
50
|
---
|
|
@@ -43,24 +53,49 @@ flowchart LR
|
|
|
43
53
|
|
|
44
54
|
Mozaik ships two ready-to-use participants:
|
|
45
55
|
|
|
46
|
-
| Participant | Capabilities | Pulls from
|
|
47
|
-
| ---------------------- | --------------------------------------------------------- |
|
|
48
|
-
| `BaseHumanParticipant` | `InputCapable` | `
|
|
49
|
-
| `BaseAgentParticipant` | `InputCapable`, `InferenceCapable`, `FunctionCallCapable` | `
|
|
56
|
+
| Participant | Capabilities | Pulls from |
|
|
57
|
+
| ---------------------- | --------------------------------------------------------- | ------------------------------------------------------ |
|
|
58
|
+
| `BaseHumanParticipant` | `InputCapable` | `InputStream` |
|
|
59
|
+
| `BaseAgentParticipant` | `InputCapable`, `InferenceCapable`, `FunctionCallCapable` | `InputStream`, `InferenceRunner`, `FunctionCallRunner` |
|
|
50
60
|
|
|
51
|
-
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.
|
|
52
62
|
|
|
53
|
-
|
|
54
|
-
export async function deliverStream<T extends ContextItem>(
|
|
55
|
-
environment: AgenticEnvironment,
|
|
56
|
-
initiator: Participant,
|
|
57
|
-
stream: AsyncIterable<T>,
|
|
58
|
-
): Promise<void> {
|
|
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:
|
|
59
64
|
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
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
|
|
79
|
+
async runInference(
|
|
80
|
+
environment: AgenticEnvironment,
|
|
81
|
+
context: ModelContext,
|
|
82
|
+
model: GenerativeModel,
|
|
83
|
+
signal?: AbortSignal,
|
|
84
|
+
): Promise<void> {
|
|
85
|
+
if (!this.isJoinedTo(environment)) return
|
|
86
|
+
|
|
87
|
+
const stream = this.inferenceRunner.run(context, model, signal)
|
|
88
|
+
|
|
89
|
+
for await (const item of stream) {
|
|
90
|
+
if (item.type === "reasoning") {
|
|
91
|
+
await environment.deliverReasoning(this, item)
|
|
92
|
+
} else if (item.type === "function_call") {
|
|
93
|
+
await environment.deliverFunctionCall(this, item)
|
|
94
|
+
} else if (item.type === "message" && item.role === "assistant") {
|
|
95
|
+
await environment.deliverModelMessage(this, item)
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
}
|
|
64
99
|
```
|
|
65
100
|
|
|
66
101
|
Because each call is a fresh promise that wraps an async iterable, multiple participants can act on the same environment **concurrently**:
|
|
@@ -96,53 +131,100 @@ The environment fans every item out to every subscriber synchronously and withou
|
|
|
96
131
|
|
|
97
132
|
---
|
|
98
133
|
|
|
99
|
-
## Intercepting
|
|
134
|
+
## Intercepting events from other participants
|
|
135
|
+
|
|
136
|
+
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:
|
|
137
|
+
|
|
138
|
+
- **Observe** events from other participants via the `onExternal*` family (telemetry, audit, UI streaming) and `onMessage` for plain-text messages.
|
|
139
|
+
- **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.
|
|
140
|
+
- **Ignore** events it doesn't care about — every handler defaults to a no-op in the bundled participants.
|
|
141
|
+
|
|
142
|
+
The intercept surface, taken from `Participant`:
|
|
143
|
+
|
|
144
|
+
```ts
|
|
145
|
+
abstract onFunctionCall(item: FunctionCallItem): Promise<void>
|
|
146
|
+
|
|
147
|
+
abstract onExternalFunctionCall(source: Participant, item: FunctionCallItem): Promise<void>
|
|
100
148
|
|
|
101
|
-
|
|
149
|
+
abstract onFunctionCallOutput(item: FunctionCallOutputItem): Promise<void>
|
|
102
150
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
151
|
+
abstract onExternalFunctionCallOutput(source: Participant, item: FunctionCallOutputItem): Promise<void>
|
|
152
|
+
|
|
153
|
+
abstract onReasoning(item: ReasoningItem): Promise<void>
|
|
154
|
+
|
|
155
|
+
abstract onExternalReasoning(source: Participant, item: ReasoningItem): Promise<void>
|
|
156
|
+
|
|
157
|
+
abstract onModelMessage(item: ModelMessageItem): Promise<void>
|
|
158
|
+
|
|
159
|
+
abstract onExternalModelMessage(source: Participant, item: ModelMessageItem): Promise<void>
|
|
160
|
+
|
|
161
|
+
abstract onMessage(message: string): Promise<void>
|
|
162
|
+
```
|
|
106
163
|
|
|
107
|
-
|
|
164
|
+
The typed `ContextItem`s involved are defined in [src/domain/model-context/context-item](src/domain/model-context/context-item):
|
|
108
165
|
|
|
109
|
-
- Client-produced: `UserMessageItem
|
|
166
|
+
- Client-produced: `FunctionCallOutputItem` (and `UserMessageItem` / `DeveloperMessageItem` / `SystemMessageItem` when building a `ModelContext` directly)
|
|
110
167
|
- Model-produced: `ModelMessageItem`, `FunctionCallItem`, `ReasoningItem`
|
|
111
168
|
|
|
169
|
+
Plain conversational input flows as a `string` through `onMessage` — participants exchange messages without committing to a specific `ContextItem` shape on the wire.
|
|
170
|
+
|
|
112
171
|
### Passive observer
|
|
113
172
|
|
|
173
|
+
A passive observer subclasses `Participant` and overrides only the handlers it cares about:
|
|
174
|
+
|
|
114
175
|
```ts
|
|
115
|
-
import { Participant,
|
|
176
|
+
import { Participant, FunctionCallItem, FunctionCallOutputItem, ReasoningItem, ModelMessageItem } from "@mozaik-ai/core"
|
|
116
177
|
|
|
117
178
|
export class TranscriptLogger extends Participant {
|
|
118
|
-
async
|
|
119
|
-
console.log(
|
|
179
|
+
async onMessage(message: string): Promise<void> {
|
|
180
|
+
console.log("[message]", message)
|
|
181
|
+
}
|
|
182
|
+
|
|
183
|
+
async onExternalFunctionCall(source: Participant, item: FunctionCallItem): Promise<void> {
|
|
184
|
+
console.log(`[${source.constructor.name}] function_call`, item.toJSON())
|
|
120
185
|
}
|
|
186
|
+
|
|
187
|
+
async onExternalFunctionCallOutput(source: Participant, item: FunctionCallOutputItem): Promise<void> {
|
|
188
|
+
console.log(`[${source.constructor.name}] function_call_output`, item.toJSON())
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
async onExternalReasoning(source: Participant, item: ReasoningItem): Promise<void> {
|
|
192
|
+
console.log(`[${source.constructor.name}] reasoning`, item.toJSON())
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
async onExternalModelMessage(source: Participant, item: ModelMessageItem): Promise<void> {
|
|
196
|
+
console.log(`[${source.constructor.name}] model_message`, item.toJSON())
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// Self-emitted handlers (onFunctionCall, onReasoning, …) can be no-ops for a pure observer.
|
|
200
|
+
async onFunctionCall(): Promise<void> {}
|
|
201
|
+
async onFunctionCallOutput(): Promise<void> {}
|
|
202
|
+
async onReasoning(): Promise<void> {}
|
|
203
|
+
async onModelMessage(): Promise<void> {}
|
|
121
204
|
}
|
|
122
205
|
```
|
|
123
206
|
|
|
124
207
|
### Reactive agent
|
|
125
208
|
|
|
126
|
-
A reactive agent extends `BaseAgentParticipant` and
|
|
209
|
+
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
210
|
|
|
128
211
|
```ts
|
|
129
212
|
import {
|
|
130
213
|
BaseAgentParticipant,
|
|
131
214
|
Participant,
|
|
132
|
-
ContextItem,
|
|
133
215
|
UserMessageItem,
|
|
134
216
|
FunctionCallItem,
|
|
135
217
|
AgenticEnvironment,
|
|
136
218
|
ModelContext,
|
|
137
219
|
GenerativeModel,
|
|
138
|
-
|
|
220
|
+
InputStream,
|
|
139
221
|
InferenceRunner,
|
|
140
222
|
FunctionCallRunner,
|
|
141
223
|
} from "@mozaik-ai/core"
|
|
142
224
|
|
|
143
225
|
export class ReactiveAgent extends BaseAgentParticipant {
|
|
144
226
|
constructor(
|
|
145
|
-
inputSource:
|
|
227
|
+
inputSource: InputStream,
|
|
146
228
|
inferenceRunner: InferenceRunner,
|
|
147
229
|
functionCallRunner: FunctionCallRunner,
|
|
148
230
|
private readonly environment: AgenticEnvironment,
|
|
@@ -152,28 +234,40 @@ export class ReactiveAgent extends BaseAgentParticipant {
|
|
|
152
234
|
super(inputSource, inferenceRunner, functionCallRunner)
|
|
153
235
|
}
|
|
154
236
|
|
|
155
|
-
|
|
156
|
-
|
|
237
|
+
// A message from a human (or any other participant) → record it and think.
|
|
238
|
+
async onMessage(message: string): Promise<void> {
|
|
239
|
+
this.context.addContextItem(UserMessageItem.create(message))
|
|
240
|
+
this.runInference(this.environment, this.context, this.model)
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
// The agent just produced a function call → execute it.
|
|
244
|
+
async onFunctionCall(item: FunctionCallItem): Promise<void> {
|
|
245
|
+
this.context.addContextItem(item)
|
|
246
|
+
this.executeFunctionCall(this.environment, item)
|
|
247
|
+
}
|
|
157
248
|
|
|
249
|
+
// The tool just produced an output → feed it back and run inference again.
|
|
250
|
+
async onFunctionCallOutput(item: FunctionCallOutputItem): Promise<void> {
|
|
158
251
|
this.context.addContextItem(item)
|
|
252
|
+
this.runInference(this.environment, this.context, this.model)
|
|
253
|
+
}
|
|
159
254
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
255
|
+
// Keep the local context in sync with model-emitted reasoning and replies.
|
|
256
|
+
async onReasoning(item: ReasoningItem): Promise<void> {
|
|
257
|
+
this.context.addContextItem(item)
|
|
258
|
+
}
|
|
164
259
|
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
return
|
|
168
|
-
}
|
|
260
|
+
async onModelMessage(item: ModelMessageItem): Promise<void> {
|
|
261
|
+
this.context.addContextItem(item)
|
|
169
262
|
}
|
|
170
263
|
}
|
|
171
264
|
```
|
|
172
265
|
|
|
173
|
-
|
|
266
|
+
Three things to note:
|
|
174
267
|
|
|
175
|
-
1. The
|
|
176
|
-
2.
|
|
268
|
+
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.
|
|
269
|
+
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.
|
|
270
|
+
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
271
|
|
|
178
272
|
---
|
|
179
273
|
|
|
@@ -194,7 +288,7 @@ await repo.save(context)
|
|
|
194
288
|
|
|
195
289
|
Implement `ModelContextRepository` to plug in any storage backend.
|
|
196
290
|
|
|
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`.
|
|
291
|
+
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
292
|
|
|
199
293
|
```ts
|
|
200
294
|
import { OpenAIResponses, InferenceRequest, Gpt54 } from "@mozaik-ai/core"
|
|
@@ -207,26 +301,34 @@ const response = await runtime.infer(new InferenceRequest(new Gpt54(), context))
|
|
|
207
301
|
|
|
208
302
|
## Advanced: overriding generators
|
|
209
303
|
|
|
210
|
-
`BaseAgentParticipant` and `BaseHumanParticipant` are deliberately thin shells around three generator interfaces. Swap any of them to change _how_
|
|
304
|
+
`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.
|
|
305
|
+
|
|
306
|
+
### Custom `InputStream`
|
|
211
307
|
|
|
212
|
-
|
|
308
|
+
An `InputStream` is the minimal text-source contract a participant uses to feed messages into the environment:
|
|
213
309
|
|
|
214
310
|
```ts
|
|
215
|
-
|
|
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`.
|
|
216
317
|
|
|
217
|
-
|
|
318
|
+
```ts
|
|
319
|
+
import { InputStream } from "@mozaik-ai/core"
|
|
218
320
|
|
|
219
|
-
export class
|
|
220
|
-
private readonly queue:
|
|
321
|
+
export class QueueInputStream implements InputStream {
|
|
322
|
+
private readonly queue: string[] = []
|
|
221
323
|
private resolveNext?: () => void
|
|
222
324
|
|
|
223
|
-
push(
|
|
224
|
-
this.queue.push(
|
|
325
|
+
push(message: string) {
|
|
326
|
+
this.queue.push(message)
|
|
225
327
|
this.resolveNext?.()
|
|
226
328
|
this.resolveNext = undefined
|
|
227
329
|
}
|
|
228
330
|
|
|
229
|
-
async *stream(signal?: AbortSignal): AsyncIterable<
|
|
331
|
+
async *stream(signal?: AbortSignal): AsyncIterable<string> {
|
|
230
332
|
while (!signal?.aborted) {
|
|
231
333
|
while (this.queue.length > 0) {
|
|
232
334
|
yield this.queue.shift()!
|
|
@@ -237,7 +339,7 @@ export class QueueInputSource implements InputItemSource {
|
|
|
237
339
|
}
|
|
238
340
|
```
|
|
239
341
|
|
|
240
|
-
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.
|
|
241
343
|
|
|
242
344
|
### Custom `InferenceRunner`
|
|
243
345
|
|
|
@@ -297,7 +399,7 @@ export class ToolRegistryFunctionCallRunner implements FunctionCallRunner {
|
|
|
297
399
|
import { BaseAgentParticipant, AgenticEnvironment } from "@mozaik-ai/core"
|
|
298
400
|
|
|
299
401
|
const agent = new BaseAgentParticipant(
|
|
300
|
-
new
|
|
402
|
+
new QueueInputStream(),
|
|
301
403
|
new OpenAIInferenceRunner(),
|
|
302
404
|
new ToolRegistryFunctionCallRunner(tools),
|
|
303
405
|
)
|
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
|
-
|
|
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
|
|
313
|
-
abstract
|
|
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
|
|
335
|
-
stream(signal?: AbortSignal): AsyncIterable<
|
|
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:
|
|
353
|
+
constructor(inputSource: InputStream, inferenceRunner: InferenceRunner, functionCallRunner: FunctionCallRunner);
|
|
343
354
|
onInternalContextItem(item: ContextItem): Promise<void>;
|
|
344
|
-
|
|
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:
|
|
353
|
-
|
|
354
|
-
|
|
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
|
|
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
|
-
|
|
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
|
|
313
|
-
abstract
|
|
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
|
|
335
|
-
stream(signal?: AbortSignal): AsyncIterable<
|
|
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:
|
|
353
|
+
constructor(inputSource: InputStream, inferenceRunner: InferenceRunner, functionCallRunner: FunctionCallRunner);
|
|
343
354
|
onInternalContextItem(item: ContextItem): Promise<void>;
|
|
344
|
-
|
|
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:
|
|
353
|
-
|
|
354
|
-
|
|
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
|
|
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 };
|