cogxai 2.8.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/LICENSE +21 -0
- package/README.md +691 -0
- package/dist/agents/executor.d.ts +17 -0
- package/dist/agents/executor.d.ts.map +1 -0
- package/dist/agents/executor.js +336 -0
- package/dist/agents/executor.js.map +1 -0
- package/dist/agents/index.d.ts +9 -0
- package/dist/agents/index.d.ts.map +1 -0
- package/dist/agents/index.js +18 -0
- package/dist/agents/index.js.map +1 -0
- package/dist/agents/tools.d.ts +31 -0
- package/dist/agents/tools.d.ts.map +1 -0
- package/dist/agents/tools.js +262 -0
- package/dist/agents/tools.js.map +1 -0
- package/dist/agents/types.d.ts +25 -0
- package/dist/agents/types.d.ts.map +1 -0
- package/dist/agents/types.js +170 -0
- package/dist/agents/types.js.map +1 -0
- package/dist/character/agent-tier-modifiers.d.ts +3 -0
- package/dist/character/agent-tier-modifiers.d.ts.map +1 -0
- package/dist/character/agent-tier-modifiers.js +24 -0
- package/dist/character/agent-tier-modifiers.js.map +1 -0
- package/dist/character/base-prompt.d.ts +3 -0
- package/dist/character/base-prompt.d.ts.map +1 -0
- package/dist/character/base-prompt.js +45 -0
- package/dist/character/base-prompt.js.map +1 -0
- package/dist/character/mood-modifiers.d.ts +3 -0
- package/dist/character/mood-modifiers.d.ts.map +1 -0
- package/dist/character/mood-modifiers.js +27 -0
- package/dist/character/mood-modifiers.js.map +1 -0
- package/dist/character/tier-modifiers.d.ts +3 -0
- package/dist/character/tier-modifiers.d.ts.map +1 -0
- package/dist/character/tier-modifiers.js +25 -0
- package/dist/character/tier-modifiers.js.map +1 -0
- package/dist/cli/banner.d.ts +20 -0
- package/dist/cli/banner.d.ts.map +1 -0
- package/dist/cli/banner.js +73 -0
- package/dist/cli/banner.js.map +1 -0
- package/dist/cli/export.d.ts +2 -0
- package/dist/cli/export.d.ts.map +1 -0
- package/dist/cli/export.js +176 -0
- package/dist/cli/export.js.map +1 -0
- package/dist/cli/index.d.ts +3 -0
- package/dist/cli/index.d.ts.map +1 -0
- package/dist/cli/index.js +80 -0
- package/dist/cli/index.js.map +1 -0
- package/dist/cli/init.d.ts +2 -0
- package/dist/cli/init.d.ts.map +1 -0
- package/dist/cli/init.js +541 -0
- package/dist/cli/init.js.map +1 -0
- package/dist/cli/register.d.ts +2 -0
- package/dist/cli/register.d.ts.map +1 -0
- package/dist/cli/register.js +121 -0
- package/dist/cli/register.js.map +1 -0
- package/dist/cli/setup.d.ts +3 -0
- package/dist/cli/setup.d.ts.map +1 -0
- package/dist/cli/setup.js +403 -0
- package/dist/cli/setup.js.map +1 -0
- package/dist/cli/ship.d.ts +2 -0
- package/dist/cli/ship.d.ts.map +1 -0
- package/dist/cli/ship.js +32 -0
- package/dist/cli/ship.js.map +1 -0
- package/dist/config.d.ts +90 -0
- package/dist/config.d.ts.map +1 -0
- package/dist/config.js +124 -0
- package/dist/config.js.map +1 -0
- package/dist/core/allium-client.d.ts +32 -0
- package/dist/core/allium-client.d.ts.map +1 -0
- package/dist/core/allium-client.js +162 -0
- package/dist/core/allium-client.js.map +1 -0
- package/dist/core/claude-client.d.ts +31 -0
- package/dist/core/claude-client.d.ts.map +1 -0
- package/dist/core/claude-client.js +172 -0
- package/dist/core/claude-client.js.map +1 -0
- package/dist/core/database.d.ts +17 -0
- package/dist/core/database.d.ts.map +1 -0
- package/dist/core/database.js +499 -0
- package/dist/core/database.js.map +1 -0
- package/dist/core/embeddings.d.ts +28 -0
- package/dist/core/embeddings.d.ts.map +1 -0
- package/dist/core/embeddings.js +212 -0
- package/dist/core/embeddings.js.map +1 -0
- package/dist/core/encryption.d.ts +49 -0
- package/dist/core/encryption.d.ts.map +1 -0
- package/dist/core/encryption.js +136 -0
- package/dist/core/encryption.js.map +1 -0
- package/dist/core/guardrails.d.ts +30 -0
- package/dist/core/guardrails.d.ts.map +1 -0
- package/dist/core/guardrails.js +191 -0
- package/dist/core/guardrails.js.map +1 -0
- package/dist/core/inference.d.ts +37 -0
- package/dist/core/inference.d.ts.map +1 -0
- package/dist/core/inference.js +110 -0
- package/dist/core/inference.js.map +1 -0
- package/dist/core/input-guardrails.d.ts +21 -0
- package/dist/core/input-guardrails.d.ts.map +1 -0
- package/dist/core/input-guardrails.js +59 -0
- package/dist/core/input-guardrails.js.map +1 -0
- package/dist/core/logger.d.ts +3 -0
- package/dist/core/logger.d.ts.map +1 -0
- package/dist/core/logger.js +41 -0
- package/dist/core/logger.js.map +1 -0
- package/dist/core/memory-graph.d.ts +126 -0
- package/dist/core/memory-graph.d.ts.map +1 -0
- package/dist/core/memory-graph.js +451 -0
- package/dist/core/memory-graph.js.map +1 -0
- package/dist/core/memory.d.ts +172 -0
- package/dist/core/memory.d.ts.map +1 -0
- package/dist/core/memory.js +1432 -0
- package/dist/core/memory.js.map +1 -0
- package/dist/core/owner-context.d.ts +8 -0
- package/dist/core/owner-context.d.ts.map +1 -0
- package/dist/core/owner-context.js +31 -0
- package/dist/core/owner-context.js.map +1 -0
- package/dist/core/price-oracle.d.ts +16 -0
- package/dist/core/price-oracle.d.ts.map +1 -0
- package/dist/core/price-oracle.js +162 -0
- package/dist/core/price-oracle.js.map +1 -0
- package/dist/core/solana-client.d.ts +39 -0
- package/dist/core/solana-client.d.ts.map +1 -0
- package/dist/core/solana-client.js +366 -0
- package/dist/core/solana-client.js.map +1 -0
- package/dist/core/telegram-client.d.ts +22 -0
- package/dist/core/telegram-client.d.ts.map +1 -0
- package/dist/core/telegram-client.js +93 -0
- package/dist/core/telegram-client.js.map +1 -0
- package/dist/core/venice-client.d.ts +94 -0
- package/dist/core/venice-client.d.ts.map +1 -0
- package/dist/core/venice-client.js +282 -0
- package/dist/core/venice-client.js.map +1 -0
- package/dist/core/x-client.d.ts +68 -0
- package/dist/core/x-client.d.ts.map +1 -0
- package/dist/core/x-client.js +383 -0
- package/dist/core/x-client.js.map +1 -0
- package/dist/events/event-bus.d.ts +37 -0
- package/dist/events/event-bus.d.ts.map +1 -0
- package/dist/events/event-bus.js +21 -0
- package/dist/events/event-bus.js.map +1 -0
- package/dist/events/handlers.d.ts +6 -0
- package/dist/events/handlers.d.ts.map +1 -0
- package/dist/events/handlers.js +21 -0
- package/dist/events/handlers.js.map +1 -0
- package/dist/features/action-learning.d.ts +61 -0
- package/dist/features/action-learning.d.ts.map +1 -0
- package/dist/features/action-learning.js +424 -0
- package/dist/features/action-learning.js.map +1 -0
- package/dist/features/active-reflection.d.ts +37 -0
- package/dist/features/active-reflection.d.ts.map +1 -0
- package/dist/features/active-reflection.js +376 -0
- package/dist/features/active-reflection.js.map +1 -0
- package/dist/features/agent-tier.d.ts +21 -0
- package/dist/features/agent-tier.d.ts.map +1 -0
- package/dist/features/agent-tier.js +56 -0
- package/dist/features/agent-tier.js.map +1 -0
- package/dist/features/campaign-tracker.d.ts +8 -0
- package/dist/features/campaign-tracker.d.ts.map +1 -0
- package/dist/features/campaign-tracker.js +206 -0
- package/dist/features/campaign-tracker.js.map +1 -0
- package/dist/features/clinamen.d.ts +48 -0
- package/dist/features/clinamen.d.ts.map +1 -0
- package/dist/features/clinamen.js +164 -0
- package/dist/features/clinamen.js.map +1 -0
- package/dist/features/dream-cycle.d.ts +12 -0
- package/dist/features/dream-cycle.d.ts.map +1 -0
- package/dist/features/dream-cycle.js +889 -0
- package/dist/features/dream-cycle.js.map +1 -0
- package/dist/features/market-monitor.d.ts +4 -0
- package/dist/features/market-monitor.d.ts.map +1 -0
- package/dist/features/market-monitor.js +135 -0
- package/dist/features/market-monitor.js.map +1 -0
- package/dist/features/memory-trace.d.ts +75 -0
- package/dist/features/memory-trace.d.ts.map +1 -0
- package/dist/features/memory-trace.js +325 -0
- package/dist/features/memory-trace.js.map +1 -0
- package/dist/features/onchain-opinion.d.ts +5 -0
- package/dist/features/onchain-opinion.d.ts.map +1 -0
- package/dist/features/onchain-opinion.js +70 -0
- package/dist/features/onchain-opinion.js.map +1 -0
- package/dist/features/price-personality.d.ts +4 -0
- package/dist/features/price-personality.d.ts.map +1 -0
- package/dist/features/price-personality.js +156 -0
- package/dist/features/price-personality.js.map +1 -0
- package/dist/features/x-sentiment-monitor.d.ts +8 -0
- package/dist/features/x-sentiment-monitor.d.ts.map +1 -0
- package/dist/features/x-sentiment-monitor.js +289 -0
- package/dist/features/x-sentiment-monitor.js.map +1 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +133 -0
- package/dist/index.js.map +1 -0
- package/dist/knowledge/tokenomics.d.ts +72 -0
- package/dist/knowledge/tokenomics.d.ts.map +1 -0
- package/dist/knowledge/tokenomics.js +140 -0
- package/dist/knowledge/tokenomics.js.map +1 -0
- package/dist/mcp/local-store.d.ts +53 -0
- package/dist/mcp/local-store.d.ts.map +1 -0
- package/dist/mcp/local-store.js +175 -0
- package/dist/mcp/local-store.js.map +1 -0
- package/dist/mcp/server.d.ts +2 -0
- package/dist/mcp/server.d.ts.map +1 -0
- package/dist/mcp/server.js +373 -0
- package/dist/mcp/server.js.map +1 -0
- package/dist/mentions/classifier.d.ts +3 -0
- package/dist/mentions/classifier.d.ts.map +1 -0
- package/dist/mentions/classifier.js +51 -0
- package/dist/mentions/classifier.js.map +1 -0
- package/dist/mentions/dispatcher.d.ts +3 -0
- package/dist/mentions/dispatcher.d.ts.map +1 -0
- package/dist/mentions/dispatcher.js +404 -0
- package/dist/mentions/dispatcher.js.map +1 -0
- package/dist/mentions/poller.d.ts +3 -0
- package/dist/mentions/poller.d.ts.map +1 -0
- package/dist/mentions/poller.js +45 -0
- package/dist/mentions/poller.js.map +1 -0
- package/dist/sdk/cortex-v2.d.ts +121 -0
- package/dist/sdk/cortex-v2.d.ts.map +1 -0
- package/dist/sdk/cortex-v2.js +207 -0
- package/dist/sdk/cortex-v2.js.map +1 -0
- package/dist/sdk/cortex.d.ts +64 -0
- package/dist/sdk/cortex.d.ts.map +1 -0
- package/dist/sdk/cortex.js +362 -0
- package/dist/sdk/cortex.js.map +1 -0
- package/dist/sdk/http-transport.d.ts +15 -0
- package/dist/sdk/http-transport.d.ts.map +1 -0
- package/dist/sdk/http-transport.js +49 -0
- package/dist/sdk/http-transport.js.map +1 -0
- package/dist/sdk/index.d.ts +5 -0
- package/dist/sdk/index.d.ts.map +1 -0
- package/dist/sdk/index.js +8 -0
- package/dist/sdk/index.js.map +1 -0
- package/dist/sdk/sdk-mode.d.ts +1 -0
- package/dist/sdk/sdk-mode.d.ts.map +1 -0
- package/dist/sdk/sdk-mode.js +5 -0
- package/dist/sdk/sdk-mode.js.map +1 -0
- package/dist/sdk/types.d.ts +48 -0
- package/dist/sdk/types.d.ts.map +1 -0
- package/dist/sdk/types.js +3 -0
- package/dist/sdk/types.js.map +1 -0
- package/dist/services/response.service.d.ts +27 -0
- package/dist/services/response.service.d.ts.map +1 -0
- package/dist/services/response.service.js +62 -0
- package/dist/services/response.service.js.map +1 -0
- package/dist/services/social.service.d.ts +14 -0
- package/dist/services/social.service.d.ts.map +1 -0
- package/dist/services/social.service.js +44 -0
- package/dist/services/social.service.js.map +1 -0
- package/dist/services/telegram.service.d.ts +30 -0
- package/dist/services/telegram.service.d.ts.map +1 -0
- package/dist/services/telegram.service.js +71 -0
- package/dist/services/telegram.service.js.map +1 -0
- package/dist/types/api.d.ts +109 -0
- package/dist/types/api.d.ts.map +1 -0
- package/dist/types/api.js +6 -0
- package/dist/types/api.js.map +1 -0
- package/dist/utils/constants.d.ts +49 -0
- package/dist/utils/constants.d.ts.map +1 -0
- package/dist/utils/constants.js +110 -0
- package/dist/utils/constants.js.map +1 -0
- package/dist/utils/env-persona.d.ts +9 -0
- package/dist/utils/env-persona.d.ts.map +1 -0
- package/dist/utils/env-persona.js +53 -0
- package/dist/utils/env-persona.js.map +1 -0
- package/dist/utils/format.d.ts +12 -0
- package/dist/utils/format.d.ts.map +1 -0
- package/dist/utils/format.js +59 -0
- package/dist/utils/format.js.map +1 -0
- package/dist/utils/index.d.ts +4 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +20 -0
- package/dist/utils/index.js.map +1 -0
- package/dist/utils/text.d.ts +10 -0
- package/dist/utils/text.d.ts.map +1 -0
- package/dist/utils/text.js +33 -0
- package/dist/utils/text.js.map +1 -0
- package/dist/verify-app/routes.d.ts +3 -0
- package/dist/verify-app/routes.d.ts.map +1 -0
- package/dist/verify-app/routes.js +101 -0
- package/dist/verify-app/routes.js.map +1 -0
- package/dist/webhook/agent-routes.d.ts +3 -0
- package/dist/webhook/agent-routes.d.ts.map +1 -0
- package/dist/webhook/agent-routes.js +314 -0
- package/dist/webhook/agent-routes.js.map +1 -0
- package/dist/webhook/campaign-routes.d.ts +3 -0
- package/dist/webhook/campaign-routes.d.ts.map +1 -0
- package/dist/webhook/campaign-routes.js +333 -0
- package/dist/webhook/campaign-routes.js.map +1 -0
- package/dist/webhook/cortex-routes.d.ts +13 -0
- package/dist/webhook/cortex-routes.d.ts.map +1 -0
- package/dist/webhook/cortex-routes.js +534 -0
- package/dist/webhook/cortex-routes.js.map +1 -0
- package/dist/webhook/dashboard-routes.d.ts +8 -0
- package/dist/webhook/dashboard-routes.d.ts.map +1 -0
- package/dist/webhook/dashboard-routes.js +588 -0
- package/dist/webhook/dashboard-routes.js.map +1 -0
- package/dist/webhook/graph-routes.d.ts +3 -0
- package/dist/webhook/graph-routes.d.ts.map +1 -0
- package/dist/webhook/graph-routes.js +238 -0
- package/dist/webhook/graph-routes.js.map +1 -0
- package/dist/webhook/privy-auth.d.ts +35 -0
- package/dist/webhook/privy-auth.d.ts.map +1 -0
- package/dist/webhook/privy-auth.js +99 -0
- package/dist/webhook/privy-auth.js.map +1 -0
- package/dist/webhook/server.d.ts +4 -0
- package/dist/webhook/server.d.ts.map +1 -0
- package/dist/webhook/server.js +912 -0
- package/dist/webhook/server.js.map +1 -0
- package/package.json +96 -0
- package/supabase-schema.sql +399 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Black-dork
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,691 @@
|
|
|
1
|
+
# CogxAI
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/cogxai)
|
|
4
|
+
[](LICENSE)
|
|
5
|
+
|
|
6
|
+
**Persistent memory for AI agents.** Two commands. Your agent remembers everything.
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
npm install -g cogxai
|
|
10
|
+
cogxai mcp-install
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
> Your agent already has files and logs. CogxAI adds semantic retrieval, typed association bonds, and automatic consolidation on top. Files are your notebook. CogxAI is your long-term memory.
|
|
14
|
+
|
|
15
|
+
**Compatible with:** Claude Desktop, Cursor, OpenClaw, DeerFlow, and any MCP-compatible agent runtime.
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
**Molecular Memory** for AI agents. Not just storage — synthesis.
|
|
20
|
+
|
|
21
|
+
> *"From thought to proof. Where memories crystallize into knowledge."*
|
|
22
|
+
|
|
23
|
+
Draws from [Stanford Generative Agents](https://arxiv.org/abs/2304.03442), [MemGPT/Letta](https://arxiv.org/abs/2310.08560), [CoALA](https://arxiv.org/abs/2309.02427), [Beads](https://github.com/steveyegge/beads), [Mole-Syn](https://x.com/bowang87/status/2025227673820176689) (molecular reasoning), and [Venice](https://venice.ai) (permissionless inference).
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
## Why Molecular Memory?
|
|
28
|
+
|
|
29
|
+
Conventional memory systems linearly scan every memory on each query — **O(n)** complexity. Molecular Memory traverses a bond graph instead — **O(k)** where k ≈ 3-5 bonds.
|
|
30
|
+
|
|
31
|
+
| Metric | Conventional | Molecular | Gain |
|
|
32
|
+
|--------|-------------|-----------|------|
|
|
33
|
+
| **Retrieval** (1000 memories) | ~1000ms | ~16ms | **60x faster** |
|
|
34
|
+
| **Context coherence** | Fragmented | Clustered | More coherent answers |
|
|
35
|
+
| **Dream cycle** | Full scan | Graph-based | 30-50% fewer LLM calls |
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npm install cogxai
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Quick Start — Hosted (Zero Setup)
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
npx cogxai register # Obtain your API key
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import { Cortex } from 'cogxai';
|
|
49
|
+
|
|
50
|
+
const brain = new Cortex({
|
|
51
|
+
hosted: { apiKey: process.env.CORTEX_API_KEY! },
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
await brain.init();
|
|
55
|
+
|
|
56
|
+
// Store a memory
|
|
57
|
+
await brain.store({
|
|
58
|
+
type: 'episodic',
|
|
59
|
+
content: 'User asked about pricing and seemed frustrated with the current plan.',
|
|
60
|
+
summary: 'Frustrated user asking about pricing',
|
|
61
|
+
tags: ['pricing', 'user-concern'],
|
|
62
|
+
importance: 0.7,
|
|
63
|
+
source: 'my-agent',
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// Retrieve relevant memories
|
|
67
|
+
const memories = await brain.recall({
|
|
68
|
+
query: 'what do users think about pricing',
|
|
69
|
+
limit: 5,
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
console.log(`Retrieved ${memories.length} memories`);
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
That's all. No database, no infrastructure. Memories are stored on CogxAI cloud, scoped by your API key.
|
|
76
|
+
|
|
77
|
+
## Quick Start — Self-Hosted (Your Supabase)
|
|
78
|
+
|
|
79
|
+
For complete control, bring your own Supabase:
|
|
80
|
+
|
|
81
|
+
```typescript
|
|
82
|
+
import { Cortex } from 'cogxai';
|
|
83
|
+
|
|
84
|
+
const brain = new Cortex({
|
|
85
|
+
supabase: {
|
|
86
|
+
url: process.env.SUPABASE_URL!,
|
|
87
|
+
serviceKey: process.env.SUPABASE_KEY!,
|
|
88
|
+
},
|
|
89
|
+
anthropic: {
|
|
90
|
+
apiKey: process.env.ANTHROPIC_API_KEY!,
|
|
91
|
+
},
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
await brain.init();
|
|
95
|
+
|
|
96
|
+
await brain.store({
|
|
97
|
+
type: 'episodic',
|
|
98
|
+
content: 'User asked about pricing and seemed frustrated with the current plan.',
|
|
99
|
+
summary: 'Frustrated user asking about pricing',
|
|
100
|
+
tags: ['pricing', 'user-concern'],
|
|
101
|
+
importance: 0.7,
|
|
102
|
+
source: 'my-agent',
|
|
103
|
+
relatedUser: 'user-123',
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
const memories = await brain.recall({
|
|
107
|
+
query: 'what do users think about pricing',
|
|
108
|
+
limit: 5,
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
const context = brain.formatContext(memories);
|
|
112
|
+
// Inject `context` into your system prompt so the LLM has access to past knowledge
|
|
113
|
+
```
|
|
114
|
+
|
|
115
|
+
---
|
|
116
|
+
|
|
117
|
+
## Examples
|
|
118
|
+
|
|
119
|
+
Check the [`examples/`](./examples) directory for runnable scripts:
|
|
120
|
+
|
|
121
|
+
- **[hosted-mode.ts](./examples/hosted-mode.ts)** — Zero-config usage with just an API key (hosted mode)
|
|
122
|
+
- **[basic-memory.ts](./examples/basic-memory.ts)** — Store and recall using Supabase (self-hosted)
|
|
123
|
+
- **[chat-agent.ts](./examples/chat-agent.ts)** — Interactive conversational agent with memory and dream cycles
|
|
124
|
+
- **[progressive-disclosure.ts](./examples/progressive-disclosure.ts)** — Token-efficient retrieval using `recallSummaries()` + `hydrate()`
|
|
125
|
+
|
|
126
|
+
```bash
|
|
127
|
+
# Hosted mode
|
|
128
|
+
CORTEX_API_KEY=clk_... npx tsx examples/hosted-mode.ts
|
|
129
|
+
|
|
130
|
+
# Self-hosted
|
|
131
|
+
SUPABASE_URL=... SUPABASE_KEY=... npx tsx examples/basic-memory.ts
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
---
|
|
135
|
+
|
|
136
|
+
## CLI
|
|
137
|
+
|
|
138
|
+
```bash
|
|
139
|
+
npx cogxai mcp-install # Auto-configure MCP for Claude Desktop/Cursor/etc.
|
|
140
|
+
npx cogxai mcp-serve # Launch as MCP server (called by agent runtimes)
|
|
141
|
+
npx cogxai setup # Guided setup wizard (choose local/hosted/self-hosted)
|
|
142
|
+
npx cogxai init # Initialize database schema
|
|
143
|
+
npx cogxai register # Obtain an API key for hosted mode
|
|
144
|
+
npx cogxai start # Launch the full CogxAI service (requires config)
|
|
145
|
+
npx cogxai export # Export memories to file
|
|
146
|
+
npx cogxai ship # Package and ship a memory pack
|
|
147
|
+
npx cogxai --version # Display version
|
|
148
|
+
```
|
|
149
|
+
|
|
150
|
+
### MCP Integration (For Agent Runtimes)
|
|
151
|
+
|
|
152
|
+
Connect CogxAI to any MCP-compatible agent:
|
|
153
|
+
|
|
154
|
+
```json
|
|
155
|
+
{
|
|
156
|
+
"mcpServers": {
|
|
157
|
+
"cogxai": {
|
|
158
|
+
"command": "npx",
|
|
159
|
+
"args": ["cogxai", "mcp-serve"]
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
```
|
|
164
|
+
|
|
165
|
+
This exposes 4 tools to your agent: `store_memory`, `recall_memories`, `get_memory_stats`, `find_clinamen`.
|
|
166
|
+
|
|
167
|
+
Compatible with: Claude Desktop (`claude_desktop_config.json`), Cursor (`.cursor/mcp.json`), OpenClaw (skills), DeerFlow (`extensions_config.json`), and any MCP-compatible runtime.
|
|
168
|
+
|
|
169
|
+
|
|
170
|
+
|
|
171
|
+
---
|
|
172
|
+
|
|
173
|
+
## Setup (Self-Hosted)
|
|
174
|
+
|
|
175
|
+
### 1. Create a Supabase project
|
|
176
|
+
|
|
177
|
+
Head to [supabase.com](https://supabase.com) and spin up a free project.
|
|
178
|
+
|
|
179
|
+
### 2. Apply the schema
|
|
180
|
+
|
|
181
|
+
Open the SQL Editor in your Supabase dashboard and run the contents of `supabase-schema.sql`:
|
|
182
|
+
|
|
183
|
+
```bash
|
|
184
|
+
# Locate the schema file
|
|
185
|
+
cat node_modules/cogxai/supabase-schema.sql
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
Alternatively, `brain.init()` can attempt auto-creation (requires an `exec_sql` RPC function in your Supabase project).
|
|
189
|
+
|
|
190
|
+
### 3. Enable extensions
|
|
191
|
+
|
|
192
|
+
In the Supabase SQL Editor:
|
|
193
|
+
|
|
194
|
+
```sql
|
|
195
|
+
CREATE EXTENSION IF NOT EXISTS vector;
|
|
196
|
+
CREATE EXTENSION IF NOT EXISTS pg_trgm;
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
### 4. Grab your keys
|
|
200
|
+
|
|
201
|
+
- **Supabase URL + service key**: Project Settings > API
|
|
202
|
+
- **Anthropic API key**: [console.anthropic.com](https://console.anthropic.com) (optional for basic store/recall, required for dream cycles)
|
|
203
|
+
- **Voyage AI or OpenAI key**: Enables vector similarity search (optional — falls back to keyword scoring without it)
|
|
204
|
+
|
|
205
|
+
---
|
|
206
|
+
|
|
207
|
+
## API Reference
|
|
208
|
+
|
|
209
|
+
### Constructor
|
|
210
|
+
|
|
211
|
+
**Hosted mode** — zero infrastructure:
|
|
212
|
+
|
|
213
|
+
```typescript
|
|
214
|
+
const brain = new Cortex({
|
|
215
|
+
hosted: {
|
|
216
|
+
apiKey: string, // From `npx cogxai register`
|
|
217
|
+
baseUrl?: string, // Default: 'https://cogxai.org'
|
|
218
|
+
},
|
|
219
|
+
});
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
**Self-hosted mode** — full control:
|
|
223
|
+
|
|
224
|
+
```typescript
|
|
225
|
+
const brain = new Cortex({
|
|
226
|
+
// Required
|
|
227
|
+
supabase: {
|
|
228
|
+
url: string,
|
|
229
|
+
serviceKey: string,
|
|
230
|
+
},
|
|
231
|
+
|
|
232
|
+
// Optional — needed for dream cycles and LLM-based importance scoring
|
|
233
|
+
anthropic: {
|
|
234
|
+
apiKey: string,
|
|
235
|
+
model?: string, // default: 'claude-sonnet-4-6'
|
|
236
|
+
},
|
|
237
|
+
|
|
238
|
+
// Optional — activates vector similarity search
|
|
239
|
+
embedding: {
|
|
240
|
+
provider: 'voyage' | 'openai',
|
|
241
|
+
apiKey: string,
|
|
242
|
+
model?: string, // default: voyage-3-lite / text-embedding-3-small
|
|
243
|
+
dimensions?: number, // default: 1024
|
|
244
|
+
},
|
|
245
|
+
|
|
246
|
+
// Optional — enables on-chain memory hash commits
|
|
247
|
+
solana: {
|
|
248
|
+
rpcUrl?: string,
|
|
249
|
+
botWalletPrivateKey?: string,
|
|
250
|
+
},
|
|
251
|
+
|
|
252
|
+
// Optional — wallet-based memory isolation
|
|
253
|
+
ownerWallet?: string,
|
|
254
|
+
});
|
|
255
|
+
```
|
|
256
|
+
|
|
257
|
+
### `brain.init()`
|
|
258
|
+
|
|
259
|
+
Initialize the database schema. Call once before any other operation.
|
|
260
|
+
|
|
261
|
+
```typescript
|
|
262
|
+
await brain.init();
|
|
263
|
+
```
|
|
264
|
+
|
|
265
|
+
### `brain.store(opts)`
|
|
266
|
+
|
|
267
|
+
Persist a new memory. Returns the memory ID or `null`.
|
|
268
|
+
|
|
269
|
+
```typescript
|
|
270
|
+
const id = await brain.store({
|
|
271
|
+
type: 'episodic', // 'episodic' | 'semantic' | 'procedural' | 'self_model'
|
|
272
|
+
content: 'Full content of the memory...',
|
|
273
|
+
summary: 'Brief summary',
|
|
274
|
+
source: 'my-agent',
|
|
275
|
+
tags: ['user', 'question'],
|
|
276
|
+
importance: 0.7, // 0-1, or omit for LLM-based scoring
|
|
277
|
+
relatedUser: 'user-123', // optional — enables per-user recall
|
|
278
|
+
emotionalValence: 0.3, // optional — -1 (negative) to 1 (positive)
|
|
279
|
+
evidenceIds: [42, 43], // optional — link to source memories
|
|
280
|
+
});
|
|
281
|
+
```
|
|
282
|
+
|
|
283
|
+
**Memory types:**
|
|
284
|
+
|
|
285
|
+
| Type | Decay/day | Use for |
|
|
286
|
+
|------|-----------|---------|
|
|
287
|
+
| `episodic` | 7% | Raw interactions, conversations, events |
|
|
288
|
+
| `semantic` | 2% | Learned knowledge, patterns, insights |
|
|
289
|
+
| `procedural` | 3% | Behavioral rules, what works/doesn't |
|
|
290
|
+
| `self_model` | 1% | Identity, self-understanding |
|
|
291
|
+
|
|
292
|
+
### `brain.recall(opts)`
|
|
293
|
+
|
|
294
|
+
Retrieve memories through hybrid scoring (vector similarity + keyword matching + tag overlap + importance + entity graph + association bonds).
|
|
295
|
+
|
|
296
|
+
```typescript
|
|
297
|
+
const memories = await brain.recall({
|
|
298
|
+
query: 'what happened with user-123',
|
|
299
|
+
tags: ['pricing'],
|
|
300
|
+
relatedUser: 'user-123',
|
|
301
|
+
memoryTypes: ['episodic', 'semantic'],
|
|
302
|
+
limit: 10,
|
|
303
|
+
minImportance: 0.3,
|
|
304
|
+
});
|
|
305
|
+
```
|
|
306
|
+
|
|
307
|
+
**6-phase retrieval pipeline:**
|
|
308
|
+
1. Vector search (memory + fragment level via pgvector)
|
|
309
|
+
2. Metadata filtering (user, wallet, tags, types)
|
|
310
|
+
3. Merge vector + metadata candidates
|
|
311
|
+
4. Composite scoring: `(1.0 × recency + 2.0 × relevance + 2.0 × importance + 4.0 × vector_similarity) × decay_factor`
|
|
312
|
+
5. Entity-aware expansion — pull in memories from co-occurring entities
|
|
313
|
+
6. Bond-typed graph traversal — follow strong bonds (causes > supports > resolves > elaborates > contradicts > relates > follows)
|
|
314
|
+
|
|
315
|
+
Retrieved memories get reinforced: access count increments, decay resets, and co-retrieved memories strengthen their association bonds (Hebbian learning).
|
|
316
|
+
|
|
317
|
+
### `brain.recallSummaries(opts)`
|
|
318
|
+
|
|
319
|
+
Token-efficient retrieval — returns lightweight summaries (~50 tokens each) instead of full content.
|
|
320
|
+
|
|
321
|
+
```typescript
|
|
322
|
+
const summaries = await brain.recallSummaries({ query: 'recent events' });
|
|
323
|
+
// Each contains: id, summary, type, tags, concepts, importance, decay, created_at
|
|
324
|
+
```
|
|
325
|
+
|
|
326
|
+
### `brain.hydrate(ids)`
|
|
327
|
+
|
|
328
|
+
Load full content for specific memory IDs. Pair with `recallSummaries` for progressive disclosure.
|
|
329
|
+
|
|
330
|
+
```typescript
|
|
331
|
+
const summaries = await brain.recallSummaries({ query: 'important' });
|
|
332
|
+
const topIds = summaries.slice(0, 3).map(s => s.id);
|
|
333
|
+
const full = await brain.hydrate(topIds);
|
|
334
|
+
```
|
|
335
|
+
|
|
336
|
+
### `brain.dream(opts?)`
|
|
337
|
+
|
|
338
|
+
Execute one dream cycle. Requires `anthropic` configuration.
|
|
339
|
+
|
|
340
|
+
```typescript
|
|
341
|
+
await brain.dream({
|
|
342
|
+
onEmergence: async (thought) => {
|
|
343
|
+
console.log('Agent thought:', thought);
|
|
344
|
+
// Post to Discord, save to file, etc.
|
|
345
|
+
},
|
|
346
|
+
});
|
|
347
|
+
```
|
|
348
|
+
|
|
349
|
+
**Six phases:**
|
|
350
|
+
1. **Consolidation** — generates focal-point questions from recent memories, synthesizes evidence-linked insights
|
|
351
|
+
2. **Compaction** — summarizes old, faded episodic memories into semantic summaries (Beads-inspired)
|
|
352
|
+
3. **Reflection** — reviews accumulated knowledge, updates self-model with evidence citations
|
|
353
|
+
4. **Contradiction Resolution** — finds unresolved `contradicts` links, analyzes each pair via LLM, stores a resolved belief with `resolves` links, accelerates decay on the weaker memory
|
|
354
|
+
5. **Learning** — extracts behavioral patterns from action outcomes, refines procedural knowledge
|
|
355
|
+
6. **Emergence** — introspective synthesis, output sent to `onEmergence` callback
|
|
356
|
+
|
|
357
|
+
### `brain.startDreamSchedule()` / `brain.stopDreamSchedule()`
|
|
358
|
+
|
|
359
|
+
Automated dream cycles every 6 hours + daily memory decay at 3am UTC. Also triggers on accumulated importance (event-driven reflection).
|
|
360
|
+
|
|
361
|
+
```typescript
|
|
362
|
+
brain.startDreamSchedule();
|
|
363
|
+
// ... later
|
|
364
|
+
brain.stopDreamSchedule();
|
|
365
|
+
```
|
|
366
|
+
|
|
367
|
+
### `brain.link(sourceId, targetId, type, strength?)`
|
|
368
|
+
|
|
369
|
+
Forge a typed association between two memories.
|
|
370
|
+
|
|
371
|
+
```typescript
|
|
372
|
+
await brain.link(42, 43, 'supports', 0.8);
|
|
373
|
+
```
|
|
374
|
+
|
|
375
|
+
Link types: `'supports'` | `'contradicts'` | `'elaborates'` | `'causes'` | `'follows'` | `'relates'` | `'resolves'`
|
|
376
|
+
|
|
377
|
+
### `brain.decay()`
|
|
378
|
+
|
|
379
|
+
Manually trigger memory decay. Each type decays at its own rate per day.
|
|
380
|
+
|
|
381
|
+
```typescript
|
|
382
|
+
const decayed = await brain.decay();
|
|
383
|
+
console.log(`${decayed} memories decayed`);
|
|
384
|
+
```
|
|
385
|
+
|
|
386
|
+
### `brain.stats()`
|
|
387
|
+
|
|
388
|
+
Retrieve memory system statistics.
|
|
389
|
+
|
|
390
|
+
```typescript
|
|
391
|
+
const stats = await brain.stats();
|
|
392
|
+
// { total, byType, avgImportance, avgDecay, totalDreamSessions, ... }
|
|
393
|
+
```
|
|
394
|
+
|
|
395
|
+
### `brain.recent(hours, types?, limit?)`
|
|
396
|
+
|
|
397
|
+
Fetch recent memories from the last N hours.
|
|
398
|
+
|
|
399
|
+
```typescript
|
|
400
|
+
const last24h = await brain.recent(24);
|
|
401
|
+
const recentInsights = await brain.recent(168, ['semantic'], 10);
|
|
402
|
+
```
|
|
403
|
+
|
|
404
|
+
### `brain.selfModel()`
|
|
405
|
+
|
|
406
|
+
Access the agent's current self-model memories.
|
|
407
|
+
|
|
408
|
+
```typescript
|
|
409
|
+
const identity = await brain.selfModel();
|
|
410
|
+
```
|
|
411
|
+
|
|
412
|
+
### `brain.formatContext(memories)`
|
|
413
|
+
|
|
414
|
+
Format memories into a markdown string for LLM system prompt injection.
|
|
415
|
+
|
|
416
|
+
```typescript
|
|
417
|
+
const memories = await brain.recall({ query: userMessage });
|
|
418
|
+
const context = brain.formatContext(memories);
|
|
419
|
+
|
|
420
|
+
// Use in your LLM call:
|
|
421
|
+
const response = await anthropic.messages.create({
|
|
422
|
+
system: `You are a helpful agent.\n\n## Memory\n${context}`,
|
|
423
|
+
messages: [{ role: 'user', content: userMessage }],
|
|
424
|
+
});
|
|
425
|
+
```
|
|
426
|
+
|
|
427
|
+
### `brain.inferConcepts(summary, source, tags)`
|
|
428
|
+
|
|
429
|
+
Auto-classify memory content into structured concept labels.
|
|
430
|
+
|
|
431
|
+
```typescript
|
|
432
|
+
const concepts = brain.inferConcepts('User frustrated about pricing', 'chat', ['pricing']);
|
|
433
|
+
// ['holder_behavior', 'sentiment_shift']
|
|
434
|
+
```
|
|
435
|
+
|
|
436
|
+
### `brain.on(event, handler)`
|
|
437
|
+
|
|
438
|
+
Subscribe to memory events.
|
|
439
|
+
|
|
440
|
+
```typescript
|
|
441
|
+
brain.on('memory:stored', ({ importance, memoryType }) => {
|
|
442
|
+
console.log(`New ${memoryType} memory stored (importance: ${importance})`);
|
|
443
|
+
});
|
|
444
|
+
```
|
|
445
|
+
|
|
446
|
+
### `brain.destroy()`
|
|
447
|
+
|
|
448
|
+
Stop dream schedules, clean up event listeners.
|
|
449
|
+
|
|
450
|
+
---
|
|
451
|
+
|
|
452
|
+
## Hosted vs Self-Hosted
|
|
453
|
+
|
|
454
|
+
| | **Hosted** | **Self-Hosted** |
|
|
455
|
+
|---|---|---|
|
|
456
|
+
| **Setup** | Just an API key | Your own Supabase |
|
|
457
|
+
| **store / recall / stats** | Yes | Yes |
|
|
458
|
+
| **recent / self-model / link** | Yes | Yes |
|
|
459
|
+
| **Dream cycles** | No | Yes (requires Anthropic) |
|
|
460
|
+
| **Entity graph** | No | Yes |
|
|
461
|
+
| **Memory packs** | No | Yes |
|
|
462
|
+
| **Embeddings** | Managed | Configurable (Voyage/OpenAI) |
|
|
463
|
+
| **On-chain commits** | No | Yes (Solana) |
|
|
464
|
+
| **Dashboard** | Yes (API key login) | Yes (Privy wallet login) |
|
|
465
|
+
|
|
466
|
+
## Graceful Degradation
|
|
467
|
+
|
|
468
|
+
Self-hosted mode progressively enhances based on what you configure:
|
|
469
|
+
|
|
470
|
+
| Feature | Without it |
|
|
471
|
+
|---------|------------|
|
|
472
|
+
| `anthropic` not set | LLM importance scoring falls back to rule-based heuristics. `dream()` throws. |
|
|
473
|
+
| `embedding` not set | Vector search disabled, recall uses keyword + tag scoring only. |
|
|
474
|
+
| `solana` not set | On-chain memory commits silently skipped. |
|
|
475
|
+
|
|
476
|
+
**Minimum hosted setup:**
|
|
477
|
+
```typescript
|
|
478
|
+
const brain = new Cortex({
|
|
479
|
+
hosted: { apiKey: 'clk_...' },
|
|
480
|
+
});
|
|
481
|
+
```
|
|
482
|
+
|
|
483
|
+
**Minimum self-hosted setup** — just Supabase:
|
|
484
|
+
```typescript
|
|
485
|
+
const brain = new Cortex({
|
|
486
|
+
supabase: { url: '...', serviceKey: '...' },
|
|
487
|
+
});
|
|
488
|
+
```
|
|
489
|
+
|
|
490
|
+
Both give you full store/recall with keyword-based retrieval. Self-hosted adds dream cycles, vector embeddings, and on-chain commits as you add API keys.
|
|
491
|
+
|
|
492
|
+
---
|
|
493
|
+
|
|
494
|
+
## Example: Chat Agent with Memory
|
|
495
|
+
|
|
496
|
+
```typescript
|
|
497
|
+
import { Cortex } from 'cogxai';
|
|
498
|
+
import Anthropic from '@anthropic-ai/sdk';
|
|
499
|
+
|
|
500
|
+
const brain = new Cortex({
|
|
501
|
+
supabase: { url: process.env.SUPABASE_URL!, serviceKey: process.env.SUPABASE_KEY! },
|
|
502
|
+
anthropic: { apiKey: process.env.ANTHROPIC_API_KEY! },
|
|
503
|
+
embedding: { provider: 'voyage', apiKey: process.env.VOYAGE_API_KEY! },
|
|
504
|
+
});
|
|
505
|
+
await brain.init();
|
|
506
|
+
brain.startDreamSchedule();
|
|
507
|
+
|
|
508
|
+
const anthropic = new Anthropic();
|
|
509
|
+
|
|
510
|
+
async function handleMessage(userId: string, message: string): Promise<string> {
|
|
511
|
+
// Retrieve relevant memories
|
|
512
|
+
const memories = await brain.recall({
|
|
513
|
+
query: message,
|
|
514
|
+
relatedUser: userId,
|
|
515
|
+
limit: 5,
|
|
516
|
+
});
|
|
517
|
+
|
|
518
|
+
// Generate response with memory context
|
|
519
|
+
const response = await anthropic.messages.create({
|
|
520
|
+
model: 'claude-sonnet-4-6-20250514',
|
|
521
|
+
max_tokens: 500,
|
|
522
|
+
system: `You are a helpful assistant.\n\n## What you remember\n${brain.formatContext(memories)}`,
|
|
523
|
+
messages: [{ role: 'user', content: message }],
|
|
524
|
+
});
|
|
525
|
+
|
|
526
|
+
const reply = response.content[0].type === 'text' ? response.content[0].text : '';
|
|
527
|
+
|
|
528
|
+
// Persist this interaction as a memory
|
|
529
|
+
await brain.store({
|
|
530
|
+
type: 'episodic',
|
|
531
|
+
content: `User (${userId}): ${message}\nAssistant: ${reply}`,
|
|
532
|
+
summary: `Conversation with ${userId} about ${message.slice(0, 50)}`,
|
|
533
|
+
source: 'chat',
|
|
534
|
+
relatedUser: userId,
|
|
535
|
+
tags: brain.inferConcepts(message, 'chat', []),
|
|
536
|
+
});
|
|
537
|
+
|
|
538
|
+
return reply;
|
|
539
|
+
}
|
|
540
|
+
```
|
|
541
|
+
|
|
542
|
+
---
|
|
543
|
+
|
|
544
|
+
## How It Works
|
|
545
|
+
|
|
546
|
+
### Memory Retrieval
|
|
547
|
+
|
|
548
|
+
Hybrid scoring combines multiple signals (Park et al. 2023):
|
|
549
|
+
|
|
550
|
+
- **Recency**: `0.995^hours` exponential decay since last access
|
|
551
|
+
- **Relevance**: Keyword trigram similarity + tag overlap
|
|
552
|
+
- **Importance**: LLM-scored 1-10, normalized to 0-1
|
|
553
|
+
- **Vector similarity**: Cosine similarity via pgvector HNSW indexes
|
|
554
|
+
- **Graph boost**: Association bond strength between co-retrieved memories
|
|
555
|
+
|
|
556
|
+
Retrieved memories get reinforced — access count increments, decay resets, and co-retrieved memories strengthen their bonds (Hebbian learning).
|
|
557
|
+
|
|
558
|
+
### Memory Decay
|
|
559
|
+
|
|
560
|
+
Each type fades at a different rate, inspired by biological memory systems:
|
|
561
|
+
|
|
562
|
+
- **Episodic** (0.93/day): Events fade quickly unless reinforced
|
|
563
|
+
- **Semantic** (0.98/day): Knowledge persists
|
|
564
|
+
- **Procedural** (0.97/day): Behavioral patterns remain stable
|
|
565
|
+
- **Self-model** (0.99/day): Identity is nearly permanent
|
|
566
|
+
|
|
567
|
+
### Hash-Based IDs (Beads-inspired)
|
|
568
|
+
|
|
569
|
+
Every memory receives a collision-resistant ID like `cogxai-a1b2c3d4`:
|
|
570
|
+
|
|
571
|
+
- **No merge conflicts**: Multiple agents can create memories simultaneously without collisions
|
|
572
|
+
- **Stable references**: IDs survive database migrations and replication
|
|
573
|
+
- **Human-readable**: Easy to reference in logs and debugging
|
|
574
|
+
|
|
575
|
+
### Memory Compaction (Beads-inspired)
|
|
576
|
+
|
|
577
|
+
Old, faded memories get summarized to conserve context window space:
|
|
578
|
+
|
|
579
|
+
**Compaction criteria:**
|
|
580
|
+
- Memory is older than 7 days
|
|
581
|
+
- Decay factor < 0.3 (faded from disuse)
|
|
582
|
+
- Importance < 0.5 (not critical)
|
|
583
|
+
- Only episodic memories (insights and self-model are preserved)
|
|
584
|
+
|
|
585
|
+
**Process:**
|
|
586
|
+
1. Group candidates by concept
|
|
587
|
+
2. Generate semantic summary for each group
|
|
588
|
+
3. Store summary with evidence links to originals
|
|
589
|
+
4. Mark originals as compacted
|
|
590
|
+
|
|
591
|
+
This mirrors how human memory consolidates — details fade, patterns persist.
|
|
592
|
+
|
|
593
|
+
### Dream Cycles
|
|
594
|
+
|
|
595
|
+
Six-phase introspection process triggered by accumulated importance or 6-hour cron:
|
|
596
|
+
|
|
597
|
+
1. **Consolidation** — Generate focal-point questions from recent episodic memories, synthesize evidence-linked semantic insights
|
|
598
|
+
2. **Compaction** — Summarize old, faded episodic memories (7+ days, low importance, high decay) into semantic summaries. Originals marked as compacted.
|
|
599
|
+
3. **Reflection** — Review self-model + recent semantic memories. Produce self-observations with evidence citations. Detect patterns and contradictions.
|
|
600
|
+
4. **Contradiction Resolution** — Find unresolved `contradicts` links via graph query. LLM analyzes each pair, stores a resolved belief as semantic memory with `resolves` links. Accelerates decay on the weaker/older memory.
|
|
601
|
+
5. **Learning** — Track action outcomes. Extract what worked and what didn't into procedural memories. Refine behavioral strategies.
|
|
602
|
+
6. **Emergence** — Introspective synthesis — the agent examines its own existence. Optionally posts the thought externally via `onEmergence` callback.
|
|
603
|
+
|
|
604
|
+
### Molecular Memory Architecture
|
|
605
|
+
|
|
606
|
+
Memories form a graph with typed bonds:
|
|
607
|
+
|
|
608
|
+
```
|
|
609
|
+
Memory Graph:
|
|
610
|
+
├── Memories = nodes with type, importance, decay
|
|
611
|
+
├── Bonds = typed weighted edges
|
|
612
|
+
│ ├── causes (1.0) — "this led to that"
|
|
613
|
+
│ ├── supports (0.9) — "evidence for"
|
|
614
|
+
│ ├── resolves (0.8) — "contradiction resolved"
|
|
615
|
+
│ ├── elaborates (0.7) — "adds detail"
|
|
616
|
+
│ ├── contradicts (0.6) — "these conflict"
|
|
617
|
+
│ ├── relates (0.4) — "conceptually linked"
|
|
618
|
+
│ └── follows (0.3) — "temporal sequence"
|
|
619
|
+
├── Entities = extracted people, tokens, concepts, wallets
|
|
620
|
+
└── Co-occurrence = entities that appear together across memories
|
|
621
|
+
```
|
|
622
|
+
|
|
623
|
+
**Why it's faster:** Conventional retrieval scans all memories — O(n). Bond traversal follows strong connections — O(k) where k ≈ 3-5.
|
|
624
|
+
|
|
625
|
+
### Permissionless Inference (Venice)
|
|
626
|
+
|
|
627
|
+
CogxAI supports [Venice](https://venice.ai) as a decentralized inference provider:
|
|
628
|
+
|
|
629
|
+
```typescript
|
|
630
|
+
const brain = new Cortex({
|
|
631
|
+
supabase: { ... },
|
|
632
|
+
venice: {
|
|
633
|
+
apiKey: process.env.VENICE_API_KEY,
|
|
634
|
+
model: 'llama-3.3-70b', // or deepseek-r1, qwen, etc.
|
|
635
|
+
},
|
|
636
|
+
inference: {
|
|
637
|
+
primary: 'venice', // Use Venice first
|
|
638
|
+
fallback: 'anthropic', // Fall back to Claude if needed
|
|
639
|
+
},
|
|
640
|
+
});
|
|
641
|
+
```
|
|
642
|
+
|
|
643
|
+
**Why Venice?**
|
|
644
|
+
- **Permissionless**: No approval process, no rate limits
|
|
645
|
+
- **Private**: No data retention — your prompts stay yours
|
|
646
|
+
- **Decentralized**: Aligns with CogxAI's on-chain memory philosophy
|
|
647
|
+
- **Multi-model**: Access Llama, DeepSeek, Qwen, and more
|
|
648
|
+
|
|
649
|
+
Set `INFERENCE_PRIMARY=venice` and `VENICE_API_KEY` to use Venice by default.
|
|
650
|
+
|
|
651
|
+
### Association Graph & Entity Knowledge Graph
|
|
652
|
+
|
|
653
|
+
**Memory-to-memory bonds** — typed, weighted links:
|
|
654
|
+
- `supports`, `contradicts`, `elaborates`, `causes`, `follows`, `relates`, `resolves`
|
|
655
|
+
- Auto-linked on storage via embedding similarity and heuristics
|
|
656
|
+
- Strengthened through co-retrieval (Hebbian learning)
|
|
657
|
+
- Boosts recall scores for connected memories
|
|
658
|
+
- `contradicts` links are resolved during dream cycles, producing `resolves` links
|
|
659
|
+
|
|
660
|
+
**Entity knowledge graph** — extracted from memory content:
|
|
661
|
+
- Entity types: person, project, concept, token, wallet, location, event
|
|
662
|
+
- Entities extracted automatically (Twitter handles, wallet addresses, token tickers, proper nouns)
|
|
663
|
+
- Entity co-occurrence drives recall expansion — when recalling about an entity, memories from co-occurring entities are surfaced with a scaled boost
|
|
664
|
+
|
|
665
|
+
---
|
|
666
|
+
|
|
667
|
+
## Running CogxAI
|
|
668
|
+
|
|
669
|
+
```bash
|
|
670
|
+
git clone https://github.com/Black-dork/cogxai.git
|
|
671
|
+
cd cogxai
|
|
672
|
+
npm install
|
|
673
|
+
cp .env.example .env # fill in API keys
|
|
674
|
+
npm run dev
|
|
675
|
+
```
|
|
676
|
+
|
|
677
|
+
See `.env.example` for the full list of environment variables (Supabase, Anthropic, embedding provider, optional integrations).
|
|
678
|
+
|
|
679
|
+
---
|
|
680
|
+
|
|
681
|
+
## Stack
|
|
682
|
+
|
|
683
|
+
TypeScript, Supabase (PostgreSQL + pgvector), Anthropic Claude, Voyage AI / OpenAI embeddings, Solana Web3.js, Node.js.
|
|
684
|
+
|
|
685
|
+
## Contributing
|
|
686
|
+
|
|
687
|
+
Contributions welcome. See [CONTRIBUTING.md](./CONTRIBUTING.md) for setup instructions and guidelines.
|
|
688
|
+
|
|
689
|
+
## License
|
|
690
|
+
|
|
691
|
+
MIT
|