agentid-sdk 0.1.18 → 0.1.20
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 +199 -38
- package/dist/chunk-LOZUJLLF.mjs +3222 -0
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +98 -29
- package/dist/index.mjs +10 -2724
- package/dist/{langchain-BykeB2WB.d.mts → langchain-BipmisU1.d.mts} +12 -3
- package/dist/{langchain-BykeB2WB.d.ts → langchain-BipmisU1.d.ts} +12 -3
- package/dist/langchain.d.mts +1 -1
- package/dist/langchain.d.ts +1 -1
- package/dist/langchain.js +190 -2
- package/dist/langchain.mjs +1 -1
- package/package.json +1 -1
- package/dist/chunk-6YR4ECGB.mjs +0 -424
package/README.md
CHANGED
|
@@ -1,65 +1,226 @@
|
|
|
1
|
-
#
|
|
1
|
+
# agentid-sdk (Node.js / TypeScript)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://www.npmjs.com/package/agentid-sdk)
|
|
4
|
+
[](https://www.npmjs.com/package/agentid-sdk)
|
|
5
|
+
[](https://nodejs.org/)
|
|
6
|
+
[](LICENSE)
|
|
4
7
|
|
|
5
|
-
##
|
|
8
|
+
## 1. Introduction
|
|
6
9
|
|
|
7
|
-
|
|
10
|
+
`agentid-sdk` is the official Node.js/TypeScript SDK for AgentID, an AI security and compliance System of Record. It allows you to gate LLM traffic through guard checks, enforce policy before execution, and capture durable telemetry for audit and governance workflows.
|
|
8
11
|
|
|
9
|
-
|
|
10
|
-
# Pro Python projekty
|
|
11
|
-
pip install agentid-sdk
|
|
12
|
+
### The Mental Model
|
|
12
13
|
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
AgentID sits between your application and the LLM runtime:
|
|
15
|
+
|
|
16
|
+
```text
|
|
17
|
+
User Input -> guard() -> [AgentID Policy] -> verdict
|
|
18
|
+
| allowed
|
|
19
|
+
v
|
|
20
|
+
LLM Provider
|
|
21
|
+
v
|
|
22
|
+
log() -> [Immutable Ledger]
|
|
15
23
|
```
|
|
16
24
|
|
|
17
|
-
|
|
25
|
+
- `guard()`: evaluates prompt and context before model execution.
|
|
26
|
+
- Model call: executes only if guard verdict is allowed.
|
|
27
|
+
- `log()`: persists immutable telemetry (prompt, output, latency) for audit and compliance.
|
|
18
28
|
|
|
19
|
-
|
|
29
|
+
## 2. Installation
|
|
20
30
|
|
|
21
|
-
```
|
|
22
|
-
|
|
23
|
-
|
|
31
|
+
```bash
|
|
32
|
+
npm install agentid-sdk
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
## 3. Prerequisites
|
|
24
36
|
|
|
25
|
-
|
|
26
|
-
|
|
37
|
+
1. Create an account at `https://app.getagentid.com`.
|
|
38
|
+
2. Create an AI system and copy:
|
|
39
|
+
- `AGENTID_API_KEY` (for example `sk_live_...`)
|
|
40
|
+
- `AGENTID_SYSTEM_ID` (UUID)
|
|
41
|
+
3. If using OpenAI/LangChain, set:
|
|
42
|
+
- `OPENAI_API_KEY`
|
|
27
43
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
)
|
|
44
|
+
```bash
|
|
45
|
+
export AGENTID_API_KEY="sk_live_..."
|
|
46
|
+
export AGENTID_SYSTEM_ID="00000000-0000-0000-0000-000000000000"
|
|
47
|
+
export OPENAI_API_KEY="sk-proj-..."
|
|
33
48
|
```
|
|
34
49
|
|
|
35
|
-
###
|
|
50
|
+
### Compatibility
|
|
51
|
+
|
|
52
|
+
- **Node.js:** v18+ / **Python:** 3.9+ (cross-SDK matrix)
|
|
53
|
+
- **Thread Safety:** AgentID clients are thread-safe and intended to be instantiated once and reused across concurrent requests.
|
|
54
|
+
- **Latency:** async `log()` is non-blocking for model execution paths; sync `guard()` typically adds network latency (commonly ~50-100ms, environment-dependent).
|
|
55
|
+
|
|
56
|
+
## 4. Quickstart
|
|
36
57
|
|
|
37
58
|
```ts
|
|
38
59
|
import { AgentID } from "agentid-sdk";
|
|
60
|
+
|
|
61
|
+
const agent = new AgentID(); // auto-loads AGENTID_API_KEY
|
|
62
|
+
const systemId = process.env.AGENTID_SYSTEM_ID!;
|
|
63
|
+
|
|
64
|
+
const verdict = await agent.guard({
|
|
65
|
+
system_id: systemId,
|
|
66
|
+
input: "Summarize this ticket in one sentence.",
|
|
67
|
+
model: "gpt-4o-mini",
|
|
68
|
+
user_id: "quickstart-user",
|
|
69
|
+
});
|
|
70
|
+
if (!verdict.allowed) throw new Error(`Blocked: ${verdict.reason}`);
|
|
71
|
+
|
|
72
|
+
await agent.log({
|
|
73
|
+
system_id: systemId,
|
|
74
|
+
event_id: verdict.client_event_id,
|
|
75
|
+
model: "gpt-4o-mini",
|
|
76
|
+
input: "Summarize this ticket in one sentence.",
|
|
77
|
+
output: "Summary generated.",
|
|
78
|
+
metadata: { agent_role: "support-assistant" },
|
|
79
|
+
});
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## 5. Core Integrations
|
|
83
|
+
|
|
84
|
+
### OpenAI Wrapper
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
npm install agentid-sdk openai
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
```ts
|
|
39
91
|
import OpenAI from "openai";
|
|
92
|
+
import { AgentID } from "agentid-sdk";
|
|
40
93
|
|
|
41
|
-
const openai = new OpenAI();
|
|
42
94
|
const agent = new AgentID({
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
95
|
+
piiMasking: true,
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
const openai = new OpenAI({ apiKey: process.env.OPENAI_API_KEY! });
|
|
99
|
+
const secured = agent.wrapOpenAI(openai, {
|
|
100
|
+
system_id: process.env.AGENTID_SYSTEM_ID!,
|
|
101
|
+
user_id: "customer-123",
|
|
47
102
|
});
|
|
48
103
|
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
104
|
+
const response = await secured.chat.completions.create({
|
|
105
|
+
model: "gpt-4o-mini",
|
|
106
|
+
messages: [{ role: "user", content: "What is the capital of the Czech Republic?" }],
|
|
52
107
|
});
|
|
108
|
+
|
|
109
|
+
console.log(response.choices[0]?.message?.content ?? "");
|
|
53
110
|
```
|
|
54
111
|
|
|
55
|
-
|
|
112
|
+
### LangChain Integration
|
|
113
|
+
|
|
114
|
+
```bash
|
|
115
|
+
npm install agentid-sdk openai @langchain/core @langchain/openai
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
```ts
|
|
119
|
+
import { AgentID } from "agentid-sdk";
|
|
120
|
+
import { AgentIDCallbackHandler } from "agentid-sdk/langchain";
|
|
121
|
+
import { ChatOpenAI } from "@langchain/openai";
|
|
122
|
+
import { ChatPromptTemplate } from "@langchain/core/prompts";
|
|
123
|
+
import { StringOutputParser } from "@langchain/core/output_parsers";
|
|
124
|
+
|
|
125
|
+
const agent = new AgentID();
|
|
126
|
+
const handler = new AgentIDCallbackHandler(agent, {
|
|
127
|
+
system_id: process.env.AGENTID_SYSTEM_ID!,
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
const prompt = ChatPromptTemplate.fromTemplate("Answer in one sentence: {question}");
|
|
131
|
+
const model = new ChatOpenAI({
|
|
132
|
+
apiKey: process.env.OPENAI_API_KEY!,
|
|
133
|
+
model: "gpt-4o-mini",
|
|
134
|
+
});
|
|
135
|
+
const chain = prompt.pipe(model).pipe(new StringOutputParser());
|
|
136
|
+
|
|
137
|
+
const result = await chain.invoke(
|
|
138
|
+
{ question: "What is the capital of the Czech Republic?" },
|
|
139
|
+
{ callbacks: [handler] }
|
|
140
|
+
);
|
|
141
|
+
console.log(result);
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
### Raw Ingest API (Telemetry Only)
|
|
145
|
+
|
|
146
|
+
```ts
|
|
147
|
+
import { AgentID } from "agentid-sdk";
|
|
148
|
+
|
|
149
|
+
const agent = new AgentID();
|
|
150
|
+
|
|
151
|
+
await agent.log({
|
|
152
|
+
system_id: process.env.AGENTID_SYSTEM_ID!,
|
|
153
|
+
event_type: "complete",
|
|
154
|
+
severity: "info",
|
|
155
|
+
model: "gpt-4o-mini",
|
|
156
|
+
input: "Raw telemetry prompt",
|
|
157
|
+
output: '{"ok": true}',
|
|
158
|
+
metadata: { agent_role: "batch-worker", channel: "manual_ingest" },
|
|
159
|
+
});
|
|
160
|
+
```
|
|
161
|
+
|
|
162
|
+
## 6. Advanced Configuration
|
|
163
|
+
|
|
164
|
+
### Custom identity / role metadata
|
|
165
|
+
|
|
166
|
+
```ts
|
|
167
|
+
await agent.guard({
|
|
168
|
+
system_id: process.env.AGENTID_SYSTEM_ID!,
|
|
169
|
+
input: "Process user request",
|
|
170
|
+
user_id: "service:billing-agent",
|
|
171
|
+
model: "gpt-4o-mini",
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
await agent.log({
|
|
175
|
+
system_id: process.env.AGENTID_SYSTEM_ID!,
|
|
176
|
+
model: "gpt-4o-mini",
|
|
177
|
+
input: "Process user request",
|
|
178
|
+
output: "Done",
|
|
179
|
+
metadata: { agent_role: "billing-agent", environment: "prod" },
|
|
180
|
+
});
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
### Strict mode and timeout tuning
|
|
184
|
+
|
|
185
|
+
```ts
|
|
186
|
+
const agent = new AgentID({
|
|
187
|
+
strictMode: true, // fail-closed on guard connectivity/timeouts
|
|
188
|
+
guardTimeoutMs: 10000, // default guard timeout is 10000ms
|
|
189
|
+
ingestTimeoutMs: 10000 // default ingest timeout is 10000ms
|
|
190
|
+
});
|
|
191
|
+
```
|
|
192
|
+
|
|
193
|
+
### Error Handling & Strict Mode
|
|
194
|
+
|
|
195
|
+
By default, AgentID is designed to keep your application running if the AgentID API has a timeout or is temporarily unreachable.
|
|
196
|
+
|
|
197
|
+
| Mode | Connectivity Failure | LLM Execution | Best For |
|
|
198
|
+
| :--- | :--- | :--- | :--- |
|
|
199
|
+
| **Default** (Strict Off) | API Timeout / Unreachable | **Fail-Open** (continues) | Standard SaaS, chatbots |
|
|
200
|
+
| **Strict Mode** (`strictMode: true`) | API Timeout / Unreachable | **Fail-Closed** (blocks) | Healthcare, FinTech, high-risk |
|
|
201
|
+
|
|
202
|
+
- `guard()` returns a verdict (`allowed`, `reason`); handle deny paths explicitly.
|
|
203
|
+
- `wrapOpenAI()` and LangChain handlers throw `SecurityBlockError` when a prompt is blocked.
|
|
204
|
+
- If `strictMode` is not explicitly set in SDK code, runtime behavior follows the system configuration from AgentID (`strict_security_mode` / `failure_mode`).
|
|
205
|
+
- Ingest retries transient failures (5xx/429) and logs warnings if persistence fails.
|
|
206
|
+
|
|
207
|
+
## 7. Security & Compliance
|
|
208
|
+
|
|
209
|
+
- Optional local PII masking and local policy enforcement before model dispatch.
|
|
210
|
+
- Prompt-injection scanning in the SDK request path.
|
|
211
|
+
- Guard checks run pre-execution; ingest telemetry captures prompt/output lifecycle.
|
|
212
|
+
- Safe for server and serverless runtimes (including async completion flows).
|
|
213
|
+
- Supports compliance and forensics workflows with durable event records.
|
|
214
|
+
|
|
215
|
+
## 8. Support
|
|
216
|
+
|
|
217
|
+
- Dashboard: `https://app.getagentid.com`
|
|
218
|
+
- Repository: `https://github.com/ondrejsukac-rgb/agentid/tree/main/js-sdk`
|
|
219
|
+
- Issues: `https://github.com/ondrejsukac-rgb/agentid/issues`
|
|
56
220
|
|
|
57
|
-
|
|
58
|
-
- Crypto-Shredding: Možnost nenávratně smazat citlivá data z logů na žádost uživatele (GDPR).
|
|
59
|
-
- Fail-Safe architektura: Inteligentní přepínání mezi bezpečností a dostupností (Fail-Open/Closed).
|
|
60
|
-
- Strict mode: při timeoutu Guard API můžeš vynutit fail-closed (`strictMode: true`).
|
|
221
|
+
## 9. Publishing Notes (NPM)
|
|
61
222
|
|
|
62
|
-
|
|
223
|
+
NPM automatically renders `README.md` from the package root during `npm publish`.
|
|
63
224
|
|
|
64
|
-
|
|
65
|
-
|
|
225
|
+
- File location: next to `package.json` in `js-sdk/`.
|
|
226
|
+
- No additional NPM config is required for README rendering.
|