autourgos-buffer-memory 1.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.
@@ -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,115 @@
1
+ Metadata-Version: 2.4
2
+ Name: autourgos-buffer-memory
3
+ Version: 1.0.0
4
+ Summary: In-memory short-term buffer for Autourgos agents — RuntimeShortTermMemory, ConversationBufferMemory.
5
+ Author-email: Jitin Kumar Sengar <devxjitin@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/devxjitin/autourgos-buffer-memory
8
+ Project-URL: Repository, https://github.com/devxjitin/autourgos-buffer-memory
9
+ Project-URL: Issues, https://github.com/devxjitin/autourgos-buffer-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-buffer-memory
25
+
26
+ In-memory short-term buffer for [Autourgos](https://github.com/devxjitin) agents.
27
+
28
+ Two classes — a message-count bounded ring buffer and an unbounded conversation buffer. Fast, zero I/O, ideal for single-session use.
29
+
30
+ ---
31
+
32
+ ## Install
33
+
34
+ ```bash
35
+ pip install autourgos-buffer-memory
36
+ ```
37
+
38
+ ---
39
+
40
+ ## Classes
41
+
42
+ ### RuntimeShortTermMemory
43
+
44
+ Keeps the last N messages in RAM. Oldest messages are dropped when the cap is exceeded.
45
+
46
+ ```python
47
+ from autourgos_buffer_memory import RuntimeShortTermMemory
48
+ from autourgos_react_agent import ReactAgent
49
+
50
+ memory = RuntimeShortTermMemory(max_messages=20)
51
+ agent = ReactAgent(llm=my_llm, memory=memory)
52
+
53
+ agent.invoke("My name is Jitin")
54
+ agent.invoke("What is my name?")
55
+ # → "Your name is Jitin."
56
+ ```
57
+
58
+ ### ConversationBufferMemory
59
+
60
+ Same as `RuntimeShortTermMemory` but with no truncation — keeps every message for the session.
61
+
62
+ ```python
63
+ from autourgos_buffer_memory import ConversationBufferMemory
64
+
65
+ memory = ConversationBufferMemory()
66
+ agent = ReactAgent(llm=my_llm, memory=memory)
67
+ ```
68
+
69
+ > For long conversations, use `autourgos-summary-memory` or `autourgos-token-memory` to stay within context window limits.
70
+
71
+ ---
72
+
73
+ ## Parameters
74
+
75
+ ### RuntimeShortTermMemory
76
+
77
+ | Parameter | Type | Default | Description |
78
+ |---|---|---|---|
79
+ | `max_messages` | int | `20` | Max messages kept. Oldest dropped when exceeded. |
80
+ | `name` | str | `"runtime"` | Human-readable identifier. |
81
+
82
+ ### ConversationBufferMemory
83
+
84
+ | Parameter | Type | Default | Description |
85
+ |---|---|---|---|
86
+ | `name` | str | `"conversation"` | Human-readable identifier. |
87
+
88
+ ---
89
+
90
+ ## API
91
+
92
+ ```python
93
+ memory.add_user_message("Hello")
94
+ memory.add_agent_message("Hi there!")
95
+ memory.add_tool_message("search", "Found 5 results")
96
+ memory.add_system_message("You are a helpful assistant")
97
+
98
+ messages = memory.get_messages() # list of role/content dicts
99
+ context = memory.format_for_llm() # formatted string for LLM prompt
100
+ memory.clear()
101
+ ```
102
+
103
+ ---
104
+
105
+ ## Links
106
+
107
+ - PyPI: https://pypi.org/project/autourgos-buffer-memory/
108
+ - GitHub: https://github.com/devxjitin/autourgos-buffer-memory
109
+ - Issues: https://github.com/devxjitin/autourgos-buffer-memory/issues
110
+
111
+ ---
112
+
113
+ ## License
114
+
115
+ MIT — see [LICENSE](LICENSE)
@@ -0,0 +1,92 @@
1
+ # autourgos-buffer-memory
2
+
3
+ In-memory short-term buffer for [Autourgos](https://github.com/devxjitin) agents.
4
+
5
+ Two classes — a message-count bounded ring buffer and an unbounded conversation buffer. Fast, zero I/O, ideal for single-session use.
6
+
7
+ ---
8
+
9
+ ## Install
10
+
11
+ ```bash
12
+ pip install autourgos-buffer-memory
13
+ ```
14
+
15
+ ---
16
+
17
+ ## Classes
18
+
19
+ ### RuntimeShortTermMemory
20
+
21
+ Keeps the last N messages in RAM. Oldest messages are dropped when the cap is exceeded.
22
+
23
+ ```python
24
+ from autourgos_buffer_memory import RuntimeShortTermMemory
25
+ from autourgos_react_agent import ReactAgent
26
+
27
+ memory = RuntimeShortTermMemory(max_messages=20)
28
+ agent = ReactAgent(llm=my_llm, memory=memory)
29
+
30
+ agent.invoke("My name is Jitin")
31
+ agent.invoke("What is my name?")
32
+ # → "Your name is Jitin."
33
+ ```
34
+
35
+ ### ConversationBufferMemory
36
+
37
+ Same as `RuntimeShortTermMemory` but with no truncation — keeps every message for the session.
38
+
39
+ ```python
40
+ from autourgos_buffer_memory import ConversationBufferMemory
41
+
42
+ memory = ConversationBufferMemory()
43
+ agent = ReactAgent(llm=my_llm, memory=memory)
44
+ ```
45
+
46
+ > For long conversations, use `autourgos-summary-memory` or `autourgos-token-memory` to stay within context window limits.
47
+
48
+ ---
49
+
50
+ ## Parameters
51
+
52
+ ### RuntimeShortTermMemory
53
+
54
+ | Parameter | Type | Default | Description |
55
+ |---|---|---|---|
56
+ | `max_messages` | int | `20` | Max messages kept. Oldest dropped when exceeded. |
57
+ | `name` | str | `"runtime"` | Human-readable identifier. |
58
+
59
+ ### ConversationBufferMemory
60
+
61
+ | Parameter | Type | Default | Description |
62
+ |---|---|---|---|
63
+ | `name` | str | `"conversation"` | Human-readable identifier. |
64
+
65
+ ---
66
+
67
+ ## API
68
+
69
+ ```python
70
+ memory.add_user_message("Hello")
71
+ memory.add_agent_message("Hi there!")
72
+ memory.add_tool_message("search", "Found 5 results")
73
+ memory.add_system_message("You are a helpful assistant")
74
+
75
+ messages = memory.get_messages() # list of role/content dicts
76
+ context = memory.format_for_llm() # formatted string for LLM prompt
77
+ memory.clear()
78
+ ```
79
+
80
+ ---
81
+
82
+ ## Links
83
+
84
+ - PyPI: https://pypi.org/project/autourgos-buffer-memory/
85
+ - GitHub: https://github.com/devxjitin/autourgos-buffer-memory
86
+ - Issues: https://github.com/devxjitin/autourgos-buffer-memory/issues
87
+
88
+ ---
89
+
90
+ ## License
91
+
92
+ MIT — see [LICENSE](LICENSE)
@@ -0,0 +1,14 @@
1
+ """
2
+ autourgos-buffer-memory — In-memory short-term buffers for Autourgos agents.
3
+
4
+ from autourgos_buffer_memory import RuntimeShortTermMemory, ConversationBufferMemory
5
+ """
6
+ from .memory import RuntimeShortTermMemory, ConversationBufferMemory
7
+
8
+ try:
9
+ from importlib.metadata import version as _v
10
+ __version__ = _v("autourgos-buffer-memory")
11
+ except Exception:
12
+ __version__ = "1.0.2"
13
+
14
+ __all__ = ["RuntimeShortTermMemory", "ConversationBufferMemory"]
@@ -0,0 +1,101 @@
1
+ """
2
+ base.py — Self-contained base classes. No external dependencies.
3
+ """
4
+ from __future__ import annotations
5
+
6
+ import warnings
7
+ from abc import ABC, abstractmethod
8
+ from dataclasses import dataclass, field
9
+ from datetime import datetime, timezone
10
+ from typing import Any, Dict, List, Optional
11
+
12
+ _ALLOWED_ROLES = {"user", "agent", "system", "tool"}
13
+
14
+
15
+ @dataclass(frozen=True)
16
+ class MemoryMessage:
17
+ """A single message in memory."""
18
+ role: str
19
+ content: str
20
+ timestamp: datetime
21
+
22
+ def __post_init__(self) -> None:
23
+ if self.role not in _ALLOWED_ROLES:
24
+ raise ValueError(f"Invalid role {self.role!r}. Allowed: {sorted(_ALLOWED_ROLES)}")
25
+ if not isinstance(self.content, str):
26
+ raise ValueError("content must be a string")
27
+ if not isinstance(self.timestamp, datetime):
28
+ raise ValueError("timestamp must be a datetime")
29
+
30
+ def to_dict(self) -> Dict[str, str]:
31
+ return {
32
+ "role": self.role,
33
+ "content": self.content,
34
+ "timestamp": self.timestamp.astimezone(timezone.utc).isoformat(),
35
+ }
36
+
37
+ @classmethod
38
+ def from_dict(cls, payload: Dict[str, Any]) -> "MemoryMessage":
39
+ ts = payload.get("timestamp")
40
+ if not isinstance(ts, str):
41
+ raise ValueError("timestamp must be a string")
42
+ dt = datetime.fromisoformat(ts)
43
+ if dt.tzinfo is None:
44
+ dt = dt.replace(tzinfo=timezone.utc)
45
+ return cls(role=str(payload.get("role", "")), content=str(payload.get("content", "")), timestamp=dt)
46
+
47
+
48
+ class BaseMemory(ABC):
49
+ """Abstract interface for agent memory."""
50
+
51
+ @abstractmethod
52
+ def add_user_message(self, content: str) -> MemoryMessage: ...
53
+
54
+ def add_ai_message(self, content: str) -> MemoryMessage:
55
+ warnings.warn("add_ai_message() is deprecated; use add_agent_message().", DeprecationWarning, stacklevel=2)
56
+ return self.add_agent_message(content)
57
+
58
+ def add_agent_message(self, content: str) -> MemoryMessage:
59
+ if type(self).add_ai_message is not BaseMemory.add_ai_message:
60
+ return self.add_ai_message(content)
61
+ raise NotImplementedError("Subclasses must implement add_agent_message")
62
+
63
+ @abstractmethod
64
+ def add_tool_message(self, tool_name: str, result: str) -> MemoryMessage: ...
65
+
66
+ def get_context(self, query: Optional[str] = None) -> str:
67
+ warnings.warn("get_context() is deprecated; use format_for_llm().", DeprecationWarning, stacklevel=2)
68
+ return self.format_for_llm(query)
69
+
70
+ def format_for_llm(self, query: Optional[str] = None) -> str:
71
+ if type(self).get_context is not BaseMemory.get_context:
72
+ return self.get_context(query)
73
+ raise NotImplementedError("Subclasses must implement format_for_llm")
74
+
75
+ @abstractmethod
76
+ def clear(self) -> None: ...
77
+
78
+
79
+ @dataclass
80
+ class Document:
81
+ """A retrieved document chunk."""
82
+ content: str
83
+ metadata: Dict[str, Any] = field(default_factory=dict)
84
+ score: float = 0.0
85
+ source: str = ""
86
+
87
+ def __str__(self) -> str:
88
+ src = f" (source: {self.source})" if self.source else ""
89
+ return f"{self.content}{src}"
90
+
91
+
92
+ class BaseRetriever(ABC):
93
+ """Abstract retriever interface."""
94
+
95
+ @abstractmethod
96
+ def retrieve(self, query: str, top_k: int = 5) -> List[Document]: ...
97
+
98
+ async def aretrieve(self, query: str, top_k: int = 5) -> List[Document]:
99
+ import asyncio
100
+ return await asyncio.to_thread(self.retrieve, query, top_k)
101
+
@@ -0,0 +1,72 @@
1
+ """
2
+ memory.py — In-memory short-term buffers.
3
+ """
4
+ from __future__ import annotations
5
+ import sys
6
+ from datetime import datetime, timezone
7
+ from typing import Dict, List, Optional
8
+
9
+ from .base import BaseMemory, MemoryMessage
10
+
11
+
12
+ class RuntimeShortTermMemory(BaseMemory):
13
+ """In-memory ring buffer bounded by message count.
14
+
15
+ Parameters
16
+ ----------
17
+ max_messages : int
18
+ Maximum messages kept. Oldest are dropped when exceeded. Default 20.
19
+ name : str
20
+ Human-readable identifier.
21
+ """
22
+
23
+ def __init__(self, max_messages: int = 20, name: str = "runtime") -> None:
24
+ if not isinstance(max_messages, int) or max_messages < 1:
25
+ raise ValueError("max_messages must be an integer >= 1")
26
+ self.max_messages = max_messages
27
+ self.name = name
28
+ self._messages: List[MemoryMessage] = []
29
+
30
+ def add_message(self, role: str, content: str, timestamp: Optional[datetime] = None) -> MemoryMessage:
31
+ msg = MemoryMessage(role=role, content=content, timestamp=timestamp or datetime.now(timezone.utc))
32
+ self._messages.append(msg)
33
+ if len(self._messages) > self.max_messages:
34
+ self._messages = self._messages[-self.max_messages:]
35
+ return msg
36
+
37
+ def add_user_message(self, content: str) -> MemoryMessage:
38
+ return self.add_message("user", content)
39
+
40
+ def add_agent_message(self, content: str) -> MemoryMessage:
41
+ return self.add_message("agent", content)
42
+
43
+ def add_system_message(self, content: str) -> MemoryMessage:
44
+ return self.add_message("system", content)
45
+
46
+ def add_tool_message(self, tool_name: str, result: str) -> MemoryMessage:
47
+ return self.add_message("tool", f"[{tool_name} returned]: {result}")
48
+
49
+ def get_messages(self) -> List[Dict[str, str]]:
50
+ _ROLE = {"user": "user", "agent": "assistant", "system": "system", "tool": "tool"}
51
+ return [{"role": _ROLE.get(m.role, m.role), "content": m.content} for m in self._messages]
52
+
53
+ def clear(self) -> None:
54
+ self._messages = []
55
+
56
+ def format_for_llm(self, query: Optional[str] = None) -> str:
57
+ if not self._messages:
58
+ return ""
59
+ lines = "\n".join(f"{m.role}: {m.content}" for m in self._messages)
60
+ return f"\n--- Previous Conversation Context ---\n{lines}\n--------------------------------------\n"
61
+
62
+
63
+ class ConversationBufferMemory(RuntimeShortTermMemory):
64
+ """Unbounded in-memory conversation buffer (no truncation).
65
+
66
+ Use this when you want to keep every message in RAM for the session.
67
+ For long conversations, prefer :class:`RuntimeShortTermMemory` with a cap,
68
+ or :class:`~autourgos_summary_memory.SummaryBufferedMemory` for LLM compression.
69
+ """
70
+
71
+ def __init__(self, name: str = "conversation") -> None:
72
+ super().__init__(max_messages=sys.maxsize, name=name)
@@ -0,0 +1,115 @@
1
+ Metadata-Version: 2.4
2
+ Name: autourgos-buffer-memory
3
+ Version: 1.0.0
4
+ Summary: In-memory short-term buffer for Autourgos agents — RuntimeShortTermMemory, ConversationBufferMemory.
5
+ Author-email: Jitin Kumar Sengar <devxjitin@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/devxjitin/autourgos-buffer-memory
8
+ Project-URL: Repository, https://github.com/devxjitin/autourgos-buffer-memory
9
+ Project-URL: Issues, https://github.com/devxjitin/autourgos-buffer-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-buffer-memory
25
+
26
+ In-memory short-term buffer for [Autourgos](https://github.com/devxjitin) agents.
27
+
28
+ Two classes — a message-count bounded ring buffer and an unbounded conversation buffer. Fast, zero I/O, ideal for single-session use.
29
+
30
+ ---
31
+
32
+ ## Install
33
+
34
+ ```bash
35
+ pip install autourgos-buffer-memory
36
+ ```
37
+
38
+ ---
39
+
40
+ ## Classes
41
+
42
+ ### RuntimeShortTermMemory
43
+
44
+ Keeps the last N messages in RAM. Oldest messages are dropped when the cap is exceeded.
45
+
46
+ ```python
47
+ from autourgos_buffer_memory import RuntimeShortTermMemory
48
+ from autourgos_react_agent import ReactAgent
49
+
50
+ memory = RuntimeShortTermMemory(max_messages=20)
51
+ agent = ReactAgent(llm=my_llm, memory=memory)
52
+
53
+ agent.invoke("My name is Jitin")
54
+ agent.invoke("What is my name?")
55
+ # → "Your name is Jitin."
56
+ ```
57
+
58
+ ### ConversationBufferMemory
59
+
60
+ Same as `RuntimeShortTermMemory` but with no truncation — keeps every message for the session.
61
+
62
+ ```python
63
+ from autourgos_buffer_memory import ConversationBufferMemory
64
+
65
+ memory = ConversationBufferMemory()
66
+ agent = ReactAgent(llm=my_llm, memory=memory)
67
+ ```
68
+
69
+ > For long conversations, use `autourgos-summary-memory` or `autourgos-token-memory` to stay within context window limits.
70
+
71
+ ---
72
+
73
+ ## Parameters
74
+
75
+ ### RuntimeShortTermMemory
76
+
77
+ | Parameter | Type | Default | Description |
78
+ |---|---|---|---|
79
+ | `max_messages` | int | `20` | Max messages kept. Oldest dropped when exceeded. |
80
+ | `name` | str | `"runtime"` | Human-readable identifier. |
81
+
82
+ ### ConversationBufferMemory
83
+
84
+ | Parameter | Type | Default | Description |
85
+ |---|---|---|---|
86
+ | `name` | str | `"conversation"` | Human-readable identifier. |
87
+
88
+ ---
89
+
90
+ ## API
91
+
92
+ ```python
93
+ memory.add_user_message("Hello")
94
+ memory.add_agent_message("Hi there!")
95
+ memory.add_tool_message("search", "Found 5 results")
96
+ memory.add_system_message("You are a helpful assistant")
97
+
98
+ messages = memory.get_messages() # list of role/content dicts
99
+ context = memory.format_for_llm() # formatted string for LLM prompt
100
+ memory.clear()
101
+ ```
102
+
103
+ ---
104
+
105
+ ## Links
106
+
107
+ - PyPI: https://pypi.org/project/autourgos-buffer-memory/
108
+ - GitHub: https://github.com/devxjitin/autourgos-buffer-memory
109
+ - Issues: https://github.com/devxjitin/autourgos-buffer-memory/issues
110
+
111
+ ---
112
+
113
+ ## License
114
+
115
+ MIT — see [LICENSE](LICENSE)
@@ -0,0 +1,11 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ autourgos_buffer_memory/__init__.py
5
+ autourgos_buffer_memory/base.py
6
+ autourgos_buffer_memory/memory.py
7
+ autourgos_buffer_memory/py.typed
8
+ autourgos_buffer_memory.egg-info/PKG-INFO
9
+ autourgos_buffer_memory.egg-info/SOURCES.txt
10
+ autourgos_buffer_memory.egg-info/dependency_links.txt
11
+ autourgos_buffer_memory.egg-info/top_level.txt
@@ -0,0 +1 @@
1
+ autourgos_buffer_memory
@@ -0,0 +1,38 @@
1
+ [build-system]
2
+ requires = ["setuptools>=68", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "autourgos-buffer-memory"
7
+ version = "1.0.0"
8
+ description = "In-memory short-term buffer for Autourgos agents — RuntimeShortTermMemory, ConversationBufferMemory."
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
+ [project.urls]
29
+ Homepage = "https://github.com/devxjitin/autourgos-buffer-memory"
30
+ Repository = "https://github.com/devxjitin/autourgos-buffer-memory"
31
+ Issues = "https://github.com/devxjitin/autourgos-buffer-memory/issues"
32
+
33
+ [tool.setuptools.packages.find]
34
+ where = ["."]
35
+ include = ["autourgos_buffer_memory*"]
36
+
37
+ [tool.setuptools.package-data]
38
+ autourgos_buffer_memory = ["py.typed"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+