nextloop 0.3.0rc2__tar.gz → 0.4.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 (89) hide show
  1. {nextloop-0.3.0rc2/src/nextloop.egg-info → nextloop-0.4.0rc1}/PKG-INFO +48 -7
  2. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/README.md +47 -6
  3. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/docs/design/harness.md +30 -1
  4. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/examples/harness-skills/echo/SKILL.md +1 -1
  5. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/examples/harness.toml +1 -1
  6. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/pyproject.toml +1 -1
  7. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/src/nextloop/__init__.py +34 -0
  8. nextloop-0.4.0rc1/src/nextloop/adapters/__init__.py +14 -0
  9. nextloop-0.4.0rc1/src/nextloop/adapters/observing.py +236 -0
  10. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/src/nextloop/contracts.py +111 -3
  11. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/src/nextloop/driver.py +2 -0
  12. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/src/nextloop/events/__init__.py +3 -0
  13. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/src/nextloop/events/outcome.py +36 -7
  14. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/src/nextloop/events/repair.py +5 -3
  15. nextloop-0.4.0rc1/src/nextloop/events/trace.py +351 -0
  16. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/src/nextloop/execute/batch.py +27 -11
  17. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/src/nextloop/execute/model.py +84 -13
  18. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/src/nextloop/execute/stdio.py +1 -1
  19. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/src/nextloop/harness.py +82 -6
  20. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1/src/nextloop.egg-info}/PKG-INFO +48 -7
  21. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/src/nextloop.egg-info/SOURCES.txt +3 -0
  22. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/tests/test_harness.py +1 -1
  23. nextloop-0.4.0rc1/tests/test_observability.py +800 -0
  24. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/tests/test_skills.py +1 -1
  25. nextloop-0.3.0rc2/src/nextloop/adapters/__init__.py +0 -6
  26. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/LICENSE +0 -0
  27. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/MANIFEST.in +0 -0
  28. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/docs/adr/0001-embeddable-agent-loop.md +0 -0
  29. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/docs/adr/0002-dsh-aligned-agent-loop.md +0 -0
  30. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/docs/adr/0003-python-and-centralized-contracts.md +0 -0
  31. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/docs/architecture/agent-loop-capability-review.md +0 -0
  32. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/docs/architecture/development-plan.md +0 -0
  33. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/docs/architecture/discussion-roadmap.md +0 -0
  34. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/docs/architecture/feature-worklist.md +0 -0
  35. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/docs/architecture/requirements.md +0 -0
  36. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/docs/design/agent-loop.md +0 -0
  37. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/docs/design/context-builder.md +0 -0
  38. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/docs/design/loop-interface.md +0 -0
  39. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/docs/design/react-protocol.md +0 -0
  40. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/docs/design/skills.md +0 -0
  41. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/docs/design/verification-matrix.md +0 -0
  42. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/docs/research/2026-11-02-dsh-primary-sources.md +0 -0
  43. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/docs/research/2026-11-02-loop-evidence-notes.md +0 -0
  44. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/docs/research/2026-11-03-hermes-turn-control.md +0 -0
  45. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/docs/research/2026-11-03-tool-batch-failures.md +0 -0
  46. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/docs/research/2026-11-03-tool-call-validation.md +0 -0
  47. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/docs/research/2026-11-03-yomi-turn-control.md +0 -0
  48. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/docs/research/2026-11-06-open-source-agent-loops.md +0 -0
  49. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/docs/research/2026-11-06-react-tool-event-recovery.md +0 -0
  50. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/examples/basic.py +0 -0
  51. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/examples/live_smoke.py +0 -0
  52. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/examples/python_tools.py +0 -0
  53. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/examples/skills/coding/SKILL.md +0 -0
  54. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/examples/skills_demo.py +0 -0
  55. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/examples/workers/cpp_worker.cpp +0 -0
  56. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/examples/workers/python_worker.py +0 -0
  57. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/examples/workers/rust_worker.rs +0 -0
  58. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/setup.cfg +0 -0
  59. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/src/nextloop/adapters/_sse.py +0 -0
  60. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/src/nextloop/adapters/anthropic.py +0 -0
  61. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/src/nextloop/adapters/memory.py +0 -0
  62. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/src/nextloop/adapters/openai.py +0 -0
  63. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/src/nextloop/adapters/sqlite.py +0 -0
  64. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/src/nextloop/cli.py +0 -0
  65. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/src/nextloop/events/project.py +0 -0
  66. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/src/nextloop/events/response.py +0 -0
  67. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/src/nextloop/execute/__init__.py +0 -0
  68. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/src/nextloop/execute/cleanup.py +0 -0
  69. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/src/nextloop/execute/composite.py +0 -0
  70. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/src/nextloop/execute/tools.py +0 -0
  71. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/src/nextloop/loop.py +0 -0
  72. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/src/nextloop/py.typed +0 -0
  73. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/src/nextloop/skills.py +0 -0
  74. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/src/nextloop.egg-info/dependency_links.txt +0 -0
  75. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/src/nextloop.egg-info/entry_points.txt +0 -0
  76. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/src/nextloop.egg-info/requires.txt +0 -0
  77. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/src/nextloop.egg-info/top_level.txt +0 -0
  78. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/tests/test_aggregate_close.py +0 -0
  79. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/tests/test_cli.py +0 -0
  80. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/tests/test_events.py +0 -0
  81. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/tests/test_failures.py +0 -0
  82. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/tests/test_loop.py +0 -0
  83. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/tests/test_providers.py +0 -0
  84. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/tests/test_stdio.py +0 -0
  85. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/tests/test_stdio_cleanup.py +0 -0
  86. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/tests/test_stdio_frames.py +0 -0
  87. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/tests/test_stdio_safety.py +0 -0
  88. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/tests/test_stores.py +0 -0
  89. {nextloop-0.3.0rc2 → nextloop-0.4.0rc1}/tests/test_worker_conformance.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nextloop
3
- Version: 0.3.0rc2
3
+ Version: 0.4.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
@@ -28,14 +28,18 @@ Dynamic: license-file
28
28
 
29
29
  # nextloop
30
30
 
31
- A small, embeddable Python AgentLoop with explicit execution, recovery, and delivery semantics.
31
+ **Small core. Serious runtime semantics.**
32
32
 
33
- Current version: **0.3.0rc2**.
33
+ nextloop is an embeddable Python AgentLoop for developers who want to build their own agent runtime — not inherit a heavyweight framework. Deterministic ReAct execution, append-only history, explicit crash recovery, typed Tools, and committed-event observability, all in a package you can actually read.
34
+
35
+ **Your agent, your rules. No magic, no black box.**
36
+
37
+ Current version: **0.4.0rc1**.
34
38
 
35
39
  ## Install
36
40
 
37
41
  ```bash
38
- python -m pip install nextloop==0.3.0rc2
42
+ python -m pip install nextloop==0.4.0rc1
39
43
  ```
40
44
 
41
45
  For local development:
@@ -45,7 +49,17 @@ uv venv --python 3.11 .venv
45
49
  uv pip install --python .venv/bin/python -e '.[dev]'
46
50
  ```
47
51
 
48
- ## What it provides
52
+ ## Why nextloop
53
+
54
+ - **Execution you can reason about.** DSH-aligned Session/Turn/Step/attempt coordinates, writer fencing, and append-only Trajectory instead of implicit runner state.
55
+ - **Crash recovery without blind replay.** Resource locks, uncertain outcomes, crash closers, and delivery-only recovery tell you what is known, what is unknown, and what must not run twice.
56
+ - **Tools without framework lock-in.** Register Python functions directly, or run persistent Rust and C++ workers over stdio JSON-RPC. Schema validation, parallel calls, and exclusive barriers are built in.
57
+ - **Observability from committed facts.** Structured Model/Tool/Turn traces, asynchronous Exporters, and Session history. No second execution path and no telemetry-driven control flow.
58
+ - **Small, explicit integration.** Assemble Providers, Stores, Tools, and Skills with `harness.toml`, or keep everything in Python. OpenAI-compatible and Anthropic Providers are included.
59
+
60
+ It is a library, not an HTTP service, product bot, Router, EventBus, or multi-agent framework. **The Loop stays in your application; the decisions stay with you.**
61
+
62
+ ## Under the hood
49
63
 
50
64
  - DSH-aligned Session/Turn/Step execution with 4D integer coordinates and writer fencing.
51
65
  - Append-only Trajectory and O(Δ) `surface_op` watermark projection.
@@ -58,8 +72,7 @@ uv pip install --python .venv/bin/python -e '.[dev]'
58
72
  - Directory-based `SkillRegistry` for progressive, on-demand `SKILL.md` loading with dependency and version validation.
59
73
  - Strict `harness.toml` assembly, Python `module:register`, and persistent Python/Rust/C++ stdio workers.
60
74
  - Offline `nextloop` CLI for configuration, worker, Tool, and Skill diagnostics.
61
-
62
- It is a library, not an HTTP service, product bot, Router, EventBus, or multi-agent framework.
75
+ - Committed-event observability with Model/Tool/Turn DTOs, asynchronous Exporters, and Session history.
63
76
 
64
77
  ## Public API
65
78
 
@@ -82,6 +95,34 @@ nextloop skills view echo-guide examples/harness.toml
82
95
 
83
96
  The example Python module is found when running from a source checkout with `PYTHONPATH=examples`. Examples and reference workers ship in the repository and sdist; wheels contain the library and CLI. No API key is needed for these diagnostic commands.
84
97
 
98
+ ## Observability
99
+
100
+ Enable committed-event traces with a built-in stdout Exporter:
101
+
102
+ ```toml
103
+ [trace]
104
+ exporter = "stdout"
105
+ ```
106
+
107
+ Or pass a sync/async function directly:
108
+
109
+ ```python
110
+ harness = Harness.load("harness.toml", exporter=my_exporter)
111
+ ```
112
+
113
+ Use `module.path:function` in TOML for a custom Exporter. No Exporter is enabled by default. Every Exporter receives `ModelCallTrace`, `ToolCallTrace`, or `TurnTrace`; exports are queued asynchronously and flushed by `await harness.close()`. Close has a bounded wait, but it cannot forcibly stop an already running synchronous Exporter thread; late residual calls are reported through `on_error`.
114
+
115
+ ```python
116
+ turn = await harness.get_turn(1)
117
+ if turn is not None:
118
+ for tool in turn.tool_calls:
119
+ print(tool.name, tool.result, tool.duration_ms)
120
+
121
+ history = await harness.history(from_turn=1, to_turn=10)
122
+ ```
123
+
124
+ History works with memory and SQLite Stores even when no Exporter is configured.
125
+
85
126
  `ToolRegistry` is the built-in `ToolRuntime` implementation:
86
127
 
87
128
  ```python
@@ -1,13 +1,17 @@
1
1
  # nextloop
2
2
 
3
- A small, embeddable Python AgentLoop with explicit execution, recovery, and delivery semantics.
3
+ **Small core. Serious runtime semantics.**
4
4
 
5
- Current version: **0.3.0rc2**.
5
+ nextloop is an embeddable Python AgentLoop for developers who want to build their own agent runtime — not inherit a heavyweight framework. Deterministic ReAct execution, append-only history, explicit crash recovery, typed Tools, and committed-event observability, all in a package you can actually read.
6
+
7
+ **Your agent, your rules. No magic, no black box.**
8
+
9
+ Current version: **0.4.0rc1**.
6
10
 
7
11
  ## Install
8
12
 
9
13
  ```bash
10
- python -m pip install nextloop==0.3.0rc2
14
+ python -m pip install nextloop==0.4.0rc1
11
15
  ```
12
16
 
13
17
  For local development:
@@ -17,7 +21,17 @@ uv venv --python 3.11 .venv
17
21
  uv pip install --python .venv/bin/python -e '.[dev]'
18
22
  ```
19
23
 
20
- ## What it provides
24
+ ## Why nextloop
25
+
26
+ - **Execution you can reason about.** DSH-aligned Session/Turn/Step/attempt coordinates, writer fencing, and append-only Trajectory instead of implicit runner state.
27
+ - **Crash recovery without blind replay.** Resource locks, uncertain outcomes, crash closers, and delivery-only recovery tell you what is known, what is unknown, and what must not run twice.
28
+ - **Tools without framework lock-in.** Register Python functions directly, or run persistent Rust and C++ workers over stdio JSON-RPC. Schema validation, parallel calls, and exclusive barriers are built in.
29
+ - **Observability from committed facts.** Structured Model/Tool/Turn traces, asynchronous Exporters, and Session history. No second execution path and no telemetry-driven control flow.
30
+ - **Small, explicit integration.** Assemble Providers, Stores, Tools, and Skills with `harness.toml`, or keep everything in Python. OpenAI-compatible and Anthropic Providers are included.
31
+
32
+ It is a library, not an HTTP service, product bot, Router, EventBus, or multi-agent framework. **The Loop stays in your application; the decisions stay with you.**
33
+
34
+ ## Under the hood
21
35
 
22
36
  - DSH-aligned Session/Turn/Step execution with 4D integer coordinates and writer fencing.
23
37
  - Append-only Trajectory and O(Δ) `surface_op` watermark projection.
@@ -30,8 +44,7 @@ uv pip install --python .venv/bin/python -e '.[dev]'
30
44
  - Directory-based `SkillRegistry` for progressive, on-demand `SKILL.md` loading with dependency and version validation.
31
45
  - Strict `harness.toml` assembly, Python `module:register`, and persistent Python/Rust/C++ stdio workers.
32
46
  - Offline `nextloop` CLI for configuration, worker, Tool, and Skill diagnostics.
33
-
34
- It is a library, not an HTTP service, product bot, Router, EventBus, or multi-agent framework.
47
+ - Committed-event observability with Model/Tool/Turn DTOs, asynchronous Exporters, and Session history.
35
48
 
36
49
  ## Public API
37
50
 
@@ -54,6 +67,34 @@ nextloop skills view echo-guide examples/harness.toml
54
67
 
55
68
  The example Python module is found when running from a source checkout with `PYTHONPATH=examples`. Examples and reference workers ship in the repository and sdist; wheels contain the library and CLI. No API key is needed for these diagnostic commands.
56
69
 
70
+ ## Observability
71
+
72
+ Enable committed-event traces with a built-in stdout Exporter:
73
+
74
+ ```toml
75
+ [trace]
76
+ exporter = "stdout"
77
+ ```
78
+
79
+ Or pass a sync/async function directly:
80
+
81
+ ```python
82
+ harness = Harness.load("harness.toml", exporter=my_exporter)
83
+ ```
84
+
85
+ Use `module.path:function` in TOML for a custom Exporter. No Exporter is enabled by default. Every Exporter receives `ModelCallTrace`, `ToolCallTrace`, or `TurnTrace`; exports are queued asynchronously and flushed by `await harness.close()`. Close has a bounded wait, but it cannot forcibly stop an already running synchronous Exporter thread; late residual calls are reported through `on_error`.
86
+
87
+ ```python
88
+ turn = await harness.get_turn(1)
89
+ if turn is not None:
90
+ for tool in turn.tool_calls:
91
+ print(tool.name, tool.result, tool.duration_ms)
92
+
93
+ history = await harness.history(from_turn=1, to_turn=10)
94
+ ```
95
+
96
+ History works with memory and SQLite Stores even when no Exporter is configured.
97
+
57
98
  `ToolRegistry` is the built-in `ToolRuntime` implementation:
58
99
 
59
100
  ```python
@@ -6,7 +6,7 @@
6
6
 
7
7
  ```toml
8
8
  schema = "nextloop.harness/v1"
9
- min_nextloop = "0.3.0rc2"
9
+ min_nextloop = "0.4.0rc1"
10
10
 
11
11
  [provider]
12
12
  protocol = "openai" # or anthropic
@@ -59,6 +59,35 @@ await harness.close()
59
59
 
60
60
  Skills remain instructions only. Their metadata is added to the system prompt, and the read-only `skill_view` Tool loads a body on demand. Loading a Skill never runs adjacent scripts or expands Tool permissions.
61
61
 
62
+ ## Observability
63
+
64
+ Observability is disabled by default. Enable the built-in JSON Lines Exporter with:
65
+
66
+ ```toml
67
+ [trace]
68
+ exporter = "stdout"
69
+ ```
70
+
71
+ Use `module.path:function` for a custom Exporter, or pass `exporter=` to `Harness.load()`. Runtime and TOML Exporters are called in configuration order. A callable may be synchronous or asynchronous; an object may implement `export(trace)` instead.
72
+
73
+ Committed Events are projected to immutable `ModelCallTrace`, `ToolCallTrace`, and `TurnTrace` objects. The underlying Store append succeeds before records enter a bounded asynchronous queue. Exporter errors, slow calls, and queue overflow do not change Turn results; dropped records are counted and reported. `await harness.close()` performs a bounded flush and closes the Store. The queue is not a durable outbox.
74
+
75
+ The close timeout bounds queue and worker waiting, not arbitrary user code execution. Python cannot forcibly stop a synchronous Exporter already running in a worker thread, so a timed-out synchronous call may still finish and produce late side effects. This residual is reported through `on_error`; it is not a completed flush. Applications that require no side effects after close must use cancellation-aware asynchronous Exporters or wait for their custom calls to finish before closing.
76
+
77
+ `ModelCallTrace` includes measured Provider timing, `purpose="inference"|"compaction"`, model, output, and usage. `ToolCallTrace` includes arguments, result, outcome, resources, and measured execution timing. `TurnTrace` closes at turn/end rather than delivery and includes final content and aggregate usage. Recovered operations use `timing_source="unknown"` and never invent end times.
78
+
79
+ Query a closed Turn or a Session's history without configuring an Exporter:
80
+
81
+ ```python
82
+ turn = await harness.get_turn(1)
83
+ if turn is not None:
84
+ tools = turn.tool_calls
85
+
86
+ history = await harness.history(from_turn=1, to_turn=10)
87
+ ```
88
+
89
+ History reads the complete EventStore log and uses the same TraceProjector as live export. Only new-format Events are supported; missing measured Model/Tool fields produce `timing_source="unknown"`, not estimated durations.
90
+
62
91
  ## Stdio protocol
63
92
 
64
93
  The protocol version is `nextloop.stdio/v1`. Messages are one JSON-RPC 2.0 object per line on stdout; logs belong on stderr. Supported methods are `initialize`, `tools/list`, `tools/call`, `notifications/cancelled`, `ping`, and `shutdown`.
@@ -2,6 +2,6 @@
2
2
  name: echo-guide
3
3
  description: Explain when to use the declared echo Tools
4
4
  requires_tools: [python_echo, python_worker__echo]
5
- min_nextloop: 0.3.0rc2
5
+ min_nextloop: 0.4.0rc1
6
6
  ---
7
7
  Use an echo Tool only when the user asks to repeat text. Return its result unchanged.
@@ -1,5 +1,5 @@
1
1
  schema = "nextloop.harness/v1"
2
- min_nextloop = "0.3.0rc2"
2
+ min_nextloop = "0.4.0rc1"
3
3
 
4
4
  [provider]
5
5
  protocol = "openai"
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "nextloop"
7
- version = "0.3.0rc2"
7
+ version = "0.4.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"
@@ -1,5 +1,6 @@
1
1
  from .adapters.anthropic import AnthropicProvider
2
2
  from .adapters.memory import InMemoryEventStore
3
+ from .adapters.observing import ObservingEventStore, StdoutExporter
3
4
  from .adapters.openai import OpenAIProvider
4
5
  from .adapters.sqlite import SQLiteEventStore
5
6
  from .contracts import (
@@ -7,6 +8,7 @@ from .contracts import (
7
8
  EVENT_SCHEMA_VERSION,
8
9
  HARNESS_SCHEMA,
9
10
  STDIO_PROTOCOL_VERSION,
11
+ TRACE_SCHEMA,
10
12
  Cancelled,
11
13
  CandidateRequest,
12
14
  CapacityError,
@@ -22,6 +24,9 @@ from .contracts import (
22
24
  InvariantViolation,
23
25
  LoopConfig,
24
26
  Message,
27
+ ModelCallPurpose,
28
+ ModelCallStatus,
29
+ ModelCallTrace,
25
30
  ModelProvider,
26
31
  ModelResponse,
27
32
  ModelUsage,
@@ -38,15 +43,25 @@ from .contracts import (
38
43
  Skipped,
39
44
  StoreConfig,
40
45
  SurfaceOp,
46
+ TimingSource,
41
47
  ToolCall,
48
+ ToolCallTrace,
42
49
  ToolConfig,
43
50
  ToolExecutionMode,
51
+ ToolExecutionTiming,
44
52
  ToolOutcome,
53
+ ToolOutcomeKind,
45
54
  ToolRuntime,
46
55
  ToolSpec,
56
+ TraceConfig,
57
+ TraceExporter,
58
+ TraceExporterInput,
59
+ TraceRecord,
47
60
  TurnContext,
48
61
  TurnOutcome,
49
62
  TurnStatus,
63
+ TurnTrace,
64
+ TurnTraceStatus,
50
65
  UncertainHanging,
51
66
  UncertainSettled,
52
67
  ValidatedCall,
@@ -54,6 +69,7 @@ from .contracts import (
54
69
  new_id,
55
70
  utc_now,
56
71
  )
72
+ from .events.trace import TraceProjector, project_traces
57
73
  from .execute.composite import CompositeToolRuntime
58
74
  from .execute.stdio import StdioDriver, StdioProtocolError
59
75
  from .execute.tools import ToolContext, ToolRegistry
@@ -66,6 +82,7 @@ __all__ = [
66
82
  "EVENT_SCHEMA_VERSION",
67
83
  "HARNESS_SCHEMA",
68
84
  "STDIO_PROTOCOL_VERSION",
85
+ "TRACE_SCHEMA",
69
86
  "AgentLoop",
70
87
  "AnthropicProvider",
71
88
  "CandidateRequest",
@@ -87,11 +104,15 @@ __all__ = [
87
104
  "LoopConfig",
88
105
  "MemoryDeliveryOwner",
89
106
  "Message",
107
+ "ModelCallPurpose",
108
+ "ModelCallStatus",
109
+ "ModelCallTrace",
90
110
  "ModelProvider",
91
111
  "ModelResponse",
92
112
  "ModelUsage",
93
113
  "NewEvent",
94
114
  "NextloopError",
115
+ "ObservingEventStore",
95
116
  "OpenAIProvider",
96
117
  "ProtocolExhausted",
97
118
  "ProviderConfig",
@@ -106,25 +127,38 @@ __all__ = [
106
127
  "Skipped",
107
128
  "StdioDriver",
108
129
  "StdioProtocolError",
130
+ "StdoutExporter",
109
131
  "StoreConfig",
110
132
  "SurfaceOp",
133
+ "TimingSource",
111
134
  "ToolCall",
135
+ "ToolCallTrace",
112
136
  "ToolConfig",
113
137
  "ToolContext",
114
138
  "ToolExecutionMode",
139
+ "ToolExecutionTiming",
115
140
  "ToolOutcome",
141
+ "ToolOutcomeKind",
116
142
  "ToolRegistry",
117
143
  "ToolRuntime",
118
144
  "ToolSpec",
145
+ "TraceConfig",
146
+ "TraceExporter",
147
+ "TraceExporterInput",
148
+ "TraceProjector",
149
+ "TraceRecord",
119
150
  "TurnContext",
120
151
  "TurnOutcome",
121
152
  "TurnStatus",
153
+ "TurnTrace",
154
+ "TurnTraceStatus",
122
155
  "UncertainHanging",
123
156
  "UncertainSettled",
124
157
  "ValidatedCall",
125
158
  "ValidationIssue",
126
159
  "load_harness_spec",
127
160
  "new_id",
161
+ "project_traces",
128
162
  "skill_view",
129
163
  "utc_now",
130
164
  ]
@@ -0,0 +1,14 @@
1
+ from .anthropic import AnthropicProvider
2
+ from .memory import InMemoryEventStore
3
+ from .observing import ObservingEventStore, StdoutExporter
4
+ from .openai import OpenAIProvider
5
+ from .sqlite import SQLiteEventStore
6
+
7
+ __all__ = [
8
+ "AnthropicProvider",
9
+ "InMemoryEventStore",
10
+ "ObservingEventStore",
11
+ "OpenAIProvider",
12
+ "SQLiteEventStore",
13
+ "StdoutExporter",
14
+ ]
@@ -0,0 +1,236 @@
1
+ from __future__ import annotations
2
+
3
+ import asyncio
4
+ import dataclasses
5
+ import inspect
6
+ import json
7
+ import sys
8
+ from collections.abc import Callable, Sequence
9
+ from typing import Any, TextIO, cast
10
+
11
+ from ..contracts import (
12
+ TRACE_SCHEMA,
13
+ Event,
14
+ EventStore,
15
+ ModelCallTrace,
16
+ NewEvent,
17
+ ToolCallTrace,
18
+ TraceExporterInput,
19
+ TraceRecord,
20
+ TurnTrace,
21
+ )
22
+ from ..events.trace import TraceProjector, project_traces
23
+ from ..execute.cleanup import wait_for_cleanup
24
+
25
+ TraceErrorHandler = Callable[[Exception, TraceRecord | None], None]
26
+
27
+
28
+ class StdoutExporter:
29
+ def __init__(self, stream: TextIO | None = None) -> None:
30
+ self.stream = stream
31
+
32
+ def export(self, trace: TraceRecord) -> None:
33
+ if isinstance(trace, ModelCallTrace):
34
+ trace_type = "model_call"
35
+ elif isinstance(trace, ToolCallTrace):
36
+ trace_type = "tool_call"
37
+ else:
38
+ trace_type = "turn"
39
+ output = {
40
+ "schema": TRACE_SCHEMA,
41
+ "trace_type": trace_type,
42
+ "data": dataclasses.asdict(trace),
43
+ }
44
+ stream = self.stream or sys.stdout
45
+ stream.write(json.dumps(output, ensure_ascii=False) + "\n")
46
+ stream.flush()
47
+
48
+
49
+ class ObservingEventStore:
50
+ def __init__(
51
+ self,
52
+ store: EventStore,
53
+ exporters: Sequence[TraceExporterInput],
54
+ *,
55
+ max_queue_size: int = 1000,
56
+ close_timeout: float = 5.0,
57
+ on_error: TraceErrorHandler | None = None,
58
+ ) -> None:
59
+ if max_queue_size <= 0 or close_timeout <= 0:
60
+ raise ValueError("max_queue_size and close_timeout must be positive")
61
+ self._store = store
62
+ self._exporters = tuple(exporters)
63
+ self._projector = TraceProjector()
64
+ self._projector_lock = asyncio.Lock()
65
+ self._seeded_sessions: set[str] = set()
66
+ self._queue: asyncio.Queue[TraceRecord] = asyncio.Queue(maxsize=max_queue_size)
67
+ self._worker_task: asyncio.Task[None] | None = None
68
+ self._in_flight: TraceRecord | None = None
69
+ self._close_timeout = close_timeout
70
+ self._on_error = on_error
71
+ self._closed = False
72
+ self._close_lock = asyncio.Lock()
73
+ self.dropped_count = 0
74
+
75
+ async def attach_writer(self, session_id: str) -> tuple[int, int, int]:
76
+ result = await self._store.attach_writer(session_id)
77
+ try:
78
+ async with self._projector_lock:
79
+ self._projector.advance_seq(session_id, result[1])
80
+ except Exception as exc:
81
+ self._report_error(exc, None)
82
+ return result
83
+
84
+ async def load_surface(self, session_id: str) -> Sequence[Event]:
85
+ return await self._store.load_surface(session_id)
86
+
87
+ async def load_recovery(self, session_id: str) -> Sequence[Event]:
88
+ events = await self._store.load_recovery(session_id)
89
+ if session_id not in self._seeded_sessions:
90
+ try:
91
+ async with self._projector_lock:
92
+ self._projector.seed(events)
93
+ self._seeded_sessions.add(session_id)
94
+ except Exception as exc:
95
+ self._report_error(exc, None)
96
+ return events
97
+
98
+ async def append(
99
+ self,
100
+ session_id: str,
101
+ writer_epoch: int,
102
+ expected_seq: int,
103
+ events: Sequence[NewEvent],
104
+ ) -> Sequence[Event]:
105
+ committed = await self._store.append(session_id, writer_epoch, expected_seq, events)
106
+ try:
107
+ async with self._projector_lock:
108
+ records = self._projector.feed(committed)
109
+ self._seeded_sessions.add(session_id)
110
+ for record in records:
111
+ self._enqueue(record)
112
+ except Exception as exc:
113
+ self._report_error(exc, None)
114
+ return committed
115
+
116
+ def _enqueue(self, record: TraceRecord) -> None:
117
+ if self._closed:
118
+ self.dropped_count += 1
119
+ self._report_error(RuntimeError("Trace Store is closed; dropping trace"), record)
120
+ return
121
+ if self._worker_task is None or self._worker_task.done():
122
+ self._worker_task = asyncio.create_task(self._worker())
123
+ try:
124
+ self._queue.put_nowait(record)
125
+ except asyncio.QueueFull:
126
+ self.dropped_count += 1
127
+ self._report_error(BufferError("Trace export queue is full; dropping trace"), record)
128
+
129
+ async def _worker(self) -> None:
130
+ while True:
131
+ record = await self._queue.get()
132
+ self._in_flight = record
133
+ try:
134
+ for exporter in self._exporters:
135
+ try:
136
+ await _export(exporter, record)
137
+ except Exception as exc:
138
+ self._report_error(exc, record)
139
+ finally:
140
+ self._in_flight = None
141
+ self._queue.task_done()
142
+
143
+ def _report_error(self, error: Exception, record: TraceRecord | None) -> None:
144
+ try:
145
+ if self._on_error is not None:
146
+ self._on_error(error, record)
147
+ else:
148
+ print(f"nextloop trace export error: {error}", file=sys.stderr)
149
+ except Exception as fallback_error:
150
+ print(f"nextloop trace error handler failed: {fallback_error}", file=sys.stderr)
151
+
152
+ async def flush(self, timeout_seconds: float | None = None) -> bool:
153
+ try:
154
+ await asyncio.wait_for(self._queue.join(), timeout=timeout_seconds)
155
+ return True
156
+ except TimeoutError:
157
+ self._report_error(TimeoutError("Timed out flushing trace exports"), None)
158
+ return False
159
+
160
+ async def close(self) -> None:
161
+ async with self._close_lock:
162
+ if self._closed:
163
+ return
164
+ self._closed = True
165
+ cancelled = await wait_for_cleanup(asyncio.create_task(self._close()))
166
+ if cancelled:
167
+ raise asyncio.CancelledError()
168
+
169
+ async def _close(self) -> None:
170
+ try:
171
+ deadline = asyncio.get_running_loop().time() + self._close_timeout
172
+ flushed = await self.flush(self._close_timeout)
173
+ pending = self._queue.qsize() + int(self._in_flight is not None)
174
+ if not flushed and pending:
175
+ self.dropped_count += pending
176
+ self._report_error(
177
+ RuntimeError(f"Closing trace Store with {pending} unexported records"),
178
+ self._in_flight,
179
+ )
180
+ if self._worker_task is not None:
181
+ self._worker_task.cancel()
182
+ remaining = max(0.0, deadline - asyncio.get_running_loop().time())
183
+ try:
184
+ await asyncio.wait_for(asyncio.shield(self._worker_task), timeout=remaining)
185
+ except TimeoutError:
186
+ self._report_error(
187
+ TimeoutError("Trace exporter did not stop before close timeout"), None
188
+ )
189
+ except asyncio.CancelledError:
190
+ if not self._worker_task.done():
191
+ raise
192
+ finally:
193
+ close = getattr(self._store, "close", None)
194
+ if callable(close):
195
+ result = close()
196
+ if inspect.isawaitable(result):
197
+ await result
198
+
199
+ async def history(
200
+ self, session_id: str, *, from_turn: int = 1, to_turn: int | None = None
201
+ ) -> tuple[TraceRecord, ...]:
202
+ return await _query_history(self._store, session_id, from_turn=from_turn, to_turn=to_turn)
203
+
204
+ async def get_turn(self, session_id: str, turn: int) -> TurnTrace | None:
205
+ return await _get_turn(self._store, session_id, turn)
206
+
207
+
208
+ async def _export(exporter: TraceExporterInput, record: TraceRecord) -> None:
209
+ export = getattr(exporter, "export", None)
210
+ callback = export if callable(export) else cast(Callable[[TraceRecord], Any], exporter)
211
+ if inspect.iscoroutinefunction(callback):
212
+ result = callback(record)
213
+ else:
214
+ result = await asyncio.to_thread(callback, record)
215
+ if inspect.isawaitable(result):
216
+ await result
217
+
218
+
219
+ async def _get_turn(store: EventStore, session_id: str, turn: int) -> TurnTrace | None:
220
+ records = await _query_history(store, session_id, from_turn=turn, to_turn=turn)
221
+ return next((record for record in records if isinstance(record, TurnTrace)), None)
222
+
223
+
224
+ async def _query_history(
225
+ store: EventStore,
226
+ session_id: str,
227
+ *,
228
+ from_turn: int = 1,
229
+ to_turn: int | None = None,
230
+ ) -> tuple[TraceRecord, ...]:
231
+ events = await store.load_recovery(session_id)
232
+ return tuple(
233
+ record
234
+ for record in project_traces(events)
235
+ if record.turn >= from_turn and (to_turn is None or record.turn <= to_turn)
236
+ )