autourgos-memory 1.0.2__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.
- autourgos_memory-1.0.2/LICENSE +21 -0
- autourgos_memory-1.0.2/PKG-INFO +144 -0
- autourgos_memory-1.0.2/README.md +121 -0
- autourgos_memory-1.0.2/autourgos_memory/__init__.py +55 -0
- autourgos_memory-1.0.2/autourgos_memory/base.py +102 -0
- autourgos_memory-1.0.2/autourgos_memory/py.typed +0 -0
- autourgos_memory-1.0.2/autourgos_memory.egg-info/PKG-INFO +144 -0
- autourgos_memory-1.0.2/autourgos_memory.egg-info/SOURCES.txt +10 -0
- autourgos_memory-1.0.2/autourgos_memory.egg-info/dependency_links.txt +1 -0
- autourgos_memory-1.0.2/autourgos_memory.egg-info/top_level.txt +1 -0
- autourgos_memory-1.0.2/pyproject.toml +39 -0
- autourgos_memory-1.0.2/setup.cfg +4 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2024 Jitin Kumar Sengar
|
|
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,144 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: autourgos-memory
|
|
3
|
+
Version: 1.0.2
|
|
4
|
+
Summary: Base memory interfaces for Autourgos agents — BaseMemory, MemoryMessage, Document, BaseRetriever.
|
|
5
|
+
Author-email: Jitin Kumar Sengar <devxjitin@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/devxjitin/autourgos-memory
|
|
8
|
+
Project-URL: Repository, https://github.com/devxjitin/autourgos-memory
|
|
9
|
+
Project-URL: Issues, https://github.com/devxjitin/autourgos-memory/issues
|
|
10
|
+
Keywords: autourgos,agent,memory,llm
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Requires-Python: >=3.9
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
|
|
24
|
+
# autourgos-memory
|
|
25
|
+
|
|
26
|
+
Base memory interfaces for [Autourgos](https://github.com/devxjitin) agents.
|
|
27
|
+
|
|
28
|
+
This is the **foundation package** — it defines the abstract interfaces (`BaseMemory`, `BaseRetriever`, `MemoryMessage`, `Document`) that all concrete memory implementations use. Install it on its own, or install one of the concrete packages that depend on it.
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Install
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
# Base interfaces only
|
|
36
|
+
pip install autourgos-memory
|
|
37
|
+
|
|
38
|
+
# Or install concrete implementations individually
|
|
39
|
+
pip install autourgos-buffer-memory # in-memory ring buffer
|
|
40
|
+
pip install autourgos-local-memory # JSON file + SQLite
|
|
41
|
+
pip install autourgos-semantic-memory # TF-IDF keyword retrieval
|
|
42
|
+
pip install autourgos-summary-memory # LLM-compressed rolling summary
|
|
43
|
+
pip install autourgos-token-memory # token-bounded buffer
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## Memory types at a glance
|
|
49
|
+
|
|
50
|
+
| Package | Class | Best for |
|
|
51
|
+
|---|---|---|
|
|
52
|
+
| `autourgos-buffer-memory` | `RuntimeShortTermMemory` | Fast in-memory buffer, message-count bounded |
|
|
53
|
+
| `autourgos-buffer-memory` | `ConversationBufferMemory` | Unbounded in-memory buffer |
|
|
54
|
+
| `autourgos-local-memory` | `LocalShortTermMemory` | Disk persistence via JSON file |
|
|
55
|
+
| `autourgos-local-memory` | `SQLiteMemory` | Disk persistence via SQLite, concurrent-safe |
|
|
56
|
+
| `autourgos-semantic-memory` | `KeywordMemory` | TF-IDF retrieval of relevant past context |
|
|
57
|
+
| `autourgos-summary-memory` | `SummaryBufferedMemory` | LLM-compressed history to save tokens |
|
|
58
|
+
| `autourgos-token-memory` | `TokenBufferedMemory` | Token-budget bounded buffer |
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## Quick start (with concrete packages installed)
|
|
63
|
+
|
|
64
|
+
`RuntimeShortTermMemory` is soft re-exported from `autourgos_memory` — it only resolves if `autourgos-buffer-memory` is also installed:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
pip install autourgos-memory autourgos-buffer-memory autourgos-openaichat
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
from autourgos_memory import RuntimeShortTermMemory # requires autourgos-buffer-memory installed
|
|
72
|
+
from autourgos_react_agent import ReactAgent
|
|
73
|
+
from autourgos_openaichat import OpenAIChatModel
|
|
74
|
+
|
|
75
|
+
my_llm = OpenAIChatModel(model="gpt-4o-mini") # needs OPENAI_API_KEY set
|
|
76
|
+
memory = RuntimeShortTermMemory(max_messages=20)
|
|
77
|
+
agent = ReactAgent(llm=my_llm, memory=memory)
|
|
78
|
+
result = agent.invoke("What did I ask you last time?")
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## Base interfaces
|
|
84
|
+
|
|
85
|
+
### MemoryMessage
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
from autourgos_memory import MemoryMessage
|
|
89
|
+
from datetime import datetime, timezone
|
|
90
|
+
|
|
91
|
+
msg = MemoryMessage(role="user", content="Hello", timestamp=datetime.now(timezone.utc))
|
|
92
|
+
print(msg.to_dict())
|
|
93
|
+
# {"role": "user", "content": "Hello", "timestamp": "2024-..."}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Allowed roles: `user`, `agent`, `system`, `tool`.
|
|
97
|
+
|
|
98
|
+
### BaseMemory
|
|
99
|
+
|
|
100
|
+
Implement this to create your own memory backend:
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
from autourgos_memory import BaseMemory, MemoryMessage
|
|
104
|
+
|
|
105
|
+
class MyCustomMemory(BaseMemory):
|
|
106
|
+
def add_user_message(self, content: str) -> MemoryMessage: ...
|
|
107
|
+
def add_agent_message(self, content: str) -> MemoryMessage: ...
|
|
108
|
+
def add_tool_message(self, tool_name: str, result: str) -> MemoryMessage: ...
|
|
109
|
+
def format_for_llm(self, query: str = None) -> str: ...
|
|
110
|
+
def clear(self) -> None: ...
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### BaseRetriever
|
|
114
|
+
|
|
115
|
+
Implement this to plug in your own vector database:
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
from autourgos_memory import BaseRetriever, Document
|
|
119
|
+
|
|
120
|
+
class MyVectorDB(BaseRetriever):
|
|
121
|
+
def retrieve(self, query: str, top_k: int = 5) -> list[Document]: ...
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Document
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
from autourgos_memory import Document
|
|
128
|
+
|
|
129
|
+
doc = Document(content="Paris is the capital of France.", score=0.92, source="wiki")
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
## Links
|
|
135
|
+
|
|
136
|
+
- PyPI: https://pypi.org/project/autourgos-memory/
|
|
137
|
+
- GitHub: https://github.com/devxjitin/autourgos-memory
|
|
138
|
+
- Issues: https://github.com/devxjitin/autourgos-memory/issues
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## License
|
|
143
|
+
|
|
144
|
+
MIT — see [LICENSE](LICENSE)
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
# autourgos-memory
|
|
2
|
+
|
|
3
|
+
Base memory interfaces for [Autourgos](https://github.com/devxjitin) agents.
|
|
4
|
+
|
|
5
|
+
This is the **foundation package** — it defines the abstract interfaces (`BaseMemory`, `BaseRetriever`, `MemoryMessage`, `Document`) that all concrete memory implementations use. Install it on its own, or install one of the concrete packages that depend on it.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
## Install
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
# Base interfaces only
|
|
13
|
+
pip install autourgos-memory
|
|
14
|
+
|
|
15
|
+
# Or install concrete implementations individually
|
|
16
|
+
pip install autourgos-buffer-memory # in-memory ring buffer
|
|
17
|
+
pip install autourgos-local-memory # JSON file + SQLite
|
|
18
|
+
pip install autourgos-semantic-memory # TF-IDF keyword retrieval
|
|
19
|
+
pip install autourgos-summary-memory # LLM-compressed rolling summary
|
|
20
|
+
pip install autourgos-token-memory # token-bounded buffer
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
---
|
|
24
|
+
|
|
25
|
+
## Memory types at a glance
|
|
26
|
+
|
|
27
|
+
| Package | Class | Best for |
|
|
28
|
+
|---|---|---|
|
|
29
|
+
| `autourgos-buffer-memory` | `RuntimeShortTermMemory` | Fast in-memory buffer, message-count bounded |
|
|
30
|
+
| `autourgos-buffer-memory` | `ConversationBufferMemory` | Unbounded in-memory buffer |
|
|
31
|
+
| `autourgos-local-memory` | `LocalShortTermMemory` | Disk persistence via JSON file |
|
|
32
|
+
| `autourgos-local-memory` | `SQLiteMemory` | Disk persistence via SQLite, concurrent-safe |
|
|
33
|
+
| `autourgos-semantic-memory` | `KeywordMemory` | TF-IDF retrieval of relevant past context |
|
|
34
|
+
| `autourgos-summary-memory` | `SummaryBufferedMemory` | LLM-compressed history to save tokens |
|
|
35
|
+
| `autourgos-token-memory` | `TokenBufferedMemory` | Token-budget bounded buffer |
|
|
36
|
+
|
|
37
|
+
---
|
|
38
|
+
|
|
39
|
+
## Quick start (with concrete packages installed)
|
|
40
|
+
|
|
41
|
+
`RuntimeShortTermMemory` is soft re-exported from `autourgos_memory` — it only resolves if `autourgos-buffer-memory` is also installed:
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
pip install autourgos-memory autourgos-buffer-memory autourgos-openaichat
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
```python
|
|
48
|
+
from autourgos_memory import RuntimeShortTermMemory # requires autourgos-buffer-memory installed
|
|
49
|
+
from autourgos_react_agent import ReactAgent
|
|
50
|
+
from autourgos_openaichat import OpenAIChatModel
|
|
51
|
+
|
|
52
|
+
my_llm = OpenAIChatModel(model="gpt-4o-mini") # needs OPENAI_API_KEY set
|
|
53
|
+
memory = RuntimeShortTermMemory(max_messages=20)
|
|
54
|
+
agent = ReactAgent(llm=my_llm, memory=memory)
|
|
55
|
+
result = agent.invoke("What did I ask you last time?")
|
|
56
|
+
```
|
|
57
|
+
|
|
58
|
+
---
|
|
59
|
+
|
|
60
|
+
## Base interfaces
|
|
61
|
+
|
|
62
|
+
### MemoryMessage
|
|
63
|
+
|
|
64
|
+
```python
|
|
65
|
+
from autourgos_memory import MemoryMessage
|
|
66
|
+
from datetime import datetime, timezone
|
|
67
|
+
|
|
68
|
+
msg = MemoryMessage(role="user", content="Hello", timestamp=datetime.now(timezone.utc))
|
|
69
|
+
print(msg.to_dict())
|
|
70
|
+
# {"role": "user", "content": "Hello", "timestamp": "2024-..."}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Allowed roles: `user`, `agent`, `system`, `tool`.
|
|
74
|
+
|
|
75
|
+
### BaseMemory
|
|
76
|
+
|
|
77
|
+
Implement this to create your own memory backend:
|
|
78
|
+
|
|
79
|
+
```python
|
|
80
|
+
from autourgos_memory import BaseMemory, MemoryMessage
|
|
81
|
+
|
|
82
|
+
class MyCustomMemory(BaseMemory):
|
|
83
|
+
def add_user_message(self, content: str) -> MemoryMessage: ...
|
|
84
|
+
def add_agent_message(self, content: str) -> MemoryMessage: ...
|
|
85
|
+
def add_tool_message(self, tool_name: str, result: str) -> MemoryMessage: ...
|
|
86
|
+
def format_for_llm(self, query: str = None) -> str: ...
|
|
87
|
+
def clear(self) -> None: ...
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
### BaseRetriever
|
|
91
|
+
|
|
92
|
+
Implement this to plug in your own vector database:
|
|
93
|
+
|
|
94
|
+
```python
|
|
95
|
+
from autourgos_memory import BaseRetriever, Document
|
|
96
|
+
|
|
97
|
+
class MyVectorDB(BaseRetriever):
|
|
98
|
+
def retrieve(self, query: str, top_k: int = 5) -> list[Document]: ...
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
### Document
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
from autourgos_memory import Document
|
|
105
|
+
|
|
106
|
+
doc = Document(content="Paris is the capital of France.", score=0.92, source="wiki")
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
---
|
|
110
|
+
|
|
111
|
+
## Links
|
|
112
|
+
|
|
113
|
+
- PyPI: https://pypi.org/project/autourgos-memory/
|
|
114
|
+
- GitHub: https://github.com/devxjitin/autourgos-memory
|
|
115
|
+
- Issues: https://github.com/devxjitin/autourgos-memory/issues
|
|
116
|
+
|
|
117
|
+
---
|
|
118
|
+
|
|
119
|
+
## License
|
|
120
|
+
|
|
121
|
+
MIT — see [LICENSE](LICENSE)
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"""
|
|
2
|
+
autourgos-memory — Base memory interfaces for Autourgos.
|
|
3
|
+
|
|
4
|
+
Install the full suite::
|
|
5
|
+
|
|
6
|
+
pip install autourgos-memory autourgos-buffer-memory autourgos-local-memory
|
|
7
|
+
pip install autourgos-semantic-memory autourgos-summary-memory autourgos-token-memory
|
|
8
|
+
|
|
9
|
+
Quick imports::
|
|
10
|
+
|
|
11
|
+
from autourgos_memory import BaseMemory, MemoryMessage, Document, BaseRetriever
|
|
12
|
+
"""
|
|
13
|
+
import logging
|
|
14
|
+
|
|
15
|
+
from .base import BaseMemory, BaseRetriever, Document, MemoryMessage
|
|
16
|
+
|
|
17
|
+
logger = logging.getLogger(__name__)
|
|
18
|
+
|
|
19
|
+
# soft re-exports of concrete implementations
|
|
20
|
+
try:
|
|
21
|
+
from autourgos_buffer_memory import RuntimeShortTermMemory, ConversationBufferMemory
|
|
22
|
+
except ImportError:
|
|
23
|
+
pass
|
|
24
|
+
try:
|
|
25
|
+
from autourgos_local_memory import LocalShortTermMemory, SQLiteMemory
|
|
26
|
+
except ImportError:
|
|
27
|
+
pass
|
|
28
|
+
try:
|
|
29
|
+
from autourgos_semantic_memory import KeywordRetriever, KeywordMemory, SimpleSemanticRetriever, HierarchicalSemanticMemory
|
|
30
|
+
except ImportError:
|
|
31
|
+
pass
|
|
32
|
+
try:
|
|
33
|
+
from autourgos_summary_memory import SummaryBufferedMemory
|
|
34
|
+
except ImportError:
|
|
35
|
+
pass
|
|
36
|
+
try:
|
|
37
|
+
from autourgos_token_memory import TokenBufferedMemory
|
|
38
|
+
except ImportError:
|
|
39
|
+
pass
|
|
40
|
+
|
|
41
|
+
try:
|
|
42
|
+
from importlib.metadata import version as _v
|
|
43
|
+
__version__ = _v("autourgos-memory")
|
|
44
|
+
except Exception:
|
|
45
|
+
logger.debug("could not resolve installed version for autourgos-memory", exc_info=True)
|
|
46
|
+
__version__ = "1.0.2"
|
|
47
|
+
|
|
48
|
+
__all__ = [
|
|
49
|
+
"BaseMemory", "BaseRetriever", "Document", "MemoryMessage",
|
|
50
|
+
"RuntimeShortTermMemory", "ConversationBufferMemory",
|
|
51
|
+
"LocalShortTermMemory", "SQLiteMemory",
|
|
52
|
+
"KeywordRetriever", "KeywordMemory", "SimpleSemanticRetriever", "HierarchicalSemanticMemory",
|
|
53
|
+
"SummaryBufferedMemory",
|
|
54
|
+
"TokenBufferedMemory",
|
|
55
|
+
]
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
"""
|
|
2
|
+
base.py — Core memory interfaces for Autourgos.
|
|
3
|
+
"""
|
|
4
|
+
from abc import ABC, abstractmethod
|
|
5
|
+
from dataclasses import dataclass, field
|
|
6
|
+
from datetime import datetime, timezone
|
|
7
|
+
from typing import Any, Dict, List, Optional
|
|
8
|
+
import warnings
|
|
9
|
+
|
|
10
|
+
_ALLOWED_ROLES = {"user", "agent", "system", "tool"}
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
@dataclass(frozen=True)
|
|
14
|
+
class MemoryMessage:
|
|
15
|
+
"""A single message in memory."""
|
|
16
|
+
role: str
|
|
17
|
+
content: str
|
|
18
|
+
timestamp: datetime
|
|
19
|
+
|
|
20
|
+
def __post_init__(self) -> None:
|
|
21
|
+
if self.role not in _ALLOWED_ROLES:
|
|
22
|
+
raise ValueError(f"Invalid role '{self.role}'. Allowed: {sorted(_ALLOWED_ROLES)}")
|
|
23
|
+
if not isinstance(self.content, str):
|
|
24
|
+
raise ValueError("content must be a string")
|
|
25
|
+
if not isinstance(self.timestamp, datetime):
|
|
26
|
+
raise ValueError("timestamp must be a datetime")
|
|
27
|
+
|
|
28
|
+
def to_dict(self) -> Dict[str, str]:
|
|
29
|
+
return {
|
|
30
|
+
"role": self.role,
|
|
31
|
+
"content": self.content,
|
|
32
|
+
"timestamp": self.timestamp.astimezone(timezone.utc).isoformat(),
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
@classmethod
|
|
36
|
+
def from_dict(cls, payload: Dict[str, Any]) -> "MemoryMessage":
|
|
37
|
+
ts = payload.get("timestamp")
|
|
38
|
+
if not isinstance(ts, str):
|
|
39
|
+
raise ValueError("Invalid message payload: timestamp must be a string")
|
|
40
|
+
dt = datetime.fromisoformat(ts)
|
|
41
|
+
if dt.tzinfo is None:
|
|
42
|
+
dt = dt.replace(tzinfo=timezone.utc)
|
|
43
|
+
return cls(
|
|
44
|
+
role=str(payload.get("role", "")),
|
|
45
|
+
content=str(payload.get("content", "")),
|
|
46
|
+
timestamp=dt,
|
|
47
|
+
)
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
class BaseMemory(ABC):
|
|
51
|
+
"""Abstract interface for agent memory."""
|
|
52
|
+
|
|
53
|
+
@abstractmethod
|
|
54
|
+
def add_user_message(self, content: str) -> MemoryMessage: ...
|
|
55
|
+
|
|
56
|
+
def add_ai_message(self, content: str) -> MemoryMessage:
|
|
57
|
+
warnings.warn("add_ai_message() is deprecated; use add_agent_message().", DeprecationWarning, stacklevel=2)
|
|
58
|
+
return self.add_agent_message(content)
|
|
59
|
+
|
|
60
|
+
def add_agent_message(self, content: str) -> MemoryMessage:
|
|
61
|
+
if type(self).add_ai_message is not BaseMemory.add_ai_message:
|
|
62
|
+
return self.add_ai_message(content)
|
|
63
|
+
raise NotImplementedError("Subclasses must implement add_agent_message")
|
|
64
|
+
|
|
65
|
+
@abstractmethod
|
|
66
|
+
def add_tool_message(self, tool_name: str, result: str) -> MemoryMessage: ...
|
|
67
|
+
|
|
68
|
+
def get_context(self, query: Optional[str] = None) -> str:
|
|
69
|
+
warnings.warn("get_context() is deprecated; use format_for_llm().", DeprecationWarning, stacklevel=2)
|
|
70
|
+
return self.format_for_llm(query)
|
|
71
|
+
|
|
72
|
+
def format_for_llm(self, query: Optional[str] = None) -> str:
|
|
73
|
+
if type(self).get_context is not BaseMemory.get_context:
|
|
74
|
+
return self.get_context(query)
|
|
75
|
+
raise NotImplementedError("Subclasses must implement format_for_llm")
|
|
76
|
+
|
|
77
|
+
@abstractmethod
|
|
78
|
+
def clear(self) -> None: ...
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
@dataclass
|
|
82
|
+
class Document:
|
|
83
|
+
"""A retrieved document chunk."""
|
|
84
|
+
content: str
|
|
85
|
+
metadata: Dict[str, Any] = field(default_factory=dict)
|
|
86
|
+
score: float = 0.0
|
|
87
|
+
source: str = ""
|
|
88
|
+
|
|
89
|
+
def __str__(self) -> str:
|
|
90
|
+
src = f" (source: {self.source})" if self.source else ""
|
|
91
|
+
return f"{self.content}{src}"
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
class BaseRetriever(ABC):
|
|
95
|
+
"""Abstract retriever interface."""
|
|
96
|
+
|
|
97
|
+
@abstractmethod
|
|
98
|
+
def retrieve(self, query: str, top_k: int = 5) -> List[Document]: ...
|
|
99
|
+
|
|
100
|
+
async def aretrieve(self, query: str, top_k: int = 5) -> List[Document]:
|
|
101
|
+
import asyncio
|
|
102
|
+
return await asyncio.to_thread(self.retrieve, query, top_k)
|
|
File without changes
|
|
@@ -0,0 +1,144 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: autourgos-memory
|
|
3
|
+
Version: 1.0.2
|
|
4
|
+
Summary: Base memory interfaces for Autourgos agents — BaseMemory, MemoryMessage, Document, BaseRetriever.
|
|
5
|
+
Author-email: Jitin Kumar Sengar <devxjitin@gmail.com>
|
|
6
|
+
License: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/devxjitin/autourgos-memory
|
|
8
|
+
Project-URL: Repository, https://github.com/devxjitin/autourgos-memory
|
|
9
|
+
Project-URL: Issues, https://github.com/devxjitin/autourgos-memory/issues
|
|
10
|
+
Keywords: autourgos,agent,memory,llm
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: License :: OSI Approved :: MIT License
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
16
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
17
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
18
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
19
|
+
Requires-Python: >=3.9
|
|
20
|
+
Description-Content-Type: text/markdown
|
|
21
|
+
License-File: LICENSE
|
|
22
|
+
Dynamic: license-file
|
|
23
|
+
|
|
24
|
+
# autourgos-memory
|
|
25
|
+
|
|
26
|
+
Base memory interfaces for [Autourgos](https://github.com/devxjitin) agents.
|
|
27
|
+
|
|
28
|
+
This is the **foundation package** — it defines the abstract interfaces (`BaseMemory`, `BaseRetriever`, `MemoryMessage`, `Document`) that all concrete memory implementations use. Install it on its own, or install one of the concrete packages that depend on it.
|
|
29
|
+
|
|
30
|
+
---
|
|
31
|
+
|
|
32
|
+
## Install
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
# Base interfaces only
|
|
36
|
+
pip install autourgos-memory
|
|
37
|
+
|
|
38
|
+
# Or install concrete implementations individually
|
|
39
|
+
pip install autourgos-buffer-memory # in-memory ring buffer
|
|
40
|
+
pip install autourgos-local-memory # JSON file + SQLite
|
|
41
|
+
pip install autourgos-semantic-memory # TF-IDF keyword retrieval
|
|
42
|
+
pip install autourgos-summary-memory # LLM-compressed rolling summary
|
|
43
|
+
pip install autourgos-token-memory # token-bounded buffer
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
---
|
|
47
|
+
|
|
48
|
+
## Memory types at a glance
|
|
49
|
+
|
|
50
|
+
| Package | Class | Best for |
|
|
51
|
+
|---|---|---|
|
|
52
|
+
| `autourgos-buffer-memory` | `RuntimeShortTermMemory` | Fast in-memory buffer, message-count bounded |
|
|
53
|
+
| `autourgos-buffer-memory` | `ConversationBufferMemory` | Unbounded in-memory buffer |
|
|
54
|
+
| `autourgos-local-memory` | `LocalShortTermMemory` | Disk persistence via JSON file |
|
|
55
|
+
| `autourgos-local-memory` | `SQLiteMemory` | Disk persistence via SQLite, concurrent-safe |
|
|
56
|
+
| `autourgos-semantic-memory` | `KeywordMemory` | TF-IDF retrieval of relevant past context |
|
|
57
|
+
| `autourgos-summary-memory` | `SummaryBufferedMemory` | LLM-compressed history to save tokens |
|
|
58
|
+
| `autourgos-token-memory` | `TokenBufferedMemory` | Token-budget bounded buffer |
|
|
59
|
+
|
|
60
|
+
---
|
|
61
|
+
|
|
62
|
+
## Quick start (with concrete packages installed)
|
|
63
|
+
|
|
64
|
+
`RuntimeShortTermMemory` is soft re-exported from `autourgos_memory` — it only resolves if `autourgos-buffer-memory` is also installed:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
pip install autourgos-memory autourgos-buffer-memory autourgos-openaichat
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
from autourgos_memory import RuntimeShortTermMemory # requires autourgos-buffer-memory installed
|
|
72
|
+
from autourgos_react_agent import ReactAgent
|
|
73
|
+
from autourgos_openaichat import OpenAIChatModel
|
|
74
|
+
|
|
75
|
+
my_llm = OpenAIChatModel(model="gpt-4o-mini") # needs OPENAI_API_KEY set
|
|
76
|
+
memory = RuntimeShortTermMemory(max_messages=20)
|
|
77
|
+
agent = ReactAgent(llm=my_llm, memory=memory)
|
|
78
|
+
result = agent.invoke("What did I ask you last time?")
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
---
|
|
82
|
+
|
|
83
|
+
## Base interfaces
|
|
84
|
+
|
|
85
|
+
### MemoryMessage
|
|
86
|
+
|
|
87
|
+
```python
|
|
88
|
+
from autourgos_memory import MemoryMessage
|
|
89
|
+
from datetime import datetime, timezone
|
|
90
|
+
|
|
91
|
+
msg = MemoryMessage(role="user", content="Hello", timestamp=datetime.now(timezone.utc))
|
|
92
|
+
print(msg.to_dict())
|
|
93
|
+
# {"role": "user", "content": "Hello", "timestamp": "2024-..."}
|
|
94
|
+
```
|
|
95
|
+
|
|
96
|
+
Allowed roles: `user`, `agent`, `system`, `tool`.
|
|
97
|
+
|
|
98
|
+
### BaseMemory
|
|
99
|
+
|
|
100
|
+
Implement this to create your own memory backend:
|
|
101
|
+
|
|
102
|
+
```python
|
|
103
|
+
from autourgos_memory import BaseMemory, MemoryMessage
|
|
104
|
+
|
|
105
|
+
class MyCustomMemory(BaseMemory):
|
|
106
|
+
def add_user_message(self, content: str) -> MemoryMessage: ...
|
|
107
|
+
def add_agent_message(self, content: str) -> MemoryMessage: ...
|
|
108
|
+
def add_tool_message(self, tool_name: str, result: str) -> MemoryMessage: ...
|
|
109
|
+
def format_for_llm(self, query: str = None) -> str: ...
|
|
110
|
+
def clear(self) -> None: ...
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
### BaseRetriever
|
|
114
|
+
|
|
115
|
+
Implement this to plug in your own vector database:
|
|
116
|
+
|
|
117
|
+
```python
|
|
118
|
+
from autourgos_memory import BaseRetriever, Document
|
|
119
|
+
|
|
120
|
+
class MyVectorDB(BaseRetriever):
|
|
121
|
+
def retrieve(self, query: str, top_k: int = 5) -> list[Document]: ...
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
### Document
|
|
125
|
+
|
|
126
|
+
```python
|
|
127
|
+
from autourgos_memory import Document
|
|
128
|
+
|
|
129
|
+
doc = Document(content="Paris is the capital of France.", score=0.92, source="wiki")
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
---
|
|
133
|
+
|
|
134
|
+
## Links
|
|
135
|
+
|
|
136
|
+
- PyPI: https://pypi.org/project/autourgos-memory/
|
|
137
|
+
- GitHub: https://github.com/devxjitin/autourgos-memory
|
|
138
|
+
- Issues: https://github.com/devxjitin/autourgos-memory/issues
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## License
|
|
143
|
+
|
|
144
|
+
MIT — see [LICENSE](LICENSE)
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
autourgos_memory/__init__.py
|
|
5
|
+
autourgos_memory/base.py
|
|
6
|
+
autourgos_memory/py.typed
|
|
7
|
+
autourgos_memory.egg-info/PKG-INFO
|
|
8
|
+
autourgos_memory.egg-info/SOURCES.txt
|
|
9
|
+
autourgos_memory.egg-info/dependency_links.txt
|
|
10
|
+
autourgos_memory.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
autourgos_memory
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68", "wheel"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "autourgos-memory"
|
|
7
|
+
version = "1.0.2"
|
|
8
|
+
description = "Base memory interfaces for Autourgos agents — BaseMemory, MemoryMessage, Document, BaseRetriever."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = {text = "MIT"}
|
|
12
|
+
authors = [
|
|
13
|
+
{name = "Jitin Kumar Sengar", email = "devxjitin@gmail.com"}
|
|
14
|
+
]
|
|
15
|
+
keywords = ["autourgos", "agent", "memory", "llm"]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Development Status :: 4 - Beta",
|
|
18
|
+
"Intended Audience :: Developers",
|
|
19
|
+
"License :: OSI Approved :: MIT License",
|
|
20
|
+
"Programming Language :: Python :: 3",
|
|
21
|
+
"Programming Language :: Python :: 3.9",
|
|
22
|
+
"Programming Language :: Python :: 3.10",
|
|
23
|
+
"Programming Language :: Python :: 3.11",
|
|
24
|
+
"Programming Language :: Python :: 3.12",
|
|
25
|
+
]
|
|
26
|
+
dependencies = []
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
[project.urls]
|
|
30
|
+
Homepage = "https://github.com/devxjitin/autourgos-memory"
|
|
31
|
+
Repository = "https://github.com/devxjitin/autourgos-memory"
|
|
32
|
+
Issues = "https://github.com/devxjitin/autourgos-memory/issues"
|
|
33
|
+
|
|
34
|
+
[tool.setuptools.packages.find]
|
|
35
|
+
where = ["."]
|
|
36
|
+
include = ["autourgos_memory*"]
|
|
37
|
+
|
|
38
|
+
[tool.setuptools.package-data]
|
|
39
|
+
autourgos_memory = ["py.typed"]
|