phronomy 0.26.0 → 0.28.0

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 (557) hide show
  1. checksums.yaml +4 -4
  2. data/.mutant.yml +9 -9
  3. data/CHANGELOG.md +92 -0
  4. data/CONTRIBUTING.md +8 -8
  5. data/README.md +13 -3
  6. data/VERIFY.sh +27 -27
  7. data/benchmark/bench_agent_invoke.rb +26 -47
  8. data/benchmark/bench_context_assembler.rb +17 -15
  9. data/benchmark/bench_regression.rb +1 -1
  10. data/benchmark/bench_tool_schema.rb +1 -1
  11. data/docs/architecture/agent-chat-and-state-ownership.md +153 -0
  12. data/docs/architecture/agent-configuration-and-tool-binding.md +139 -0
  13. data/docs/architecture/agent-context.md +4 -2
  14. data/docs/architecture/agent-transition-ownership.md +13 -0
  15. data/docs/architecture/backend-groups.md +152 -0
  16. data/docs/architecture/before-llm-input.md +9 -3
  17. data/docs/architecture/context-management.md +31 -1
  18. data/docs/architecture/context-preparation-steps.md +90 -0
  19. data/docs/architecture/entry-action-and-team-wording.md +72 -0
  20. data/docs/architecture/execution-abstraction-review.md +88 -0
  21. data/docs/architecture/execution-boundaries.md +28 -0
  22. data/docs/architecture/execution-metadata-and-values.md +86 -0
  23. data/docs/architecture/generator-verifier-ownership.md +111 -0
  24. data/docs/architecture/multi-agent-handoff.md +11 -4
  25. data/docs/architecture/persistence-refactoring-plan.md +50 -0
  26. data/docs/architecture/persistence.md +45 -4
  27. data/docs/architecture/r8-unit1.md +104 -0
  28. data/docs/architecture/r8-unit10.md +72 -0
  29. data/docs/architecture/r8-unit11.md +71 -0
  30. data/docs/architecture/r8-unit12.md +67 -0
  31. data/docs/architecture/r8-unit13.md +61 -0
  32. data/docs/architecture/r8-unit14.md +72 -0
  33. data/docs/architecture/r8-unit15.md +65 -0
  34. data/docs/architecture/r8-unit16.md +54 -0
  35. data/docs/architecture/r8-unit17.md +73 -0
  36. data/docs/architecture/r8-unit18.md +92 -0
  37. data/docs/architecture/r8-unit19.md +61 -0
  38. data/docs/architecture/r8-unit2.md +55 -0
  39. data/docs/architecture/r8-unit20.md +51 -0
  40. data/docs/architecture/r8-unit21.md +79 -0
  41. data/docs/architecture/r8-unit22.md +74 -0
  42. data/docs/architecture/r8-unit23.md +81 -0
  43. data/docs/architecture/r8-unit3.md +130 -0
  44. data/docs/architecture/r8-unit4.md +79 -0
  45. data/docs/architecture/r8-unit5.md +115 -0
  46. data/docs/architecture/r8-unit6.md +71 -0
  47. data/docs/architecture/r8-unit7.md +70 -0
  48. data/docs/architecture/r8-unit8.md +78 -0
  49. data/docs/architecture/r8-unit9.md +73 -0
  50. data/docs/architecture/refactoring-closure.md +343 -0
  51. data/docs/architecture/remaining-refactoring-plan.md +390 -0
  52. data/docs/architecture/rubyllm-2-token-ownership.md +82 -0
  53. data/docs/architecture/storage-execution-boundaries.md +54 -0
  54. data/docs/architecture/tool-schema-recording-gap.md +56 -0
  55. data/docs/architecture/tracing.md +2 -2
  56. data/docs/architecture/workflow-terminal-ownership-design.md +104 -0
  57. data/docs/architecture.md +222 -0
  58. data/docs/decisions/014-unified-persistence-durable-state.md +11 -0
  59. data/docs/decisions/015-tool-public-facade-and-rbs-boundary.md +3 -3
  60. data/docs/decisions/024-event-loop-single-writer-agent-runtime.md +5 -1
  61. data/docs/decisions/025-process-local-agent-ownership-and-runtime-admission.md +13 -3
  62. data/docs/decisions/026-workflow-runtime-admission-and-durable-terminal-barrier.md +5 -1
  63. data/docs/decisions/027-llm-adapter-provider-boundary.md +2 -0
  64. data/docs/decisions/030-agent-handoff-domain-and-durable-responsibility.md +7 -0
  65. data/docs/decisions/031-durable-multi-agent-coordination.md +7 -0
  66. data/docs/decisions/032-storage-backend-composition.md +85 -0
  67. data/docs/decisions/033-domain-persistence-ownership.md +79 -0
  68. data/docs/decisions/034-handoff-runner-coordination-ownership.md +78 -0
  69. data/docs/decisions/035-tool-executor-capability-ownership.md +68 -0
  70. data/docs/decisions/036-context-contract-ownership.md +86 -0
  71. data/docs/decisions/037-common-definition-ownership.md +62 -0
  72. data/docs/decisions/038-responsibility-based-source-layout.md +145 -0
  73. data/docs/decisions/039-runtime-configuration-lifecycle-ownership.md +82 -0
  74. data/docs/decisions/040-configuration-default-composition.md +105 -0
  75. data/docs/decisions/041-feature-owned-identity-registries.md +100 -0
  76. data/docs/decisions/042-feature-owned-execution-state.md +106 -0
  77. data/docs/decisions/043-storage-execution-constraint-notifications.md +75 -0
  78. data/docs/decisions/044-agent-default-and-one-shot-composition.md +106 -0
  79. data/docs/decisions/045-worker-input-restriction-ownership.md +104 -0
  80. data/docs/decisions/046-agent-responsibility-layout-and-shared-records.md +110 -0
  81. data/docs/decisions/047-recovered-execution-continuation-contract.md +116 -0
  82. data/docs/decisions/048-dispatch-preparation-worker-ownership.md +120 -0
  83. data/docs/decisions/049-initial-preparation-worker-ownership.md +111 -0
  84. data/docs/decisions/050-approval-resume-snapshot-and-commit-ownership.md +98 -0
  85. data/docs/decisions/051-execution-outcome-worker-ownership.md +153 -0
  86. data/docs/decisions/052-tool-invocation-restoration-ownership.md +92 -0
  87. data/docs/decisions/053-shared-state-coordination-ownership.md +71 -0
  88. data/docs/decisions/054-workflow-terminal-save-single-owner.md +76 -0
  89. data/docs/decisions/055-terminal-observer-failure-settlement.md +60 -0
  90. data/docs/decisions/056-workflow-terminal-policy-ownership.md +87 -0
  91. data/docs/decisions/057-storage-transaction-boundaries.md +73 -0
  92. data/docs/decisions/058-neutral-storage-primitives.md +83 -0
  93. data/docs/decisions/059-backend-contracts-and-async-clients.md +74 -0
  94. data/docs/decisions/060-runtime-settings-and-application-configuration.md +86 -0
  95. data/docs/decisions/061-persistence-failure-contracts.md +89 -0
  96. data/docs/decisions/062-content-store-service.md +52 -0
  97. data/docs/decisions/063-execution-contracts-and-services.md +88 -0
  98. data/docs/decisions/064-agent-execution-and-multi-agent-responsibility.md +36 -0
  99. data/docs/decisions/065-vector-and-embeddings-common-operations.md +38 -0
  100. data/docs/decisions/066-llm-and-tool-operation-contracts.md +20 -0
  101. data/docs/decisions/067-agent-progress-and-engine-connection.md +29 -0
  102. data/docs/decisions/068-agent-tool-child-progress-and-tool-operation.md +36 -0
  103. data/docs/decisions/README.md +52 -6
  104. data/docs/design/durable-semantic-coordination/IMPLEMENTATION_DESIGN_V2.md +6 -0
  105. data/docs/design/durable-semantic-coordination/IMPLEMENTATION_REPORT.md +6 -0
  106. data/docs/execution-boundaries-preview.md +45 -0
  107. data/docs/features.md +16 -5
  108. data/docs/getting-started.md +11 -8
  109. data/docs/migrations/0.15.md +5 -0
  110. data/docs/migrations/0.22.md +2 -2
  111. data/docs/migrations/durable-semantic-coordination-v2.md +8 -0
  112. data/docs/migrations/handoff-runner-multi-agent.md +37 -0
  113. data/docs/migrations/neutral-storage-spi.md +43 -0
  114. data/docs/migrations/parallel-tool-chat-removal.md +49 -0
  115. data/docs/migrations/persistence-failure-contracts.md +67 -0
  116. data/docs/migrations/r8-unit10.md +36 -0
  117. data/docs/migrations/r8-unit11.md +33 -0
  118. data/docs/migrations/r8-unit12.md +31 -0
  119. data/docs/migrations/r8-unit13.md +36 -0
  120. data/docs/migrations/r8-unit14.md +31 -0
  121. data/docs/migrations/r8-unit15.md +31 -0
  122. data/docs/migrations/r8-unit16.md +26 -0
  123. data/docs/migrations/r8-unit17.md +28 -0
  124. data/docs/migrations/r8-unit18.md +29 -0
  125. data/docs/migrations/r8-unit19.md +28 -0
  126. data/docs/migrations/r8-unit20.md +24 -0
  127. data/docs/migrations/r8-unit21.md +28 -0
  128. data/docs/migrations/r8-unit22.md +29 -0
  129. data/docs/migrations/r8-unit23.md +20 -0
  130. data/docs/migrations/r8-unit4.md +67 -0
  131. data/docs/migrations/r8-unit5.md +75 -0
  132. data/docs/migrations/r8-unit6.md +109 -0
  133. data/docs/migrations/r8-unit7.md +31 -0
  134. data/docs/migrations/r8-unit8.md +33 -0
  135. data/docs/migrations/r8-unit9.md +28 -0
  136. data/docs/migrations/shared-state-multi-agent.md +44 -0
  137. data/docs/migrations/storage-async-client.md +103 -0
  138. data/docs/migrations/storage-backend-composition.md +117 -0
  139. data/docs/migrations/storage-transaction-boundaries.md +74 -0
  140. data/docs/migrations/vector-async-clients.md +110 -0
  141. data/docs/persistence-backends.md +190 -215
  142. data/docs/runtime-and-concurrency.md +142 -32
  143. data/lib/phronomy/agent/admission.rb +78 -0
  144. data/lib/phronomy/{agent_already_exists_error.rb → agent/agent_already_exists_error.rb} +2 -0
  145. data/lib/phronomy/{agent_busy_error.rb → agent/agent_busy_error.rb} +2 -0
  146. data/lib/phronomy/{agent_purged_error.rb → agent/agent_purged_error.rb} +2 -0
  147. data/lib/phronomy/agent/api/agent.rb +17 -0
  148. data/lib/phronomy/{execution_rehydration_required_error.rb → agent/api/execution_rehydration_required_error.rb} +2 -0
  149. data/lib/phronomy/agent/async_event_api.rb +38 -33
  150. data/lib/phronomy/agent/base.rb +106 -294
  151. data/lib/phronomy/agent/before_llm_input.rb +64 -0
  152. data/lib/phronomy/{agent.rb → agent/composition/run_once.rb} +4 -13
  153. data/lib/phronomy/agent/context_candidate_resolver.rb +2 -2
  154. data/lib/phronomy/agent/context_importer.rb +2 -2
  155. data/lib/phronomy/agent/{context_assembler.rb → context_preparation.rb} +157 -288
  156. data/lib/phronomy/agent/control_request.rb +21 -0
  157. data/lib/phronomy/agent/{agent_execution.rb → execution/agent_execution.rb} +8 -4
  158. data/lib/phronomy/agent/{agent_invocation.rb → execution/agent_invocation.rb} +32 -63
  159. data/lib/phronomy/agent/execution/approval_resume_commit.rb +108 -0
  160. data/lib/phronomy/agent/execution/dispatch_preparation.rb +195 -0
  161. data/lib/phronomy/agent/{exact_execution.rb → execution/exact_execution.rb} +43 -23
  162. data/lib/phronomy/agent/{execution_cancellation.rb → execution/execution_cancellation.rb} +8 -5
  163. data/lib/phronomy/agent/execution/execution_coordinator.rb +1744 -0
  164. data/lib/phronomy/agent/execution/execution_failure.rb +30 -0
  165. data/lib/phronomy/agent/execution/execution_metadata.rb +54 -0
  166. data/lib/phronomy/agent/execution/execution_outcome_committer.rb +288 -0
  167. data/lib/phronomy/agent/execution/execution_registry.rb +463 -0
  168. data/lib/phronomy/agent/execution/execution_session_runner.rb +113 -0
  169. data/lib/phronomy/agent/execution/initial_preparation.rb +323 -0
  170. data/lib/phronomy/agent/execution/invocation_actions.rb +368 -0
  171. data/lib/phronomy/agent/execution/invocation_transitions.rb +124 -0
  172. data/lib/phronomy/agent/execution/runtime_record_encoder.rb +210 -0
  173. data/lib/phronomy/agent/execution_change.rb +161 -0
  174. data/lib/phronomy/agent/execution_environment.rb +36 -0
  175. data/lib/phronomy/agent/execution_extension_state.rb +21 -0
  176. data/lib/phronomy/agent/execution_observation.rb +35 -0
  177. data/lib/phronomy/agent/filterable.rb +182 -0
  178. data/lib/phronomy/agent/{handoff_context.rb → handoff/transfer_context.rb} +6 -6
  179. data/lib/phronomy/agent/{handoff_projection.rb → handoff/transfer_projection.rb} +14 -33
  180. data/lib/phronomy/agent/handoff_error.rb +7 -0
  181. data/lib/phronomy/agent/{journal_projection.rb → journal/journal_projection.rb} +4 -0
  182. data/lib/phronomy/agent/{journal_record.rb → journal/journal_record.rb} +3 -3
  183. data/lib/phronomy/agent/{llm_call_record.rb → journal/llm_call_record.rb} +2 -2
  184. data/lib/phronomy/agent/knowledge_item.rb +13 -0
  185. data/lib/phronomy/agent/{agent_root.rb → lifecycle/agent_root.rb} +6 -2
  186. data/lib/phronomy/agent/lifecycle/default_persistence.rb +29 -0
  187. data/lib/phronomy/{engine/runtime/agent_ownership_registry.rb → agent/lifecycle/ownership_registry.rb} +24 -15
  188. data/lib/phronomy/agent/persistence/agent_repository.rb +69 -0
  189. data/lib/phronomy/agent/persistence/cancellation_repository.rb +51 -0
  190. data/lib/phronomy/agent/persistence/codec.rb +338 -0
  191. data/lib/phronomy/agent/persistence/execution_repository.rb +124 -0
  192. data/lib/phronomy/agent/persistence/journal_repository.rb +63 -0
  193. data/lib/phronomy/agent/persistence/records.rb +33 -0
  194. data/lib/phronomy/agent/persistence/retention_repository.rb +70 -0
  195. data/lib/phronomy/agent/persistence/storage_schema.rb +29 -0
  196. data/lib/phronomy/agent/persistence/watermark.rb +29 -0
  197. data/lib/phronomy/agent/recovery/invocation_restorer.rb +124 -0
  198. data/lib/phronomy/agent/{recovery_coordinator → recovery/recovery_coordinator}/continuation.rb +28 -51
  199. data/lib/phronomy/agent/{recovery_coordinator → recovery/recovery_coordinator}/installation.rb +50 -55
  200. data/lib/phronomy/agent/{recovery_coordinator → recovery/recovery_coordinator}/resolution.rb +38 -43
  201. data/lib/phronomy/agent/{recovery_coordinator.rb → recovery/recovery_coordinator.rb} +26 -23
  202. data/lib/phronomy/agent/recovery/recovery_rules.rb +119 -0
  203. data/lib/phronomy/agent/recovery/recovery_support.rb +224 -0
  204. data/lib/phronomy/agent/reserved_execution.rb +16 -0
  205. data/lib/phronomy/agent/retention.rb +17 -0
  206. data/lib/phronomy/agent/runtime_binding/engine_environment.rb +60 -0
  207. data/lib/phronomy/agent/runtime_binding/engine_session_builder.rb +34 -0
  208. data/lib/phronomy/agent/runtime_binding/phase_machine_builder.rb +64 -0
  209. data/lib/phronomy/agent/runtime_binding/tool_session_builder.rb +34 -0
  210. data/lib/phronomy/agent/{ruby_llm_materializer.rb → runtime_input.rb} +19 -39
  211. data/lib/phronomy/agent/saved_context_reader.rb +55 -0
  212. data/lib/phronomy/agent/settings.rb +47 -0
  213. data/lib/phronomy/agent/state_writer.rb +166 -0
  214. data/lib/phronomy/agent/store.rb +253 -0
  215. data/lib/phronomy/{stream_callback_error.rb → agent/stream_callback_error.rb} +2 -0
  216. data/lib/phronomy/agent/{approval_evaluation_request.rb → tool_execution/approval_evaluation_request.rb} +1 -12
  217. data/lib/phronomy/agent/{tool_approval_request.rb → tool_execution/tool_approval_request.rb} +1 -10
  218. data/lib/phronomy/agent/tool_execution/tool_binding.rb +30 -0
  219. data/lib/phronomy/agent/{tool_invocation.rb → tool_execution/tool_invocation.rb} +114 -248
  220. data/lib/phronomy/agent/tool_execution/tool_invocation_actions.rb +107 -0
  221. data/lib/phronomy/agent/tool_execution/tool_invocation_transitions.rb +70 -0
  222. data/lib/phronomy/common/configuration_error.rb +7 -0
  223. data/lib/phronomy/common/error.rb +5 -0
  224. data/lib/phronomy/{agent → common/values}/immutable.rb +9 -1
  225. data/lib/phronomy/common/values/serializable.rb +32 -0
  226. data/lib/phronomy/configuration/runtime_settings.rb +49 -0
  227. data/lib/phronomy/content_store/storage_schema.rb +12 -0
  228. data/lib/phronomy/content_store/stored_contents.rb +44 -0
  229. data/lib/phronomy/context/assembly.rb +202 -0
  230. data/lib/phronomy/{context_budget_exceeded_error.rb → context/budget_exceeded_error.rb} +5 -1
  231. data/lib/phronomy/context/candidate.rb +51 -0
  232. data/lib/phronomy/context/constraint.rb +47 -0
  233. data/lib/phronomy/{agent → context}/context_plan.rb +2 -2
  234. data/lib/phronomy/{agent → context}/context_plan_validator.rb +3 -3
  235. data/lib/phronomy/{agent → context}/context_policy.rb +1 -1
  236. data/lib/phronomy/{agent → context}/context_policy_input.rb +7 -7
  237. data/lib/phronomy/{agent → context}/context_policy_input_builder.rb +1 -1
  238. data/lib/phronomy/context/default_policy.rb +140 -0
  239. data/lib/phronomy/context/final_budget_validator.rb +33 -0
  240. data/lib/phronomy/{agent → context}/llm_input_build_context.rb +2 -2
  241. data/lib/phronomy/{agent → context}/llm_input_manifest.rb +21 -21
  242. data/lib/phronomy/{agent → context}/llm_input_patch.rb +3 -3
  243. data/lib/phronomy/context/manifest_error.rb +10 -0
  244. data/lib/phronomy/context/prompt_template.rb +98 -0
  245. data/lib/phronomy/{vector_store → documents}/loader/base.rb +1 -1
  246. data/lib/phronomy/{vector_store → documents}/loader/csv_loader.rb +2 -2
  247. data/lib/phronomy/{vector_store → documents}/loader/markdown_loader.rb +3 -3
  248. data/lib/phronomy/{vector_store → documents}/loader/plain_text_loader.rb +2 -2
  249. data/lib/phronomy/{vector_store → documents}/splitter/base.rb +1 -1
  250. data/lib/phronomy/{vector_store → documents}/splitter/fixed_size_splitter.rb +2 -2
  251. data/lib/phronomy/{vector_store → documents}/splitter/recursive_splitter.rb +2 -2
  252. data/lib/phronomy/embeddings/async/async_client.rb +44 -0
  253. data/lib/phronomy/embeddings/backends/ruby_llm_embeddings.rb +48 -0
  254. data/lib/phronomy/embeddings/base.rb +43 -0
  255. data/lib/phronomy/embeddings/invalid_result_error.rb +11 -0
  256. data/lib/phronomy/embeddings/transport_error.rb +11 -0
  257. data/lib/phronomy/engine/concurrency/offload_pool.rb +39 -20
  258. data/lib/phronomy/engine/concurrency/pool_registry.rb +47 -12
  259. data/lib/phronomy/{diagnostics.rb → engine/diagnostics.rb} +1 -1
  260. data/lib/phronomy/engine/event_loop.rb +164 -630
  261. data/lib/phronomy/engine/execution_binding.rb +23 -0
  262. data/lib/phronomy/engine/execution_receiver_binding.rb +43 -0
  263. data/lib/phronomy/engine/fsm_protocol.rb +9 -0
  264. data/lib/phronomy/engine/fsm_session.rb +37 -30
  265. data/lib/phronomy/engine/metrics.rb +28 -0
  266. data/lib/phronomy/engine/runtime/timer_queue.rb +1 -1
  267. data/lib/phronomy/engine/runtime.rb +104 -95
  268. data/lib/phronomy/engine/terminal_decision.rb +7 -0
  269. data/lib/phronomy/execution/async_operation.rb +41 -0
  270. data/lib/phronomy/execution/backpressure_error.rb +7 -0
  271. data/lib/phronomy/{blocking.rb → execution/blocking.rb} +2 -2
  272. data/lib/phronomy/execution/cancellation_error.rb +7 -0
  273. data/lib/phronomy/{engine → execution}/concurrency/cancellation_token.rb +5 -1
  274. data/lib/phronomy/{engine → execution}/concurrency/deadline.rb +0 -17
  275. data/lib/phronomy/{engine → execution}/concurrency/physical_completion_task.rb +1 -1
  276. data/lib/phronomy/{engine → execution}/concurrency/result_collector.rb +1 -1
  277. data/lib/phronomy/{engine → execution}/concurrency/result_composition.rb +33 -12
  278. data/lib/phronomy/{engine/concurrency/subscriptions.rb → execution/concurrency/result_subscriptions.rb} +14 -18
  279. data/lib/phronomy/execution/concurrency/subscriptions.rb +25 -0
  280. data/lib/phronomy/execution/concurrency/worker_input_restricted.rb +14 -0
  281. data/lib/phronomy/execution/event_loop_reentrancy_error.rb +8 -0
  282. data/lib/phronomy/{execution.rb → execution/execution.rb} +57 -30
  283. data/lib/phronomy/{execution_cancellation_error.rb → execution/execution_cancellation_error.rb} +2 -0
  284. data/lib/phronomy/execution/execution_receiver.rb +78 -0
  285. data/lib/phronomy/execution/execution_scope_state.rb +35 -0
  286. data/lib/phronomy/{execution_timeout_error.rb → execution/execution_timeout_error.rb} +2 -0
  287. data/lib/phronomy/{invalid_async_entry_action_error.rb → execution/invalid_async_entry_action_error.rb} +2 -0
  288. data/lib/phronomy/{invalid_async_transition_action_error.rb → execution/invalid_async_transition_action_error.rb} +2 -0
  289. data/lib/phronomy/{invalid_async_workflow_action_error.rb → execution/invalid_async_workflow_action_error.rb} +2 -0
  290. data/lib/phronomy/{invocation_context.rb → execution/invocation_context.rb} +0 -15
  291. data/lib/phronomy/execution/invocation_controls.rb +73 -0
  292. data/lib/phronomy/execution/pool_shutdown_error.rb +7 -0
  293. data/lib/phronomy/execution/recursion_limit_error.rb +7 -0
  294. data/lib/phronomy/execution/runnable.rb +24 -0
  295. data/lib/phronomy/execution/runtime_shutdown_error.rb +7 -0
  296. data/lib/phronomy/execution/runtime_shutdown_reentrancy_error.rb +7 -0
  297. data/lib/phronomy/execution/scheduler_reentrancy_error.rb +9 -0
  298. data/lib/phronomy/{engine → execution}/task_result.rb +7 -3
  299. data/lib/phronomy/execution/timeout_error.rb +7 -0
  300. data/lib/phronomy/execution/wait_policy.rb +24 -0
  301. data/lib/phronomy/filter/filter_block_error.rb +14 -0
  302. data/lib/phronomy/generation/generator_verifier/agent_operation.rb +65 -0
  303. data/lib/phronomy/generation/generator_verifier/agent_result_receiver.rb +89 -0
  304. data/lib/phronomy/generation/generator_verifier/default_parser.rb +27 -0
  305. data/lib/phronomy/generation/generator_verifier/pipeline_state.rb +57 -0
  306. data/lib/phronomy/generation/generator_verifier/workflow_builder.rb +112 -0
  307. data/lib/phronomy/generation/generator_verifier.rb +118 -0
  308. data/lib/phronomy/generation/low_confidence_error.rb +14 -0
  309. data/lib/phronomy/llm_adapter/async/async_client.rb +47 -0
  310. data/lib/phronomy/llm_adapter/authentication_error.rb +9 -0
  311. data/lib/phronomy/llm_adapter/backends/ruby_llm.rb +183 -0
  312. data/lib/phronomy/llm_adapter/base.rb +49 -68
  313. data/lib/phronomy/llm_adapter/context_length_error.rb +9 -0
  314. data/lib/phronomy/llm_adapter/invalid_result_error.rb +10 -0
  315. data/lib/phronomy/llm_adapter/message.rb +62 -0
  316. data/lib/phronomy/llm_adapter/rate_limit_error.rb +9 -0
  317. data/lib/phronomy/llm_adapter/request.rb +79 -0
  318. data/lib/phronomy/llm_adapter/response.rb +36 -0
  319. data/lib/phronomy/llm_adapter/stream_chunk.rb +18 -0
  320. data/lib/phronomy/llm_adapter/token_usage.rb +64 -0
  321. data/lib/phronomy/llm_adapter/transport_error.rb +9 -0
  322. data/lib/phronomy/llm_adapter.rb +3 -16
  323. data/lib/phronomy/llm_context_window/token_budget.rb +6 -7
  324. data/lib/phronomy/multi_agent/admission_registry.rb +15 -2
  325. data/lib/phronomy/multi_agent/durable_subagent_coordinator.rb +108 -84
  326. data/lib/phronomy/multi_agent/execution_environment.rb +29 -0
  327. data/lib/phronomy/{agent → multi_agent}/handoff.rb +2 -2
  328. data/lib/phronomy/{agent → multi_agent}/handoff_capability_factory.rb +21 -2
  329. data/lib/phronomy/multi_agent/handoff_participant.rb +79 -0
  330. data/lib/phronomy/{agent → multi_agent}/handoff_policy.rb +1 -1
  331. data/lib/phronomy/multi_agent/handoff_runner.rb +156 -0
  332. data/lib/phronomy/{agent → multi_agent}/handoff_state.rb +2 -2
  333. data/lib/phronomy/multi_agent/orchestrator.rb +61 -75
  334. data/lib/phronomy/multi_agent/persistence/codec.rb +75 -0
  335. data/lib/phronomy/multi_agent/persistence/handoff_state_repository.rb +77 -0
  336. data/lib/phronomy/multi_agent/persistence/records.rb +27 -0
  337. data/lib/phronomy/multi_agent/persistence/storage_schema.rb +21 -0
  338. data/lib/phronomy/multi_agent/persistence/team_execution_repository.rb +124 -0
  339. data/lib/phronomy/multi_agent/persistence/team_repository.rb +69 -0
  340. data/lib/phronomy/multi_agent/reserved_child_admission.rb +88 -0
  341. data/lib/phronomy/multi_agent/runtime_binding/engine_environment.rb +35 -0
  342. data/lib/phronomy/{agent → multi_agent}/shared_state.rb +56 -39
  343. data/lib/phronomy/multi_agent/store.rb +156 -0
  344. data/lib/phronomy/multi_agent/team_coordinator.rb +87 -75
  345. data/lib/phronomy/multi_agent/team_execution.rb +1 -1
  346. data/lib/phronomy/{engine/runtime → multi_agent}/team_ownership_registry.rb +5 -5
  347. data/lib/phronomy/multi_agent/team_root.rb +1 -1
  348. data/lib/phronomy/output_parser/parse_error.rb +7 -0
  349. data/lib/phronomy/persistence/content_repository.rb +26 -0
  350. data/lib/phronomy/persistence/errors.rb +16 -0
  351. data/lib/phronomy/persistence/migration/initial_format_migration.rb +21 -21
  352. data/lib/phronomy/persistence/persistence.rb +23 -0
  353. data/lib/phronomy/persistence/save_outcome.rb +24 -0
  354. data/lib/phronomy/persistence/snapshot_comparison.rb +81 -0
  355. data/lib/phronomy/persistence/storage_boundary.rb +32 -0
  356. data/lib/phronomy/persistence/transaction.rb +86 -0
  357. data/lib/phronomy/persistence_composition/storage_schema.rb +29 -0
  358. data/lib/phronomy/persistence_composition/stores.rb +34 -0
  359. data/lib/phronomy/persistence_composition/unit4_migration.rb +276 -0
  360. data/lib/phronomy/runtime_composition/agent_defaults.rb +11 -0
  361. data/lib/phronomy/runtime_composition/configuration.rb +146 -0
  362. data/lib/phronomy/runtime_composition/configuration_defaults.rb +9 -0
  363. data/lib/phronomy/runtime_composition/evaluation_defaults.rb +7 -0
  364. data/lib/phronomy/runtime_composition/execution_defaults.rb +5 -0
  365. data/lib/phronomy/runtime_composition/generation_defaults.rb +6 -0
  366. data/lib/phronomy/runtime_composition/global_configuration.rb +38 -0
  367. data/lib/phronomy/runtime_composition/global_runtime.rb +19 -0
  368. data/lib/phronomy/runtime_composition/multi_agent_defaults.rb +9 -0
  369. data/lib/phronomy/runtime_composition/workflow_defaults.rb +4 -0
  370. data/lib/phronomy/storage/async/async_client.rb +60 -0
  371. data/lib/phronomy/storage/backend.rb +107 -0
  372. data/lib/phronomy/storage/backends/in_memory.rb +157 -0
  373. data/lib/phronomy/storage/blob_conflict_error.rb +10 -0
  374. data/lib/phronomy/storage/blobs.rb +31 -0
  375. data/lib/phronomy/storage/condition.rb +25 -0
  376. data/lib/phronomy/storage/condition_failed_error.rb +16 -0
  377. data/lib/phronomy/storage/conflict_error.rb +9 -0
  378. data/lib/phronomy/{persistence → storage}/durable_record.rb +12 -12
  379. data/lib/phronomy/storage/entry.rb +33 -0
  380. data/lib/phronomy/storage/guard_ref.rb +13 -0
  381. data/lib/phronomy/storage/not_found_error.rb +9 -0
  382. data/lib/phronomy/storage/record_codec.rb +177 -0
  383. data/lib/phronomy/storage/records.rb +61 -0
  384. data/lib/phronomy/storage/resource.rb +126 -0
  385. data/lib/phronomy/storage/scope.rb +25 -0
  386. data/lib/phronomy/storage/serialization_error.rb +9 -0
  387. data/lib/phronomy/storage/streams.rb +44 -0
  388. data/lib/phronomy/storage/transaction_error.rb +10 -0
  389. data/lib/phronomy/storage/unique_constraint_error.rb +17 -0
  390. data/lib/phronomy/storage/unsupported_backend_error.rb +9 -0
  391. data/lib/phronomy/storage/validation.rb +53 -0
  392. data/lib/phronomy/storage/view.rb +131 -0
  393. data/lib/phronomy/testing/eval/metrics.rb +1 -1
  394. data/lib/phronomy/testing/eval/scorer/llm_judge.rb +19 -3
  395. data/lib/phronomy/testing/persistence_contract/a_content_store.rb +1 -1
  396. data/lib/phronomy/testing/persistence_contract/a_journal_repository.rb +2 -2
  397. data/lib/phronomy/testing/persistence_contract/a_persistence_backend.rb +54 -48
  398. data/lib/phronomy/testing/persistence_contract/a_workflow_state_repository.rb +1 -1
  399. data/lib/phronomy/testing/persistence_contract/an_agent_repository.rb +1 -1
  400. data/lib/phronomy/testing/persistence_contract/an_execution_repository.rb +5 -5
  401. data/lib/phronomy/testing/persistence_contract/coordination_repositories.rb +52 -46
  402. data/lib/phronomy/testing/persistence_contract/neutral_storage_primitives.rb +263 -0
  403. data/lib/phronomy/testing/persistence_contract/storage_transaction_boundaries.rb +124 -0
  404. data/lib/phronomy/testing/persistence_contract.rb +4 -0
  405. data/lib/phronomy/tool/authorization.rb +77 -0
  406. data/lib/phronomy/tool/base.rb +549 -9
  407. data/lib/phronomy/tool/call_request.rb +40 -0
  408. data/lib/phronomy/{agent/tool_definition_set.rb → tool/definition_set.rb} +16 -12
  409. data/lib/phronomy/tool/operation.rb +88 -0
  410. data/lib/phronomy/tool/schema.rb +214 -0
  411. data/lib/phronomy/tool/settings.rb +31 -0
  412. data/lib/phronomy/tool/tool_error.rb +7 -0
  413. data/lib/phronomy/{agent → tool}/tool_executor.rb +10 -7
  414. data/lib/phronomy/tools/agent.rb +22 -90
  415. data/lib/phronomy/tools/mcp.rb +21 -14
  416. data/lib/phronomy/tools/vector_search.rb +4 -4
  417. data/lib/phronomy/tracing/automatic.rb +11 -6
  418. data/lib/phronomy/tracing/base.rb +1 -1
  419. data/lib/phronomy/tracing/observation.rb +37 -0
  420. data/lib/phronomy/tracing/settings.rb +36 -0
  421. data/lib/phronomy/vector_store/{async_backend.rb → async/async_client.rb} +35 -29
  422. data/lib/phronomy/vector_store/{in_memory.rb → backends/in_memory.rb} +12 -10
  423. data/lib/phronomy/vector_store/{pgvector.rb → backends/pgvector.rb} +44 -16
  424. data/lib/phronomy/vector_store/{redis_search.rb → backends/redis_search.rb} +74 -37
  425. data/lib/phronomy/vector_store/base.rb +118 -49
  426. data/lib/phronomy/vector_store/invalid_result_error.rb +12 -0
  427. data/lib/phronomy/vector_store.rb +2 -17
  428. data/lib/phronomy/version.rb +1 -1
  429. data/lib/phronomy/workflow/completion.rb +11 -0
  430. data/lib/phronomy/{workflow.rb → workflow/execution/workflow.rb} +10 -8
  431. data/lib/phronomy/workflow/execution/workflow_action_rules.rb +67 -0
  432. data/lib/phronomy/{workflow_context.rb → workflow/execution/workflow_context.rb} +5 -1
  433. data/lib/phronomy/workflow/execution/workflow_context_ownership_error.rb +7 -0
  434. data/lib/phronomy/workflow/execution/workflow_execution_environment.rb +27 -0
  435. data/lib/phronomy/workflow/execution/workflow_execution_registry.rb +186 -0
  436. data/lib/phronomy/{workflow_runner.rb → workflow/execution/workflow_runner.rb} +145 -115
  437. data/lib/phronomy/workflow/execution/workflow_settings.rb +28 -0
  438. data/lib/phronomy/workflow/persistence/codec.rb +153 -0
  439. data/lib/phronomy/workflow/persistence/state_repository.rb +63 -0
  440. data/lib/phronomy/workflow/persistence/storage_schema.rb +13 -0
  441. data/lib/phronomy/workflow/runtime_binding/workflow_engine_environment.rb +38 -0
  442. data/lib/phronomy/workflow/runtime_binding/workflow_phase_machine_builder.rb +156 -0
  443. data/lib/phronomy/workflow/runtime_binding/workflow_terminal_policy.rb +40 -0
  444. data/lib/phronomy.rb +97 -98
  445. data/scripts/api_snapshot.rb +36 -16
  446. data/scripts/storage_spi_snapshot.rb +36 -0
  447. data/sig/_private/phronomy/agent/settings.rbs +19 -0
  448. data/sig/_private/phronomy/configuration/runtime_settings.rbs +20 -0
  449. data/sig/_private/phronomy/llm_adapter/async/async_client.rbs +10 -0
  450. data/sig/_private/phronomy/multi_agent/store.rbs +8 -0
  451. data/sig/_private/phronomy/persistence/storage_boundary.rbs +7 -0
  452. data/sig/_private/phronomy/tool/settings.rbs +13 -0
  453. data/sig/_private/phronomy/tracing/settings.rbs +15 -0
  454. data/sig/_private/phronomy/workflow/execution/workflow_settings.rbs +13 -0
  455. data/sig/phronomy/agent/admission.rbs +19 -0
  456. data/sig/phronomy/agent/execution_contract.rbs +132 -0
  457. data/sig/phronomy/agent/execution_environment.rbs +20 -0
  458. data/sig/phronomy/agent/store.rbs +73 -0
  459. data/sig/phronomy/agent.rbs +14 -139
  460. data/sig/phronomy/common.rbs +7 -0
  461. data/sig/phronomy/content_store/contracts.rbs +13 -0
  462. data/sig/phronomy/context.rbs +152 -0
  463. data/sig/phronomy/embeddings/async/async_client.rbs +9 -0
  464. data/sig/phronomy/embeddings/base.rbs +17 -0
  465. data/sig/phronomy/engine/concurrency/timer_bindings.rbs +22 -0
  466. data/sig/phronomy/engine/control_bindings.rbs +11 -0
  467. data/sig/phronomy/engine/control_protocols.rbs +23 -0
  468. data/sig/phronomy/engine/execution_binding.rbs +6 -0
  469. data/sig/phronomy/engine/execution_receiver.rbs +15 -0
  470. data/sig/phronomy/engine/observability.rbs +13 -0
  471. data/sig/phronomy/execution/async_operation.rbs +7 -0
  472. data/sig/phronomy/execution/blocking.rbs +5 -0
  473. data/sig/phronomy/execution/concurrency/cancellation_token.rbs +13 -0
  474. data/sig/phronomy/execution/concurrency/deadline.rbs +10 -0
  475. data/sig/phronomy/execution/concurrency/result_composition.rbs +7 -0
  476. data/sig/phronomy/execution/control_protocols.rbs +18 -0
  477. data/sig/phronomy/execution/errors.rbs +7 -0
  478. data/sig/phronomy/execution/execution.rbs +41 -0
  479. data/sig/phronomy/execution/execution_receiver.rbs +40 -0
  480. data/sig/phronomy/execution/execution_scope_state.rbs +9 -0
  481. data/sig/phronomy/execution/invocation_context.rbs +18 -0
  482. data/sig/phronomy/execution/invocation_controls.rbs +13 -0
  483. data/sig/phronomy/execution/task_result.rbs +29 -0
  484. data/sig/phronomy/extensions.rbs +0 -21
  485. data/sig/phronomy/handoff.rbs +12 -4
  486. data/sig/phronomy/llm_adapter/backends/ruby_llm.rbs +6 -0
  487. data/sig/phronomy/llm_adapter/base.rbs +14 -0
  488. data/sig/phronomy/llm_adapter/usage.rbs +14 -0
  489. data/sig/phronomy/llm_adapter/values.rbs +43 -0
  490. data/sig/phronomy/llm_context_window.rbs +10 -0
  491. data/sig/phronomy/multi_agent/reserved_child_admission.rbs +8 -0
  492. data/sig/phronomy/multi_agent/store.rbs +54 -0
  493. data/sig/phronomy/multi_agent.rbs +24 -3
  494. data/sig/phronomy/persistence/errors.rbs +18 -0
  495. data/sig/phronomy/persistence/migration.rbs +13 -0
  496. data/sig/phronomy/persistence/transaction.rbs +19 -0
  497. data/sig/phronomy/persistence.rbs +3 -185
  498. data/sig/phronomy/persistence_composition.rbs +19 -0
  499. data/sig/phronomy/runtime_composition/configuration.rbs +36 -0
  500. data/sig/phronomy/storage/async/async_client.rbs +8 -0
  501. data/sig/phronomy/storage/backends/in_memory.rbs +9 -0
  502. data/sig/phronomy/storage/contracts.rbs +160 -0
  503. data/sig/phronomy/tool.rbs +58 -5
  504. data/sig/phronomy/tracing/observation.rbs +7 -0
  505. data/sig/phronomy/vector_store/async/async_client.rbs +13 -0
  506. data/sig/phronomy/vector_store/base.rbs +23 -0
  507. data/sig/phronomy/workflow/execution/workflow_execution_environment.rbs +14 -0
  508. data/sig/phronomy/workflow/runtime_binding/workflow_terminal_policy.rbs +7 -0
  509. data/sig/phronomy/workflow/store.rbs +8 -0
  510. data/sig/phronomy/workflow.rbs +1 -1
  511. data/sig/phronomy.rbs +0 -49
  512. metadata +462 -130
  513. data/lib/phronomy/agent/agent_invocation_session_builder.rb +0 -584
  514. data/lib/phronomy/agent/concerns/before_llm_input.rb +0 -66
  515. data/lib/phronomy/agent/concerns/error_translation.rb +0 -45
  516. data/lib/phronomy/agent/concerns/filterable.rb +0 -184
  517. data/lib/phronomy/agent/context/capability/base.rb +0 -507
  518. data/lib/phronomy/agent/context/instruction/prompt_template.rb +0 -102
  519. data/lib/phronomy/agent/context_parts/validators/final_budget_validator.rb +0 -37
  520. data/lib/phronomy/agent/context_policies/default.rb +0 -142
  521. data/lib/phronomy/agent/execution_coordinator.rb +0 -3151
  522. data/lib/phronomy/agent/handoff_execution_coordinator.rb +0 -143
  523. data/lib/phronomy/agent/handoff_request.rb +0 -45
  524. data/lib/phronomy/agent/handoff_runner.rb +0 -178
  525. data/lib/phronomy/agent/phase_machine_builder.rb +0 -152
  526. data/lib/phronomy/agent/provider_call_outcome.rb +0 -106
  527. data/lib/phronomy/agent/recovery_support.rb +0 -504
  528. data/lib/phronomy/agent/selection/candidate.rb +0 -53
  529. data/lib/phronomy/agent/selection/constraint.rb +0 -49
  530. data/lib/phronomy/agent/token_budget_resolver.rb +0 -70
  531. data/lib/phronomy/agent/tool_call_intercepted.rb +0 -29
  532. data/lib/phronomy/agent/tool_invocation_session_builder.rb +0 -276
  533. data/lib/phronomy/configuration.rb +0 -59
  534. data/lib/phronomy/engine/concurrency/cancellation_scope.rb +0 -124
  535. data/lib/phronomy/engine/concurrency/operation_binding.rb +0 -43
  536. data/lib/phronomy/generator_verifier.rb +0 -369
  537. data/lib/phronomy/invalid_context_budget_configuration_error.rb +0 -8
  538. data/lib/phronomy/llm_adapter/ruby_llm.rb +0 -47
  539. data/lib/phronomy/metrics.rb +0 -26
  540. data/lib/phronomy/multi_agent/parallel_tool_chat.rb +0 -116
  541. data/lib/phronomy/persistence/durable_codec.rb +0 -706
  542. data/lib/phronomy/persistence/in_memory.rb +0 -690
  543. data/lib/phronomy/persistence/repository_facades.rb +0 -535
  544. data/lib/phronomy/persistence.rb +0 -276
  545. data/lib/phronomy/recovery.rb +0 -186
  546. data/lib/phronomy/ruby_llm_patches.rb +0 -24
  547. data/lib/phronomy/runnable.rb +0 -54
  548. data/lib/phronomy/token_usage.rb +0 -85
  549. data/lib/phronomy/vector_store/embeddings/base.rb +0 -44
  550. data/lib/phronomy/vector_store/embeddings/ruby_llm_embeddings.rb +0 -47
  551. data/lib/phronomy/workflow/phase_machine_builder.rb +0 -205
  552. data/lib/phronomy/workflow_recovery.rb +0 -123
  553. data/sig/phronomy/llm_adapter.rbs +0 -11
  554. data/sig/phronomy/runtime.rbs +0 -76
  555. /data/lib/phronomy/agent/{llm_operation_result.rb → execution/llm_operation_result.rb} +0 -0
  556. /data/lib/phronomy/{canonical_json.rb → common/canonical_json.rb} +0 -0
  557. /data/lib/phronomy/{event.rb → engine/event.rb} +0 -0
@@ -0,0 +1,104 @@
1
+ # r8第1適用版:Context/ToolとExecutionの共通基盤
2
+
3
+ > Current boundary: r8 unit 6 supersedes the historical Chat/SDK ownership and
4
+ > adapter extension SPI below. Agent uses LLMAdapter values; the backend owns SDK
5
+ > construction/interception; Tool owns canonical schema validation. See
6
+ > `docs/architecture/r8-unit6.md` and `docs/migrations/r8-unit6.md`.
7
+
8
+
9
+ 対象は2026-09-30に確認したmain `653e255a34fe4062d4beca47530e084fdd3a6ba9`。設計基準は同日更新のr8修正仕様・directory配置資料である。本変更はその第1適用単位であり、r8全体、S1全項目、S2/S3全受入条件の完了を意味しない。互換alias・転送だけの旧APIは残さない。
10
+
11
+ ## 実装した責務と操作
12
+
13
+ | 所有者 | 共通基盤が実行すること | 利用側に残すこと |
14
+ |---|---|---|
15
+ | `Context::Assembly` | Policyを一度呼びPlanを検証する。内容を正規化し、最終予算を検査してManifestを保存する | Agentはsnapshotを取得し、保存直前のwatermark再確認とAgent実行記録更新を行う |
16
+ | `Tool::DefinitionSet` | Tool定義の正規化、名前重複と保存済み定義の整合性を検証する | Agentは自身のTool alias・decorator・runtime実体を準備する |
17
+ | `Tool::Authorization` | 不変の引数・認可contextでfacts→requirement→policy→decisionを評価する | Agentは対象実行の照合、承認状態、受付結果、supervisionを管理する |
18
+ | `Tool::ToolExecutor` | cooperative/offloadedの実行規則と結果を扱う | Engineのpool選択はExecutionの機構接続へ委ねる |
19
+ | `LLMAdapter::Base` / `RubyLLM` | 同期生成とchat構築・設定・message/tool-call構築。RubyLLM実装がSDK失敗を変換する | Agentは自身の保存データ・Tool定義を検証してadapterへ渡す |
20
+ | `Execution` | submitの入口、fan-out/fan-in、結果合成、取消・期限・待機規則 | Engineはpool・timer・RuntimeとFSMの機構を実装する |
21
+ | `Tracing::Observation` | 明示的な観測とPII秘匿。実際の返り値は変えない | Runnableはinvoke/stream/batchの実行契約を持つ |
22
+
23
+ ContextとToolはAgentの薄い型定義の置場ではなく、実際の共通手順を所有する。ただし、Contextの現在の入力にはAgent由来の識別情報や由来情報が残る。完全に汎用の新domainモデルまで設計し直したものではない。ToolのDSL基底は引き続きRubyLLM::Toolを使用する。
24
+
25
+ `Context::Assembly#prepare(input:, policy:, adapter_identity:)` は保存transaction外でPolicyを呼ぶ。`#store(prepared, contents:)` は呼出側が渡す同じtransactionのcontents repositoryだけを使い、自分では独立transactionを開始しない。初回とfollow-upのAgent commitは既存transaction内でManifestとAgentExecutionの参照を保存する。後続書込に失敗したときManifestもrollbackされ、Policyは再実行されない。live projectionをcommit後に適用する既存順序を維持する。これはP02のAgent/Context部分の検証であり、任意domainの外側transaction参加を完成させたものではない。
26
+
27
+ Executionは`_ExecutionBackend`の操作に依存する。構成処理が遅延providerを設定し、Engineの`ExecutionBinding`がsubmit/afterを実装する。settled TaskResultの生成・map/flat_map/all_settled・待機制約の確認ではEngineを読み込まない。Runtime取得は実際のsubmit/タイマー登録時に行う。単なる名義移管に留めず、機構参照をここへ集約した。
28
+
29
+ WorkflowのFINISHと終了値は`Workflow::Completion`が所有し、WorkflowRunnerがFSM側へ変換する。FSMSession専用のEvent/FSMProtocol/TerminalDecisionはEngineに置く。Agent・MultiAgentのFSM専用接続の全面分離は残っている。
30
+
31
+ ## 公開名・配置の変更
32
+
33
+ | 旧配置・API | 新配置・API | 判断 |
34
+ |---|---|---|
35
+ | `agent/context_contract/` と `Agent::ContextPolicy` 等 | `context/`、`Context::ContextPolicy` 等 | Policy・Plan・Manifest・検証を共通操作と同じ所有者へ統合 |
36
+ | `agent/context_policies/default.rb` | `context/default_policy.rb`、`Context::DefaultPolicy` | 具体Policyも同domainに配置 |
37
+ | `Agent::Context::Instruction::PromptTemplate` | `Context::PromptTemplate` | Agent内の旧公開名を削除 |
38
+ | `Agent::Selection::{Candidate,Constraint}` | `Context::{Candidate,Constraint}` | 薄いSelection下位区分を削除 |
39
+ | `Agent::LLMInputPatch` / `LLMInputBuildContext` | `Context::LLMInputPatch` / `LLMInputBuildContext` | hook入力・返却値の所有を統一 |
40
+ | `ContextBudgetExceededError` | `Context::BudgetExceededError` | LLMのprovider失敗ではなくContext予算失敗 |
41
+ | `agent/context_assembly/` | `context/assembly.rb` とAgent直下の準備・状態・入力処理 | Context共通手順、Agent snapshot/state、LLM SDK処理を分離 |
42
+ | `Agent::Context::Capability::Base` | 実装本体の `Tool::Base` | 旧名とaliasを削除 |
43
+ | `agent/tool_execution/tool_definition_set.rb` | `tool/definition_set.rb` | 共通定義処理を移管。Agent固有生成はAgent内 |
44
+ | `execution_contract/` と `execution_services/` | `execution/` と必要な `execution/concurrency/` | 操作・値・共通規則を統合。`execution_result`等の薄い別分割を追加しない |
45
+ | `WorkerSubmission` | `Execution.submit` | 転送専用moduleを削除 |
46
+ | `Runnable#trace` | `Tracing::Observation.trace` | 実行基盤から観測への依存を除去 |
47
+ | `tool/contract`、`filter/contract`、`output_parser/contract`、`agent/lifecycle_contract` | 各所有domain配下の例外ファイル | 例外だけのdirectoryを削除。既存の意味を持つ例外定数名は実体として保持 |
48
+
49
+ 独自LLM adapterはcomplete/streamだけでなく、`build_chat`、`configure_chat`、`message`、`tool_call`を実装する。`identity`には基底の既定値、`input_budget`にはnilの既定値がある。正確なkeywordと返却契約は`sig/phronomy/llm_adapter/base.rbs`を参照する。SDK固有例外はadapter操作の境界でLLM失敗へ変換し、元のcauseを保持する。アプリ例外・取消は無関係なprovider失敗へ変換しない。
50
+
51
+ 既存設定APIの`tool_result_max_size`/loggerはアプリ構成から中立RuntimeSettingsへ供給する。Toolから構成factoryへの参照を除き、default・nil・scoped copyの意味を維持する。RBSは`sig/`と`sig/_private/`に置き、実装定数・宣言所有者に基づいて依存を解析する。
52
+
53
+ ## r8項目別の到達点
54
+
55
+ | 項目 | この適用版 | 未完了部分 |
56
+ |---|---|---|
57
+ | DP01 Context集約 | 主対象を実装 | より広いdomain入力・公開操作レビューは残る |
58
+ | DP02 Tool共通基盤 | 定義・認可評価・呼出しの共通部分を実装 | Agent側FSM接続と全親子認可の整理はDP12/P04 |
59
+ | DP03 Execution統合 | 実装 | domain全体のFSM利用整理を完了としない |
60
+ | DP04 Persistence | 未着手 | facade除去、共通transaction/参加/成否照合API |
61
+ | DP05 domain保存schema | 未着手 | MultiAgent/Workflowのstorage_contract統合 |
62
+ | DP06 LLM集約 | 前提部分のみ | llm_contractとllm_adapterの全面統合 |
63
+ | DP07 薄い失敗directory統合 | 実装 | domainごとの失敗語彙全体の再設計ではない |
64
+ | DP08 composition集約 | 接続追加のみ | runtime/persistence/agent構成の物理統合 |
65
+ | DP09 Embeddings独立 | 未着手 | vector_storeからの独立配置 |
66
+ | DP10 Documents | 未着手 | loader/splitter再配置 |
67
+ | DP11 assembly/concerns分解 | 主対象を実装 | Agent固有処理はAgent直下に保持 |
68
+ | DP12 domain実行接続 | Workflow終了境界など一部 | Agent/ToolInvocation/Teamのdomain判断とFSM接続の全面分離 |
69
+ | DP13 Recovery/Handoff | 未着手 | domain復旧・Persistence成否照合・親子操作の所有整理 |
70
+ | P02保存参加 | Agent/Contextの既存transactionで検証 | 外側scope、savepoint、複数domainの公開参加API |
71
+ | P01/P03〜P06保存・親子連携 | 未着手 | 下記の原子性条件を確定する必要がある |
72
+ | 155組・393件の三角形レビュー | 再判定未完了 | 図の再解析は判定完了の代わりにはならない |
73
+
74
+ NC/F/RMの全項目を「対応済み」とする資料は作成していない。受入可否はこの表の実装単位と同梱テスト証拠に限定する。
75
+
76
+ ## Persistenceをこの適用単位から外した理由
77
+
78
+ 現在のAgent初回受付は保存transaction内でTeam予約を読む。AgentからTeam内部への参照は最終設計では解消すべきだが、検証を単純に先行呼出へ移すと次の競合が生じる。
79
+
80
+ 1. 親側が予約の有効性を確認する。
81
+ 2. 別の処理が予約を取り消す。
82
+ 3. Agentが新しいtransactionで受付記録を保存し、取消済みの子を開始してしまう。
83
+
84
+ 次の適用単位では、親が所有する予約確認とAgent受付記録を同一scopeで行う参加APIが必要である。親は予約規則、Agentは受付規則、Persistenceは参加とcommit境界を所有する。Agentが親kindをswitchしてTeamを選ぶ現在の逆依存を、新しいcallbackの裏へ隠すだけでは解決にならない。
85
+
86
+ 具体的に未確定なのは、参加操作の公開keyword/返却値、取消との競合条件、commit後のRuntime admission、停止後の同じ子IDによる照会・再開である。Workflowのhalt/finish snapshotだけで任意action内の子実行が耐障害化されるとは扱わない。Workflow→Agent/Teamの具体経路、checkpoint、結果取込一回性をP05で定める。成否不明は単一record一致だけで成功にせず、複数domainの証拠をP06で定める。
87
+
88
+ そのため既存Persistence facade、Team受付検証、予約・子記録のtransaction境界を本変更では改変しない。保証を弱めた仮実装を入れず、次の仕様・実装単位として残す。
89
+
90
+ ## 解析図の読み方
91
+
92
+ 実ソースとRBSから再生成する。従来の水平帯・グループ色・個別module枠を維持し、文字の背景は透過。M33/M41/M44への矢印は表示のみ省略し、JSON・行列・境界判定にはすべて残す。旧IDは再利用せず退役させる。
93
+
94
+ これは修正版candidateの実測図であり、全r8完了時の構想図ではない。残る循環・逆依存もそのまま出力する。静的解析で見えない注入先・動的dispatchはRBSだけで完全に証明できない。Engine機構接続とdomain保存の実行テストを併用する。
95
+
96
+ ```bash
97
+ bundle exec rbs -I sig validate
98
+ python -m pip install -r tools/architecture/tools/requirements.txt
99
+ python -m unittest discover -s tools/architecture/tests -v
100
+ # lib/sigをcommitした後、未公開candidateでは次の指定を用いる
101
+ python tools/architecture/refresh_diagram.py . tmp/architecture-r8-unit1 --candidate
102
+ ```
103
+
104
+ 同梱SVGのSHAは作成用のローカルcandidateを示す。利用者が適用してcommitしたSHAとは異なるため、適用後の図はそのcheckoutで再生成する。Rubyの検証環境、件数、skip理由、未検証環境と適用手順は配布パッケージの検証報告を参照する。
@@ -0,0 +1,72 @@
1
+ # r8 unit 10: C01 MultiAgent execution connection
2
+
3
+ Contract placement follows ownership of meaning and invariants, not reuse.
4
+ AdmissionRegistry and TeamOwnershipRegistry already existed in MultiAgent.
5
+ They remain there; neither moves to Engine and no generic Registry is added.
6
+
7
+ | Owner | Responsibility |
8
+ | --- | --- |
9
+ | MultiAgent AdmissionRegistry | One synchronous coordination call per live owner; close admission and wait for admitted calls |
10
+ | MultiAgent TeamOwnershipRegistry | One live Team per ID and environment; class/store consistency, construction exclusion, shutdown cleanup |
11
+ | MultiAgent TeamCoordinator / HandoffRunner | Coordination, durable reservations, child operations, scheduling, aggregation, recovery and outcomes |
12
+ | MultiAgent ExecutionEnvironment | Private process-local connection needed by C01: registry access, owning-environment validity and submission |
13
+ | MultiAgent EngineEnvironment in runtime_binding | Runtime selection, participant registration/lookup, Runtime identity comparison and Execution submission to the captured Runtime |
14
+ | Engine Runtime | Generic participant lifecycle: close, wait under one deadline, stop resources, then finalize |
15
+ | runtime_composition/multi_agent_defaults.rb | Lazy selection of the environment and default persistence factory |
16
+
17
+ There are two registrations. Recording a Team or an active coordination call
18
+ inside a Registry is a MultiAgent operation. Registering that Registry as a
19
+ Runtime shutdown participant is an implementation connection. Previously the
20
+ Registry class methods and their callers mixed these two responsibilities.
21
+ Team/Handoff also selected Runtime directly, and Team cancellation submitted
22
+ work directly to it. The environment port separates those concrete connections.
23
+
24
+ Runtime's existing begin_draining / wait_until_idle / optional
25
+ after_runtime_shutdown protocol remains unchanged. Registry methods define
26
+ what those callbacks mean for MultiAgent. The admission registry waits for
27
+ active coordination calls; Team ownership waits for in-progress construction,
28
+ not for every retained Team to disappear. Live Team references are cleared
29
+ only after successful resource shutdown. Runtime acquires no Team/Handoff rules.
30
+ The shared callback protocol alone is not a reason to add a new logical Contract.
31
+
32
+ The default adapter shares registries by their existing class keys within each
33
+ Runtime. Concurrent adapters get the same registered instance. Lookup does not
34
+ register a participant, including after draining starts. Admission acquisition
35
+ continues to reject a stopped/failed Runtime; a retained ownership registry can
36
+ still be looked up, while its own construction gate rejects new work.
37
+
38
+ Team and Handoff capture their environment on construction. Existing objects do
39
+ not switch registry or cancellation destination when the provider changes.
40
+ The default adapter compares the captured Runtime with the current default to
41
+ preserve stale-owner rejection. Cancellation submission uses the captured
42
+ Runtime explicitly. The environment itself is neither persisted nor authority
43
+ for a durable execution. This is an internal composition extension, not a new
44
+ supported application plugin API.
45
+
46
+ Public Team/Handoff signatures, exception classes, durable IDs, record schemas,
47
+ CAS rules, parent/child atomic participation and recovery semantics are unchanged.
48
+ ReservedChildAdmission still validates domain reservations within the shared
49
+ persistence scope. It is distinct from the process-local AdmissionRegistry.
50
+ Engine lifecycle and Execution completion/cancellation rules are unchanged.
51
+
52
+ ## Evidence and remaining scope
53
+
54
+ Standalone tests use both registries without loading Engine. Connection tests
55
+ exercise Team identity and store consistency, duplicate Handoff calls, release
56
+ on failure, stale-owner rejection, original-environment cancellation, callback
57
+ cleanup and real worker submission after default Runtime replacement. Existing
58
+ shutdown tests cover concurrent registration, construction during draining,
59
+ failed EventLoop closure, deadlines and finalization. Durable coordination and
60
+ recovery suites remain acceptance gates.
61
+
62
+ The dependency model adds M89/G63 for multi_agent/runtime_binding. AST guards
63
+ reject Runtime/Engine selection and private shutdown registration/lookup inside
64
+ MultiAgent domain files. Graph guards reject direct domain-to-Engine/binding
65
+ dependencies while retaining lower-level reverse-dependency restrictions.
66
+ Measured Ruby/RBS references remain visible; these are scoped rules, not proof
67
+ that the complete dependency graph is acyclic or every Contract is complete.
68
+
69
+ Remaining work includes Workflow connections and durable child outcomes,
70
+ MultiAgent's existing global/default persistence selection, broader semantic
71
+ dependency review, and live-service/additional persistence acceptance gates.
72
+ This unit completes the proposed C01 Runtime connection split, not all C01 work.
@@ -0,0 +1,71 @@
1
+ # r8 unit 11: C04 concrete Policy and LLM connection selection
2
+
3
+ Contract placement follows ownership of meaning and invariants, not reuse.
4
+ This unit addresses review findings B01 and B02: Agent::Base selected the
5
+ concrete DefaultPolicy, and InvocationActions constructed the concrete LLM
6
+ AsyncClient. Neither choice belongs to Agent progress decisions.
7
+
8
+ | Owner | Responsibility |
9
+ | --- | --- |
10
+ | Agent::Base / C04 | Declare, validate, inherit and use a ContextPolicy |
11
+ | ContextPolicy / C05 | Context-selection operation contract |
12
+ | DefaultPolicy implementation / I01 | Existing selection strategy and token-budget allocation |
13
+ | runtime_composition/agent_defaults.rb / A01 | Install DefaultPolicy through the existing Base.context_policy DSL |
14
+ | Agent InvocationActions / C04 | Prepare the LLM request, request a client through the owning environment, track completion and deliver progress |
15
+ | Agent ExecutionEnvironment | Private connection capability to build an LLM client for the supplied adapter |
16
+ | Agent EngineEnvironment / I07 | Select AsyncClient and bind submission to the captured Runtime |
17
+ | LLM AsyncClient / I06 | Run the complete C09 operation through C13 submission; forward stream chunks and cancellation |
18
+ | LLMAdapter / C09 | Synchronous complete/stream operations and request/response rules |
19
+
20
+ Ordinary require "phronomy" installs the existing DefaultPolicy instance.
21
+ Base no longer supplies a concrete fallback; an unconfigured root raises a
22
+ ConfigurationError. No supported loading path is left unconfigured. Class
23
+ inheritance and explicit Policy overrides retain their existing semantics.
24
+ Selecting the default does not create configuration, stores or a Runtime.
25
+ This does not change DefaultPolicy's algorithm or introduce a policy registry.
26
+
27
+ InvocationActions now asks its retained environment for the LLM client.
28
+ It still reads the configured adapter at dispatch time. The Engine binding
29
+ constructs AsyncClient with itself as the existing C13 submitter protocol;
30
+ AsyncClient does not depend on the Agent environment type. No generic factory
31
+ registry, new logical Contract or public application API is introduced.
32
+
33
+ The client forwards the original TaskResult rather than replacing it. Logical
34
+ cancellation and physical worker completion remain distinct. An explicit pool
35
+ still uses Execution's existing pool-selection protocol and overrides the
36
+ injected submitter. A standalone client with no injected submitter continues
37
+ to resolve the current default Runtime at each call. Client construction
38
+ starts no Runtime resources.
39
+
40
+ For Agent calls, submission now uses the Agent's captured Runtime, matching
41
+ its sessions and other work. Replacing the default Runtime cannot redirect
42
+ only its LLM worker to a different owner. A stopped owner rejects new work
43
+ through the existing RuntimeShutdownError. Provider errors, admission failure,
44
+ chunk ordering, cancellation and completion are not translated by this change.
45
+ Public Agent/Policy signatures, manifests, durable schemas and recovery rules
46
+ are unchanged. The private AsyncClient constructor adds an optional submitter;
47
+ its private RBS uses the existing _ExecutionSubmitter interface.
48
+
49
+ ## Evidence and remaining scope
50
+
51
+ Regression tests cover ordinary lazy loading, inherited/explicit Policies,
52
+ complete and streaming Agent calls after default Runtime replacement, live
53
+ adapter selection, provider worker ownership and EventLoop callback ownership.
54
+ Connection tests cover resource-free construction and stopped-owner rejection.
55
+ Async client tests cover the narrow submitter, explicit pool precedence and
56
+ physical completion after cancellation; existing failure/backpressure tests
57
+ remain acceptance gates.
58
+
59
+ Ruby AST guards reject DefaultPolicy and AsyncClient references in Agent domain
60
+ files. The Ruby/RBS graph gate separately rejects Agent domain dependencies on
61
+ llm_adapter/async and permits the binding connection. Existing lower-level
62
+ reverse-dependency rules remain intact. These checks have the same static
63
+ analysis limitations as the existing architecture tooling; they do not prove
64
+ that all logical Contract dependencies are acyclic or complete.
65
+
66
+ B01 and B02 are addressed in this candidate. C04 is not declared globally
67
+ complete. Remaining review includes C01 Orchestrator inheritance from the
68
+ concrete Agent tool, C02 Workflow execution connections and separately scoped
69
+ durable child behavior, and Recovery's domain/persistence responsibilities.
70
+ Existing domain-level explicit/configured/default store selection is not itself
71
+ a defect: concrete default persistence factories are already in composition.
@@ -0,0 +1,67 @@
1
+ # r8 unit 12: C01 subagent operations use the C06 Tool contract
2
+
3
+ Contract placement follows ownership of meaning and invariants, not reuse.
4
+ This unit addresses B03: Orchestrator.subagent generated a subclass of the
5
+ concrete Tools::Agent implementation (I04). The generated class replaced Agent
6
+ creation and child coordination, but inherited Tool operation rules incidentally.
7
+
8
+ | Owner | Responsibility |
9
+ | --- | --- |
10
+ | MultiAgent / C01 | Define the subagent operation, child class, knowledge/context inheritance, child error policy and durable reconciliation |
11
+ | Agent / C04 | Public child invocation and recovery outcomes |
12
+ | Tool / C06 | Input schema, Tool error policy, result limits and completion-handle requirements |
13
+ | Execution / C13 | Nonblocking completion composition and physical completion propagation |
14
+ | Tools::Agent / I04 | Standalone concrete Agent Tool construction through from_agent |
15
+
16
+ Orchestrator remains an Agent::Base subclass: a coordinating Agent is a valid
17
+ C01-to-C04 relationship. Its generated subagent Tool now derives directly from
18
+ Tool::Base and explicitly declares cooperative execution and its input schema.
19
+ Generating this domain-owned operation belongs to C01; no runtime registry,
20
+ factory, new logical Contract or composition layer is needed for that operation.
21
+
22
+ Tool::Base has a private call_async_operation helper that validates inputs,
23
+ requires a completion handle, applies Tool error policy and limits successful
24
+ results. Its block supplies the domain operation. It does not create Agents,
25
+ select implementations, wait for completion or decide how many application
26
+ filters to run. Both the subagent operation and Tools::Agent use this helper.
27
+ The default Tool::Base#call_async path and synchronous-call delegation are
28
+ unchanged, including the unit 9 result-transformation behavior.
29
+
30
+ ExecutionRehydrationRequiredError remains an Agent-domain outcome. Tools::Agent
31
+ and the C01 operation retain their private pass-through hooks; C06 does not
32
+ reference this error or interpret recovery. Generic errors retain their original
33
+ backtrace when wrapped; ToolError and CancellationError remain unchanged.
34
+ Suppression logging uses C06's existing RuntimeSettings logger capability.
35
+
36
+ An ordinary asynchronous subagent call still checks cancellation before schema
37
+ validation, starts the child without occupying a waiting offload worker, maps
38
+ its output and applies Tool policy. The subagent on_error option continues to
39
+ control child failure (raise or skip); it is distinct from Tool on_error policy.
40
+
41
+ An admitted durable child follows the existing reconciliation path directly.
42
+ It is reconciled even with a cancelled parent token; unknown outcomes and
43
+ recovery requirements are not hidden. This path retains its existing validation,
44
+ result and cancellation behavior, without adding the ordinary-call truncation
45
+ or error-suppression pipeline. Agent-owned configured result transformations
46
+ still wrap either path in the configured order, including repeated filters.
47
+ Parent/child IDs, reservations, stores, persistence schemas and recovery rules
48
+ are unchanged. Logical settlement does not falsely imply physical completion.
49
+
50
+ ## Evidence and remaining scope
51
+
52
+ Non-Agent Tool tests cover asynchronous validation/coercion, errors, result
53
+ limits, cancellation and separate physical completion. Subagent tests cover
54
+ operation without Tools::Agent, ordinary and admitted-child cancellation,
55
+ recovery error identity and repeated transformations after truncation. Existing
56
+ pool-starvation, knowledge inheritance, durable coordination/restart and result
57
+ transformation tests remain acceptance gates.
58
+
59
+ The AST gate rejects concrete Tools references in C01 domain files and
60
+ Agent recovery interpretation in C06. The Ruby/RBS graph gate rejects C01
61
+ domain-to-tools implementation dependencies. Existing lower-level and Engine
62
+ binding rules remain intact. These are targeted regression checks, not proof
63
+ of all logical Contract dependencies or global acyclicity.
64
+
65
+ B03 is addressed in this candidate. C02 Workflow execution connections, its
66
+ separately scoped durable child guarantees, and broader Recovery responsibility
67
+ review remain. No completed status is asserted for all of C01/C02/C04.
@@ -0,0 +1,61 @@
1
+ # r8 unit 13: C02 Workflow rules and Engine connections
2
+
3
+ Contract placement follows ownership of meaning and invariants, not reuse.
4
+ This unit addresses B04: WorkflowRunner and its registry previously selected
5
+ Runtime, built FSMSession instances and constructed Engine event envelopes.
6
+ The phase compiler also contained Workflow callback rules alongside the
7
+ state_machines translation.
8
+
9
+ | Owner | Responsibility |
10
+ | --- | --- |
11
+ | Workflow / C02 | Topology, callback rules, segment admission, identity/owner checks, hydration, snapshots, persistence outcome classification and recovery-required retention |
12
+ | Workflow runtime binding | Compile topology into state_machines, build/register sessions, select the owning Runtime and translate classified outcomes into terminal decisions |
13
+ | Execution / C13 | Completion handles and receiver lifecycle/routing protocol |
14
+ | Engine | Serial dispatch, atomic delivery, generic FSM execution and terminal gate |
15
+ | Application | State actions, guards, external event correlation and child operation choices |
16
+
17
+ WorkflowActionRules owns synchronous entry, transition and exit callback
18
+ constraints, optional event arguments and adoption of returned WorkflowContext
19
+ values. The compiler installs these rules as machine callbacks. Initial entry
20
+ callbacks also pass through the rules before reaching the generic FSM session.
21
+ Application callback order remains exit, transition action, entry.
22
+
23
+ WorkflowExecutionEnvironment is a private C02 connection port. Composition
24
+ installs its provider; WorkflowEngineEnvironment implements it. Compiling a
25
+ Workflow captures its environment without starting an EventLoop, workers or
26
+ execution registration. Starts, durable loads, live signals, terminal saves,
27
+ completion and admission release use that same owner. Changing the default
28
+ Runtime does not silently move a compiled Workflow or its continuations to a
29
+ different owner. Recompile the Workflow after replacing/stopping that Runtime.
30
+ Scalar per-call configuration and configured repository resolution retain their
31
+ existing behavior. Tracing keeps its independent existing execution composition.
32
+
33
+ WorkflowExecutionRegistry remains in C02. workflow_instance_id, opaque owner
34
+ token and fsm_session_id remain distinct. Routing resolves the current target
35
+ under the existing lifecycle lock; ExecutionReceiverBinding constructs the
36
+ Engine event within the same atomic delivery operation. No new registry or
37
+ public extension API is introduced.
38
+
39
+ Runner continues to classify terminal persistence results as success, known
40
+ failure or outcome unknown. The binding only translates these outcomes into
41
+ complete, fail or retire instructions. A successful terminal notification still
42
+ requires confirmed persistence. An uncertain outcome still retires the session
43
+ while retaining recovery-required admission; it does not announce success or
44
+ release another owner's segment. Readback/reconciliation does not retry a save.
45
+ Admission is acquired before durable load, and rejected competitors do not load.
46
+
47
+ ## Evidence and remaining scope
48
+
49
+ Existing tests cover competing admission, immutable terminal snapshots, lost
50
+ responses, unknown outcomes, shutdown, wait/resume, live event routing and action
51
+ ordering. New tests cover standalone callback rules, resource-free compilation,
52
+ owner retention across blocked load/save and default replacement, and rejection
53
+ on a stopped owner. Ruby AST and Ruby/RBS graph checks reject C02-to-Engine or
54
+ C02-to-binding dependencies while preserving lower-layer restrictions.
55
+
56
+ The targeted C02 execution connection boundary is addressed. This is not proof
57
+ that every logical Contract is complete or that the whole source graph is
58
+ acyclic. F01 durable Workflow children still need an explicit specification for
59
+ identity, reservation, completion persistence and recovery; application actions
60
+ may still launch ordinary asynchronous work. Broader Recovery ownership review
61
+ also remains. No durable child protocol or persistence schema is added here.
@@ -0,0 +1,72 @@
1
+ # r8 unit 14: assign existing recovery rules to their owners
2
+
3
+ The former private `Phronomy::Recovery` combined Agent operation subjects and
4
+ factual resolutions with general persistence evidence comparison. Sharing a
5
+ file or using the word recovery does not make these one Contract.
6
+
7
+ | Responsibility | Owner after this change |
8
+ | --- | --- |
9
+ | LLM/Tool subject identity, resolution material, resumability classification | C04 Agent, private `Agent::RecoveryRules` |
10
+ | Revision/snapshot evidence comparison and normalization | C07 Persistence, private `Persistence::SnapshotComparison` |
11
+ | Selection of Workflow evidence and interpretation of pre/post/conflict | C02 Workflow, existing WorkflowRunner |
12
+ | Agent restoration, resolution save/readback and continuation | C04 Agent, existing RecoveryCoordinator |
13
+ | Parent/child coordination and durable reconciliation | C01 MultiAgent, unchanged |
14
+
15
+ There is no independent Recovery Contract. C14 remains retired; C17 is
16
+ OutputParser. M50/G34 are retired in the current source architecture without
17
+ reusing their identifiers. Historical phase configurations retain their history.
18
+
19
+ ## Behavioral scope
20
+
21
+ This is a relocation of existing rules and their call sites. No public API,
22
+ persisted schema, outcome value, retry, observer, admission or ownership rule is
23
+ added. Error classes/messages and validation ordering are retained. Ordinary
24
+ framework boot still loads the relocated definitions. The former private
25
+ namespace and file are removed, without a compatibility alias. The existing
26
+ public `Phronomy::ExecutionRehydrationRequiredError` moves to `agent/api` while
27
+ retaining its root namespace, superclass and lazy-loading behavior; it remains
28
+ an Agent-domain outcome, also consumed by delegation callers.
29
+
30
+ `Agent::RecoveryRules` describes external operation facts as `succeeded`,
31
+ `failed` or `not_performed`. Its `Classification` describes resumability. The
32
+ existing structural `persistence_operation` subject normalization is retained
33
+ to avoid changing accepted input or errors; it does not provide a new generic
34
+ durable operation identity or a new supported Agent resolution operation.
35
+
36
+ `Persistence::SnapshotComparison` returns `pre_state`, `post_state` or
37
+ `conflict`. It performs no I/O. Workflow supplies authoritative readback and
38
+ intended evidence, handles read errors, and decides completion, known failure
39
+ or recovery-waiting admission retention. In particular:
40
+
41
+ - An absent record with an absent expected pre revision remains pre-state.
42
+ - Without an explicit post revision, a matching normalized snapshot and a
43
+ revision different from the expected pre revision identifies post-state.
44
+ - With an explicit post revision, both revision and snapshot must match.
45
+ - Otherwise a matching pre revision identifies pre-state, even if the snapshot
46
+ differs. The explicit post comparison still precedes this check.
47
+ - Accessors precede symbol keys, which precede string keys. Nested hash keys
48
+ and symbol values normalize to strings. Read/accessor errors propagate to
49
+ the owning domain as before.
50
+
51
+ `Persistence::SaveOutcome` is unchanged. It compares domain-supplied before/after
52
+ evidence using its existing equality and reports `committed`, `not_committed`
53
+ or `unknown`. It is not substituted for snapshot comparison: their predicates
54
+ and error handling differ. Agent-specific execution metadata comparisons also
55
+ remain in Agent.
56
+
57
+ ## Verification and limits
58
+
59
+ The relocated specs retain existing cases. Additional regressions fix comparison
60
+ priority, normalization, accessor precedence, error identity, resolution error
61
+ ordering and subject immutability. The same 45 primitive examples pass against
62
+ the unit13 definitions and the relocated definitions. Existing Agent recovery
63
+ and Workflow terminal persistence tests cover their surrounding behavior.
64
+
65
+ AST and combined Ruby/RBS graph gates reject dependencies from other domains on
66
+ Agent recovery rules and domain references in generic persistence comparison.
67
+ These checks guard this boundary, not all possible semantic coupling. Root
68
+ loader wiring and dynamic injection require separate review and runtime tests.
69
+
70
+ Durable Workflow children (F01) remain deferred feature work, outside this
71
+ responsibility refactor and outside its acceptance criteria. This change does
72
+ not establish global acyclicity or completion of every Contract.
@@ -0,0 +1,65 @@
1
+ # r8 unit15: Generation contract boundaries
2
+
3
+ This responsibility refactor is based on applied unit14, commit
4
+ `97c3d76b35594bb971a60a2932410ddf22e48d3a` (tree
5
+ `c326196212a4ac369294a9ccb936619813e51250`).
6
+
7
+ ## B05: Agent operation connection
8
+
9
+ Generation previously used `send(:__invoke_async_with_event_sink, ...)` to
10
+ select Agent's private per-execution listener. It now constructs each Agent
11
+ once with its public `on_event:` option and calls public `invoke_async`.
12
+
13
+ The private Generation `AgentOperation` owns the connection, not Agent execution:
14
+
15
+ - Each returned TaskResult supplies that call's terminal result or original
16
+ failure. Terminal incarnation notifications are not interpreted a second time.
17
+ - Approval remains a listener notification while the Agent TaskResult is pending.
18
+ Generation retains its existing policy: approval suspension fails the pipeline.
19
+ - Pending submissions retain their Generation listeners in Workflow entry order.
20
+ Agent continues to own admission. A rejected overlapping call cannot replace
21
+ another call's approval listener; a queued call may be admitted after the prior
22
+ result settles. Only the corresponding settled or synchronously failed request
23
+ is removed. Result callbacks are thread-safe and never wait on the EventLoop.
24
+ - Agent instances and their conversations are reused across iterations and
25
+ pipeline invocations. No per-call Agent creation, automatic cancellation,
26
+ retry policy, durable child tracking, or new runtime registry is introduced.
27
+ - The unused private Agent event-sink method is removed. Per-invocation public
28
+ `on_event:` arguments remain unsupported.
29
+
30
+ `AgentResultReceiver` and `PipelineState` retain event interpretation, parsing,
31
+ request correlation, stale-result rejection, review feedback and trust decisions.
32
+ Their rule bodies are unchanged. `WorkflowBuilder` retains state definitions and
33
+ entry order. Its private operation port is not a new public Agent API.
34
+
35
+ The connection relies on existing public Agent guarantees: one admitted
36
+ execution per Agent, ordered incarnation notifications, and TaskResult settlement
37
+ for terminal results. Approval does not settle the TaskResult. Handoff remains
38
+ outside GeneratorVerifier completion semantics, as before.
39
+
40
+ ## B06: Default parser composition
41
+
42
+ `runtime_composition/generation_defaults.rb` selects the existing JsonParser
43
+ through a private one-time factory binding. Generation lazily creates and reuses
44
+ one default parser per pipeline only when default parsing is needed. Boot creates
45
+ no parser, Agent, Persistence or Runtime for this binding.
46
+
47
+ Generation owns `default_parse_draft` and `default_parse_review`, including the
48
+ existing ParseError fallback payloads. Existing custom parser callables take
49
+ precedence. No application configuration changes are required. OutputParser's
50
+ contract and its concrete implementations are unchanged.
51
+
52
+ ## Scope and verification
53
+
54
+ AST regression gates reject concrete parser selection and the removed private
55
+ Agent invocation in Generation. Public-only Agent doubles cover inline completion,
56
+ busy failure, queued admission, stale terminal notifications, timeout, cancellation
57
+ and approval while pending. Real Agent integration covers approval in both phases
58
+ and retained conversations. Domain event-rule tests use the private Generation
59
+ operation port; they no longer pretend a private Agent method is the public API.
60
+
61
+ Public signatures, result shape, stored schemas, generation/review decisions,
62
+ parser fallback values and default iteration limits are preserved. The internal
63
+ result-observation plumbing changes; this is not merely a physical file move.
64
+ F01 durable Workflow children remain deferred feature work. This checkpoint does
65
+ not certify all framework dependencies or all concrete Engine responsibilities.
@@ -0,0 +1,54 @@
1
+ # r8 unit16: Explicit cancellation subscription ownership
2
+
3
+ This responsibility refactor is based on applied unit15, commit
4
+ `9aebef9217383cebb7fa3ec8b2d17b5763cd3c5e` (tree
5
+ `fcc1bd3bc72ed611a7d4e9090dcf2391b6bc7471`). It addresses B07 only.
6
+
7
+ ## C13 owns registration lifetime
8
+
9
+ `Concurrency::ResultSubscriptions#explicit_cancellation` registers the existing
10
+ CancellationToken notification and owns its disposal through `close`. This is
11
+ an internal Execution operation, reusing the existing subscription collection;
12
+ it is not a new public registry or a new Tool implementation.
13
+
14
+ The existing `cancellation` operation delegates its registration bookkeeping to
15
+ this method and retains its additional `cancelled?` check. Its `Subscriptions`
16
+ subclass retains deadline scheduling. An explicit registration alone neither
17
+ checks an elapsed deadline nor schedules a timer.
18
+
19
+ CancellationToken still owns callback storage, delivery, exception isolation,
20
+ and private removal. `on_cancel` still returns the token. Public signatures,
21
+ exception types, and the callback behavior are unchanged. In particular, closing
22
+ a registration does not retract a callback already taken by concurrent `cancel!`.
23
+
24
+ ## Consumers retain their execution decisions
25
+
26
+ - C01 TeamCoordinator registers its existing cancellation callback through C13
27
+ and closes the collection in the existing `ensure` block. Team still owns the
28
+ durable cancel request, child cancellation, and terminal outcome interpretation.
29
+ - I09 OffloadPool registers its existing operation cancellation callback through
30
+ the same operation. It still owns queue/worker admission, logical settlement,
31
+ deadline promotion, abandonment, and physical completion. Timer registrations
32
+ are closed before cancellation registrations, preserving cleanup order.
33
+ - C06 Tool already passes its token to the standard offloaded submitter. Its
34
+ operation dispatch and cooperative/custom-async paths are unchanged. No
35
+ Tool-specific subscription or symmetric copy of Team logic is introduced.
36
+
37
+ An already-cancelled token may deliver during registration and close the
38
+ subscription collection before registration returns. The existing collection's
39
+ `add` behavior disposes such a late-added registration immediately. The same
40
+ mechanism covers a concurrent `close` during registration.
41
+
42
+ ## Verification and remaining scope
43
+
44
+ Behavioral checks cover explicit cancellation, expired deadlines without explicit
45
+ cancellation, inline and concurrent close, delivery already in flight, callback
46
+ failure isolation, and Team/worker cleanup after success and failure. Existing
47
+ OffloadPool timeout, cancellation, and physical-completion tests remain applicable.
48
+ The AST gate rejects private token-removal calls outside Execution, including
49
+ literal reflective calls in Engine and domain code.
50
+
51
+ B08 configuration access and F01 durable Workflow children are not implemented
52
+ here. Public API/RBS, storage schemas, default configuration, and domain rules
53
+ are retained. This change does not certify all Contract boundaries or eliminate
54
+ the aggregate implementation graph's cycles.