phronomy 0.37.0 → 0.38.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +87 -0
- data/README.md +24 -2
- data/SECURITY.md +1 -1
- data/docs/architecture/agent-approval-recovery.md +320 -0
- data/docs/architecture/agent-child-approval-recovery.md +387 -0
- data/docs/architecture/agent-child-execution-recovery.md +425 -0
- data/docs/architecture/agent-dispatch-recovery.md +308 -0
- data/docs/architecture/agent-terminal-persistence-evidence.md +360 -0
- data/docs/architecture/agent-terminal-recovery.md +298 -0
- data/docs/architecture/agent-terminal-submission-recovery.md +275 -0
- data/docs/architecture/agent-tool-child-lifetime.md +29 -0
- data/docs/architecture/agent-transition-ownership.md +24 -0
- data/docs/architecture/backend-groups.md +6 -0
- data/docs/architecture/detached-outcome-proof-projection.md +576 -0
- data/docs/architecture/execution-abstraction-review.md +5 -0
- data/docs/architecture/handoff-dispatch-recovery.md +205 -0
- data/docs/architecture/handoff-initial-terminal-application.md +321 -0
- data/docs/architecture/initial-preparation-recovery.md +308 -0
- data/docs/architecture/multi-agent-handoff.md +17 -0
- data/docs/architecture/native-outcome-preparation.md +715 -0
- data/docs/architecture/native-parent-dispatch-recovery.md +460 -0
- data/docs/architecture/native-parent-outcome-recovery.md +644 -0
- data/docs/architecture/parent-child-terminal-acknowledgement.md +297 -0
- data/docs/architecture/r8-unit12.md +6 -3
- data/docs/architecture/r8-unit4.md +11 -2
- data/docs/architecture/recovery-physical-attempt.md +88 -0
- data/docs/architecture/recovery-submission-custody.md +247 -0
- data/docs/architecture/retained-attempts.md +229 -0
- data/docs/architecture/retained-outcome-materialization.md +636 -0
- data/docs/architecture/retained-outcome-publication.md +506 -0
- data/docs/architecture/storage-execution-boundaries.md +1 -1
- data/docs/architecture/structured-output-and-scope.md +15 -0
- data/docs/architecture/synchronous-participant-application.md +397 -0
- data/docs/architecture/synchronous-participant-contract.md +195 -0
- data/docs/architecture/team-admission-rejection.md +91 -0
- data/docs/architecture/team-cancellation-delivery.md +245 -0
- data/docs/architecture/team-child-retirement.md +104 -0
- data/docs/architecture/tracing.md +26 -0
- data/docs/architecture/workflow-terminal-ownership-design.md +25 -9
- data/docs/architecture/workflow-terminal-reconciliation.md +221 -0
- data/docs/architecture.md +16 -9
- data/docs/decisions/025-process-local-agent-ownership-and-runtime-admission.md +8 -0
- data/docs/features.md +3 -3
- data/docs/mcp-client.md +138 -5
- data/docs/migrations/orchestrator-subagent-dispatch.md +89 -0
- data/docs/migrations/vector-async-clients.md +18 -3
- data/docs/persistence-backends.md +30 -4
- data/docs/runtime-and-concurrency.md +235 -11
- data/lib/phronomy/agent/admission.rb +37 -17
- data/lib/phronomy/agent/api/agent.rb +25 -0
- data/lib/phronomy/agent/approval_recovery.rb +30 -0
- data/lib/phronomy/agent/approval_recovery_api.rb +61 -0
- data/lib/phronomy/agent/approval_recovery_error.rb +39 -0
- data/lib/phronomy/agent/approval_recovery_result.rb +94 -0
- data/lib/phronomy/agent/async_event_api.rb +22 -5
- data/lib/phronomy/agent/base.rb +76 -48
- data/lib/phronomy/agent/context_preparation.rb +10 -8
- data/lib/phronomy/agent/dispatch_recovery.rb +29 -0
- data/lib/phronomy/agent/dispatch_recovery_api.rb +84 -0
- data/lib/phronomy/agent/dispatch_recovery_error.rb +36 -0
- data/lib/phronomy/agent/dispatch_recovery_result.rb +93 -0
- data/lib/phronomy/agent/execution/agent_invocation.rb +11 -3
- data/lib/phronomy/agent/execution/approval_continuation_plan.rb +131 -0
- data/lib/phronomy/agent/execution/approval_parent_evidence.rb +116 -0
- data/lib/phronomy/agent/execution/approval_persistence_evidence.rb +111 -0
- data/lib/phronomy/agent/execution/approval_recovery_operation.rb +496 -0
- data/lib/phronomy/agent/execution/approval_resume_commit.rb +174 -10
- data/lib/phronomy/agent/execution/dispatch_continuation_delivery.rb +96 -0
- data/lib/phronomy/agent/execution/dispatch_persistence_evidence.rb +147 -0
- data/lib/phronomy/agent/execution/dispatch_preparation.rb +63 -7
- data/lib/phronomy/agent/execution/dispatch_recovery_operation.rb +495 -0
- data/lib/phronomy/agent/execution/execution_coordinator.rb +724 -158
- data/lib/phronomy/agent/execution/execution_outcome_committer.rb +312 -39
- data/lib/phronomy/agent/execution/execution_registry.rb +508 -13
- data/lib/phronomy/agent/execution/initial_persistence_evidence.rb +269 -0
- data/lib/phronomy/agent/execution/initial_preparation.rb +132 -40
- data/lib/phronomy/agent/execution/initial_preparation_recovery_operation.rb +513 -0
- data/lib/phronomy/agent/execution/invocation_transitions.rb +3 -0
- data/lib/phronomy/agent/execution/outcome_planning.rb +108 -0
- data/lib/phronomy/agent/execution/outcome_preparation.rb +81 -0
- data/lib/phronomy/agent/execution/outcome_recovery_operation.rb +609 -0
- data/lib/phronomy/agent/execution/outcome_text_projection.rb +73 -0
- data/lib/phronomy/agent/execution/outcome_write_plan.rb +48 -0
- data/lib/phronomy/agent/execution/runtime_record_encoder.rb +7 -4
- data/lib/phronomy/agent/execution/terminal_persistence_evidence.rb +280 -0
- data/lib/phronomy/agent/execution/terminal_recovery_operation.rb +38 -0
- data/lib/phronomy/agent/execution_change.rb +138 -26
- data/lib/phronomy/agent/execution_environment.rb +29 -0
- data/lib/phronomy/agent/execution_rejected_error.rb +34 -0
- data/lib/phronomy/agent/initial_preparation_recovery.rb +32 -0
- data/lib/phronomy/agent/initial_preparation_recovery_api.rb +85 -0
- data/lib/phronomy/agent/initial_preparation_recovery_error.rb +41 -0
- data/lib/phronomy/agent/initial_preparation_recovery_result.rb +115 -0
- data/lib/phronomy/agent/lifecycle/hosted_approval_context.rb +86 -0
- data/lib/phronomy/agent/lifecycle/hosted_invocation.rb +42 -10
- data/lib/phronomy/agent/lifecycle/identity_write.rb +101 -0
- data/lib/phronomy/agent/lifecycle/lifetime_api.rb +28 -0
- data/lib/phronomy/agent/lifecycle/ownership_registry.rb +136 -70
- data/lib/phronomy/agent/lifecycle/scope.rb +3 -3
- data/lib/phronomy/agent/outcome_recovery.rb +47 -0
- data/lib/phronomy/agent/outcome_recovery_api.rb +114 -0
- data/lib/phronomy/agent/outcome_recovery_error.rb +36 -0
- data/lib/phronomy/agent/outcome_recovery_result.rb +92 -0
- data/lib/phronomy/agent/output_contract.rb +16 -6
- data/lib/phronomy/agent/persistence/identity_receipt_repository.rb +61 -0
- data/lib/phronomy/agent/persistence/records.rb +2 -0
- data/lib/phronomy/agent/persistence/storage_schema.rb +2 -0
- data/lib/phronomy/agent/recovery/invocation_restorer.rb +8 -5
- data/lib/phronomy/agent/recovery/recovery_coordinator/continuation.rb +6 -4
- data/lib/phronomy/agent/recovery/recovery_coordinator/installation.rb +21 -43
- data/lib/phronomy/agent/recovery/recovery_coordinator.rb +19 -6
- data/lib/phronomy/agent/runtime_binding/engine_environment.rb +12 -0
- data/lib/phronomy/agent/state_writer.rb +4 -3
- data/lib/phronomy/agent/store.rb +7 -1
- data/lib/phronomy/agent/terminal_recovery.rb +41 -0
- data/lib/phronomy/agent/terminal_recovery_api.rb +101 -0
- data/lib/phronomy/agent/terminal_recovery_error.rb +36 -0
- data/lib/phronomy/agent/terminal_recovery_result.rb +67 -0
- data/lib/phronomy/agent/tool_execution/tool_approval_request.rb +25 -1
- data/lib/phronomy/common/values/serializable.rb +37 -4
- data/lib/phronomy/engine/concurrency/offload_pool.rb +32 -4
- data/lib/phronomy/engine/concurrency/pool_registry.rb +6 -0
- data/lib/phronomy/engine/event_loop.rb +161 -11
- data/lib/phronomy/engine/execution_binding.rb +4 -2
- data/lib/phronomy/engine/execution_receiver_binding.rb +5 -0
- data/lib/phronomy/engine/runtime/shutdown_result.rb +21 -0
- data/lib/phronomy/engine/runtime/timer_queue.rb +7 -2
- data/lib/phronomy/engine/runtime.rb +119 -15
- data/lib/phronomy/execution/attempt_completion.rb +91 -0
- data/lib/phronomy/execution/concurrency/cancellation_token.rb +7 -2
- data/lib/phronomy/execution/concurrency/physical_completion_task.rb +7 -2
- data/lib/phronomy/execution/execution.rb +17 -2
- data/lib/phronomy/execution/execution_receiver.rb +27 -0
- data/lib/phronomy/execution/execution_retirement.rb +30 -0
- data/lib/phronomy/execution/invocation_controls.rb +2 -2
- data/lib/phronomy/execution/retained_attempts.rb +179 -0
- data/lib/phronomy/execution/stopped_terminal_custody.rb +99 -0
- data/lib/phronomy/llm_adapter/response.rb +7 -1
- data/lib/phronomy/multi_agent/admission_registry.rb +6 -0
- data/lib/phronomy/multi_agent/durable_subagent_coordinator.rb +175 -39
- data/lib/phronomy/multi_agent/handoff_dispatch_evidence.rb +176 -0
- data/lib/phronomy/multi_agent/handoff_finalization_error.rb +33 -0
- data/lib/phronomy/multi_agent/handoff_history_release.rb +80 -0
- data/lib/phronomy/multi_agent/handoff_participant.rb +31 -6
- data/lib/phronomy/multi_agent/handoff_runner.rb +195 -21
- data/lib/phronomy/multi_agent/handoff_terminal_finalization.rb +176 -0
- data/lib/phronomy/multi_agent/native_approval_evidence.rb +26 -0
- data/lib/phronomy/multi_agent/native_child_authority.rb +135 -0
- data/lib/phronomy/multi_agent/native_dispatch_evidence.rb +43 -0
- data/lib/phronomy/multi_agent/native_outcome_evidence.rb +46 -0
- data/lib/phronomy/multi_agent/native_persistence_plan.rb +93 -0
- data/lib/phronomy/multi_agent/orchestrator.rb +28 -52
- data/lib/phronomy/multi_agent/reserved_child_admission.rb +90 -1
- data/lib/phronomy/multi_agent/store.rb +5 -34
- data/lib/phronomy/multi_agent/subagent_history_release.rb +88 -0
- data/lib/phronomy/multi_agent/team_cancellation_delivery_error.rb +21 -0
- data/lib/phronomy/multi_agent/team_cancellation_request.rb +134 -0
- data/lib/phronomy/multi_agent/team_coordinator.rb +174 -27
- data/lib/phronomy/persistence_composition/stores.rb +10 -3
- data/lib/phronomy/runtime_composition/execution_defaults.rb +18 -0
- data/lib/phronomy/storage/backends/in_memory.rb +3 -1
- data/lib/phronomy/storage/resource.rb +10 -1
- data/lib/phronomy/tools/agent.rb +7 -1
- data/lib/phronomy/tools/mcp.rb +210 -91
- data/lib/phronomy/tools/mcp_http_close_response.rb +23 -0
- data/lib/phronomy/tools/mcp_transport_registry.rb +210 -0
- data/lib/phronomy/tools/vector_search.rb +28 -5
- data/lib/phronomy/tracing/automatic.rb +8 -1
- data/lib/phronomy/version.rb +1 -1
- data/lib/phronomy/workflow/execution/workflow.rb +34 -0
- data/lib/phronomy/workflow/execution/workflow_execution_environment.rb +1 -0
- data/lib/phronomy/workflow/execution/workflow_execution_registry.rb +106 -7
- data/lib/phronomy/workflow/execution/workflow_runner.rb +53 -108
- data/lib/phronomy/workflow/execution/workflow_terminal_operation.rb +489 -0
- data/lib/phronomy/workflow/execution/workflow_terminal_persistence.rb +81 -0
- data/lib/phronomy/workflow/execution/workflow_terminal_recovery.rb +38 -0
- data/lib/phronomy/workflow/execution/workflow_terminal_recovery_error.rb +34 -0
- data/lib/phronomy/workflow/execution/workflow_terminal_recovery_result.rb +56 -0
- data/lib/phronomy/workflow/runtime_binding/workflow_engine_environment.rb +10 -1
- data/lib/phronomy/workflow/runtime_binding/workflow_task_session.rb +3 -1
- data/lib/phronomy/workflow/runtime_binding/workflow_terminal_policy.rb +2 -1
- data/scripts/api_snapshot.rb +46 -1
- data/sig/_private/phronomy/multi_agent/team_cancellation_request.rbs +19 -0
- data/sig/phronomy/agent/approval_recovery.rbs +54 -0
- data/sig/phronomy/agent/dispatch_recovery.rbs +49 -0
- data/sig/phronomy/agent/execution_contract.rbs +4 -1
- data/sig/phronomy/agent/execution_environment.rbs +2 -0
- data/sig/phronomy/agent/initial_preparation_recovery.rbs +48 -0
- data/sig/phronomy/agent/outcome_recovery.rbs +51 -0
- data/sig/phronomy/agent/store.rbs +1 -0
- data/sig/phronomy/agent/terminal_persistence_evidence.rbs +111 -0
- data/sig/phronomy/agent/terminal_recovery.rbs +46 -0
- data/sig/phronomy/agent.rbs +36 -0
- data/sig/phronomy/engine/concurrency/timer_bindings.rbs +2 -0
- data/sig/phronomy/engine/execution_binding.rbs +2 -1
- data/sig/phronomy/engine/execution_receiver.rbs +4 -0
- data/sig/phronomy/engine/observability.rbs +22 -1
- data/sig/phronomy/execution/execution.rbs +16 -1
- data/sig/phronomy/execution/execution_receiver.rbs +12 -0
- data/sig/phronomy/execution/execution_retirement.rbs +18 -0
- data/sig/phronomy/execution/stopped_terminal_custody.rbs +19 -0
- data/sig/phronomy/handoff.rbs +1 -0
- data/sig/phronomy/multi_agent/handoff_finalization_error.rbs +18 -0
- data/sig/phronomy/multi_agent/store.rbs +1 -1
- data/sig/phronomy/multi_agent/team_cancellation_delivery_error.rbs +9 -0
- data/sig/phronomy/persistence_composition.rbs +2 -1
- data/sig/phronomy/storage/contracts.rbs +2 -1
- data/sig/phronomy/tools/mcp.rbs +27 -0
- data/sig/phronomy/workflow.rbs +42 -0
- metadata +104 -2
|
@@ -36,6 +36,11 @@ module Phronomy
|
|
|
36
36
|
# Starts or observes the reserved execution and returns its committed result.
|
|
37
37
|
# Failed executions, including OutputError, fulfill the Task with status
|
|
38
38
|
# and error details. Admission, recovery and observation errors reject it.
|
|
39
|
+
# ExecutionRejectedError identifies durable-context, input-extraction or
|
|
40
|
+
# preparation-metadata validation rejected before durable admission.
|
|
41
|
+
# It identifies this start request, not global absence; coordinating owners
|
|
42
|
+
# must observe the reservation under their guard before ending their run.
|
|
43
|
+
# @see file:docs/architecture/team-admission-rejection.md
|
|
39
44
|
# @return [Phronomy::TaskResult] the exact execution result
|
|
40
45
|
# @api public
|
|
41
46
|
def start_reserved_async(reservation:, input:, config: {}, output_schema: nil, schema_delivery: nil)
|
|
@@ -275,11 +280,18 @@ module Phronomy
|
|
|
275
280
|
reader.call(agent_id, parent_execution_id, child_execution_id, approval_id,
|
|
276
281
|
parent_revision: parent_wait.revision, live_child: owner.agent)
|
|
277
282
|
end
|
|
278
|
-
|
|
279
|
-
|
|
283
|
+
parent_evidence = ApprovalParentEvidence.capture(persistence: owner.agent.persistence,
|
|
284
|
+
parent_agent_id: agent_id, parent_execution_id: parent_execution_id,
|
|
285
|
+
parent_revision: parent_wait.revision, child_agent_id: owner.agent.agent_id) do
|
|
286
|
+
lookup.call(execution_id, approval_request_id)
|
|
287
|
+
end
|
|
288
|
+
wait = parent_evidence.wait
|
|
289
|
+
context = HostedApprovalContext.new(parent: self, child: owner.agent,
|
|
290
|
+
parent_wait: parent_wait, parent_evidence: parent_evidence, reader: reader)
|
|
280
291
|
task = owner.coordinator.resume(wait.execution_id, approval_request_id: wait.approval_request_id, approved: approved,
|
|
281
|
-
config: owner.agent._prepare_invocation_config(config, nil), parent_wait: parent_wait)
|
|
282
|
-
|
|
292
|
+
config: owner.agent._prepare_invocation_config(config, nil), parent_wait: parent_wait, hosted_context: context)
|
|
293
|
+
context.build_invocation(observation: task, detach_task: task) ||
|
|
294
|
+
HostedInvocation.new(self, parent_execution_id, task, resumed_from: wait)
|
|
283
295
|
end
|
|
284
296
|
end
|
|
285
297
|
|
|
@@ -294,7 +306,12 @@ module Phronomy
|
|
|
294
306
|
end
|
|
295
307
|
|
|
296
308
|
def _start_agent_operation(input, config:, mode:, listener:)
|
|
297
|
-
|
|
309
|
+
begin
|
|
310
|
+
config = __invocation_config(_snapshot_durable_context(config))
|
|
311
|
+
rescue => error
|
|
312
|
+
raise ExecutionRejectedError.from_error(error, agent_id: agent_id,
|
|
313
|
+
execution_id: config[:phronomy_exact_observers] && config[:phronomy_reserved_execution_id])
|
|
314
|
+
end
|
|
298
315
|
@_phronomy_execution_wiring = config.dup.freeze
|
|
299
316
|
approval = _approval_configuration_snapshot(nil)
|
|
300
317
|
execution_coordinator_for(config).start(
|
data/lib/phronomy/agent/base.rb
CHANGED
|
@@ -229,7 +229,7 @@ module Phronomy
|
|
|
229
229
|
listener_supplied = !on_event.nil? || !event_block.nil?
|
|
230
230
|
materialized = false
|
|
231
231
|
|
|
232
|
-
agent = OwnershipRegistry.current.load(key, expected_class: self) do |owner_runtime|
|
|
232
|
+
agent = OwnershipRegistry.current.load(key, expected_class: self) do |owner_runtime, before_install|
|
|
233
233
|
materialized = true
|
|
234
234
|
instance = __construct_owned_agent(
|
|
235
235
|
owner_runtime,
|
|
@@ -241,7 +241,7 @@ module Phronomy
|
|
|
241
241
|
on_event: on_event,
|
|
242
242
|
&event_block
|
|
243
243
|
)
|
|
244
|
-
Phronomy::Agent::RecoveryCoordinator.new(instance).recover_on_load!
|
|
244
|
+
Phronomy::Agent::RecoveryCoordinator.new(instance).recover_on_load!(&before_install)
|
|
245
245
|
instance
|
|
246
246
|
end
|
|
247
247
|
|
|
@@ -258,6 +258,18 @@ module Phronomy
|
|
|
258
258
|
agent
|
|
259
259
|
end
|
|
260
260
|
|
|
261
|
+
# Observe the original unconfirmed create or purge without replaying it.
|
|
262
|
+
# Requires the same Store and concrete Agent definition in this Runtime.
|
|
263
|
+
# Returns nil when there is no retained identity operation to observe.
|
|
264
|
+
# @return [Symbol, nil] :committed, :not_committed, :superseded, :unknown, or nil
|
|
265
|
+
# @api public
|
|
266
|
+
def reconcile_identity(agent_id, persistence:)
|
|
267
|
+
if Phronomy::WaitPolicy.blocking_forbidden?
|
|
268
|
+
raise Phronomy::EventLoopReentrancyError, "Agent identity reconciliation requires an external thread"
|
|
269
|
+
end
|
|
270
|
+
OwnershipRegistry.existing_current&.reconcile_identity(agent_id, expected_class: self, persistence: persistence)
|
|
271
|
+
end
|
|
272
|
+
|
|
261
273
|
# Returns only the process-local live Agent owner. Does not access
|
|
262
274
|
# Persistence and returns nil when this Runtime has no live owner.
|
|
263
275
|
def get(agent_id)
|
|
@@ -316,9 +328,9 @@ module Phronomy
|
|
|
316
328
|
_class_tool_result_filters.each { |filter| derived.tool_result_filter(filter) }
|
|
317
329
|
end
|
|
318
330
|
|
|
319
|
-
def __construct_owned_agent(owner_runtime, reserved_agent_id, *args, **kwargs, &block)
|
|
331
|
+
def __construct_owned_agent(owner_runtime, reserved_agent_id, *args, identity_write: nil, **kwargs, &block)
|
|
320
332
|
instance = allocate
|
|
321
|
-
instance.send(:__prepare_runtime_owner!, owner_runtime, reserved_agent_id)
|
|
333
|
+
instance.send(:__prepare_runtime_owner!, owner_runtime, reserved_agent_id, identity_write: identity_write)
|
|
322
334
|
instance.send(:initialize, *args, **kwargs, &block)
|
|
323
335
|
instance
|
|
324
336
|
end
|
|
@@ -412,8 +424,8 @@ module Phronomy
|
|
|
412
424
|
end
|
|
413
425
|
|
|
414
426
|
begin
|
|
415
|
-
OwnershipRegistry.current.create(effective_agent_id, expected_class: self.class) do |owner_runtime|
|
|
416
|
-
__prepare_runtime_owner!(owner_runtime, effective_agent_id)
|
|
427
|
+
OwnershipRegistry.current.create(effective_agent_id, expected_class: self.class) do |owner_runtime, write|
|
|
428
|
+
__prepare_runtime_owner!(owner_runtime, effective_agent_id, identity_write: write)
|
|
417
429
|
initialize_owned_state(
|
|
418
430
|
agent_id: effective_agent_id,
|
|
419
431
|
context: context,
|
|
@@ -540,40 +552,36 @@ module Phronomy
|
|
|
540
552
|
__assert_live_agent!
|
|
541
553
|
runtime = @_phronomy_runtime_owner
|
|
542
554
|
registry = OwnershipRegistry.for(runtime)
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
tx.executions.assert_idle!(agent_id)
|
|
553
|
-
tx.guard_agent!(agent_id)
|
|
554
|
-
unless tx.retentions.list(agent_id).empty?
|
|
555
|
-
raise Phronomy::AgentBusyError, "Agent #{agent_id} is retained by durable coordination history"
|
|
555
|
+
write = IdentityWrite.new(agent_id: agent_id, kind: :purge, agent_class: self.class,
|
|
556
|
+
generation: @_phronomy_identity_generation)
|
|
557
|
+
Thread.handle_interrupt(Object => :never) do
|
|
558
|
+
token = registry.begin_purge(self)
|
|
559
|
+
disposition = :abort_purge
|
|
560
|
+
begin
|
|
561
|
+
if runtime.existing_registry&.agent_execution_admitted?(agent_id)
|
|
562
|
+
raise Phronomy::AgentBusyError,
|
|
563
|
+
"Agent #{agent_id.inspect} has a nonterminal top-level execution"
|
|
556
564
|
end
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
565
|
+
disposition = :leave_purge_uncertain
|
|
566
|
+
Thread.handle_interrupt(Object => :immediate) { purge_durable_records!(write) }
|
|
567
|
+
disposition = :complete_purge
|
|
568
|
+
rescue Phronomy::AgentBusyError,
|
|
569
|
+
Phronomy::Persistence::ConflictError,
|
|
570
|
+
Phronomy::Persistence::NotFoundError,
|
|
571
|
+
Phronomy::Persistence::SerializationError,
|
|
572
|
+
ArgumentError
|
|
573
|
+
disposition = :abort_purge unless write.prepared?
|
|
574
|
+
raise
|
|
575
|
+
ensure
|
|
576
|
+
if disposition == :complete_purge || write.committed?
|
|
577
|
+
registry.complete_purge(self, token)
|
|
578
|
+
elsif write.rolled_back? || disposition == :abort_purge
|
|
579
|
+
registry.abort_purge(self, token)
|
|
580
|
+
else
|
|
581
|
+
registry.leave_purge_uncertain(self, token, write: write)
|
|
582
|
+
end
|
|
583
|
+
end
|
|
584
|
+
end
|
|
577
585
|
true
|
|
578
586
|
end
|
|
579
587
|
|
|
@@ -581,11 +589,26 @@ module Phronomy
|
|
|
581
589
|
# methods; application code must use new/create/load/get/purge!.
|
|
582
590
|
private
|
|
583
591
|
|
|
592
|
+
def purge_durable_records!(write)
|
|
593
|
+
write.perform(persistence) do |tx|
|
|
594
|
+
tx.executions.assert_idle!(agent_id)
|
|
595
|
+
tx.guard_agent!(agent_id)
|
|
596
|
+
unless tx.retentions.list(agent_id).empty?
|
|
597
|
+
raise Phronomy::AgentBusyError, "Agent #{agent_id} is retained by durable coordination history"
|
|
598
|
+
end
|
|
599
|
+
tx.cancellations.delete_for_agent(agent_id)
|
|
600
|
+
tx.journals.delete(agent_id)
|
|
601
|
+
tx.executions.delete_for_agent(agent_id)
|
|
602
|
+
tx.agents.delete(agent_id)
|
|
603
|
+
end
|
|
604
|
+
end
|
|
605
|
+
|
|
584
606
|
# @api private
|
|
585
|
-
def __prepare_runtime_owner!(runtime, reserved_agent_id)
|
|
607
|
+
def __prepare_runtime_owner!(runtime, reserved_agent_id, identity_write: nil)
|
|
586
608
|
@_phronomy_runtime_owner = runtime
|
|
587
609
|
@_phronomy_runtime_owner_state = :constructing
|
|
588
610
|
@_phronomy_reserved_agent_id = reserved_agent_id.to_s.freeze
|
|
611
|
+
@_phronomy_identity_write = identity_write
|
|
589
612
|
self
|
|
590
613
|
end
|
|
591
614
|
|
|
@@ -614,7 +637,7 @@ module Phronomy
|
|
|
614
637
|
# @api private
|
|
615
638
|
def __restore_live_after_purge_abort!(runtime)
|
|
616
639
|
unless @_phronomy_runtime_owner.equal?(runtime) &&
|
|
617
|
-
@_phronomy_runtime_owner_state
|
|
640
|
+
%i[purging recovery_required].include?(@_phronomy_runtime_owner_state)
|
|
618
641
|
raise Phronomy::Error, "Agent Runtime ownership purge rollback state is invalid"
|
|
619
642
|
end
|
|
620
643
|
@_phronomy_runtime_owner_state = :live
|
|
@@ -634,7 +657,7 @@ module Phronomy
|
|
|
634
657
|
# @api private
|
|
635
658
|
def __mark_purged!(runtime)
|
|
636
659
|
unless @_phronomy_runtime_owner.equal?(runtime) &&
|
|
637
|
-
@_phronomy_runtime_owner_state
|
|
660
|
+
%i[purging recovery_required].include?(@_phronomy_runtime_owner_state)
|
|
638
661
|
raise Phronomy::Error, "Agent Runtime ownership purge completion state is invalid"
|
|
639
662
|
end
|
|
640
663
|
@root = nil
|
|
@@ -679,7 +702,9 @@ module Phronomy
|
|
|
679
702
|
|
|
680
703
|
if load_existing
|
|
681
704
|
root = records = nil
|
|
705
|
+
receipts = IdentityWrite.supported?(@persistence)
|
|
682
706
|
@persistence.transaction do |tx|
|
|
707
|
+
tx.identity_receipts.guard!(@agent_id) if receipts
|
|
683
708
|
begin
|
|
684
709
|
root = tx.agents.load(@agent_id)
|
|
685
710
|
rescue Phronomy::Persistence::NotFoundError => error
|
|
@@ -690,21 +715,23 @@ module Phronomy
|
|
|
690
715
|
@agent_id,
|
|
691
716
|
limit: root.journal_position
|
|
692
717
|
)
|
|
718
|
+
@_phronomy_identity_generation = tx.identity_receipts.read(@agent_id)&.operation_id if receipts
|
|
693
719
|
end
|
|
694
720
|
validate_loaded_definition!(root)
|
|
695
721
|
@root = root
|
|
696
722
|
@_phronomy_journal_records = Array(records).dup.freeze
|
|
697
723
|
else
|
|
698
|
-
|
|
724
|
+
update = create_agent_root!(
|
|
699
725
|
context: context,
|
|
700
726
|
knowledge: knowledge,
|
|
701
727
|
metadata: metadata
|
|
702
728
|
)
|
|
703
|
-
@
|
|
704
|
-
|
|
705
|
-
|
|
706
|
-
).dup.freeze
|
|
729
|
+
@root = update.root
|
|
730
|
+
@_phronomy_journal_records = update.records
|
|
731
|
+
@_phronomy_identity_generation = @_phronomy_identity_write.generation
|
|
707
732
|
end
|
|
733
|
+
ensure
|
|
734
|
+
@_phronomy_identity_write = nil
|
|
708
735
|
end
|
|
709
736
|
|
|
710
737
|
def validate_loaded_definition!(loaded)
|
|
@@ -725,7 +752,8 @@ module Phronomy
|
|
|
725
752
|
def create_agent_root!(context:, knowledge:, metadata:)
|
|
726
753
|
definition = self.class.agent_definition
|
|
727
754
|
state_writer.create_root(
|
|
728
|
-
definition: definition, context: context, knowledge: knowledge, metadata: metadata,
|
|
755
|
+
definition: definition, context: context, knowledge: knowledge, metadata: metadata,
|
|
756
|
+
retention: @initial_retention, write: @_phronomy_identity_write
|
|
729
757
|
)
|
|
730
758
|
end
|
|
731
759
|
|
|
@@ -13,10 +13,12 @@ module Phronomy
|
|
|
13
13
|
agent:,
|
|
14
14
|
persistence:,
|
|
15
15
|
candidate_resolver: nil,
|
|
16
|
-
journal_records: nil
|
|
16
|
+
journal_records: nil,
|
|
17
|
+
contents: persistence.contents
|
|
17
18
|
)
|
|
18
19
|
@agent = agent
|
|
19
20
|
@persistence = persistence
|
|
21
|
+
@contents = contents
|
|
20
22
|
@policy = agent.class.context_policy
|
|
21
23
|
@journal_records = journal_records
|
|
22
24
|
@candidate_resolver = candidate_resolver || ContextCandidateResolver.new(
|
|
@@ -36,7 +38,7 @@ module Phronomy
|
|
|
36
38
|
system_text = build_system_text(input)
|
|
37
39
|
hook_candidates = normalize_candidates(patch.segment_candidates)
|
|
38
40
|
input_ref = execution.metadata.fetch("current_input_ref")
|
|
39
|
-
current_input_content = @
|
|
41
|
+
current_input_content = @contents.fetch_text(input_ref)
|
|
40
42
|
excluded = [execution.metadata["current_input_record_id"]].compact
|
|
41
43
|
handoff_context = config[:phronomy_transfer_context]
|
|
42
44
|
|
|
@@ -391,9 +393,9 @@ module Phronomy
|
|
|
391
393
|
generated = hooks.each_with_index.map do |hook, index|
|
|
392
394
|
content = hook.fetch(:content)
|
|
393
395
|
content_ref = if content.is_a?(String)
|
|
394
|
-
@
|
|
396
|
+
@contents.put_text(content)
|
|
395
397
|
else
|
|
396
|
-
@
|
|
398
|
+
@contents.put_json(content)
|
|
397
399
|
end
|
|
398
400
|
metadata = hook.fetch(:metadata).merge(
|
|
399
401
|
SEGMENT_ORIGIN_METADATA_KEY => BEFORE_LLM_INPUT_ORIGIN,
|
|
@@ -433,9 +435,9 @@ module Phronomy
|
|
|
433
435
|
next_sequence = Array(candidates).filter_map(&:sequence).max.to_i
|
|
434
436
|
transferred = handoff_context.items.each_with_index.map do |item, index|
|
|
435
437
|
content_ref = if item.content_format == :json
|
|
436
|
-
@
|
|
438
|
+
@contents.put_json(item.content)
|
|
437
439
|
else
|
|
438
|
-
@
|
|
440
|
+
@contents.put_text(item.content.to_s)
|
|
439
441
|
end
|
|
440
442
|
metadata = item.metadata.merge(
|
|
441
443
|
SEGMENT_ORIGIN_METADATA_KEY => HANDOFF_CONTEXT_ORIGIN,
|
|
@@ -483,9 +485,9 @@ module Phronomy
|
|
|
483
485
|
end
|
|
484
486
|
|
|
485
487
|
def fetch_content(ref)
|
|
486
|
-
@
|
|
488
|
+
@contents.fetch_text(ref)
|
|
487
489
|
rescue
|
|
488
|
-
@
|
|
490
|
+
@contents.fetch(ref)
|
|
489
491
|
end
|
|
490
492
|
|
|
491
493
|
def build_system_text(input)
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Phronomy
|
|
4
|
+
module Agent
|
|
5
|
+
# A process-local capability for one retained pre-dispatch save on the exact
|
|
6
|
+
# original Agent incarnation. Its identities describe responsibility; they
|
|
7
|
+
# do not reconstruct authority in another Runtime or process.
|
|
8
|
+
# @api public
|
|
9
|
+
class DispatchRecovery
|
|
10
|
+
# @api public
|
|
11
|
+
attr_reader :agent_id, :execution_id, :recovery_id, :dispatch_kind
|
|
12
|
+
|
|
13
|
+
# @api private
|
|
14
|
+
def initialize(operation)
|
|
15
|
+
@operation = operation
|
|
16
|
+
@agent_id = operation.agent_id.to_s.dup.freeze
|
|
17
|
+
@execution_id = operation.execution_id.to_s.dup.freeze
|
|
18
|
+
@recovery_id = operation.recovery_id.to_s.dup.freeze
|
|
19
|
+
@dispatch_kind = operation.dispatch_kind
|
|
20
|
+
freeze
|
|
21
|
+
end
|
|
22
|
+
private_class_method :new
|
|
23
|
+
|
|
24
|
+
private
|
|
25
|
+
|
|
26
|
+
attr_reader :operation
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Phronomy
|
|
4
|
+
module Agent
|
|
5
|
+
# Recovery observes responsibility already held by this Agent, including
|
|
6
|
+
# during Runtime drain. It does not create a replacement owner or enter
|
|
7
|
+
# ordinary new-execution admission.
|
|
8
|
+
# @api private
|
|
9
|
+
module DispatchRecoveryApi
|
|
10
|
+
# Finds pre-dispatch work retained by this exact Agent incarnation.
|
|
11
|
+
# Lookup performs no persistence I/O and creates no Runtime. Resolved work
|
|
12
|
+
# leaves the index; an already held capability can return its final receipt.
|
|
13
|
+
# @param execution_id [String] nonempty accepted execution identity
|
|
14
|
+
# @return [DispatchRecovery, nil]
|
|
15
|
+
# @api public
|
|
16
|
+
def pending_dispatch_recovery(execution_id:)
|
|
17
|
+
unless execution_id.is_a?(String) && !execution_id.empty?
|
|
18
|
+
raise ArgumentError, "execution_id must be a nonempty String"
|
|
19
|
+
end
|
|
20
|
+
@_phronomy_runtime_owner&.existing_registry&.pending_agent_dispatch_recovery(execution_id, agent: self)
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
# Reads the retained barrier and applies confirmed post-state on its exact
|
|
24
|
+
# owner. A positively established pre-barrier failure instead redelivers
|
|
25
|
+
# only its retained setup-failure notification. Neither path repeats
|
|
26
|
+
# provider/Tool work to infer its outcome or retries barrier writes.
|
|
27
|
+
# Cancelling this observation does not cancel retained work or continuation.
|
|
28
|
+
# @param recovery [DispatchRecovery] reference from this Agent
|
|
29
|
+
# @return [TaskResult<DispatchRecoveryResult>] a fresh observation
|
|
30
|
+
# @api public
|
|
31
|
+
def reconcile_dispatch_async(recovery:)
|
|
32
|
+
_dispatch_recovery_operation(recovery).observe(:reconcile)
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
# Waits for reconciliation on a host thread. The earlier failed execution
|
|
36
|
+
# observation stays closed; a resumed receipt supplies a new observation.
|
|
37
|
+
# @param recovery [DispatchRecovery] reference from this Agent
|
|
38
|
+
# @return [DispatchRecoveryResult]
|
|
39
|
+
# @raise [EventLoopReentrancyError] when called on EventLoop
|
|
40
|
+
# @api public
|
|
41
|
+
def reconcile_dispatch(recovery:)
|
|
42
|
+
_check_event_loop_reentrancy(:reconcile_dispatch, :reconcile_dispatch_async)
|
|
43
|
+
reconcile_dispatch_async(recovery: recovery).wait_result
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Explicitly retries only the captured barrier writes after checking the
|
|
47
|
+
# complete pre-state under the original Store guard and transaction.
|
|
48
|
+
# Hooks, Policy, provider requests and Tool work are never replayed to
|
|
49
|
+
# reconstruct a proposal. A positively established pre-barrier failure can
|
|
50
|
+
# only redeliver its retained notification; other incomplete proposals stay
|
|
51
|
+
# retained and pending.
|
|
52
|
+
# @param recovery [DispatchRecovery] reference from this Agent
|
|
53
|
+
# @return [TaskResult<DispatchRecoveryResult>] a fresh observation
|
|
54
|
+
# @api public
|
|
55
|
+
def retry_dispatch_async(recovery:)
|
|
56
|
+
_dispatch_recovery_operation(recovery).observe(:retry)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Waits for the explicit persistence-only retry on a host thread.
|
|
60
|
+
# @param recovery [DispatchRecovery] reference from this Agent
|
|
61
|
+
# @return [DispatchRecoveryResult]
|
|
62
|
+
# @raise [EventLoopReentrancyError] when called on EventLoop
|
|
63
|
+
# @api public
|
|
64
|
+
def retry_dispatch(recovery:)
|
|
65
|
+
_check_event_loop_reentrancy(:retry_dispatch, :retry_dispatch_async)
|
|
66
|
+
retry_dispatch_async(recovery: recovery).wait_result
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
private
|
|
70
|
+
|
|
71
|
+
def _dispatch_recovery_operation(recovery)
|
|
72
|
+
unless recovery.is_a?(DispatchRecovery)
|
|
73
|
+
raise ArgumentError, "recovery must be an Agent::DispatchRecovery"
|
|
74
|
+
end
|
|
75
|
+
operation = recovery.send(:operation)
|
|
76
|
+
unless operation.is_a?(DispatchRecoveryOperation) &&
|
|
77
|
+
operation.recovery.equal?(recovery) && operation.belongs_to?(self)
|
|
78
|
+
raise ArgumentError, "recovery belongs to another Agent incarnation"
|
|
79
|
+
end
|
|
80
|
+
operation
|
|
81
|
+
end
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
end
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Phronomy
|
|
4
|
+
module Agent
|
|
5
|
+
# The caller's execution observation ended while its original Agent retained
|
|
6
|
+
# pre-dispatch responsibility. This does not classify the job as failed or
|
|
7
|
+
# prove that an external request occurred. Recovery is a new observation.
|
|
8
|
+
# @api public
|
|
9
|
+
class DispatchRecoveryError < Phronomy::Error
|
|
10
|
+
# @api public
|
|
11
|
+
attr_reader :recovery, :agent_id, :execution_id, :recovery_id,
|
|
12
|
+
:dispatch_kind, :original_error
|
|
13
|
+
|
|
14
|
+
# @api private
|
|
15
|
+
def initialize(recovery:, error:, original_error: error)
|
|
16
|
+
@recovery = recovery
|
|
17
|
+
@agent_id = recovery.agent_id.to_s.dup.freeze
|
|
18
|
+
@execution_id = recovery.execution_id.to_s.dup.freeze
|
|
19
|
+
@recovery_id = recovery.recovery_id.to_s.dup.freeze
|
|
20
|
+
@dispatch_kind = recovery.dispatch_kind
|
|
21
|
+
@operation_error = error
|
|
22
|
+
@original_error = original_error
|
|
23
|
+
super("Agent #{@agent_id.inspect} execution #{@execution_id.inspect} " \
|
|
24
|
+
"#{@dispatch_kind} dispatch recovery #{@recovery_id.inspect} requires an explicit " \
|
|
25
|
+
"recovery observation", code: "agent.dispatch_recovery")
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# Preserve the immediate operation error across TaskResult delivery.
|
|
29
|
+
# @return [Exception, nil]
|
|
30
|
+
# @api public
|
|
31
|
+
def cause
|
|
32
|
+
@operation_error || super
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
36
|
+
end
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Phronomy
|
|
4
|
+
module Agent
|
|
5
|
+
# One immutable observation of pre-dispatch persistence and continuation.
|
|
6
|
+
# error describes recovery; execution_task observes the job's actual result.
|
|
7
|
+
# Resolving this obligation neither proves job success nor releases the job.
|
|
8
|
+
# @api public
|
|
9
|
+
class DispatchRecoveryResult
|
|
10
|
+
OUTCOMES = %i[confirmed_pre confirmed_post not_prepared unresolved unavailable].freeze
|
|
11
|
+
APPLICATION_STATES = %i[pending applied].freeze
|
|
12
|
+
CONTINUATION_STATES = %i[pending resumed stopped].freeze
|
|
13
|
+
private_constant :OUTCOMES, :APPLICATION_STATES, :CONTINUATION_STATES
|
|
14
|
+
|
|
15
|
+
# revision describes the captured barrier's confirmed record. An execution
|
|
16
|
+
# observation is fresh for each receipt, never the owner's canonical task.
|
|
17
|
+
# @api public
|
|
18
|
+
attr_reader :recovery, :agent_id, :execution_id, :recovery_id, :dispatch_kind,
|
|
19
|
+
:outcome, :application_state, :continuation_state, :revision, :execution_task, :error
|
|
20
|
+
|
|
21
|
+
# @api private
|
|
22
|
+
def initialize(recovery:, outcome:, application_state:, continuation_state:,
|
|
23
|
+
physical_complete:, revision: nil, execution_task: nil, error: nil)
|
|
24
|
+
unless OUTCOMES.include?(outcome) && APPLICATION_STATES.include?(application_state) &&
|
|
25
|
+
CONTINUATION_STATES.include?(continuation_state)
|
|
26
|
+
raise ArgumentError, "unsupported Agent dispatch recovery state"
|
|
27
|
+
end
|
|
28
|
+
unless physical_complete.equal?(true) || physical_complete.equal?(false)
|
|
29
|
+
raise ArgumentError, "dispatch physical completion must be a boolean"
|
|
30
|
+
end
|
|
31
|
+
if %i[confirmed_pre confirmed_post].include?(outcome)
|
|
32
|
+
unless revision.is_a?(Integer) && revision >= 0
|
|
33
|
+
raise ArgumentError, "confirmed dispatch persistence requires its nonnegative execution revision"
|
|
34
|
+
end
|
|
35
|
+
elsif !revision.nil?
|
|
36
|
+
raise ArgumentError, "unclassified or unprepared dispatch work has no confirmed revision"
|
|
37
|
+
end
|
|
38
|
+
case outcome
|
|
39
|
+
when :confirmed_post
|
|
40
|
+
if continuation_state == :stopped
|
|
41
|
+
raise ArgumentError, "only positively unprepared dispatch work can use stopped continuation"
|
|
42
|
+
end
|
|
43
|
+
when :not_prepared
|
|
44
|
+
if continuation_state == :resumed
|
|
45
|
+
raise ArgumentError, "unprepared dispatch work cannot resume a barrier"
|
|
46
|
+
end
|
|
47
|
+
else
|
|
48
|
+
if application_state != :pending || continuation_state != :pending
|
|
49
|
+
raise ArgumentError, "dispatch work without confirmed post-state must remain pending"
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
if %i[resumed stopped].include?(continuation_state)
|
|
53
|
+
unless application_state == :applied && physical_complete && execution_task.is_a?(Phronomy::TaskResult)
|
|
54
|
+
raise ArgumentError, "dispatch continuation requires application, physical completion and an execution observation"
|
|
55
|
+
end
|
|
56
|
+
elsif !execution_task.nil?
|
|
57
|
+
raise ArgumentError, "only resumed or stopped dispatch work has an execution observation"
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
@recovery = recovery
|
|
61
|
+
@agent_id = recovery.agent_id.to_s.dup.freeze
|
|
62
|
+
@execution_id = recovery.execution_id.to_s.dup.freeze
|
|
63
|
+
@recovery_id = recovery.recovery_id.to_s.dup.freeze
|
|
64
|
+
@dispatch_kind = recovery.dispatch_kind
|
|
65
|
+
@outcome = outcome
|
|
66
|
+
@application_state = application_state
|
|
67
|
+
@continuation_state = continuation_state
|
|
68
|
+
@physical_complete = physical_complete
|
|
69
|
+
@revision = revision
|
|
70
|
+
@execution_task = execution_task
|
|
71
|
+
@error = error
|
|
72
|
+
freeze
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# True only after the original preparation and recovery workers stopped.
|
|
76
|
+
# The continued provider, Tool or overall Agent execution may still run.
|
|
77
|
+
# @return [Boolean]
|
|
78
|
+
# @api public
|
|
79
|
+
def physical_complete?
|
|
80
|
+
@physical_complete
|
|
81
|
+
end
|
|
82
|
+
|
|
83
|
+
# True after the exact owner handed off the confirmed barrier continuation,
|
|
84
|
+
# or its positively established pre-barrier failure notification. Stopped
|
|
85
|
+
# never permits preparation replay; execution_task observes the job result.
|
|
86
|
+
# @return [Boolean]
|
|
87
|
+
# @api public
|
|
88
|
+
def resolved?
|
|
89
|
+
@physical_complete && @application_state == :applied && %i[resumed stopped].include?(@continuation_state)
|
|
90
|
+
end
|
|
91
|
+
end
|
|
92
|
+
end
|
|
93
|
+
end
|
|
@@ -47,6 +47,7 @@ module Phronomy
|
|
|
47
47
|
:error
|
|
48
48
|
|
|
49
49
|
attr_reader :final_response,
|
|
50
|
+
:output_contract,
|
|
50
51
|
:execution_id,
|
|
51
52
|
:agent,
|
|
52
53
|
:config,
|
|
@@ -69,13 +70,15 @@ module Phronomy
|
|
|
69
70
|
approval_listener: nil,
|
|
70
71
|
event_listener: nil,
|
|
71
72
|
mode: nil,
|
|
72
|
-
execution_id: nil
|
|
73
|
+
execution_id: nil,
|
|
74
|
+
output_contract: config[:phronomy_output_contract]
|
|
73
75
|
)
|
|
74
76
|
@agent = agent
|
|
75
77
|
@input = input
|
|
76
78
|
# The caller's Hash must not become a shared mutable Runtime object.
|
|
77
|
-
#
|
|
78
|
-
#
|
|
79
|
+
# Keep the final-output promise on its owner. The Manifest supplies
|
|
80
|
+
# provider schemas, and child Tools receive only the ordinary config.
|
|
81
|
+
@output_contract = output_contract
|
|
79
82
|
@config = config.except(:phronomy_output_contract)
|
|
80
83
|
resolved_execution_id = execution_id || @config[:execution_id]
|
|
81
84
|
@execution_id = resolved_execution_id&.to_s&.freeze
|
|
@@ -168,6 +171,11 @@ module Phronomy
|
|
|
168
171
|
end
|
|
169
172
|
|
|
170
173
|
def handle_fsm_event(event)
|
|
174
|
+
if event.type == :approval_resume_cancelled
|
|
175
|
+
@error ||= event.payload.fetch(:error)
|
|
176
|
+
return true
|
|
177
|
+
end
|
|
178
|
+
|
|
171
179
|
if event.type == :llm_stream_chunk
|
|
172
180
|
payload = event.payload || {}
|
|
173
181
|
return :consume unless current_llm_result_authoritative?(payload[:llm_call_id])
|