@mozaik-ai/core 0.7.0 → 0.7.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 +91 -96
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -9,7 +9,7 @@ Mozaik is a TypeScript library for orchestrating AI agents, supporting both manu
|
|
|
9
9
|
## 📦 Installation
|
|
10
10
|
|
|
11
11
|
```bash
|
|
12
|
-
yarn add @
|
|
12
|
+
yarn add @mozaik-ai/core
|
|
13
13
|
```
|
|
14
14
|
|
|
15
15
|
## API Key Configuration
|
|
@@ -30,22 +30,22 @@ The system supports OpenAI models (gpt-5, gpt-5-mini, gpt-5-nano, gpt-5.1) and A
|
|
|
30
30
|
|
|
31
31
|
---
|
|
32
32
|
|
|
33
|
-
## Features
|
|
33
|
+
## Features
|
|
34
34
|
|
|
35
35
|
### AI Agents
|
|
36
36
|
|
|
37
37
|
This feature lets developers create AI agents through a single unified request definition, making it easy to compose tasks and leverage multiple models. You can mix providers, choose the best model for each task, and build agents that work across different capabilities.
|
|
38
38
|
|
|
39
39
|
```typescript
|
|
40
|
-
import
|
|
41
|
-
import { Agent, Command } from
|
|
40
|
+
import "dotenv/config"
|
|
41
|
+
import { Agent, Command } from "@mozaik-ai/core"
|
|
42
42
|
|
|
43
43
|
const command: Command = {
|
|
44
|
-
|
|
44
|
+
model: "claude-sonnet-4.5",
|
|
45
45
|
}
|
|
46
46
|
|
|
47
47
|
const agent = new Agent(command)
|
|
48
|
-
const codingResponse = await agent.act(
|
|
48
|
+
const codingResponse = await agent.act("Write a React component for a todo list")
|
|
49
49
|
```
|
|
50
50
|
|
|
51
51
|
### Structured Output
|
|
@@ -53,25 +53,27 @@ const codingResponse = await agent.act('Write a React component for a todo list'
|
|
|
53
53
|
Structured output lets you enforce exact response formats—using schemas like Zod—so AI returns predictable, validated data every time.
|
|
54
54
|
|
|
55
55
|
```typescript
|
|
56
|
-
import { z } from
|
|
57
|
-
import { Agent, Command } from
|
|
56
|
+
import { z } from "zod"
|
|
57
|
+
import { Agent, Command } from "@mozaik-ai/core"
|
|
58
58
|
|
|
59
59
|
const mealPlanSchema = z.object({
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
60
|
+
calories: z.number(),
|
|
61
|
+
meals: z
|
|
62
|
+
.array(
|
|
63
|
+
z.object({
|
|
64
|
+
name: z.string(),
|
|
65
|
+
description: z.string(),
|
|
66
|
+
ingredients: z.array(z.string()).min(3),
|
|
67
|
+
}),
|
|
68
|
+
)
|
|
69
|
+
.length(3),
|
|
70
|
+
shoppingList: z.array(z.string()),
|
|
69
71
|
})
|
|
70
72
|
|
|
71
73
|
const command: Command = {
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
74
|
+
model: "gpt-5-mini",
|
|
75
|
+
task: "Create a 1-day vegetarian meal plan with breakfast, lunch, and dinner.",
|
|
76
|
+
structuredOutput: mealPlanSchema,
|
|
75
77
|
}
|
|
76
78
|
|
|
77
79
|
const agent = new Agent(command)
|
|
@@ -83,19 +85,19 @@ const response = await agent.act()
|
|
|
83
85
|
Multi-turn conversation allows developers to provide chat history so the AI agent can maintain context and generate more relevant, continuous responses.
|
|
84
86
|
|
|
85
87
|
```typescript
|
|
86
|
-
import { Agent, Command } from
|
|
88
|
+
import { Agent, Command } from "@mozaik-ai/core"
|
|
87
89
|
|
|
88
90
|
const command: Command = {
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
91
|
+
messages: [
|
|
92
|
+
{ role: "system", content: "You are a coding assistant" },
|
|
93
|
+
{ role: "user", content: "How do I sort an array in TypeScript?" },
|
|
94
|
+
{ role: "assistant", content: "You can use the .sort() method..." },
|
|
95
|
+
],
|
|
96
|
+
model: "claude-haiku-4.5",
|
|
95
97
|
}
|
|
96
98
|
|
|
97
99
|
const agent = new Agent(command)
|
|
98
|
-
const response = await agent.act(
|
|
100
|
+
const response = await agent.act("Can you show me an example?")
|
|
99
101
|
```
|
|
100
102
|
|
|
101
103
|
### Tool Calling
|
|
@@ -103,38 +105,38 @@ const response = await agent.act('Can you show me an example?')
|
|
|
103
105
|
Tool calling allows the agent to invoke real functions in your environment—letting it perform actual actions (like writing files, calling APIs, or modifying state) instead of merely generating text.
|
|
104
106
|
|
|
105
107
|
```typescript
|
|
106
|
-
import { promises as fs } from
|
|
107
|
-
import { Agent, Command, Tool } from
|
|
108
|
+
import { promises as fs } from "fs"
|
|
109
|
+
import { Agent, Command, Tool } from "@mozaik-ai/core"
|
|
108
110
|
|
|
109
111
|
const tools: Tool[] = [
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
112
|
+
{
|
|
113
|
+
name: "write_file",
|
|
114
|
+
description: "Write text to a file.",
|
|
115
|
+
schema: {
|
|
116
|
+
type: "object",
|
|
117
|
+
properties: {
|
|
118
|
+
filename: { type: "string" },
|
|
119
|
+
content: { type: "string" },
|
|
120
|
+
},
|
|
121
|
+
required: ["filename", "content"],
|
|
122
|
+
},
|
|
123
|
+
async invoke({ filename, content }) {
|
|
124
|
+
await fs.writeFile(filename, content, "utf8")
|
|
125
|
+
return { ok: true }
|
|
126
|
+
},
|
|
127
|
+
},
|
|
126
128
|
]
|
|
127
129
|
|
|
128
130
|
const command: Command = {
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
131
|
+
model: "gpt-5.1",
|
|
132
|
+
tools,
|
|
133
|
+
messages: [
|
|
134
|
+
{
|
|
135
|
+
role: "system",
|
|
136
|
+
content: "Save notes to disk using the tool, then confirm where the file was written.",
|
|
137
|
+
},
|
|
138
|
+
],
|
|
139
|
+
task: "Create a two-bullet trip prep checklist for Belgrade and save it as trip-checklist.txt.",
|
|
138
140
|
}
|
|
139
141
|
|
|
140
142
|
const agent = new Agent(command)
|
|
@@ -146,23 +148,25 @@ await agent.act()
|
|
|
146
148
|
Vision support allows AI agents to interpret images alongside text, enabling richer understanding and multimodal interactions.
|
|
147
149
|
|
|
148
150
|
```typescript
|
|
149
|
-
import { Agent, Command } from
|
|
151
|
+
import { Agent, Command } from "@mozaik-ai/core"
|
|
150
152
|
|
|
151
153
|
const command: Command = {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
154
|
+
messages: [
|
|
155
|
+
{
|
|
156
|
+
role: "user",
|
|
157
|
+
content: [
|
|
158
|
+
{
|
|
159
|
+
type: "image_url",
|
|
160
|
+
url: "data:image/jpeg;base64,/9j/4AAQSkZJRg...",
|
|
161
|
+
},
|
|
162
|
+
{
|
|
163
|
+
type: "text",
|
|
164
|
+
text: "What is in this image?",
|
|
165
|
+
},
|
|
166
|
+
],
|
|
167
|
+
},
|
|
168
|
+
],
|
|
169
|
+
model: "claude-opus-4.5",
|
|
166
170
|
}
|
|
167
171
|
|
|
168
172
|
const agent = new Agent(command)
|
|
@@ -174,27 +178,24 @@ const response = await agent.act()
|
|
|
174
178
|
This example demonstrates how to use standard JavaScript/TypeScript concurrency (Promise.all) to run multiple AI agents in parallel and compare or combine their responses.
|
|
175
179
|
|
|
176
180
|
```typescript
|
|
177
|
-
import
|
|
178
|
-
import { Agent, Command } from
|
|
181
|
+
import "dotenv/config"
|
|
182
|
+
import { Agent, Command } from "@mozaik-ai/core"
|
|
179
183
|
|
|
180
184
|
const openaiCommand: Command = {
|
|
181
|
-
|
|
185
|
+
model: "gpt-5",
|
|
182
186
|
}
|
|
183
187
|
|
|
184
188
|
const anthropicCommand: Command = {
|
|
185
|
-
|
|
189
|
+
model: "claude-sonnet-4.5",
|
|
186
190
|
}
|
|
187
191
|
|
|
188
192
|
const openaiAgent = new Agent(openaiCommand)
|
|
189
193
|
const anthropicAgent = new Agent(anthropicCommand)
|
|
190
194
|
|
|
191
|
-
const task =
|
|
195
|
+
const task = "What are the key differences between TypeScript and JavaScript?"
|
|
192
196
|
|
|
193
197
|
// Execute both agents in parallel using Promise.all()
|
|
194
|
-
const [openaiResponse, anthropicResponse] = await Promise.all([
|
|
195
|
-
openaiAgent.act(task),
|
|
196
|
-
anthropicAgent.act(task)
|
|
197
|
-
])
|
|
198
|
+
const [openaiResponse, anthropicResponse] = await Promise.all([openaiAgent.act(task), anthropicAgent.act(task)])
|
|
198
199
|
```
|
|
199
200
|
|
|
200
201
|
### Workflow
|
|
@@ -203,12 +204,12 @@ A workflow defines how tasks are executed together, either sequentially (one aft
|
|
|
203
204
|
|
|
204
205
|
```typescript
|
|
205
206
|
const workflow = new Workflow("sequential", [
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
207
|
+
new Task("Analyze requirements", "gpt-5"),
|
|
208
|
+
new Workflow("parallel", [
|
|
209
|
+
new Task("Generate API schema", "gpt-5-mini"),
|
|
210
|
+
new Task("Draft documentation", "gpt-5-nano"),
|
|
211
|
+
]),
|
|
212
|
+
new Task("Review and finalize", "gpt-5"),
|
|
212
213
|
])
|
|
213
214
|
|
|
214
215
|
await workflow.execute()
|
|
@@ -222,13 +223,10 @@ For example, given the goal `"Implement login functionality"`, the planner can g
|
|
|
222
223
|
|
|
223
224
|
```typescript
|
|
224
225
|
Workflow(sequential, [
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
Task("Style the login form", "gpt-5-nano")
|
|
230
|
-
]),
|
|
231
|
-
Task("Write unit tests", "gpt-5")
|
|
226
|
+
Task("Design login form UI", "gpt-5"),
|
|
227
|
+
Task("Implement authentication logic", "claude-sonnet-4.5"),
|
|
228
|
+
Workflow(parallel, [Task("Add input validation", "gpt-5-mini"), Task("Style the login form", "gpt-5-nano")]),
|
|
229
|
+
Task("Write unit tests", "gpt-5"),
|
|
232
230
|
])
|
|
233
231
|
```
|
|
234
232
|
|
|
@@ -257,10 +255,7 @@ import { ClusterHook } from "@core/workflow/hooks/cluster"
|
|
|
257
255
|
import { DEFAULT_CLUSTER_HOOK } from "@core/workflow/hooks"
|
|
258
256
|
import { MetricsHook } from "./metrics-hook"
|
|
259
257
|
|
|
260
|
-
const extendedHook = new ClusterHook([
|
|
261
|
-
DEFAULT_CLUSTER_HOOK,
|
|
262
|
-
new MetricsHook()
|
|
263
|
-
])
|
|
258
|
+
const extendedHook = new ClusterHook([DEFAULT_CLUSTER_HOOK, new MetricsHook()])
|
|
264
259
|
|
|
265
260
|
await workflow.execute(extendedHook)
|
|
266
261
|
```
|