nextloop 0.5.0rc1__tar.gz → 0.5.0rc2__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 (113) hide show
  1. {nextloop-0.5.0rc1/src/nextloop.egg-info → nextloop-0.5.0rc2}/PKG-INFO +24 -10
  2. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/README.md +23 -9
  3. nextloop-0.5.0rc2/docs/adr/0005-pending-input.md +31 -0
  4. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/docs/design/harness.md +13 -1
  5. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/pyproject.toml +1 -1
  6. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/src/nextloop/__init__.py +2 -0
  7. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/src/nextloop/adapters/anthropic.py +23 -2
  8. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/src/nextloop/adapters/memory.py +1 -1
  9. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/src/nextloop/adapters/observing.py +19 -3
  10. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/src/nextloop/adapters/openai.py +30 -5
  11. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/src/nextloop/adapters/sqlite.py +4 -1
  12. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/src/nextloop/contracts.py +16 -3
  13. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/src/nextloop/driver.py +8 -23
  14. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/src/nextloop/events/outcome.py +15 -20
  15. nextloop-0.5.0rc2/src/nextloop/events/pending.py +25 -0
  16. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/src/nextloop/events/project.py +13 -0
  17. nextloop-0.5.0rc2/src/nextloop/execute/cancellation.py +29 -0
  18. nextloop-0.5.0rc2/src/nextloop/execute/cleanup.py +22 -0
  19. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/src/nextloop/execute/mcp.py +28 -17
  20. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/src/nextloop/execute/model.py +5 -24
  21. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/src/nextloop/execute/result_read.py +20 -16
  22. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/src/nextloop/execute/stdio.py +0 -21
  23. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/src/nextloop/execute/stdio_transport.py +11 -0
  24. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/src/nextloop/execute/tools.py +3 -20
  25. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/src/nextloop/harness.py +3 -0
  26. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/src/nextloop/loop.py +5 -0
  27. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/src/nextloop/testing.py +44 -4
  28. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2/src/nextloop.egg-info}/PKG-INFO +24 -10
  29. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/src/nextloop.egg-info/SOURCES.txt +9 -0
  30. nextloop-0.5.0rc2/tests/test_complexity_regressions.py +56 -0
  31. nextloop-0.5.0rc2/tests/test_mcp_hardening.py +84 -0
  32. nextloop-0.5.0rc2/tests/test_observability_close_deadline.py +53 -0
  33. nextloop-0.5.0rc2/tests/test_pending_inputs.py +135 -0
  34. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/tests/test_preview.py +1 -0
  35. nextloop-0.5.0rc2/tests/test_provider_terminal.py +105 -0
  36. nextloop-0.5.0rc2/tests/test_result_budget_regressions.py +51 -0
  37. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/tests/test_result_policies.py +18 -9
  38. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/tests/test_store_contract.py +15 -1
  39. nextloop-0.5.0rc1/src/nextloop/execute/cleanup.py +0 -17
  40. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/LICENSE +0 -0
  41. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/MANIFEST.in +0 -0
  42. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/docs/adr/0001-embeddable-agent-loop.md +0 -0
  43. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/docs/adr/0002-dsh-aligned-agent-loop.md +0 -0
  44. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/docs/adr/0003-python-and-centralized-contracts.md +0 -0
  45. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/docs/architecture/agent-loop-capability-review.md +0 -0
  46. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/docs/architecture/development-plan.md +0 -0
  47. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/docs/architecture/discussion-roadmap.md +0 -0
  48. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/docs/architecture/feature-worklist.md +0 -0
  49. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/docs/architecture/requirements.md +0 -0
  50. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/docs/design/agent-loop.md +0 -0
  51. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/docs/design/context-builder.md +0 -0
  52. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/docs/design/loop-interface.md +0 -0
  53. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/docs/design/react-protocol.md +0 -0
  54. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/docs/design/skills.md +0 -0
  55. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/docs/design/verification-matrix.md +0 -0
  56. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/docs/research/2026-11-02-dsh-primary-sources.md +0 -0
  57. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/docs/research/2026-11-02-loop-evidence-notes.md +0 -0
  58. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/docs/research/2026-11-03-hermes-turn-control.md +0 -0
  59. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/docs/research/2026-11-03-tool-batch-failures.md +0 -0
  60. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/docs/research/2026-11-03-tool-call-validation.md +0 -0
  61. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/docs/research/2026-11-03-yomi-turn-control.md +0 -0
  62. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/docs/research/2026-11-06-open-source-agent-loops.md +0 -0
  63. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/docs/research/2026-11-06-react-tool-event-recovery.md +0 -0
  64. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/docs/research/2026-11-10-nextloop-optimization-review.md +0 -0
  65. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/examples/basic.py +0 -0
  66. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/examples/harness-skills/echo/SKILL.md +0 -0
  67. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/examples/harness.toml +0 -0
  68. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/examples/live_smoke.py +0 -0
  69. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/examples/python_tools.py +0 -0
  70. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/examples/skills/coding/SKILL.md +0 -0
  71. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/examples/skills_demo.py +0 -0
  72. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/examples/workers/cpp_worker.cpp +0 -0
  73. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/examples/workers/python_worker.py +0 -0
  74. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/examples/workers/rust_worker.rs +0 -0
  75. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/setup.cfg +0 -0
  76. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/src/nextloop/adapters/__init__.py +0 -0
  77. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/src/nextloop/adapters/_sse.py +0 -0
  78. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/src/nextloop/cli.py +0 -0
  79. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/src/nextloop/events/__init__.py +0 -0
  80. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/src/nextloop/events/repair.py +0 -0
  81. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/src/nextloop/events/response.py +0 -0
  82. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/src/nextloop/events/trace.py +0 -0
  83. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/src/nextloop/execute/__init__.py +0 -0
  84. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/src/nextloop/execute/batch.py +0 -0
  85. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/src/nextloop/execute/composite.py +0 -0
  86. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/src/nextloop/execute/preview.py +0 -0
  87. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/src/nextloop/py.typed +0 -0
  88. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/src/nextloop/skills.py +0 -0
  89. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/src/nextloop.egg-info/dependency_links.txt +0 -0
  90. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/src/nextloop.egg-info/entry_points.txt +0 -0
  91. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/src/nextloop.egg-info/requires.txt +0 -0
  92. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/src/nextloop.egg-info/top_level.txt +0 -0
  93. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/tests/test_aggregate_close.py +0 -0
  94. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/tests/test_budgets.py +0 -0
  95. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/tests/test_cli.py +0 -0
  96. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/tests/test_correctness_regressions.py +0 -0
  97. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/tests/test_events.py +0 -0
  98. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/tests/test_failures.py +0 -0
  99. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/tests/test_harness.py +0 -0
  100. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/tests/test_harness_injection.py +0 -0
  101. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/tests/test_loop.py +0 -0
  102. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/tests/test_mcp.py +0 -0
  103. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/tests/test_observability.py +0 -0
  104. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/tests/test_providers.py +0 -0
  105. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/tests/test_review_regressions.py +0 -0
  106. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/tests/test_skills.py +0 -0
  107. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/tests/test_stdio.py +0 -0
  108. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/tests/test_stdio_cleanup.py +0 -0
  109. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/tests/test_stdio_frames.py +0 -0
  110. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/tests/test_stdio_safety.py +0 -0
  111. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/tests/test_stores.py +0 -0
  112. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/tests/test_surface_snapshot.py +0 -0
  113. {nextloop-0.5.0rc1 → nextloop-0.5.0rc2}/tests/test_worker_conformance.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: nextloop
3
- Version: 0.5.0rc1
3
+ Version: 0.5.0rc2
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,16 +30,16 @@ Dynamic: license-file
30
30
 
31
31
  **Small core. Serious runtime semantics.**
32
32
 
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.
33
+ nextloop is an embeddable Python AgentLoop for developers who want to build their own agent runtime — not inherit a heavyweight framework. Deterministic scheduling and state folding, append-only history, explicit crash recovery, typed Tools, and committed-event observability, all in a package you can actually read.
34
34
 
35
35
  **Your agent, your rules. No magic, no black box.**
36
36
 
37
- Current version: **0.5.0rc1**.
37
+ Current version: **0.5.0rc2**.
38
38
 
39
39
  ## Install
40
40
 
41
41
  ```bash
42
- python -m pip install nextloop==0.5.0rc1
42
+ python -m pip install nextloop==0.5.0rc2
43
43
  ```
44
44
 
45
45
  For local development:
@@ -63,9 +63,9 @@ It is a library, not an HTTP service, product bot, Router, EventBus, or multi-ag
63
63
 
64
64
  ## Under the hood
65
65
 
66
- - DSH-aligned Session/Turn/Step execution with 4D integer coordinates and writer fencing.
67
- - Append-only Trajectory and O(Δ) `surface_op` watermark projection.
68
- - In-memory `Inbox` serialization for steer and final commitment.
66
+ - Session/Turn/Step execution with 4D integer coordinates and writer fencing.
67
+ - Append-only Trajectory with `surface_op` watermark semantics and Turn-private surface snapshots.
68
+ - Log-derived Pending Input and in-memory inbox signaling for steer and final commitment.
69
69
  - Whole-batch Tool Schema validation, bounded parallel calls, and exclusive failure barriers.
70
70
  - Closed five-variant `ToolOutcome`: `Completed`, `Skipped`, `Cancelled`, `UncertainSettled`, `UncertainHanging`.
71
71
  - Bounded Provider retries, protocol correction, WorkingContext, Compaction, and cancellation.
@@ -87,9 +87,23 @@ AgentLoop.run(TurnContext) -> TurnOutcome
87
87
  AgentLoop.steer(session_id, content, *, input_id=None) -> bool
88
88
  AgentLoop.cancel(session_id, cause="user_stop") -> bool
89
89
  AgentLoop.recover(session_id, store, delivery) -> RecoveryOutcome
90
+ AgentLoop.pending_inputs(session_id, store) -> tuple[PendingInput, ...]
90
91
  ```
91
92
 
92
- The only four Adapter protocols are `EventStore`, `ModelProvider`, `ToolRuntime`, and `DeliveryOwner`. Context projection and Compaction are built in and configured through `LoopConfig`.
93
+ Core adapter seams are `EventStore`, `ModelProvider`, `ToolRuntime`, and `DeliveryOwner`. Additional extension points include `PreviewSink`, Exporters, Skills, and stdio/MCP workers. Context projection and Compaction are built in and configured through `LoopConfig`.
94
+
95
+ ## Guarantees and non-guarantees
96
+
97
+ | Area | Guarantee | Not a guarantee |
98
+ |---|---|---|
99
+ | Accepted input | Accepted inputs are projected from the log by `input_id` and can be queried with `AgentLoop.pending_inputs`. | Automatic deduplication when callers retry with a different or missing ID. |
100
+ | Delivery | Delivery is at least once; DeliveryOwner must deduplicate by stable `final_message_id`. | Exactly-once delivery or delivery without an idempotent owner. |
101
+ | Tool execution | The library never automatically replays an already dispatched Tool. | No duplicate external effect when a model reissues a call or a Tool is not idempotent. |
102
+ | Resource locks | Unresolved uncertain results block later calls sharing declared resources. | Global idempotency across different resources or Tools without resource declarations. |
103
+ | Recovery | Recovery writes crash closers; the caller starts a new Turn with projected prior messages and Pending Input. | In-place replay of the interrupted Turn or automatic execution of uncertain calls. |
104
+ | Preview | Preview is transient and cannot execute partial Tool arguments. | Preview as a durable EventStore fact or a substitute for committed Delivery. |
105
+ | Observability | Committed Events are authoritative and can be replayed for history. | The current in-memory Exporter queue as a durable outbox. |
106
+ | MCP | stdio lifecycle, paginated static catalogs, and uncertain crash handling. | Remote MCP, OAuth, dynamic `listChanged`, or non-text content mapping. |
93
107
 
94
108
  `Harness.load("harness.toml")` assembles those adapters without changing the Loop. Use `await harness.check()` for offline validation and `await harness.run("input")` for a model-backed Turn. See [Harness and extension interface](docs/design/harness.md) for the strict TOML schema, stdio protocol, lifecycle rules, and CLI.
95
109
 
@@ -205,7 +219,7 @@ The release-candidate checks cover:
205
219
  - recorded OpenAI and Anthropic SSE streams;
206
220
  - 12 live Kimi scenarios across both protocols, real Tool usage, parallel execution, recovery, steer, cancellation, Compaction, and WorkingContext;
207
221
  - live DeepSeek text + Preview + usage and real Tool Call + Delivery smoke;
208
- - 185 offline tests, `ruff`, `mypy`, wheel/sdist builds, `twine check`, and clean wheel installation.
222
+ - 215 offline tests, `ruff`, `mypy`, wheel/sdist builds, `twine check`, and clean wheel installation.
209
223
 
210
224
  Current limits:
211
225
 
@@ -223,7 +237,7 @@ Current limits:
223
237
  - [Verification matrix](docs/design/verification-matrix.md)
224
238
  - [Development plan](docs/architecture/development-plan.md)
225
239
  - [Changelog](CHANGELOG.md)
226
- - [ADR-0002](docs/adr/0002-dsh-aligned-agent-loop.md) and [ADR-0003](docs/adr/0003-python-and-centralized-contracts.md)
240
+ - [ADR-0002](docs/adr/0002-dsh-aligned-agent-loop.md), [ADR-0003](docs/adr/0003-python-and-centralized-contracts.md), and [ADR-0005 Pending Input](docs/adr/0005-pending-input.md)
227
241
 
228
242
  ## Release
229
243
 
@@ -2,16 +2,16 @@
2
2
 
3
3
  **Small core. Serious runtime semantics.**
4
4
 
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.
5
+ nextloop is an embeddable Python AgentLoop for developers who want to build their own agent runtime — not inherit a heavyweight framework. Deterministic scheduling and state folding, append-only history, explicit crash recovery, typed Tools, and committed-event observability, all in a package you can actually read.
6
6
 
7
7
  **Your agent, your rules. No magic, no black box.**
8
8
 
9
- Current version: **0.5.0rc1**.
9
+ Current version: **0.5.0rc2**.
10
10
 
11
11
  ## Install
12
12
 
13
13
  ```bash
14
- python -m pip install nextloop==0.5.0rc1
14
+ python -m pip install nextloop==0.5.0rc2
15
15
  ```
16
16
 
17
17
  For local development:
@@ -35,9 +35,9 @@ It is a library, not an HTTP service, product bot, Router, EventBus, or multi-ag
35
35
 
36
36
  ## Under the hood
37
37
 
38
- - DSH-aligned Session/Turn/Step execution with 4D integer coordinates and writer fencing.
39
- - Append-only Trajectory and O(Δ) `surface_op` watermark projection.
40
- - In-memory `Inbox` serialization for steer and final commitment.
38
+ - Session/Turn/Step execution with 4D integer coordinates and writer fencing.
39
+ - Append-only Trajectory with `surface_op` watermark semantics and Turn-private surface snapshots.
40
+ - Log-derived Pending Input and in-memory inbox signaling for steer and final commitment.
41
41
  - Whole-batch Tool Schema validation, bounded parallel calls, and exclusive failure barriers.
42
42
  - Closed five-variant `ToolOutcome`: `Completed`, `Skipped`, `Cancelled`, `UncertainSettled`, `UncertainHanging`.
43
43
  - Bounded Provider retries, protocol correction, WorkingContext, Compaction, and cancellation.
@@ -59,9 +59,23 @@ AgentLoop.run(TurnContext) -> TurnOutcome
59
59
  AgentLoop.steer(session_id, content, *, input_id=None) -> bool
60
60
  AgentLoop.cancel(session_id, cause="user_stop") -> bool
61
61
  AgentLoop.recover(session_id, store, delivery) -> RecoveryOutcome
62
+ AgentLoop.pending_inputs(session_id, store) -> tuple[PendingInput, ...]
62
63
  ```
63
64
 
64
- The only four Adapter protocols are `EventStore`, `ModelProvider`, `ToolRuntime`, and `DeliveryOwner`. Context projection and Compaction are built in and configured through `LoopConfig`.
65
+ Core adapter seams are `EventStore`, `ModelProvider`, `ToolRuntime`, and `DeliveryOwner`. Additional extension points include `PreviewSink`, Exporters, Skills, and stdio/MCP workers. Context projection and Compaction are built in and configured through `LoopConfig`.
66
+
67
+ ## Guarantees and non-guarantees
68
+
69
+ | Area | Guarantee | Not a guarantee |
70
+ |---|---|---|
71
+ | Accepted input | Accepted inputs are projected from the log by `input_id` and can be queried with `AgentLoop.pending_inputs`. | Automatic deduplication when callers retry with a different or missing ID. |
72
+ | Delivery | Delivery is at least once; DeliveryOwner must deduplicate by stable `final_message_id`. | Exactly-once delivery or delivery without an idempotent owner. |
73
+ | Tool execution | The library never automatically replays an already dispatched Tool. | No duplicate external effect when a model reissues a call or a Tool is not idempotent. |
74
+ | Resource locks | Unresolved uncertain results block later calls sharing declared resources. | Global idempotency across different resources or Tools without resource declarations. |
75
+ | Recovery | Recovery writes crash closers; the caller starts a new Turn with projected prior messages and Pending Input. | In-place replay of the interrupted Turn or automatic execution of uncertain calls. |
76
+ | Preview | Preview is transient and cannot execute partial Tool arguments. | Preview as a durable EventStore fact or a substitute for committed Delivery. |
77
+ | Observability | Committed Events are authoritative and can be replayed for history. | The current in-memory Exporter queue as a durable outbox. |
78
+ | MCP | stdio lifecycle, paginated static catalogs, and uncertain crash handling. | Remote MCP, OAuth, dynamic `listChanged`, or non-text content mapping. |
65
79
 
66
80
  `Harness.load("harness.toml")` assembles those adapters without changing the Loop. Use `await harness.check()` for offline validation and `await harness.run("input")` for a model-backed Turn. See [Harness and extension interface](docs/design/harness.md) for the strict TOML schema, stdio protocol, lifecycle rules, and CLI.
67
81
 
@@ -177,7 +191,7 @@ The release-candidate checks cover:
177
191
  - recorded OpenAI and Anthropic SSE streams;
178
192
  - 12 live Kimi scenarios across both protocols, real Tool usage, parallel execution, recovery, steer, cancellation, Compaction, and WorkingContext;
179
193
  - live DeepSeek text + Preview + usage and real Tool Call + Delivery smoke;
180
- - 185 offline tests, `ruff`, `mypy`, wheel/sdist builds, `twine check`, and clean wheel installation.
194
+ - 215 offline tests, `ruff`, `mypy`, wheel/sdist builds, `twine check`, and clean wheel installation.
181
195
 
182
196
  Current limits:
183
197
 
@@ -195,7 +209,7 @@ Current limits:
195
209
  - [Verification matrix](docs/design/verification-matrix.md)
196
210
  - [Development plan](docs/architecture/development-plan.md)
197
211
  - [Changelog](CHANGELOG.md)
198
- - [ADR-0002](docs/adr/0002-dsh-aligned-agent-loop.md) and [ADR-0003](docs/adr/0003-python-and-centralized-contracts.md)
212
+ - [ADR-0002](docs/adr/0002-dsh-aligned-agent-loop.md), [ADR-0003](docs/adr/0003-python-and-centralized-contracts.md), and [ADR-0005 Pending Input](docs/adr/0005-pending-input.md)
199
213
 
200
214
  ## Release
201
215
 
@@ -0,0 +1,31 @@
1
+ # ADR-0005: Pending Input as a pure log projection
2
+
3
+ Status: accepted
4
+
5
+ ## Context
6
+
7
+ `steer()` persists INPUT_ACCEPTED before writing the in-memory actor inbox. INPUT_ACCEPTED alone is not part of the model-visible projection. A crash can therefore acknowledge an input that the model never sees. Rebuilding this state in `recover()` would create another writer and another crash window.
8
+
9
+ ## Decision
10
+
11
+ The event log is the sole source of truth. The actor inbox is only a wake-up signal.
12
+
13
+ - Scan INPUT_ACCEPTED and USER_MESSAGE in seq order and match them by `input_id`.
14
+ - Accepted inputs without a corresponding USER_MESSAGE are Pending Input.
15
+ - Compute Pending Input at the start of each Turn. Recovery never writes the actor inbox.
16
+ - Pending historical inputs appear before the new Turn's initial_input. Inputs accepted during approval suspension appear only after the corresponding Tool results.
17
+ - Inputs from cancelled or budget-terminated Turns carry into the next Turn by default.
18
+ - Active execution also uses the log's consumption state, so an input present in both the log and actor inbox is injected once.
19
+ - Pending is queryable with `input_id`, original seq, original Turn, and content. No cleanup event is introduced in this version.
20
+ - `recover()` may be called repeatedly without duplicating Pending. A crash between recover and run has the same projection.
21
+
22
+ `input_id` is the idempotency boundary. A caller retrying initial input or steer must supply the same `input_id`, or query Pending before retrying. An absent or automatically generated ID does not provide cross-crash deduplication.
23
+
24
+ No cleanup event is introduced. Pending remains visible until the caller consumes it or the protocol later defines an explicit discard fact.
25
+
26
+ ## Consequences
27
+
28
+ - Accepted inputs are not silently lost after process crashes.
29
+ - No second recovery writer or in-memory Pending copy can diverge from the log.
30
+ - Callers that blindly retry with a new ID may intentionally receive duplicate content; this is not deduplicated.
31
+ - Compaction and approval pairing must preserve Pending ordering and must not split a Tool Intent from its result.
@@ -6,7 +6,7 @@
6
6
 
7
7
  ```toml
8
8
  schema = "nextloop.harness/v1"
9
- min_nextloop = "0.4.0rc1"
9
+ min_nextloop = "0.5.0rc1"
10
10
 
11
11
  [provider]
12
12
  protocol = "openai" # or anthropic
@@ -82,12 +82,24 @@ Skills remain instructions only. Their metadata is added to the system prompt, a
82
82
 
83
83
  Exporters may optionally implement `flush()` and `close()`, synchronously or asynchronously. The queue is flushed before Exporter lifecycle calls. Harness closes Exporters created from `[trace]`; runtime-injected Exporters are flushed but not closed. `nextloop.testing.check_event_store(store)` exposes the same basic atomicity, idempotency, fencing, surface, and recovery-read contract used by the built-in Stores.
84
84
 
85
+ ## Pending Input
86
+
87
+ The event log is the sole source of truth for accepted input. `AgentLoop.pending_inputs(session_id, store)` returns accepted inputs that have not been consumed by a USER_MESSAGE, ordered by their original seq. Recovery projects these inputs at the start of the next Turn instead of rebuilding an in-memory inbox. Callers must provide a stable `input_id` to deduplicate retries or query Pending before retrying.
88
+
89
+ ```python
90
+ pending = await loop.pending_inputs("session-id", store)
91
+ ```
92
+
93
+ Pending historical inputs appear before the new Turn's initial input. Inputs from cancelled or budget-terminated Turns carry forward by default. Repeated recovery and a crash between recover and run do not duplicate them.
94
+
85
95
  ## Budgets and Tool Results
86
96
 
87
97
  All budget fields default to `None`. Step, model-attempt, and validated Tool-batch limits stop the next side effect. Model attempts include retries and compaction. Token limits use Provider-reported usage and fail closed when required usage is missing or invalid. `turn_deadline_seconds` reuses cancellation and uncertain Tool semantics. Budgets are Turn-local; recovery closes an interrupted Turn and a later Turn gets a new budget.
88
98
 
89
99
  `ToolSpec.result_mode` supports `PREVIEW`, `PAGED`, and `FULL`, with `PREVIEW` as the default. Small results are unchanged. Large previews retain UTF-8-safe head/tail content and an `event_id`; pages are continuous. The durable outcome retains full content while the model Message contains the projection. `read_tool_result` reads committed content from the recovery log by `event_id`, UTF-8 byte offset, and bounded limit. FULL and terminal results are not generically truncated; exceeding the hard limit commits the full result and ends the Turn as failed without final delivery.
90
100
 
101
+ The minimum preview/page budget is 256 bytes, with 128 bytes reserved for protocol metadata. The budget applies to the complete model-visible projection, including metadata. `read_tool_result` returns a `[Tool result page: ...]` header followed by the continuous page body and `next_offset`; it does not return a JSON envelope.
102
+
91
103
  ## Transient Preview
92
104
 
93
105
  `TurnContext.preview` accepts one optional synchronous `PreviewSink`. Providers may implement `complete_with_preview`; Providers that only implement `complete` remain compatible and produce a response snapshot rather than synthetic token deltas. Preview events are transient, never enter the EventStore, never execute partial Tool Calls, and never trigger Delivery. The bounded worker queue replaces overflow with a RESET containing the latest transient snapshot. Slow or failing sinks do not change the Turn result, and closing a subscription does not cancel the Turn.
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "nextloop"
7
- version = "0.5.0rc1"
7
+ version = "0.5.0rc2"
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"
@@ -32,6 +32,7 @@ from .contracts import (
32
32
  ModelUsage,
33
33
  NewEvent,
34
34
  NextloopError,
35
+ PendingInput,
35
36
  PreviewEvent,
36
37
  PreviewKind,
37
38
  PreviewSink,
@@ -123,6 +124,7 @@ __all__ = [
123
124
  "NextloopError",
124
125
  "ObservingEventStore",
125
126
  "OpenAIProvider",
127
+ "PendingInput",
126
128
  "PreviewEvent",
127
129
  "PreviewKind",
128
130
  "PreviewSink",
@@ -92,9 +92,10 @@ class AnthropicProvider:
92
92
  client = self.http_client or httpx.AsyncClient(timeout=self.timeout_seconds)
93
93
  text_blocks: dict[int, list[str]] = {}
94
94
  tool_blocks: dict[int, dict[str, Any]] = {}
95
- finish_reason = FinishReason.STOP
95
+ finish_reason: FinishReason | None = None
96
96
  input_tokens = None
97
97
  output_tokens = None
98
+ message_stopped = False
98
99
  try:
99
100
  async with client.stream(
100
101
  "POST", self._endpoint(), json=body, headers=headers
@@ -166,8 +167,17 @@ class AnthropicProvider:
166
167
  )
167
168
  elif event == "message_delta":
168
169
  stop_reason = payload.get("delta", {}).get("stop_reason")
169
- finish_reason = self._finish_reason(stop_reason) or finish_reason
170
+ if stop_reason is not None:
171
+ mapped = self._finish_reason(stop_reason)
172
+ if mapped is None:
173
+ raise ProviderError(
174
+ f"Anthropic stream returned unknown stop reason: {stop_reason}",
175
+ partial_output=bool(text_blocks or tool_blocks),
176
+ )
177
+ finish_reason = mapped
170
178
  output_tokens = payload.get("usage", {}).get("output_tokens", output_tokens)
179
+ elif event == "message_stop":
180
+ message_stopped = True
171
181
  elif event == "error":
172
182
  error = payload.get("error", {})
173
183
  raise ProviderError(
@@ -176,6 +186,17 @@ class AnthropicProvider:
176
186
  partial_output=bool(text_blocks or tool_blocks),
177
187
  code=error.get("type"),
178
188
  )
189
+ if not message_stopped:
190
+ raise ProviderError(
191
+ "Anthropic stream ended before message_stop",
192
+ retryable=True,
193
+ partial_output=bool(text_blocks or tool_blocks),
194
+ )
195
+ if finish_reason is None:
196
+ raise ProviderError(
197
+ "Anthropic stream completed without a stop reason",
198
+ partial_output=bool(text_blocks or tool_blocks),
199
+ )
179
200
  return ModelResponse(
180
201
  content=self._text(text_blocks),
181
202
  tool_calls=tuple(
@@ -78,7 +78,7 @@ class InMemoryEventStore:
78
78
  if event.seq >= epoch_seq
79
79
  and (
80
80
  event.surface_op != SurfaceOp.NONE
81
- or event.event_type == EventType.TOOL_BATCH_REJECTED
81
+ or event.event_type in (EventType.TOOL_BATCH_REJECTED, EventType.INPUT_ACCEPTED)
82
82
  )
83
83
  )
84
84
 
@@ -161,7 +161,9 @@ class ObservingEventStore:
161
161
  return False
162
162
  for exporter in self._exporters:
163
163
  try:
164
- await _exporter_lifecycle(exporter, "flush")
164
+ await asyncio.wait_for(
165
+ _exporter_lifecycle(exporter, "flush"), timeout=timeout_seconds
166
+ )
165
167
  except Exception as exc:
166
168
  self._report_error(exc, None)
167
169
  return False
@@ -172,8 +174,17 @@ class ObservingEventStore:
172
174
  if self._closed:
173
175
  return
174
176
  self._closed = True
175
- cancelled = await wait_for_cleanup(asyncio.create_task(self._close()))
177
+ try:
178
+ cancelled = await wait_for_cleanup(asyncio.create_task(self._close()))
179
+ except TimeoutError as exc:
180
+ self._closed = False
181
+ self._report_error(exc, None)
182
+ return
183
+ except BaseException:
184
+ self._closed = False
185
+ raise
176
186
  if cancelled:
187
+ self._closed = False
177
188
  raise asyncio.CancelledError()
178
189
 
179
190
  async def _close(self) -> None:
@@ -201,7 +212,12 @@ class ObservingEventStore:
201
212
  raise
202
213
  for exporter in self._close_exporters:
203
214
  try:
204
- await _exporter_lifecycle(exporter, "close")
215
+ remaining = max(0.0, deadline - asyncio.get_running_loop().time())
216
+ await asyncio.wait_for(
217
+ _exporter_lifecycle(exporter, "close"), timeout=remaining
218
+ )
219
+ except TimeoutError:
220
+ raise
205
221
  except Exception as exc:
206
222
  self._report_error(exc, None)
207
223
  finally:
@@ -87,8 +87,9 @@ class OpenAIProvider:
87
87
  content_parts: list[str] = []
88
88
  refusal_parts: list[str] = []
89
89
  calls: dict[int, dict[str, str]] = {}
90
- finish_reason = FinishReason.STOP
90
+ finish_reason: FinishReason | None = None
91
91
  usage: ModelUsage | None = None
92
+ done = False
92
93
  try:
93
94
  async with client.stream(
94
95
  "POST",
@@ -105,13 +106,19 @@ class OpenAIProvider:
105
106
  or response.status_code >= 500,
106
107
  code=str(response.status_code),
107
108
  )
108
- async for _event, data in data_events(response):
109
+ async for event, data in data_events(response):
109
110
  if cancel.is_set():
110
111
  return ModelResponse(
111
112
  content="".join(content_parts),
112
113
  finish_reason=FinishReason.CANCELLED,
113
114
  )
115
+ if event == "error":
116
+ raise ProviderError(
117
+ f"OpenAI stream error: {data}",
118
+ partial_output=bool(content_parts or refusal_parts or calls),
119
+ )
114
120
  if data == "[DONE]":
121
+ done = True
115
122
  break
116
123
  chunk = json.loads(data)
117
124
  usage = self._usage(chunk.get("usage")) or usage
@@ -148,9 +155,27 @@ class OpenAIProvider:
148
155
  preview["arguments_delta"] = str(function["arguments"])
149
156
  if emit is not None:
150
157
  emit(preview)
151
- finish_reason = (
152
- self._finish_reason(choice.get("finish_reason")) or finish_reason
153
- )
158
+ raw_finish_reason = choice.get("finish_reason")
159
+ if raw_finish_reason is not None:
160
+ mapped = self._finish_reason(raw_finish_reason)
161
+ if mapped is None:
162
+ raise ProviderError(
163
+ "OpenAI stream returned unknown finish reason: "
164
+ f"{raw_finish_reason}",
165
+ partial_output=bool(content_parts or refusal_parts or calls),
166
+ )
167
+ finish_reason = mapped
168
+ if not done:
169
+ raise ProviderError(
170
+ "OpenAI stream ended before [DONE]",
171
+ retryable=True,
172
+ partial_output=bool(content_parts or refusal_parts or calls),
173
+ )
174
+ if finish_reason is None:
175
+ raise ProviderError(
176
+ "OpenAI stream completed without a finish reason",
177
+ partial_output=bool(content_parts or refusal_parts or calls),
178
+ )
154
179
  return ModelResponse(
155
180
  content="".join(content_parts),
156
181
  refusal="".join(refusal_parts) or None,
@@ -173,7 +173,10 @@ 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' OR event_type = 'tool/batch-rejected')
176
+ AND (
177
+ surface_op != 'none'
178
+ OR event_type IN ('tool/batch-rejected', 'input/accepted')
179
+ )
177
180
  ORDER BY seq
178
181
  """,
179
182
  (session_id, session_id),
@@ -10,11 +10,16 @@ from datetime import UTC, datetime
10
10
  from enum import StrEnum
11
11
  from typing import Any, Literal, Protocol
12
12
 
13
- API_VERSION = "0.5.0rc1"
13
+ API_VERSION = "0.5.0rc2"
14
14
  EVENT_SCHEMA_VERSION = "1.0"
15
15
  HARNESS_SCHEMA = "nextloop.harness/v1"
16
16
  STDIO_PROTOCOL_VERSION = "nextloop.stdio/v1"
17
17
  TRACE_SCHEMA = "nextloop.trace/v1"
18
+ TOOL_RESULT_MIN_BYTES = 256
19
+ TOOL_RESULT_METADATA_BYTES = 128
20
+ READ_TOOL_RESULT_NAME = "read_tool_result"
21
+ DEFAULT_TOOL_RESULT_BYTES = 50_000
22
+ DEFAULT_TOOL_RESULT_FULL_MAX_BYTES = 1_048_576
18
23
 
19
24
 
20
25
  def parse_version(value: str) -> tuple[int, int, int, int, int]:
@@ -458,8 +463,8 @@ class LoopConfig:
458
463
  max_output_tokens: int | None = None
459
464
  max_total_tokens: int | None = None
460
465
  turn_deadline_seconds: float | None = None
461
- tool_result_bytes: int = 50_000
462
- tool_result_full_max_bytes: int = 1_048_576
466
+ tool_result_bytes: int = DEFAULT_TOOL_RESULT_BYTES
467
+ tool_result_full_max_bytes: int = DEFAULT_TOOL_RESULT_FULL_MAX_BYTES
463
468
 
464
469
 
465
470
  @dataclass(frozen=True)
@@ -513,6 +518,14 @@ class HarnessSpec:
513
518
  source_path: str = "<memory>"
514
519
 
515
520
 
521
+ @dataclass(frozen=True)
522
+ class PendingInput:
523
+ input_id: str
524
+ turn: int
525
+ seq: int
526
+ content: str
527
+
528
+
516
529
  @dataclass(frozen=True)
517
530
  class FinalMessage:
518
531
  final_message_id: str
@@ -1,7 +1,7 @@
1
1
  from __future__ import annotations
2
2
 
3
3
  import asyncio
4
- from collections.abc import Awaitable, Sequence
4
+ from collections.abc import Sequence
5
5
  from dataclasses import dataclass, field
6
6
 
7
7
  from .contracts import (
@@ -29,6 +29,7 @@ from .events.project import (
29
29
  )
30
30
  from .events.response import ResponseAction, decide_response, reject_batch
31
31
  from .execute.batch import BatchExecutor
32
+ from .execute.cancellation import await_with_cancel
32
33
  from .execute.model import ModelCaller
33
34
  from .execute.preview import PreviewChannel
34
35
 
@@ -165,9 +166,9 @@ class SessionExecution:
165
166
  for event in committed:
166
167
  if event.surface_op == SurfaceOp.EPOCH:
167
168
  self.surface = (event,)
168
- elif (
169
- event.surface_op == SurfaceOp.APPEND
170
- or event.event_type == EventType.TOOL_BATCH_REJECTED
169
+ elif event.surface_op == SurfaceOp.APPEND or event.event_type in (
170
+ EventType.TOOL_BATCH_REJECTED,
171
+ EventType.INPUT_ACCEPTED,
171
172
  ):
172
173
  self.surface = (*self.surface, event)
173
174
 
@@ -521,7 +522,9 @@ class TurnDriver:
521
522
  await execution._append_locked(events)
522
523
  execution.final_committed = True
523
524
  try:
524
- await _deliver_with_cancel(execution.context.delivery.deliver(final), execution.cancel)
525
+ await await_with_cancel(
526
+ execution.context.delivery.deliver(final), execution.cancel, _DeliveryCancelled
527
+ )
525
528
  await execution.append(
526
529
  [
527
530
  NewEvent(
@@ -611,21 +614,3 @@ class TurnDriver:
611
614
  step=execution.step,
612
615
  error=error,
613
616
  )
614
-
615
-
616
- async def _deliver_with_cancel(awaitable: Awaitable[None], cancel: asyncio.Event) -> None:
617
- operation = asyncio.ensure_future(awaitable)
618
- cancellation = asyncio.create_task(cancel.wait())
619
- try:
620
- done, _ = await asyncio.wait({operation, cancellation}, return_when=asyncio.FIRST_COMPLETED)
621
- if cancellation in done and not operation.done():
622
- operation.cancel()
623
- await asyncio.gather(operation, return_exceptions=True)
624
- raise _DeliveryCancelled()
625
- cancellation.cancel()
626
- await operation
627
- finally:
628
- cancellation.cancel()
629
- if not operation.done():
630
- operation.cancel()
631
- await asyncio.gather(operation, cancellation, return_exceptions=True)
@@ -6,6 +6,10 @@ from enum import StrEnum
6
6
  from typing import Any
7
7
 
8
8
  from ..contracts import (
9
+ DEFAULT_TOOL_RESULT_BYTES,
10
+ DEFAULT_TOOL_RESULT_FULL_MAX_BYTES,
11
+ TOOL_RESULT_METADATA_BYTES,
12
+ TOOL_RESULT_MIN_BYTES,
9
13
  Cancelled,
10
14
  Completed,
11
15
  EventType,
@@ -127,28 +131,19 @@ def project_result_content(content: str, mode: ToolResultMode, event_id: str, li
127
131
  total = len(data)
128
132
  if total <= limit or mode == ToolResultMode.FULL:
129
133
  return content
134
+ if limit < TOOL_RESULT_MIN_BYTES:
135
+ raise ValueError("Tool Result budget is too small for preview metadata")
136
+ body_budget = limit - TOOL_RESULT_METADATA_BYTES
130
137
  if mode == ToolResultMode.PAGED:
131
- page = result_page(content, 0, limit)
138
+ page = result_page(content, 0, body_budget)
132
139
  return (
133
140
  f"[Tool result page: event_id={event_id} total_bytes={total} "
134
141
  f"next_offset={page.next_offset}]\n"
135
142
  ) + page.content
136
- omitted = 0
137
- head = b""
138
- tail = b""
139
- for _ in range(4):
140
- header = (
141
- f"[Tool result preview: event_id={event_id} total_bytes={total} "
142
- f"omitted_bytes={omitted}; use read_tool_result for missing content]\n"
143
- )
144
- budget = max(0, limit - len(header.encode("utf-8")))
145
- head_budget = int(budget * 0.4)
146
- head = _utf8_prefix(data, head_budget)
147
- tail = _utf8_suffix(data, budget - head_budget)
148
- updated = total - len(head) - len(tail)
149
- if updated == omitted:
150
- break
151
- omitted = updated
143
+ head_budget = int(body_budget * 0.4)
144
+ head = _utf8_prefix(data, head_budget)
145
+ tail = _utf8_suffix(data, body_budget - head_budget)
146
+ omitted = total - len(head) - len(tail)
152
147
  header = (
153
148
  f"[Tool result preview: event_id={event_id} total_bytes={total} "
154
149
  f"omitted_bytes={omitted}; use read_tool_result for missing content]\n"
@@ -166,7 +161,7 @@ def outcome_event(
166
161
  timing: ToolExecutionTiming | None = None,
167
162
  recovered: bool = False,
168
163
  spec: ToolSpec | None = None,
169
- result_bytes: int = 50_000,
164
+ result_bytes: int = DEFAULT_TOOL_RESULT_BYTES,
170
165
  ) -> NewEvent:
171
166
  event_id = new_id("evt")
172
167
  if (
@@ -218,8 +213,8 @@ def settle_outcomes(
218
213
  pacing_step_interval: int,
219
214
  blocked_resources: frozenset[str] = frozenset(),
220
215
  timings: Mapping[str, ToolExecutionTiming] | None = None,
221
- result_bytes: int = 50_000,
222
- full_max_bytes: int = 1_048_576,
216
+ result_bytes: int = DEFAULT_TOOL_RESULT_BYTES,
217
+ full_max_bytes: int = DEFAULT_TOOL_RESULT_FULL_MAX_BYTES,
223
218
  ) -> BatchDecision:
224
219
  events: list[NewEvent] = []
225
220
  acquired: set[str] = set()
@@ -0,0 +1,25 @@
1
+ from __future__ import annotations
2
+
3
+ from collections.abc import Sequence
4
+
5
+ from ..contracts import Event, EventType, PendingInput
6
+
7
+
8
+ def pending_inputs(events: Sequence[Event]) -> tuple[PendingInput, ...]:
9
+ pending: dict[str, PendingInput] = {}
10
+ consumed: set[str] = set()
11
+ for event in events:
12
+ if event.event_type == EventType.INPUT_ACCEPTED:
13
+ input_id = str(event.payload.get("input_id", ""))
14
+ if input_id:
15
+ pending[input_id] = PendingInput(
16
+ input_id=input_id,
17
+ turn=event.turn,
18
+ seq=event.seq,
19
+ content=str(event.payload.get("content", "")),
20
+ )
21
+ elif event.event_type == EventType.USER_MESSAGE:
22
+ input_id = str(event.payload.get("input_id", ""))
23
+ if input_id:
24
+ consumed.add(input_id)
25
+ return tuple(item for input_id, item in pending.items() if input_id not in consumed)