@agenttool/sdk 0.2.3 → 0.2.5
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 +106 -78
- package/dist/index.d.ts +1 -1
- package/dist/memory.d.ts +10 -0
- package/dist/memory.js +32 -0
- package/dist/tools.d.ts +15 -1
- package/dist/tools.js +22 -0
- package/dist/types.d.ts +15 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
# @agenttool/sdk · TypeScript
|
|
2
2
|
|
|
3
|
-
> Persistent memory,
|
|
3
|
+
> Persistent memory, reasoning traces, fact verification, tool access, and agent-to-agent payments — one API key.
|
|
4
4
|
|
|
5
5
|
[](https://www.npmjs.com/package/@agenttool/sdk)
|
|
6
6
|
[](https://www.typescriptlang.org/)
|
|
7
7
|
[](LICENSE)
|
|
8
|
+
[](https://api.agenttool.dev/health)
|
|
8
9
|
|
|
9
10
|
```bash
|
|
10
11
|
npm install @agenttool/sdk
|
|
@@ -19,11 +20,12 @@ AgentTool gives AI agents the infrastructure they need to operate reliably:
|
|
|
19
20
|
| Service | What it does |
|
|
20
21
|
|---------|-------------|
|
|
21
22
|
| **agent-memory** | Persistent semantic memory — store facts, retrieve by similarity |
|
|
22
|
-
| **agent-tools** | Web search, page scraping, code execution |
|
|
23
|
-
| **agent-verify** |
|
|
24
|
-
| **agent-economy** | Wallets,
|
|
23
|
+
| **agent-tools** | Web search, page scraping, sandboxed code execution |
|
|
24
|
+
| **agent-verify** | Fact-check claims with AI-powered evidence gathering |
|
|
25
|
+
| **agent-economy** | Wallets, spending policies, escrow, agent-to-agent payments |
|
|
26
|
+
| **agent-trace** | Reasoning provenance — log and search decision traces |
|
|
25
27
|
|
|
26
|
-
All
|
|
28
|
+
All five services, one API key, one SDK.
|
|
27
29
|
|
|
28
30
|
## Quick start (60 seconds)
|
|
29
31
|
|
|
@@ -53,8 +55,8 @@ const results = await at.memory.search({
|
|
|
53
55
|
limit: 5,
|
|
54
56
|
});
|
|
55
57
|
|
|
56
|
-
for (const
|
|
57
|
-
console.log(`${
|
|
58
|
+
for (const r of results) {
|
|
59
|
+
console.log(`${r.score.toFixed(2)} ${r.content}`);
|
|
58
60
|
}
|
|
59
61
|
```
|
|
60
62
|
|
|
@@ -63,78 +65,117 @@ for (const result of results) {
|
|
|
63
65
|
### Memory
|
|
64
66
|
|
|
65
67
|
```typescript
|
|
66
|
-
import { AgentTool } from "@agenttool/sdk";
|
|
67
|
-
|
|
68
68
|
const at = new AgentTool({ apiKey: "at_..." }); // or use AT_API_KEY env var
|
|
69
69
|
|
|
70
70
|
// Store
|
|
71
|
-
const mem = await at.memory.store({
|
|
72
|
-
content: "User is based in London, timezone Europe/London",
|
|
73
|
-
});
|
|
71
|
+
const mem = await at.memory.store({ content: "User is in London, timezone Europe/London" });
|
|
74
72
|
|
|
75
|
-
//
|
|
76
|
-
const results = await at.memory.search({ query: "where is the user?" });
|
|
73
|
+
// Semantic search
|
|
74
|
+
const results = await at.memory.search({ query: "where is the user?", limit: 5 });
|
|
77
75
|
|
|
78
76
|
// Retrieve by ID
|
|
79
|
-
const
|
|
77
|
+
const mem = await at.memory.get("mem_abc123");
|
|
80
78
|
|
|
81
|
-
//
|
|
82
|
-
await at.memory.
|
|
79
|
+
// Usage stats
|
|
80
|
+
const stats = await at.memory.usage();
|
|
81
|
+
console.log(stats.memoriesStored, stats.searchesPerformed);
|
|
83
82
|
```
|
|
84
83
|
|
|
85
84
|
### Tools
|
|
86
85
|
|
|
87
86
|
```typescript
|
|
88
87
|
// Web search
|
|
89
|
-
const results = await at.tools.search(
|
|
90
|
-
for (const r of results)
|
|
91
|
-
console.log(r.title, r.url);
|
|
92
|
-
}
|
|
88
|
+
const results = await at.tools.search("latest papers on RAG", { numResults: 5 });
|
|
89
|
+
for (const r of results) console.log(r.title, r.url);
|
|
93
90
|
|
|
94
91
|
// Scrape a page
|
|
95
|
-
const page = await at.tools.scrape(
|
|
96
|
-
console.log(page.
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
92
|
+
const page = await at.tools.scrape("https://example.com");
|
|
93
|
+
console.log(page.content); // page text/HTML
|
|
94
|
+
console.log(page.statusCode);
|
|
95
|
+
|
|
96
|
+
// Execute code (sandboxed — Python, JavaScript, Bash)
|
|
97
|
+
const result = await at.tools.execute("print(42)", { language: "python" });
|
|
98
|
+
console.log(result.output); // stdout
|
|
99
|
+
console.log(result.error); // stderr
|
|
100
|
+
console.log(result.exitCode); // 0 = success
|
|
101
101
|
```
|
|
102
102
|
|
|
103
103
|
### Verify
|
|
104
104
|
|
|
105
105
|
```typescript
|
|
106
|
-
//
|
|
107
|
-
const
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
106
|
+
// Fact-check a claim with AI-powered evidence gathering
|
|
107
|
+
const result = await at.verify.check("The Eiffel Tower is 330 metres tall.");
|
|
108
|
+
console.log(result.verdict); // "verified" | "false" | "disputed" | "unverifiable"
|
|
109
|
+
console.log(result.confidence); // 0.0 – 1.0
|
|
110
|
+
console.log(result.caveats); // string[] of nuances
|
|
111
|
+
|
|
112
|
+
// With domain hint for better evidence
|
|
113
|
+
const r = await at.verify.check("Bitcoin was created in 2009.", {
|
|
114
|
+
domain: "finance", // "finance" | "science" | "medical" | "legal" | "general"
|
|
115
|
+
context: "On the whitepaper publication date",
|
|
111
116
|
});
|
|
112
|
-
console.log(proof.attestationId, proof.hash);
|
|
113
|
-
|
|
114
|
-
// Verify an attestation
|
|
115
|
-
const result = await at.verify.check("att_...");
|
|
116
|
-
console.log(result.valid); // true
|
|
117
117
|
```
|
|
118
118
|
|
|
119
|
-
### Economy
|
|
119
|
+
### Economy (wallets & escrows)
|
|
120
120
|
|
|
121
121
|
```typescript
|
|
122
122
|
// Create a wallet
|
|
123
|
-
const wallet = await at.economy.createWallet({ name: "agent-wallet" });
|
|
123
|
+
const wallet = await at.economy.createWallet({ name: "agent-wallet", agentId: "agent-42" });
|
|
124
124
|
|
|
125
|
-
//
|
|
126
|
-
|
|
125
|
+
// Fund it
|
|
126
|
+
await at.economy.fundWallet(wallet.id, { amount: 500, description: "Weekly budget" });
|
|
127
127
|
|
|
128
|
-
//
|
|
129
|
-
await at.economy.
|
|
130
|
-
fromWallet: wallet.id,
|
|
131
|
-
toWallet: "wlt_...",
|
|
128
|
+
// Spend credits
|
|
129
|
+
await at.economy.spend(wallet.id, {
|
|
132
130
|
amount: 10,
|
|
133
|
-
|
|
131
|
+
counterparty: "wal_target_id",
|
|
132
|
+
description: "Payment for research task",
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
// Set a spending policy
|
|
136
|
+
await at.economy.setPolicy(wallet.id, {
|
|
137
|
+
maxPerTransaction: 50,
|
|
138
|
+
maxPerHour: 200,
|
|
139
|
+
maxPerDay: 1000,
|
|
140
|
+
});
|
|
141
|
+
|
|
142
|
+
// Escrow: lock credits until work is done
|
|
143
|
+
const escrow = await at.economy.createEscrow({
|
|
144
|
+
creatorWalletId: wallet.id,
|
|
145
|
+
amount: 100,
|
|
146
|
+
description: "Summarise 50 research papers",
|
|
147
|
+
deadline: "2026-03-14T12:00:00Z",
|
|
148
|
+
});
|
|
149
|
+
// Worker accepts:
|
|
150
|
+
await at.economy.acceptEscrow(escrow.id, "wal_worker");
|
|
151
|
+
// Release on completion:
|
|
152
|
+
await at.economy.releaseEscrow(escrow.id);
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Traces (reasoning provenance)
|
|
156
|
+
|
|
157
|
+
```typescript
|
|
158
|
+
// Store a reasoning trace
|
|
159
|
+
const trace = await at.traces.store({
|
|
160
|
+
step: "web_search",
|
|
161
|
+
input: { query: "climate change solutions" },
|
|
162
|
+
output: { results: ["..."] },
|
|
163
|
+
});
|
|
164
|
+
|
|
165
|
+
// Semantic search across traces
|
|
166
|
+
const results = await at.traces.search({
|
|
167
|
+
query: "decisions about climate data",
|
|
168
|
+
limit: 5,
|
|
134
169
|
});
|
|
170
|
+
|
|
171
|
+
// Get a chain of reasoning steps
|
|
172
|
+
const chain = await at.traces.chain("parent_trace_id");
|
|
173
|
+
|
|
174
|
+
// Delete
|
|
175
|
+
await at.traces.delete(trace.id);
|
|
135
176
|
```
|
|
136
177
|
|
|
137
|
-
## Integration example — Vercel AI SDK
|
|
178
|
+
## Integration example — LangChain / Vercel AI SDK
|
|
138
179
|
|
|
139
180
|
```typescript
|
|
140
181
|
import { AgentTool } from "@agenttool/sdk";
|
|
@@ -143,48 +184,34 @@ import { z } from "zod";
|
|
|
143
184
|
|
|
144
185
|
const at = new AgentTool();
|
|
145
186
|
|
|
146
|
-
|
|
187
|
+
const tools = {
|
|
147
188
|
remember: tool({
|
|
148
189
|
description: "Store a memory for later retrieval",
|
|
149
190
|
parameters: z.object({ content: z.string() }),
|
|
150
191
|
execute: async ({ content }) => {
|
|
151
|
-
const mem = await at.memory.store({ content, agentId: "
|
|
152
|
-
return
|
|
192
|
+
const mem = await at.memory.store({ content, agentId: "my-agent" });
|
|
193
|
+
return `Stored memory ${mem.id}`;
|
|
153
194
|
},
|
|
154
195
|
}),
|
|
155
196
|
recall: tool({
|
|
156
197
|
description: "Search past memories by semantic similarity",
|
|
157
198
|
parameters: z.object({ query: z.string() }),
|
|
158
199
|
execute: async ({ query }) => {
|
|
159
|
-
const results = await at.memory.search({ query, limit:
|
|
160
|
-
return results.map((r) =>
|
|
200
|
+
const results = await at.memory.search({ query, limit: 3 });
|
|
201
|
+
return results.map((r) => r.content).join("\n");
|
|
202
|
+
},
|
|
203
|
+
}),
|
|
204
|
+
factCheck: tool({
|
|
205
|
+
description: "Verify whether a factual claim is true",
|
|
206
|
+
parameters: z.object({ claim: z.string() }),
|
|
207
|
+
execute: async ({ claim }) => {
|
|
208
|
+
const result = await at.verify.check(claim);
|
|
209
|
+
return `${result.verdict} (${(result.confidence * 100).toFixed(0)}% confidence)`;
|
|
161
210
|
},
|
|
162
211
|
}),
|
|
163
212
|
};
|
|
164
213
|
```
|
|
165
214
|
|
|
166
|
-
## Integration example — any agent loop
|
|
167
|
-
|
|
168
|
-
```typescript
|
|
169
|
-
import { AgentTool } from "@agenttool/sdk";
|
|
170
|
-
|
|
171
|
-
const at = new AgentTool();
|
|
172
|
-
|
|
173
|
-
async function agentLoop(userMessage: string): Promise<string> {
|
|
174
|
-
// Recall relevant memories
|
|
175
|
-
const memories = await at.memory.search({ query: userMessage, limit: 5 });
|
|
176
|
-
const context = memories.map((m) => m.content).join("\n");
|
|
177
|
-
|
|
178
|
-
// Call your LLM with context
|
|
179
|
-
const response = await yourLLM(`Context:\n${context}\n\nUser: ${userMessage}`);
|
|
180
|
-
|
|
181
|
-
// Store the exchange
|
|
182
|
-
await at.memory.store({ content: `User: ${userMessage}\nAgent: ${response}` });
|
|
183
|
-
|
|
184
|
-
return response;
|
|
185
|
-
}
|
|
186
|
-
```
|
|
187
|
-
|
|
188
215
|
## Free tier
|
|
189
216
|
|
|
190
217
|
| Resource | Free | Seed ($29/mo) | Grow ($99/mo) |
|
|
@@ -192,6 +219,7 @@ async function agentLoop(userMessage: string): Promise<string> {
|
|
|
192
219
|
| Memory ops/day | 100 | 10,000 | 100,000 |
|
|
193
220
|
| Tool calls/day | 10 | 500 | 5,000 |
|
|
194
221
|
| Verifications/day | 5 | 100 | 1,000 |
|
|
222
|
+
| Traces/day | 100 | 10,000 | 100,000 |
|
|
195
223
|
|
|
196
224
|
[Upgrade at app.agenttool.dev/billing](https://app.agenttool.dev/billing)
|
|
197
225
|
|
|
@@ -201,9 +229,9 @@ async function agentLoop(userMessage: string): Promise<string> {
|
|
|
201
229
|
import { AgentTool } from "@agenttool/sdk";
|
|
202
230
|
|
|
203
231
|
const at = new AgentTool({
|
|
204
|
-
apiKey: "at_...",
|
|
205
|
-
baseUrl: "https://api.agenttool.dev",
|
|
206
|
-
timeout: 30_000,
|
|
232
|
+
apiKey: "at_...", // default: AT_API_KEY env var
|
|
233
|
+
baseUrl: "https://api.agenttool.dev", // default
|
|
234
|
+
timeout: 30_000, // ms
|
|
207
235
|
});
|
|
208
236
|
```
|
|
209
237
|
|
|
@@ -213,7 +241,7 @@ const at = new AgentTool({
|
|
|
213
241
|
- 📖 [docs.agenttool.dev](https://docs.agenttool.dev)
|
|
214
242
|
- 🎛️ [app.agenttool.dev](https://app.agenttool.dev) — dashboard + API key
|
|
215
243
|
- 📦 [npm](https://www.npmjs.com/package/@agenttool/sdk)
|
|
216
|
-
- 🐍 [Python SDK](https://github.com/
|
|
244
|
+
- 🐍 [Python SDK](https://github.com/mynameisyou-cmyk/agenttool-sdk-py)
|
|
217
245
|
|
|
218
246
|
## License
|
|
219
247
|
|
package/dist/index.d.ts
CHANGED
|
@@ -12,4 +12,4 @@
|
|
|
12
12
|
export { AgentTool } from "./client.js";
|
|
13
13
|
export { AgentToolError } from "./errors.js";
|
|
14
14
|
export type { Trace, StoreTraceOptions, SearchTracesOptions, TraceSearchResult, TraceChain } from "./traces.js";
|
|
15
|
-
export type { CreateEscrowOptions, CreateWalletOptions, Escrow, ExecuteResult, Memory, ScrapeResult, SearchMemoryOptions, SearchResponse, SearchResult, StoreOptions, UsageStats, VerifyResult, Wallet, WalletPolicy, } from "./types.js";
|
|
15
|
+
export type { CreateEscrowOptions, CreateWalletOptions, DocumentResult, Escrow, ExecuteResult, ParseDocumentOptions, Memory, ScrapeResult, SearchMemoryOptions, SearchResponse, SearchResult, StoreOptions, UsageStats, VerifyResult, Wallet, WalletPolicy, } from "./types.js";
|
package/dist/memory.d.ts
CHANGED
|
@@ -51,6 +51,16 @@ export declare class MemoryClient {
|
|
|
51
51
|
* @returns UsageStats with current counters.
|
|
52
52
|
*/
|
|
53
53
|
usage(): Promise<UsageStats>;
|
|
54
|
+
/**
|
|
55
|
+
* Delete a memory by ID.
|
|
56
|
+
* @param memoryId - UUID of the memory to delete.
|
|
57
|
+
*/
|
|
58
|
+
delete(memoryId: string): Promise<void>;
|
|
59
|
+
/**
|
|
60
|
+
* Delete all memories with a given key.
|
|
61
|
+
* @param key - The key shared by memories to delete.
|
|
62
|
+
*/
|
|
63
|
+
deleteByKey(key: string): Promise<void>;
|
|
54
64
|
private post;
|
|
55
65
|
private fetch;
|
|
56
66
|
}
|
package/dist/memory.js
CHANGED
|
@@ -79,6 +79,38 @@ export class MemoryClient {
|
|
|
79
79
|
const resp = await this.fetch("GET", "/v1/usage");
|
|
80
80
|
return resp;
|
|
81
81
|
}
|
|
82
|
+
/**
|
|
83
|
+
* Delete a memory by ID.
|
|
84
|
+
* @param memoryId - UUID of the memory to delete.
|
|
85
|
+
*/
|
|
86
|
+
async delete(memoryId) {
|
|
87
|
+
await this.fetch("DELETE", `/v1/memories/${memoryId}`);
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Delete all memories with a given key.
|
|
91
|
+
* @param key - The key shared by memories to delete.
|
|
92
|
+
*/
|
|
93
|
+
async deleteByKey(key) {
|
|
94
|
+
const url = `${this.http.baseUrl}/v1/memories?key=${encodeURIComponent(key)}`;
|
|
95
|
+
const resp = await globalThis.fetch(url, {
|
|
96
|
+
method: "DELETE",
|
|
97
|
+
headers: this.http.headers,
|
|
98
|
+
signal: AbortSignal.timeout(this.http.timeout),
|
|
99
|
+
});
|
|
100
|
+
if (resp.status >= 400) {
|
|
101
|
+
let detail;
|
|
102
|
+
try {
|
|
103
|
+
const json = (await resp.json());
|
|
104
|
+
detail = json.detail ?? resp.statusText;
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
detail = resp.statusText;
|
|
108
|
+
}
|
|
109
|
+
throw new AgentToolError(`Memory API error (${resp.status}): ${detail}`, {
|
|
110
|
+
hint: "Check your API key and memory key.",
|
|
111
|
+
});
|
|
112
|
+
}
|
|
113
|
+
}
|
|
82
114
|
// --- internal ---
|
|
83
115
|
async post(path, body) {
|
|
84
116
|
return this.fetch("POST", path, body);
|
package/dist/tools.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Tools client for the agent-tools API.
|
|
3
3
|
*/
|
|
4
|
-
import type { ExecuteResult, ScrapeResult, SearchResponse } from "./types.js";
|
|
4
|
+
import type { DocumentResult, ExecuteResult, ParseDocumentOptions, ScrapeResult, SearchResponse } from "./types.js";
|
|
5
5
|
import type { HttpConfig } from "./memory.js";
|
|
6
6
|
/**
|
|
7
7
|
* Client for the agent-tools API (search, scrape, execute).
|
|
@@ -45,5 +45,19 @@ export declare class ToolsClient {
|
|
|
45
45
|
execute(code: string, options?: {
|
|
46
46
|
language?: string;
|
|
47
47
|
}): Promise<ExecuteResult>;
|
|
48
|
+
/**
|
|
49
|
+
* Parse a document and extract readable text.
|
|
50
|
+
* Supports HTML (via Readability) and plain text.
|
|
51
|
+
*
|
|
52
|
+
* @param options - Either `url` (fetched server-side) or `base64` encoded content.
|
|
53
|
+
* @returns DocumentResult with title, content, word_count, metadata.
|
|
54
|
+
*
|
|
55
|
+
* @example
|
|
56
|
+
* ```ts
|
|
57
|
+
* const doc = await at.tools.parseDocument({ url: "https://example.com/paper.html" });
|
|
58
|
+
* console.log(doc.title, doc.word_count);
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
parseDocument(options: ParseDocumentOptions): Promise<DocumentResult>;
|
|
48
62
|
private post;
|
|
49
63
|
}
|
package/dist/tools.js
CHANGED
|
@@ -67,6 +67,28 @@ export class ToolsClient {
|
|
|
67
67
|
const data = await this.post("/v1/execute", body);
|
|
68
68
|
return data;
|
|
69
69
|
}
|
|
70
|
+
/**
|
|
71
|
+
* Parse a document and extract readable text.
|
|
72
|
+
* Supports HTML (via Readability) and plain text.
|
|
73
|
+
*
|
|
74
|
+
* @param options - Either `url` (fetched server-side) or `base64` encoded content.
|
|
75
|
+
* @returns DocumentResult with title, content, word_count, metadata.
|
|
76
|
+
*
|
|
77
|
+
* @example
|
|
78
|
+
* ```ts
|
|
79
|
+
* const doc = await at.tools.parseDocument({ url: "https://example.com/paper.html" });
|
|
80
|
+
* console.log(doc.title, doc.word_count);
|
|
81
|
+
* ```
|
|
82
|
+
*/
|
|
83
|
+
async parseDocument(options) {
|
|
84
|
+
if (!options.url && !options.base64) {
|
|
85
|
+
throw new AgentToolError("parseDocument requires either url or base64.", {
|
|
86
|
+
hint: "Pass { url: '...' } or { base64: '...', content_type: 'text/html' }",
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
const data = await this.post("/v1/document/document", options);
|
|
90
|
+
return data;
|
|
91
|
+
}
|
|
70
92
|
// --- internal ---
|
|
71
93
|
async post(path, body) {
|
|
72
94
|
const url = `${this.http.baseUrl}${path}`;
|
package/dist/types.d.ts
CHANGED
|
@@ -56,6 +56,21 @@ export interface ScrapeResult {
|
|
|
56
56
|
status_code: number;
|
|
57
57
|
[key: string]: unknown;
|
|
58
58
|
}
|
|
59
|
+
/** Result of document parsing. */
|
|
60
|
+
export interface DocumentResult {
|
|
61
|
+
title: string;
|
|
62
|
+
content: string;
|
|
63
|
+
word_count: number;
|
|
64
|
+
content_type: string;
|
|
65
|
+
metadata: Record<string, unknown>;
|
|
66
|
+
duration_ms: number;
|
|
67
|
+
}
|
|
68
|
+
/** Options for document parsing. */
|
|
69
|
+
export interface ParseDocumentOptions {
|
|
70
|
+
url?: string;
|
|
71
|
+
base64?: string;
|
|
72
|
+
content_type?: string;
|
|
73
|
+
}
|
|
59
74
|
/** Result of sandboxed code execution. */
|
|
60
75
|
export interface ExecuteResult {
|
|
61
76
|
stdout: string;
|