@framers/agentos 0.1.2 → 0.1.3
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 +285 -261
- package/dist/core/guardrails/ICrossAgentGuardrailService.d.ts +180 -0
- package/dist/core/guardrails/ICrossAgentGuardrailService.d.ts.map +1 -0
- package/dist/core/guardrails/ICrossAgentGuardrailService.js +26 -0
- package/dist/core/guardrails/ICrossAgentGuardrailService.js.map +1 -0
- package/dist/core/guardrails/IGuardrailService.d.ts +233 -42
- package/dist/core/guardrails/IGuardrailService.d.ts.map +1 -1
- package/dist/core/guardrails/IGuardrailService.js +34 -4
- package/dist/core/guardrails/IGuardrailService.js.map +1 -1
- package/dist/core/guardrails/crossAgentGuardrailDispatcher.d.ts +119 -0
- package/dist/core/guardrails/crossAgentGuardrailDispatcher.d.ts.map +1 -0
- package/dist/core/guardrails/crossAgentGuardrailDispatcher.js +221 -0
- package/dist/core/guardrails/crossAgentGuardrailDispatcher.js.map +1 -0
- package/dist/core/guardrails/guardrailDispatcher.d.ts +97 -9
- package/dist/core/guardrails/guardrailDispatcher.d.ts.map +1 -1
- package/dist/core/guardrails/guardrailDispatcher.js +119 -9
- package/dist/core/guardrails/guardrailDispatcher.js.map +1 -1
- package/dist/core/guardrails/index.d.ts +52 -0
- package/dist/core/guardrails/index.d.ts.map +1 -0
- package/dist/core/guardrails/index.js +56 -0
- package/dist/core/guardrails/index.js.map +1 -0
- package/package.json +84 -84
package/README.md
CHANGED
|
@@ -274,269 +274,293 @@ for await (const chunk of agent.processRequest({
|
|
|
274
274
|
|
|
275
275
|
---
|
|
276
276
|
|
|
277
|
-
## Documentation
|
|
278
|
-
|
|
279
|
-
### Core Concepts
|
|
280
|
-
|
|
281
|
-
| Guide | Description |
|
|
282
|
-
|-------|-------------|
|
|
283
|
-
| [Architecture](./docs/ARCHITECTURE.md) | System design and component overview |
|
|
284
|
-
| [
|
|
285
|
-
| [Extensions](./docs/RFC_EXTENSION_STANDARDS.md) | Extension system and standards |
|
|
286
|
-
| [Ecosystem](./docs/ECOSYSTEM.md) | Related repos and packages |
|
|
287
|
-
|
|
288
|
-
### Agent Features
|
|
289
|
-
|
|
290
|
-
| Guide | Description |
|
|
291
|
-
|-------|-------------|
|
|
292
|
-
| [Planning Engine](./docs/PLANNING_ENGINE.md) | Multi-step task planning and execution |
|
|
293
|
-
| [Human-in-the-Loop](./docs/HUMAN_IN_THE_LOOP.md) | Approval workflows and oversight |
|
|
294
|
-
| [Agent Communication](./docs/AGENT_COMMUNICATION.md) | Inter-agent messaging patterns |
|
|
295
|
-
| [Self-Building Agents](./docs/RECURSIVE_SELF_BUILDING_AGENTS.md) | Recursive agent construction |
|
|
296
|
-
| [Structured Output](./docs/STRUCTURED_OUTPUT.md) | JSON schema validation |
|
|
297
|
-
| [Evaluation Framework](./docs/EVALUATION_FRAMEWORK.md) | Testing and quality assurance |
|
|
298
|
-
|
|
299
|
-
### Storage & Memory
|
|
300
|
-
|
|
301
|
-
| Guide | Description |
|
|
302
|
-
|-------|-------------|
|
|
303
|
-
| [RAG Configuration](./docs/RAG_MEMORY_CONFIGURATION.md) | Memory and retrieval setup |
|
|
304
|
-
| [SQL Storage](./docs/SQL_STORAGE_QUICKSTART.md) | SQLite/PostgreSQL setup |
|
|
305
|
-
| [Client-Side Storage](./docs/CLIENT_SIDE_STORAGE.md) | Browser storage options |
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
| [
|
|
313
|
-
| [
|
|
314
|
-
| [
|
|
315
|
-
|
|
277
|
+
## Documentation
|
|
278
|
+
|
|
279
|
+
### Core Concepts
|
|
280
|
+
|
|
281
|
+
| Guide | Description |
|
|
282
|
+
|-------|-------------|
|
|
283
|
+
| [Architecture](./docs/ARCHITECTURE.md) | System design and component overview |
|
|
284
|
+
| [Guardrails](./docs/GUARDRAILS_USAGE.md) | Safety controls and mid-stream intervention |
|
|
285
|
+
| [Extensions](./docs/RFC_EXTENSION_STANDARDS.md) | Extension system and standards |
|
|
286
|
+
| [Ecosystem](./docs/ECOSYSTEM.md) | Related repos and packages |
|
|
287
|
+
|
|
288
|
+
### Agent Features
|
|
289
|
+
|
|
290
|
+
| Guide | Description |
|
|
291
|
+
|-------|-------------|
|
|
292
|
+
| [Planning Engine](./docs/PLANNING_ENGINE.md) | Multi-step task planning and execution |
|
|
293
|
+
| [Human-in-the-Loop](./docs/HUMAN_IN_THE_LOOP.md) | Approval workflows and oversight |
|
|
294
|
+
| [Agent Communication](./docs/AGENT_COMMUNICATION.md) | Inter-agent messaging patterns |
|
|
295
|
+
| [Self-Building Agents](./docs/RECURSIVE_SELF_BUILDING_AGENTS.md) | Recursive agent construction |
|
|
296
|
+
| [Structured Output](./docs/STRUCTURED_OUTPUT.md) | JSON schema validation |
|
|
297
|
+
| [Evaluation Framework](./docs/EVALUATION_FRAMEWORK.md) | Testing and quality assurance |
|
|
298
|
+
|
|
299
|
+
### Storage & Memory
|
|
300
|
+
|
|
301
|
+
| Guide | Description |
|
|
302
|
+
|-------|-------------|
|
|
303
|
+
| [RAG Configuration](./docs/RAG_MEMORY_CONFIGURATION.md) | Memory and retrieval setup |
|
|
304
|
+
| [SQL Storage](./docs/SQL_STORAGE_QUICKSTART.md) | SQLite/PostgreSQL setup |
|
|
305
|
+
| [Client-Side Storage](./docs/CLIENT_SIDE_STORAGE.md) | Browser storage options |
|
|
306
|
+
|
|
307
|
+
### Operations
|
|
308
|
+
|
|
309
|
+
| Guide | Description |
|
|
310
|
+
|-------|-------------|
|
|
311
|
+
| [Cost Optimization](./docs/COST_OPTIMIZATION.md) | Token usage and cost management |
|
|
312
|
+
| [Platform Support](./docs/PLATFORM_SUPPORT.md) | Supported platforms and environments |
|
|
313
|
+
| [Releasing](./docs/RELEASING.md) | How to publish new versions |
|
|
314
|
+
| [API Reference](./docs/api/index.html) | TypeDoc-generated API docs |
|
|
315
|
+
---
|
|
316
|
+
|
|
317
|
+
## Examples
|
|
318
|
+
|
|
319
|
+
### Structured Data Extraction
|
|
320
|
+
|
|
321
|
+
```typescript
|
|
322
|
+
import { AgentOS, StructuredOutputManager } from '@framers/agentos';
|
|
323
|
+
|
|
324
|
+
const agent = new AgentOS();
|
|
325
|
+
await agent.initialize({
|
|
326
|
+
llmProvider: { provider: 'openai', apiKey: process.env.OPENAI_API_KEY, model: 'gpt-4o' }
|
|
327
|
+
});
|
|
328
|
+
|
|
329
|
+
// Extract typed data from unstructured text
|
|
330
|
+
const structured = new StructuredOutputManager({ llmProviderManager: agent.llmProviderManager });
|
|
331
|
+
const contact = await structured.generate({
|
|
332
|
+
prompt: 'Extract: "Meeting with Sarah Chen (sarah@startup.io) on Jan 15 re: Series A"',
|
|
333
|
+
schema: {
|
|
334
|
+
type: 'object',
|
|
335
|
+
properties: {
|
|
336
|
+
name: { type: 'string' },
|
|
337
|
+
email: { type: 'string', format: 'email' },
|
|
338
|
+
date: { type: 'string' },
|
|
339
|
+
topic: { type: 'string' }
|
|
340
|
+
},
|
|
341
|
+
required: ['name', 'email']
|
|
342
|
+
},
|
|
343
|
+
schemaName: 'ContactInfo'
|
|
344
|
+
});
|
|
345
|
+
// → { name: 'Sarah Chen', email: 'sarah@startup.io', date: 'Jan 15', topic: 'Series A' }
|
|
346
|
+
```
|
|
347
|
+
|
|
348
|
+
### Human-in-the-Loop Approvals
|
|
349
|
+
|
|
350
|
+
```typescript
|
|
351
|
+
import { HumanInteractionManager } from '@framers/agentos';
|
|
352
|
+
|
|
353
|
+
const hitl = new HumanInteractionManager({ defaultTimeoutMs: 300000 });
|
|
354
|
+
|
|
355
|
+
// Gate high-risk operations with human approval
|
|
356
|
+
const decision = await hitl.requestApproval({
|
|
357
|
+
action: {
|
|
358
|
+
type: 'database_mutation',
|
|
359
|
+
description: 'Archive 50K inactive accounts older than 2 years',
|
|
360
|
+
severity: 'high',
|
|
361
|
+
metadata: { affectedRows: 50000, table: 'users' }
|
|
362
|
+
},
|
|
363
|
+
alternatives: [
|
|
364
|
+
{ action: 'soft_delete', description: 'Mark as inactive instead of archiving' },
|
|
365
|
+
{ action: 'export_first', description: 'Export to CSV before archiving' }
|
|
366
|
+
]
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
if (decision.approved) {
|
|
370
|
+
await executeArchive();
|
|
371
|
+
} else if (decision.selectedAlternative) {
|
|
372
|
+
await executeAlternative(decision.selectedAlternative);
|
|
373
|
+
}
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
### Autonomous Task Planning
|
|
377
|
+
|
|
378
|
+
```typescript
|
|
379
|
+
import { AgentOS, PlanningEngine } from '@framers/agentos';
|
|
380
|
+
|
|
381
|
+
const agent = new AgentOS();
|
|
382
|
+
await agent.initialize({
|
|
383
|
+
llmProvider: { provider: 'openai', apiKey: process.env.OPENAI_API_KEY, model: 'gpt-4o' }
|
|
384
|
+
});
|
|
385
|
+
|
|
386
|
+
const planner = new PlanningEngine({ llmProvider: agent.llmProviderManager, strategy: 'react' });
|
|
387
|
+
|
|
388
|
+
// Decompose complex goals into executable steps with ReAct reasoning
|
|
389
|
+
const plan = await planner.generatePlan({
|
|
390
|
+
goal: 'Migrate authentication from sessions to JWT',
|
|
391
|
+
constraints: ['Zero downtime', 'Backwards compatible for 30 days', 'Audit logging required'],
|
|
392
|
+
context: { currentStack: 'Express + Redis sessions', userCount: '50K' }
|
|
393
|
+
});
|
|
394
|
+
|
|
395
|
+
for await (const step of planner.executePlan(plan.id)) {
|
|
396
|
+
console.log(`[${step.status}] ${step.action}`);
|
|
397
|
+
if (step.requiresHumanApproval) {
|
|
398
|
+
const approved = await promptUser(step.description);
|
|
399
|
+
if (!approved) break;
|
|
400
|
+
}
|
|
401
|
+
}
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
### Multi-Agent Collaboration
|
|
405
|
+
|
|
406
|
+
```typescript
|
|
407
|
+
import { AgentOS, AgencyRegistry, AgentCommunicationBus } from '@framers/agentos';
|
|
408
|
+
|
|
409
|
+
// Create specialized agents
|
|
410
|
+
const researcher = new AgentOS();
|
|
411
|
+
await researcher.initialize({ llmProvider: llmConfig, persona: 'Research analyst' });
|
|
412
|
+
|
|
413
|
+
const writer = new AgentOS();
|
|
414
|
+
await writer.initialize({ llmProvider: llmConfig, persona: 'Technical writer' });
|
|
415
|
+
|
|
416
|
+
// Register in agency with shared communication
|
|
417
|
+
const agency = new AgencyRegistry();
|
|
418
|
+
const bus = new AgentCommunicationBus();
|
|
419
|
+
agency.register('researcher', researcher, { bus });
|
|
420
|
+
agency.register('writer', writer, { bus });
|
|
421
|
+
|
|
422
|
+
// Agents coordinate via message passing
|
|
423
|
+
bus.on('research:complete', async ({ findings }) => {
|
|
424
|
+
await writer.processRequest({
|
|
425
|
+
message: `Write documentation based on: ${JSON.stringify(findings)}`
|
|
426
|
+
});
|
|
427
|
+
});
|
|
428
|
+
|
|
429
|
+
await researcher.processRequest({ message: 'Analyze the authentication module' });
|
|
430
|
+
```
|
|
431
|
+
|
|
432
|
+
### Guardrails: Mid-Stream Decision Override
|
|
433
|
+
|
|
434
|
+
```typescript
|
|
435
|
+
import { AgentOS } from '@framers/agentos';
|
|
436
|
+
import { CostCeilingGuardrail } from './guardrails/CostCeilingGuardrail';
|
|
437
|
+
|
|
438
|
+
const costGuard = new CostCeilingGuardrail({
|
|
439
|
+
maxCostUsd: 0.05, // 5 cents per request
|
|
440
|
+
inputTokenPricePer1k: 0.0001,
|
|
441
|
+
outputTokenPricePer1k: 0.0002,
|
|
442
|
+
budgetExceededText: 'Response exceeded cost ceiling. Please refine your request.'
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
const agent = new AgentOS();
|
|
446
|
+
await agent.initialize({
|
|
447
|
+
llmProvider: { provider: 'openai', apiKey: process.env.OPENAI_API_KEY },
|
|
448
|
+
guardrailService: costGuard
|
|
449
|
+
});
|
|
450
|
+
|
|
451
|
+
// Agent generates expensive response → guardrail intercepts → substitutes budget message
|
|
452
|
+
// Agents can "change their mind" before delivery based on cost, content policy, or quality checks
|
|
453
|
+
```
|
|
454
|
+
|
|
455
|
+
See [Guardrails Usage Guide](./docs/GUARDRAILS_USAGE.md) for complete documentation.
|
|
456
|
+
|
|
457
|
+
### Non-Streaming Response
|
|
458
|
+
|
|
459
|
+
```typescript
|
|
460
|
+
import { AgentOS } from '@framers/agentos';
|
|
461
|
+
|
|
462
|
+
const agent = new AgentOS();
|
|
463
|
+
await agent.initialize({
|
|
464
|
+
llmProvider: { provider: 'openai', apiKey: process.env.OPENAI_API_KEY, model: 'gpt-4o' }
|
|
465
|
+
});
|
|
466
|
+
|
|
467
|
+
// Collect full response without streaming
|
|
468
|
+
const chunks = [];
|
|
469
|
+
for await (const chunk of agent.processRequest({ message: 'Explain OAuth 2.0 briefly' })) {
|
|
470
|
+
if (chunk.type === 'content') {
|
|
471
|
+
chunks.push(chunk.content);
|
|
472
|
+
}
|
|
473
|
+
}
|
|
474
|
+
const fullResponse = chunks.join('');
|
|
475
|
+
```
|
|
476
|
+
|
|
477
|
+
### Mood-Adaptive Responses
|
|
478
|
+
|
|
479
|
+
```typescript
|
|
480
|
+
import { AgentOS, GMIMood } from '@framers/agentos';
|
|
481
|
+
|
|
482
|
+
const agent = new AgentOS();
|
|
483
|
+
await agent.initialize({
|
|
484
|
+
llmProvider: { provider: 'openai', apiKey: process.env.OPENAI_API_KEY, model: 'gpt-4o' },
|
|
485
|
+
persona: {
|
|
486
|
+
name: 'Support Agent',
|
|
487
|
+
moodAdaptation: {
|
|
488
|
+
enabled: true,
|
|
489
|
+
defaultMood: GMIMood.EMPATHETIC,
|
|
490
|
+
allowedMoods: [GMIMood.EMPATHETIC, GMIMood.FOCUSED, GMIMood.ANALYTICAL],
|
|
491
|
+
sensitivityFactor: 0.7,
|
|
492
|
+
// Mood-specific prompt modifiers
|
|
493
|
+
moodPrompts: {
|
|
494
|
+
[GMIMood.EMPATHETIC]: 'Prioritize understanding and emotional support.',
|
|
495
|
+
[GMIMood.FRUSTRATED]: 'Acknowledge difficulty, offer step-by-step guidance.',
|
|
496
|
+
[GMIMood.ANALYTICAL]: 'Provide detailed technical explanations with examples.'
|
|
497
|
+
}
|
|
498
|
+
}
|
|
499
|
+
}
|
|
500
|
+
});
|
|
501
|
+
|
|
502
|
+
// Agent automatically adapts tone based on conversation context
|
|
503
|
+
for await (const chunk of agent.processRequest({
|
|
504
|
+
message: 'This is so frustrating, nothing works!'
|
|
505
|
+
})) {
|
|
506
|
+
// Response adapts with empathetic tone, mood shifts to EMPATHETIC
|
|
507
|
+
}
|
|
508
|
+
```
|
|
509
|
+
|
|
510
|
+
### Contextual Prompt Adaptation
|
|
511
|
+
|
|
512
|
+
```typescript
|
|
513
|
+
import { AgentOS } from '@framers/agentos';
|
|
514
|
+
|
|
515
|
+
const agent = new AgentOS();
|
|
516
|
+
await agent.initialize({
|
|
517
|
+
llmProvider: llmConfig,
|
|
518
|
+
persona: {
|
|
519
|
+
name: 'Adaptive Tutor',
|
|
520
|
+
// Dynamic prompt elements injected based on runtime context
|
|
521
|
+
contextualPromptElements: [
|
|
522
|
+
{
|
|
523
|
+
id: 'beginner-guidance',
|
|
524
|
+
type: 'SYSTEM_INSTRUCTION_ADDON',
|
|
525
|
+
content: 'Explain concepts simply, avoid jargon, use analogies.',
|
|
526
|
+
criteria: { userSkillLevel: ['novice', 'beginner'] },
|
|
527
|
+
priority: 10
|
|
528
|
+
},
|
|
529
|
+
{
|
|
530
|
+
id: 'expert-mode',
|
|
531
|
+
type: 'SYSTEM_INSTRUCTION_ADDON',
|
|
532
|
+
content: 'Assume deep technical knowledge, be concise, skip basics.',
|
|
533
|
+
criteria: { userSkillLevel: ['expert', 'advanced'] },
|
|
534
|
+
priority: 10
|
|
535
|
+
},
|
|
536
|
+
{
|
|
537
|
+
id: 'debugging-context',
|
|
538
|
+
type: 'FEW_SHOT_EXAMPLE',
|
|
539
|
+
content: { role: 'assistant', content: 'Let\'s trace through step by step...' },
|
|
540
|
+
criteria: { taskHint: ['debugging', 'troubleshooting'] }
|
|
541
|
+
}
|
|
542
|
+
],
|
|
543
|
+
// Meta-prompts for self-reflection and planning
|
|
544
|
+
metaPrompts: [
|
|
545
|
+
{
|
|
546
|
+
id: 'mid-conversation-check',
|
|
547
|
+
trigger: 'every_n_turns',
|
|
548
|
+
triggerConfig: { n: 5 },
|
|
549
|
+
prompt: 'Assess: Is the user making progress? Should I adjust my approach?'
|
|
550
|
+
}
|
|
551
|
+
]
|
|
552
|
+
}
|
|
553
|
+
});
|
|
554
|
+
|
|
555
|
+
// Prompts automatically adapt based on user context and task
|
|
556
|
+
await agent.updateUserContext({ skillLevel: 'expert' });
|
|
557
|
+
for await (const chunk of agent.processRequest({ message: 'Explain monads' })) {
|
|
558
|
+
// Uses expert-mode prompt element, skips beginner explanations
|
|
559
|
+
}
|
|
560
|
+
```
|
|
561
|
+
|
|
316
562
|
---
|
|
317
563
|
|
|
318
|
-
## Examples
|
|
319
|
-
|
|
320
|
-
### Structured Data Extraction
|
|
321
|
-
|
|
322
|
-
```typescript
|
|
323
|
-
import { AgentOS, StructuredOutputManager } from '@framers/agentos';
|
|
324
|
-
|
|
325
|
-
const agent = new AgentOS();
|
|
326
|
-
await agent.initialize({
|
|
327
|
-
llmProvider: { provider: 'openai', apiKey: process.env.OPENAI_API_KEY, model: 'gpt-4o' }
|
|
328
|
-
});
|
|
329
|
-
|
|
330
|
-
// Extract typed data from unstructured text
|
|
331
|
-
const structured = new StructuredOutputManager({ llmProviderManager: agent.llmProviderManager });
|
|
332
|
-
const contact = await structured.generate({
|
|
333
|
-
prompt: 'Extract: "Meeting with Sarah Chen (sarah@startup.io) on Jan 15 re: Series A"',
|
|
334
|
-
schema: {
|
|
335
|
-
type: 'object',
|
|
336
|
-
properties: {
|
|
337
|
-
name: { type: 'string' },
|
|
338
|
-
email: { type: 'string', format: 'email' },
|
|
339
|
-
date: { type: 'string' },
|
|
340
|
-
topic: { type: 'string' }
|
|
341
|
-
},
|
|
342
|
-
required: ['name', 'email']
|
|
343
|
-
},
|
|
344
|
-
schemaName: 'ContactInfo'
|
|
345
|
-
});
|
|
346
|
-
// → { name: 'Sarah Chen', email: 'sarah@startup.io', date: 'Jan 15', topic: 'Series A' }
|
|
347
|
-
```
|
|
348
|
-
|
|
349
|
-
### Human-in-the-Loop Approvals
|
|
350
|
-
|
|
351
|
-
```typescript
|
|
352
|
-
import { HumanInteractionManager } from '@framers/agentos';
|
|
353
|
-
|
|
354
|
-
const hitl = new HumanInteractionManager({ defaultTimeoutMs: 300000 });
|
|
355
|
-
|
|
356
|
-
// Gate high-risk operations with human approval
|
|
357
|
-
const decision = await hitl.requestApproval({
|
|
358
|
-
action: {
|
|
359
|
-
type: 'database_mutation',
|
|
360
|
-
description: 'Archive 50K inactive accounts older than 2 years',
|
|
361
|
-
severity: 'high',
|
|
362
|
-
metadata: { affectedRows: 50000, table: 'users' }
|
|
363
|
-
},
|
|
364
|
-
alternatives: [
|
|
365
|
-
{ action: 'soft_delete', description: 'Mark as inactive instead of archiving' },
|
|
366
|
-
{ action: 'export_first', description: 'Export to CSV before archiving' }
|
|
367
|
-
]
|
|
368
|
-
});
|
|
369
|
-
|
|
370
|
-
if (decision.approved) {
|
|
371
|
-
await executeArchive();
|
|
372
|
-
} else if (decision.selectedAlternative) {
|
|
373
|
-
await executeAlternative(decision.selectedAlternative);
|
|
374
|
-
}
|
|
375
|
-
```
|
|
376
|
-
|
|
377
|
-
### Autonomous Task Planning
|
|
378
|
-
|
|
379
|
-
```typescript
|
|
380
|
-
import { AgentOS, PlanningEngine } from '@framers/agentos';
|
|
381
|
-
|
|
382
|
-
const agent = new AgentOS();
|
|
383
|
-
await agent.initialize({
|
|
384
|
-
llmProvider: { provider: 'openai', apiKey: process.env.OPENAI_API_KEY, model: 'gpt-4o' }
|
|
385
|
-
});
|
|
386
|
-
|
|
387
|
-
const planner = new PlanningEngine({ llmProvider: agent.llmProviderManager, strategy: 'react' });
|
|
388
|
-
|
|
389
|
-
// Decompose complex goals into executable steps with ReAct reasoning
|
|
390
|
-
const plan = await planner.generatePlan({
|
|
391
|
-
goal: 'Migrate authentication from sessions to JWT',
|
|
392
|
-
constraints: ['Zero downtime', 'Backwards compatible for 30 days', 'Audit logging required'],
|
|
393
|
-
context: { currentStack: 'Express + Redis sessions', userCount: '50K' }
|
|
394
|
-
});
|
|
395
|
-
|
|
396
|
-
for await (const step of planner.executePlan(plan.id)) {
|
|
397
|
-
console.log(`[${step.status}] ${step.action}`);
|
|
398
|
-
if (step.requiresHumanApproval) {
|
|
399
|
-
const approved = await promptUser(step.description);
|
|
400
|
-
if (!approved) break;
|
|
401
|
-
}
|
|
402
|
-
}
|
|
403
|
-
```
|
|
404
|
-
|
|
405
|
-
### Multi-Agent Collaboration
|
|
406
|
-
|
|
407
|
-
```typescript
|
|
408
|
-
import { AgentOS, AgencyRegistry, AgentCommunicationBus } from '@framers/agentos';
|
|
409
|
-
|
|
410
|
-
// Create specialized agents
|
|
411
|
-
const researcher = new AgentOS();
|
|
412
|
-
await researcher.initialize({ llmProvider: llmConfig, persona: 'Research analyst' });
|
|
413
|
-
|
|
414
|
-
const writer = new AgentOS();
|
|
415
|
-
await writer.initialize({ llmProvider: llmConfig, persona: 'Technical writer' });
|
|
416
|
-
|
|
417
|
-
// Register in agency with shared communication
|
|
418
|
-
const agency = new AgencyRegistry();
|
|
419
|
-
const bus = new AgentCommunicationBus();
|
|
420
|
-
agency.register('researcher', researcher, { bus });
|
|
421
|
-
agency.register('writer', writer, { bus });
|
|
422
|
-
|
|
423
|
-
// Agents coordinate via message passing
|
|
424
|
-
bus.on('research:complete', async ({ findings }) => {
|
|
425
|
-
await writer.processRequest({
|
|
426
|
-
message: `Write documentation based on: ${JSON.stringify(findings)}`
|
|
427
|
-
});
|
|
428
|
-
});
|
|
429
|
-
|
|
430
|
-
await researcher.processRequest({ message: 'Analyze the authentication module' });
|
|
431
|
-
```
|
|
432
|
-
|
|
433
|
-
### Non-Streaming Response
|
|
434
|
-
|
|
435
|
-
```typescript
|
|
436
|
-
import { AgentOS } from '@framers/agentos';
|
|
437
|
-
|
|
438
|
-
const agent = new AgentOS();
|
|
439
|
-
await agent.initialize({
|
|
440
|
-
llmProvider: { provider: 'openai', apiKey: process.env.OPENAI_API_KEY, model: 'gpt-4o' }
|
|
441
|
-
});
|
|
442
|
-
|
|
443
|
-
// Collect full response without streaming
|
|
444
|
-
const chunks = [];
|
|
445
|
-
for await (const chunk of agent.processRequest({ message: 'Explain OAuth 2.0 briefly' })) {
|
|
446
|
-
if (chunk.type === 'content') {
|
|
447
|
-
chunks.push(chunk.content);
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
const fullResponse = chunks.join('');
|
|
451
|
-
```
|
|
452
|
-
|
|
453
|
-
### Mood-Adaptive Responses
|
|
454
|
-
|
|
455
|
-
```typescript
|
|
456
|
-
import { AgentOS, GMIMood } from '@framers/agentos';
|
|
457
|
-
|
|
458
|
-
const agent = new AgentOS();
|
|
459
|
-
await agent.initialize({
|
|
460
|
-
llmProvider: { provider: 'openai', apiKey: process.env.OPENAI_API_KEY, model: 'gpt-4o' },
|
|
461
|
-
persona: {
|
|
462
|
-
name: 'Support Agent',
|
|
463
|
-
moodAdaptation: {
|
|
464
|
-
enabled: true,
|
|
465
|
-
defaultMood: GMIMood.EMPATHETIC,
|
|
466
|
-
allowedMoods: [GMIMood.EMPATHETIC, GMIMood.FOCUSED, GMIMood.ANALYTICAL],
|
|
467
|
-
sensitivityFactor: 0.7,
|
|
468
|
-
// Mood-specific prompt modifiers
|
|
469
|
-
moodPrompts: {
|
|
470
|
-
[GMIMood.EMPATHETIC]: 'Prioritize understanding and emotional support.',
|
|
471
|
-
[GMIMood.FRUSTRATED]: 'Acknowledge difficulty, offer step-by-step guidance.',
|
|
472
|
-
[GMIMood.ANALYTICAL]: 'Provide detailed technical explanations with examples.'
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
});
|
|
477
|
-
|
|
478
|
-
// Agent automatically adapts tone based on conversation context
|
|
479
|
-
for await (const chunk of agent.processRequest({
|
|
480
|
-
message: 'This is so frustrating, nothing works!'
|
|
481
|
-
})) {
|
|
482
|
-
// Response adapts with empathetic tone, mood shifts to EMPATHETIC
|
|
483
|
-
}
|
|
484
|
-
```
|
|
485
|
-
|
|
486
|
-
### Contextual Prompt Adaptation
|
|
487
|
-
|
|
488
|
-
```typescript
|
|
489
|
-
import { AgentOS } from '@framers/agentos';
|
|
490
|
-
|
|
491
|
-
const agent = new AgentOS();
|
|
492
|
-
await agent.initialize({
|
|
493
|
-
llmProvider: llmConfig,
|
|
494
|
-
persona: {
|
|
495
|
-
name: 'Adaptive Tutor',
|
|
496
|
-
// Dynamic prompt elements injected based on runtime context
|
|
497
|
-
contextualPromptElements: [
|
|
498
|
-
{
|
|
499
|
-
id: 'beginner-guidance',
|
|
500
|
-
type: 'SYSTEM_INSTRUCTION_ADDON',
|
|
501
|
-
content: 'Explain concepts simply, avoid jargon, use analogies.',
|
|
502
|
-
criteria: { userSkillLevel: ['novice', 'beginner'] },
|
|
503
|
-
priority: 10
|
|
504
|
-
},
|
|
505
|
-
{
|
|
506
|
-
id: 'expert-mode',
|
|
507
|
-
type: 'SYSTEM_INSTRUCTION_ADDON',
|
|
508
|
-
content: 'Assume deep technical knowledge, be concise, skip basics.',
|
|
509
|
-
criteria: { userSkillLevel: ['expert', 'advanced'] },
|
|
510
|
-
priority: 10
|
|
511
|
-
},
|
|
512
|
-
{
|
|
513
|
-
id: 'debugging-context',
|
|
514
|
-
type: 'FEW_SHOT_EXAMPLE',
|
|
515
|
-
content: { role: 'assistant', content: 'Let\'s trace through step by step...' },
|
|
516
|
-
criteria: { taskHint: ['debugging', 'troubleshooting'] }
|
|
517
|
-
}
|
|
518
|
-
],
|
|
519
|
-
// Meta-prompts for self-reflection and planning
|
|
520
|
-
metaPrompts: [
|
|
521
|
-
{
|
|
522
|
-
id: 'mid-conversation-check',
|
|
523
|
-
trigger: 'every_n_turns',
|
|
524
|
-
triggerConfig: { n: 5 },
|
|
525
|
-
prompt: 'Assess: Is the user making progress? Should I adjust my approach?'
|
|
526
|
-
}
|
|
527
|
-
]
|
|
528
|
-
}
|
|
529
|
-
});
|
|
530
|
-
|
|
531
|
-
// Prompts automatically adapt based on user context and task
|
|
532
|
-
await agent.updateUserContext({ skillLevel: 'expert' });
|
|
533
|
-
for await (const chunk of agent.processRequest({ message: 'Explain monads' })) {
|
|
534
|
-
// Uses expert-mode prompt element, skips beginner explanations
|
|
535
|
-
}
|
|
536
|
-
```
|
|
537
|
-
|
|
538
|
-
---
|
|
539
|
-
|
|
540
564
|
## Roadmap
|
|
541
565
|
|
|
542
566
|
| Version | Status | Features |
|