nextloop 0.1.0rc1__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.
Files changed (35) hide show
  1. nextloop-0.1.0rc1/LICENSE +21 -0
  2. nextloop-0.1.0rc1/PKG-INFO +148 -0
  3. nextloop-0.1.0rc1/README.md +120 -0
  4. nextloop-0.1.0rc1/pyproject.toml +66 -0
  5. nextloop-0.1.0rc1/setup.cfg +4 -0
  6. nextloop-0.1.0rc1/src/nextloop/__init__.py +96 -0
  7. nextloop-0.1.0rc1/src/nextloop/adapters/__init__.py +6 -0
  8. nextloop-0.1.0rc1/src/nextloop/adapters/_sse.py +25 -0
  9. nextloop-0.1.0rc1/src/nextloop/adapters/anthropic.py +211 -0
  10. nextloop-0.1.0rc1/src/nextloop/adapters/memory.py +97 -0
  11. nextloop-0.1.0rc1/src/nextloop/adapters/openai.py +188 -0
  12. nextloop-0.1.0rc1/src/nextloop/adapters/sqlite.py +250 -0
  13. nextloop-0.1.0rc1/src/nextloop/contracts.py +350 -0
  14. nextloop-0.1.0rc1/src/nextloop/driver.py +446 -0
  15. nextloop-0.1.0rc1/src/nextloop/events/__init__.py +17 -0
  16. nextloop-0.1.0rc1/src/nextloop/events/outcome.py +183 -0
  17. nextloop-0.1.0rc1/src/nextloop/events/project.py +186 -0
  18. nextloop-0.1.0rc1/src/nextloop/events/repair.py +143 -0
  19. nextloop-0.1.0rc1/src/nextloop/events/response.py +215 -0
  20. nextloop-0.1.0rc1/src/nextloop/execute/__init__.py +15 -0
  21. nextloop-0.1.0rc1/src/nextloop/execute/batch.py +165 -0
  22. nextloop-0.1.0rc1/src/nextloop/execute/model.py +134 -0
  23. nextloop-0.1.0rc1/src/nextloop/execute/tools.py +151 -0
  24. nextloop-0.1.0rc1/src/nextloop/loop.py +169 -0
  25. nextloop-0.1.0rc1/src/nextloop/py.typed +0 -0
  26. nextloop-0.1.0rc1/src/nextloop.egg-info/PKG-INFO +148 -0
  27. nextloop-0.1.0rc1/src/nextloop.egg-info/SOURCES.txt +33 -0
  28. nextloop-0.1.0rc1/src/nextloop.egg-info/dependency_links.txt +1 -0
  29. nextloop-0.1.0rc1/src/nextloop.egg-info/requires.txt +11 -0
  30. nextloop-0.1.0rc1/src/nextloop.egg-info/top_level.txt +1 -0
  31. nextloop-0.1.0rc1/tests/test_events.py +241 -0
  32. nextloop-0.1.0rc1/tests/test_failures.py +277 -0
  33. nextloop-0.1.0rc1/tests/test_loop.py +316 -0
  34. nextloop-0.1.0rc1/tests/test_providers.py +191 -0
  35. nextloop-0.1.0rc1/tests/test_stores.py +68 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 12bitsD
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,148 @@
1
+ Metadata-Version: 2.4
2
+ Name: nextloop
3
+ Version: 0.1.0rc1
4
+ Summary: An embeddable AgentLoop with explicit event, tool, recovery, and delivery semantics
5
+ Author-email: 12bitsD <bis12@163.com>
6
+ License-Expression: MIT
7
+ Project-URL: Repository, https://github.com/12bitsD/nextloop
8
+ Classifier: Development Status :: 3 - Alpha
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.11
11
+ Classifier: Programming Language :: Python :: 3.12
12
+ Classifier: Programming Language :: Python :: 3.13
13
+ Classifier: Typing :: Typed
14
+ Requires-Python: >=3.11
15
+ Description-Content-Type: text/markdown
16
+ License-File: LICENSE
17
+ Requires-Dist: httpx<1,>=0.27
18
+ Requires-Dist: jsonschema<5,>=4.23
19
+ Provides-Extra: dev
20
+ Requires-Dist: build<2,>=1.2; extra == "dev"
21
+ Requires-Dist: mypy<2,>=1.13; extra == "dev"
22
+ Requires-Dist: pytest<10,>=8; extra == "dev"
23
+ Requires-Dist: pytest-asyncio<2,>=0.24; extra == "dev"
24
+ Requires-Dist: ruff<1,>=0.8; extra == "dev"
25
+ Requires-Dist: twine<7,>=5; extra == "dev"
26
+ Requires-Dist: types-jsonschema<5,>=4.23; extra == "dev"
27
+ Dynamic: license-file
28
+
29
+ # nextloop
30
+
31
+ A small, embeddable Python AgentLoop with explicit execution, recovery, and delivery semantics.
32
+
33
+ Current version: **0.1.0rc1**.
34
+
35
+ ## Install
36
+
37
+ ```bash
38
+ python -m pip install nextloop==0.1.0rc1
39
+ ```
40
+
41
+ For local development:
42
+
43
+ ```bash
44
+ uv venv --python 3.11 .venv
45
+ uv pip install --python .venv/bin/python -e '.[dev]'
46
+ ```
47
+
48
+ ## What it provides
49
+
50
+ - DSH-aligned Session/Turn/Step execution with 4D integer coordinates and writer fencing.
51
+ - Append-only Trajectory and O(Δ) `surface_op` watermark projection.
52
+ - In-memory `Inbox` serialization for steer and final commitment.
53
+ - Whole-batch Tool Schema validation, bounded parallel calls, and exclusive failure barriers.
54
+ - Closed five-variant `ToolOutcome`: `Completed`, `Skipped`, `Cancelled`, `UncertainSettled`, `UncertainHanging`.
55
+ - Bounded Provider retries, protocol correction, WorkingContext, Compaction, and cancellation.
56
+ - SQLite and in-memory EventStores, crash closers, and delivery-only recovery.
57
+ - OpenAI-compatible and Anthropic streaming Provider adapters.
58
+
59
+ It is a library, not an HTTP service, product bot, Router, EventBus, or multi-agent framework.
60
+
61
+ ## Public API
62
+
63
+ ```python
64
+ AgentLoop.run(TurnContext) -> TurnOutcome
65
+ AgentLoop.steer(session_id, content, *, input_id=None) -> bool
66
+ AgentLoop.cancel(session_id, cause="user_stop") -> bool
67
+ AgentLoop.recover(session_id, store, delivery) -> RecoveryOutcome
68
+ ```
69
+
70
+ The only four Adapter protocols are `EventStore`, `ModelProvider`, `ToolRuntime`, and `DeliveryOwner`. Context projection and Compaction are built in and configured through `LoopConfig`.
71
+
72
+ `ToolRegistry` is the built-in `ToolRuntime` implementation:
73
+
74
+ ```python
75
+ from nextloop import ToolRegistry, ToolSpec, ToolExecutionMode
76
+
77
+ registry = ToolRegistry()
78
+ registry.register(
79
+ ToolSpec(
80
+ "read",
81
+ "Read a file",
82
+ {
83
+ "type": "object",
84
+ "properties": {"path": {"type": "string"}},
85
+ "required": ["path"],
86
+ },
87
+ mode=ToolExecutionMode.PARALLEL,
88
+ ),
89
+ lambda arguments, context: "file contents",
90
+ )
91
+ ```
92
+
93
+ Run the complete fake-Provider example:
94
+
95
+ ```bash
96
+ python examples/basic.py
97
+ ```
98
+
99
+ It executes model → Tool → Observation → model → delivery without a hosted model.
100
+
101
+ ## Code structure
102
+
103
+ ```text
104
+ src/nextloop/
105
+ contracts.py # public schemas, ToolOutcome, four Protocols, LoopConfig
106
+ loop.py # AgentLoop and active Session registry
107
+ driver.py # thin Turn/Step orchestration and SessionActor
108
+ events/ # pure projection, response/outcome folds, crash repair
109
+ execute/ # model retries, Tool registration, batch scheduling
110
+ adapters/ # SQLite, memory, OpenAI, Anthropic
111
+ ```
112
+
113
+ `events/` performs no I/O. `execute/` owns side effects and classified failures. `driver.py` only composes them.
114
+
115
+ ## Verification
116
+
117
+ The release-candidate checks cover:
118
+
119
+ - text, Tool, multi-Step, mixed, empty, truncated, and malformed responses;
120
+ - whole-batch rejection and parallel/exclusive scheduling with deterministic gates;
121
+ - steer/final ordering, cancellation, WorkingContext, and Compaction;
122
+ - protocol exhaustion, exact-byte retry, and partial-output failure;
123
+ - resource-lock recovery, conflict prevention, and explicit release;
124
+ - real subprocess exits during Tool execution and final delivery, followed by SQLite recovery;
125
+ - recorded OpenAI and Anthropic SSE streams;
126
+ - `ruff`, `mypy`, wheel/sdist builds, `twine check`, and clean wheel installation.
127
+
128
+ Current limits:
129
+
130
+ - Hosted-model smoke and nika integration are separate acceptance work.
131
+ - Concurrent writers across multiple processes fail closed; they are not coordinated.
132
+ - Large-asset lifecycle, backup, and GC are not part of this release candidate.
133
+
134
+ ## Documents
135
+
136
+ - [AgentLoop design](docs/design/agent-loop.md)
137
+ - [Public interface](docs/design/loop-interface.md)
138
+ - [ReAct protocol](docs/design/react-protocol.md)
139
+ - [Verification matrix](docs/design/verification-matrix.md)
140
+ - [Development plan](docs/architecture/development-plan.md)
141
+ - [Changelog](CHANGELOG.md)
142
+ - [ADR-0002](docs/adr/0002-dsh-aligned-agent-loop.md) and [ADR-0003](docs/adr/0003-python-and-centralized-contracts.md)
143
+
144
+ ## Release
145
+
146
+ CI covers Python 3.11, 3.12, and 3.13. A `v*` tag runs the release workflow, which verifies the package, publishes wheel and sdist to PyPI through Trusted Publishing, and creates a GitHub Release.
147
+
148
+ This is a public repository. Do not commit credentials, private trajectories, internal endpoints, or personal data.
@@ -0,0 +1,120 @@
1
+ # nextloop
2
+
3
+ A small, embeddable Python AgentLoop with explicit execution, recovery, and delivery semantics.
4
+
5
+ Current version: **0.1.0rc1**.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ python -m pip install nextloop==0.1.0rc1
11
+ ```
12
+
13
+ For local development:
14
+
15
+ ```bash
16
+ uv venv --python 3.11 .venv
17
+ uv pip install --python .venv/bin/python -e '.[dev]'
18
+ ```
19
+
20
+ ## What it provides
21
+
22
+ - DSH-aligned Session/Turn/Step execution with 4D integer coordinates and writer fencing.
23
+ - Append-only Trajectory and O(Δ) `surface_op` watermark projection.
24
+ - In-memory `Inbox` serialization for steer and final commitment.
25
+ - Whole-batch Tool Schema validation, bounded parallel calls, and exclusive failure barriers.
26
+ - Closed five-variant `ToolOutcome`: `Completed`, `Skipped`, `Cancelled`, `UncertainSettled`, `UncertainHanging`.
27
+ - Bounded Provider retries, protocol correction, WorkingContext, Compaction, and cancellation.
28
+ - SQLite and in-memory EventStores, crash closers, and delivery-only recovery.
29
+ - OpenAI-compatible and Anthropic streaming Provider adapters.
30
+
31
+ It is a library, not an HTTP service, product bot, Router, EventBus, or multi-agent framework.
32
+
33
+ ## Public API
34
+
35
+ ```python
36
+ AgentLoop.run(TurnContext) -> TurnOutcome
37
+ AgentLoop.steer(session_id, content, *, input_id=None) -> bool
38
+ AgentLoop.cancel(session_id, cause="user_stop") -> bool
39
+ AgentLoop.recover(session_id, store, delivery) -> RecoveryOutcome
40
+ ```
41
+
42
+ The only four Adapter protocols are `EventStore`, `ModelProvider`, `ToolRuntime`, and `DeliveryOwner`. Context projection and Compaction are built in and configured through `LoopConfig`.
43
+
44
+ `ToolRegistry` is the built-in `ToolRuntime` implementation:
45
+
46
+ ```python
47
+ from nextloop import ToolRegistry, ToolSpec, ToolExecutionMode
48
+
49
+ registry = ToolRegistry()
50
+ registry.register(
51
+ ToolSpec(
52
+ "read",
53
+ "Read a file",
54
+ {
55
+ "type": "object",
56
+ "properties": {"path": {"type": "string"}},
57
+ "required": ["path"],
58
+ },
59
+ mode=ToolExecutionMode.PARALLEL,
60
+ ),
61
+ lambda arguments, context: "file contents",
62
+ )
63
+ ```
64
+
65
+ Run the complete fake-Provider example:
66
+
67
+ ```bash
68
+ python examples/basic.py
69
+ ```
70
+
71
+ It executes model → Tool → Observation → model → delivery without a hosted model.
72
+
73
+ ## Code structure
74
+
75
+ ```text
76
+ src/nextloop/
77
+ contracts.py # public schemas, ToolOutcome, four Protocols, LoopConfig
78
+ loop.py # AgentLoop and active Session registry
79
+ driver.py # thin Turn/Step orchestration and SessionActor
80
+ events/ # pure projection, response/outcome folds, crash repair
81
+ execute/ # model retries, Tool registration, batch scheduling
82
+ adapters/ # SQLite, memory, OpenAI, Anthropic
83
+ ```
84
+
85
+ `events/` performs no I/O. `execute/` owns side effects and classified failures. `driver.py` only composes them.
86
+
87
+ ## Verification
88
+
89
+ The release-candidate checks cover:
90
+
91
+ - text, Tool, multi-Step, mixed, empty, truncated, and malformed responses;
92
+ - whole-batch rejection and parallel/exclusive scheduling with deterministic gates;
93
+ - steer/final ordering, cancellation, WorkingContext, and Compaction;
94
+ - protocol exhaustion, exact-byte retry, and partial-output failure;
95
+ - resource-lock recovery, conflict prevention, and explicit release;
96
+ - real subprocess exits during Tool execution and final delivery, followed by SQLite recovery;
97
+ - recorded OpenAI and Anthropic SSE streams;
98
+ - `ruff`, `mypy`, wheel/sdist builds, `twine check`, and clean wheel installation.
99
+
100
+ Current limits:
101
+
102
+ - Hosted-model smoke and nika integration are separate acceptance work.
103
+ - Concurrent writers across multiple processes fail closed; they are not coordinated.
104
+ - Large-asset lifecycle, backup, and GC are not part of this release candidate.
105
+
106
+ ## Documents
107
+
108
+ - [AgentLoop design](docs/design/agent-loop.md)
109
+ - [Public interface](docs/design/loop-interface.md)
110
+ - [ReAct protocol](docs/design/react-protocol.md)
111
+ - [Verification matrix](docs/design/verification-matrix.md)
112
+ - [Development plan](docs/architecture/development-plan.md)
113
+ - [Changelog](CHANGELOG.md)
114
+ - [ADR-0002](docs/adr/0002-dsh-aligned-agent-loop.md) and [ADR-0003](docs/adr/0003-python-and-centralized-contracts.md)
115
+
116
+ ## Release
117
+
118
+ CI covers Python 3.11, 3.12, and 3.13. A `v*` tag runs the release workflow, which verifies the package, publishes wheel and sdist to PyPI through Trusted Publishing, and creates a GitHub Release.
119
+
120
+ This is a public repository. Do not commit credentials, private trajectories, internal endpoints, or personal data.
@@ -0,0 +1,66 @@
1
+ [build-system]
2
+ requires = ["setuptools>=77"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "nextloop"
7
+ version = "0.1.0rc1"
8
+ description = "An embeddable AgentLoop with explicit event, tool, recovery, and delivery semantics"
9
+ readme = "README.md"
10
+ requires-python = ">=3.11"
11
+ license = "MIT"
12
+ license-files = ["LICENSE"]
13
+ authors = [{name = "12bitsD", email = "bis12@163.com"}]
14
+ classifiers = [
15
+ "Development Status :: 3 - Alpha",
16
+ "Programming Language :: Python :: 3",
17
+ "Programming Language :: Python :: 3.11",
18
+ "Programming Language :: Python :: 3.12",
19
+ "Programming Language :: Python :: 3.13",
20
+ "Typing :: Typed",
21
+ ]
22
+ dependencies = [
23
+ "httpx>=0.27,<1",
24
+ "jsonschema>=4.23,<5",
25
+ ]
26
+
27
+ [project.optional-dependencies]
28
+ dev = [
29
+ "build>=1.2,<2",
30
+ "mypy>=1.13,<2",
31
+ "pytest>=8,<10",
32
+ "pytest-asyncio>=0.24,<2",
33
+ "ruff>=0.8,<1",
34
+ "twine>=5,<7",
35
+ "types-jsonschema>=4.23,<5",
36
+ ]
37
+
38
+ [project.urls]
39
+ Repository = "https://github.com/12bitsD/nextloop"
40
+
41
+ [tool.setuptools]
42
+ package-dir = {"" = "src"}
43
+
44
+ [tool.setuptools.packages.find]
45
+ where = ["src"]
46
+
47
+ [tool.setuptools.package-data]
48
+ nextloop = ["py.typed"]
49
+
50
+ [tool.pytest.ini_options]
51
+ addopts = "-ra"
52
+ asyncio_mode = "auto"
53
+ asyncio_default_fixture_loop_scope = "function"
54
+ testpaths = ["tests"]
55
+
56
+ [tool.ruff]
57
+ target-version = "py311"
58
+ line-length = 100
59
+
60
+ [tool.ruff.lint]
61
+ select = ["E", "F", "I", "UP", "B", "ASYNC", "SIM"]
62
+
63
+ [tool.mypy]
64
+ python_version = "3.11"
65
+ strict = true
66
+ packages = ["nextloop"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,96 @@
1
+ from .adapters.anthropic import AnthropicProvider
2
+ from .adapters.memory import InMemoryEventStore
3
+ from .adapters.openai import OpenAIProvider
4
+ from .adapters.sqlite import SQLiteEventStore
5
+ from .contracts import (
6
+ API_VERSION,
7
+ EVENT_SCHEMA_VERSION,
8
+ Cancelled,
9
+ CandidateRequest,
10
+ CapacityError,
11
+ Completed,
12
+ DeliveryOwner,
13
+ Event,
14
+ EventStore,
15
+ EventType,
16
+ FinalMessage,
17
+ FinishReason,
18
+ InvariantViolation,
19
+ LoopConfig,
20
+ Message,
21
+ ModelProvider,
22
+ ModelResponse,
23
+ ModelUsage,
24
+ NewEvent,
25
+ NextloopError,
26
+ ProtocolExhausted,
27
+ ProviderError,
28
+ RecoveryOutcome,
29
+ Skipped,
30
+ SurfaceOp,
31
+ ToolCall,
32
+ ToolExecutionMode,
33
+ ToolOutcome,
34
+ ToolRuntime,
35
+ ToolSpec,
36
+ TurnContext,
37
+ TurnOutcome,
38
+ TurnStatus,
39
+ UncertainHanging,
40
+ UncertainSettled,
41
+ ValidatedCall,
42
+ ValidationIssue,
43
+ new_id,
44
+ utc_now,
45
+ )
46
+ from .execute.tools import ToolContext, ToolRegistry
47
+ from .loop import AgentLoop
48
+
49
+ __all__ = [
50
+ "API_VERSION",
51
+ "EVENT_SCHEMA_VERSION",
52
+ "AgentLoop",
53
+ "AnthropicProvider",
54
+ "CandidateRequest",
55
+ "Cancelled",
56
+ "CapacityError",
57
+ "Completed",
58
+ "DeliveryOwner",
59
+ "Event",
60
+ "EventStore",
61
+ "EventType",
62
+ "FinalMessage",
63
+ "FinishReason",
64
+ "InMemoryEventStore",
65
+ "InvariantViolation",
66
+ "LoopConfig",
67
+ "Message",
68
+ "ModelProvider",
69
+ "ModelResponse",
70
+ "ModelUsage",
71
+ "NewEvent",
72
+ "NextloopError",
73
+ "OpenAIProvider",
74
+ "ProtocolExhausted",
75
+ "ProviderError",
76
+ "RecoveryOutcome",
77
+ "SQLiteEventStore",
78
+ "Skipped",
79
+ "SurfaceOp",
80
+ "ToolCall",
81
+ "ToolContext",
82
+ "ToolExecutionMode",
83
+ "ToolOutcome",
84
+ "ToolRegistry",
85
+ "ToolRuntime",
86
+ "ToolSpec",
87
+ "TurnContext",
88
+ "TurnOutcome",
89
+ "TurnStatus",
90
+ "UncertainHanging",
91
+ "UncertainSettled",
92
+ "ValidatedCall",
93
+ "ValidationIssue",
94
+ "new_id",
95
+ "utc_now",
96
+ ]
@@ -0,0 +1,6 @@
1
+ from .anthropic import AnthropicProvider
2
+ from .memory import InMemoryEventStore
3
+ from .openai import OpenAIProvider
4
+ from .sqlite import SQLiteEventStore
5
+
6
+ __all__ = ["AnthropicProvider", "InMemoryEventStore", "OpenAIProvider", "SQLiteEventStore"]
@@ -0,0 +1,25 @@
1
+ from __future__ import annotations
2
+
3
+ from collections.abc import AsyncIterator
4
+
5
+ import httpx
6
+
7
+
8
+ async def data_events(response: httpx.Response) -> AsyncIterator[tuple[str, str]]:
9
+ event = "message"
10
+ data: list[str] = []
11
+ async for line in response.aiter_lines():
12
+ if not line:
13
+ if data:
14
+ yield event, "\n".join(data)
15
+ event = "message"
16
+ data = []
17
+ continue
18
+ if line.startswith(":"):
19
+ continue
20
+ if line.startswith("event:"):
21
+ event = line[6:].strip()
22
+ elif line.startswith("data:"):
23
+ data.append(line[5:].lstrip())
24
+ if data:
25
+ yield event, "\n".join(data)