Class: LlmGateway::Agents::Harness
- Defined in:
- lib/llm_gateway/agents/harness.rb
Constant Summary collapse
- COMPACTION_TOKEN_THRESHOLD =
180_000- COMPACTION_IDLE_THRESHOLD_SECONDS =
60 * 60
Instance Attribute Summary collapse
-
#default_queue_mode ⇒ Object
Returns the value of attribute default_queue_mode.
-
#model ⇒ Object
Returns the value of attribute model.
-
#provider ⇒ Object
Returns the value of attribute provider.
-
#queue_drain_mode ⇒ Object
Returns the value of attribute queue_drain_mode.
-
#reasoning ⇒ Object
Returns the value of attribute reasoning.
-
#session_manager ⇒ Object
readonly
Returns the value of attribute session_manager.
Attributes inherited from Prompt
Instance Method Summary collapse
- #compact ⇒ Object
- #continue(&block) ⇒ Object
- #follow_up_message(message, &block) ⇒ Object
-
#initialize(session_manager, provider:, model: nil, reasoning: "high") ⇒ Harness
constructor
A new instance of Harness.
- #prompt_message(message, &block) ⇒ Object
- #run(&block) ⇒ Object
- #steer_message(message, &block) ⇒ Object
- #transcript ⇒ Object (also: #prompt)
Methods inherited from Prompt
after_execute, before_execute, find_tool, #stream, #system_prompt, tools, #tools
Constructor Details
#initialize(session_manager, provider:, model: nil, reasoning: "high") ⇒ Harness
Returns a new instance of Harness.
15 16 17 18 19 20 21 22 |
# File 'lib/llm_gateway/agents/harness.rb', line 15 def initialize(session_manager, provider:, model: nil, reasoning: "high") @provider = provider super(provider: provider, model: model, reasoning: reasoning) @session_manager = session_manager sync_initial_configuration_events self.default_queue_mode = :follow_up self.queue_drain_mode = :all end |
Instance Attribute Details
#default_queue_mode ⇒ Object
Returns the value of attribute default_queue_mode.
12 13 14 |
# File 'lib/llm_gateway/agents/harness.rb', line 12 def default_queue_mode @default_queue_mode end |
#model ⇒ Object
Returns the value of attribute model.
12 13 14 |
# File 'lib/llm_gateway/agents/harness.rb', line 12 def model @model end |
#provider ⇒ Object
Returns the value of attribute provider.
11 12 13 |
# File 'lib/llm_gateway/agents/harness.rb', line 11 def provider @provider end |
#queue_drain_mode ⇒ Object
Returns the value of attribute queue_drain_mode.
12 13 14 |
# File 'lib/llm_gateway/agents/harness.rb', line 12 def queue_drain_mode @queue_drain_mode end |
#reasoning ⇒ Object
Returns the value of attribute reasoning.
12 13 14 |
# File 'lib/llm_gateway/agents/harness.rb', line 12 def reasoning @reasoning end |
#session_manager ⇒ Object (readonly)
Returns the value of attribute session_manager.
12 13 14 |
# File 'lib/llm_gateway/agents/harness.rb', line 12 def session_manager @session_manager end |
Instance Method Details
#compact ⇒ Object
65 66 67 |
# File 'lib/llm_gateway/agents/harness.rb', line 65 def compact session_manager.compaction(provider) end |
#continue(&block) ⇒ Object
110 111 112 113 114 115 116 117 118 119 120 121 |
# File 'lib/llm_gateway/agents/harness.rb', line 110 def continue(&block) raise RuntimeError, "Cannot continue a busy agent" if session_manager.busy? session_manager.busy! begin drain_queue(:steer) drain_queue(:follow_up) run(&block) ensure session_manager.idle! end end |
#follow_up_message(message, &block) ⇒ Object
37 38 39 |
# File 'lib/llm_gateway/agents/harness.rb', line 37 def (, &block) enqueue_and_continue_if_idle(, :follow_up, &block) end |
#prompt_message(message, &block) ⇒ Object
29 30 31 |
# File 'lib/llm_gateway/agents/harness.rb', line 29 def (, &block) enqueue_and_continue_if_idle(, default_queue_mode, &block) end |
#run(&block) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/llm_gateway/agents/harness.rb', line 69 def run(&block) emit(Event::AgentStart.new, &block) drain_queue(:steer) emit(Event::TurnStart.new, &block) emit(Event::MessageStart.new, &block) = stream do |event| emit(Event::MessageUpdate.new(stream_event: event), &block) end = session_manager.(.to_h) emit(Event::MessageEnd.new(message: ), &block) tool_request_blocks = tool_requests() = execute_tool_requests( requests: tool_request_blocks, assistant_message: , session_event: ) do |requests_to_execute| run_tool_requests(requests_to_execute, session_event: , &block) end tool_results = .tool_results session_manager.(.to_h) if .any? turn_end_event = Event::TurnEnd.new(message: , tool_results: tool_results) emit(turn_end_event, &block) if tool_results.length.positive? return run(&block) end if session_manager.(:follow_up) compact_if_needed return run(&block) if drain_queue(:follow_up).any? end emit(Event::AgentEnd.new(messages: []), &block) end |
#steer_message(message, &block) ⇒ Object
33 34 35 |
# File 'lib/llm_gateway/agents/harness.rb', line 33 def (, &block) enqueue_and_continue_if_idle(, :steer, &block) end |
#transcript ⇒ Object Also known as: prompt
24 25 26 |
# File 'lib/llm_gateway/agents/harness.rb', line 24 def transcript session_manager. end |