Class: PromptObjects::Execution::Context
- Inherits:
-
Object
- Object
- PromptObjects::Execution::Context
- Defined in:
- lib/prompt_objects/execution/context.rb
Overview
Immutable identity and dependencies passed to one run or tool call.
Instance Attribute Summary collapse
-
#bus ⇒ Object
readonly
Returns the value of attribute bus.
-
#caller_po ⇒ Object
readonly
Returns the value of attribute caller_po.
-
#calling_po ⇒ Object
readonly
Returns the value of attribute calling_po.
-
#cancellation_token ⇒ Object
readonly
Returns the value of attribute cancellation_token.
-
#current_capability ⇒ Object
readonly
Returns the value of attribute current_capability.
-
#deadline ⇒ Object
readonly
Returns the value of attribute deadline.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#event_publisher ⇒ Object
readonly
Returns the value of attribute event_publisher.
-
#human_queue ⇒ Object
readonly
Returns the value of attribute human_queue.
-
#resource_lock_manager ⇒ Object
readonly
Returns the value of attribute resource_lock_manager.
-
#run_id ⇒ Object
readonly
Returns the value of attribute run_id.
-
#source_name ⇒ Object
readonly
Returns the value of attribute source_name.
-
#source_type ⇒ Object
readonly
Returns the value of attribute source_type.
-
#span_id ⇒ Object
readonly
Returns the value of attribute span_id.
-
#target_po ⇒ Object
readonly
Returns the value of attribute target_po.
-
#thread_id ⇒ Object
readonly
Returns the value of attribute thread_id.
-
#trace_id ⇒ Object
readonly
Returns the value of attribute trace_id.
-
#tui_mode ⇒ Object
readonly
Returns the value of attribute tui_mode.
-
#workspace_session_id ⇒ Object
readonly
Returns the value of attribute workspace_session_id.
Instance Method Summary collapse
- #check_cancelled! ⇒ Object
- #env_data_scope ⇒ Object
- #for_child_run(run_id:, thread_id:, target_po:, source_name: nil) ⇒ Object
- #for_tool_call(tool_call) ⇒ Object
-
#initialize(env:, workspace_session_id:, thread_id:, run_id:, target_po:, source_type:, source_name: nil, caller_po: nil, current_capability: nil, cancellation_token: CancellationToken.new, trace_id: SecureRandom.uuid, span_id: SecureRandom.uuid, deadline: nil, resource_lock_manager: nil, event_publisher: nil, tui_mode: false) ⇒ Context
constructor
A new instance of Context.
- #log_message(to:, message:) ⇒ Object
- #log_response(from:, message:) ⇒ Object
Constructor Details
#initialize(env:, workspace_session_id:, thread_id:, run_id:, target_po:, source_type:, source_name: nil, caller_po: nil, current_capability: nil, cancellation_token: CancellationToken.new, trace_id: SecureRandom.uuid, span_id: SecureRandom.uuid, deadline: nil, resource_lock_manager: nil, event_publisher: nil, tui_mode: false) ⇒ Context
Returns a new instance of Context.
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/prompt_objects/execution/context.rb', line 43 def initialize(env:, workspace_session_id:, thread_id:, run_id:, target_po:, source_type:, source_name: nil, caller_po: nil, current_capability: nil, cancellation_token: CancellationToken.new, trace_id: SecureRandom.uuid, span_id: SecureRandom.uuid, deadline: nil, resource_lock_manager: nil, event_publisher: nil, tui_mode: false) @env = env @bus = env.bus @human_queue = env.human_queue @workspace_session_id = workspace_session_id @thread_id = thread_id @run_id = run_id @caller_po = caller_po @target_po = target_po @source_type = source_type @source_name = source_name @current_capability = current_capability @calling_po = caller_po @cancellation_token = cancellation_token @trace_id = trace_id @span_id = span_id @deadline = deadline @resource_lock_manager = resource_lock_manager @event_publisher = event_publisher @tui_mode = tui_mode freeze end |
Instance Attribute Details
#bus ⇒ Object (readonly)
Returns the value of attribute bus.
37 38 39 |
# File 'lib/prompt_objects/execution/context.rb', line 37 def bus @bus end |
#caller_po ⇒ Object (readonly)
Returns the value of attribute caller_po.
37 38 39 |
# File 'lib/prompt_objects/execution/context.rb', line 37 def caller_po @caller_po end |
#calling_po ⇒ Object (readonly)
Returns the value of attribute calling_po.
37 38 39 |
# File 'lib/prompt_objects/execution/context.rb', line 37 def calling_po @calling_po end |
#cancellation_token ⇒ Object (readonly)
Returns the value of attribute cancellation_token.
37 38 39 |
# File 'lib/prompt_objects/execution/context.rb', line 37 def cancellation_token @cancellation_token end |
#current_capability ⇒ Object (readonly)
Returns the value of attribute current_capability.
37 38 39 |
# File 'lib/prompt_objects/execution/context.rb', line 37 def current_capability @current_capability end |
#deadline ⇒ Object (readonly)
Returns the value of attribute deadline.
37 38 39 |
# File 'lib/prompt_objects/execution/context.rb', line 37 def deadline @deadline end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
37 38 39 |
# File 'lib/prompt_objects/execution/context.rb', line 37 def env @env end |
#event_publisher ⇒ Object (readonly)
Returns the value of attribute event_publisher.
37 38 39 |
# File 'lib/prompt_objects/execution/context.rb', line 37 def event_publisher @event_publisher end |
#human_queue ⇒ Object (readonly)
Returns the value of attribute human_queue.
37 38 39 |
# File 'lib/prompt_objects/execution/context.rb', line 37 def human_queue @human_queue end |
#resource_lock_manager ⇒ Object (readonly)
Returns the value of attribute resource_lock_manager.
37 38 39 |
# File 'lib/prompt_objects/execution/context.rb', line 37 def resource_lock_manager @resource_lock_manager end |
#run_id ⇒ Object (readonly)
Returns the value of attribute run_id.
37 38 39 |
# File 'lib/prompt_objects/execution/context.rb', line 37 def run_id @run_id end |
#source_name ⇒ Object (readonly)
Returns the value of attribute source_name.
37 38 39 |
# File 'lib/prompt_objects/execution/context.rb', line 37 def source_name @source_name end |
#source_type ⇒ Object (readonly)
Returns the value of attribute source_type.
37 38 39 |
# File 'lib/prompt_objects/execution/context.rb', line 37 def source_type @source_type end |
#span_id ⇒ Object (readonly)
Returns the value of attribute span_id.
37 38 39 |
# File 'lib/prompt_objects/execution/context.rb', line 37 def span_id @span_id end |
#target_po ⇒ Object (readonly)
Returns the value of attribute target_po.
37 38 39 |
# File 'lib/prompt_objects/execution/context.rb', line 37 def target_po @target_po end |
#thread_id ⇒ Object (readonly)
Returns the value of attribute thread_id.
37 38 39 |
# File 'lib/prompt_objects/execution/context.rb', line 37 def thread_id @thread_id end |
#trace_id ⇒ Object (readonly)
Returns the value of attribute trace_id.
37 38 39 |
# File 'lib/prompt_objects/execution/context.rb', line 37 def trace_id @trace_id end |
#tui_mode ⇒ Object (readonly)
Returns the value of attribute tui_mode.
37 38 39 |
# File 'lib/prompt_objects/execution/context.rb', line 37 def tui_mode @tui_mode end |
#workspace_session_id ⇒ Object (readonly)
Returns the value of attribute workspace_session_id.
37 38 39 |
# File 'lib/prompt_objects/execution/context.rb', line 37 def workspace_session_id @workspace_session_id end |
Instance Method Details
#check_cancelled! ⇒ Object
98 99 100 101 102 103 |
# File 'lib/prompt_objects/execution/context.rb', line 98 def check_cancelled! cancellation_token.check! return true unless deadline && Time.now >= deadline raise CancelledError, "deadline exceeded" end |
#env_data_scope ⇒ Object
94 95 96 |
# File 'lib/prompt_objects/execution/context.rb', line 94 def env_data_scope workspace_session_id end |
#for_child_run(run_id:, thread_id:, target_po:, source_name: nil) ⇒ Object
80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/prompt_objects/execution/context.rb', line 80 def for_child_run(run_id:, thread_id:, target_po:, source_name: nil) self.class.new( **shared_attributes, run_id: run_id, thread_id: thread_id, target_po: target_po, caller_po: self.target_po, source_type: "delegation", source_name: source_name || self.target_po, current_capability: nil, span_id: SecureRandom.uuid ) end |
#for_tool_call(tool_call) ⇒ Object
71 72 73 74 75 76 77 78 |
# File 'lib/prompt_objects/execution/context.rb', line 71 def for_tool_call(tool_call) self.class.new( **shared_attributes, caller_po: target_po, current_capability: tool_call.name, span_id: SecureRandom.uuid ) end |
#log_message(to:, message:) ⇒ Object
105 106 107 |
# File 'lib/prompt_objects/execution/context.rb', line 105 def (to:, message:) bus.publish(from: current_capability || source_name || source_type, to: to, message: ) end |
#log_response(from:, message:) ⇒ Object
109 110 111 |
# File 'lib/prompt_objects/execution/context.rb', line 109 def log_response(from:, message:) bus.publish(from: from, to: current_capability || target_po, message: ) end |