autonomous-agents 0.1.0 → 2.0.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/.turbo/turbo-build.log +5 -0
- package/CHANGELOG.md +9 -0
- package/README.md +260 -96
- package/dist/actions.d.ts +136 -0
- package/dist/actions.d.ts.map +1 -0
- package/dist/actions.js +303 -0
- package/dist/actions.js.map +1 -0
- package/dist/agent.d.ts +49 -0
- package/dist/agent.d.ts.map +1 -0
- package/dist/agent.js +452 -0
- package/dist/agent.js.map +1 -0
- package/dist/goals.d.ts +138 -0
- package/dist/goals.d.ts.map +1 -0
- package/dist/goals.js +342 -0
- package/dist/goals.js.map +1 -0
- package/dist/index.d.ts +55 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +60 -0
- package/dist/index.js.map +1 -0
- package/dist/metrics.d.ts +245 -0
- package/dist/metrics.d.ts.map +1 -0
- package/dist/metrics.js +436 -0
- package/dist/metrics.js.map +1 -0
- package/dist/role.d.ts +122 -0
- package/dist/role.d.ts.map +1 -0
- package/dist/role.js +393 -0
- package/dist/role.js.map +1 -0
- package/dist/team.d.ts +152 -0
- package/dist/team.d.ts.map +1 -0
- package/dist/team.js +347 -0
- package/dist/team.js.map +1 -0
- package/dist/types.d.ts +327 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +8 -0
- package/dist/types.js.map +1 -0
- package/package.json +27 -36
- package/src/actions.ts +366 -0
- package/src/agent.ts +548 -0
- package/src/goals.ts +435 -0
- package/src/index.ts +135 -0
- package/src/metrics.ts +591 -0
- package/src/role.ts +422 -0
- package/src/team.ts +466 -0
- package/src/types.ts +356 -0
- package/test/actions.test.ts +522 -0
- package/test/agent.test.ts +490 -0
- package/test/goals.test.ts +570 -0
- package/test/metrics.test.ts +707 -0
- package/test/role.test.ts +423 -0
- package/test/team.test.ts +708 -0
- package/tsconfig.json +9 -0
|
@@ -0,0 +1,490 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for Agent functionality
|
|
3
|
+
*
|
|
4
|
+
* Covers agent creation, state management, and configuration.
|
|
5
|
+
* Note: AI-dependent functions are tested with mocks.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
9
|
+
import { Agent, Role } from '../src/index.js'
|
|
10
|
+
|
|
11
|
+
// Mock the ai-functions module
|
|
12
|
+
vi.mock('ai-functions', () => ({
|
|
13
|
+
generateObject: vi.fn().mockResolvedValue({
|
|
14
|
+
object: { result: 'mocked result' },
|
|
15
|
+
}),
|
|
16
|
+
}))
|
|
17
|
+
|
|
18
|
+
describe('Agent', () => {
|
|
19
|
+
describe('Agent creation', () => {
|
|
20
|
+
it('creates an agent with basic config', () => {
|
|
21
|
+
const role = Role({
|
|
22
|
+
name: 'Assistant',
|
|
23
|
+
description: 'General assistant',
|
|
24
|
+
skills: ['helping'],
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
const agent = Agent({
|
|
28
|
+
name: 'TestAgent',
|
|
29
|
+
role,
|
|
30
|
+
})
|
|
31
|
+
|
|
32
|
+
expect(agent.config.name).toBe('TestAgent')
|
|
33
|
+
expect(agent.config.role.name).toBe('Assistant')
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
it('creates an agent with goals', () => {
|
|
37
|
+
const role = Role({
|
|
38
|
+
name: 'Assistant',
|
|
39
|
+
description: 'General assistant',
|
|
40
|
+
skills: ['helping'],
|
|
41
|
+
})
|
|
42
|
+
|
|
43
|
+
const agent = Agent({
|
|
44
|
+
name: 'TestAgent',
|
|
45
|
+
role,
|
|
46
|
+
goals: [
|
|
47
|
+
{ id: 'g1', description: 'Help users', target: '100%' },
|
|
48
|
+
{ id: 'g2', description: 'Be accurate', target: '100%' },
|
|
49
|
+
],
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
expect(agent.config.goals).toHaveLength(2)
|
|
53
|
+
})
|
|
54
|
+
|
|
55
|
+
it('creates an agent with context', () => {
|
|
56
|
+
const role = Role({
|
|
57
|
+
name: 'Assistant',
|
|
58
|
+
description: 'General assistant',
|
|
59
|
+
skills: ['helping'],
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
const agent = Agent({
|
|
63
|
+
name: 'TestAgent',
|
|
64
|
+
role,
|
|
65
|
+
context: { project: 'technical' },
|
|
66
|
+
})
|
|
67
|
+
|
|
68
|
+
expect(agent.config.context).toEqual({ project: 'technical' })
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
it('creates an agent with default mode (not autonomous)', () => {
|
|
72
|
+
const role = Role({
|
|
73
|
+
name: 'Assistant',
|
|
74
|
+
description: 'General assistant',
|
|
75
|
+
skills: ['helping'],
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
const agent = Agent({
|
|
79
|
+
name: 'TestAgent',
|
|
80
|
+
role,
|
|
81
|
+
})
|
|
82
|
+
|
|
83
|
+
expect(agent.config.mode).toBeUndefined()
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
it('creates an agent with autonomous mode', () => {
|
|
87
|
+
const role = Role({
|
|
88
|
+
name: 'Assistant',
|
|
89
|
+
description: 'General assistant',
|
|
90
|
+
skills: ['helping'],
|
|
91
|
+
})
|
|
92
|
+
|
|
93
|
+
const agent = Agent({
|
|
94
|
+
name: 'TestAgent',
|
|
95
|
+
role,
|
|
96
|
+
mode: 'autonomous',
|
|
97
|
+
})
|
|
98
|
+
|
|
99
|
+
expect(agent.config.mode).toBe('autonomous')
|
|
100
|
+
})
|
|
101
|
+
|
|
102
|
+
it('creates an agent with model config', () => {
|
|
103
|
+
const role = Role({
|
|
104
|
+
name: 'Assistant',
|
|
105
|
+
description: 'General assistant',
|
|
106
|
+
skills: ['helping'],
|
|
107
|
+
})
|
|
108
|
+
|
|
109
|
+
const agent = Agent({
|
|
110
|
+
name: 'TestAgent',
|
|
111
|
+
role,
|
|
112
|
+
model: 'opus',
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
expect(agent.config.model).toBe('opus')
|
|
116
|
+
})
|
|
117
|
+
})
|
|
118
|
+
|
|
119
|
+
describe('Agent state management', () => {
|
|
120
|
+
it('sets and gets state', () => {
|
|
121
|
+
const role = Role({
|
|
122
|
+
name: 'Assistant',
|
|
123
|
+
description: 'General assistant',
|
|
124
|
+
skills: ['helping'],
|
|
125
|
+
})
|
|
126
|
+
|
|
127
|
+
const agent = Agent({
|
|
128
|
+
name: 'TestAgent',
|
|
129
|
+
role,
|
|
130
|
+
})
|
|
131
|
+
|
|
132
|
+
agent.setState('task', 'processing')
|
|
133
|
+
|
|
134
|
+
expect(agent.getState('task')).toBe('processing')
|
|
135
|
+
})
|
|
136
|
+
|
|
137
|
+
it('handles multiple state keys', () => {
|
|
138
|
+
const role = Role({
|
|
139
|
+
name: 'Assistant',
|
|
140
|
+
description: 'General assistant',
|
|
141
|
+
skills: ['helping'],
|
|
142
|
+
})
|
|
143
|
+
|
|
144
|
+
const agent = Agent({
|
|
145
|
+
name: 'TestAgent',
|
|
146
|
+
role,
|
|
147
|
+
})
|
|
148
|
+
|
|
149
|
+
agent.setState('count', 1)
|
|
150
|
+
agent.setState('name', 'test')
|
|
151
|
+
|
|
152
|
+
expect(agent.getState('count')).toBe(1)
|
|
153
|
+
expect(agent.getState('name')).toBe('test')
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
it('resets agent state', () => {
|
|
157
|
+
const role = Role({
|
|
158
|
+
name: 'Assistant',
|
|
159
|
+
description: 'General assistant',
|
|
160
|
+
skills: ['helping'],
|
|
161
|
+
})
|
|
162
|
+
|
|
163
|
+
const agent = Agent({
|
|
164
|
+
name: 'TestAgent',
|
|
165
|
+
role,
|
|
166
|
+
})
|
|
167
|
+
|
|
168
|
+
agent.setState('data', 'value')
|
|
169
|
+
agent.reset()
|
|
170
|
+
|
|
171
|
+
expect(agent.getState('data')).toBeUndefined()
|
|
172
|
+
})
|
|
173
|
+
|
|
174
|
+
it('tracks history', () => {
|
|
175
|
+
const role = Role({
|
|
176
|
+
name: 'Assistant',
|
|
177
|
+
description: 'General assistant',
|
|
178
|
+
skills: ['helping'],
|
|
179
|
+
})
|
|
180
|
+
|
|
181
|
+
const agent = Agent({
|
|
182
|
+
name: 'TestAgent',
|
|
183
|
+
role,
|
|
184
|
+
})
|
|
185
|
+
|
|
186
|
+
const history = agent.getHistory()
|
|
187
|
+
|
|
188
|
+
expect(Array.isArray(history)).toBe(true)
|
|
189
|
+
})
|
|
190
|
+
|
|
191
|
+
it('clears history on reset', () => {
|
|
192
|
+
const role = Role({
|
|
193
|
+
name: 'Assistant',
|
|
194
|
+
description: 'General assistant',
|
|
195
|
+
skills: ['helping'],
|
|
196
|
+
})
|
|
197
|
+
|
|
198
|
+
const agent = Agent({
|
|
199
|
+
name: 'TestAgent',
|
|
200
|
+
role,
|
|
201
|
+
})
|
|
202
|
+
|
|
203
|
+
agent.reset()
|
|
204
|
+
|
|
205
|
+
expect(agent.getHistory()).toHaveLength(0)
|
|
206
|
+
})
|
|
207
|
+
})
|
|
208
|
+
|
|
209
|
+
describe('Agent methods exist', () => {
|
|
210
|
+
it('has do method', () => {
|
|
211
|
+
const role = Role({
|
|
212
|
+
name: 'Assistant',
|
|
213
|
+
description: 'General assistant',
|
|
214
|
+
skills: ['helping'],
|
|
215
|
+
})
|
|
216
|
+
|
|
217
|
+
const agent = Agent({
|
|
218
|
+
name: 'TestAgent',
|
|
219
|
+
role,
|
|
220
|
+
})
|
|
221
|
+
|
|
222
|
+
expect(typeof agent.do).toBe('function')
|
|
223
|
+
})
|
|
224
|
+
|
|
225
|
+
it('has ask method', () => {
|
|
226
|
+
const role = Role({
|
|
227
|
+
name: 'Assistant',
|
|
228
|
+
description: 'General assistant',
|
|
229
|
+
skills: ['helping'],
|
|
230
|
+
})
|
|
231
|
+
|
|
232
|
+
const agent = Agent({
|
|
233
|
+
name: 'TestAgent',
|
|
234
|
+
role,
|
|
235
|
+
})
|
|
236
|
+
|
|
237
|
+
expect(typeof agent.ask).toBe('function')
|
|
238
|
+
})
|
|
239
|
+
|
|
240
|
+
it('has decide method', () => {
|
|
241
|
+
const role = Role({
|
|
242
|
+
name: 'Assistant',
|
|
243
|
+
description: 'General assistant',
|
|
244
|
+
skills: ['helping'],
|
|
245
|
+
})
|
|
246
|
+
|
|
247
|
+
const agent = Agent({
|
|
248
|
+
name: 'TestAgent',
|
|
249
|
+
role,
|
|
250
|
+
})
|
|
251
|
+
|
|
252
|
+
expect(typeof agent.decide).toBe('function')
|
|
253
|
+
})
|
|
254
|
+
|
|
255
|
+
it('has approve method', () => {
|
|
256
|
+
const role = Role({
|
|
257
|
+
name: 'Assistant',
|
|
258
|
+
description: 'General assistant',
|
|
259
|
+
skills: ['helping'],
|
|
260
|
+
})
|
|
261
|
+
|
|
262
|
+
const agent = Agent({
|
|
263
|
+
name: 'TestAgent',
|
|
264
|
+
role,
|
|
265
|
+
})
|
|
266
|
+
|
|
267
|
+
expect(typeof agent.approve).toBe('function')
|
|
268
|
+
})
|
|
269
|
+
|
|
270
|
+
it('has generate method', () => {
|
|
271
|
+
const role = Role({
|
|
272
|
+
name: 'Assistant',
|
|
273
|
+
description: 'General assistant',
|
|
274
|
+
skills: ['helping'],
|
|
275
|
+
})
|
|
276
|
+
|
|
277
|
+
const agent = Agent({
|
|
278
|
+
name: 'TestAgent',
|
|
279
|
+
role,
|
|
280
|
+
})
|
|
281
|
+
|
|
282
|
+
expect(typeof agent.generate).toBe('function')
|
|
283
|
+
})
|
|
284
|
+
|
|
285
|
+
it('has is method', () => {
|
|
286
|
+
const role = Role({
|
|
287
|
+
name: 'Assistant',
|
|
288
|
+
description: 'General assistant',
|
|
289
|
+
skills: ['helping'],
|
|
290
|
+
})
|
|
291
|
+
|
|
292
|
+
const agent = Agent({
|
|
293
|
+
name: 'TestAgent',
|
|
294
|
+
role,
|
|
295
|
+
})
|
|
296
|
+
|
|
297
|
+
expect(typeof agent.is).toBe('function')
|
|
298
|
+
})
|
|
299
|
+
|
|
300
|
+
it('has notify method', () => {
|
|
301
|
+
const role = Role({
|
|
302
|
+
name: 'Assistant',
|
|
303
|
+
description: 'General assistant',
|
|
304
|
+
skills: ['helping'],
|
|
305
|
+
})
|
|
306
|
+
|
|
307
|
+
const agent = Agent({
|
|
308
|
+
name: 'TestAgent',
|
|
309
|
+
role,
|
|
310
|
+
})
|
|
311
|
+
|
|
312
|
+
expect(typeof agent.notify).toBe('function')
|
|
313
|
+
})
|
|
314
|
+
})
|
|
315
|
+
|
|
316
|
+
describe('Agent configuration', () => {
|
|
317
|
+
it('uses role permissions', () => {
|
|
318
|
+
const role = Role({
|
|
319
|
+
name: 'Admin',
|
|
320
|
+
description: 'Administrator',
|
|
321
|
+
skills: ['admin'],
|
|
322
|
+
permissions: ['read', 'write', 'admin'],
|
|
323
|
+
})
|
|
324
|
+
|
|
325
|
+
const agent = Agent({
|
|
326
|
+
name: 'AdminAgent',
|
|
327
|
+
role,
|
|
328
|
+
})
|
|
329
|
+
|
|
330
|
+
expect(agent.config.role.permissions).toContain('admin')
|
|
331
|
+
})
|
|
332
|
+
|
|
333
|
+
it('uses role skills', () => {
|
|
334
|
+
const role = Role({
|
|
335
|
+
name: 'Developer',
|
|
336
|
+
description: 'Software developer',
|
|
337
|
+
skills: ['typescript', 'javascript'],
|
|
338
|
+
})
|
|
339
|
+
|
|
340
|
+
const agent = Agent({
|
|
341
|
+
name: 'DevAgent',
|
|
342
|
+
role,
|
|
343
|
+
})
|
|
344
|
+
|
|
345
|
+
expect(agent.config.role.skills).toContain('typescript')
|
|
346
|
+
})
|
|
347
|
+
|
|
348
|
+
it('accepts temperature setting', () => {
|
|
349
|
+
const role = Role({
|
|
350
|
+
name: 'Assistant',
|
|
351
|
+
description: 'General assistant',
|
|
352
|
+
skills: ['helping'],
|
|
353
|
+
})
|
|
354
|
+
|
|
355
|
+
const agent = Agent({
|
|
356
|
+
name: 'TestAgent',
|
|
357
|
+
role,
|
|
358
|
+
temperature: 0.5,
|
|
359
|
+
})
|
|
360
|
+
|
|
361
|
+
expect(agent.config.temperature).toBe(0.5)
|
|
362
|
+
})
|
|
363
|
+
|
|
364
|
+
it('accepts requiresApproval setting', () => {
|
|
365
|
+
const role = Role({
|
|
366
|
+
name: 'Assistant',
|
|
367
|
+
description: 'General assistant',
|
|
368
|
+
skills: ['helping'],
|
|
369
|
+
})
|
|
370
|
+
|
|
371
|
+
const agent = Agent({
|
|
372
|
+
name: 'TestAgent',
|
|
373
|
+
role,
|
|
374
|
+
requiresApproval: true,
|
|
375
|
+
})
|
|
376
|
+
|
|
377
|
+
expect(agent.config.requiresApproval).toBe(true)
|
|
378
|
+
})
|
|
379
|
+
})
|
|
380
|
+
|
|
381
|
+
describe('Agent with initial context', () => {
|
|
382
|
+
it('accepts initial context', () => {
|
|
383
|
+
const role = Role({
|
|
384
|
+
name: 'Assistant',
|
|
385
|
+
description: 'General assistant',
|
|
386
|
+
skills: ['helping'],
|
|
387
|
+
})
|
|
388
|
+
|
|
389
|
+
const agent = Agent({
|
|
390
|
+
name: 'TestAgent',
|
|
391
|
+
role,
|
|
392
|
+
context: {
|
|
393
|
+
counter: 0,
|
|
394
|
+
messages: [],
|
|
395
|
+
},
|
|
396
|
+
})
|
|
397
|
+
|
|
398
|
+
// Context is used as initial state
|
|
399
|
+
expect(agent.getState('counter')).toBe(0)
|
|
400
|
+
expect(agent.getState('messages')).toEqual([])
|
|
401
|
+
})
|
|
402
|
+
})
|
|
403
|
+
|
|
404
|
+
describe('Agent status', () => {
|
|
405
|
+
it('has default idle status', () => {
|
|
406
|
+
const role = Role({
|
|
407
|
+
name: 'Assistant',
|
|
408
|
+
description: 'General assistant',
|
|
409
|
+
skills: ['helping'],
|
|
410
|
+
})
|
|
411
|
+
|
|
412
|
+
const agent = Agent({
|
|
413
|
+
name: 'TestAgent',
|
|
414
|
+
role,
|
|
415
|
+
})
|
|
416
|
+
|
|
417
|
+
expect(agent.status).toBe('idle')
|
|
418
|
+
})
|
|
419
|
+
})
|
|
420
|
+
})
|
|
421
|
+
|
|
422
|
+
describe('Agent integration scenarios', () => {
|
|
423
|
+
it('creates a product manager agent', () => {
|
|
424
|
+
const role = Role({
|
|
425
|
+
name: 'Product Manager',
|
|
426
|
+
description: 'Manages product development',
|
|
427
|
+
permissions: ['product.strategy', 'requirements.write'],
|
|
428
|
+
skills: ['product-roadmap', 'market-analysis', 'stakeholder-management'],
|
|
429
|
+
})
|
|
430
|
+
|
|
431
|
+
const agent = Agent({
|
|
432
|
+
name: 'ProductBot',
|
|
433
|
+
role,
|
|
434
|
+
goals: [
|
|
435
|
+
{ id: 'g1', description: 'Understand customer needs', target: '100%' },
|
|
436
|
+
{ id: 'g2', description: 'Prioritize features', target: '100%' },
|
|
437
|
+
{ id: 'g3', description: 'Communicate with stakeholders', target: '100%' },
|
|
438
|
+
],
|
|
439
|
+
description: 'Working on a B2B SaaS product',
|
|
440
|
+
})
|
|
441
|
+
|
|
442
|
+
expect(agent.config.name).toBe('ProductBot')
|
|
443
|
+
expect(agent.config.role.skills).toContain('market-analysis')
|
|
444
|
+
expect(agent.config.goals).toHaveLength(3)
|
|
445
|
+
})
|
|
446
|
+
|
|
447
|
+
it('creates a support agent', () => {
|
|
448
|
+
const role = Role({
|
|
449
|
+
name: 'Support Agent',
|
|
450
|
+
description: 'Handles customer inquiries',
|
|
451
|
+
permissions: ['tickets.read', 'tickets.respond', 'knowledge.search'],
|
|
452
|
+
skills: ['customer-service', 'troubleshooting', 'empathy'],
|
|
453
|
+
})
|
|
454
|
+
|
|
455
|
+
const agent = Agent({
|
|
456
|
+
name: 'SupportBot',
|
|
457
|
+
role,
|
|
458
|
+
mode: 'supervised',
|
|
459
|
+
goals: [
|
|
460
|
+
{ id: 'g1', description: 'Resolve customer issues quickly', target: '100%' },
|
|
461
|
+
],
|
|
462
|
+
})
|
|
463
|
+
|
|
464
|
+
expect(agent.config.mode).toBe('supervised')
|
|
465
|
+
expect(agent.config.role.permissions).toContain('tickets.respond')
|
|
466
|
+
})
|
|
467
|
+
|
|
468
|
+
it('creates an autonomous data processor', () => {
|
|
469
|
+
const role = Role({
|
|
470
|
+
name: 'Data Processor',
|
|
471
|
+
description: 'Processes and analyzes data',
|
|
472
|
+
permissions: ['data.read', 'data.write', 'reports.generate'],
|
|
473
|
+
skills: ['data-analysis', 'etl', 'visualization'],
|
|
474
|
+
})
|
|
475
|
+
|
|
476
|
+
const agent = Agent({
|
|
477
|
+
name: 'DataBot',
|
|
478
|
+
role,
|
|
479
|
+
mode: 'autonomous',
|
|
480
|
+
goals: [
|
|
481
|
+
{ id: 'g1', description: 'Process incoming data streams', target: '100%' },
|
|
482
|
+
],
|
|
483
|
+
model: 'sonnet',
|
|
484
|
+
temperature: 0.3,
|
|
485
|
+
})
|
|
486
|
+
|
|
487
|
+
expect(agent.config.mode).toBe('autonomous')
|
|
488
|
+
expect(agent.config.temperature).toBe(0.3)
|
|
489
|
+
})
|
|
490
|
+
})
|