@virtualkitchenco/multiverse-sdk 0.0.16 → 0.0.18
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 +54 -44
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -11,7 +11,7 @@ npm install @virtualkitchenco/multiverse-sdk
|
|
|
11
11
|
## Quick Start
|
|
12
12
|
|
|
13
13
|
```typescript
|
|
14
|
-
import { multiverse
|
|
14
|
+
import { multiverse } from '@virtualkitchenco/multiverse-sdk';
|
|
15
15
|
import { z } from 'zod';
|
|
16
16
|
|
|
17
17
|
// 1. Configure
|
|
@@ -21,53 +21,29 @@ multiverse.configure({
|
|
|
21
21
|
apiKey: process.env.MULTIVERSE_API_KEY,
|
|
22
22
|
});
|
|
23
23
|
|
|
24
|
-
// 2.
|
|
25
|
-
const SearchResultSchema = z.object({
|
|
26
|
-
flights: z.array(z.object({
|
|
27
|
-
id: z.string(),
|
|
28
|
-
from: z.string(),
|
|
29
|
-
to: z.string(),
|
|
30
|
-
price: z.number(),
|
|
31
|
-
airline: z.string(),
|
|
32
|
-
})),
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
const BookingSchema = z.object({
|
|
36
|
-
bookingId: z.string(),
|
|
37
|
-
flightId: z.string(),
|
|
38
|
-
passengerName: z.string(),
|
|
39
|
-
status: z.enum(['confirmed', 'pending', 'failed']),
|
|
40
|
-
});
|
|
24
|
+
// 2. Register tools (see multiverse.tool() and wrap() below)
|
|
41
25
|
|
|
42
|
-
// 3.
|
|
43
|
-
const searchFlights = wrap(searchFlightsTool, {
|
|
44
|
-
output: SearchResultSchema,
|
|
45
|
-
effects: (output) =>
|
|
46
|
-
output.flights.map((f) => ({
|
|
47
|
-
operation: 'create' as const,
|
|
48
|
-
collection: 'flights',
|
|
49
|
-
id: f.id,
|
|
50
|
-
data: f,
|
|
51
|
-
})),
|
|
52
|
-
});
|
|
53
|
-
|
|
54
|
-
const bookFlight = wrap(bookFlightTool, {
|
|
55
|
-
output: BookingSchema,
|
|
56
|
-
effects: (output) => [
|
|
57
|
-
{ operation: 'create', collection: 'bookings', id: output.bookingId, data: output },
|
|
58
|
-
],
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
// 4. Define and run tests
|
|
26
|
+
// 3. Describe what you're testing
|
|
62
27
|
const test = multiverse.describe({
|
|
63
28
|
name: 'flight-booking-agent',
|
|
64
|
-
task: '
|
|
29
|
+
task: 'Help the user book a flight',
|
|
65
30
|
agent: runAgent,
|
|
66
31
|
});
|
|
67
32
|
|
|
33
|
+
// 4. Generate scenarios with typed variables
|
|
34
|
+
const scenarios = await test.generateScenarios({
|
|
35
|
+
count: 5,
|
|
36
|
+
variables: z.object({
|
|
37
|
+
expectedBookings: z.number().describe('Total flight bookings expected'),
|
|
38
|
+
}),
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
// 5. Run
|
|
68
42
|
const results = await test.run({
|
|
43
|
+
scenarios,
|
|
69
44
|
simulateUser: true,
|
|
70
|
-
success: (world
|
|
45
|
+
success: (world, trace, scenario) =>
|
|
46
|
+
world.getCollection('bookings').size === scenario.variables.expectedBookings,
|
|
71
47
|
});
|
|
72
48
|
|
|
73
49
|
console.log(`${results.passRate}% pass`);
|
|
@@ -90,9 +66,46 @@ multiverse.configure({
|
|
|
90
66
|
});
|
|
91
67
|
```
|
|
92
68
|
|
|
69
|
+
### `multiverse.tool(def)`
|
|
70
|
+
|
|
71
|
+
Register a tool for simulation. Works with any plain function — no framework required.
|
|
72
|
+
|
|
73
|
+
```typescript
|
|
74
|
+
const searchFlights = multiverse.tool({
|
|
75
|
+
name: 'searchFlights',
|
|
76
|
+
description: 'Search for available flights',
|
|
77
|
+
input: z.object({
|
|
78
|
+
from: z.string().describe('Departure airport code'),
|
|
79
|
+
to: z.string().describe('Arrival airport code'),
|
|
80
|
+
date: z.string().describe('Departure date (YYYY-MM-DD)'),
|
|
81
|
+
}),
|
|
82
|
+
output: SearchResultSchema,
|
|
83
|
+
execute: async (input) => realSearchFlights(input),
|
|
84
|
+
effects: (output) =>
|
|
85
|
+
output.flights.map((f) => ({
|
|
86
|
+
operation: 'create' as const,
|
|
87
|
+
collection: 'flights',
|
|
88
|
+
id: f.id,
|
|
89
|
+
data: f,
|
|
90
|
+
})),
|
|
91
|
+
});
|
|
92
|
+
```
|
|
93
|
+
|
|
94
|
+
Returns a callable function `(input) => Promise<output>`. During tests, calls are intercepted and simulated. Outside tests, `execute` is called directly.
|
|
95
|
+
|
|
96
|
+
| Option | Type | Description |
|
|
97
|
+
|--------|------|-------------|
|
|
98
|
+
| `name` | `string` | Tool name |
|
|
99
|
+
| `description` | `string` | Tool description |
|
|
100
|
+
| `input` | `ZodSchema` | Input schema |
|
|
101
|
+
| `output` | `ZodSchema` | Output schema |
|
|
102
|
+
| `execute` | `(input) => Promise<output>` | Real implementation |
|
|
103
|
+
| `effects` | `(output, world) => Effect[]` | Declare state changes from output |
|
|
104
|
+
| `invariants` | `Invariant[]` | Constraints to enforce |
|
|
105
|
+
|
|
93
106
|
### `wrap(tool, config)`
|
|
94
107
|
|
|
95
|
-
Wrap a LangChain tool for simulation
|
|
108
|
+
Wrap a LangChain tool for simulation. Extracts `name`, `description`, and `schema` automatically.
|
|
96
109
|
|
|
97
110
|
```typescript
|
|
98
111
|
import { wrap } from '@virtualkitchenco/multiverse-sdk';
|
|
@@ -102,9 +115,6 @@ const myTool = wrap(langchainTool, {
|
|
|
102
115
|
effects: (output, world) => [
|
|
103
116
|
{ operation: 'create', collection: 'orders', id: output.id, data: output },
|
|
104
117
|
],
|
|
105
|
-
invariants: [
|
|
106
|
-
{ collection: 'inventory', field: 'quantity', condition: 'gte', value: 0 },
|
|
107
|
-
],
|
|
108
118
|
});
|
|
109
119
|
```
|
|
110
120
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@virtualkitchenco/multiverse-sdk",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.18",
|
|
4
4
|
"description": "Simulated worlds for AI agents - 6 months production in 6 minutes",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
27
|
"nanoid": "^5.0.4",
|
|
28
|
-
"@virtualkitchenco/multiverse-types": "0.0.
|
|
28
|
+
"@virtualkitchenco/multiverse-types": "0.0.18"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
31
|
"@types/node": "^20.11.0",
|