Module: Phronomy::Agent::ToolExecutor
- Defined in:
- lib/phronomy/agent/tool_executor.rb
Overview
Routes Tool work according to the Tool execution contract.
Both execution modes return Task; only the execution mechanism differs.
:cooperative Tool calls execute inline and must return quickly. call_async wraps their result in an already-settled Task and never consumes an OffloadPool worker.
:offloaded Tool calls route synchronous work through OffloadPool, whose caller-facing completion handle is also a Task. Phronomy does not distinguish whether the reason is blocking I/O, CPU-bound work, or another long synchronous operation.
Class Method Summary collapse
Class Method Details
.call_async(tool:, args:, cancellation_token: nil, config: {}, runtime: nil, on_full: :raise) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/phronomy/agent/tool_executor.rb', line 19 def self.call_async( tool:, args:, cancellation_token: nil, config: {}, runtime: nil, on_full: :raise ) mode = tool.class.execution_mode case mode when :cooperative task = Phronomy::Task.deferred(name: "tool-#{tool.name}") begin task.complete( tool.call(args, cancellation_token: cancellation_token) ) rescue => error task.fail(error) end task when :offloaded runtime ||= Phronomy::Runtime.instance runtime.offload.submit( cancellation_token: cancellation_token, on_full: on_full ) do tool.call(args, cancellation_token: cancellation_token) end else raise Phronomy::ConfigurationError, "unknown Tool execution_mode: #{mode.inspect}" end end |