hipcortex 0.5.2__tar.gz → 1.4.0__tar.gz
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.
- {hipcortex-0.5.2 → hipcortex-1.4.0}/PKG-INFO +2 -2
- {hipcortex-0.5.2 → hipcortex-1.4.0}/README.md +122 -122
- {hipcortex-0.5.2 → hipcortex-1.4.0}/hipcortex/__init__.py +17 -15
- {hipcortex-0.5.2 → hipcortex-1.4.0}/hipcortex/adapters/autogen.py +54 -0
- {hipcortex-0.5.2 → hipcortex-1.4.0}/hipcortex/adapters/crewai.py +60 -0
- {hipcortex-0.5.2 → hipcortex-1.4.0}/hipcortex/cli.py +1 -1
- {hipcortex-0.5.2 → hipcortex-1.4.0}/hipcortex/client.py +157 -0
- {hipcortex-0.5.2 → hipcortex-1.4.0}/hipcortex/install/SKILL.md +34 -0
- hipcortex-1.4.0/hipcortex/install/mcp_server.py +1570 -0
- {hipcortex-0.5.2 → hipcortex-1.4.0}/hipcortex/langchain_memory.py +71 -0
- hipcortex-1.4.0/hipcortex/substrate.py +100 -0
- {hipcortex-0.5.2 → hipcortex-1.4.0}/hipcortex.egg-info/PKG-INFO +2 -2
- {hipcortex-0.5.2 → hipcortex-1.4.0}/hipcortex.egg-info/SOURCES.txt +4 -1
- {hipcortex-0.5.2 → hipcortex-1.4.0}/pyproject.toml +53 -53
- {hipcortex-0.5.2 → hipcortex-1.4.0}/tests/test_can_execute.py +33 -33
- hipcortex-1.4.0/tests/test_client_v070.py +161 -0
- hipcortex-1.4.0/tests/test_substrate.py +72 -0
- hipcortex-0.5.2/hipcortex/install/mcp_server.py +0 -794
- {hipcortex-0.5.2 → hipcortex-1.4.0}/hipcortex/adapters/__init__.py +0 -0
- {hipcortex-0.5.2 → hipcortex-1.4.0}/hipcortex/adapters/common.py +0 -0
- {hipcortex-0.5.2 → hipcortex-1.4.0}/hipcortex/async_client.py +0 -0
- {hipcortex-0.5.2 → hipcortex-1.4.0}/hipcortex/config.py +0 -0
- {hipcortex-0.5.2 → hipcortex-1.4.0}/hipcortex/daemon.py +0 -0
- {hipcortex-0.5.2 → hipcortex-1.4.0}/hipcortex/doctor.py +0 -0
- {hipcortex-0.5.2 → hipcortex-1.4.0}/hipcortex/framework_scaffold.py +0 -0
- {hipcortex-0.5.2 → hipcortex-1.4.0}/hipcortex/indexer.py +0 -0
- {hipcortex-0.5.2 → hipcortex-1.4.0}/hipcortex/install/__init__.py +0 -0
- {hipcortex-0.5.2 → hipcortex-1.4.0}/hipcortex/install/templates/autogen.py.tmpl +0 -0
- {hipcortex-0.5.2 → hipcortex-1.4.0}/hipcortex/install/templates/crewai.py.tmpl +0 -0
- {hipcortex-0.5.2 → hipcortex-1.4.0}/hipcortex/install/templates/dspy.py.tmpl +0 -0
- {hipcortex-0.5.2 → hipcortex-1.4.0}/hipcortex/install/templates/langchain.py.tmpl +0 -0
- {hipcortex-0.5.2 → hipcortex-1.4.0}/hipcortex/install/templates/llamaindex.py.tmpl +0 -0
- {hipcortex-0.5.2 → hipcortex-1.4.0}/hipcortex/install/templates/n8n_curl.sh.tmpl +0 -0
- {hipcortex-0.5.2 → hipcortex-1.4.0}/hipcortex/install/templates/pydantic_ai.py.tmpl +0 -0
- {hipcortex-0.5.2 → hipcortex-1.4.0}/hipcortex/install_hosts.py +0 -0
- {hipcortex-0.5.2 → hipcortex-1.4.0}/hipcortex/llamaindex_storage.py +0 -0
- {hipcortex-0.5.2 → hipcortex-1.4.0}/hipcortex.egg-info/dependency_links.txt +0 -0
- {hipcortex-0.5.2 → hipcortex-1.4.0}/hipcortex.egg-info/entry_points.txt +0 -0
- {hipcortex-0.5.2 → hipcortex-1.4.0}/hipcortex.egg-info/requires.txt +0 -0
- {hipcortex-0.5.2 → hipcortex-1.4.0}/hipcortex.egg-info/top_level.txt +0 -0
- {hipcortex-0.5.2 → hipcortex-1.4.0}/setup.cfg +0 -0
- {hipcortex-0.5.2 → hipcortex-1.4.0}/setup.py +0 -0
- {hipcortex-0.5.2 → hipcortex-1.4.0}/tests/test_adapters_common.py +0 -0
- {hipcortex-0.5.2 → hipcortex-1.4.0}/tests/test_async_client.py +0 -0
- {hipcortex-0.5.2 → hipcortex-1.4.0}/tests/test_async_langchain.py +0 -0
- {hipcortex-0.5.2 → hipcortex-1.4.0}/tests/test_cli_install.py +0 -0
- {hipcortex-0.5.2 → hipcortex-1.4.0}/tests/test_client_config.py +0 -0
- {hipcortex-0.5.2 → hipcortex-1.4.0}/tests/test_config.py +0 -0
- {hipcortex-0.5.2 → hipcortex-1.4.0}/tests/test_daemon.py +0 -0
- {hipcortex-0.5.2 → hipcortex-1.4.0}/tests/test_doctor.py +0 -0
- {hipcortex-0.5.2 → hipcortex-1.4.0}/tests/test_harness_with_loop.py +0 -0
- {hipcortex-0.5.2 → hipcortex-1.4.0}/tests/test_host_install_e2e.py +0 -0
- {hipcortex-0.5.2 → hipcortex-1.4.0}/tests/test_reflect_predict.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: hipcortex
|
|
3
|
-
Version:
|
|
3
|
+
Version: 1.4.0
|
|
4
4
|
Summary: Persistent causal memory for AI agents -- LangChain, LlamaIndex, AutoGen, CrewAI
|
|
5
5
|
Author: HipCortex Contributors
|
|
6
6
|
License: Apache-2.0
|
|
@@ -59,7 +59,7 @@ hipcortex install # wizard: MCP hosts + copies ~/.hipcortex-mcp/server.py (18 t
|
|
|
59
59
|
hipcortex channels # honesty matrix (native / mcp / framework / guide)
|
|
60
60
|
```
|
|
61
61
|
|
|
62
|
-
**Version matrix:** product pip/Cargo/MCP `serverInfo` = **0.5.2**; VS Code VSIX = **0.5.
|
|
62
|
+
**Version matrix:** product pip/Cargo/MCP `serverInfo` = **0.5.2**; VS Code VSIX = **0.5.8**. See [docs/channels.md](../../docs/channels.md).
|
|
63
63
|
|
|
64
64
|
---
|
|
65
65
|
|
|
@@ -1,122 +1,122 @@
|
|
|
1
|
-
# HipCortex Python SDK (`v0.5.2`)
|
|
2
|
-
|
|
3
|
-
**Persistent causal topological memory, recursive Bayesian world-model prediction (`/worldmodel/rollout`), and automatic FSM skill compilation for autonomous AI agents.**
|
|
4
|
-
|
|
5
|
-
Runs against the standalone local Rust binary (`http://127.0.0.1:3030`) with `0.48–0.61 ms p50` write latency, SHA-256 Merkle audit chains, and Headroom context budgeting (`59–88% token savings`).
|
|
6
|
-
|
|
7
|
-
---
|
|
8
|
-
|
|
9
|
-
## 🚀 Installation
|
|
10
|
-
|
|
11
|
-
```bash
|
|
12
|
-
pip install hipcortex
|
|
13
|
-
hipcortex doctor # verify server health + version after install
|
|
14
|
-
hipcortex install # wizard: MCP hosts + copies ~/.hipcortex-mcp/server.py (18 tools)
|
|
15
|
-
hipcortex channels # honesty matrix (native / mcp / framework / guide)
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
**Version matrix:** product pip/Cargo/MCP `serverInfo` = **0.5.2**; VS Code VSIX = **0.5.
|
|
19
|
-
|
|
20
|
-
---
|
|
21
|
-
|
|
22
|
-
## ⚡ Quick Start: Multi-Tier Memory & World Model Prediction
|
|
23
|
-
|
|
24
|
-
```python
|
|
25
|
-
from hipcortex import HipCortexClient
|
|
26
|
-
|
|
27
|
-
client = HipCortexClient(base_url="http://127.0.0.1:3030")
|
|
28
|
-
|
|
29
|
-
# 1. Multi-Tier Memory Ingestion (5 verified memory tiers)
|
|
30
|
-
client.add_memory(
|
|
31
|
-
actor="agent",
|
|
32
|
-
action="configured",
|
|
33
|
-
target="jwt_token_ttl=3600",
|
|
34
|
-
record_type="Working", # Mapped natively to Temporal tier
|
|
35
|
-
priority="high"
|
|
36
|
-
)
|
|
37
|
-
|
|
38
|
-
client.add_memory(
|
|
39
|
-
actor="agent",
|
|
40
|
-
action="established",
|
|
41
|
-
target="All database migrations must run inside transactions",
|
|
42
|
-
record_type="Semantic", # Mapped natively to Symbolic/LongTerm tier
|
|
43
|
-
priority="pinned"
|
|
44
|
-
)
|
|
45
|
-
|
|
46
|
-
# 2. Check SelfModel Execution Capacity Gates before running risky actions
|
|
47
|
-
if client.can_execute("rollout"):
|
|
48
|
-
print("Health check passed — engine ready for simulation")
|
|
49
|
-
|
|
50
|
-
# 3. World Model Trajectory Rollout Prediction (POST /worldmodel/rollout)
|
|
51
|
-
rollout_result = client.rollout(
|
|
52
|
-
initial_state={"db_status": "locked", "active_tx": 1},
|
|
53
|
-
actions=["rollback_tx", "release_lock", "retry_migration"]
|
|
54
|
-
)
|
|
55
|
-
print("Predicted outcome:", rollout_result)
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
---
|
|
59
|
-
|
|
60
|
-
## 🧠 Proactive CodeAct Harness & Live Beliefs
|
|
61
|
-
|
|
62
|
-
For autonomous agent harnesses (`LangChain`, `LlamaIndex`, `CrewAI`, `AutoGen`), query the topological substrate before reasoning:
|
|
63
|
-
|
|
64
|
-
```python
|
|
65
|
-
# Query live causal beliefs and Top-K topological context (Personalized PageRank)
|
|
66
|
-
context = client.context(query="database migrations", actor="agent", limit=5)
|
|
67
|
-
print("Active Topological Context:\n", context)
|
|
68
|
-
|
|
69
|
-
# Store multi-hop reasoning or CoT reflection
|
|
70
|
-
client.add_memory(
|
|
71
|
-
actor="agent",
|
|
72
|
-
action="reflected",
|
|
73
|
-
target="Migration failed due to missing index on users.email",
|
|
74
|
-
record_type="Causal"
|
|
75
|
-
)
|
|
76
|
-
```
|
|
77
|
-
|
|
78
|
-
---
|
|
79
|
-
|
|
80
|
-
## 🧩 Framework Integrations
|
|
81
|
-
|
|
82
|
-
### LangChain (`ConversationBufferMemory` drop-in)
|
|
83
|
-
```python
|
|
84
|
-
from hipcortex.langchain_memory import HipCortexMemory
|
|
85
|
-
|
|
86
|
-
memory = HipCortexMemory(session_id="session-42", url="http://127.0.0.1:3030")
|
|
87
|
-
```
|
|
88
|
-
|
|
89
|
-
### LlamaIndex (`ChatStore`)
|
|
90
|
-
```python
|
|
91
|
-
from hipcortex.llamaindex_storage import HipCortexStorageContext
|
|
92
|
-
|
|
93
|
-
storage_context = HipCortexStorageContext.from_defaults(client=client)
|
|
94
|
-
```
|
|
95
|
-
|
|
96
|
-
### CrewAI (`Remember` & `Recall` Tools)
|
|
97
|
-
```python
|
|
98
|
-
from hipcortex.adapters.crewai import HipCortexRememberTool, HipCortexRecallTool
|
|
99
|
-
|
|
100
|
-
tools = [HipCortexRememberTool(client=client), HipCortexRecallTool(client=client)]
|
|
101
|
-
```
|
|
102
|
-
|
|
103
|
-
### AutoGen (`Memory` Hook)
|
|
104
|
-
```python
|
|
105
|
-
from hipcortex.adapters.autogen import HipCortexAutoGenMemory
|
|
106
|
-
|
|
107
|
-
mem = HipCortexAutoGenMemory(client=client, agent_id="researcher")
|
|
108
|
-
agent.register_hook("process_message_before_send", mem.on_message_sent)
|
|
109
|
-
```
|
|
110
|
-
|
|
111
|
-
---
|
|
112
|
-
|
|
113
|
-
## 📊 Server Statistics & GDPR Right-to-Forget
|
|
114
|
-
|
|
115
|
-
```python
|
|
116
|
-
# Get Merkle hash chain status and tier counts
|
|
117
|
-
stats = client.stats()
|
|
118
|
-
print("Memory statistics:", stats)
|
|
119
|
-
|
|
120
|
-
# Erase all records for a specific actor (GDPR compliant)
|
|
121
|
-
client.forget("agent")
|
|
122
|
-
```
|
|
1
|
+
# HipCortex Python SDK (`v0.5.2`)
|
|
2
|
+
|
|
3
|
+
**Persistent causal topological memory, recursive Bayesian world-model prediction (`/worldmodel/rollout`), and automatic FSM skill compilation for autonomous AI agents.**
|
|
4
|
+
|
|
5
|
+
Runs against the standalone local Rust binary (`http://127.0.0.1:3030`) with `0.48–0.61 ms p50` write latency, SHA-256 Merkle audit chains, and Headroom context budgeting (`59–88% token savings`).
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## 🚀 Installation
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
pip install hipcortex
|
|
13
|
+
hipcortex doctor # verify server health + version after install
|
|
14
|
+
hipcortex install # wizard: MCP hosts + copies ~/.hipcortex-mcp/server.py (18 tools)
|
|
15
|
+
hipcortex channels # honesty matrix (native / mcp / framework / guide)
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
**Version matrix:** product pip/Cargo/MCP `serverInfo` = **0.5.2**; VS Code VSIX = **0.5.8**. See [docs/channels.md](../../docs/channels.md).
|
|
19
|
+
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
## ⚡ Quick Start: Multi-Tier Memory & World Model Prediction
|
|
23
|
+
|
|
24
|
+
```python
|
|
25
|
+
from hipcortex import HipCortexClient
|
|
26
|
+
|
|
27
|
+
client = HipCortexClient(base_url="http://127.0.0.1:3030")
|
|
28
|
+
|
|
29
|
+
# 1. Multi-Tier Memory Ingestion (5 verified memory tiers)
|
|
30
|
+
client.add_memory(
|
|
31
|
+
actor="agent",
|
|
32
|
+
action="configured",
|
|
33
|
+
target="jwt_token_ttl=3600",
|
|
34
|
+
record_type="Working", # Mapped natively to Temporal tier
|
|
35
|
+
priority="high"
|
|
36
|
+
)
|
|
37
|
+
|
|
38
|
+
client.add_memory(
|
|
39
|
+
actor="agent",
|
|
40
|
+
action="established",
|
|
41
|
+
target="All database migrations must run inside transactions",
|
|
42
|
+
record_type="Semantic", # Mapped natively to Symbolic/LongTerm tier
|
|
43
|
+
priority="pinned"
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
# 2. Check SelfModel Execution Capacity Gates before running risky actions
|
|
47
|
+
if client.can_execute("rollout"):
|
|
48
|
+
print("Health check passed — engine ready for simulation")
|
|
49
|
+
|
|
50
|
+
# 3. World Model Trajectory Rollout Prediction (POST /worldmodel/rollout)
|
|
51
|
+
rollout_result = client.rollout(
|
|
52
|
+
initial_state={"db_status": "locked", "active_tx": 1},
|
|
53
|
+
actions=["rollback_tx", "release_lock", "retry_migration"]
|
|
54
|
+
)
|
|
55
|
+
print("Predicted outcome:", rollout_result)
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## 🧠 Proactive CodeAct Harness & Live Beliefs
|
|
61
|
+
|
|
62
|
+
For autonomous agent harnesses (`LangChain`, `LlamaIndex`, `CrewAI`, `AutoGen`), query the topological substrate before reasoning:
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
# Query live causal beliefs and Top-K topological context (Personalized PageRank)
|
|
66
|
+
context = client.context(query="database migrations", actor="agent", limit=5)
|
|
67
|
+
print("Active Topological Context:\n", context)
|
|
68
|
+
|
|
69
|
+
# Store multi-hop reasoning or CoT reflection
|
|
70
|
+
client.add_memory(
|
|
71
|
+
actor="agent",
|
|
72
|
+
action="reflected",
|
|
73
|
+
target="Migration failed due to missing index on users.email",
|
|
74
|
+
record_type="Causal"
|
|
75
|
+
)
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
---
|
|
79
|
+
|
|
80
|
+
## 🧩 Framework Integrations
|
|
81
|
+
|
|
82
|
+
### LangChain (`ConversationBufferMemory` drop-in)
|
|
83
|
+
```python
|
|
84
|
+
from hipcortex.langchain_memory import HipCortexMemory
|
|
85
|
+
|
|
86
|
+
memory = HipCortexMemory(session_id="session-42", url="http://127.0.0.1:3030")
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
### LlamaIndex (`ChatStore`)
|
|
90
|
+
```python
|
|
91
|
+
from hipcortex.llamaindex_storage import HipCortexStorageContext
|
|
92
|
+
|
|
93
|
+
storage_context = HipCortexStorageContext.from_defaults(client=client)
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
### CrewAI (`Remember` & `Recall` Tools)
|
|
97
|
+
```python
|
|
98
|
+
from hipcortex.adapters.crewai import HipCortexRememberTool, HipCortexRecallTool
|
|
99
|
+
|
|
100
|
+
tools = [HipCortexRememberTool(client=client), HipCortexRecallTool(client=client)]
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
### AutoGen (`Memory` Hook)
|
|
104
|
+
```python
|
|
105
|
+
from hipcortex.adapters.autogen import HipCortexAutoGenMemory
|
|
106
|
+
|
|
107
|
+
mem = HipCortexAutoGenMemory(client=client, agent_id="researcher")
|
|
108
|
+
agent.register_hook("process_message_before_send", mem.on_message_sent)
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
---
|
|
112
|
+
|
|
113
|
+
## 📊 Server Statistics & GDPR Right-to-Forget
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
# Get Merkle hash chain status and tier counts
|
|
117
|
+
stats = client.stats()
|
|
118
|
+
print("Memory statistics:", stats)
|
|
119
|
+
|
|
120
|
+
# Erase all records for a specific actor (GDPR compliant)
|
|
121
|
+
client.forget("agent")
|
|
122
|
+
```
|
|
@@ -1,15 +1,17 @@
|
|
|
1
|
-
"""HipCortex Python SDK - AI memory engine client."""
|
|
2
|
-
|
|
3
|
-
from .client import HipCortexClient
|
|
4
|
-
from .async_client import AsyncHipCortexClient
|
|
5
|
-
from .langchain_memory import HipCortexMemory, AsyncHipCortexMemory
|
|
6
|
-
from .llamaindex_storage import HipCortexStorageContext
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
|
|
1
|
+
"""HipCortex Python SDK - AI memory engine client."""
|
|
2
|
+
|
|
3
|
+
from .client import HipCortexClient
|
|
4
|
+
from .async_client import AsyncHipCortexClient
|
|
5
|
+
from .langchain_memory import HipCortexMemory, AsyncHipCortexMemory
|
|
6
|
+
from .llamaindex_storage import HipCortexStorageContext
|
|
7
|
+
from .substrate import HipCortexSubstrate
|
|
8
|
+
|
|
9
|
+
__version__ = "1.3.0"
|
|
10
|
+
__all__ = [
|
|
11
|
+
"HipCortexClient",
|
|
12
|
+
"AsyncHipCortexClient",
|
|
13
|
+
"HipCortexMemory",
|
|
14
|
+
"AsyncHipCortexMemory",
|
|
15
|
+
"HipCortexStorageContext",
|
|
16
|
+
"HipCortexSubstrate",
|
|
17
|
+
]
|
|
@@ -173,3 +173,57 @@ class HipCortexAutoGenMemory(Memory): # type: ignore[misc]
|
|
|
173
173
|
|
|
174
174
|
def forget_all(self) -> Dict[str, Any]:
|
|
175
175
|
return self._client.forget(self._agent_id)
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
class HipCortexAutoGenObserver:
|
|
179
|
+
"""Passive AutoGen observer. Wire via agent hooks or v0.3 send/receive hooks."""
|
|
180
|
+
|
|
181
|
+
def __init__(self, client, actor: str = "autogen-agent"):
|
|
182
|
+
self._client = client
|
|
183
|
+
self._actor = actor
|
|
184
|
+
|
|
185
|
+
def _capture(self, action: str, target: str, record_type: str = "Temporal") -> None:
|
|
186
|
+
try:
|
|
187
|
+
self._client.add_memory(
|
|
188
|
+
actor=self._actor,
|
|
189
|
+
action=action,
|
|
190
|
+
target=target[:120],
|
|
191
|
+
record_type=record_type,
|
|
192
|
+
source="autogen-passive",
|
|
193
|
+
)
|
|
194
|
+
except Exception:
|
|
195
|
+
pass
|
|
196
|
+
|
|
197
|
+
def on_message_received(self, sender: str, content: str, role: str = "user") -> None:
|
|
198
|
+
self._capture("message_received", f"[{sender}/{role}] {str(content)[:100]}")
|
|
199
|
+
|
|
200
|
+
def on_message_sent(self, recipient: str, content: str) -> None:
|
|
201
|
+
self._capture("message_sent", f"[→{recipient}] {str(content)[:100]}")
|
|
202
|
+
|
|
203
|
+
def on_function_call(self, name: str, arguments: dict) -> None:
|
|
204
|
+
self._capture("function_call", f"{name}({str(arguments)[:80]})")
|
|
205
|
+
|
|
206
|
+
def on_function_result(self, name: str, result: str) -> None:
|
|
207
|
+
self._capture("function_result", f"{name} → {str(result)[:80]}")
|
|
208
|
+
|
|
209
|
+
def make_v03_send_hook(self):
|
|
210
|
+
"""Hook for AutoGen v0.3 send hook."""
|
|
211
|
+
def _hook(message: dict) -> None:
|
|
212
|
+
try:
|
|
213
|
+
content = message.get("content", "") or ""
|
|
214
|
+
role = message.get("role", "unknown")
|
|
215
|
+
self._capture("message_sent", f"[{role}] {str(content)[:100]}")
|
|
216
|
+
except Exception:
|
|
217
|
+
pass
|
|
218
|
+
return _hook
|
|
219
|
+
|
|
220
|
+
def make_v03_receive_hook(self):
|
|
221
|
+
"""Hook for AutoGen v0.3 receive hook."""
|
|
222
|
+
def _hook(message: dict, sender=None) -> None:
|
|
223
|
+
try:
|
|
224
|
+
content = message.get("content", "") or ""
|
|
225
|
+
sender_name = getattr(sender, "name", str(sender)) if sender else "unknown"
|
|
226
|
+
self._capture("message_received", f"[{sender_name}] {str(content)[:100]}")
|
|
227
|
+
except Exception:
|
|
228
|
+
pass
|
|
229
|
+
return _hook
|
|
@@ -171,3 +171,63 @@ def make_memory_tools(
|
|
|
171
171
|
HipCortexRecallTool(client=client, agent_id=agent_id),
|
|
172
172
|
HipCortexForgetTool(client=client, agent_id=agent_id),
|
|
173
173
|
]
|
|
174
|
+
|
|
175
|
+
|
|
176
|
+
class HipCortexCrewObserver:
|
|
177
|
+
"""Passive CrewAI observer. Wire via: Crew(step_callback=obs.step_callback, task_callback=obs.task_callback)."""
|
|
178
|
+
|
|
179
|
+
def __init__(self, client, actor: str = "crew-agent"):
|
|
180
|
+
self._client = client
|
|
181
|
+
self._actor = actor
|
|
182
|
+
self._injected: set = set()
|
|
183
|
+
|
|
184
|
+
def inject_context(self, crew) -> None:
|
|
185
|
+
"""Inject relevant memories into crew context before kickoff. Idempotent."""
|
|
186
|
+
crew_id = id(crew)
|
|
187
|
+
if crew_id in self._injected:
|
|
188
|
+
return
|
|
189
|
+
self._injected.add(crew_id)
|
|
190
|
+
try:
|
|
191
|
+
memories = self._client.query_memory(actor=self._actor, limit=5)
|
|
192
|
+
if memories and hasattr(crew, "context"):
|
|
193
|
+
snippets = [f"[{m.get('action', '')}] {m.get('target', '')}" for m in memories]
|
|
194
|
+
prefix = "Prior context:\n" + "\n".join(snippets)
|
|
195
|
+
if isinstance(crew.context, str):
|
|
196
|
+
crew.context = prefix + "\n\n" + crew.context
|
|
197
|
+
except Exception:
|
|
198
|
+
pass
|
|
199
|
+
|
|
200
|
+
@property
|
|
201
|
+
def step_callback(self):
|
|
202
|
+
"""Callable for Crew(step_callback=...). Signature: fn(AgentAction) -> None."""
|
|
203
|
+
def _on_step(action) -> None:
|
|
204
|
+
try:
|
|
205
|
+
tool = getattr(action, "tool", "unknown")
|
|
206
|
+
tool_input = str(getattr(action, "tool_input", ""))[:80]
|
|
207
|
+
self._client.add_memory(
|
|
208
|
+
actor=self._actor,
|
|
209
|
+
action="crew_step",
|
|
210
|
+
target=f"{tool}({tool_input})",
|
|
211
|
+
record_type="Temporal",
|
|
212
|
+
source="crewai-passive",
|
|
213
|
+
)
|
|
214
|
+
except Exception:
|
|
215
|
+
pass
|
|
216
|
+
return _on_step
|
|
217
|
+
|
|
218
|
+
@property
|
|
219
|
+
def task_callback(self):
|
|
220
|
+
"""Callable for Task(callback=...). Signature: fn(TaskOutput) -> None."""
|
|
221
|
+
def _on_task(output) -> None:
|
|
222
|
+
try:
|
|
223
|
+
raw = getattr(output, "raw_output", None) or str(output)
|
|
224
|
+
self._client.add_memory(
|
|
225
|
+
actor=self._actor,
|
|
226
|
+
action="task_complete",
|
|
227
|
+
target=str(raw)[:120],
|
|
228
|
+
record_type="Reflexion",
|
|
229
|
+
source="crewai-passive",
|
|
230
|
+
)
|
|
231
|
+
except Exception:
|
|
232
|
+
pass
|
|
233
|
+
return _on_task
|
|
@@ -1380,7 +1380,7 @@ def _fallback_channels() -> list[dict]:
|
|
|
1380
1380
|
{"id": "claude-code", "name": "Claude Code", "status": "native", "install": "hipcortex install"},
|
|
1381
1381
|
{"id": "cursor", "name": "Cursor", "status": "mcp", "install": "hipcortex install"},
|
|
1382
1382
|
{"id": "windsurf", "name": "Windsurf", "status": "mcp", "install": "hipcortex install"},
|
|
1383
|
-
{"id": "vscode-extension", "name": "VS Code VSIX", "status": "native", "install": "hipcortex-memory-0.5.
|
|
1383
|
+
{"id": "vscode-extension", "name": "VS Code VSIX", "status": "native", "install": "hipcortex-memory-0.5.8.vsix"},
|
|
1384
1384
|
{"id": "vscode-mcp", "name": "VS Code MCP", "status": "mcp", "install": "hipcortex install"},
|
|
1385
1385
|
{"id": "cline", "name": "Cline", "status": "mcp", "install": "hipcortex install"},
|
|
1386
1386
|
{"id": "roocode", "name": "RooCode", "status": "mcp", "install": "hipcortex install"},
|
|
@@ -10,6 +10,8 @@ import requests
|
|
|
10
10
|
|
|
11
11
|
|
|
12
12
|
class HipCortexClient:
|
|
13
|
+
VERSION = "0.8.0"
|
|
14
|
+
|
|
13
15
|
"""Synchronous HTTP client for the HipCortex memory server.
|
|
14
16
|
|
|
15
17
|
Args:
|
|
@@ -613,3 +615,158 @@ class HipCortexClient:
|
|
|
613
615
|
resp.raise_for_status()
|
|
614
616
|
return resp.json()
|
|
615
617
|
|
|
618
|
+
def get_state_diff(self, from_tx: int, to_tx: int) -> Dict[str, Any]:
|
|
619
|
+
"""POST /v1/state/diff — causal StateDiff over a tx-log range."""
|
|
620
|
+
resp = self._session.post(
|
|
621
|
+
f"{self.base_url}/v1/state/diff",
|
|
622
|
+
json={"from_tx": from_tx, "to_tx": to_tx},
|
|
623
|
+
timeout=self.timeout,
|
|
624
|
+
)
|
|
625
|
+
resp.raise_for_status()
|
|
626
|
+
return resp.json()
|
|
627
|
+
|
|
628
|
+
def consolidate_memory(self, min_group_size: int = 3) -> Dict[str, Any]:
|
|
629
|
+
"""POST /v1/memory/consolidate — trigger hierarchical memory consolidation."""
|
|
630
|
+
resp = self._session.post(
|
|
631
|
+
f"{self.base_url}/v1/memory/consolidate",
|
|
632
|
+
json={"min_group_size": min_group_size},
|
|
633
|
+
timeout=self.timeout,
|
|
634
|
+
)
|
|
635
|
+
resp.raise_for_status()
|
|
636
|
+
return resp.json()
|
|
637
|
+
|
|
638
|
+
def get_system_health(self) -> Dict[str, Any]:
|
|
639
|
+
"""GET /self/health — SelfModel health + CalibrationTracker metrics."""
|
|
640
|
+
resp = self._session.get(f"{self.base_url}/self/health", timeout=self.timeout)
|
|
641
|
+
resp.raise_for_status()
|
|
642
|
+
return resp.json()
|
|
643
|
+
|
|
644
|
+
def get_live_beliefs(
|
|
645
|
+
self,
|
|
646
|
+
actor: Optional[str] = None,
|
|
647
|
+
limit: int = 20,
|
|
648
|
+
min_conf: float = 0.0,
|
|
649
|
+
) -> Dict[str, Any]:
|
|
650
|
+
"""GET /memory/live_beliefs — filtered by actor and confidence threshold."""
|
|
651
|
+
params: Dict[str, Any] = {"limit": limit, "min_conf": min_conf}
|
|
652
|
+
if actor:
|
|
653
|
+
params["actor"] = actor
|
|
654
|
+
resp = self._session.get(
|
|
655
|
+
f"{self.base_url}/memory/live_beliefs", params=params, timeout=self.timeout
|
|
656
|
+
)
|
|
657
|
+
resp.raise_for_status()
|
|
658
|
+
return resp.json()
|
|
659
|
+
|
|
660
|
+
def simulate_rollout(
|
|
661
|
+
self,
|
|
662
|
+
initial_state: Any,
|
|
663
|
+
actions: List[str],
|
|
664
|
+
max_depth: int = 5,
|
|
665
|
+
) -> Dict[str, Any]:
|
|
666
|
+
"""POST /worldmodel/rollout — k-step (k≤5) Dirichlet-MAP world-model rollout."""
|
|
667
|
+
if not isinstance(initial_state, str):
|
|
668
|
+
initial_state = json.dumps(initial_state)
|
|
669
|
+
max_depth = min(max_depth, 5)
|
|
670
|
+
resp = self._session.post(
|
|
671
|
+
f"{self.base_url}/worldmodel/rollout",
|
|
672
|
+
json={"initial_state": initial_state, "actions": actions, "max_depth": max_depth},
|
|
673
|
+
timeout=self.timeout,
|
|
674
|
+
)
|
|
675
|
+
resp.raise_for_status()
|
|
676
|
+
return resp.json()
|
|
677
|
+
|
|
678
|
+
# ------------------------------------------------------------------
|
|
679
|
+
# Phase 5: Agent Surfaces (v0.8.0)
|
|
680
|
+
# ------------------------------------------------------------------
|
|
681
|
+
|
|
682
|
+
def _get(self, path: str, params: Optional[Dict[str, Any]] = None) -> Dict[str, Any]:
|
|
683
|
+
resp = self._session.get(f"{self.base_url}{path}", params=params, timeout=self.timeout)
|
|
684
|
+
resp.raise_for_status()
|
|
685
|
+
return resp.json()
|
|
686
|
+
|
|
687
|
+
def _post(self, path: str, body: Any = None) -> Dict[str, Any]:
|
|
688
|
+
resp = self._session.post(f"{self.base_url}{path}", json=body, timeout=self.timeout)
|
|
689
|
+
resp.raise_for_status()
|
|
690
|
+
return resp.json()
|
|
691
|
+
|
|
692
|
+
def _delete(self, path: str) -> Dict[str, Any]:
|
|
693
|
+
resp = self._session.delete(f"{self.base_url}{path}", timeout=self.timeout)
|
|
694
|
+
resp.raise_for_status()
|
|
695
|
+
return resp.json()
|
|
696
|
+
|
|
697
|
+
def transact(self, delta: Dict[str, Any], actor: str) -> Dict[str, Any]:
|
|
698
|
+
"""POST /v1/cognitive/transact — apply a CognitiveDelta."""
|
|
699
|
+
return self._post("/v1/cognitive/transact", {"delta": delta, "actor": actor})
|
|
700
|
+
|
|
701
|
+
def cognitive_diff(self, from_tx: int, to_tx: int) -> Dict[str, Any]:
|
|
702
|
+
"""GET /v1/cognitive/diff — causal StateDiff over a tx range."""
|
|
703
|
+
return self._get("/v1/cognitive/diff", params={"from_tx": from_tx, "to_tx": to_tx})
|
|
704
|
+
|
|
705
|
+
def self_health(self) -> Dict[str, Any]:
|
|
706
|
+
"""GET /v1/self/health — SelfModel health metrics."""
|
|
707
|
+
return self._get("/v1/self/health")
|
|
708
|
+
|
|
709
|
+
def cognitive_snapshot(self, actor: str = "") -> Dict[str, Any]:
|
|
710
|
+
"""GET /v1/cognitive/snapshot."""
|
|
711
|
+
return self._get("/v1/cognitive/snapshot", params={"actor": actor})
|
|
712
|
+
|
|
713
|
+
def fork_create(self) -> Dict[str, Any]:
|
|
714
|
+
"""POST /v1/fork — create a new SimulationFork (CoW snapshot)."""
|
|
715
|
+
return self._post("/v1/fork", {})
|
|
716
|
+
|
|
717
|
+
def fork_step(self, fork_id: str, action: str) -> Dict[str, Any]:
|
|
718
|
+
"""POST /v1/fork/{id}/step — advance fork by one action."""
|
|
719
|
+
return self._post(f"/v1/fork/{fork_id}/step", {"action": action})
|
|
720
|
+
|
|
721
|
+
def fork_snapshot(self, fork_id: str, actor: str = "") -> Dict[str, Any]:
|
|
722
|
+
"""GET /v1/fork/{id}/snapshot — read fork cognitive snapshot."""
|
|
723
|
+
return self._get(f"/v1/fork/{fork_id}/snapshot", params={"actor": actor})
|
|
724
|
+
|
|
725
|
+
def fork_delete(self, fork_id: str) -> Dict[str, Any]:
|
|
726
|
+
"""DELETE /v1/fork/{id} — discard a SimulationFork."""
|
|
727
|
+
return self._delete(f"/v1/fork/{fork_id}")
|
|
728
|
+
|
|
729
|
+
def fork_rollout(
|
|
730
|
+
self, fork_id: str, actions: List[str], sigma2_max: float = 0.25
|
|
731
|
+
) -> Dict[str, Any]:
|
|
732
|
+
"""POST /v1/fork/{id}/rollout — k-step hybrid rollout (k≤5)."""
|
|
733
|
+
return self._post(
|
|
734
|
+
f"/v1/fork/{fork_id}/rollout",
|
|
735
|
+
{"actions": actions, "sigma2_max": sigma2_max},
|
|
736
|
+
)
|
|
737
|
+
|
|
738
|
+
def consolidate(self, source_ids: List[str], summary: Dict[str, Any]) -> Dict[str, Any]:
|
|
739
|
+
"""Consolidate source records into a summary via cognitive transact."""
|
|
740
|
+
delta = {"type": "Consolidate", "source_ids": source_ids, "summary": summary}
|
|
741
|
+
return self.transact(delta, actor="sdk")
|
|
742
|
+
|
|
743
|
+
def forget_actor(self, actor_id: str) -> Dict[str, Any]:
|
|
744
|
+
"""GDPR hard-delete all records for actor_id via cognitive transact."""
|
|
745
|
+
return self.transact({"type": "ForgetActor", "actor": actor_id}, actor="sdk")
|
|
746
|
+
|
|
747
|
+
def archive_record(self, record_id: str) -> Dict[str, Any]:
|
|
748
|
+
"""Archive or delete a record via cognitive transact."""
|
|
749
|
+
return self.transact({"type": "ArchiveRecord", "id": record_id}, actor="sdk")
|
|
750
|
+
|
|
751
|
+
def workspace_open(self, workspace_id: str, mode: str = "Private") -> Dict[str, Any]:
|
|
752
|
+
"""Open a scoped workspace for isolated or shared multi-agent cognition."""
|
|
753
|
+
return self.transact({"type": "WorkspaceOpen", "id": workspace_id, "mode": mode}, actor="sdk")
|
|
754
|
+
|
|
755
|
+
def workspace_merge(self, from_id: str, into_id: str) -> Dict[str, Any]:
|
|
756
|
+
"""Merge a Shared workspace into another via OR-Set CRDT convergence."""
|
|
757
|
+
return self.transact({"type": "WorkspaceMerge", "from": from_id, "into": into_id}, actor="sdk")
|
|
758
|
+
|
|
759
|
+
def retract_belief(self, belief_id: str, reason: str = "retracted") -> Dict[str, Any]:
|
|
760
|
+
"""Retract a belief, triggering JTMS dependency propagation."""
|
|
761
|
+
return self.transact({"type": "RetractBelief", "id": belief_id, "reason": reason}, actor="sdk")
|
|
762
|
+
|
|
763
|
+
def trigger_consolidation(self, min_frequency: int = 3) -> Dict[str, Any]:
|
|
764
|
+
"""Trigger memory consolidation to compact episodic traces into skills/beliefs."""
|
|
765
|
+
return self.transact({"type": "AutoConsolidate", "min_frequency": min_frequency}, actor="sdk")
|
|
766
|
+
|
|
767
|
+
def compute_state_diff(self, from_tx: int, to_tx: int) -> Dict[str, Any]:
|
|
768
|
+
"""Return causal-attributed ΔS between two tx checkpoints."""
|
|
769
|
+
resp = self._session.post(f"{self.base_url}/v1/state/diff", json={"from_tx": from_tx, "to_tx": to_tx}, timeout=self.timeout)
|
|
770
|
+
resp.raise_for_status()
|
|
771
|
+
return resp.json()
|
|
772
|
+
|
|
@@ -6,6 +6,40 @@ HipCortex gives you persistent causal memory across sessions. Store decisions, r
|
|
|
6
6
|
|
|
7
7
|
You are a memory-centric agent. The HipCortex substrate (memories + hypotheses graph as persistent beliefs + world model predictions + self health + coherence) is your primary durable mind and reasoning engine.
|
|
8
8
|
|
|
9
|
+
## Lifecycle self-prompting (substrate-first at every stage)
|
|
10
|
+
|
|
11
|
+
For any complex task, follow this sequence. Each step has an exit condition — never loop indefinitely.
|
|
12
|
+
|
|
13
|
+
### 1. Setup (once, before loop)
|
|
14
|
+
```
|
|
15
|
+
recommend_tools(task) → install recommended MCP servers + skills
|
|
16
|
+
clarify_goal(task) → structured GoalPayload + suggested success_factors + clarifying questions
|
|
17
|
+
(if uncertainty_flags non-empty: ask user before proceeding)
|
|
18
|
+
plan_validation(success_factors) → test plan: how to verify each factor
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### 2. ReAct loop (per iteration — exits when should_exit ≠ continue)
|
|
22
|
+
```
|
|
23
|
+
OBSERVE: get_live_beliefs() → substrate state
|
|
24
|
+
REFLECT: POST /memory/reflect → substrate CoT (before acting on ambiguous state)
|
|
25
|
+
ACT: execute tool / write / call API
|
|
26
|
+
STORE: add_memory(actor, Temporal, observation)
|
|
27
|
+
→ auto-fires WMUpdater, BeliefInvalidator, EmergenceDetector
|
|
28
|
+
PROGRESS: check_progress(success_factors, observations, iteration, max_iterations)
|
|
29
|
+
→ if uncertainty_detected: POST /memory/reflect then POST /v1/loop/omega
|
|
30
|
+
EXIT: should_exit(iteration, max_iterations, progress_ratio, surprise_signal)
|
|
31
|
+
→ continue → next iteration
|
|
32
|
+
→ succeed → store Reflexion summary, exit loop
|
|
33
|
+
→ fail → store partial results, report pending_factors to user, exit
|
|
34
|
+
→ escalate → run omega loop, ask user for clarification or reduced scope, exit
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
### Exit rules (HARD — never bypass)
|
|
38
|
+
- `should_exit` MUST be called every iteration
|
|
39
|
+
- `max_iterations` cap is absolute — fail at the limit, never extend silently
|
|
40
|
+
- Zero progress after 25% of budget → fail and reframe (call clarify_goal again)
|
|
41
|
+
- High surprise (>0.8) + >50% budget + <50% progress → escalate, not continue
|
|
42
|
+
|
|
9
43
|
MUST: Before any question involving project state, architecture, decisions, bugs, or context, call search_memory or get_live_beliefs (or /memory/context) first. Use substrate for state/hyp/pred.
|
|
10
44
|
|
|
11
45
|
MUST: After any decision, architectural discussion, bug fix, or important finding, use /memory/ingest or add_memory (or reflect for CoT).
|