@tanmaysangam018/crossagent 0.0.0-stage → 0.2.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/README.md +179 -2
- package/dist/index.d.ts +59 -0
- package/dist/index.js +72 -0
- package/package.json +42 -4
package/README.md
CHANGED
|
@@ -1,3 +1,180 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @tanmaysangam018/crossagent (Engram SDK)
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Persistent memory + cognitive security layer for AI applications.
|
|
4
|
+
|
|
5
|
+
Store what your users tell any AI. Search it semantically. Scan every AI response for prompt injection before you act on it.
|
|
6
|
+
|
|
7
|
+
```bash
|
|
8
|
+
npm install @tanmaysangam018/crossagent
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
---
|
|
12
|
+
|
|
13
|
+
## Quick start
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
import { Crossagent } from 'crossagent'
|
|
17
|
+
|
|
18
|
+
const ca = new Crossagent()
|
|
19
|
+
|
|
20
|
+
// Store a memory after any AI conversation
|
|
21
|
+
await ca.memory.add({
|
|
22
|
+
userId: 'user_123',
|
|
23
|
+
message: 'I prefer TypeScript over Python for backend work.',
|
|
24
|
+
response: "Got it, I'll keep that in mind.",
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
// Semantic search over everything the user has ever said
|
|
28
|
+
const memories = await ca.memory.search('user_123', 'programming preferences')
|
|
29
|
+
// → [{ content: 'User prefers TypeScript over Python for backend.', score: 0.91 }]
|
|
30
|
+
|
|
31
|
+
// Ask a natural language question over stored memories
|
|
32
|
+
const answer = await ca.memory.ask('user_123', 'What languages does this user like?')
|
|
33
|
+
// → "Based on your memories, you prefer TypeScript for backend work."
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
---
|
|
37
|
+
|
|
38
|
+
## Cognitive security: scan before you trust
|
|
39
|
+
|
|
40
|
+
```ts
|
|
41
|
+
import Crossagent from '@tanmaysangam018/crossagent'
|
|
42
|
+
|
|
43
|
+
const engram = new Crossagent({ apiKey: 'your-key' })
|
|
44
|
+
|
|
45
|
+
// Scan any AI response for injection attacks before acting on it
|
|
46
|
+
const scan = await engram.memory.scan(aiResponse)
|
|
47
|
+
|
|
48
|
+
if (scan.verdict !== 'clean') {
|
|
49
|
+
console.warn('Injection detected:', scan.flags)
|
|
50
|
+
// → { type: 'instruction_override', severity: 'critical', match: 'Ignore all previous instructions', position: 0 }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
// score: 0–100 | verdict: clean / suspicious / likely_injection / definite_injection
|
|
54
|
+
// Detects: instruction_override, role_hijacking, context_extraction, data_exfiltration,
|
|
55
|
+
// encoded_payload, urgency_manipulation, chain_injection, indirect_injection
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
Try it live (no account needed): **crossagentsi.vercel.app/demo**
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## API
|
|
63
|
+
|
|
64
|
+
### `new Crossagent(options?)`
|
|
65
|
+
|
|
66
|
+
| Option | Type | Default | Description |
|
|
67
|
+
|--------|------|---------|-------------|
|
|
68
|
+
| `apiKey` | `string` | — | Your Crossagent API key (optional on free tier) |
|
|
69
|
+
| `baseUrl` | `string` | `https://backend-wine-phi-85.vercel.app` | Self-host override |
|
|
70
|
+
|
|
71
|
+
---
|
|
72
|
+
|
|
73
|
+
### `ca.memory.add(opts)`
|
|
74
|
+
|
|
75
|
+
Stores a conversation turn as one or more atomic memories. Facts are extracted automatically via LLM and embedded with pgvector.
|
|
76
|
+
|
|
77
|
+
```ts
|
|
78
|
+
await ca.memory.add({
|
|
79
|
+
userId: 'user_123',
|
|
80
|
+
message: 'I live in New York and work in fintech.',
|
|
81
|
+
response: 'Noted!',
|
|
82
|
+
sourceAgent: 'my-app', // optional — where the message came from
|
|
83
|
+
targetAgent: 'claude', // optional — which AI responded
|
|
84
|
+
})
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
---
|
|
88
|
+
|
|
89
|
+
### `ca.memory.search(userId, query, limit?)`
|
|
90
|
+
|
|
91
|
+
Semantic search over a user's memories. Returns matches sorted by relevance.
|
|
92
|
+
|
|
93
|
+
```ts
|
|
94
|
+
const results = await ca.memory.search('user_123', 'where does the user live', 5)
|
|
95
|
+
// → [{ id, content, mem_type, score }, ...]
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
---
|
|
99
|
+
|
|
100
|
+
### `ca.memory.ask(userId, question)`
|
|
101
|
+
|
|
102
|
+
Natural language Q&A over stored memories. Uses an LLM to synthesize an answer from the user's memory.
|
|
103
|
+
|
|
104
|
+
```ts
|
|
105
|
+
const answer = await ca.memory.ask('user_123', 'What industry does this user work in?')
|
|
106
|
+
// → "Based on your memories, you work in fintech in New York."
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
### `ca.memory.list(userId)`
|
|
112
|
+
|
|
113
|
+
Returns all memories for a user, ordered by recency.
|
|
114
|
+
|
|
115
|
+
```ts
|
|
116
|
+
const all = await ca.memory.list('user_123')
|
|
117
|
+
```
|
|
118
|
+
|
|
119
|
+
---
|
|
120
|
+
|
|
121
|
+
### `ca.memory.profile(userId)`
|
|
122
|
+
|
|
123
|
+
Returns a pre-built profile: permanent facts and recent activity context.
|
|
124
|
+
|
|
125
|
+
```ts
|
|
126
|
+
const { static_facts, dynamic_ctx } = await ca.memory.profile('user_123')
|
|
127
|
+
// static_facts: ['User works in fintech', 'User prefers TypeScript']
|
|
128
|
+
// dynamic_ctx: ['User is building a payments API']
|
|
129
|
+
```
|
|
130
|
+
|
|
131
|
+
---
|
|
132
|
+
|
|
133
|
+
### `ca.memory.delete(userId, memoryId)`
|
|
134
|
+
|
|
135
|
+
Soft-deletes a memory (marks it superseded).
|
|
136
|
+
|
|
137
|
+
```ts
|
|
138
|
+
await ca.memory.delete('user_123', 'mem_id_here')
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
---
|
|
142
|
+
|
|
143
|
+
## MCP server
|
|
144
|
+
|
|
145
|
+
Connect any MCP-compatible AI agent directly to Crossagent memory:
|
|
146
|
+
|
|
147
|
+
```
|
|
148
|
+
https://backend-wine-phi-85.vercel.app/mcp
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
Tools exposed: `remember`, `recall`, `get_profile`, `list_memories`
|
|
152
|
+
|
|
153
|
+
---
|
|
154
|
+
|
|
155
|
+
## Memory types
|
|
156
|
+
|
|
157
|
+
| Type | What it means | Expires |
|
|
158
|
+
|------|---------------|---------|
|
|
159
|
+
| `fact` | Permanent info — name, location, job, stack | Never |
|
|
160
|
+
| `preference` | What the user likes or wants | Never |
|
|
161
|
+
| `episode` | Current activity — "working on X" | 21 days |
|
|
162
|
+
|
|
163
|
+
---
|
|
164
|
+
|
|
165
|
+
## Self-hosting
|
|
166
|
+
|
|
167
|
+
The backend is open source. Deploy your own in one command:
|
|
168
|
+
|
|
169
|
+
```bash
|
|
170
|
+
git clone https://github.com/TanmaySangam18/crossagent-backend
|
|
171
|
+
vercel deploy
|
|
172
|
+
```
|
|
173
|
+
|
|
174
|
+
Requires: `GEMINI_API_KEY`, `SUPABASE_URL`, `SUPABASE_SERVICE_KEY`
|
|
175
|
+
|
|
176
|
+
---
|
|
177
|
+
|
|
178
|
+
## License
|
|
179
|
+
|
|
180
|
+
MIT
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
export interface CrossagentOptions {
|
|
2
|
+
apiKey?: string;
|
|
3
|
+
baseUrl?: string;
|
|
4
|
+
}
|
|
5
|
+
export interface Memory {
|
|
6
|
+
id: string;
|
|
7
|
+
content: string;
|
|
8
|
+
mem_type: 'fact' | 'preference' | 'episode';
|
|
9
|
+
src_agent: string;
|
|
10
|
+
tgt_agent: string;
|
|
11
|
+
strength: number;
|
|
12
|
+
created_at: string;
|
|
13
|
+
expires_at: string | null;
|
|
14
|
+
}
|
|
15
|
+
export interface MemoryMatch extends Pick<Memory, 'id' | 'content' | 'mem_type' | 'src_agent' | 'tgt_agent'> {
|
|
16
|
+
score: number;
|
|
17
|
+
}
|
|
18
|
+
export interface ScanFlag {
|
|
19
|
+
type: string;
|
|
20
|
+
severity: 'low' | 'medium' | 'high' | 'critical';
|
|
21
|
+
match: string;
|
|
22
|
+
position: number;
|
|
23
|
+
description: string;
|
|
24
|
+
}
|
|
25
|
+
export interface ScanResult {
|
|
26
|
+
score: number;
|
|
27
|
+
verdict: 'clean' | 'suspicious' | 'likely_injection' | 'definite_injection';
|
|
28
|
+
flags: ScanFlag[];
|
|
29
|
+
summary: string;
|
|
30
|
+
scanned_at: string;
|
|
31
|
+
}
|
|
32
|
+
export interface Profile {
|
|
33
|
+
static_facts: string[];
|
|
34
|
+
dynamic_ctx: string[];
|
|
35
|
+
}
|
|
36
|
+
export declare class CrossagentMemory {
|
|
37
|
+
private base;
|
|
38
|
+
private headers;
|
|
39
|
+
constructor(base: string, headers: Record<string, string>);
|
|
40
|
+
add(opts: {
|
|
41
|
+
userId: string;
|
|
42
|
+
message: string;
|
|
43
|
+
response: string;
|
|
44
|
+
sourceAgent?: string;
|
|
45
|
+
targetAgent?: string;
|
|
46
|
+
}): Promise<void>;
|
|
47
|
+
search(userId: string, query: string, limit?: number): Promise<MemoryMatch[]>;
|
|
48
|
+
list(userId: string): Promise<Memory[]>;
|
|
49
|
+
ask(userId: string, question: string): Promise<string>;
|
|
50
|
+
profile(userId: string): Promise<Profile>;
|
|
51
|
+
delete(userId: string, memoryId: string): Promise<void>;
|
|
52
|
+
scan(text: string): Promise<ScanResult>;
|
|
53
|
+
}
|
|
54
|
+
export declare class Crossagent {
|
|
55
|
+
readonly memory: CrossagentMemory;
|
|
56
|
+
readonly mcpUrl: string;
|
|
57
|
+
constructor(opts?: CrossagentOptions);
|
|
58
|
+
}
|
|
59
|
+
export default Crossagent;
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
const DEFAULT_BASE = 'https://backend-wine-phi-85.vercel.app';
|
|
2
|
+
export class CrossagentMemory {
|
|
3
|
+
constructor(base, headers) {
|
|
4
|
+
this.base = base;
|
|
5
|
+
this.headers = headers;
|
|
6
|
+
}
|
|
7
|
+
async add(opts) {
|
|
8
|
+
await fetch(`${this.base}/memory/store`, {
|
|
9
|
+
method: 'POST',
|
|
10
|
+
headers: { 'Content-Type': 'application/json', ...this.headers },
|
|
11
|
+
body: JSON.stringify({
|
|
12
|
+
userId: opts.userId,
|
|
13
|
+
message: opts.message,
|
|
14
|
+
response: opts.response,
|
|
15
|
+
sourceAgent: opts.sourceAgent ?? 'sdk',
|
|
16
|
+
targetAgent: opts.targetAgent ?? 'sdk',
|
|
17
|
+
}),
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
async search(userId, query, limit = 5) {
|
|
21
|
+
const url = `${this.base}/memory/search?userId=${encodeURIComponent(userId)}&q=${encodeURIComponent(query)}&limit=${limit}`;
|
|
22
|
+
const res = await fetch(url, { headers: this.headers });
|
|
23
|
+
const data = await res.json();
|
|
24
|
+
return data.memories ?? [];
|
|
25
|
+
}
|
|
26
|
+
async list(userId) {
|
|
27
|
+
const res = await fetch(`${this.base}/memory/list?userId=${encodeURIComponent(userId)}`, { headers: this.headers });
|
|
28
|
+
const data = await res.json();
|
|
29
|
+
return data.memories ?? [];
|
|
30
|
+
}
|
|
31
|
+
async ask(userId, question) {
|
|
32
|
+
const res = await fetch(`${this.base}/memory/ask`, {
|
|
33
|
+
method: 'POST',
|
|
34
|
+
headers: { 'Content-Type': 'application/json', ...this.headers },
|
|
35
|
+
body: JSON.stringify({ userId, question }),
|
|
36
|
+
});
|
|
37
|
+
const data = await res.json();
|
|
38
|
+
return data.response ?? '';
|
|
39
|
+
}
|
|
40
|
+
async profile(userId) {
|
|
41
|
+
const res = await fetch(`${this.base}/memory/profile?userId=${encodeURIComponent(userId)}`, { headers: this.headers });
|
|
42
|
+
const data = await res.json();
|
|
43
|
+
return data.profile ?? { static_facts: [], dynamic_ctx: [] };
|
|
44
|
+
}
|
|
45
|
+
async delete(userId, memoryId) {
|
|
46
|
+
await fetch(`${this.base}/memory/delete/${memoryId}?userId=${encodeURIComponent(userId)}`, {
|
|
47
|
+
method: 'DELETE',
|
|
48
|
+
headers: this.headers,
|
|
49
|
+
});
|
|
50
|
+
}
|
|
51
|
+
async scan(text) {
|
|
52
|
+
const res = await fetch(`${this.base}/memory/scan`, {
|
|
53
|
+
method: 'POST',
|
|
54
|
+
headers: { 'Content-Type': 'application/json', ...this.headers },
|
|
55
|
+
body: JSON.stringify({ text }),
|
|
56
|
+
});
|
|
57
|
+
if (!res.ok)
|
|
58
|
+
throw new Error(`scan failed: ${res.status}`);
|
|
59
|
+
return res.json();
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
export class Crossagent {
|
|
63
|
+
constructor(opts = {}) {
|
|
64
|
+
const base = (opts.baseUrl ?? DEFAULT_BASE).replace(/\/$/, '');
|
|
65
|
+
const headers = {};
|
|
66
|
+
if (opts.apiKey)
|
|
67
|
+
headers['x-api-key'] = opts.apiKey;
|
|
68
|
+
this.memory = new CrossagentMemory(base, headers);
|
|
69
|
+
this.mcpUrl = `${base}/mcp`;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
export default Crossagent;
|
package/package.json
CHANGED
|
@@ -1,6 +1,44 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanmaysangam018/crossagent",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
3
|
+
"version": "0.2.0",
|
|
4
|
+
"description": "Persistent memory + cognitive security layer for AI apps. Semantic memory, pattern intelligence, and prompt injection scanning.",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"type": "module",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist",
|
|
17
|
+
"README.md"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc --skipLibCheck --outDir dist --declaration",
|
|
21
|
+
"prepublishOnly": "npm run build"
|
|
22
|
+
},
|
|
23
|
+
"keywords": [
|
|
24
|
+
"ai",
|
|
25
|
+
"memory",
|
|
26
|
+
"llm",
|
|
27
|
+
"crossagent",
|
|
28
|
+
"multi-model",
|
|
29
|
+
"mcp",
|
|
30
|
+
"chatgpt",
|
|
31
|
+
"claude",
|
|
32
|
+
"gemini"
|
|
33
|
+
],
|
|
34
|
+
"author": "Tanmay Sangam",
|
|
35
|
+
"license": "MIT",
|
|
36
|
+
"repository": {
|
|
37
|
+
"type": "git",
|
|
38
|
+
"url": "https://github.com/TanmaySangam18/crossagent-backend"
|
|
39
|
+
},
|
|
40
|
+
"devDependencies": {
|
|
41
|
+
"tsup": "^9.0.0",
|
|
42
|
+
"typescript": "^5.0.0"
|
|
43
|
+
}
|
|
44
|
+
}
|