Class: PromptObjects::Execution::Runner
- Inherits:
-
Object
- Object
- PromptObjects::Execution::Runner
- Defined in:
- lib/prompt_objects/execution/runner.rb
Overview
Executes one persisted run to completion without owning scheduler policy. The scheduler may call this concurrently for different leased threads.
Defined Under Namespace
Classes: CapabilityError, PreparedTool
Instance Method Summary collapse
- #execute(run_id, cancellation_token: CancellationToken.new, tui_mode: false) ⇒ Object
-
#initialize(runtime, event_publisher: nil, llm_resolver: nil, provider_permits: nil, tool_permits: nil, cpu_permits: nil, resource_lock_manager: nil) ⇒ Runner
constructor
A new instance of Runner.
Constructor Details
#initialize(runtime, event_publisher: nil, llm_resolver: nil, provider_permits: nil, tool_permits: nil, cpu_permits: nil, resource_lock_manager: nil) ⇒ Runner
Returns a new instance of Runner.
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/prompt_objects/execution/runner.rb', line 11 def initialize(runtime, event_publisher: nil, llm_resolver: nil, provider_permits: nil, tool_permits: nil, cpu_permits: nil, resource_lock_manager: nil) @runtime = runtime @event_publisher = event_publisher @llm_resolver = llm_resolver || ->(_definition) { runtime.llm } @provider_permits = provider_permits @tool_permits = tool_permits @cpu_permits = cpu_permits @resource_lock_manager = resource_lock_manager store = runtime.session_store raise ArgumentError, "run execution requires a session store" unless store @threads = Repositories::ThreadRepository.new(store) @runs = Repositories::RunRepository.new(store) @definitions = Repositories::DefinitionRepository.new(store) @messages = Repositories::MessageRepository.new(store) @events = Repositories::EventRepository.new(store) @tools = Repositories::ToolExecutionRepository.new(store) end |
Instance Method Details
#execute(run_id, cancellation_token: CancellationToken.new, tui_mode: false) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/prompt_objects/execution/runner.rb', line 31 def execute(run_id, cancellation_token: CancellationToken.new, tui_mode: false) run = required_run(run_id) definition = required_definition(run_id) prompt_object = required_prompt_object(run.po_name) context = build_context(run, cancellation_token, tui_mode) start_run(run, context) history = history_for(run) loop do context.check_cancelled! response = call_model(prompt_object, definition, history, run) context.check_cancelled! if response.tool_calls? (run, response) results = execute_tool_batch(run, definition, response.tool_calls, context) persist_tool_results(run, results) history = history_for(run) else return complete_run(run, response) end end rescue CancelledError => e cancel_run(run_id, e.) raise rescue => e fail_run(run_id, e) raise end |