agentkeeper-ai 1.1.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.
- agentkeeper_ai-1.1.0/LICENSE +21 -0
- agentkeeper_ai-1.1.0/PKG-INFO +328 -0
- agentkeeper_ai-1.1.0/README.md +267 -0
- agentkeeper_ai-1.1.0/agentkeeper/__init__.py +1106 -0
- agentkeeper_ai-1.1.0/agentkeeper/adapters/__init__.py +20 -0
- agentkeeper_ai-1.1.0/agentkeeper/adapters/anthropic.py +99 -0
- agentkeeper_ai-1.1.0/agentkeeper/adapters/base.py +66 -0
- agentkeeper_ai-1.1.0/agentkeeper/adapters/gemini.py +26 -0
- agentkeeper_ai-1.1.0/agentkeeper/adapters/ollama.py +47 -0
- agentkeeper_ai-1.1.0/agentkeeper/adapters/openai.py +91 -0
- agentkeeper_ai-1.1.0/agentkeeper/async_agent.py +603 -0
- agentkeeper_ai-1.1.0/agentkeeper/benchmark/__init__.py +17 -0
- agentkeeper_ai-1.1.0/agentkeeper/benchmark/cross_model.py +158 -0
- agentkeeper_ai-1.1.0/agentkeeper/benchmark/dataset.py +60 -0
- agentkeeper_ai-1.1.0/agentkeeper/benchmark/real_run.py +143 -0
- agentkeeper_ai-1.1.0/agentkeeper/benchmark/run.py +167 -0
- agentkeeper_ai-1.1.0/agentkeeper/benchmark/verification.py +41 -0
- agentkeeper_ai-1.1.0/agentkeeper/compression/__init__.py +43 -0
- agentkeeper_ai-1.1.0/agentkeeper/compression/async_llm_synth.py +84 -0
- agentkeeper_ai-1.1.0/agentkeeper/compression/consolidation.py +163 -0
- agentkeeper_ai-1.1.0/agentkeeper/compression/contradiction.py +200 -0
- agentkeeper_ai-1.1.0/agentkeeper/compression/decay.py +109 -0
- agentkeeper_ai-1.1.0/agentkeeper/compression/llm_synth.py +72 -0
- agentkeeper_ai-1.1.0/agentkeeper/compression/pipeline.py +174 -0
- agentkeeper_ai-1.1.0/agentkeeper/cre/__init__.py +5 -0
- agentkeeper_ai-1.1.0/agentkeeper/cre/engine.py +320 -0
- agentkeeper_ai-1.1.0/agentkeeper/cso/__init__.py +27 -0
- agentkeeper_ai-1.1.0/agentkeeper/cso/fact_types.py +98 -0
- agentkeeper_ai-1.1.0/agentkeeper/cso/identity.py +83 -0
- agentkeeper_ai-1.1.0/agentkeeper/cso/inference.py +134 -0
- agentkeeper_ai-1.1.0/agentkeeper/cso/tiers.py +53 -0
- agentkeeper_ai-1.1.0/agentkeeper/cso/types.py +397 -0
- agentkeeper_ai-1.1.0/agentkeeper/errors.py +80 -0
- agentkeeper_ai-1.1.0/agentkeeper/graph/__init__.py +19 -0
- agentkeeper_ai-1.1.0/agentkeeper/graph/relation_graph.py +221 -0
- agentkeeper_ai-1.1.0/agentkeeper/graph/triple.py +168 -0
- agentkeeper_ai-1.1.0/agentkeeper/integrations/__init__.py +32 -0
- agentkeeper_ai-1.1.0/agentkeeper/integrations/crewai.py +103 -0
- agentkeeper_ai-1.1.0/agentkeeper/integrations/langchain.py +111 -0
- agentkeeper_ai-1.1.0/agentkeeper/logging.py +44 -0
- agentkeeper_ai-1.1.0/agentkeeper/mcp/__init__.py +65 -0
- agentkeeper_ai-1.1.0/agentkeeper/mcp/errors.py +14 -0
- agentkeeper_ai-1.1.0/agentkeeper/mcp/server.py +342 -0
- agentkeeper_ai-1.1.0/agentkeeper/py.typed +0 -0
- agentkeeper_ai-1.1.0/agentkeeper/retention/__init__.py +11 -0
- agentkeeper_ai-1.1.0/agentkeeper/retention/policy.py +79 -0
- agentkeeper_ai-1.1.0/agentkeeper/retention/ttl.py +152 -0
- agentkeeper_ai-1.1.0/agentkeeper/retry.py +124 -0
- agentkeeper_ai-1.1.0/agentkeeper/semantic/__init__.py +20 -0
- agentkeeper_ai-1.1.0/agentkeeper/semantic/base.py +42 -0
- agentkeeper_ai-1.1.0/agentkeeper/semantic/factory.py +84 -0
- agentkeeper_ai-1.1.0/agentkeeper/semantic/index.py +101 -0
- agentkeeper_ai-1.1.0/agentkeeper/semantic/mock.py +61 -0
- agentkeeper_ai-1.1.0/agentkeeper/semantic/openai_provider.py +48 -0
- agentkeeper_ai-1.1.0/agentkeeper/semantic/recaller.py +136 -0
- agentkeeper_ai-1.1.0/agentkeeper/semantic/sentence_transformers_provider.py +56 -0
- agentkeeper_ai-1.1.0/agentkeeper/semantic/sqlite_vec_index.py +219 -0
- agentkeeper_ai-1.1.0/agentkeeper/storage/__init__.py +26 -0
- agentkeeper_ai-1.1.0/agentkeeper/storage/base.py +52 -0
- agentkeeper_ai-1.1.0/agentkeeper/storage/encrypted_sqlite.py +129 -0
- agentkeeper_ai-1.1.0/agentkeeper/storage/factory.py +65 -0
- agentkeeper_ai-1.1.0/agentkeeper/storage/postgres.py +64 -0
- agentkeeper_ai-1.1.0/agentkeeper/storage/sqlite_store.py +123 -0
- agentkeeper_ai-1.1.0/agentkeeper/translation/__init__.py +25 -0
- agentkeeper_ai-1.1.0/agentkeeper/translation/profiles.py +122 -0
- agentkeeper_ai-1.1.0/agentkeeper/translation/renderers.py +251 -0
- agentkeeper_ai-1.1.0/agentkeeper_ai.egg-info/PKG-INFO +328 -0
- agentkeeper_ai-1.1.0/agentkeeper_ai.egg-info/SOURCES.txt +110 -0
- agentkeeper_ai-1.1.0/agentkeeper_ai.egg-info/dependency_links.txt +1 -0
- agentkeeper_ai-1.1.0/agentkeeper_ai.egg-info/entry_points.txt +2 -0
- agentkeeper_ai-1.1.0/agentkeeper_ai.egg-info/requires.txt +44 -0
- agentkeeper_ai-1.1.0/agentkeeper_ai.egg-info/top_level.txt +1 -0
- agentkeeper_ai-1.1.0/pyproject.toml +120 -0
- agentkeeper_ai-1.1.0/setup.cfg +4 -0
- agentkeeper_ai-1.1.0/tests/test_adapters.py +30 -0
- agentkeeper_ai-1.1.0/tests/test_agent_api.py +172 -0
- agentkeeper_ai-1.1.0/tests/test_agent_compress.py +107 -0
- agentkeeper_ai-1.1.0/tests/test_agent_graph.py +196 -0
- agentkeeper_ai-1.1.0/tests/test_agent_recall.py +99 -0
- agentkeeper_ai-1.1.0/tests/test_async_agent.py +152 -0
- agentkeeper_ai-1.1.0/tests/test_async_llm_synth.py +99 -0
- agentkeeper_ai-1.1.0/tests/test_benchmark.py +72 -0
- agentkeeper_ai-1.1.0/tests/test_consolidation.py +74 -0
- agentkeeper_ai-1.1.0/tests/test_contradiction.py +99 -0
- agentkeeper_ai-1.1.0/tests/test_cre.py +175 -0
- agentkeeper_ai-1.1.0/tests/test_cross_model.py +144 -0
- agentkeeper_ai-1.1.0/tests/test_cso.py +88 -0
- agentkeeper_ai-1.1.0/tests/test_decay.py +85 -0
- agentkeeper_ai-1.1.0/tests/test_decay_per_type.py +57 -0
- agentkeeper_ai-1.1.0/tests/test_embedding_mock.py +59 -0
- agentkeeper_ai-1.1.0/tests/test_errors.py +58 -0
- agentkeeper_ai-1.1.0/tests/test_fact_types.py +56 -0
- agentkeeper_ai-1.1.0/tests/test_graph_triple.py +215 -0
- agentkeeper_ai-1.1.0/tests/test_helpers_ak2.py +147 -0
- agentkeeper_ai-1.1.0/tests/test_helpers_ak9.py +198 -0
- agentkeeper_ai-1.1.0/tests/test_identity.py +60 -0
- agentkeeper_ai-1.1.0/tests/test_identity_hardening.py +239 -0
- agentkeeper_ai-1.1.0/tests/test_integrations.py +100 -0
- agentkeeper_ai-1.1.0/tests/test_mcp_server.py +267 -0
- agentkeeper_ai-1.1.0/tests/test_migration.py +62 -0
- agentkeeper_ai-1.1.0/tests/test_pipeline.py +59 -0
- agentkeeper_ai-1.1.0/tests/test_policy.py +63 -0
- agentkeeper_ai-1.1.0/tests/test_profiles.py +139 -0
- agentkeeper_ai-1.1.0/tests/test_recaller.py +86 -0
- agentkeeper_ai-1.1.0/tests/test_retention.py +244 -0
- agentkeeper_ai-1.1.0/tests/test_retry.py +112 -0
- agentkeeper_ai-1.1.0/tests/test_sqlite_vec.py +206 -0
- agentkeeper_ai-1.1.0/tests/test_storage.py +93 -0
- agentkeeper_ai-1.1.0/tests/test_storage_pluggable.py +201 -0
- agentkeeper_ai-1.1.0/tests/test_tiers.py +101 -0
- agentkeeper_ai-1.1.0/tests/test_ttl.py +125 -0
- agentkeeper_ai-1.1.0/tests/test_vector_index.py +71 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Tom — ThinkLanceAI
|
|
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.
|
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: agentkeeper-ai
|
|
3
|
+
Version: 1.1.0
|
|
4
|
+
Summary: Cognitive continuity infrastructure for long-lived AI agents — cross-model state reconstruction, semantic recall, cognitive compression
|
|
5
|
+
Author-email: Tom <hello@thinklanceai.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/Thinklanceai/agentkeeper
|
|
8
|
+
Project-URL: Repository, https://github.com/Thinklanceai/agentkeeper
|
|
9
|
+
Project-URL: Issues, https://github.com/Thinklanceai/agentkeeper/issues
|
|
10
|
+
Keywords: ai,agents,llm,memory,cognitive,continuity,openai,anthropic,claude,gemini,ollama
|
|
11
|
+
Classifier: Development Status :: 5 - Production/Stable
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Operating System :: OS Independent
|
|
15
|
+
Classifier: Programming Language :: Python :: 3
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
20
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
21
|
+
Classifier: Typing :: Typed
|
|
22
|
+
Classifier: Framework :: AsyncIO
|
|
23
|
+
Requires-Python: >=3.10
|
|
24
|
+
Description-Content-Type: text/markdown
|
|
25
|
+
License-File: LICENSE
|
|
26
|
+
Provides-Extra: openai
|
|
27
|
+
Requires-Dist: openai>=1.30.0; extra == "openai"
|
|
28
|
+
Provides-Extra: anthropic
|
|
29
|
+
Requires-Dist: anthropic>=0.30.0; extra == "anthropic"
|
|
30
|
+
Provides-Extra: gemini
|
|
31
|
+
Requires-Dist: google-generativeai>=0.8.0; extra == "gemini"
|
|
32
|
+
Provides-Extra: dotenv
|
|
33
|
+
Requires-Dist: python-dotenv>=1.0.0; extra == "dotenv"
|
|
34
|
+
Provides-Extra: semantic
|
|
35
|
+
Requires-Dist: sentence-transformers>=3.0.0; extra == "semantic"
|
|
36
|
+
Provides-Extra: vec
|
|
37
|
+
Requires-Dist: sqlite-vec>=0.1.6; extra == "vec"
|
|
38
|
+
Provides-Extra: encrypted
|
|
39
|
+
Requires-Dist: cryptography>=42.0.0; extra == "encrypted"
|
|
40
|
+
Provides-Extra: mcp
|
|
41
|
+
Requires-Dist: fastmcp>=3.0.0; extra == "mcp"
|
|
42
|
+
Provides-Extra: all
|
|
43
|
+
Requires-Dist: openai>=1.30.0; extra == "all"
|
|
44
|
+
Requires-Dist: anthropic>=0.30.0; extra == "all"
|
|
45
|
+
Requires-Dist: google-generativeai>=0.8.0; extra == "all"
|
|
46
|
+
Requires-Dist: python-dotenv>=1.0.0; extra == "all"
|
|
47
|
+
Requires-Dist: sentence-transformers>=3.0.0; extra == "all"
|
|
48
|
+
Requires-Dist: sqlite-vec>=0.1.6; extra == "all"
|
|
49
|
+
Requires-Dist: cryptography>=42.0.0; extra == "all"
|
|
50
|
+
Requires-Dist: fastmcp>=3.0.0; extra == "all"
|
|
51
|
+
Provides-Extra: dev
|
|
52
|
+
Requires-Dist: pytest>=8.0; extra == "dev"
|
|
53
|
+
Requires-Dist: pytest-asyncio>=0.23.0; extra == "dev"
|
|
54
|
+
Requires-Dist: pytest-cov>=5.0; extra == "dev"
|
|
55
|
+
Requires-Dist: ruff>=0.6.0; extra == "dev"
|
|
56
|
+
Requires-Dist: mypy>=1.10; extra == "dev"
|
|
57
|
+
Requires-Dist: sqlite-vec>=0.1.6; extra == "dev"
|
|
58
|
+
Requires-Dist: cryptography>=42.0.0; extra == "dev"
|
|
59
|
+
Requires-Dist: fastmcp>=3.0.0; extra == "dev"
|
|
60
|
+
Dynamic: license-file
|
|
61
|
+
|
|
62
|
+
# AgentKeeper
|
|
63
|
+
|
|
64
|
+
**Cognitive continuity infrastructure for long-lived AI agents.**
|
|
65
|
+
|
|
66
|
+
AgentKeeper reconstructs persistent cognitive state across model switches, crashes, restarts, and constrained contexts.
|
|
67
|
+
Built for agents that must survive longer than a single context window.
|
|
68
|
+
|
|
69
|
+
[](https://pypi.org/project/agentkeeper/)
|
|
70
|
+
[](https://pypi.org/project/agentkeeper/)
|
|
71
|
+
[](https://opensource.org/licenses/MIT)
|
|
72
|
+
[](https://github.com/Thinklanceai/agentkeeper/actions/workflows/ci.yml)
|
|
73
|
+
[](https://thinklanceai.com)
|
|
74
|
+
|
|
75
|
+
---
|
|
76
|
+
|
|
77
|
+
## Why AgentKeeper exists
|
|
78
|
+
|
|
79
|
+
Agents don't fail because they forget facts.
|
|
80
|
+
They fail because they lose **cognitive continuity** — their state, priorities, identity, and decision context drift the moment the underlying model changes, the context window fills, or the process restarts.
|
|
81
|
+
|
|
82
|
+
AgentKeeper treats this as a systems problem, not a memory problem.
|
|
83
|
+
|
|
84
|
+
It provides:
|
|
85
|
+
|
|
86
|
+
- A **Cognitive Reconstruction Engine** that rebuilds an agent's state for the target model, every call.
|
|
87
|
+
- A **memory hierarchy** (working / episodic / semantic / archival) with importance-aware retention.
|
|
88
|
+
- **Semantic recall** based on embeddings — meaning, not keywords.
|
|
89
|
+
- **Cognitive compression** — decay, consolidation, contradiction arbitration.
|
|
90
|
+
- **Identity persistence** — principles and hard constraints that survive every form of compression.
|
|
91
|
+
- **Cross-model translation** — XML for Claude, sections for GPT-4, narrative for Gemini, minimal for local models.
|
|
92
|
+
|
|
93
|
+
Continuity, not just memory.
|
|
94
|
+
|
|
95
|
+
## Install
|
|
96
|
+
|
|
97
|
+
```bash
|
|
98
|
+
pip install agentkeeper
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Optional extras (only install what you need):
|
|
102
|
+
|
|
103
|
+
```bash
|
|
104
|
+
pip install 'agentkeeper[anthropic]' # Claude
|
|
105
|
+
pip install 'agentkeeper[openai]' # GPT models + OpenAI embeddings
|
|
106
|
+
pip install 'agentkeeper[gemini]' # Google Gemini
|
|
107
|
+
pip install 'agentkeeper[semantic]' # Local embeddings (sentence-transformers)
|
|
108
|
+
pip install 'agentkeeper[all]' # everything
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
No external infrastructure required. Storage defaults to local SQLite. Vendor-agnostic by design.
|
|
112
|
+
|
|
113
|
+
## 60-second tour
|
|
114
|
+
|
|
115
|
+
```python
|
|
116
|
+
import agentkeeper
|
|
117
|
+
|
|
118
|
+
# 1. Create an agent and define its persistent identity
|
|
119
|
+
agent = agentkeeper.create(agent_id="aria", provider="anthropic")
|
|
120
|
+
agent.set_identity(
|
|
121
|
+
name="Aria",
|
|
122
|
+
role="EU insurance broker copilot",
|
|
123
|
+
principles=["never share PII without explicit consent"],
|
|
124
|
+
constraints=["EU data residency only"],
|
|
125
|
+
)
|
|
126
|
+
|
|
127
|
+
# 2. Teach it about the world
|
|
128
|
+
agent.principle("always confirm budget changes in writing")
|
|
129
|
+
agent.fact("client: Acme Corporation", importance=0.95)
|
|
130
|
+
agent.event("contract signed", when="2026-05-15")
|
|
131
|
+
agent.remember("favourite colour: blue") # tier inferred automatically
|
|
132
|
+
|
|
133
|
+
# 3. Ask — context is reconstructed for the target model
|
|
134
|
+
response = agent.ask("What do we know about the Acme deal?")
|
|
135
|
+
|
|
136
|
+
# 4. Switch providers — memory and identity survive
|
|
137
|
+
agent.switch_provider("openai").save()
|
|
138
|
+
response = agent.ask("Same question, different model.")
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
## Architecture
|
|
142
|
+
|
|
143
|
+
```
|
|
144
|
+
┌──────────────────────────────────────────────────────────────┐
|
|
145
|
+
│ AgentKeeper Public API │
|
|
146
|
+
│ agent.remember() · agent.recall() · agent.ask() │
|
|
147
|
+
│ agent.compress() · agent.set_identity() · agent.save() │
|
|
148
|
+
└────────────────────────────┬──────────────────────────────────┘
|
|
149
|
+
│
|
|
150
|
+
┌────────────────────────────▼──────────────────────────────────┐
|
|
151
|
+
│ Cognitive Reconstruction Engine (CRE) │
|
|
152
|
+
│ Identity injection · importance ranking · semantic boost │
|
|
153
|
+
│ Token budget · profile-driven rendering │
|
|
154
|
+
└─┬────────────┬────────────┬────────────┬─────────────────────┘
|
|
155
|
+
│ │ │ │
|
|
156
|
+
┌─────▼─────┐ ┌───▼────────┐ ┌─▼─────────┐ ┌▼──────────────┐
|
|
157
|
+
│ Memory │ │ Semantic │ │ Cognitive │ │ Cross-Model │
|
|
158
|
+
│ Hierarchy │ │ Recall │ │ Compress │ │ Translation │
|
|
159
|
+
│ │ │ │ │ │ │ │
|
|
160
|
+
│ working │ │ embeddings │ │ decay │ │ XML / sections │
|
|
161
|
+
│ episodic │ │ vector │ │ consol. │ │ narrative │
|
|
162
|
+
│ semantic │ │ index │ │ contradic │ │ minimal │
|
|
163
|
+
│ archival │ │ │ │ │ │ │
|
|
164
|
+
└───────────┘ └────────────┘ └───────────┘ └────────────────┘
|
|
165
|
+
│
|
|
166
|
+
┌─────────────▼─────────────┐
|
|
167
|
+
│ Storage (SQLite-first) │
|
|
168
|
+
│ Vendor-agnostic │
|
|
169
|
+
└───────────────────────────┘
|
|
170
|
+
```
|
|
171
|
+
|
|
172
|
+
Every layer is **interchangeable** and **opt-in**. The base CRE works with no embeddings, no compression, no profile customisation. Layers stack as you need them.
|
|
173
|
+
|
|
174
|
+
## Cognitive continuity in five primitives
|
|
175
|
+
|
|
176
|
+
### 1. Identity that never erodes
|
|
177
|
+
|
|
178
|
+
```python
|
|
179
|
+
agent.set_identity(
|
|
180
|
+
name="Aria",
|
|
181
|
+
role="EU broker copilot",
|
|
182
|
+
principles=["never share PII"],
|
|
183
|
+
constraints=["EU data residency only"],
|
|
184
|
+
)
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
Identity is injected into every reconstructed context, regardless of token budget. It survives compression, model switches, and restarts. Principles are **protected** — never decayed, never consolidated, never flagged.
|
|
188
|
+
|
|
189
|
+
### 2. Memory organised by tier
|
|
190
|
+
|
|
191
|
+
```python
|
|
192
|
+
agent.fact("budget: 50k EUR") # semantic (stable)
|
|
193
|
+
agent.event("contract signed", when="2026-05-15") # episodic (time-anchored)
|
|
194
|
+
agent.principle("always confirm changes") # protected, identity-level
|
|
195
|
+
agent.remember("favourite colour: blue") # tier inferred automatically
|
|
196
|
+
```
|
|
197
|
+
|
|
198
|
+
Tiers shape narration in reconstructed prompts and drive retention policy under compression.
|
|
199
|
+
|
|
200
|
+
### 3. Semantic recall
|
|
201
|
+
|
|
202
|
+
```python
|
|
203
|
+
results = agent.recall("money allocated to the project", top_k=5)
|
|
204
|
+
for fact, score in results:
|
|
205
|
+
print(f"{score:.2f} {fact.content}")
|
|
206
|
+
```
|
|
207
|
+
|
|
208
|
+
Pluggable embedding providers: local `sentence-transformers` (default, free, no lock-in), OpenAI, or your own. Recall biases context reconstruction toward facts that actually matter for the current question.
|
|
209
|
+
|
|
210
|
+
### 4. Cognitive compression
|
|
211
|
+
|
|
212
|
+
```python
|
|
213
|
+
report = agent.compress()
|
|
214
|
+
# CompressionReport(
|
|
215
|
+
# decayed_facts=12,
|
|
216
|
+
# consolidation={'clusters_found': 3, 'facts_removed': 7, ...},
|
|
217
|
+
# contradictions={'pairs_found': 2, 'resolutions': 2},
|
|
218
|
+
# facts_before=120, facts_after=102,
|
|
219
|
+
# )
|
|
220
|
+
```
|
|
221
|
+
|
|
222
|
+
Three independent passes:
|
|
223
|
+
|
|
224
|
+
- **Decay** — exponential half-life on unused non-critical facts. Critical and protected facts are immortal.
|
|
225
|
+
- **Consolidation** — embedding-based clustering merges near-duplicates. Optional LLM-backed synthesiser.
|
|
226
|
+
- **Contradiction arbitration** — key-value divergence and polarity-opposition detection. Deterministic winner (critical > importance > recency). Loser is flagged, not deleted.
|
|
227
|
+
|
|
228
|
+
### 5. Cross-model translation
|
|
229
|
+
|
|
230
|
+
The same cognitive state, four formats:
|
|
231
|
+
|
|
232
|
+
| Provider | Format | Why |
|
|
233
|
+
|------------|------------|-----------------------------------------------|
|
|
234
|
+
| Anthropic | XML | Claude excels with structured `<agent_identity>` and `<memory>` blocks |
|
|
235
|
+
| OpenAI | Sections | GPT family responds well to labelled sections (`AGENT IDENTITY`, `MEMORY`, `CURRENT TASK`) |
|
|
236
|
+
| Gemini | Narrative | Long-context model — prefers prose framing |
|
|
237
|
+
| Ollama | Minimal | Small/local models — aggressive compression, terse tokens |
|
|
238
|
+
|
|
239
|
+
Custom providers? Register your own:
|
|
240
|
+
|
|
241
|
+
```python
|
|
242
|
+
from agentkeeper import CognitiveProfile, PromptFormat, register_profile
|
|
243
|
+
|
|
244
|
+
register_profile(CognitiveProfile(
|
|
245
|
+
provider="my-llm",
|
|
246
|
+
format=PromptFormat.SECTIONS,
|
|
247
|
+
effective_context_tokens=10_000,
|
|
248
|
+
))
|
|
249
|
+
```
|
|
250
|
+
|
|
251
|
+
## Async API
|
|
252
|
+
|
|
253
|
+
```python
|
|
254
|
+
import asyncio
|
|
255
|
+
import agentkeeper
|
|
256
|
+
|
|
257
|
+
async def main() -> None:
|
|
258
|
+
agent = agentkeeper.create_async(agent_id="aria", provider="anthropic")
|
|
259
|
+
agent.set_identity(name="Aria", role="copilot")
|
|
260
|
+
agent.fact("budget: 50k", importance=0.95)
|
|
261
|
+
|
|
262
|
+
# Parallel asks across providers
|
|
263
|
+
answers = await asyncio.gather(
|
|
264
|
+
agent.ask("status?", provider="anthropic"),
|
|
265
|
+
agent.ask("status?", provider="openai"),
|
|
266
|
+
)
|
|
267
|
+
|
|
268
|
+
asyncio.run(main())
|
|
269
|
+
```
|
|
270
|
+
|
|
271
|
+
Sync and async agents share storage — you can save with one and load with the other.
|
|
272
|
+
|
|
273
|
+
## Production-grade
|
|
274
|
+
|
|
275
|
+
- **Type-safe**: `py.typed` marker shipped, mypy-strict friendly.
|
|
276
|
+
- **Typed exceptions**: `AgentKeeperError` root, with subclasses for every failure mode (provider down, agent missing, retriable network errors).
|
|
277
|
+
- **Structured logging**: namespaced under `agentkeeper.*`, opt-in.
|
|
278
|
+
- **Retries**: built-in exponential backoff for transient provider errors via `with_retry` / `with_async_retry`.
|
|
279
|
+
- **Tested**: 267 tests, CI on Python 3.10 / 3.11 / 3.12.
|
|
280
|
+
|
|
281
|
+
## Configuration
|
|
282
|
+
|
|
283
|
+
Environment variables (all optional):
|
|
284
|
+
|
|
285
|
+
| Variable | Default | Purpose |
|
|
286
|
+
|-----------------------------------|----------------------------------|---------|
|
|
287
|
+
| `OPENAI_API_KEY` | — | Required for OpenAI provider |
|
|
288
|
+
| `ANTHROPIC_API_KEY` | — | Required for Anthropic provider |
|
|
289
|
+
| `GEMINI_API_KEY` | — | Required for Gemini provider |
|
|
290
|
+
| `OPENAI_MODEL` | `gpt-4-turbo` | OpenAI model name |
|
|
291
|
+
| `ANTHROPIC_MODEL` | `claude-sonnet-4-5-20250929` | Anthropic model name |
|
|
292
|
+
| `OLLAMA_HOST` | `http://localhost:11434` | Ollama server URL |
|
|
293
|
+
| `AGENTKEEPER_DB` | `agentkeeper.db` | SQLite path |
|
|
294
|
+
| `AGENTKEEPER_EMBEDDING_PROVIDER` | auto (sentence-transformers > openai > mock) | Override embedding backend |
|
|
295
|
+
|
|
296
|
+
## Roadmap (v1.x)
|
|
297
|
+
|
|
298
|
+
- **v1.1** — Persistent vector index (`sqlite-vec`) so the recaller survives restarts without rebuild.
|
|
299
|
+
- **v1.2** — Async LLM-backed synthesiser in compression.
|
|
300
|
+
- **v1.3** — Pluggable storage backends (Postgres, encrypted).
|
|
301
|
+
- **v1.4** — `AgentKeeper Cloud` (managed sync). *Stays optional; OSS remains feature-complete.*
|
|
302
|
+
|
|
303
|
+
## Featured on
|
|
304
|
+
|
|
305
|
+
AgentKeeper was vouched for in March 2026 by:
|
|
306
|
+
|
|
307
|
+
- Shruti Codes ✓
|
|
308
|
+
- Chidanand Tripathi ✓ ([80K-view thread](#))
|
|
309
|
+
- Kayvon Jafarzadeh ✓
|
|
310
|
+
- Leonard Rodman ✓
|
|
311
|
+
- Martin Szerment ✓
|
|
312
|
+
- Bespoke AI Solutions Inc ✓
|
|
313
|
+
- @grok (xAI)
|
|
314
|
+
|
|
315
|
+
If you've shipped agents that needed to survive across model changes, you understand why this matters. Thank you to everyone who saw the project early.
|
|
316
|
+
|
|
317
|
+
## Contributing
|
|
318
|
+
|
|
319
|
+
Issues, ideas, and PRs welcome. See [CONTRIBUTING.md](./CONTRIBUTING.md).
|
|
320
|
+
|
|
321
|
+
## License
|
|
322
|
+
|
|
323
|
+
MIT. See [LICENSE](./LICENSE).
|
|
324
|
+
|
|
325
|
+
## Built by
|
|
326
|
+
|
|
327
|
+
[**ThinkLanceAI**](https://thinklanceai.com) — cognitive infrastructure for AI systems.
|
|
328
|
+
Need this in production with custom integrations? `hello@thinklanceai.com`.
|
|
@@ -0,0 +1,267 @@
|
|
|
1
|
+
# AgentKeeper
|
|
2
|
+
|
|
3
|
+
**Cognitive continuity infrastructure for long-lived AI agents.**
|
|
4
|
+
|
|
5
|
+
AgentKeeper reconstructs persistent cognitive state across model switches, crashes, restarts, and constrained contexts.
|
|
6
|
+
Built for agents that must survive longer than a single context window.
|
|
7
|
+
|
|
8
|
+
[](https://pypi.org/project/agentkeeper/)
|
|
9
|
+
[](https://pypi.org/project/agentkeeper/)
|
|
10
|
+
[](https://opensource.org/licenses/MIT)
|
|
11
|
+
[](https://github.com/Thinklanceai/agentkeeper/actions/workflows/ci.yml)
|
|
12
|
+
[](https://thinklanceai.com)
|
|
13
|
+
|
|
14
|
+
---
|
|
15
|
+
|
|
16
|
+
## Why AgentKeeper exists
|
|
17
|
+
|
|
18
|
+
Agents don't fail because they forget facts.
|
|
19
|
+
They fail because they lose **cognitive continuity** — their state, priorities, identity, and decision context drift the moment the underlying model changes, the context window fills, or the process restarts.
|
|
20
|
+
|
|
21
|
+
AgentKeeper treats this as a systems problem, not a memory problem.
|
|
22
|
+
|
|
23
|
+
It provides:
|
|
24
|
+
|
|
25
|
+
- A **Cognitive Reconstruction Engine** that rebuilds an agent's state for the target model, every call.
|
|
26
|
+
- A **memory hierarchy** (working / episodic / semantic / archival) with importance-aware retention.
|
|
27
|
+
- **Semantic recall** based on embeddings — meaning, not keywords.
|
|
28
|
+
- **Cognitive compression** — decay, consolidation, contradiction arbitration.
|
|
29
|
+
- **Identity persistence** — principles and hard constraints that survive every form of compression.
|
|
30
|
+
- **Cross-model translation** — XML for Claude, sections for GPT-4, narrative for Gemini, minimal for local models.
|
|
31
|
+
|
|
32
|
+
Continuity, not just memory.
|
|
33
|
+
|
|
34
|
+
## Install
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install agentkeeper
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Optional extras (only install what you need):
|
|
41
|
+
|
|
42
|
+
```bash
|
|
43
|
+
pip install 'agentkeeper[anthropic]' # Claude
|
|
44
|
+
pip install 'agentkeeper[openai]' # GPT models + OpenAI embeddings
|
|
45
|
+
pip install 'agentkeeper[gemini]' # Google Gemini
|
|
46
|
+
pip install 'agentkeeper[semantic]' # Local embeddings (sentence-transformers)
|
|
47
|
+
pip install 'agentkeeper[all]' # everything
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
No external infrastructure required. Storage defaults to local SQLite. Vendor-agnostic by design.
|
|
51
|
+
|
|
52
|
+
## 60-second tour
|
|
53
|
+
|
|
54
|
+
```python
|
|
55
|
+
import agentkeeper
|
|
56
|
+
|
|
57
|
+
# 1. Create an agent and define its persistent identity
|
|
58
|
+
agent = agentkeeper.create(agent_id="aria", provider="anthropic")
|
|
59
|
+
agent.set_identity(
|
|
60
|
+
name="Aria",
|
|
61
|
+
role="EU insurance broker copilot",
|
|
62
|
+
principles=["never share PII without explicit consent"],
|
|
63
|
+
constraints=["EU data residency only"],
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
# 2. Teach it about the world
|
|
67
|
+
agent.principle("always confirm budget changes in writing")
|
|
68
|
+
agent.fact("client: Acme Corporation", importance=0.95)
|
|
69
|
+
agent.event("contract signed", when="2026-05-15")
|
|
70
|
+
agent.remember("favourite colour: blue") # tier inferred automatically
|
|
71
|
+
|
|
72
|
+
# 3. Ask — context is reconstructed for the target model
|
|
73
|
+
response = agent.ask("What do we know about the Acme deal?")
|
|
74
|
+
|
|
75
|
+
# 4. Switch providers — memory and identity survive
|
|
76
|
+
agent.switch_provider("openai").save()
|
|
77
|
+
response = agent.ask("Same question, different model.")
|
|
78
|
+
```
|
|
79
|
+
|
|
80
|
+
## Architecture
|
|
81
|
+
|
|
82
|
+
```
|
|
83
|
+
┌──────────────────────────────────────────────────────────────┐
|
|
84
|
+
│ AgentKeeper Public API │
|
|
85
|
+
│ agent.remember() · agent.recall() · agent.ask() │
|
|
86
|
+
│ agent.compress() · agent.set_identity() · agent.save() │
|
|
87
|
+
└────────────────────────────┬──────────────────────────────────┘
|
|
88
|
+
│
|
|
89
|
+
┌────────────────────────────▼──────────────────────────────────┐
|
|
90
|
+
│ Cognitive Reconstruction Engine (CRE) │
|
|
91
|
+
│ Identity injection · importance ranking · semantic boost │
|
|
92
|
+
│ Token budget · profile-driven rendering │
|
|
93
|
+
└─┬────────────┬────────────┬────────────┬─────────────────────┘
|
|
94
|
+
│ │ │ │
|
|
95
|
+
┌─────▼─────┐ ┌───▼────────┐ ┌─▼─────────┐ ┌▼──────────────┐
|
|
96
|
+
│ Memory │ │ Semantic │ │ Cognitive │ │ Cross-Model │
|
|
97
|
+
│ Hierarchy │ │ Recall │ │ Compress │ │ Translation │
|
|
98
|
+
│ │ │ │ │ │ │ │
|
|
99
|
+
│ working │ │ embeddings │ │ decay │ │ XML / sections │
|
|
100
|
+
│ episodic │ │ vector │ │ consol. │ │ narrative │
|
|
101
|
+
│ semantic │ │ index │ │ contradic │ │ minimal │
|
|
102
|
+
│ archival │ │ │ │ │ │ │
|
|
103
|
+
└───────────┘ └────────────┘ └───────────┘ └────────────────┘
|
|
104
|
+
│
|
|
105
|
+
┌─────────────▼─────────────┐
|
|
106
|
+
│ Storage (SQLite-first) │
|
|
107
|
+
│ Vendor-agnostic │
|
|
108
|
+
└───────────────────────────┘
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
Every layer is **interchangeable** and **opt-in**. The base CRE works with no embeddings, no compression, no profile customisation. Layers stack as you need them.
|
|
112
|
+
|
|
113
|
+
## Cognitive continuity in five primitives
|
|
114
|
+
|
|
115
|
+
### 1. Identity that never erodes
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
agent.set_identity(
|
|
119
|
+
name="Aria",
|
|
120
|
+
role="EU broker copilot",
|
|
121
|
+
principles=["never share PII"],
|
|
122
|
+
constraints=["EU data residency only"],
|
|
123
|
+
)
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
Identity is injected into every reconstructed context, regardless of token budget. It survives compression, model switches, and restarts. Principles are **protected** — never decayed, never consolidated, never flagged.
|
|
127
|
+
|
|
128
|
+
### 2. Memory organised by tier
|
|
129
|
+
|
|
130
|
+
```python
|
|
131
|
+
agent.fact("budget: 50k EUR") # semantic (stable)
|
|
132
|
+
agent.event("contract signed", when="2026-05-15") # episodic (time-anchored)
|
|
133
|
+
agent.principle("always confirm changes") # protected, identity-level
|
|
134
|
+
agent.remember("favourite colour: blue") # tier inferred automatically
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
Tiers shape narration in reconstructed prompts and drive retention policy under compression.
|
|
138
|
+
|
|
139
|
+
### 3. Semantic recall
|
|
140
|
+
|
|
141
|
+
```python
|
|
142
|
+
results = agent.recall("money allocated to the project", top_k=5)
|
|
143
|
+
for fact, score in results:
|
|
144
|
+
print(f"{score:.2f} {fact.content}")
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
Pluggable embedding providers: local `sentence-transformers` (default, free, no lock-in), OpenAI, or your own. Recall biases context reconstruction toward facts that actually matter for the current question.
|
|
148
|
+
|
|
149
|
+
### 4. Cognitive compression
|
|
150
|
+
|
|
151
|
+
```python
|
|
152
|
+
report = agent.compress()
|
|
153
|
+
# CompressionReport(
|
|
154
|
+
# decayed_facts=12,
|
|
155
|
+
# consolidation={'clusters_found': 3, 'facts_removed': 7, ...},
|
|
156
|
+
# contradictions={'pairs_found': 2, 'resolutions': 2},
|
|
157
|
+
# facts_before=120, facts_after=102,
|
|
158
|
+
# )
|
|
159
|
+
```
|
|
160
|
+
|
|
161
|
+
Three independent passes:
|
|
162
|
+
|
|
163
|
+
- **Decay** — exponential half-life on unused non-critical facts. Critical and protected facts are immortal.
|
|
164
|
+
- **Consolidation** — embedding-based clustering merges near-duplicates. Optional LLM-backed synthesiser.
|
|
165
|
+
- **Contradiction arbitration** — key-value divergence and polarity-opposition detection. Deterministic winner (critical > importance > recency). Loser is flagged, not deleted.
|
|
166
|
+
|
|
167
|
+
### 5. Cross-model translation
|
|
168
|
+
|
|
169
|
+
The same cognitive state, four formats:
|
|
170
|
+
|
|
171
|
+
| Provider | Format | Why |
|
|
172
|
+
|------------|------------|-----------------------------------------------|
|
|
173
|
+
| Anthropic | XML | Claude excels with structured `<agent_identity>` and `<memory>` blocks |
|
|
174
|
+
| OpenAI | Sections | GPT family responds well to labelled sections (`AGENT IDENTITY`, `MEMORY`, `CURRENT TASK`) |
|
|
175
|
+
| Gemini | Narrative | Long-context model — prefers prose framing |
|
|
176
|
+
| Ollama | Minimal | Small/local models — aggressive compression, terse tokens |
|
|
177
|
+
|
|
178
|
+
Custom providers? Register your own:
|
|
179
|
+
|
|
180
|
+
```python
|
|
181
|
+
from agentkeeper import CognitiveProfile, PromptFormat, register_profile
|
|
182
|
+
|
|
183
|
+
register_profile(CognitiveProfile(
|
|
184
|
+
provider="my-llm",
|
|
185
|
+
format=PromptFormat.SECTIONS,
|
|
186
|
+
effective_context_tokens=10_000,
|
|
187
|
+
))
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## Async API
|
|
191
|
+
|
|
192
|
+
```python
|
|
193
|
+
import asyncio
|
|
194
|
+
import agentkeeper
|
|
195
|
+
|
|
196
|
+
async def main() -> None:
|
|
197
|
+
agent = agentkeeper.create_async(agent_id="aria", provider="anthropic")
|
|
198
|
+
agent.set_identity(name="Aria", role="copilot")
|
|
199
|
+
agent.fact("budget: 50k", importance=0.95)
|
|
200
|
+
|
|
201
|
+
# Parallel asks across providers
|
|
202
|
+
answers = await asyncio.gather(
|
|
203
|
+
agent.ask("status?", provider="anthropic"),
|
|
204
|
+
agent.ask("status?", provider="openai"),
|
|
205
|
+
)
|
|
206
|
+
|
|
207
|
+
asyncio.run(main())
|
|
208
|
+
```
|
|
209
|
+
|
|
210
|
+
Sync and async agents share storage — you can save with one and load with the other.
|
|
211
|
+
|
|
212
|
+
## Production-grade
|
|
213
|
+
|
|
214
|
+
- **Type-safe**: `py.typed` marker shipped, mypy-strict friendly.
|
|
215
|
+
- **Typed exceptions**: `AgentKeeperError` root, with subclasses for every failure mode (provider down, agent missing, retriable network errors).
|
|
216
|
+
- **Structured logging**: namespaced under `agentkeeper.*`, opt-in.
|
|
217
|
+
- **Retries**: built-in exponential backoff for transient provider errors via `with_retry` / `with_async_retry`.
|
|
218
|
+
- **Tested**: 267 tests, CI on Python 3.10 / 3.11 / 3.12.
|
|
219
|
+
|
|
220
|
+
## Configuration
|
|
221
|
+
|
|
222
|
+
Environment variables (all optional):
|
|
223
|
+
|
|
224
|
+
| Variable | Default | Purpose |
|
|
225
|
+
|-----------------------------------|----------------------------------|---------|
|
|
226
|
+
| `OPENAI_API_KEY` | — | Required for OpenAI provider |
|
|
227
|
+
| `ANTHROPIC_API_KEY` | — | Required for Anthropic provider |
|
|
228
|
+
| `GEMINI_API_KEY` | — | Required for Gemini provider |
|
|
229
|
+
| `OPENAI_MODEL` | `gpt-4-turbo` | OpenAI model name |
|
|
230
|
+
| `ANTHROPIC_MODEL` | `claude-sonnet-4-5-20250929` | Anthropic model name |
|
|
231
|
+
| `OLLAMA_HOST` | `http://localhost:11434` | Ollama server URL |
|
|
232
|
+
| `AGENTKEEPER_DB` | `agentkeeper.db` | SQLite path |
|
|
233
|
+
| `AGENTKEEPER_EMBEDDING_PROVIDER` | auto (sentence-transformers > openai > mock) | Override embedding backend |
|
|
234
|
+
|
|
235
|
+
## Roadmap (v1.x)
|
|
236
|
+
|
|
237
|
+
- **v1.1** — Persistent vector index (`sqlite-vec`) so the recaller survives restarts without rebuild.
|
|
238
|
+
- **v1.2** — Async LLM-backed synthesiser in compression.
|
|
239
|
+
- **v1.3** — Pluggable storage backends (Postgres, encrypted).
|
|
240
|
+
- **v1.4** — `AgentKeeper Cloud` (managed sync). *Stays optional; OSS remains feature-complete.*
|
|
241
|
+
|
|
242
|
+
## Featured on
|
|
243
|
+
|
|
244
|
+
AgentKeeper was vouched for in March 2026 by:
|
|
245
|
+
|
|
246
|
+
- Shruti Codes ✓
|
|
247
|
+
- Chidanand Tripathi ✓ ([80K-view thread](#))
|
|
248
|
+
- Kayvon Jafarzadeh ✓
|
|
249
|
+
- Leonard Rodman ✓
|
|
250
|
+
- Martin Szerment ✓
|
|
251
|
+
- Bespoke AI Solutions Inc ✓
|
|
252
|
+
- @grok (xAI)
|
|
253
|
+
|
|
254
|
+
If you've shipped agents that needed to survive across model changes, you understand why this matters. Thank you to everyone who saw the project early.
|
|
255
|
+
|
|
256
|
+
## Contributing
|
|
257
|
+
|
|
258
|
+
Issues, ideas, and PRs welcome. See [CONTRIBUTING.md](./CONTRIBUTING.md).
|
|
259
|
+
|
|
260
|
+
## License
|
|
261
|
+
|
|
262
|
+
MIT. See [LICENSE](./LICENSE).
|
|
263
|
+
|
|
264
|
+
## Built by
|
|
265
|
+
|
|
266
|
+
[**ThinkLanceAI**](https://thinklanceai.com) — cognitive infrastructure for AI systems.
|
|
267
|
+
Need this in production with custom integrations? `hello@thinklanceai.com`.
|