nexusagent-runtime 1.2.0__tar.gz → 1.3.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.
- {nexusagent_runtime-1.2.0/src/nexusagent_runtime.egg-info → nexusagent_runtime-1.3.0}/PKG-INFO +35 -3
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/README.md +34 -2
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/src/nexusagent/__init__.py +4 -2
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/src/nexusagent/memory.py +106 -4
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0/src/nexusagent_runtime.egg-info}/PKG-INFO +35 -3
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/src/nexusagent_runtime.egg-info/SOURCES.txt +1 -0
- nexusagent_runtime-1.3.0/tests/test_memory_sqlite.py +325 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/tests/test_public_api.py +2 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/LICENSE +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/pyproject.toml +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/setup.cfg +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/src/nexusagent/__main__.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/src/nexusagent/agent.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/src/nexusagent/anthropic_provider.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/src/nexusagent/application.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/src/nexusagent/async_agent.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/src/nexusagent/async_provider.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/src/nexusagent/async_runtime.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/src/nexusagent/async_tool_executor.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/src/nexusagent/calculator_tool.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/src/nexusagent/config.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/src/nexusagent/echo_tool.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/src/nexusagent/factory.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/src/nexusagent/gemini_provider.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/src/nexusagent/http_provider.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/src/nexusagent/logging.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/src/nexusagent/main.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/src/nexusagent/openai_provider.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/src/nexusagent/provider.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/src/nexusagent/providers.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/src/nexusagent/py.typed +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/src/nexusagent/runtime.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/src/nexusagent/runtime_factory.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/src/nexusagent/tool.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/src/nexusagent/tool_executor.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/src/nexusagent/tool_factory.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/src/nexusagent/tool_registry.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/src/nexusagent/uppercase_tool.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/src/nexusagent_runtime.egg-info/dependency_links.txt +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/src/nexusagent_runtime.egg-info/entry_points.txt +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/src/nexusagent_runtime.egg-info/requires.txt +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/src/nexusagent_runtime.egg-info/top_level.txt +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/tests/test_agent.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/tests/test_anthropic_provider.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/tests/test_application.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/tests/test_architecture.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/tests/test_async_agent.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/tests/test_async_provider.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/tests/test_async_runtime.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/tests/test_async_tool_executor.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/tests/test_calculator_tool.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/tests/test_config.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/tests/test_echo_tool.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/tests/test_factory.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/tests/test_gemini_provider.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/tests/test_http_provider.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/tests/test_http_provider_tools.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/tests/test_http_retries.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/tests/test_http_tool_loop_integration.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/tests/test_init.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/tests/test_logging.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/tests/test_main.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/tests/test_memory.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/tests/test_openai_provider.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/tests/test_provider.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/tests/test_providers.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/tests/test_runtime.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/tests/test_runtime_factory.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/tests/test_sse_transport.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/tests/test_streaming_agent.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/tests/test_streaming_anthropic.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/tests/test_streaming_async.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/tests/test_streaming_cli.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/tests/test_streaming_gemini.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/tests/test_streaming_openai.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/tests/test_tool.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/tests/test_tool_executor.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/tests/test_tool_factory.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/tests/test_tool_loop.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/tests/test_tool_registry.py +0 -0
- {nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/tests/test_uppercase_tool.py +0 -0
{nexusagent_runtime-1.2.0/src/nexusagent_runtime.egg-info → nexusagent_runtime-1.3.0}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: nexusagent-runtime
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.3.0
|
|
4
4
|
Summary: A small, modular AI agent runtime in Python — agents, providers, tools and a readable core.
|
|
5
5
|
License-Expression: MIT
|
|
6
6
|
Project-URL: Homepage, https://github.com/Abolfazlrwm/nexusagent
|
|
@@ -59,12 +59,12 @@ print(runtime.execute_tool("calculator", "2 + 3")) # 5
|
|
|
59
59
|
|
|
60
60
|
- **Zero runtime dependencies** — the whole core is the Python standard library. `pip install nexusagent-runtime` pulls nothing else.
|
|
61
61
|
- **Automatic retries** — transient HTTP failures (connection errors, timeouts, 429/5xx) are retried with exponential backoff, full jitter and `Retry-After` support. See [ADR 0011](docs/adr/0011-http-retry-backoff.md).
|
|
62
|
-
- **Conversation memory** — opt-in
|
|
62
|
+
- **Conversation memory** — opt-in memory composes remembered turns into each run's prompt, so the agent carries context across runs with any provider — in-process (`InMemoryMemory`) or persisted to a local SQLite file (`SQLiteMemory`). See [ADR 0012](docs/adr/0012-conversation-memory.md) and [ADR 0013](docs/adr/0013-sqlite-memory.md).
|
|
63
63
|
- **Stable public API** — 1.0 declares SemVer stability over the full root surface; a CI-pinned test fails on any accidental removal, rename or silent addition. See [ADR 0010](docs/adr/0010-1.0-api-stability-and-versioning-policy.md).
|
|
64
64
|
- **Readable by design** — the core is small enough to audit in an afternoon; architecture rules are enforced by tests, not comments.
|
|
65
65
|
- **Honest** — the feature list below says what exists *and what doesn't*. No fake benchmarks, no aspirational docs.
|
|
66
66
|
- **Typed** — ships `py.typed`; the source itself passes `mypy --strict`.
|
|
67
|
-
- **Tested** —
|
|
67
|
+
- **Tested** — 1200+ contract tests, ≥95% coverage floor enforced in CI.
|
|
68
68
|
|
|
69
69
|
## Features
|
|
70
70
|
|
|
@@ -86,6 +86,7 @@ print(runtime.execute_tool("calculator", "2 + 3")) # 5
|
|
|
86
86
|
| Streaming responses (SSE, all HTTP adapters, sync + async) | ✅ [ADR 0009](docs/adr/0009-streaming-responses.md) |
|
|
87
87
|
| Retries / backoff on HTTP failures (429/5xx, jitter, `Retry-After`) | ✅ [ADR 0011](docs/adr/0011-http-retry-backoff.md) |
|
|
88
88
|
| Conversation memory (opt-in, in-process, provider-agnostic) | ✅ [ADR 0012](docs/adr/0012-conversation-memory.md) |
|
|
89
|
+
| Persistent conversation memory (local SQLite file, same contract) | ✅ [ADR 0013](docs/adr/0013-sqlite-memory.md) |
|
|
89
90
|
| Planning, multi-agent orchestration | ❌ |
|
|
90
91
|
|
|
91
92
|
## Architecture
|
|
@@ -306,6 +307,36 @@ Failed runs record nothing, and a memory with no history composes the
|
|
|
306
307
|
prompt byte-for-byte like the no-memory path. Design details:
|
|
307
308
|
[ADR 0012](docs/adr/0012-conversation-memory.md).
|
|
308
309
|
|
|
310
|
+
#### Persistent memory (SQLite)
|
|
311
|
+
|
|
312
|
+
`InMemoryMemory` lives in the process and is gone when it ends. To keep
|
|
313
|
+
history across restarts, hand the runtime a `SQLiteMemory`: turns live in
|
|
314
|
+
a local SQLite database file (`sqlite3` is in the standard library, so
|
|
315
|
+
still zero dependencies), the bounded-FIFO semantics and `max_turns` cap
|
|
316
|
+
match the in-process backend, and the oldest rows are evicted the same
|
|
317
|
+
way — the eviction itself is persisted.
|
|
318
|
+
|
|
319
|
+
```python
|
|
320
|
+
from nexusagent import SQLiteMemory, create_runtime
|
|
321
|
+
|
|
322
|
+
memory = SQLiteMemory("session.db", max_turns=50) # created on first use
|
|
323
|
+
runtime = create_runtime(memory=memory)
|
|
324
|
+
|
|
325
|
+
runtime.run("My name is Sara")
|
|
326
|
+
memory.close()
|
|
327
|
+
|
|
328
|
+
# A later process reopens the same file and remembers:
|
|
329
|
+
memory = SQLiteMemory("session.db", max_turns=50)
|
|
330
|
+
runtime = create_runtime(memory=memory)
|
|
331
|
+
print(runtime.run("What is my name?").output) # the model still knows
|
|
332
|
+
memory.close()
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
Every mutation commits immediately; `close()` (or using the instance as a
|
|
336
|
+
context manager) releases the database connection, and runtimes that open
|
|
337
|
+
the same file one after another see the same turns. Design details:
|
|
338
|
+
[ADR 0013](docs/adr/0013-sqlite-memory.md).
|
|
339
|
+
|
|
309
340
|
### Async runtime
|
|
310
341
|
|
|
311
342
|
The async layer mirrors the sync contracts one-to-one — `await runtime.run(...)`,
|
|
@@ -360,6 +391,7 @@ All examples run offline, with no API keys:
|
|
|
360
391
|
- [`examples/tool_loop_demo.py`](examples/tool_loop_demo.py) — the autonomous tool loop over local HTTP
|
|
361
392
|
- [`examples/streaming.py`](examples/streaming.py) — streamed text through `on_delta`, offline
|
|
362
393
|
- [`examples/memory.py`](examples/memory.py) — conversation memory across runs, offline
|
|
394
|
+
- [`examples/sqlite_memory.py`](examples/sqlite_memory.py) — persistent SQLite memory across restarts, offline
|
|
363
395
|
- [`examples/async_tool_loop.py`](examples/async_tool_loop.py) — the async tool loop with an awaited tool
|
|
364
396
|
- [`examples/http_provider_local.py`](examples/http_provider_local.py) — `http` provider against a local backend
|
|
365
397
|
|
|
@@ -26,12 +26,12 @@ print(runtime.execute_tool("calculator", "2 + 3")) # 5
|
|
|
26
26
|
|
|
27
27
|
- **Zero runtime dependencies** — the whole core is the Python standard library. `pip install nexusagent-runtime` pulls nothing else.
|
|
28
28
|
- **Automatic retries** — transient HTTP failures (connection errors, timeouts, 429/5xx) are retried with exponential backoff, full jitter and `Retry-After` support. See [ADR 0011](docs/adr/0011-http-retry-backoff.md).
|
|
29
|
-
- **Conversation memory** — opt-in
|
|
29
|
+
- **Conversation memory** — opt-in memory composes remembered turns into each run's prompt, so the agent carries context across runs with any provider — in-process (`InMemoryMemory`) or persisted to a local SQLite file (`SQLiteMemory`). See [ADR 0012](docs/adr/0012-conversation-memory.md) and [ADR 0013](docs/adr/0013-sqlite-memory.md).
|
|
30
30
|
- **Stable public API** — 1.0 declares SemVer stability over the full root surface; a CI-pinned test fails on any accidental removal, rename or silent addition. See [ADR 0010](docs/adr/0010-1.0-api-stability-and-versioning-policy.md).
|
|
31
31
|
- **Readable by design** — the core is small enough to audit in an afternoon; architecture rules are enforced by tests, not comments.
|
|
32
32
|
- **Honest** — the feature list below says what exists *and what doesn't*. No fake benchmarks, no aspirational docs.
|
|
33
33
|
- **Typed** — ships `py.typed`; the source itself passes `mypy --strict`.
|
|
34
|
-
- **Tested** —
|
|
34
|
+
- **Tested** — 1200+ contract tests, ≥95% coverage floor enforced in CI.
|
|
35
35
|
|
|
36
36
|
## Features
|
|
37
37
|
|
|
@@ -53,6 +53,7 @@ print(runtime.execute_tool("calculator", "2 + 3")) # 5
|
|
|
53
53
|
| Streaming responses (SSE, all HTTP adapters, sync + async) | ✅ [ADR 0009](docs/adr/0009-streaming-responses.md) |
|
|
54
54
|
| Retries / backoff on HTTP failures (429/5xx, jitter, `Retry-After`) | ✅ [ADR 0011](docs/adr/0011-http-retry-backoff.md) |
|
|
55
55
|
| Conversation memory (opt-in, in-process, provider-agnostic) | ✅ [ADR 0012](docs/adr/0012-conversation-memory.md) |
|
|
56
|
+
| Persistent conversation memory (local SQLite file, same contract) | ✅ [ADR 0013](docs/adr/0013-sqlite-memory.md) |
|
|
56
57
|
| Planning, multi-agent orchestration | ❌ |
|
|
57
58
|
|
|
58
59
|
## Architecture
|
|
@@ -273,6 +274,36 @@ Failed runs record nothing, and a memory with no history composes the
|
|
|
273
274
|
prompt byte-for-byte like the no-memory path. Design details:
|
|
274
275
|
[ADR 0012](docs/adr/0012-conversation-memory.md).
|
|
275
276
|
|
|
277
|
+
#### Persistent memory (SQLite)
|
|
278
|
+
|
|
279
|
+
`InMemoryMemory` lives in the process and is gone when it ends. To keep
|
|
280
|
+
history across restarts, hand the runtime a `SQLiteMemory`: turns live in
|
|
281
|
+
a local SQLite database file (`sqlite3` is in the standard library, so
|
|
282
|
+
still zero dependencies), the bounded-FIFO semantics and `max_turns` cap
|
|
283
|
+
match the in-process backend, and the oldest rows are evicted the same
|
|
284
|
+
way — the eviction itself is persisted.
|
|
285
|
+
|
|
286
|
+
```python
|
|
287
|
+
from nexusagent import SQLiteMemory, create_runtime
|
|
288
|
+
|
|
289
|
+
memory = SQLiteMemory("session.db", max_turns=50) # created on first use
|
|
290
|
+
runtime = create_runtime(memory=memory)
|
|
291
|
+
|
|
292
|
+
runtime.run("My name is Sara")
|
|
293
|
+
memory.close()
|
|
294
|
+
|
|
295
|
+
# A later process reopens the same file and remembers:
|
|
296
|
+
memory = SQLiteMemory("session.db", max_turns=50)
|
|
297
|
+
runtime = create_runtime(memory=memory)
|
|
298
|
+
print(runtime.run("What is my name?").output) # the model still knows
|
|
299
|
+
memory.close()
|
|
300
|
+
```
|
|
301
|
+
|
|
302
|
+
Every mutation commits immediately; `close()` (or using the instance as a
|
|
303
|
+
context manager) releases the database connection, and runtimes that open
|
|
304
|
+
the same file one after another see the same turns. Design details:
|
|
305
|
+
[ADR 0013](docs/adr/0013-sqlite-memory.md).
|
|
306
|
+
|
|
276
307
|
### Async runtime
|
|
277
308
|
|
|
278
309
|
The async layer mirrors the sync contracts one-to-one — `await runtime.run(...)`,
|
|
@@ -327,6 +358,7 @@ All examples run offline, with no API keys:
|
|
|
327
358
|
- [`examples/tool_loop_demo.py`](examples/tool_loop_demo.py) — the autonomous tool loop over local HTTP
|
|
328
359
|
- [`examples/streaming.py`](examples/streaming.py) — streamed text through `on_delta`, offline
|
|
329
360
|
- [`examples/memory.py`](examples/memory.py) — conversation memory across runs, offline
|
|
361
|
+
- [`examples/sqlite_memory.py`](examples/sqlite_memory.py) — persistent SQLite memory across restarts, offline
|
|
330
362
|
- [`examples/async_tool_loop.py`](examples/async_tool_loop.py) — the async tool loop with an awaited tool
|
|
331
363
|
- [`examples/http_provider_local.py`](examples/http_provider_local.py) — `http` provider against a local backend
|
|
332
364
|
|
|
@@ -21,7 +21,7 @@ from nexusagent.async_runtime import AsyncRuntime, create_async_runtime
|
|
|
21
21
|
from nexusagent.async_tool_executor import AsyncToolExecutor
|
|
22
22
|
from nexusagent.config import Settings
|
|
23
23
|
from nexusagent.factory import create_provider
|
|
24
|
-
from nexusagent.memory import ConversationTurn, InMemoryMemory, Memory
|
|
24
|
+
from nexusagent.memory import ConversationTurn, InMemoryMemory, Memory, SQLiteMemory
|
|
25
25
|
from nexusagent.provider import (
|
|
26
26
|
AsyncProvider,
|
|
27
27
|
Provider,
|
|
@@ -44,7 +44,7 @@ from nexusagent.tool import AsyncTool, Tool
|
|
|
44
44
|
from nexusagent.tool_executor import ToolExecutionError, ToolExecutor
|
|
45
45
|
from nexusagent.tool_registry import ToolRegistry
|
|
46
46
|
|
|
47
|
-
__version__ = "1.
|
|
47
|
+
__version__ = "1.3.0"
|
|
48
48
|
|
|
49
49
|
__all__ = [
|
|
50
50
|
# Agent layer (sync and async)
|
|
@@ -72,6 +72,8 @@ __all__ = [
|
|
|
72
72
|
"ProviderResponseError",
|
|
73
73
|
"ProviderStreamEvent",
|
|
74
74
|
"Runtime",
|
|
75
|
+
# Persistent conversation memory (ADR 0013)
|
|
76
|
+
"SQLiteMemory",
|
|
75
77
|
"ScriptedProvider",
|
|
76
78
|
# Configuration
|
|
77
79
|
"Settings",
|
|
@@ -15,20 +15,25 @@ well as user-written subclasses — because nothing new crosses the
|
|
|
15
15
|
Provider boundary. With an empty memory the composed prompt is the input
|
|
16
16
|
byte-for-byte, so configuring memory never changes a first run.
|
|
17
17
|
|
|
18
|
-
Storage
|
|
19
|
-
|
|
20
|
-
|
|
18
|
+
Storage ships in two flavors: a process-local, bounded FIFO
|
|
19
|
+
(:class:`InMemoryMemory`) and a persistent backend backed by a local
|
|
20
|
+
SQLite database file (:class:`SQLiteMemory`) — both dependency-free.
|
|
21
|
+
Custom backends (Redis, PostgreSQL, ...) implement the three-method
|
|
22
|
+
:class:`Memory` ABC.
|
|
21
23
|
"""
|
|
22
24
|
|
|
23
25
|
from __future__ import annotations
|
|
24
26
|
|
|
27
|
+
import os
|
|
28
|
+
import sqlite3
|
|
25
29
|
from abc import ABC, abstractmethod
|
|
26
30
|
from collections.abc import Sequence
|
|
27
31
|
from dataclasses import dataclass
|
|
32
|
+
from types import TracebackType
|
|
28
33
|
|
|
29
34
|
from nexusagent.logging import get_logger
|
|
30
35
|
|
|
31
|
-
__all__ = ["ConversationTurn", "InMemoryMemory", "Memory"]
|
|
36
|
+
__all__ = ["ConversationTurn", "InMemoryMemory", "Memory", "SQLiteMemory"]
|
|
32
37
|
|
|
33
38
|
USER_ROLE = "user"
|
|
34
39
|
ASSISTANT_ROLE = "assistant"
|
|
@@ -129,6 +134,103 @@ class InMemoryMemory(Memory):
|
|
|
129
134
|
self._turns.clear()
|
|
130
135
|
|
|
131
136
|
|
|
137
|
+
class SQLiteMemory(Memory):
|
|
138
|
+
"""Conversation memory persisted in a local SQLite database (ADR 0013).
|
|
139
|
+
|
|
140
|
+
A drop-in :class:`Memory` backend for durability beyond the current
|
|
141
|
+
process: turns live in a ``turns`` table of a SQLite database at
|
|
142
|
+
``path`` (created on first use — missing parent directories are
|
|
143
|
+
created too), so history survives restarts and runtimes that open the
|
|
144
|
+
same file one after another see the same turns. Storage stays
|
|
145
|
+
dependency-free: ``sqlite3`` ships with Python.
|
|
146
|
+
|
|
147
|
+
The bounded-FIFO semantics match :class:`InMemoryMemory`: ``max_turns``
|
|
148
|
+
(default :data:`DEFAULT_MAX_TURNS`, validated the same way) caps the
|
|
149
|
+
stored turns and the *oldest rows are deleted* when the cap is
|
|
150
|
+
exceeded — the eviction itself is persisted. Every mutation commits
|
|
151
|
+
immediately. One ``sqlite3`` connection is opened for the lifetime of
|
|
152
|
+
the instance; the runtime never accesses it concurrently and the
|
|
153
|
+
instance is not thread-safe. Call :meth:`close` — or use the instance
|
|
154
|
+
as a context manager — when done; further use of a closed instance
|
|
155
|
+
raises :class:`sqlite3.ProgrammingError`.
|
|
156
|
+
"""
|
|
157
|
+
|
|
158
|
+
def __init__(self, path: str | os.PathLike[str], max_turns: int = DEFAULT_MAX_TURNS) -> None:
|
|
159
|
+
if isinstance(max_turns, bool) or not isinstance(max_turns, int):
|
|
160
|
+
raise TypeError("max_turns must be an integer")
|
|
161
|
+
|
|
162
|
+
if max_turns < 1:
|
|
163
|
+
raise ValueError("max_turns must be at least 1")
|
|
164
|
+
|
|
165
|
+
self._path = os.fspath(path)
|
|
166
|
+
if not self._path:
|
|
167
|
+
raise ValueError("path must not be empty")
|
|
168
|
+
|
|
169
|
+
parent = os.path.dirname(self._path)
|
|
170
|
+
if parent:
|
|
171
|
+
os.makedirs(parent, exist_ok=True)
|
|
172
|
+
|
|
173
|
+
self._max_turns = max_turns
|
|
174
|
+
self._conn = sqlite3.connect(self._path)
|
|
175
|
+
self._conn.execute(
|
|
176
|
+
"CREATE TABLE IF NOT EXISTS turns ("
|
|
177
|
+
"id INTEGER PRIMARY KEY, "
|
|
178
|
+
"role TEXT NOT NULL, "
|
|
179
|
+
"text TEXT NOT NULL)"
|
|
180
|
+
)
|
|
181
|
+
self._conn.commit()
|
|
182
|
+
|
|
183
|
+
@property
|
|
184
|
+
def path(self) -> str:
|
|
185
|
+
"""The database file this memory persists to."""
|
|
186
|
+
return self._path
|
|
187
|
+
|
|
188
|
+
def append(self, turn: ConversationTurn) -> None:
|
|
189
|
+
if not isinstance(turn, ConversationTurn):
|
|
190
|
+
raise TypeError("turn must be a ConversationTurn")
|
|
191
|
+
|
|
192
|
+
self._conn.execute(
|
|
193
|
+
"INSERT INTO turns (role, text) VALUES (?, ?)",
|
|
194
|
+
(turn.role, turn.text),
|
|
195
|
+
)
|
|
196
|
+
self._prune()
|
|
197
|
+
self._conn.commit()
|
|
198
|
+
|
|
199
|
+
def history(self) -> tuple[ConversationTurn, ...]:
|
|
200
|
+
rows = self._conn.execute("SELECT role, text FROM turns ORDER BY id ASC").fetchall()
|
|
201
|
+
return tuple(ConversationTurn(role=role, text=text) for role, text in rows)
|
|
202
|
+
|
|
203
|
+
def clear(self) -> None:
|
|
204
|
+
self._conn.execute("DELETE FROM turns")
|
|
205
|
+
self._conn.commit()
|
|
206
|
+
|
|
207
|
+
def close(self) -> None:
|
|
208
|
+
"""Close the underlying database connection."""
|
|
209
|
+
self._conn.close()
|
|
210
|
+
|
|
211
|
+
def __enter__(self) -> SQLiteMemory:
|
|
212
|
+
return self
|
|
213
|
+
|
|
214
|
+
def __exit__(
|
|
215
|
+
self,
|
|
216
|
+
exc_type: type[BaseException] | None,
|
|
217
|
+
exc_value: BaseException | None,
|
|
218
|
+
traceback: TracebackType | None,
|
|
219
|
+
) -> None:
|
|
220
|
+
self.close()
|
|
221
|
+
|
|
222
|
+
def _prune(self) -> None:
|
|
223
|
+
row = self._conn.execute("SELECT COUNT(*) FROM turns").fetchone()
|
|
224
|
+
count = row[0] if row is not None else 0
|
|
225
|
+
excess = count - self._max_turns
|
|
226
|
+
if excess > 0:
|
|
227
|
+
self._conn.execute(
|
|
228
|
+
"DELETE FROM turns WHERE id IN (SELECT id FROM turns ORDER BY id ASC LIMIT ?)",
|
|
229
|
+
(excess,),
|
|
230
|
+
)
|
|
231
|
+
_logger.debug("memory evicted %d turns beyond the cap of %d", excess, self._max_turns)
|
|
232
|
+
|
|
233
|
+
|
|
132
234
|
def compose_prompt(input_text: str, history: Sequence[ConversationTurn]) -> str:
|
|
133
235
|
"""Compose the prompt the Provider actually sees for this run.
|
|
134
236
|
|
{nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0/src/nexusagent_runtime.egg-info}/PKG-INFO
RENAMED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: nexusagent-runtime
|
|
3
|
-
Version: 1.
|
|
3
|
+
Version: 1.3.0
|
|
4
4
|
Summary: A small, modular AI agent runtime in Python — agents, providers, tools and a readable core.
|
|
5
5
|
License-Expression: MIT
|
|
6
6
|
Project-URL: Homepage, https://github.com/Abolfazlrwm/nexusagent
|
|
@@ -59,12 +59,12 @@ print(runtime.execute_tool("calculator", "2 + 3")) # 5
|
|
|
59
59
|
|
|
60
60
|
- **Zero runtime dependencies** — the whole core is the Python standard library. `pip install nexusagent-runtime` pulls nothing else.
|
|
61
61
|
- **Automatic retries** — transient HTTP failures (connection errors, timeouts, 429/5xx) are retried with exponential backoff, full jitter and `Retry-After` support. See [ADR 0011](docs/adr/0011-http-retry-backoff.md).
|
|
62
|
-
- **Conversation memory** — opt-in
|
|
62
|
+
- **Conversation memory** — opt-in memory composes remembered turns into each run's prompt, so the agent carries context across runs with any provider — in-process (`InMemoryMemory`) or persisted to a local SQLite file (`SQLiteMemory`). See [ADR 0012](docs/adr/0012-conversation-memory.md) and [ADR 0013](docs/adr/0013-sqlite-memory.md).
|
|
63
63
|
- **Stable public API** — 1.0 declares SemVer stability over the full root surface; a CI-pinned test fails on any accidental removal, rename or silent addition. See [ADR 0010](docs/adr/0010-1.0-api-stability-and-versioning-policy.md).
|
|
64
64
|
- **Readable by design** — the core is small enough to audit in an afternoon; architecture rules are enforced by tests, not comments.
|
|
65
65
|
- **Honest** — the feature list below says what exists *and what doesn't*. No fake benchmarks, no aspirational docs.
|
|
66
66
|
- **Typed** — ships `py.typed`; the source itself passes `mypy --strict`.
|
|
67
|
-
- **Tested** —
|
|
67
|
+
- **Tested** — 1200+ contract tests, ≥95% coverage floor enforced in CI.
|
|
68
68
|
|
|
69
69
|
## Features
|
|
70
70
|
|
|
@@ -86,6 +86,7 @@ print(runtime.execute_tool("calculator", "2 + 3")) # 5
|
|
|
86
86
|
| Streaming responses (SSE, all HTTP adapters, sync + async) | ✅ [ADR 0009](docs/adr/0009-streaming-responses.md) |
|
|
87
87
|
| Retries / backoff on HTTP failures (429/5xx, jitter, `Retry-After`) | ✅ [ADR 0011](docs/adr/0011-http-retry-backoff.md) |
|
|
88
88
|
| Conversation memory (opt-in, in-process, provider-agnostic) | ✅ [ADR 0012](docs/adr/0012-conversation-memory.md) |
|
|
89
|
+
| Persistent conversation memory (local SQLite file, same contract) | ✅ [ADR 0013](docs/adr/0013-sqlite-memory.md) |
|
|
89
90
|
| Planning, multi-agent orchestration | ❌ |
|
|
90
91
|
|
|
91
92
|
## Architecture
|
|
@@ -306,6 +307,36 @@ Failed runs record nothing, and a memory with no history composes the
|
|
|
306
307
|
prompt byte-for-byte like the no-memory path. Design details:
|
|
307
308
|
[ADR 0012](docs/adr/0012-conversation-memory.md).
|
|
308
309
|
|
|
310
|
+
#### Persistent memory (SQLite)
|
|
311
|
+
|
|
312
|
+
`InMemoryMemory` lives in the process and is gone when it ends. To keep
|
|
313
|
+
history across restarts, hand the runtime a `SQLiteMemory`: turns live in
|
|
314
|
+
a local SQLite database file (`sqlite3` is in the standard library, so
|
|
315
|
+
still zero dependencies), the bounded-FIFO semantics and `max_turns` cap
|
|
316
|
+
match the in-process backend, and the oldest rows are evicted the same
|
|
317
|
+
way — the eviction itself is persisted.
|
|
318
|
+
|
|
319
|
+
```python
|
|
320
|
+
from nexusagent import SQLiteMemory, create_runtime
|
|
321
|
+
|
|
322
|
+
memory = SQLiteMemory("session.db", max_turns=50) # created on first use
|
|
323
|
+
runtime = create_runtime(memory=memory)
|
|
324
|
+
|
|
325
|
+
runtime.run("My name is Sara")
|
|
326
|
+
memory.close()
|
|
327
|
+
|
|
328
|
+
# A later process reopens the same file and remembers:
|
|
329
|
+
memory = SQLiteMemory("session.db", max_turns=50)
|
|
330
|
+
runtime = create_runtime(memory=memory)
|
|
331
|
+
print(runtime.run("What is my name?").output) # the model still knows
|
|
332
|
+
memory.close()
|
|
333
|
+
```
|
|
334
|
+
|
|
335
|
+
Every mutation commits immediately; `close()` (or using the instance as a
|
|
336
|
+
context manager) releases the database connection, and runtimes that open
|
|
337
|
+
the same file one after another see the same turns. Design details:
|
|
338
|
+
[ADR 0013](docs/adr/0013-sqlite-memory.md).
|
|
339
|
+
|
|
309
340
|
### Async runtime
|
|
310
341
|
|
|
311
342
|
The async layer mirrors the sync contracts one-to-one — `await runtime.run(...)`,
|
|
@@ -360,6 +391,7 @@ All examples run offline, with no API keys:
|
|
|
360
391
|
- [`examples/tool_loop_demo.py`](examples/tool_loop_demo.py) — the autonomous tool loop over local HTTP
|
|
361
392
|
- [`examples/streaming.py`](examples/streaming.py) — streamed text through `on_delta`, offline
|
|
362
393
|
- [`examples/memory.py`](examples/memory.py) — conversation memory across runs, offline
|
|
394
|
+
- [`examples/sqlite_memory.py`](examples/sqlite_memory.py) — persistent SQLite memory across restarts, offline
|
|
363
395
|
- [`examples/async_tool_loop.py`](examples/async_tool_loop.py) — the async tool loop with an awaited tool
|
|
364
396
|
- [`examples/http_provider_local.py`](examples/http_provider_local.py) — `http` provider against a local backend
|
|
365
397
|
|
|
@@ -0,0 +1,325 @@
|
|
|
1
|
+
"""Contract tests for the persistent SQLite memory backend (ADR 0013).
|
|
2
|
+
|
|
3
|
+
SQLiteMemory keeps the exact bounded-FIFO semantics of ``InMemoryMemory``
|
|
4
|
+
but stores turns in a local SQLite database file, so history survives
|
|
5
|
+
process restarts and runtimes that reopen the same file. These tests pin
|
|
6
|
+
the construction and validation contract, the FIFO eviction and its
|
|
7
|
+
persistence, ``clear()``, ``close()`` and context-manager behavior,
|
|
8
|
+
sharing one database file between instances, and the end-to-end agent
|
|
9
|
+
wiring with a reopened memory.
|
|
10
|
+
"""
|
|
11
|
+
|
|
12
|
+
from __future__ import annotations
|
|
13
|
+
|
|
14
|
+
import dataclasses
|
|
15
|
+
import os
|
|
16
|
+
import sqlite3
|
|
17
|
+
from pathlib import Path
|
|
18
|
+
|
|
19
|
+
import pytest
|
|
20
|
+
|
|
21
|
+
from nexusagent import (
|
|
22
|
+
Agent,
|
|
23
|
+
ConversationTurn,
|
|
24
|
+
InMemoryMemory,
|
|
25
|
+
Memory,
|
|
26
|
+
ScriptedProvider,
|
|
27
|
+
SQLiteMemory,
|
|
28
|
+
TextResponse,
|
|
29
|
+
create_runtime,
|
|
30
|
+
)
|
|
31
|
+
from nexusagent.memory import ASSISTANT_ROLE, USER_ROLE
|
|
32
|
+
|
|
33
|
+
EXPECTED_TRANSCRIPT = (
|
|
34
|
+
"Previous conversation (oldest first):\n"
|
|
35
|
+
"user: My name is Sara\n"
|
|
36
|
+
"assistant: first answer\n"
|
|
37
|
+
"\n"
|
|
38
|
+
"Respond to this new user message:\n"
|
|
39
|
+
"What is my name?"
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
def turn(role: str, text: str) -> ConversationTurn:
|
|
44
|
+
return ConversationTurn(role, text)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
# --- construction and validation -------------------------------------------
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def test_is_a_memory_subclass(tmp_path: Path) -> None:
|
|
51
|
+
assert isinstance(SQLiteMemory(tmp_path / "memory.db"), Memory)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def test_accepts_str_and_pathlib_paths(tmp_path: Path) -> None:
|
|
55
|
+
str_path = os.path.join(tmp_path, "a.db")
|
|
56
|
+
string_memory = SQLiteMemory(str_path)
|
|
57
|
+
string_memory.append(turn(USER_ROLE, "hi"))
|
|
58
|
+
assert Path(str_path).is_file()
|
|
59
|
+
string_memory.close()
|
|
60
|
+
|
|
61
|
+
path_object = tmp_path / "b.db"
|
|
62
|
+
path_memory = SQLiteMemory(path_object)
|
|
63
|
+
path_memory.append(turn(USER_ROLE, "hi"))
|
|
64
|
+
assert path_object.is_file()
|
|
65
|
+
path_memory.close()
|
|
66
|
+
|
|
67
|
+
|
|
68
|
+
def test_creates_missing_parent_directories(tmp_path: Path) -> None:
|
|
69
|
+
db = tmp_path / "nested" / "deep" / "memory.db"
|
|
70
|
+
memory = SQLiteMemory(db)
|
|
71
|
+
memory.append(turn(USER_ROLE, "hello"))
|
|
72
|
+
assert memory.history() == (turn(USER_ROLE, "hello"),)
|
|
73
|
+
assert db.is_file()
|
|
74
|
+
memory.close()
|
|
75
|
+
|
|
76
|
+
|
|
77
|
+
def test_rejects_empty_path() -> None:
|
|
78
|
+
with pytest.raises(ValueError, match="path must not be empty"):
|
|
79
|
+
SQLiteMemory("")
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def test_rejects_non_path_arguments() -> None:
|
|
83
|
+
with pytest.raises(TypeError):
|
|
84
|
+
SQLiteMemory(123) # type: ignore[arg-type]
|
|
85
|
+
|
|
86
|
+
with pytest.raises(TypeError):
|
|
87
|
+
SQLiteMemory(None) # type: ignore[arg-type]
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
def test_path_property_reports_the_database_file(tmp_path: Path) -> None:
|
|
91
|
+
memory = SQLiteMemory(tmp_path / "m.db")
|
|
92
|
+
assert memory.path == str(tmp_path / "m.db")
|
|
93
|
+
memory.close()
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def test_max_turns_rejects_bool(tmp_path: Path) -> None:
|
|
97
|
+
with pytest.raises(TypeError, match="max_turns must be an integer"):
|
|
98
|
+
SQLiteMemory(tmp_path / "m.db", max_turns=True)
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
@pytest.mark.parametrize("value", ["10", 1.5, None])
|
|
102
|
+
def test_max_turns_rejects_non_integers(tmp_path: Path, value: object) -> None:
|
|
103
|
+
with pytest.raises(TypeError, match="max_turns must be an integer"):
|
|
104
|
+
SQLiteMemory(tmp_path / "m.db", max_turns=value) # type: ignore[arg-type]
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
@pytest.mark.parametrize("value", [0, -1, -100])
|
|
108
|
+
def test_max_turns_rejects_values_below_one(tmp_path: Path, value: int) -> None:
|
|
109
|
+
with pytest.raises(ValueError, match="max_turns must be at least 1"):
|
|
110
|
+
SQLiteMemory(tmp_path / "m.db", max_turns=value)
|
|
111
|
+
|
|
112
|
+
|
|
113
|
+
# --- append / history --------------------------------------------------------
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
def test_append_rejects_non_turn(tmp_path: Path) -> None:
|
|
117
|
+
memory = SQLiteMemory(tmp_path / "m.db")
|
|
118
|
+
with pytest.raises(TypeError, match="turn must be a ConversationTurn"):
|
|
119
|
+
memory.append("hello") # type: ignore[arg-type]
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def test_history_round_trips_turns_oldest_first(tmp_path: Path) -> None:
|
|
123
|
+
memory = SQLiteMemory(tmp_path / "m.db")
|
|
124
|
+
memory.append(turn(USER_ROLE, "first"))
|
|
125
|
+
memory.append(turn(ASSISTANT_ROLE, "reply"))
|
|
126
|
+
memory.append(turn(USER_ROLE, "third"))
|
|
127
|
+
assert memory.history() == (
|
|
128
|
+
turn(USER_ROLE, "first"),
|
|
129
|
+
turn(ASSISTANT_ROLE, "reply"),
|
|
130
|
+
turn(USER_ROLE, "third"),
|
|
131
|
+
)
|
|
132
|
+
|
|
133
|
+
|
|
134
|
+
def test_history_returns_a_tuple_of_frozen_turns(tmp_path: Path) -> None:
|
|
135
|
+
memory = SQLiteMemory(tmp_path / "m.db")
|
|
136
|
+
memory.append(turn(USER_ROLE, "hi"))
|
|
137
|
+
history = memory.history()
|
|
138
|
+
assert isinstance(history, tuple)
|
|
139
|
+
with pytest.raises(dataclasses.FrozenInstanceError):
|
|
140
|
+
history[0].role = ASSISTANT_ROLE # type: ignore[misc]
|
|
141
|
+
|
|
142
|
+
|
|
143
|
+
def test_len_counts_stored_turns(tmp_path: Path) -> None:
|
|
144
|
+
memory = SQLiteMemory(tmp_path / "m.db")
|
|
145
|
+
assert len(memory) == 0
|
|
146
|
+
memory.append(turn(USER_ROLE, "a"))
|
|
147
|
+
memory.append(turn(ASSISTANT_ROLE, "b"))
|
|
148
|
+
assert len(memory) == 2
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
# --- bounded FIFO eviction ---------------------------------------------------
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def test_fifo_evicts_oldest_turns_beyond_the_cap(tmp_path: Path) -> None:
|
|
155
|
+
memory = SQLiteMemory(tmp_path / "m.db", max_turns=3)
|
|
156
|
+
for i in range(5):
|
|
157
|
+
memory.append(turn(USER_ROLE, f"t{i}"))
|
|
158
|
+
assert [t.text for t in memory.history()] == ["t2", "t3", "t4"]
|
|
159
|
+
assert len(memory) == 3
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def test_eviction_is_persisted_across_reopen(tmp_path: Path) -> None:
|
|
163
|
+
db = tmp_path / "m.db"
|
|
164
|
+
memory = SQLiteMemory(db, max_turns=2)
|
|
165
|
+
for i in range(4):
|
|
166
|
+
memory.append(turn(USER_ROLE, f"t{i}"))
|
|
167
|
+
memory.close()
|
|
168
|
+
|
|
169
|
+
reopened = SQLiteMemory(db, max_turns=2)
|
|
170
|
+
assert [t.text for t in reopened.history()] == ["t2", "t3"]
|
|
171
|
+
reopened.close()
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def test_cap_of_one_keeps_only_the_latest_turn(tmp_path: Path) -> None:
|
|
175
|
+
memory = SQLiteMemory(tmp_path / "m.db", max_turns=1)
|
|
176
|
+
memory.append(turn(USER_ROLE, "old"))
|
|
177
|
+
memory.append(turn(ASSISTANT_ROLE, "new"))
|
|
178
|
+
assert memory.history() == (turn(ASSISTANT_ROLE, "new"),)
|
|
179
|
+
|
|
180
|
+
|
|
181
|
+
def test_matches_inmemory_fifo_semantics() -> None:
|
|
182
|
+
in_memory = InMemoryMemory(max_turns=3)
|
|
183
|
+
on_disk = SQLiteMemory(":memory:", max_turns=3)
|
|
184
|
+
for i in range(6):
|
|
185
|
+
in_memory.append(turn(USER_ROLE, f"t{i}"))
|
|
186
|
+
on_disk.append(turn(USER_ROLE, f"t{i}"))
|
|
187
|
+
assert on_disk.history() == in_memory.history()
|
|
188
|
+
in_memory.clear()
|
|
189
|
+
on_disk.clear()
|
|
190
|
+
assert on_disk.history() == in_memory.history() == ()
|
|
191
|
+
on_disk.close()
|
|
192
|
+
|
|
193
|
+
|
|
194
|
+
# --- clear ---------------------------------------------------------------------
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
def test_clear_empties_history(tmp_path: Path) -> None:
|
|
198
|
+
memory = SQLiteMemory(tmp_path / "m.db")
|
|
199
|
+
memory.append(turn(USER_ROLE, "a"))
|
|
200
|
+
memory.clear()
|
|
201
|
+
assert memory.history() == ()
|
|
202
|
+
assert len(memory) == 0
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
def test_clear_persists_across_reopen(tmp_path: Path) -> None:
|
|
206
|
+
db = tmp_path / "m.db"
|
|
207
|
+
memory = SQLiteMemory(db)
|
|
208
|
+
memory.append(turn(USER_ROLE, "a"))
|
|
209
|
+
memory.clear()
|
|
210
|
+
memory.close()
|
|
211
|
+
assert SQLiteMemory(db).history() == ()
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
# --- persistence across reopen -------------------------------------------------
|
|
215
|
+
|
|
216
|
+
|
|
217
|
+
def test_history_survives_close_and_reopen(tmp_path: Path) -> None:
|
|
218
|
+
db = tmp_path / "m.db"
|
|
219
|
+
writer = SQLiteMemory(db)
|
|
220
|
+
writer.append(turn(USER_ROLE, "My name is Sara"))
|
|
221
|
+
writer.append(turn(ASSISTANT_ROLE, "Nice to meet you, Sara!"))
|
|
222
|
+
writer.close()
|
|
223
|
+
|
|
224
|
+
reader = SQLiteMemory(db)
|
|
225
|
+
assert reader.history() == (
|
|
226
|
+
turn(USER_ROLE, "My name is Sara"),
|
|
227
|
+
turn(ASSISTANT_ROLE, "Nice to meet you, Sara!"),
|
|
228
|
+
)
|
|
229
|
+
reader.close()
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
def test_two_instances_share_one_database_file(tmp_path: Path) -> None:
|
|
233
|
+
db = tmp_path / "m.db"
|
|
234
|
+
first = SQLiteMemory(db)
|
|
235
|
+
first.append(turn(USER_ROLE, "shared"))
|
|
236
|
+
|
|
237
|
+
second = SQLiteMemory(db)
|
|
238
|
+
assert second.history() == (turn(USER_ROLE, "shared"),)
|
|
239
|
+
second.append(turn(ASSISTANT_ROLE, "seen"))
|
|
240
|
+
assert [t.text for t in first.history()] == ["shared", "seen"]
|
|
241
|
+
first.close()
|
|
242
|
+
second.close()
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
def test_in_memory_database_works_while_open() -> None:
|
|
246
|
+
memory = SQLiteMemory(":memory:")
|
|
247
|
+
memory.append(turn(USER_ROLE, "volatile"))
|
|
248
|
+
assert [t.text for t in memory.history()] == ["volatile"]
|
|
249
|
+
memory.close()
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
# --- close and context manager -------------------------------------------------
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
def test_close_is_idempotent(tmp_path: Path) -> None:
|
|
256
|
+
memory = SQLiteMemory(tmp_path / "m.db")
|
|
257
|
+
memory.close()
|
|
258
|
+
memory.close() # must not raise
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
def test_operations_after_close_raise(tmp_path: Path) -> None:
|
|
262
|
+
memory = SQLiteMemory(tmp_path / "m.db")
|
|
263
|
+
memory.append(turn(USER_ROLE, "a"))
|
|
264
|
+
memory.close()
|
|
265
|
+
with pytest.raises(sqlite3.ProgrammingError):
|
|
266
|
+
memory.append(turn(USER_ROLE, "b"))
|
|
267
|
+
with pytest.raises(sqlite3.ProgrammingError):
|
|
268
|
+
memory.history()
|
|
269
|
+
with pytest.raises(sqlite3.ProgrammingError):
|
|
270
|
+
memory.clear()
|
|
271
|
+
|
|
272
|
+
|
|
273
|
+
def test_context_manager_closes_on_exit(tmp_path: Path) -> None:
|
|
274
|
+
db = tmp_path / "m.db"
|
|
275
|
+
with SQLiteMemory(db) as memory:
|
|
276
|
+
assert isinstance(memory, SQLiteMemory)
|
|
277
|
+
memory.append(turn(USER_ROLE, "inside"))
|
|
278
|
+
assert len(memory) == 1
|
|
279
|
+
with pytest.raises(sqlite3.ProgrammingError):
|
|
280
|
+
memory.append(turn(USER_ROLE, "after"))
|
|
281
|
+
assert SQLiteMemory(db).history() == (turn(USER_ROLE, "inside"),)
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
# --- agent and runtime wiring --------------------------------------------------
|
|
285
|
+
|
|
286
|
+
|
|
287
|
+
def test_agent_records_turns_into_sqlite_memory(tmp_path: Path) -> None:
|
|
288
|
+
memory = SQLiteMemory(tmp_path / "m.db")
|
|
289
|
+
provider = ScriptedProvider([TextResponse("answer")])
|
|
290
|
+
agent = Agent(provider, memory=memory)
|
|
291
|
+
result = agent.run("hello")
|
|
292
|
+
assert result.success
|
|
293
|
+
assert memory.history() == (
|
|
294
|
+
turn(USER_ROLE, "hello"),
|
|
295
|
+
turn(ASSISTANT_ROLE, "answer"),
|
|
296
|
+
)
|
|
297
|
+
memory.close()
|
|
298
|
+
|
|
299
|
+
|
|
300
|
+
def test_reopened_memory_composes_previous_transcript(tmp_path: Path) -> None:
|
|
301
|
+
"""A reopened file plays the role of a brand-new process remembering."""
|
|
302
|
+
db = tmp_path / "m.db"
|
|
303
|
+
|
|
304
|
+
first = Agent(
|
|
305
|
+
ScriptedProvider([TextResponse("first answer")]),
|
|
306
|
+
memory=SQLiteMemory(db),
|
|
307
|
+
)
|
|
308
|
+
assert first.run("My name is Sara").success
|
|
309
|
+
|
|
310
|
+
second_provider = ScriptedProvider([TextResponse("second answer")])
|
|
311
|
+
second = Agent(second_provider, memory=SQLiteMemory(db))
|
|
312
|
+
assert second.run("What is my name?").success
|
|
313
|
+
assert second_provider.calls[0][0] == EXPECTED_TRANSCRIPT
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
def test_runtime_factory_accepts_sqlite_memory(
|
|
317
|
+
monkeypatch: pytest.MonkeyPatch, tmp_path: Path
|
|
318
|
+
) -> None:
|
|
319
|
+
monkeypatch.setenv("NEXUS_PROVIDER", "fake")
|
|
320
|
+
memory = SQLiteMemory(tmp_path / "m.db")
|
|
321
|
+
runtime = create_runtime(memory=memory)
|
|
322
|
+
assert runtime.memory is memory
|
|
323
|
+
assert runtime.run("hello").success
|
|
324
|
+
assert runtime.memory is not None and len(runtime.memory) == 2
|
|
325
|
+
memory.close()
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/src/nexusagent_runtime.egg-info/requires.txt
RENAMED
|
File without changes
|
{nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/src/nexusagent_runtime.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{nexusagent_runtime-1.2.0 → nexusagent_runtime-1.3.0}/tests/test_http_tool_loop_integration.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|