agentic-api 2.0.26 β 2.0.31
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 +224 -60
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,33 +1,59 @@
|
|
|
1
1
|
# @agentic-api
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Comprehensive framework for intelligent agent orchestration, document processing, and enterprise workflow management. (inspired from [OpenAI Swarm](https://github.com/openai/openai-realtime-agents)) (01/2025)
|
|
4
4
|
|
|
5
|
-
> **
|
|
6
|
-
> This project is not meant to be better than Vercel or LangChain. It's simply less generic and optimized for a specific set of problems.
|
|
5
|
+
> **Design Philosophy**:
|
|
6
|
+
> This project is not meant to be better than Vercel or LangChain. It's simply less generic and optimized for a specific set of enterprise problems.
|
|
7
7
|
> It focuses on specific features that required too many dependencies with other frameworks.
|
|
8
8
|
|
|
9
|
+
## π Core Capabilities
|
|
9
10
|
|
|
10
|
-
|
|
11
|
+
### π€ Agent Orchestration
|
|
12
|
+
- Multi-agent conversations with automatic transfers
|
|
13
|
+
- State machine-driven workflows for complex processes
|
|
14
|
+
- Confidence-based escalation between specialized agents
|
|
15
|
+
- **StateGraph Architecture**: Modern conversation state management with automatic persistence
|
|
11
16
|
|
|
12
|
-
|
|
13
|
-
-
|
|
14
|
-
-
|
|
15
|
-
-
|
|
16
|
-
-
|
|
17
|
+
### π Document Processing
|
|
18
|
+
- **MapLLM**: Advanced map-reduce pattern for large document analysis
|
|
19
|
+
- **Structured Outputs**: OpenAI JSON schema validation support
|
|
20
|
+
- **Flexible Loaders**: File and string content processing with chunking strategies
|
|
21
|
+
- **Callback-Driven**: User-defined logic for accumulation and flow control
|
|
17
22
|
|
|
23
|
+
### π§ͺ Testing & Validation
|
|
24
|
+
- **Agent Simulator**: Comprehensive testing framework with scenario-based simulations
|
|
25
|
+
- **Realistic Personas**: Authentic user behavior simulation for thorough testing
|
|
26
|
+
- **Automatic Validation**: Built-in success/failure detection and reporting
|
|
18
27
|
|
|
19
|
-
###
|
|
28
|
+
### π Enterprise Workflow
|
|
29
|
+
- **Rules Management**: Git-based workflow for business rules and procedures
|
|
30
|
+
- **Pull Request Validation**: Structured review and approval processes
|
|
31
|
+
- **Multi-File Operations**: Atomic operations across related documents
|
|
32
|
+
- **Search Integration**: Full-text search with RAG embeddings
|
|
20
33
|
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
-
|
|
25
|
-
-
|
|
34
|
+
## π― Key Advantages
|
|
35
|
+
|
|
36
|
+
1. **Enterprise-Ready**
|
|
37
|
+
- Production-grade document workflows
|
|
38
|
+
- Comprehensive testing capabilities
|
|
39
|
+
- Git-based version control integration
|
|
40
|
+
|
|
41
|
+
2. **Developer-Friendly**
|
|
42
|
+
- Minimal configuration required
|
|
43
|
+
- TypeScript-first with full type safety
|
|
44
|
+
- Modular architecture for easy extension
|
|
45
|
+
|
|
46
|
+
3. **Performance-Optimized**
|
|
47
|
+
- Efficient chunking strategies
|
|
48
|
+
- Intelligent caching systems
|
|
49
|
+
- Parallel processing support
|
|
26
50
|
|
|
27
51
|
### Recommended Use Cases
|
|
28
52
|
|
|
29
|
-
-
|
|
30
|
-
-
|
|
53
|
+
- **Enterprise Document Management**: Rules, procedures, and knowledge base management
|
|
54
|
+
- **Agent Development & Testing**: Comprehensive agent behavior validation
|
|
55
|
+
- **Large Document Processing**: Analysis and synthesis of complex documents
|
|
56
|
+
- **Conversational AI Systems**: Multi-agent workflows with state management
|
|
31
57
|
|
|
32
58
|
|
|
33
59
|
[](https://mermaid.live/edit#pako:eNpVkcluwjAQhl_FGgmJSoDIQoAcKhEQ7aGXNkiVmqDKTYYkUmJHxu5GeZaq575cH6EmC8sc7PnG_4xn7B1EPEZwYZPztyilQpLVImREmy81dYNqW1_VsVlwIxAlinXNi24Qwt_37w-5VQVlIbTCet2ql0TQMiU-itcswudZgkxuSdAwqbkpdrA4ExjJjDNy93CKekbg0xzPhZ4ZzNVW8gIF8VVZct3k2akV3CsujxnI4pDV7jx4XC3XLVXTkX7_msyaCSvwjAsyL8hqkzsdsuQi0h3QPEsYFnoYknKRfXImaV6LPIP0B2dFPLNhq2Gr5kVbtUn4WtIsVwK_yLxp_HD7KXrUQw_0IxQ0i_U37g6xEGSqmwnB1W6MG6pyGULI9lpKleT-B4vAlUJhDwRXSQruhuZbTaqMqcRFRvW3Fa2kpOyJ8yMm4nBTk60fFsWcKybBHVVScHfwrmFiDgzTGJvToWFY2nrwAe54OBg5pu1Yjj21Dcd29j34rGoPB5OxPT23_T90g8Qf)
|
|
@@ -42,9 +68,9 @@ npm install @agentic-api
|
|
|
42
68
|
|
|
43
69
|
```typescript
|
|
44
70
|
import OpenAI from "openai";
|
|
45
|
-
import { executeAgentSet } from '@agentic-api
|
|
46
|
-
import { AgenticContext } from '@agentic-api
|
|
47
|
-
import { AgentStateGraph } from '@agentic-api
|
|
71
|
+
import { executeAgentSet } from '@agentic-api';
|
|
72
|
+
import { AgenticContext } from '@agentic-api';
|
|
73
|
+
import { AgentStateGraph } from '@agentic-api';
|
|
48
74
|
|
|
49
75
|
const openai = new OpenAI({
|
|
50
76
|
apiKey: process.env.OPENAI_API_KEY,
|
|
@@ -74,8 +100,7 @@ const stream = await executeAgentSet(agents, context, {
|
|
|
74
100
|
## π€ Custom Agent Creation
|
|
75
101
|
|
|
76
102
|
```typescript
|
|
77
|
-
import { AgentConfig } from '@agentic-api
|
|
78
|
-
import { modelConfig } from '@agentic-api/execute';
|
|
103
|
+
import { AgentConfig, modelConfig } from '@agentic-api';
|
|
79
104
|
|
|
80
105
|
// Example specialized agent with thinking tool
|
|
81
106
|
const haiku: AgentConfig = {
|
|
@@ -98,7 +123,7 @@ const welcome: AgentConfig = {
|
|
|
98
123
|
};
|
|
99
124
|
|
|
100
125
|
// Inject transfer and thinking tools
|
|
101
|
-
import { injectTransferTools } from '@agentic-api
|
|
126
|
+
import { injectTransferTools } from '@agentic-api';
|
|
102
127
|
const myAgents = injectTransferTools([welcome, haiku]);
|
|
103
128
|
```
|
|
104
129
|
|
|
@@ -107,7 +132,7 @@ const myAgents = injectTransferTools([welcome, haiku]);
|
|
|
107
132
|
The new StateGraph architecture provides automatic conversation state management:
|
|
108
133
|
|
|
109
134
|
```typescript
|
|
110
|
-
import { AgentStateGraph, sessionStateGraphGet, sessionStateGraphSet } from '@agentic-api
|
|
135
|
+
import { AgentStateGraph, sessionStateGraphGet, sessionStateGraphSet } from '@agentic-api';
|
|
111
136
|
|
|
112
137
|
// StateGraph is automatically managed during executeAgentSet
|
|
113
138
|
// But you can also work with it directly:
|
|
@@ -234,7 +259,7 @@ stateGraph.clearDiscussion("agentName");
|
|
|
234
259
|
### **Utility Functions**
|
|
235
260
|
```typescript
|
|
236
261
|
// Get specialized (starting) agent for discussion
|
|
237
|
-
import { getSpecializedAgent } from '@agentic-api
|
|
262
|
+
import { getSpecializedAgent } from '@agentic-api';
|
|
238
263
|
const specializedAgent = getSpecializedAgent(discussion);
|
|
239
264
|
|
|
240
265
|
// Find discussion by ID
|
|
@@ -247,49 +272,188 @@ stateGraph.renameDiscussion("agentName", "New Name", "Description");
|
|
|
247
272
|
stateGraph.deleteDiscussion("agentName");
|
|
248
273
|
```
|
|
249
274
|
|
|
250
|
-
##
|
|
275
|
+
## ποΈ MapLLM Document Processing
|
|
276
|
+
|
|
277
|
+
Modern map-reduce pattern for processing large documents with flexible content handling and OpenAI structured outputs.
|
|
278
|
+
|
|
279
|
+
- **Flexible Loaders**: `FileNativeLoader` and `StringNativeLoader` with configurable chunking strategies
|
|
280
|
+
- **Callback-Driven**: User-defined logic for accumulation, termination, and flow control
|
|
281
|
+
- **Structured Outputs**: Optional JSON schema validation via OpenAI structured outputs
|
|
282
|
+
- **Robust EOF Handling**: Proper chunk boundary detection and clean termination
|
|
283
|
+
|
|
284
|
+
π **[Complete MapLLM Documentation β](./docs/README-AGENT-REDUCE.md)**
|
|
285
|
+
|
|
286
|
+
```typescript
|
|
287
|
+
import { MapLLM, FileNativeLoader, modelConfig } from '@agentic-api';
|
|
288
|
+
|
|
289
|
+
// Basic text processing
|
|
290
|
+
const config = {
|
|
291
|
+
digestPrompt: "Analyze this chunk for key information.",
|
|
292
|
+
reducePrompt: "Merge analysis with previous results."
|
|
293
|
+
};
|
|
294
|
+
|
|
295
|
+
const loader = new FileNativeLoader('document.pdf', { type: 'pages', size: 1 });
|
|
296
|
+
const mapper = new MapLLM(loader);
|
|
297
|
+
|
|
298
|
+
const callback = (result, currentValue) => {
|
|
299
|
+
result.acc = result.acc + `\n${currentValue}\n`;
|
|
300
|
+
|
|
301
|
+
// Stop conditions
|
|
302
|
+
if (result.acc.length > 5000) {
|
|
303
|
+
result.continue = true;
|
|
304
|
+
}
|
|
305
|
+
if (result.metadata.iterations > 20) {
|
|
306
|
+
result.maxIterations = true;
|
|
307
|
+
}
|
|
308
|
+
|
|
309
|
+
return result;
|
|
310
|
+
};
|
|
311
|
+
|
|
312
|
+
const init = {
|
|
313
|
+
acc: "",
|
|
314
|
+
model: modelConfig("LOW-fast"),
|
|
315
|
+
verbose: true
|
|
316
|
+
};
|
|
317
|
+
|
|
318
|
+
const result = await mapper.reduce(config, callback, init);
|
|
319
|
+
console.log('Final result:', result.acc);
|
|
320
|
+
|
|
321
|
+
// Structured output processing with JSON schema
|
|
322
|
+
const myJsonSchema = {
|
|
323
|
+
type: "object",
|
|
324
|
+
properties: {
|
|
325
|
+
summary: { type: "string" },
|
|
326
|
+
key_points: { type: "array", items: { type: "string" } }
|
|
327
|
+
},
|
|
328
|
+
required: ["summary", "key_points"]
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
const structuredCallback = (result, currentValue) => {
|
|
332
|
+
// Set structured output format
|
|
333
|
+
result.format = {
|
|
334
|
+
name: "analysis",
|
|
335
|
+
schema: myJsonSchema,
|
|
336
|
+
strict: true
|
|
337
|
+
};
|
|
338
|
+
|
|
339
|
+
// For structured output, accumulate as object or merged object
|
|
340
|
+
result.acc = { ...result.acc, ...currentValue };
|
|
341
|
+
|
|
342
|
+
if (result.metadata.iterations > 5) {
|
|
343
|
+
result.maxIterations = true;
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
return result;
|
|
347
|
+
};
|
|
348
|
+
|
|
349
|
+
const structuredResult = await mapper.reduce(config, structuredCallback, {
|
|
350
|
+
acc: {},
|
|
351
|
+
verbose: true
|
|
352
|
+
});
|
|
353
|
+
// structuredResult.acc is validated JSON matching the schema
|
|
354
|
+
```
|
|
355
|
+
|
|
356
|
+
## π€ Agent Simulator
|
|
251
357
|
|
|
252
|
-
|
|
358
|
+
Advanced testing framework for agent behavior validation with scenario-based simulations.
|
|
253
359
|
|
|
254
|
-
- **
|
|
255
|
-
- **
|
|
256
|
-
- **
|
|
257
|
-
- **
|
|
360
|
+
- **Scenario-Based Testing**: Define complex test scenarios with goals, personas, and expected outcomes
|
|
361
|
+
- **Conversational Simulation**: Simulate realistic user interactions with agents
|
|
362
|
+
- **Automatic Validation**: Built-in success/failure detection and error reporting
|
|
363
|
+
- **Exchange Limiting**: Control simulation length with configurable exchange limits
|
|
364
|
+
|
|
365
|
+
π **[Complete Agent Simulator Documentation β](./docs/README-AGENT-SIMULATOR.md)**
|
|
258
366
|
|
|
259
367
|
```typescript
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
//
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
368
|
+
import { AgentSimulator, SimulationScenario } from '@agentic-api';
|
|
369
|
+
|
|
370
|
+
// Define test scenario
|
|
371
|
+
const scenario: SimulationScenario = {
|
|
372
|
+
testGoals: "Verify that the agent can help with haiku creation",
|
|
373
|
+
testEnd: "Agent provides a complete haiku poem",
|
|
374
|
+
testPersona: "A poetry enthusiast seeking creative assistance",
|
|
375
|
+
testQuery: "I want to write a haiku about nature. Can you help me?",
|
|
376
|
+
testResult: "Agent successfully guides haiku creation process",
|
|
377
|
+
testError: "Agent refuses to help or provides incorrect format"
|
|
378
|
+
};
|
|
379
|
+
|
|
380
|
+
// Configure simulator
|
|
381
|
+
const simulator = new AgentSimulator({
|
|
382
|
+
agents: [haikuAgent, welcomeAgent],
|
|
383
|
+
start: "welcome",
|
|
384
|
+
verbose: true,
|
|
385
|
+
instructionEx: "Focus on creative writing assistance"
|
|
268
386
|
});
|
|
269
387
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
});
|
|
287
|
-
currentChunk = nextChunkData.content;
|
|
288
|
-
nextPosition = nextChunkData.nextPosition;
|
|
388
|
+
// Run simulation
|
|
389
|
+
const result = await simulator.executeSimulation({
|
|
390
|
+
scenario,
|
|
391
|
+
maxExchanges: 10,
|
|
392
|
+
onMessage: (message) => {
|
|
393
|
+
console.log(`${message.role}: ${message.content}`);
|
|
394
|
+
}
|
|
395
|
+
});
|
|
396
|
+
|
|
397
|
+
// Validate results
|
|
398
|
+
console.log('Success:', result.success);
|
|
399
|
+
console.log('Summary:', result.message);
|
|
400
|
+
console.log('Exchanges:', result.exchangeCount);
|
|
401
|
+
|
|
402
|
+
if (!result.success) {
|
|
403
|
+
console.error('Error:', result.error);
|
|
289
404
|
}
|
|
405
|
+
```
|
|
406
|
+
|
|
407
|
+
### Simulation Features
|
|
408
|
+
|
|
409
|
+
- **Structured Scenarios**: Define test goals, end conditions, and expected behaviors
|
|
410
|
+
- **Persona Simulation**: Simulator adopts specific user personas for realistic testing
|
|
411
|
+
- **Error Detection**: Automatic detection of unwanted content or behaviors
|
|
412
|
+
- **Exchange Tracking**: Monitor conversation flow and agent performance
|
|
413
|
+
- **Execution Metadata**: Access to token usage, actions, and performance metrics
|
|
414
|
+
|
|
415
|
+
## π Rules Management System
|
|
416
|
+
|
|
417
|
+
Enterprise-grade Git-based workflow for managing business rules, procedures, and documentation.
|
|
418
|
+
|
|
419
|
+
- **Git-Based Workflow**: Complete version control with branch-based status management
|
|
420
|
+
- **Pull Request Validation**: Structured validation process with reviewer assignment
|
|
421
|
+
- **Multi-File Operations**: Atomic operations across multiple related documents
|
|
422
|
+
- **Content Management**: Rich metadata support with front-matter parsing
|
|
423
|
+
- **Search Integration**: Full-text search with RAG embeddings support
|
|
424
|
+
|
|
425
|
+
π **[Complete Rules System Documentation β](./docs/README-RULES-SYSTEM.md)**
|
|
426
|
+
|
|
427
|
+
```typescript
|
|
428
|
+
import { RulesWorkflow, gitLoad, RuleStatus } from '@agentic-api';
|
|
429
|
+
|
|
430
|
+
// Initialize workflow
|
|
431
|
+
const config = gitLoad(); // Loads from environment variables
|
|
432
|
+
const workflow = new RulesWorkflow(config);
|
|
433
|
+
|
|
434
|
+
// Create a new rule
|
|
435
|
+
const newRule = await workflow.createRule('procedures/finance/budget.md', {
|
|
436
|
+
title: 'Budget Validation Process',
|
|
437
|
+
slugs: ['budget-validation'],
|
|
438
|
+
tags: ['finance', 'validation'],
|
|
439
|
+
role: 'rule'
|
|
440
|
+
}, 'Initial budget validation procedure');
|
|
441
|
+
|
|
442
|
+
// Create validation request (PR)
|
|
443
|
+
const prBranch = await workflow.createPullRequest(
|
|
444
|
+
['procedure-a.md', 'procedure-b.md'],
|
|
445
|
+
'Update financial procedures'
|
|
446
|
+
);
|
|
447
|
+
|
|
448
|
+
// Search rules by content
|
|
449
|
+
const searchResults = await workflow.searchRules('budget validation', {
|
|
450
|
+
branch: 'main',
|
|
451
|
+
tags: ['finance'],
|
|
452
|
+
limit: 10
|
|
453
|
+
});
|
|
290
454
|
|
|
291
|
-
//
|
|
292
|
-
const
|
|
455
|
+
// Get rules by status
|
|
456
|
+
const draftRules = await workflow.getRulesByStatus(RuleStatus.EDITING);
|
|
293
457
|
```
|
|
294
458
|
|
|
295
459
|
## π§ͺ Testing
|
package/package.json
CHANGED