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
- #follow_up_message(message, &block) ⇒ Object
-
#initialize(session_manager, provider:, model: nil, reasoning: "high") ⇒ Harness
constructor
A new instance of Harness.
- #next_turn_message(message, &block) ⇒ Object
- #prompt_message(message, &block) ⇒ Object
- #run(&block) ⇒ Object (also: #continue)
- #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 = :next_turn 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
69 70 71 |
# File 'lib/llm_gateway/agents/harness.rb', line 69 def compact session_manager.compaction(provider) end |
#follow_up_message(message, &block) ⇒ Object
37 38 39 |
# File 'lib/llm_gateway/agents/harness.rb', line 37 def (, &block) (, :follow_up, &block) end |
#next_turn_message(message, &block) ⇒ Object
41 42 43 |
# File 'lib/llm_gateway/agents/harness.rb', line 41 def (, &block) (, :next_turn, &block) end |
#prompt_message(message, &block) ⇒ Object
29 30 31 |
# File 'lib/llm_gateway/agents/harness.rb', line 29 def (, &block) (, default_queue_mode, &block) end |
#run(&block) ⇒ Object Also known as: continue
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 109 110 111 112 113 114 |
# File 'lib/llm_gateway/agents/harness.rb', line 73 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_results = tool_requests().map do || parameters = .to_h emit(Event::ToolExecutionStart.new(parameters: parameters), &block) tool_result = find_and_execute_tool() emit(Event::ToolExecutionEnd.new(parameters: parameters, result: tool_result), &block) tool_result end tool_result_content = tool_results.map(&:to_h) session_manager.( role: "user", content: tool_result_content, ) unless tool_result_content.empty? 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) (, :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 |