nextloop 0.1.0rc1__tar.gz → 0.2.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.
- {nextloop-0.1.0rc1/src/nextloop.egg-info → nextloop-0.2.0rc1}/PKG-INFO +13 -4
- {nextloop-0.1.0rc1 → nextloop-0.2.0rc1}/README.md +12 -3
- {nextloop-0.1.0rc1 → nextloop-0.2.0rc1}/pyproject.toml +1 -1
- {nextloop-0.1.0rc1 → nextloop-0.2.0rc1}/src/nextloop/__init__.py +9 -0
- {nextloop-0.1.0rc1 → nextloop-0.2.0rc1}/src/nextloop/adapters/memory.py +6 -1
- {nextloop-0.1.0rc1 → nextloop-0.2.0rc1}/src/nextloop/adapters/sqlite.py +1 -1
- {nextloop-0.1.0rc1 → nextloop-0.2.0rc1}/src/nextloop/contracts.py +19 -0
- {nextloop-0.1.0rc1 → nextloop-0.2.0rc1}/src/nextloop/events/project.py +18 -1
- nextloop-0.2.0rc1/src/nextloop/skills.py +166 -0
- {nextloop-0.1.0rc1 → nextloop-0.2.0rc1/src/nextloop.egg-info}/PKG-INFO +13 -4
- {nextloop-0.1.0rc1 → nextloop-0.2.0rc1}/src/nextloop.egg-info/SOURCES.txt +2 -0
- {nextloop-0.1.0rc1 → nextloop-0.2.0rc1}/tests/test_loop.py +3 -0
- nextloop-0.2.0rc1/tests/test_skills.py +113 -0
- {nextloop-0.1.0rc1 → nextloop-0.2.0rc1}/LICENSE +0 -0
- {nextloop-0.1.0rc1 → nextloop-0.2.0rc1}/setup.cfg +0 -0
- {nextloop-0.1.0rc1 → nextloop-0.2.0rc1}/src/nextloop/adapters/__init__.py +0 -0
- {nextloop-0.1.0rc1 → nextloop-0.2.0rc1}/src/nextloop/adapters/_sse.py +0 -0
- {nextloop-0.1.0rc1 → nextloop-0.2.0rc1}/src/nextloop/adapters/anthropic.py +0 -0
- {nextloop-0.1.0rc1 → nextloop-0.2.0rc1}/src/nextloop/adapters/openai.py +0 -0
- {nextloop-0.1.0rc1 → nextloop-0.2.0rc1}/src/nextloop/driver.py +0 -0
- {nextloop-0.1.0rc1 → nextloop-0.2.0rc1}/src/nextloop/events/__init__.py +0 -0
- {nextloop-0.1.0rc1 → nextloop-0.2.0rc1}/src/nextloop/events/outcome.py +0 -0
- {nextloop-0.1.0rc1 → nextloop-0.2.0rc1}/src/nextloop/events/repair.py +0 -0
- {nextloop-0.1.0rc1 → nextloop-0.2.0rc1}/src/nextloop/events/response.py +0 -0
- {nextloop-0.1.0rc1 → nextloop-0.2.0rc1}/src/nextloop/execute/__init__.py +0 -0
- {nextloop-0.1.0rc1 → nextloop-0.2.0rc1}/src/nextloop/execute/batch.py +0 -0
- {nextloop-0.1.0rc1 → nextloop-0.2.0rc1}/src/nextloop/execute/model.py +0 -0
- {nextloop-0.1.0rc1 → nextloop-0.2.0rc1}/src/nextloop/execute/tools.py +0 -0
- {nextloop-0.1.0rc1 → nextloop-0.2.0rc1}/src/nextloop/loop.py +0 -0
- {nextloop-0.1.0rc1 → nextloop-0.2.0rc1}/src/nextloop/py.typed +0 -0
- {nextloop-0.1.0rc1 → nextloop-0.2.0rc1}/src/nextloop.egg-info/dependency_links.txt +0 -0
- {nextloop-0.1.0rc1 → nextloop-0.2.0rc1}/src/nextloop.egg-info/requires.txt +0 -0
- {nextloop-0.1.0rc1 → nextloop-0.2.0rc1}/src/nextloop.egg-info/top_level.txt +0 -0
- {nextloop-0.1.0rc1 → nextloop-0.2.0rc1}/tests/test_events.py +0 -0
- {nextloop-0.1.0rc1 → nextloop-0.2.0rc1}/tests/test_failures.py +0 -0
- {nextloop-0.1.0rc1 → nextloop-0.2.0rc1}/tests/test_providers.py +0 -0
- {nextloop-0.1.0rc1 → nextloop-0.2.0rc1}/tests/test_stores.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: nextloop
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0rc1
|
|
4
4
|
Summary: An embeddable AgentLoop with explicit event, tool, recovery, and delivery semantics
|
|
5
5
|
Author-email: 12bitsD <bis12@163.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -30,12 +30,12 @@ Dynamic: license-file
|
|
|
30
30
|
|
|
31
31
|
A small, embeddable Python AgentLoop with explicit execution, recovery, and delivery semantics.
|
|
32
32
|
|
|
33
|
-
Current version: **0.
|
|
33
|
+
Current version: **0.2.0rc1**.
|
|
34
34
|
|
|
35
35
|
## Install
|
|
36
36
|
|
|
37
37
|
```bash
|
|
38
|
-
python -m pip install nextloop==0.
|
|
38
|
+
python -m pip install nextloop==0.2.0rc1
|
|
39
39
|
```
|
|
40
40
|
|
|
41
41
|
For local development:
|
|
@@ -55,6 +55,7 @@ uv pip install --python .venv/bin/python -e '.[dev]'
|
|
|
55
55
|
- Bounded Provider retries, protocol correction, WorkingContext, Compaction, and cancellation.
|
|
56
56
|
- SQLite and in-memory EventStores, crash closers, and delivery-only recovery.
|
|
57
57
|
- OpenAI-compatible and Anthropic streaming Provider adapters.
|
|
58
|
+
- Directory-based `SkillRegistry` for progressive, on-demand `SKILL.md` loading with dependency and version validation.
|
|
58
59
|
|
|
59
60
|
It is a library, not an HTTP service, product bot, Router, EventBus, or multi-agent framework.
|
|
60
61
|
|
|
@@ -98,6 +99,12 @@ python examples/basic.py
|
|
|
98
99
|
|
|
99
100
|
It executes model → Tool → Observation → model → delivery without a hosted model.
|
|
100
101
|
|
|
102
|
+
For a directory-based Skill example, run:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
python examples/skills_demo.py
|
|
106
|
+
```
|
|
107
|
+
|
|
101
108
|
## Code structure
|
|
102
109
|
|
|
103
110
|
```text
|
|
@@ -123,11 +130,12 @@ The release-candidate checks cover:
|
|
|
123
130
|
- resource-lock recovery, conflict prevention, and explicit release;
|
|
124
131
|
- real subprocess exits during Tool execution and final delivery, followed by SQLite recovery;
|
|
125
132
|
- recorded OpenAI and Anthropic SSE streams;
|
|
133
|
+
- 12 live Kimi scenarios across both protocols, real Tool usage, parallel execution, recovery, steer, cancellation, Compaction, and WorkingContext;
|
|
126
134
|
- `ruff`, `mypy`, wheel/sdist builds, `twine check`, and clean wheel installation.
|
|
127
135
|
|
|
128
136
|
Current limits:
|
|
129
137
|
|
|
130
|
-
-
|
|
138
|
+
- nika integration is separate acceptance work.
|
|
131
139
|
- Concurrent writers across multiple processes fail closed; they are not coordinated.
|
|
132
140
|
- Large-asset lifecycle, backup, and GC are not part of this release candidate.
|
|
133
141
|
|
|
@@ -136,6 +144,7 @@ Current limits:
|
|
|
136
144
|
- [AgentLoop design](docs/design/agent-loop.md)
|
|
137
145
|
- [Public interface](docs/design/loop-interface.md)
|
|
138
146
|
- [ReAct protocol](docs/design/react-protocol.md)
|
|
147
|
+
- [Directory-based SkillRegistry](docs/design/skills.md)
|
|
139
148
|
- [Verification matrix](docs/design/verification-matrix.md)
|
|
140
149
|
- [Development plan](docs/architecture/development-plan.md)
|
|
141
150
|
- [Changelog](CHANGELOG.md)
|
|
@@ -2,12 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
A small, embeddable Python AgentLoop with explicit execution, recovery, and delivery semantics.
|
|
4
4
|
|
|
5
|
-
Current version: **0.
|
|
5
|
+
Current version: **0.2.0rc1**.
|
|
6
6
|
|
|
7
7
|
## Install
|
|
8
8
|
|
|
9
9
|
```bash
|
|
10
|
-
python -m pip install nextloop==0.
|
|
10
|
+
python -m pip install nextloop==0.2.0rc1
|
|
11
11
|
```
|
|
12
12
|
|
|
13
13
|
For local development:
|
|
@@ -27,6 +27,7 @@ uv pip install --python .venv/bin/python -e '.[dev]'
|
|
|
27
27
|
- Bounded Provider retries, protocol correction, WorkingContext, Compaction, and cancellation.
|
|
28
28
|
- SQLite and in-memory EventStores, crash closers, and delivery-only recovery.
|
|
29
29
|
- OpenAI-compatible and Anthropic streaming Provider adapters.
|
|
30
|
+
- Directory-based `SkillRegistry` for progressive, on-demand `SKILL.md` loading with dependency and version validation.
|
|
30
31
|
|
|
31
32
|
It is a library, not an HTTP service, product bot, Router, EventBus, or multi-agent framework.
|
|
32
33
|
|
|
@@ -70,6 +71,12 @@ python examples/basic.py
|
|
|
70
71
|
|
|
71
72
|
It executes model → Tool → Observation → model → delivery without a hosted model.
|
|
72
73
|
|
|
74
|
+
For a directory-based Skill example, run:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
python examples/skills_demo.py
|
|
78
|
+
```
|
|
79
|
+
|
|
73
80
|
## Code structure
|
|
74
81
|
|
|
75
82
|
```text
|
|
@@ -95,11 +102,12 @@ The release-candidate checks cover:
|
|
|
95
102
|
- resource-lock recovery, conflict prevention, and explicit release;
|
|
96
103
|
- real subprocess exits during Tool execution and final delivery, followed by SQLite recovery;
|
|
97
104
|
- recorded OpenAI and Anthropic SSE streams;
|
|
105
|
+
- 12 live Kimi scenarios across both protocols, real Tool usage, parallel execution, recovery, steer, cancellation, Compaction, and WorkingContext;
|
|
98
106
|
- `ruff`, `mypy`, wheel/sdist builds, `twine check`, and clean wheel installation.
|
|
99
107
|
|
|
100
108
|
Current limits:
|
|
101
109
|
|
|
102
|
-
-
|
|
110
|
+
- nika integration is separate acceptance work.
|
|
103
111
|
- Concurrent writers across multiple processes fail closed; they are not coordinated.
|
|
104
112
|
- Large-asset lifecycle, backup, and GC are not part of this release candidate.
|
|
105
113
|
|
|
@@ -108,6 +116,7 @@ Current limits:
|
|
|
108
116
|
- [AgentLoop design](docs/design/agent-loop.md)
|
|
109
117
|
- [Public interface](docs/design/loop-interface.md)
|
|
110
118
|
- [ReAct protocol](docs/design/react-protocol.md)
|
|
119
|
+
- [Directory-based SkillRegistry](docs/design/skills.md)
|
|
111
120
|
- [Verification matrix](docs/design/verification-matrix.md)
|
|
112
121
|
- [Development plan](docs/architecture/development-plan.md)
|
|
113
122
|
- [Changelog](CHANGELOG.md)
|
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "nextloop"
|
|
7
|
-
version = "0.
|
|
7
|
+
version = "0.2.0rc1"
|
|
8
8
|
description = "An embeddable AgentLoop with explicit event, tool, recovery, and delivery semantics"
|
|
9
9
|
readme = "README.md"
|
|
10
10
|
requires-python = ">=3.11"
|
|
@@ -26,6 +26,9 @@ from .contracts import (
|
|
|
26
26
|
ProtocolExhausted,
|
|
27
27
|
ProviderError,
|
|
28
28
|
RecoveryOutcome,
|
|
29
|
+
SkillDocument,
|
|
30
|
+
SkillError,
|
|
31
|
+
SkillSpec,
|
|
29
32
|
Skipped,
|
|
30
33
|
SurfaceOp,
|
|
31
34
|
ToolCall,
|
|
@@ -45,6 +48,7 @@ from .contracts import (
|
|
|
45
48
|
)
|
|
46
49
|
from .execute.tools import ToolContext, ToolRegistry
|
|
47
50
|
from .loop import AgentLoop
|
|
51
|
+
from .skills import SkillRegistry, skill_view
|
|
48
52
|
|
|
49
53
|
__all__ = [
|
|
50
54
|
"API_VERSION",
|
|
@@ -75,6 +79,10 @@ __all__ = [
|
|
|
75
79
|
"ProviderError",
|
|
76
80
|
"RecoveryOutcome",
|
|
77
81
|
"SQLiteEventStore",
|
|
82
|
+
"SkillDocument",
|
|
83
|
+
"SkillError",
|
|
84
|
+
"SkillRegistry",
|
|
85
|
+
"SkillSpec",
|
|
78
86
|
"Skipped",
|
|
79
87
|
"SurfaceOp",
|
|
80
88
|
"ToolCall",
|
|
@@ -92,5 +100,6 @@ __all__ = [
|
|
|
92
100
|
"ValidatedCall",
|
|
93
101
|
"ValidationIssue",
|
|
94
102
|
"new_id",
|
|
103
|
+
"skill_view",
|
|
95
104
|
"utc_now",
|
|
96
105
|
]
|
|
@@ -7,6 +7,7 @@ from collections.abc import Sequence
|
|
|
7
7
|
|
|
8
8
|
from ..contracts import (
|
|
9
9
|
Event,
|
|
10
|
+
EventType,
|
|
10
11
|
InvariantViolation,
|
|
11
12
|
NewEvent,
|
|
12
13
|
SurfaceOp,
|
|
@@ -69,7 +70,11 @@ class InMemoryEventStore:
|
|
|
69
70
|
return tuple(
|
|
70
71
|
copy.deepcopy(event)
|
|
71
72
|
for event in events
|
|
72
|
-
if event.seq >= epoch_seq
|
|
73
|
+
if event.seq >= epoch_seq
|
|
74
|
+
and (
|
|
75
|
+
event.surface_op != SurfaceOp.NONE
|
|
76
|
+
or event.event_type == EventType.TOOL_BATCH_REJECTED
|
|
77
|
+
)
|
|
73
78
|
)
|
|
74
79
|
|
|
75
80
|
async def load_recovery(self, session_id: str) -> Sequence[Event]:
|
|
@@ -173,7 +173,7 @@ class SQLiteEventStore:
|
|
|
173
173
|
SELECT MAX(seq) FROM session_events
|
|
174
174
|
WHERE session_id = ? AND surface_op = 'epoch'
|
|
175
175
|
), 1)
|
|
176
|
-
AND surface_op != 'none'
|
|
176
|
+
AND (surface_op != 'none' OR event_type = 'tool/batch-rejected')
|
|
177
177
|
ORDER BY seq
|
|
178
178
|
""",
|
|
179
179
|
(session_id, session_id),
|
|
@@ -25,6 +25,10 @@ class NextloopError(Exception):
|
|
|
25
25
|
"""Base error for nextloop."""
|
|
26
26
|
|
|
27
27
|
|
|
28
|
+
class SkillError(NextloopError):
|
|
29
|
+
"""Raised when a Skill document or its dependencies are invalid."""
|
|
30
|
+
|
|
31
|
+
|
|
28
32
|
class InvariantViolation(NextloopError):
|
|
29
33
|
"""Raised when seq, idempotency, or writer_epoch invariants fail."""
|
|
30
34
|
|
|
@@ -251,6 +255,21 @@ class UncertainHanging:
|
|
|
251
255
|
ToolOutcome = Completed | Skipped | Cancelled | UncertainSettled | UncertainHanging
|
|
252
256
|
|
|
253
257
|
|
|
258
|
+
@dataclass(frozen=True)
|
|
259
|
+
class SkillSpec:
|
|
260
|
+
name: str
|
|
261
|
+
description: str
|
|
262
|
+
path: str
|
|
263
|
+
requires_tools: tuple[str, ...] = ()
|
|
264
|
+
min_nextloop: str | None = None
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
@dataclass(frozen=True)
|
|
268
|
+
class SkillDocument:
|
|
269
|
+
spec: SkillSpec
|
|
270
|
+
body: str
|
|
271
|
+
|
|
272
|
+
|
|
254
273
|
class TurnStatus(StrEnum):
|
|
255
274
|
SUCCEEDED = "succeeded"
|
|
256
275
|
FAILED = "failed"
|
|
@@ -93,6 +93,11 @@ def project_events(
|
|
|
93
93
|
config: LoopConfig,
|
|
94
94
|
tools: Sequence[ToolSpec],
|
|
95
95
|
) -> Projection:
|
|
96
|
+
rejected_steps = {
|
|
97
|
+
(event.turn, event.step)
|
|
98
|
+
for event in events
|
|
99
|
+
if event.event_type == EventType.TOOL_BATCH_REJECTED
|
|
100
|
+
}
|
|
96
101
|
messages = [Message(role="system", content=config.system_prompt)]
|
|
97
102
|
messages.extend(config.bootstrap_messages)
|
|
98
103
|
for event in events:
|
|
@@ -105,7 +110,19 @@ def project_events(
|
|
|
105
110
|
EventType.ASSISTANT_MESSAGE,
|
|
106
111
|
EventType.TOOL_RESULT,
|
|
107
112
|
):
|
|
108
|
-
|
|
113
|
+
message = message_from_data(event.payload["message"])
|
|
114
|
+
if (
|
|
115
|
+
event.event_type == EventType.ASSISTANT_MESSAGE
|
|
116
|
+
and (event.turn, event.step) in rejected_steps
|
|
117
|
+
):
|
|
118
|
+
if not message.content:
|
|
119
|
+
continue
|
|
120
|
+
message = Message(
|
|
121
|
+
role=message.role,
|
|
122
|
+
content=message.content,
|
|
123
|
+
provider_data=message.provider_data,
|
|
124
|
+
)
|
|
125
|
+
messages.append(message)
|
|
109
126
|
request = CandidateRequest(
|
|
110
127
|
session_id=session_id,
|
|
111
128
|
turn=turn,
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import re
|
|
4
|
+
from collections.abc import Callable, Mapping, Sequence
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Any
|
|
7
|
+
|
|
8
|
+
from .contracts import API_VERSION, Completed, SkillDocument, SkillError, SkillSpec
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
class SkillRegistry:
|
|
12
|
+
def __init__(
|
|
13
|
+
self,
|
|
14
|
+
paths: Sequence[str | Path],
|
|
15
|
+
*,
|
|
16
|
+
available_tools: Sequence[str] | None = None,
|
|
17
|
+
) -> None:
|
|
18
|
+
self._documents: dict[str, Path] = {}
|
|
19
|
+
self._specs: dict[str, SkillSpec] = {}
|
|
20
|
+
files = []
|
|
21
|
+
for raw_path in paths:
|
|
22
|
+
path = Path(raw_path).expanduser().resolve()
|
|
23
|
+
if path.is_file():
|
|
24
|
+
if path.name != "SKILL.md":
|
|
25
|
+
raise SkillError(f"{path}: expected a SKILL.md file")
|
|
26
|
+
files.append(path)
|
|
27
|
+
elif path.is_dir():
|
|
28
|
+
files.extend(sorted(path.rglob("SKILL.md")))
|
|
29
|
+
else:
|
|
30
|
+
raise SkillError(f"{path}: Skill path does not exist")
|
|
31
|
+
for path in files:
|
|
32
|
+
spec = self._read_spec(path)
|
|
33
|
+
if spec.name in self._specs:
|
|
34
|
+
previous = self._specs[spec.name].path
|
|
35
|
+
raise SkillError(
|
|
36
|
+
f"{path}: duplicate Skill name '{spec.name}' (already defined in {previous})"
|
|
37
|
+
)
|
|
38
|
+
if available_tools is not None:
|
|
39
|
+
missing = sorted(set(spec.requires_tools) - set(available_tools))
|
|
40
|
+
if missing:
|
|
41
|
+
raise SkillError(f"{path}: missing required Tool(s): {', '.join(missing)}")
|
|
42
|
+
self._documents[spec.name] = path
|
|
43
|
+
self._specs[spec.name] = spec
|
|
44
|
+
|
|
45
|
+
def list(self) -> tuple[SkillSpec, ...]:
|
|
46
|
+
return tuple(self._specs[name] for name in sorted(self._specs))
|
|
47
|
+
|
|
48
|
+
def load(self, name: str) -> SkillDocument:
|
|
49
|
+
path = self._documents.get(name)
|
|
50
|
+
if path is None:
|
|
51
|
+
raise SkillError(f"Skill '{name}' was not found")
|
|
52
|
+
try:
|
|
53
|
+
text = path.read_text(encoding="utf-8")
|
|
54
|
+
except OSError as exc:
|
|
55
|
+
raise SkillError(f"{path}: cannot read Skill: {exc}") from exc
|
|
56
|
+
_, body = _split_frontmatter(text, path)
|
|
57
|
+
return SkillDocument(spec=self._specs[name], body=body)
|
|
58
|
+
|
|
59
|
+
@staticmethod
|
|
60
|
+
def _read_spec(path: Path) -> SkillSpec:
|
|
61
|
+
try:
|
|
62
|
+
with path.open(encoding="utf-8") as source:
|
|
63
|
+
header_lines = []
|
|
64
|
+
for index, line in enumerate(source):
|
|
65
|
+
if index > 100:
|
|
66
|
+
raise SkillError(f"{path}: frontmatter exceeds 100 lines")
|
|
67
|
+
header_lines.append(line)
|
|
68
|
+
if index > 0 and line.strip() == "---":
|
|
69
|
+
break
|
|
70
|
+
else:
|
|
71
|
+
raise SkillError(f"{path}: frontmatter is not closed with ---")
|
|
72
|
+
except OSError as exc:
|
|
73
|
+
raise SkillError(f"{path}: cannot read Skill metadata: {exc}") from exc
|
|
74
|
+
header = "".join(header_lines)
|
|
75
|
+
metadata, _ = _split_frontmatter(header, path)
|
|
76
|
+
if metadata is None:
|
|
77
|
+
raise SkillError(f"{path}: expected frontmatter between --- lines")
|
|
78
|
+
fields = _parse_fields(metadata, path)
|
|
79
|
+
name = fields.get("name", "").strip()
|
|
80
|
+
description = fields.get("description", "").strip()
|
|
81
|
+
if not name:
|
|
82
|
+
raise SkillError(f"{path}: frontmatter field 'name' is required")
|
|
83
|
+
if not description:
|
|
84
|
+
raise SkillError(f"{path}: frontmatter field 'description' is required")
|
|
85
|
+
requires_tools = _parse_tool_list(fields.get("requires_tools", ""))
|
|
86
|
+
min_nextloop = fields.get("min_nextloop") or None
|
|
87
|
+
if min_nextloop is not None:
|
|
88
|
+
_check_version(min_nextloop, path)
|
|
89
|
+
return SkillSpec(
|
|
90
|
+
name=name,
|
|
91
|
+
description=description,
|
|
92
|
+
path=str(path),
|
|
93
|
+
requires_tools=requires_tools,
|
|
94
|
+
min_nextloop=min_nextloop,
|
|
95
|
+
)
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
def skill_view(registry: SkillRegistry) -> Callable[[Mapping[str, Any], Any], Completed]:
|
|
99
|
+
def handler(arguments: Mapping[str, Any], context: Any) -> Completed:
|
|
100
|
+
name = arguments.get("name")
|
|
101
|
+
if not isinstance(name, str) or not name.strip():
|
|
102
|
+
return Completed("Skill name must be a nonempty string", is_error=True)
|
|
103
|
+
try:
|
|
104
|
+
document = registry.load(name.strip())
|
|
105
|
+
except SkillError as exc:
|
|
106
|
+
return Completed(str(exc), is_error=True)
|
|
107
|
+
return Completed(
|
|
108
|
+
document.body,
|
|
109
|
+
structured={
|
|
110
|
+
"skill": {
|
|
111
|
+
"name": document.spec.name,
|
|
112
|
+
"description": document.spec.description,
|
|
113
|
+
"path": document.spec.path,
|
|
114
|
+
"requires_tools": list(document.spec.requires_tools),
|
|
115
|
+
}
|
|
116
|
+
},
|
|
117
|
+
)
|
|
118
|
+
|
|
119
|
+
return handler
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def _split_frontmatter(text: str, path: Path) -> tuple[str | None, str]:
|
|
123
|
+
lines = text.splitlines()
|
|
124
|
+
if not lines or lines[0].strip() != "---":
|
|
125
|
+
raise SkillError(f"{path}: expected frontmatter starting with ---")
|
|
126
|
+
for index in range(1, len(lines)):
|
|
127
|
+
if lines[index].strip() == "---":
|
|
128
|
+
return "\n".join(lines[1:index]), "\n".join(lines[index + 1 :]).lstrip("\n")
|
|
129
|
+
raise SkillError(f"{path}: frontmatter is not closed with ---")
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
def _parse_fields(metadata: str, path: Path) -> dict[str, str]:
|
|
133
|
+
fields: dict[str, str] = {}
|
|
134
|
+
for line in metadata.splitlines():
|
|
135
|
+
if not line.strip() or line.lstrip().startswith("#"):
|
|
136
|
+
continue
|
|
137
|
+
if ":" not in line:
|
|
138
|
+
raise SkillError(f"{path}: unsupported frontmatter line: {line}")
|
|
139
|
+
key, value = line.split(":", 1)
|
|
140
|
+
key = key.strip()
|
|
141
|
+
value = value.strip()
|
|
142
|
+
if len(value) >= 2 and value[0] == value[-1] and value[0] in ("'", '"'):
|
|
143
|
+
value = value[1:-1]
|
|
144
|
+
fields[key] = value
|
|
145
|
+
return fields
|
|
146
|
+
|
|
147
|
+
|
|
148
|
+
def _parse_tool_list(value: str) -> tuple[str, ...]:
|
|
149
|
+
stripped = value.strip()
|
|
150
|
+
if stripped.startswith("[") and stripped.endswith("]"):
|
|
151
|
+
stripped = stripped[1:-1]
|
|
152
|
+
return tuple(sorted({item.strip() for item in stripped.split(",") if item.strip()}))
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def _check_version(min_nextloop: str, path: Path) -> None:
|
|
156
|
+
required = _version_tuple(min_nextloop, path)
|
|
157
|
+
current = _version_tuple(API_VERSION, path)
|
|
158
|
+
if current < required:
|
|
159
|
+
raise SkillError(f"{path}: requires nextloop >= {min_nextloop}, current is {API_VERSION}")
|
|
160
|
+
|
|
161
|
+
|
|
162
|
+
def _version_tuple(value: str, path: Path) -> tuple[int, ...]:
|
|
163
|
+
match = re.match(r"^\s*(\d+(?:\.\d+){0,2})", value)
|
|
164
|
+
if match is None:
|
|
165
|
+
raise SkillError(f"{path}: invalid nextloop version '{value}'")
|
|
166
|
+
return tuple(int(part) for part in match.group(1).split("."))
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: nextloop
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0rc1
|
|
4
4
|
Summary: An embeddable AgentLoop with explicit event, tool, recovery, and delivery semantics
|
|
5
5
|
Author-email: 12bitsD <bis12@163.com>
|
|
6
6
|
License-Expression: MIT
|
|
@@ -30,12 +30,12 @@ Dynamic: license-file
|
|
|
30
30
|
|
|
31
31
|
A small, embeddable Python AgentLoop with explicit execution, recovery, and delivery semantics.
|
|
32
32
|
|
|
33
|
-
Current version: **0.
|
|
33
|
+
Current version: **0.2.0rc1**.
|
|
34
34
|
|
|
35
35
|
## Install
|
|
36
36
|
|
|
37
37
|
```bash
|
|
38
|
-
python -m pip install nextloop==0.
|
|
38
|
+
python -m pip install nextloop==0.2.0rc1
|
|
39
39
|
```
|
|
40
40
|
|
|
41
41
|
For local development:
|
|
@@ -55,6 +55,7 @@ uv pip install --python .venv/bin/python -e '.[dev]'
|
|
|
55
55
|
- Bounded Provider retries, protocol correction, WorkingContext, Compaction, and cancellation.
|
|
56
56
|
- SQLite and in-memory EventStores, crash closers, and delivery-only recovery.
|
|
57
57
|
- OpenAI-compatible and Anthropic streaming Provider adapters.
|
|
58
|
+
- Directory-based `SkillRegistry` for progressive, on-demand `SKILL.md` loading with dependency and version validation.
|
|
58
59
|
|
|
59
60
|
It is a library, not an HTTP service, product bot, Router, EventBus, or multi-agent framework.
|
|
60
61
|
|
|
@@ -98,6 +99,12 @@ python examples/basic.py
|
|
|
98
99
|
|
|
99
100
|
It executes model → Tool → Observation → model → delivery without a hosted model.
|
|
100
101
|
|
|
102
|
+
For a directory-based Skill example, run:
|
|
103
|
+
|
|
104
|
+
```bash
|
|
105
|
+
python examples/skills_demo.py
|
|
106
|
+
```
|
|
107
|
+
|
|
101
108
|
## Code structure
|
|
102
109
|
|
|
103
110
|
```text
|
|
@@ -123,11 +130,12 @@ The release-candidate checks cover:
|
|
|
123
130
|
- resource-lock recovery, conflict prevention, and explicit release;
|
|
124
131
|
- real subprocess exits during Tool execution and final delivery, followed by SQLite recovery;
|
|
125
132
|
- recorded OpenAI and Anthropic SSE streams;
|
|
133
|
+
- 12 live Kimi scenarios across both protocols, real Tool usage, parallel execution, recovery, steer, cancellation, Compaction, and WorkingContext;
|
|
126
134
|
- `ruff`, `mypy`, wheel/sdist builds, `twine check`, and clean wheel installation.
|
|
127
135
|
|
|
128
136
|
Current limits:
|
|
129
137
|
|
|
130
|
-
-
|
|
138
|
+
- nika integration is separate acceptance work.
|
|
131
139
|
- Concurrent writers across multiple processes fail closed; they are not coordinated.
|
|
132
140
|
- Large-asset lifecycle, backup, and GC are not part of this release candidate.
|
|
133
141
|
|
|
@@ -136,6 +144,7 @@ Current limits:
|
|
|
136
144
|
- [AgentLoop design](docs/design/agent-loop.md)
|
|
137
145
|
- [Public interface](docs/design/loop-interface.md)
|
|
138
146
|
- [ReAct protocol](docs/design/react-protocol.md)
|
|
147
|
+
- [Directory-based SkillRegistry](docs/design/skills.md)
|
|
139
148
|
- [Verification matrix](docs/design/verification-matrix.md)
|
|
140
149
|
- [Development plan](docs/architecture/development-plan.md)
|
|
141
150
|
- [Changelog](CHANGELOG.md)
|
|
@@ -6,6 +6,7 @@ src/nextloop/contracts.py
|
|
|
6
6
|
src/nextloop/driver.py
|
|
7
7
|
src/nextloop/loop.py
|
|
8
8
|
src/nextloop/py.typed
|
|
9
|
+
src/nextloop/skills.py
|
|
9
10
|
src/nextloop.egg-info/PKG-INFO
|
|
10
11
|
src/nextloop.egg-info/SOURCES.txt
|
|
11
12
|
src/nextloop.egg-info/dependency_links.txt
|
|
@@ -30,4 +31,5 @@ tests/test_events.py
|
|
|
30
31
|
tests/test_failures.py
|
|
31
32
|
tests/test_loop.py
|
|
32
33
|
tests/test_providers.py
|
|
34
|
+
tests/test_skills.py
|
|
33
35
|
tests/test_stores.py
|
|
@@ -117,6 +117,9 @@ async def test_invalid_batch_executes_nothing_then_corrects():
|
|
|
117
117
|
events = await store.load_recovery("s")
|
|
118
118
|
assert any(event.event_type == EventType.TOOL_BATCH_REJECTED for event in events)
|
|
119
119
|
assert not any(event.event_type == EventType.TOOL_CALL for event in events)
|
|
120
|
+
second_request = provider.requests[1]
|
|
121
|
+
assert all(not message.tool_calls for message in second_request.messages)
|
|
122
|
+
assert second_request.messages[-1].content.startswith("[Protocol correction]")
|
|
120
123
|
|
|
121
124
|
|
|
122
125
|
@pytest.mark.asyncio
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
|
|
5
|
+
import pytest
|
|
6
|
+
|
|
7
|
+
from nextloop import SkillError, SkillRegistry, skill_view
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
def write_skill(
|
|
11
|
+
directory: Path, name="coding", description="用于代码修改与验证", body="先读代码,再运行测试。"
|
|
12
|
+
):
|
|
13
|
+
directory.mkdir(parents=True, exist_ok=True)
|
|
14
|
+
path = directory / "SKILL.md"
|
|
15
|
+
path.write_text(
|
|
16
|
+
f"""---
|
|
17
|
+
name: {name}
|
|
18
|
+
description: {description}
|
|
19
|
+
requires_tools: read_file, bash
|
|
20
|
+
---
|
|
21
|
+
|
|
22
|
+
{body}
|
|
23
|
+
""",
|
|
24
|
+
encoding="utf-8",
|
|
25
|
+
)
|
|
26
|
+
return path
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def test_directory_discovers_metadata_and_loads_body_on_demand(tmp_path):
|
|
30
|
+
write_skill(tmp_path / "coding")
|
|
31
|
+
write_skill(
|
|
32
|
+
tmp_path / "debugging",
|
|
33
|
+
name="debugging",
|
|
34
|
+
description="用于故障诊断",
|
|
35
|
+
body="先复现,再定位。",
|
|
36
|
+
)
|
|
37
|
+
registry = SkillRegistry([tmp_path])
|
|
38
|
+
|
|
39
|
+
specs = registry.list()
|
|
40
|
+
assert [spec.name for spec in specs] == ["coding", "debugging"]
|
|
41
|
+
assert specs[0].requires_tools == ("bash", "read_file")
|
|
42
|
+
|
|
43
|
+
document = registry.load("coding")
|
|
44
|
+
assert document.body == "先读代码,再运行测试。"
|
|
45
|
+
assert document.spec.description == "用于代码修改与验证"
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
def test_direct_file_and_current_body_on_next_load(tmp_path):
|
|
49
|
+
path = write_skill(tmp_path / "coding")
|
|
50
|
+
registry = SkillRegistry([path])
|
|
51
|
+
assert registry.load("coding").body == "先读代码,再运行测试。"
|
|
52
|
+
|
|
53
|
+
path.write_text(path.read_text().replace("先读代码,再运行测试。", "修改后重新验证。"))
|
|
54
|
+
assert registry.load("coding").body == "修改后重新验证。"
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
def test_duplicate_names_fail_with_both_paths(tmp_path):
|
|
58
|
+
first = write_skill(tmp_path / "a" / "coding")
|
|
59
|
+
second = write_skill(tmp_path / "b" / "coding")
|
|
60
|
+
with pytest.raises(SkillError, match="duplicate Skill name") as caught:
|
|
61
|
+
SkillRegistry([tmp_path])
|
|
62
|
+
assert str(first) in str(caught.value)
|
|
63
|
+
assert str(second) in str(caught.value)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def test_missing_required_fields_fail(tmp_path):
|
|
67
|
+
path = tmp_path / "bad" / "SKILL.md"
|
|
68
|
+
path.parent.mkdir()
|
|
69
|
+
path.write_text("---\ndescription: missing name\n---\nbody\n")
|
|
70
|
+
with pytest.raises(SkillError, match="field 'name' is required"):
|
|
71
|
+
SkillRegistry([tmp_path])
|
|
72
|
+
|
|
73
|
+
path.write_text("---\nname: bad\n---\nbody\n")
|
|
74
|
+
with pytest.raises(SkillError, match="field 'description' is required"):
|
|
75
|
+
SkillRegistry([tmp_path])
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def test_requires_tools_validation(tmp_path):
|
|
79
|
+
write_skill(tmp_path / "coding")
|
|
80
|
+
with pytest.raises(SkillError, match="missing required Tool"):
|
|
81
|
+
SkillRegistry([tmp_path], available_tools=["read_file"])
|
|
82
|
+
registry = SkillRegistry([tmp_path], available_tools=["read_file", "bash"])
|
|
83
|
+
assert registry.list()[0].requires_tools == ("bash", "read_file")
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
def test_version_validation(tmp_path):
|
|
87
|
+
write_skill(tmp_path / "coding")
|
|
88
|
+
path = tmp_path / "coding" / "SKILL.md"
|
|
89
|
+
path.write_text(
|
|
90
|
+
path.read_text().replace("requires_tools: read_file, bash", "min_nextloop: '999.0'")
|
|
91
|
+
)
|
|
92
|
+
with pytest.raises(SkillError, match="requires nextloop"):
|
|
93
|
+
SkillRegistry([tmp_path])
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
def test_skill_view_returns_body_and_honest_not_found(tmp_path):
|
|
97
|
+
write_skill(tmp_path / "coding")
|
|
98
|
+
registry = SkillRegistry([tmp_path])
|
|
99
|
+
handler = skill_view(registry)
|
|
100
|
+
|
|
101
|
+
result = handler({"name": "coding"}, context=None)
|
|
102
|
+
assert result.is_error is False
|
|
103
|
+
assert result.content == "先读代码,再运行测试。"
|
|
104
|
+
assert result.structured["skill"]["requires_tools"] == ["bash", "read_file"]
|
|
105
|
+
|
|
106
|
+
missing = handler({"name": "missing"}, context=None)
|
|
107
|
+
assert missing.is_error is True
|
|
108
|
+
assert "was not found" in missing.content
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
def test_missing_path_fails(tmp_path):
|
|
112
|
+
with pytest.raises(SkillError, match="does not exist"):
|
|
113
|
+
SkillRegistry([tmp_path / "missing"])
|
|
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
|