@hazeljs/agent 0.2.0-beta.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/IMPLEMENTATION_SUMMARY.md +400 -0
- package/PERSISTENCE.md +201 -0
- package/PRISMA_INTEGRATION.md +499 -0
- package/PRODUCTION_READINESS.md +264 -0
- package/QUICKSTART.md +135 -0
- package/README.md +427 -0
- package/STATE_VS_MEMORY.md +243 -0
- package/dist/agent.module.d.ts +42 -0
- package/dist/agent.module.d.ts.map +1 -0
- package/dist/agent.module.js +90 -0
- package/dist/agent.module.js.map +1 -0
- package/dist/context/agent.context.d.ts +27 -0
- package/dist/context/agent.context.d.ts.map +1 -0
- package/dist/context/agent.context.js +98 -0
- package/dist/context/agent.context.js.map +1 -0
- package/dist/decorators/agent.decorator.d.ts +21 -0
- package/dist/decorators/agent.decorator.d.ts.map +1 -0
- package/dist/decorators/agent.decorator.js +38 -0
- package/dist/decorators/agent.decorator.js.map +1 -0
- package/dist/decorators/tool.decorator.d.ts +23 -0
- package/dist/decorators/tool.decorator.d.ts.map +1 -0
- package/dist/decorators/tool.decorator.js +61 -0
- package/dist/decorators/tool.decorator.js.map +1 -0
- package/dist/events/event.emitter.d.ts +45 -0
- package/dist/events/event.emitter.d.ts.map +1 -0
- package/dist/events/event.emitter.js +96 -0
- package/dist/events/event.emitter.js.map +1 -0
- package/dist/executor/agent.executor.d.ts +57 -0
- package/dist/executor/agent.executor.d.ts.map +1 -0
- package/dist/executor/agent.executor.js +303 -0
- package/dist/executor/agent.executor.js.map +1 -0
- package/dist/executor/tool.executor.d.ts +53 -0
- package/dist/executor/tool.executor.d.ts.map +1 -0
- package/dist/executor/tool.executor.js +234 -0
- package/dist/executor/tool.executor.js.map +1 -0
- package/dist/index.d.ts +30 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +46 -0
- package/dist/index.js.map +1 -0
- package/dist/registry/agent.registry.d.ts +49 -0
- package/dist/registry/agent.registry.d.ts.map +1 -0
- package/dist/registry/agent.registry.js +90 -0
- package/dist/registry/agent.registry.js.map +1 -0
- package/dist/registry/tool.registry.d.ts +54 -0
- package/dist/registry/tool.registry.d.ts.map +1 -0
- package/dist/registry/tool.registry.js +153 -0
- package/dist/registry/tool.registry.js.map +1 -0
- package/dist/runtime/agent.runtime.d.ts +155 -0
- package/dist/runtime/agent.runtime.d.ts.map +1 -0
- package/dist/runtime/agent.runtime.extensions.d.ts +49 -0
- package/dist/runtime/agent.runtime.extensions.d.ts.map +1 -0
- package/dist/runtime/agent.runtime.extensions.js +93 -0
- package/dist/runtime/agent.runtime.extensions.js.map +1 -0
- package/dist/runtime/agent.runtime.js +347 -0
- package/dist/runtime/agent.runtime.js.map +1 -0
- package/dist/state/agent-state.interface.d.ts +63 -0
- package/dist/state/agent-state.interface.d.ts.map +1 -0
- package/dist/state/agent-state.interface.js +7 -0
- package/dist/state/agent-state.interface.js.map +1 -0
- package/dist/state/agent.state.d.ts +67 -0
- package/dist/state/agent.state.d.ts.map +1 -0
- package/dist/state/agent.state.js +172 -0
- package/dist/state/agent.state.js.map +1 -0
- package/dist/state/database-state.manager.d.ts +63 -0
- package/dist/state/database-state.manager.d.ts.map +1 -0
- package/dist/state/database-state.manager.js +282 -0
- package/dist/state/database-state.manager.js.map +1 -0
- package/dist/state/redis-state.manager.d.ts +81 -0
- package/dist/state/redis-state.manager.d.ts.map +1 -0
- package/dist/state/redis-state.manager.js +253 -0
- package/dist/state/redis-state.manager.js.map +1 -0
- package/dist/types/agent.types.d.ts +151 -0
- package/dist/types/agent.types.d.ts.map +1 -0
- package/dist/types/agent.types.js +32 -0
- package/dist/types/agent.types.js.map +1 -0
- package/dist/types/event.types.d.ts +123 -0
- package/dist/types/event.types.d.ts.map +1 -0
- package/dist/types/event.types.js +30 -0
- package/dist/types/event.types.js.map +1 -0
- package/dist/types/llm.types.d.ts +66 -0
- package/dist/types/llm.types.d.ts.map +1 -0
- package/dist/types/llm.types.js +7 -0
- package/dist/types/llm.types.js.map +1 -0
- package/dist/types/rag.types.d.ts +40 -0
- package/dist/types/rag.types.d.ts.map +1 -0
- package/dist/types/rag.types.js +7 -0
- package/dist/types/rag.types.js.map +1 -0
- package/dist/types/tool.types.d.ts +118 -0
- package/dist/types/tool.types.d.ts.map +1 -0
- package/dist/types/tool.types.js +19 -0
- package/dist/types/tool.types.js.map +1 -0
- package/dist/utils/circuit-breaker.d.ts +69 -0
- package/dist/utils/circuit-breaker.d.ts.map +1 -0
- package/dist/utils/circuit-breaker.js +156 -0
- package/dist/utils/circuit-breaker.js.map +1 -0
- package/dist/utils/health-check.d.ts +71 -0
- package/dist/utils/health-check.d.ts.map +1 -0
- package/dist/utils/health-check.js +156 -0
- package/dist/utils/health-check.js.map +1 -0
- package/dist/utils/logger.d.ts +53 -0
- package/dist/utils/logger.d.ts.map +1 -0
- package/dist/utils/logger.js +133 -0
- package/dist/utils/logger.js.map +1 -0
- package/dist/utils/metrics.d.ts +90 -0
- package/dist/utils/metrics.d.ts.map +1 -0
- package/dist/utils/metrics.js +186 -0
- package/dist/utils/metrics.js.map +1 -0
- package/dist/utils/rate-limiter.d.ts +44 -0
- package/dist/utils/rate-limiter.d.ts.map +1 -0
- package/dist/utils/rate-limiter.js +82 -0
- package/dist/utils/rate-limiter.js.map +1 -0
- package/dist/utils/retry.d.ts +42 -0
- package/dist/utils/retry.d.ts.map +1 -0
- package/dist/utils/retry.js +103 -0
- package/dist/utils/retry.js.map +1 -0
- package/package.json +58 -0
- package/prisma-schema.example.prisma +76 -0
|
@@ -0,0 +1,499 @@
|
|
|
1
|
+
# Prisma Integration Guide
|
|
2
|
+
|
|
3
|
+
This guide shows you how to integrate the Agent State Persistence models into your existing Prisma schema.
|
|
4
|
+
|
|
5
|
+
## Quick Start
|
|
6
|
+
|
|
7
|
+
### Step 1: Add Models to Your Schema
|
|
8
|
+
|
|
9
|
+
Copy the models from `prisma-schema.example.prisma` into your existing `prisma/schema.prisma` file:
|
|
10
|
+
|
|
11
|
+
```prisma
|
|
12
|
+
// Your existing schema.prisma
|
|
13
|
+
generator client {
|
|
14
|
+
provider = "prisma-client-js"
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
datasource db {
|
|
18
|
+
provider = "postgresql" // or "mysql", "sqlite", etc.
|
|
19
|
+
url = env("DATABASE_URL")
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
// Your existing models...
|
|
23
|
+
model User {
|
|
24
|
+
id Int @id @default(autoincrement())
|
|
25
|
+
name String
|
|
26
|
+
email String @unique
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Add these Agent State models:
|
|
30
|
+
model AgentContext {
|
|
31
|
+
id String @id @default(uuid())
|
|
32
|
+
executionId String @unique
|
|
33
|
+
agentId String
|
|
34
|
+
sessionId String
|
|
35
|
+
userId String?
|
|
36
|
+
input String
|
|
37
|
+
state String // AgentState enum as string
|
|
38
|
+
steps Json // AgentStep[]
|
|
39
|
+
conversationHistory Json // ConversationMessage[]
|
|
40
|
+
workingMemory Json // Record<string, unknown>
|
|
41
|
+
facts Json // string[]
|
|
42
|
+
entities Json // Entity[]
|
|
43
|
+
ragContext Json? // string[]
|
|
44
|
+
metadata Json // Record<string, unknown>
|
|
45
|
+
createdAt DateTime @default(now())
|
|
46
|
+
updatedAt DateTime @updatedAt
|
|
47
|
+
deletedAt DateTime? // For soft deletes
|
|
48
|
+
agentSteps AgentStep[] // Relation to steps table (optional)
|
|
49
|
+
|
|
50
|
+
@@index([sessionId])
|
|
51
|
+
@@index([userId])
|
|
52
|
+
@@index([agentId])
|
|
53
|
+
@@index([state])
|
|
54
|
+
@@index([createdAt])
|
|
55
|
+
@@index([deletedAt])
|
|
56
|
+
@@map("agent_contexts")
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
// Optional: Separate table for execution steps (for better querying)
|
|
60
|
+
model AgentStep {
|
|
61
|
+
id String @id @default(uuid())
|
|
62
|
+
executionId String
|
|
63
|
+
stepNumber Int
|
|
64
|
+
state String
|
|
65
|
+
action Json?
|
|
66
|
+
result Json?
|
|
67
|
+
error String?
|
|
68
|
+
timestamp DateTime @default(now())
|
|
69
|
+
duration Int?
|
|
70
|
+
|
|
71
|
+
context AgentContext @relation(fields: [executionId], references: [executionId], onDelete: Cascade)
|
|
72
|
+
|
|
73
|
+
@@index([executionId])
|
|
74
|
+
@@index([timestamp])
|
|
75
|
+
@@map("agent_steps")
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Optional: Session tracking
|
|
79
|
+
model AgentSession {
|
|
80
|
+
id String @id @default(uuid())
|
|
81
|
+
sessionId String @unique
|
|
82
|
+
userId String?
|
|
83
|
+
agentId String
|
|
84
|
+
createdAt DateTime @default(now())
|
|
85
|
+
updatedAt DateTime @updatedAt
|
|
86
|
+
completedAt DateTime?
|
|
87
|
+
|
|
88
|
+
@@index([userId])
|
|
89
|
+
@@index([agentId])
|
|
90
|
+
@@index([createdAt])
|
|
91
|
+
@@map("agent_sessions")
|
|
92
|
+
}
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
### Step 2: Create Migration
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
# Create a new migration
|
|
99
|
+
npx prisma migrate dev --name add_agent_state_models
|
|
100
|
+
|
|
101
|
+
# Or if using migrate manually
|
|
102
|
+
npx prisma migrate dev
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
### Step 3: Generate Prisma Client
|
|
106
|
+
|
|
107
|
+
```bash
|
|
108
|
+
npx prisma generate
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Step 4: Use in Your Code
|
|
112
|
+
|
|
113
|
+
```typescript
|
|
114
|
+
import { AgentRuntime, DatabaseStateManager } from '@hazeljs/agent';
|
|
115
|
+
import { PrismaClient } from '@prisma/client';
|
|
116
|
+
|
|
117
|
+
const prisma = new PrismaClient();
|
|
118
|
+
|
|
119
|
+
const stateManager = new DatabaseStateManager({
|
|
120
|
+
client: prisma,
|
|
121
|
+
softDelete: true,
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
const runtime = new AgentRuntime({
|
|
125
|
+
stateManager,
|
|
126
|
+
});
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
## Integration Options
|
|
130
|
+
|
|
131
|
+
### Option 1: Minimal (Recommended)
|
|
132
|
+
|
|
133
|
+
Add only the `AgentContext` model. Steps are stored as JSON in the context:
|
|
134
|
+
|
|
135
|
+
```prisma
|
|
136
|
+
model AgentContext {
|
|
137
|
+
id String @id @default(uuid())
|
|
138
|
+
executionId String @unique
|
|
139
|
+
agentId String
|
|
140
|
+
sessionId String
|
|
141
|
+
userId String?
|
|
142
|
+
input String
|
|
143
|
+
state String
|
|
144
|
+
steps Json // All steps stored here
|
|
145
|
+
conversationHistory Json
|
|
146
|
+
workingMemory Json
|
|
147
|
+
facts Json
|
|
148
|
+
entities Json
|
|
149
|
+
ragContext Json?
|
|
150
|
+
metadata Json
|
|
151
|
+
createdAt DateTime @default(now())
|
|
152
|
+
updatedAt DateTime @updatedAt
|
|
153
|
+
deletedAt DateTime?
|
|
154
|
+
|
|
155
|
+
@@index([sessionId])
|
|
156
|
+
@@index([userId])
|
|
157
|
+
@@index([agentId])
|
|
158
|
+
@@index([state])
|
|
159
|
+
@@map("agent_contexts")
|
|
160
|
+
}
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
**Pros**: Simple, single table, fast writes
|
|
164
|
+
**Cons**: Can't query steps independently
|
|
165
|
+
|
|
166
|
+
### Option 2: Full (For Analytics)
|
|
167
|
+
|
|
168
|
+
Add all three models (`AgentContext`, `AgentStep`, `AgentSession`) for better querying:
|
|
169
|
+
|
|
170
|
+
```prisma
|
|
171
|
+
model AgentContext {
|
|
172
|
+
// ... fields ...
|
|
173
|
+
agentSteps AgentStep[] // Relation
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
model AgentStep {
|
|
177
|
+
// ... fields ...
|
|
178
|
+
context AgentContext @relation(...)
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
model AgentSession {
|
|
182
|
+
// ... fields ...
|
|
183
|
+
}
|
|
184
|
+
```
|
|
185
|
+
|
|
186
|
+
**Pros**: Can query steps independently, better for analytics
|
|
187
|
+
**Cons**: More complex, requires joins
|
|
188
|
+
|
|
189
|
+
### Option 3: Custom Schema
|
|
190
|
+
|
|
191
|
+
Adapt the schema to your needs:
|
|
192
|
+
|
|
193
|
+
```prisma
|
|
194
|
+
// Example: Add relation to your User model
|
|
195
|
+
model User {
|
|
196
|
+
id Int @id @default(autoincrement())
|
|
197
|
+
name String
|
|
198
|
+
email String @unique
|
|
199
|
+
agentContexts AgentContext[] // Add this
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
model AgentContext {
|
|
203
|
+
// ... fields ...
|
|
204
|
+
userId String?
|
|
205
|
+
user User? @relation(fields: [userId], references: [id]) // Add this
|
|
206
|
+
}
|
|
207
|
+
```
|
|
208
|
+
|
|
209
|
+
## Database Compatibility
|
|
210
|
+
|
|
211
|
+
### PostgreSQL (Recommended)
|
|
212
|
+
|
|
213
|
+
```prisma
|
|
214
|
+
datasource db {
|
|
215
|
+
provider = "postgresql"
|
|
216
|
+
url = env("DATABASE_URL")
|
|
217
|
+
}
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
✅ Full support for JSON fields
|
|
221
|
+
✅ Excellent indexing
|
|
222
|
+
✅ Best performance
|
|
223
|
+
|
|
224
|
+
### MySQL
|
|
225
|
+
|
|
226
|
+
```prisma
|
|
227
|
+
datasource db {
|
|
228
|
+
provider = "mysql"
|
|
229
|
+
url = env("DATABASE_URL")
|
|
230
|
+
}
|
|
231
|
+
```
|
|
232
|
+
|
|
233
|
+
✅ JSON support (MySQL 5.7+)
|
|
234
|
+
✅ Good performance
|
|
235
|
+
⚠️ Use `Json` type for JSON fields
|
|
236
|
+
|
|
237
|
+
### SQLite
|
|
238
|
+
|
|
239
|
+
```prisma
|
|
240
|
+
datasource db {
|
|
241
|
+
provider = "sqlite"
|
|
242
|
+
url = env("DATABASE_URL")
|
|
243
|
+
}
|
|
244
|
+
```
|
|
245
|
+
|
|
246
|
+
✅ Works for development
|
|
247
|
+
⚠️ JSON stored as TEXT (slower queries)
|
|
248
|
+
⚠️ Not recommended for production
|
|
249
|
+
|
|
250
|
+
### SQL Server
|
|
251
|
+
|
|
252
|
+
```prisma
|
|
253
|
+
datasource db {
|
|
254
|
+
provider = "sqlserver"
|
|
255
|
+
url = env("DATABASE_URL")
|
|
256
|
+
}
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
✅ JSON support (SQL Server 2016+)
|
|
260
|
+
✅ Good for enterprise
|
|
261
|
+
|
|
262
|
+
## Migration Examples
|
|
263
|
+
|
|
264
|
+
### Initial Migration
|
|
265
|
+
|
|
266
|
+
```bash
|
|
267
|
+
# Create migration
|
|
268
|
+
npx prisma migrate dev --name add_agent_state_models
|
|
269
|
+
|
|
270
|
+
# This will create:
|
|
271
|
+
# - agent_contexts table
|
|
272
|
+
# - agent_steps table (if included)
|
|
273
|
+
# - agent_sessions table (if included)
|
|
274
|
+
# - All indexes
|
|
275
|
+
```
|
|
276
|
+
|
|
277
|
+
### Adding to Existing Database
|
|
278
|
+
|
|
279
|
+
If you already have a database with other tables:
|
|
280
|
+
|
|
281
|
+
```bash
|
|
282
|
+
# Prisma will detect the new models
|
|
283
|
+
npx prisma migrate dev --name add_agent_state
|
|
284
|
+
|
|
285
|
+
# Review the migration SQL before applying
|
|
286
|
+
npx prisma migrate dev --create-only
|
|
287
|
+
# Edit the migration file if needed
|
|
288
|
+
npx prisma migrate dev
|
|
289
|
+
```
|
|
290
|
+
|
|
291
|
+
## Schema Customization
|
|
292
|
+
|
|
293
|
+
### Customize Field Types
|
|
294
|
+
|
|
295
|
+
```prisma
|
|
296
|
+
model AgentContext {
|
|
297
|
+
// Use your own ID format
|
|
298
|
+
id String @id @default(cuid()) // or @default(uuid())
|
|
299
|
+
|
|
300
|
+
// Add custom fields
|
|
301
|
+
priority Int @default(0)
|
|
302
|
+
tags String[]
|
|
303
|
+
|
|
304
|
+
// Customize JSON fields
|
|
305
|
+
metadata Json @default("{}")
|
|
306
|
+
}
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
### Add Relations
|
|
310
|
+
|
|
311
|
+
```prisma
|
|
312
|
+
model User {
|
|
313
|
+
id Int @id @default(autoincrement())
|
|
314
|
+
agentContexts AgentContext[]
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
model AgentContext {
|
|
318
|
+
userId String?
|
|
319
|
+
user User? @relation(fields: [userId], references: [id])
|
|
320
|
+
}
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
### Custom Indexes
|
|
324
|
+
|
|
325
|
+
```prisma
|
|
326
|
+
model AgentContext {
|
|
327
|
+
// ... fields ...
|
|
328
|
+
|
|
329
|
+
// Add composite indexes
|
|
330
|
+
@@index([agentId, state])
|
|
331
|
+
@@index([sessionId, createdAt])
|
|
332
|
+
|
|
333
|
+
// Add full-text search (PostgreSQL)
|
|
334
|
+
@@index([input(ops: Raw("gin_trgm_ops"))])
|
|
335
|
+
}
|
|
336
|
+
```
|
|
337
|
+
|
|
338
|
+
## Using with HazelJS Prisma Module
|
|
339
|
+
|
|
340
|
+
If you're using `@hazeljs/prisma`:
|
|
341
|
+
|
|
342
|
+
```typescript
|
|
343
|
+
import { HazelModule } from '@hazeljs/core';
|
|
344
|
+
import { PrismaModule } from '@hazeljs/prisma';
|
|
345
|
+
import { AgentModule } from '@hazeljs/agent';
|
|
346
|
+
import { PrismaClient } from '@prisma/client';
|
|
347
|
+
import { DatabaseStateManager } from '@hazeljs/agent';
|
|
348
|
+
|
|
349
|
+
@HazelModule({
|
|
350
|
+
imports: [
|
|
351
|
+
PrismaModule.forRoot({
|
|
352
|
+
// Your Prisma config
|
|
353
|
+
}),
|
|
354
|
+
AgentModule.forRoot({
|
|
355
|
+
// Agent config
|
|
356
|
+
}),
|
|
357
|
+
],
|
|
358
|
+
})
|
|
359
|
+
export class AppModule {
|
|
360
|
+
constructor(private prisma: PrismaClient) {
|
|
361
|
+
// Create state manager
|
|
362
|
+
const stateManager = new DatabaseStateManager({
|
|
363
|
+
client: this.prisma,
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
// Use with AgentRuntime
|
|
367
|
+
// (configure in your agent service)
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
```
|
|
371
|
+
|
|
372
|
+
## Troubleshooting
|
|
373
|
+
|
|
374
|
+
### Error: "Model AgentContext not found"
|
|
375
|
+
|
|
376
|
+
**Solution**: Make sure you've:
|
|
377
|
+
1. Added the model to your schema
|
|
378
|
+
2. Run `npx prisma generate`
|
|
379
|
+
3. Restarted your application
|
|
380
|
+
|
|
381
|
+
### Error: "Column does not exist"
|
|
382
|
+
|
|
383
|
+
**Solution**: Run migrations:
|
|
384
|
+
```bash
|
|
385
|
+
npx prisma migrate dev
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
### JSON Field Issues
|
|
389
|
+
|
|
390
|
+
**PostgreSQL**: Use `Json` type (works out of the box)
|
|
391
|
+
**MySQL**: Use `Json` type (MySQL 5.7+)
|
|
392
|
+
**SQLite**: Use `String` type and parse manually, or use `Json` (stored as TEXT)
|
|
393
|
+
|
|
394
|
+
### Performance Issues
|
|
395
|
+
|
|
396
|
+
1. **Add indexes** on frequently queried fields:
|
|
397
|
+
```prisma
|
|
398
|
+
@@index([sessionId])
|
|
399
|
+
@@index([userId])
|
|
400
|
+
@@index([state])
|
|
401
|
+
```
|
|
402
|
+
|
|
403
|
+
2. **Use soft deletes** to avoid expensive DELETE operations:
|
|
404
|
+
```prisma
|
|
405
|
+
deletedAt DateTime?
|
|
406
|
+
@@index([deletedAt])
|
|
407
|
+
```
|
|
408
|
+
|
|
409
|
+
3. **Partition large tables** (PostgreSQL):
|
|
410
|
+
```sql
|
|
411
|
+
-- Partition by date for very large tables
|
|
412
|
+
CREATE TABLE agent_contexts_2024_12 PARTITION OF agent_contexts
|
|
413
|
+
FOR VALUES FROM ('2024-12-01') TO ('2025-01-01');
|
|
414
|
+
```
|
|
415
|
+
|
|
416
|
+
## Example: Complete Integration
|
|
417
|
+
|
|
418
|
+
```prisma
|
|
419
|
+
// prisma/schema.prisma
|
|
420
|
+
generator client {
|
|
421
|
+
provider = "prisma-client-js"
|
|
422
|
+
}
|
|
423
|
+
|
|
424
|
+
datasource db {
|
|
425
|
+
provider = "postgresql"
|
|
426
|
+
url = env("DATABASE_URL")
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
// Your existing models
|
|
430
|
+
model User {
|
|
431
|
+
id Int @id @default(autoincrement())
|
|
432
|
+
email String @unique
|
|
433
|
+
name String
|
|
434
|
+
agentContexts AgentContext[] // Relation
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
// Agent State models
|
|
438
|
+
model AgentContext {
|
|
439
|
+
id String @id @default(uuid())
|
|
440
|
+
executionId String @unique
|
|
441
|
+
agentId String
|
|
442
|
+
sessionId String
|
|
443
|
+
userId String?
|
|
444
|
+
user User? @relation(fields: [userId], references: [id])
|
|
445
|
+
input String
|
|
446
|
+
state String
|
|
447
|
+
steps Json
|
|
448
|
+
conversationHistory Json
|
|
449
|
+
workingMemory Json
|
|
450
|
+
facts Json
|
|
451
|
+
entities Json
|
|
452
|
+
ragContext Json?
|
|
453
|
+
metadata Json
|
|
454
|
+
createdAt DateTime @default(now())
|
|
455
|
+
updatedAt DateTime @updatedAt
|
|
456
|
+
deletedAt DateTime?
|
|
457
|
+
|
|
458
|
+
@@index([sessionId])
|
|
459
|
+
@@index([userId])
|
|
460
|
+
@@index([agentId])
|
|
461
|
+
@@index([state])
|
|
462
|
+
@@index([createdAt])
|
|
463
|
+
@@map("agent_contexts")
|
|
464
|
+
}
|
|
465
|
+
```
|
|
466
|
+
|
|
467
|
+
```typescript
|
|
468
|
+
// app.module.ts
|
|
469
|
+
import { HazelModule } from '@hazeljs/core';
|
|
470
|
+
import { PrismaModule } from '@hazeljs/prisma';
|
|
471
|
+
import { AgentModule } from '@hazeljs/agent';
|
|
472
|
+
import { DatabaseStateManager } from '@hazeljs/agent';
|
|
473
|
+
|
|
474
|
+
@HazelModule({
|
|
475
|
+
imports: [
|
|
476
|
+
PrismaModule.forRoot({}),
|
|
477
|
+
AgentModule.forRoot({
|
|
478
|
+
stateManager: new DatabaseStateManager({
|
|
479
|
+
client: prismaClient, // From PrismaModule
|
|
480
|
+
softDelete: true,
|
|
481
|
+
}),
|
|
482
|
+
}),
|
|
483
|
+
],
|
|
484
|
+
})
|
|
485
|
+
export class AppModule {}
|
|
486
|
+
```
|
|
487
|
+
|
|
488
|
+
## Next Steps
|
|
489
|
+
|
|
490
|
+
1. ✅ Add models to your schema
|
|
491
|
+
2. ✅ Run migrations
|
|
492
|
+
3. ✅ Generate Prisma client
|
|
493
|
+
4. ✅ Configure DatabaseStateManager
|
|
494
|
+
5. ✅ Test with your agents
|
|
495
|
+
|
|
496
|
+
For more details, see:
|
|
497
|
+
- [PERSISTENCE.md](./PERSISTENCE.md) - Configuration guide
|
|
498
|
+
- [STATE_VS_MEMORY.md](./STATE_VS_MEMORY.md) - Understanding State vs Memory
|
|
499
|
+
- [prisma-schema.example.prisma](./prisma-schema.example.prisma) - Full schema example
|