agentflow-core 0.7.0 → 0.8.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/README.md +99 -0
- package/dist/{chunk-DY7YHFIB.js → chunk-BYWLDTZK.js} +2 -1
- package/dist/{chunk-5PRHVYYD.js → chunk-NVFWBTAZ.js} +198 -89
- package/dist/cli.cjs +225 -112
- package/dist/cli.js +12 -8
- package/dist/index.cjs +1657 -166
- package/dist/index.d.cts +917 -37
- package/dist/index.d.ts +917 -37
- package/dist/index.js +1381 -10
- package/dist/{loader-LYRR6LMM.js → loader-JMFEFI3Q.js} +1 -1
- package/package.json +7 -3
package/README.md
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# agentflow-core
|
|
2
|
+
|
|
3
|
+
**v0.8.0** — Monitor any AI agent system. Auto-detects failures, sends alerts, audits OS processes. Zero config, zero dependencies.
|
|
4
|
+
|
|
5
|
+
Works with any agent framework: OpenAI, Anthropic, LangChain, CrewAI, AutoGen, or hand-rolled agents.
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install agentflow-core
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Requires Node.js >= 20.
|
|
14
|
+
|
|
15
|
+
## Quick start
|
|
16
|
+
|
|
17
|
+
### Step 1 — Build an execution graph
|
|
18
|
+
|
|
19
|
+
Wrap your agent's work with `createGraphBuilder`. Each logical unit of work is a node; the graph captures the full execution tree.
|
|
20
|
+
|
|
21
|
+
```ts
|
|
22
|
+
import { createGraphBuilder, getStats } from 'agentflow-core';
|
|
23
|
+
|
|
24
|
+
const builder = createGraphBuilder({ agentId: 'my-agent' });
|
|
25
|
+
|
|
26
|
+
const rootId = builder.startNode({ type: 'agent', name: 'main' });
|
|
27
|
+
const toolId = builder.startNode({ type: 'tool', name: 'fetch', parentId: rootId });
|
|
28
|
+
builder.endNode(toolId);
|
|
29
|
+
builder.endNode(rootId);
|
|
30
|
+
|
|
31
|
+
const graph = builder.build();
|
|
32
|
+
console.log(getStats(graph));
|
|
33
|
+
// { totalNodes: 2, failedNodes: 0, duration: 42, status: 'completed' }
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
### Step 2 — Mine patterns across runs
|
|
37
|
+
|
|
38
|
+
Accumulate graphs over time and use process mining to find variants, bottlenecks, and conformance drift.
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
import { discoverProcess, findVariants, getBottlenecks, checkConformance } from 'agentflow-core';
|
|
42
|
+
|
|
43
|
+
const model = discoverProcess(graphs); // build a process model from observed runs
|
|
44
|
+
const variants = findVariants(graphs); // group runs by their execution path
|
|
45
|
+
const bottlenecks = getBottlenecks(graphs); // rank nodes by cumulative wait time
|
|
46
|
+
const report = checkConformance(graph, model); // score a new run against the baseline
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
### Step 3 — Add guards
|
|
50
|
+
|
|
51
|
+
Guards detect runaway loops, spawn explosions, and policy violations at runtime. Wrap your builder with `withGuards` to activate them.
|
|
52
|
+
|
|
53
|
+
```ts
|
|
54
|
+
import { createGraphBuilder, withGuards, createSomaPolicySource } from 'agentflow-core';
|
|
55
|
+
|
|
56
|
+
const raw = createGraphBuilder({ agentId: 'my-agent' });
|
|
57
|
+
const guarded = withGuards(raw, {
|
|
58
|
+
maxDepth: 8,
|
|
59
|
+
maxReasoningSteps: 20,
|
|
60
|
+
onViolation: 'warn', // 'warn' | 'error' | 'abort'
|
|
61
|
+
policySource: myPolicySource, // optional: adaptive thresholds from Soma
|
|
62
|
+
});
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
## API highlights
|
|
66
|
+
|
|
67
|
+
| Export | Kind | Description |
|
|
68
|
+
|---|---|---|
|
|
69
|
+
| `createGraphBuilder` | factory | Build and mutate an execution graph during a run |
|
|
70
|
+
| `withGuards` | wrapper | Add runtime guard checks to any GraphBuilder |
|
|
71
|
+
| `checkGuards` | fn | Pure guard check on a graph snapshot |
|
|
72
|
+
| `getStats` | fn | Summary stats: node counts, status, duration |
|
|
73
|
+
| `getCriticalPath` | fn | Longest path through the graph by duration |
|
|
74
|
+
| `getFailures` | fn | All failed nodes with error metadata |
|
|
75
|
+
| `getHungNodes` | fn | Nodes that are running beyond their timeout |
|
|
76
|
+
| `discoverProcess` | fn | Build a process model from a run corpus |
|
|
77
|
+
| `findVariants` | fn | Group runs by execution path signature |
|
|
78
|
+
| `getBottlenecks` | fn | Rank nodes by cumulative elapsed time |
|
|
79
|
+
| `checkConformance` | fn | Score a run against a reference process model |
|
|
80
|
+
| `createInsightEngine` | factory | Tier-2 LLM analysis: anomaly, failure, and fix prompts |
|
|
81
|
+
| `createTraceStore` | factory | Persist and load graphs from disk |
|
|
82
|
+
| `createEventEmitter` | factory | Emit structured events during execution |
|
|
83
|
+
| `createJsonEventWriter` | factory | Write events to newline-delimited JSON |
|
|
84
|
+
| `createSomaEventWriter` | factory | Write events to a Soma inbox for ingestion |
|
|
85
|
+
| `createKnowledgeStore` | factory | Lightweight in-process key/value knowledge store |
|
|
86
|
+
| `createPolicySource` | factory | Static policy source for guard thresholds |
|
|
87
|
+
| `stitchTrace` | fn | Reconstruct a distributed trace from span events |
|
|
88
|
+
| `startLive` | fn | Live terminal monitor for a running agent |
|
|
89
|
+
| `startWatch` | fn | Headless watcher with alerting via notify channels |
|
|
90
|
+
| `auditProcesses` | fn | Audit OS processes, PIDs, and systemd units |
|
|
91
|
+
| `runTraced` | fn | Run a shell command with full execution tracing |
|
|
92
|
+
| `toAsciiTree` | fn | Render a graph as an ASCII tree |
|
|
93
|
+
| `toTimeline` | fn | Render a graph as a text timeline |
|
|
94
|
+
|
|
95
|
+
Full type definitions are bundled. All functions are pure unless noted as factory.
|
|
96
|
+
|
|
97
|
+
## Docs
|
|
98
|
+
|
|
99
|
+
[https://github.com/ClemenceChee/AgentFlow#readme](https://github.com/ClemenceChee/AgentFlow#readme)
|