wontopos 2.0.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.
- wontopos-2.0.0/LICENSE +21 -0
- wontopos-2.0.0/PKG-INFO +101 -0
- wontopos-2.0.0/README.md +72 -0
- wontopos-2.0.0/pyproject.toml +37 -0
- wontopos-2.0.0/setup.cfg +4 -0
- wontopos-2.0.0/wontopos/__init__.py +247 -0
- wontopos-2.0.0/wontopos.egg-info/PKG-INFO +101 -0
- wontopos-2.0.0/wontopos.egg-info/SOURCES.txt +9 -0
- wontopos-2.0.0/wontopos.egg-info/dependency_links.txt +1 -0
- wontopos-2.0.0/wontopos.egg-info/requires.txt +1 -0
- wontopos-2.0.0/wontopos.egg-info/top_level.txt +1 -0
wontopos-2.0.0/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Wontopos
|
|
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.
|
wontopos-2.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: wontopos
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: Wontopos — long-term memory for AI agents. Pure semantic retrieval, identical recall in every language, ~100× lower LLM bill.
|
|
5
|
+
Author: Wontopos
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://wontopos.com
|
|
8
|
+
Project-URL: Documentation, https://wontopos.com/why
|
|
9
|
+
Project-URL: Repository, https://github.com/Irina1920/Wos_API
|
|
10
|
+
Project-URL: Issues, https://github.com/Irina1920/Wos_API/issues
|
|
11
|
+
Keywords: memory,ai,agent,llm,vector,embedding,semantic,rag,context
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
24
|
+
Requires-Python: >=3.9
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
License-File: LICENSE
|
|
27
|
+
Requires-Dist: requests>=2.28
|
|
28
|
+
Dynamic: license-file
|
|
29
|
+
|
|
30
|
+
# Wontopos — long-term memory for AI agents
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pip install wontopos
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
from wontopos import Client
|
|
38
|
+
|
|
39
|
+
mem = Client(api_key="wos-...")
|
|
40
|
+
mem.add("she prefers tea over coffee", user_id="alice")
|
|
41
|
+
|
|
42
|
+
# one call → short-term + long-term + context, ready for your LLM prompt
|
|
43
|
+
ctx = mem.recall("what does alice drink?", user_id="alice")
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Why
|
|
47
|
+
|
|
48
|
+
- **Pure semantic retrieval** — no keyword/BM25. Identical recall in every language (한국어 · 日本語 · 中文 · English).
|
|
49
|
+
- **No LLM in the loop** — `store` / `search` / `recall` never call a language model. You pay embeddings, not generation.
|
|
50
|
+
- **Bounded retrieval** — `recall()` returns a small, fixed-size slice (~1,200 tokens) regardless of how much you've stored. Your LLM bill stops growing with history.
|
|
51
|
+
|
|
52
|
+
## Methods
|
|
53
|
+
|
|
54
|
+
| Method | Purpose |
|
|
55
|
+
|---|---|
|
|
56
|
+
| `add(content, user_id, **metadata)` | Store one memory |
|
|
57
|
+
| `add_turn(user_id, user_msg, assistant_msg)` | Store a conversation exchange |
|
|
58
|
+
| `add_bulk(content, user_id, category=, timestamp=)` | Backfill a long history |
|
|
59
|
+
| `update(user_id, old_memory_id, new_content)` | Supersede an old fact |
|
|
60
|
+
| `search(query, user_id, limit=10, **opts)` | Semantic search |
|
|
61
|
+
| `recall(query, user_id)` | One-call context (short + long + surrounding) |
|
|
62
|
+
| `history(user_id)` | Recent turns (short-term) |
|
|
63
|
+
| `stats(user_id)` | Counts |
|
|
64
|
+
| `delete(user_id, memory_id)` | Delete one memory |
|
|
65
|
+
| `delete_all(user_id)` | GDPR erase (delete every memory for the user) |
|
|
66
|
+
|
|
67
|
+
All methods take a `user_id` — memories are isolated per user, then per account (your API key).
|
|
68
|
+
|
|
69
|
+
## Errors
|
|
70
|
+
|
|
71
|
+
Any non-2xx response raises `WosError(status, message)`:
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
from wontopos import Client, WosError
|
|
75
|
+
|
|
76
|
+
try:
|
|
77
|
+
mem.search("...", user_id="alice")
|
|
78
|
+
except WosError as e:
|
|
79
|
+
if e.status == 401:
|
|
80
|
+
print("API key invalid or revoked")
|
|
81
|
+
elif e.status == 429:
|
|
82
|
+
print("Rate limited — back off")
|
|
83
|
+
else:
|
|
84
|
+
print(e.status, e.message)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Self-host
|
|
88
|
+
|
|
89
|
+
Point at your own engine:
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
mem = Client(api_key="...", base_url="https://wos.your-host.com")
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Links
|
|
96
|
+
|
|
97
|
+
- Homepage: <https://wontopos.com>
|
|
98
|
+
- API reference: <https://wontopos.com/why> (Developers tab)
|
|
99
|
+
- Repo: <https://github.com/Irina1920/Wos_API>
|
|
100
|
+
|
|
101
|
+
License: MIT.
|
wontopos-2.0.0/README.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# Wontopos — long-term memory for AI agents
|
|
2
|
+
|
|
3
|
+
```bash
|
|
4
|
+
pip install wontopos
|
|
5
|
+
```
|
|
6
|
+
|
|
7
|
+
```python
|
|
8
|
+
from wontopos import Client
|
|
9
|
+
|
|
10
|
+
mem = Client(api_key="wos-...")
|
|
11
|
+
mem.add("she prefers tea over coffee", user_id="alice")
|
|
12
|
+
|
|
13
|
+
# one call → short-term + long-term + context, ready for your LLM prompt
|
|
14
|
+
ctx = mem.recall("what does alice drink?", user_id="alice")
|
|
15
|
+
```
|
|
16
|
+
|
|
17
|
+
## Why
|
|
18
|
+
|
|
19
|
+
- **Pure semantic retrieval** — no keyword/BM25. Identical recall in every language (한국어 · 日本語 · 中文 · English).
|
|
20
|
+
- **No LLM in the loop** — `store` / `search` / `recall` never call a language model. You pay embeddings, not generation.
|
|
21
|
+
- **Bounded retrieval** — `recall()` returns a small, fixed-size slice (~1,200 tokens) regardless of how much you've stored. Your LLM bill stops growing with history.
|
|
22
|
+
|
|
23
|
+
## Methods
|
|
24
|
+
|
|
25
|
+
| Method | Purpose |
|
|
26
|
+
|---|---|
|
|
27
|
+
| `add(content, user_id, **metadata)` | Store one memory |
|
|
28
|
+
| `add_turn(user_id, user_msg, assistant_msg)` | Store a conversation exchange |
|
|
29
|
+
| `add_bulk(content, user_id, category=, timestamp=)` | Backfill a long history |
|
|
30
|
+
| `update(user_id, old_memory_id, new_content)` | Supersede an old fact |
|
|
31
|
+
| `search(query, user_id, limit=10, **opts)` | Semantic search |
|
|
32
|
+
| `recall(query, user_id)` | One-call context (short + long + surrounding) |
|
|
33
|
+
| `history(user_id)` | Recent turns (short-term) |
|
|
34
|
+
| `stats(user_id)` | Counts |
|
|
35
|
+
| `delete(user_id, memory_id)` | Delete one memory |
|
|
36
|
+
| `delete_all(user_id)` | GDPR erase (delete every memory for the user) |
|
|
37
|
+
|
|
38
|
+
All methods take a `user_id` — memories are isolated per user, then per account (your API key).
|
|
39
|
+
|
|
40
|
+
## Errors
|
|
41
|
+
|
|
42
|
+
Any non-2xx response raises `WosError(status, message)`:
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
from wontopos import Client, WosError
|
|
46
|
+
|
|
47
|
+
try:
|
|
48
|
+
mem.search("...", user_id="alice")
|
|
49
|
+
except WosError as e:
|
|
50
|
+
if e.status == 401:
|
|
51
|
+
print("API key invalid or revoked")
|
|
52
|
+
elif e.status == 429:
|
|
53
|
+
print("Rate limited — back off")
|
|
54
|
+
else:
|
|
55
|
+
print(e.status, e.message)
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
## Self-host
|
|
59
|
+
|
|
60
|
+
Point at your own engine:
|
|
61
|
+
|
|
62
|
+
```python
|
|
63
|
+
mem = Client(api_key="...", base_url="https://wos.your-host.com")
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
## Links
|
|
67
|
+
|
|
68
|
+
- Homepage: <https://wontopos.com>
|
|
69
|
+
- API reference: <https://wontopos.com/why> (Developers tab)
|
|
70
|
+
- Repo: <https://github.com/Irina1920/Wos_API>
|
|
71
|
+
|
|
72
|
+
License: MIT.
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "wontopos"
|
|
7
|
+
version = "2.0.0"
|
|
8
|
+
description = "Wontopos — long-term memory for AI agents. Pure semantic retrieval, identical recall in every language, ~100× lower LLM bill."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
authors = [{ name = "Wontopos" }]
|
|
11
|
+
license = { text = "MIT" }
|
|
12
|
+
requires-python = ">=3.9"
|
|
13
|
+
keywords = ["memory", "ai", "agent", "llm", "vector", "embedding", "semantic", "rag", "context"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Development Status :: 4 - Beta",
|
|
16
|
+
"Intended Audience :: Developers",
|
|
17
|
+
"License :: OSI Approved :: MIT License",
|
|
18
|
+
"Operating System :: OS Independent",
|
|
19
|
+
"Programming Language :: Python :: 3",
|
|
20
|
+
"Programming Language :: Python :: 3.9",
|
|
21
|
+
"Programming Language :: Python :: 3.10",
|
|
22
|
+
"Programming Language :: Python :: 3.11",
|
|
23
|
+
"Programming Language :: Python :: 3.12",
|
|
24
|
+
"Programming Language :: Python :: 3.13",
|
|
25
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
26
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
27
|
+
]
|
|
28
|
+
dependencies = ["requests>=2.28"]
|
|
29
|
+
|
|
30
|
+
[project.urls]
|
|
31
|
+
Homepage = "https://wontopos.com"
|
|
32
|
+
Documentation = "https://wontopos.com/why"
|
|
33
|
+
Repository = "https://github.com/Irina1920/Wos_API"
|
|
34
|
+
Issues = "https://github.com/Irina1920/Wos_API/issues"
|
|
35
|
+
|
|
36
|
+
[tool.setuptools.packages.find]
|
|
37
|
+
include = ["wontopos*"]
|
wontopos-2.0.0/setup.cfg
ADDED
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
"""Wontopos — long-term memory for AI, in three lines.
|
|
2
|
+
|
|
3
|
+
pip install wontopos
|
|
4
|
+
|
|
5
|
+
from wontopos import Client
|
|
6
|
+
mem = Client(api_key="wos-...")
|
|
7
|
+
mem.add("I love hiking in Yosemite", user_id="alice")
|
|
8
|
+
print(mem.search("what does she like?", user_id="alice"))
|
|
9
|
+
|
|
10
|
+
Pure semantic retrieval — no keyword/BM25 matching, so it works the SAME in every
|
|
11
|
+
language (Korean, Japanese, Chinese, English, ...). Storing and searching call no LLM;
|
|
12
|
+
you only pay for embeddings.
|
|
13
|
+
|
|
14
|
+
For BYOK chat/persona (bring your own LLM key), see the advanced `Wos` client at the
|
|
15
|
+
bottom of this module.
|
|
16
|
+
"""
|
|
17
|
+
from __future__ import annotations
|
|
18
|
+
|
|
19
|
+
from typing import Any, Optional
|
|
20
|
+
|
|
21
|
+
import requests
|
|
22
|
+
|
|
23
|
+
__version__ = "2.0.0"
|
|
24
|
+
DEFAULT_BASE_URL = "https://api.wontopos.com"
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
class WosError(RuntimeError):
|
|
28
|
+
"""Raised when the Wontopos API returns a non-2xx response (or the network fails)."""
|
|
29
|
+
|
|
30
|
+
def __init__(self, status: int, message: str):
|
|
31
|
+
self.status = status
|
|
32
|
+
self.message = message
|
|
33
|
+
super().__init__(f"[{status}] {message}")
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class Client:
|
|
37
|
+
"""Wontopos memory client.
|
|
38
|
+
|
|
39
|
+
Store and recall memories, isolated per ``user_id``.
|
|
40
|
+
|
|
41
|
+
mem = Client(api_key="wos-...")
|
|
42
|
+
mem.add("she prefers tea over coffee", user_id="alice")
|
|
43
|
+
hits = mem.search("what does alice drink?", user_id="alice")
|
|
44
|
+
|
|
45
|
+
Args:
|
|
46
|
+
api_key: your Wontopos API key (sent as ``X-API-Key``).
|
|
47
|
+
base_url: API base URL (defaults to the hosted service).
|
|
48
|
+
timeout: per-request timeout in seconds.
|
|
49
|
+
"""
|
|
50
|
+
|
|
51
|
+
def __init__(self, api_key: str, base_url: str = DEFAULT_BASE_URL, timeout: float = 30.0):
|
|
52
|
+
if not api_key:
|
|
53
|
+
raise ValueError("api_key is required")
|
|
54
|
+
self._base = base_url.rstrip("/")
|
|
55
|
+
self._timeout = timeout
|
|
56
|
+
self._session = requests.Session()
|
|
57
|
+
self._session.headers.update({"X-API-Key": api_key, "Content-Type": "application/json"})
|
|
58
|
+
|
|
59
|
+
# ----- write -----
|
|
60
|
+
|
|
61
|
+
def add(self, content: str, user_id: str, **metadata: Any) -> dict:
|
|
62
|
+
"""Store one memory. Extra keyword args become metadata.
|
|
63
|
+
|
|
64
|
+
mem.add("moved to Berlin", user_id="alice", event_date="2026-03-01")
|
|
65
|
+
"""
|
|
66
|
+
return self._post(
|
|
67
|
+
"/api/v1/memory/store",
|
|
68
|
+
{"user_id": user_id, "content": content, "metadata": metadata},
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
store = add # alias (back-compat / preference)
|
|
72
|
+
|
|
73
|
+
def add_turn(self, user_id: str, user_msg: str, assistant_msg: str) -> dict:
|
|
74
|
+
"""Store a conversation turn (user + assistant) into short-term + long-term memory."""
|
|
75
|
+
return self._post(
|
|
76
|
+
"/api/v1/memory/store-turn",
|
|
77
|
+
{"user_id": user_id, "user_msg": user_msg, "assistant_msg": assistant_msg},
|
|
78
|
+
)
|
|
79
|
+
|
|
80
|
+
def add_bulk(
|
|
81
|
+
self, content: str, user_id: str, category: str = "general",
|
|
82
|
+
timestamp: Optional[str] = None,
|
|
83
|
+
) -> dict:
|
|
84
|
+
"""Bulk-ingest a large blob of text (chunked + embedded server-side).
|
|
85
|
+
|
|
86
|
+
Use this to backfill long histories in one call. ``timestamp`` is an RFC3339 string.
|
|
87
|
+
"""
|
|
88
|
+
body: dict[str, Any] = {"user_id": user_id, "content": content, "category": category}
|
|
89
|
+
if timestamp:
|
|
90
|
+
body["timestamp"] = timestamp
|
|
91
|
+
return self._post("/api/v1/memory/bulk-store", body)
|
|
92
|
+
|
|
93
|
+
def update(self, user_id: str, old_memory_id: str, new_content: str) -> dict:
|
|
94
|
+
"""Supersede an old memory with new content (e.g. a fact that changed)."""
|
|
95
|
+
return self._post(
|
|
96
|
+
"/api/v1/memory/supersede",
|
|
97
|
+
{"user_id": user_id, "old_memory_id": old_memory_id, "new_content": new_content},
|
|
98
|
+
)
|
|
99
|
+
|
|
100
|
+
# ----- read -----
|
|
101
|
+
|
|
102
|
+
def search(self, query: str, user_id: str, limit: int = 10, **opts: Any) -> list[dict]:
|
|
103
|
+
"""Semantic search over a user's memories. Returns memories, most relevant first."""
|
|
104
|
+
body = {"user_id": user_id, "query": query, "max_results": limit, **opts}
|
|
105
|
+
return self._post("/api/v1/memory/search", body).get("memories", [])
|
|
106
|
+
|
|
107
|
+
def recall(self, query: str, user_id: str) -> dict:
|
|
108
|
+
"""One-call context for an LLM: short-term turns + long-term matches + surrounding context.
|
|
109
|
+
|
|
110
|
+
Returns ``{"short_term": ..., "long_term": ..., "context": ...}``. No extra round-trips.
|
|
111
|
+
"""
|
|
112
|
+
return self._post("/api/v1/memory/recall", {"user_id": user_id, "query": query})
|
|
113
|
+
|
|
114
|
+
def history(self, user_id: str) -> list[dict]:
|
|
115
|
+
"""Recent conversation turns (short-term memory)."""
|
|
116
|
+
return self._post("/api/v1/memory/history", {"user_id": user_id}).get("turns", [])
|
|
117
|
+
|
|
118
|
+
def stats(self, user_id: str) -> dict:
|
|
119
|
+
"""Memory counts for a user: ``{total_memories, short_term_turns}``."""
|
|
120
|
+
return self._post("/api/v1/memory/stats", {"user_id": user_id})
|
|
121
|
+
|
|
122
|
+
# ----- delete -----
|
|
123
|
+
|
|
124
|
+
def delete(self, user_id: str, memory_id: str) -> dict:
|
|
125
|
+
"""Delete a single memory by id."""
|
|
126
|
+
return self._post("/api/v1/memory/forget", {"user_id": user_id, "memory_id": memory_id})
|
|
127
|
+
|
|
128
|
+
def delete_all(self, user_id: str) -> dict:
|
|
129
|
+
"""Delete ALL memories for a user (GDPR erase)."""
|
|
130
|
+
return self._post("/api/v1/memory/forget", {"user_id": user_id})
|
|
131
|
+
|
|
132
|
+
# ----- internal -----
|
|
133
|
+
|
|
134
|
+
def _post(self, path: str, body: dict) -> dict:
|
|
135
|
+
try:
|
|
136
|
+
r = self._session.post(f"{self._base}{path}", json=body, timeout=self._timeout)
|
|
137
|
+
except requests.RequestException as e:
|
|
138
|
+
raise WosError(0, f"network error: {e}") from e
|
|
139
|
+
if not r.ok:
|
|
140
|
+
# Server may return either:
|
|
141
|
+
# Anthropic-style envelope: {"type":"error","error":{"type":...,"message":...,"request_id":...}}
|
|
142
|
+
# Spec simple: {"error":"reason string"}
|
|
143
|
+
# Fall back to raw text.
|
|
144
|
+
msg = r.text
|
|
145
|
+
try:
|
|
146
|
+
data = r.json()
|
|
147
|
+
if isinstance(data, dict):
|
|
148
|
+
err = data.get("error")
|
|
149
|
+
if isinstance(err, dict):
|
|
150
|
+
msg = err.get("message") or err.get("type") or msg
|
|
151
|
+
elif isinstance(err, str):
|
|
152
|
+
msg = err
|
|
153
|
+
elif "message" in data:
|
|
154
|
+
msg = data["message"]
|
|
155
|
+
except Exception:
|
|
156
|
+
pass
|
|
157
|
+
raise WosError(r.status_code, msg)
|
|
158
|
+
return r.json()
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
# Back-compat alias: older code used `WME`.
|
|
162
|
+
WME = Client
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
# ---------------------------------------------------------------------------
|
|
166
|
+
# Advanced: BYOK chat (WPE + WME). Most users only need `Client` above.
|
|
167
|
+
# The customer brings their own LLM API key; Wos never stores it (sent per request).
|
|
168
|
+
# ---------------------------------------------------------------------------
|
|
169
|
+
|
|
170
|
+
import json as _json # noqa: E402
|
|
171
|
+
from typing import Iterator # noqa: E402
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
class Wos:
|
|
175
|
+
"""Full chat client (persona + memory). Bring your own LLM API key.
|
|
176
|
+
|
|
177
|
+
Model slots (named after neurotransmitters by function):
|
|
178
|
+
glu (Glutamate) : MAIN — LLM1 (fast reply / deficit) + LLM3 (synthesis).
|
|
179
|
+
sero (Serotonin) : SUB — LLM2 engram router.
|
|
180
|
+
ach (Acetylcholine) : MIDDLE — optional, future use.
|
|
181
|
+
"""
|
|
182
|
+
|
|
183
|
+
def __init__(
|
|
184
|
+
self,
|
|
185
|
+
llm_api_key: str,
|
|
186
|
+
glu: str,
|
|
187
|
+
sero: str,
|
|
188
|
+
persona: str = "",
|
|
189
|
+
ach: Optional[str] = None,
|
|
190
|
+
llm_base_url: Optional[str] = None,
|
|
191
|
+
api_key: Optional[str] = None,
|
|
192
|
+
base_url: str = DEFAULT_BASE_URL,
|
|
193
|
+
):
|
|
194
|
+
self._url = base_url.rstrip("/")
|
|
195
|
+
self._llm_key = llm_api_key
|
|
196
|
+
self._glu = glu
|
|
197
|
+
self._sero = sero
|
|
198
|
+
self._ach = ach
|
|
199
|
+
self._persona = persona
|
|
200
|
+
self._llm_base = llm_base_url
|
|
201
|
+
self._svc_key = api_key
|
|
202
|
+
|
|
203
|
+
def _headers(self, stream: bool = False) -> dict:
|
|
204
|
+
h = {
|
|
205
|
+
"Content-Type": "application/json",
|
|
206
|
+
"X-LLM-Key": self._llm_key,
|
|
207
|
+
"X-LLM-Glu": self._glu,
|
|
208
|
+
"X-LLM-Sero": self._sero,
|
|
209
|
+
}
|
|
210
|
+
if self._ach:
|
|
211
|
+
h["X-LLM-Ach"] = self._ach
|
|
212
|
+
if self._llm_base:
|
|
213
|
+
h["X-LLM-Base-Url"] = self._llm_base
|
|
214
|
+
if self._svc_key:
|
|
215
|
+
h["X-API-Key"] = self._svc_key
|
|
216
|
+
if stream:
|
|
217
|
+
h["Accept"] = "text/event-stream"
|
|
218
|
+
return h
|
|
219
|
+
|
|
220
|
+
def create_character(self, name: str, **extra) -> str:
|
|
221
|
+
body = {"name": name, "persona": self._persona, **extra}
|
|
222
|
+
r = requests.post(f"{self._url}/api/v1/character/create", json=body, headers=self._headers(), timeout=30)
|
|
223
|
+
r.raise_for_status()
|
|
224
|
+
return r.json()["id"]
|
|
225
|
+
|
|
226
|
+
def chat(self, character_id: str, message: str) -> Iterator[str]:
|
|
227
|
+
"""Stream a chat response token by token."""
|
|
228
|
+
body = {"message": message, "persona": self._persona}
|
|
229
|
+
with requests.post(
|
|
230
|
+
f"{self._url}/api/v1/character/{character_id}/chat",
|
|
231
|
+
json=body, headers=self._headers(stream=True), stream=True, timeout=180,
|
|
232
|
+
) as r:
|
|
233
|
+
r.raise_for_status()
|
|
234
|
+
for line in r.iter_lines(decode_unicode=True):
|
|
235
|
+
if not line or not line.startswith("data:"):
|
|
236
|
+
continue
|
|
237
|
+
payload = line[5:].strip()
|
|
238
|
+
if not payload:
|
|
239
|
+
continue
|
|
240
|
+
try:
|
|
241
|
+
evt = _json.loads(payload)
|
|
242
|
+
except _json.JSONDecodeError:
|
|
243
|
+
continue
|
|
244
|
+
if "delta" in evt:
|
|
245
|
+
yield evt["delta"]
|
|
246
|
+
elif "error" in evt:
|
|
247
|
+
raise RuntimeError(evt["error"])
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: wontopos
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: Wontopos — long-term memory for AI agents. Pure semantic retrieval, identical recall in every language, ~100× lower LLM bill.
|
|
5
|
+
Author: Wontopos
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://wontopos.com
|
|
8
|
+
Project-URL: Documentation, https://wontopos.com/why
|
|
9
|
+
Project-URL: Repository, https://github.com/Irina1920/Wos_API
|
|
10
|
+
Project-URL: Issues, https://github.com/Irina1920/Wos_API/issues
|
|
11
|
+
Keywords: memory,ai,agent,llm,vector,embedding,semantic,rag,context
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Intended Audience :: Developers
|
|
14
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
15
|
+
Classifier: Operating System :: OS Independent
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
19
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
20
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
22
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
23
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
24
|
+
Requires-Python: >=3.9
|
|
25
|
+
Description-Content-Type: text/markdown
|
|
26
|
+
License-File: LICENSE
|
|
27
|
+
Requires-Dist: requests>=2.28
|
|
28
|
+
Dynamic: license-file
|
|
29
|
+
|
|
30
|
+
# Wontopos — long-term memory for AI agents
|
|
31
|
+
|
|
32
|
+
```bash
|
|
33
|
+
pip install wontopos
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
```python
|
|
37
|
+
from wontopos import Client
|
|
38
|
+
|
|
39
|
+
mem = Client(api_key="wos-...")
|
|
40
|
+
mem.add("she prefers tea over coffee", user_id="alice")
|
|
41
|
+
|
|
42
|
+
# one call → short-term + long-term + context, ready for your LLM prompt
|
|
43
|
+
ctx = mem.recall("what does alice drink?", user_id="alice")
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Why
|
|
47
|
+
|
|
48
|
+
- **Pure semantic retrieval** — no keyword/BM25. Identical recall in every language (한국어 · 日本語 · 中文 · English).
|
|
49
|
+
- **No LLM in the loop** — `store` / `search` / `recall` never call a language model. You pay embeddings, not generation.
|
|
50
|
+
- **Bounded retrieval** — `recall()` returns a small, fixed-size slice (~1,200 tokens) regardless of how much you've stored. Your LLM bill stops growing with history.
|
|
51
|
+
|
|
52
|
+
## Methods
|
|
53
|
+
|
|
54
|
+
| Method | Purpose |
|
|
55
|
+
|---|---|
|
|
56
|
+
| `add(content, user_id, **metadata)` | Store one memory |
|
|
57
|
+
| `add_turn(user_id, user_msg, assistant_msg)` | Store a conversation exchange |
|
|
58
|
+
| `add_bulk(content, user_id, category=, timestamp=)` | Backfill a long history |
|
|
59
|
+
| `update(user_id, old_memory_id, new_content)` | Supersede an old fact |
|
|
60
|
+
| `search(query, user_id, limit=10, **opts)` | Semantic search |
|
|
61
|
+
| `recall(query, user_id)` | One-call context (short + long + surrounding) |
|
|
62
|
+
| `history(user_id)` | Recent turns (short-term) |
|
|
63
|
+
| `stats(user_id)` | Counts |
|
|
64
|
+
| `delete(user_id, memory_id)` | Delete one memory |
|
|
65
|
+
| `delete_all(user_id)` | GDPR erase (delete every memory for the user) |
|
|
66
|
+
|
|
67
|
+
All methods take a `user_id` — memories are isolated per user, then per account (your API key).
|
|
68
|
+
|
|
69
|
+
## Errors
|
|
70
|
+
|
|
71
|
+
Any non-2xx response raises `WosError(status, message)`:
|
|
72
|
+
|
|
73
|
+
```python
|
|
74
|
+
from wontopos import Client, WosError
|
|
75
|
+
|
|
76
|
+
try:
|
|
77
|
+
mem.search("...", user_id="alice")
|
|
78
|
+
except WosError as e:
|
|
79
|
+
if e.status == 401:
|
|
80
|
+
print("API key invalid or revoked")
|
|
81
|
+
elif e.status == 429:
|
|
82
|
+
print("Rate limited — back off")
|
|
83
|
+
else:
|
|
84
|
+
print(e.status, e.message)
|
|
85
|
+
```
|
|
86
|
+
|
|
87
|
+
## Self-host
|
|
88
|
+
|
|
89
|
+
Point at your own engine:
|
|
90
|
+
|
|
91
|
+
```python
|
|
92
|
+
mem = Client(api_key="...", base_url="https://wos.your-host.com")
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
## Links
|
|
96
|
+
|
|
97
|
+
- Homepage: <https://wontopos.com>
|
|
98
|
+
- API reference: <https://wontopos.com/why> (Developers tab)
|
|
99
|
+
- Repo: <https://github.com/Irina1920/Wos_API>
|
|
100
|
+
|
|
101
|
+
License: MIT.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
requests>=2.28
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
wontopos
|