agentcheck-sdk 1.0.1 → 2.0.0
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/dist/cache.d.ts +78 -0
- package/dist/cache.js +155 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +24 -1
- package/dist/integrations/autogen.d.ts +50 -0
- package/dist/integrations/autogen.js +93 -0
- package/dist/integrations/crewai.d.ts +49 -0
- package/dist/integrations/crewai.js +107 -0
- package/dist/integrations/index.d.ts +8 -0
- package/dist/integrations/index.js +17 -0
- package/dist/integrations/langchain.d.ts +63 -0
- package/dist/integrations/langchain.js +104 -0
- package/dist/pipeline.d.ts +24 -0
- package/dist/pipeline.js +84 -48
- package/dist/pqc/dsse.d.ts +47 -0
- package/dist/pqc/dsse.js +113 -0
- package/dist/pqc/index.d.ts +11 -0
- package/dist/pqc/index.js +18 -0
- package/dist/pqc/signer.d.ts +44 -0
- package/dist/pqc/signer.js +97 -0
- package/dist/pqc/verifier.d.ts +49 -0
- package/dist/pqc/verifier.js +93 -0
- package/dist/router.d.ts +78 -0
- package/dist/router.js +102 -0
- package/dist/safety.d.ts +66 -7
- package/dist/safety.js +85 -1
- package/dist/semantic.d.ts +14 -2
- package/dist/semantic.js +22 -10
- package/dist/templates.d.ts +130 -1
- package/dist/templates.js +275 -12
- package/dist/trust.d.ts +97 -0
- package/dist/trust.js +146 -0
- package/package.json +2 -2
package/dist/trust.js
ADDED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Trust Engine - Agent trust scoring and outcome tracking.
|
|
4
|
+
*
|
|
5
|
+
* Tier: Atom (single responsibility: compute and track agent trust scores)
|
|
6
|
+
*
|
|
7
|
+
* Computes a trust score (0.0 to 1.0) per agent based on execution history.
|
|
8
|
+
* The score drives dynamic layer routing in LayerRouter.
|
|
9
|
+
*
|
|
10
|
+
* Score formula:
|
|
11
|
+
* score = successRate * ageFactor * violationPenalty
|
|
12
|
+
*
|
|
13
|
+
* Where:
|
|
14
|
+
* - successRate: fraction of successes in the last 100 outcomes
|
|
15
|
+
* - ageFactor: min(1.0, historySize / 20) - new agents get lower trust
|
|
16
|
+
* - violationPenalty: 0.9 ^ violationCount
|
|
17
|
+
*
|
|
18
|
+
* Tier assignment:
|
|
19
|
+
* - "high": score >= highThreshold (default 0.8)
|
|
20
|
+
* - "medium": lowThreshold <= score < highThreshold
|
|
21
|
+
* - "low": score < lowThreshold (default 0.5)
|
|
22
|
+
*/
|
|
23
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
24
|
+
exports.TrustEngine = void 0;
|
|
25
|
+
const HISTORY_WINDOW = 100;
|
|
26
|
+
class TrustEngine {
|
|
27
|
+
constructor(highThreshold = 0.8, lowThreshold = 0.5) {
|
|
28
|
+
/**
|
|
29
|
+
* Compute and track trust scores for agents.
|
|
30
|
+
*
|
|
31
|
+
* Maintains per-agent execution history and recomputes scores after
|
|
32
|
+
* each recorded outcome. New agents receive a default medium-trust
|
|
33
|
+
* score until enough history accumulates.
|
|
34
|
+
*
|
|
35
|
+
* Usage:
|
|
36
|
+
* const engine = new TrustEngine();
|
|
37
|
+
* engine.recordOutcome("bot-001", true);
|
|
38
|
+
* const score = engine.getScore("bot-001");
|
|
39
|
+
* // TrustScore { agentId: "bot-001", score: 0.05, tier: "low", ... }
|
|
40
|
+
*/
|
|
41
|
+
this.scores = new Map();
|
|
42
|
+
this.history = new Map();
|
|
43
|
+
this.violations = new Map();
|
|
44
|
+
this.high = highThreshold;
|
|
45
|
+
this.low = lowThreshold;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* Return the current trust score for an agent.
|
|
49
|
+
*
|
|
50
|
+
* If the agent has no recorded history, returns a default medium-trust
|
|
51
|
+
* score with a score value halfway between the two thresholds.
|
|
52
|
+
*
|
|
53
|
+
* @param agentId - The agent identifier.
|
|
54
|
+
* @returns TrustScore with score, tier, and diagnostic factors.
|
|
55
|
+
*/
|
|
56
|
+
getScore(agentId) {
|
|
57
|
+
const cached = this.scores.get(agentId);
|
|
58
|
+
if (cached)
|
|
59
|
+
return cached;
|
|
60
|
+
const defaultScore = (this.high + this.low) / 2.0;
|
|
61
|
+
return {
|
|
62
|
+
agentId,
|
|
63
|
+
score: defaultScore,
|
|
64
|
+
tier: "medium",
|
|
65
|
+
factors: { historySize: 0, note: "no history - default medium" },
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Record one execution outcome and recompute the trust score.
|
|
70
|
+
*
|
|
71
|
+
* @param agentId - The agent identifier.
|
|
72
|
+
* @param success - True if the execution completed without error or
|
|
73
|
+
* violation, false otherwise.
|
|
74
|
+
* @param details - Optional details. When details.violation is true,
|
|
75
|
+
* the violation counter increments.
|
|
76
|
+
*/
|
|
77
|
+
recordOutcome(agentId, success, details) {
|
|
78
|
+
// Update history (keep last HISTORY_WINDOW outcomes)
|
|
79
|
+
const hist = this.history.get(agentId) ?? [];
|
|
80
|
+
hist.push(success);
|
|
81
|
+
if (hist.length > HISTORY_WINDOW)
|
|
82
|
+
hist.shift();
|
|
83
|
+
this.history.set(agentId, hist);
|
|
84
|
+
// Track violations separately from plain failures
|
|
85
|
+
if (details?.violation) {
|
|
86
|
+
this.violations.set(agentId, (this.violations.get(agentId) ?? 0) + 1);
|
|
87
|
+
}
|
|
88
|
+
// Recompute and cache
|
|
89
|
+
const score = this.computeScore(agentId);
|
|
90
|
+
const tier = this.scoreToTier(score);
|
|
91
|
+
const histLen = hist.length;
|
|
92
|
+
const violationCount = this.violations.get(agentId) ?? 0;
|
|
93
|
+
this.scores.set(agentId, {
|
|
94
|
+
agentId,
|
|
95
|
+
score: Math.round(score * 10000) / 10000,
|
|
96
|
+
tier,
|
|
97
|
+
factors: {
|
|
98
|
+
successRate: Math.round((hist.filter(Boolean).length / histLen) * 10000) / 10000,
|
|
99
|
+
historySize: histLen,
|
|
100
|
+
violationCount,
|
|
101
|
+
ageFactor: Math.round(Math.min(1.0, histLen / 20.0) * 10000) / 10000,
|
|
102
|
+
},
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* Reset all trust data for an agent.
|
|
107
|
+
*
|
|
108
|
+
* Removes history, violation count, and cached score so the agent
|
|
109
|
+
* reverts to default medium trust on the next call to getScore().
|
|
110
|
+
*
|
|
111
|
+
* @param agentId - The agent identifier.
|
|
112
|
+
*/
|
|
113
|
+
reset(agentId) {
|
|
114
|
+
this.history.delete(agentId);
|
|
115
|
+
this.violations.delete(agentId);
|
|
116
|
+
this.scores.delete(agentId);
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Return the cached scores for all tracked agents.
|
|
120
|
+
*
|
|
121
|
+
* @returns Map of agentId to TrustScore. Only includes agents with at
|
|
122
|
+
* least one recorded outcome.
|
|
123
|
+
*/
|
|
124
|
+
allScores() {
|
|
125
|
+
return new Map(this.scores);
|
|
126
|
+
}
|
|
127
|
+
// -- Private helpers --
|
|
128
|
+
computeScore(agentId) {
|
|
129
|
+
const hist = this.history.get(agentId);
|
|
130
|
+
if (!hist || hist.length === 0)
|
|
131
|
+
return (this.high + this.low) / 2.0;
|
|
132
|
+
const successRate = hist.filter(Boolean).length / hist.length;
|
|
133
|
+
const ageFactor = Math.min(1.0, hist.length / 20.0);
|
|
134
|
+
const violationCount = this.violations.get(agentId) ?? 0;
|
|
135
|
+
const violationPenalty = Math.pow(0.9, violationCount);
|
|
136
|
+
return successRate * ageFactor * violationPenalty;
|
|
137
|
+
}
|
|
138
|
+
scoreToTier(score) {
|
|
139
|
+
if (score >= this.high)
|
|
140
|
+
return "high";
|
|
141
|
+
if (score >= this.low)
|
|
142
|
+
return "medium";
|
|
143
|
+
return "low";
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
exports.TrustEngine = TrustEngine;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "agentcheck-sdk",
|
|
3
|
-
"version": "
|
|
4
|
-
"description": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "AI Agent Delegation Governance SDK - Zero Trust verification, PQC audit, dynamic safety routing",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"types": "dist/index.d.ts",
|
|
7
7
|
"files": [
|