Class: OllamaAgent::LLM::Planner

Inherits:
Object
  • Object
show all
Defined in:
lib/ollama_agent/llm/planner.rb

Overview

Strict JSON plan extraction from LLM text with bounded retries (no coercion).

Instance Method Summary collapse

Constructor Details

#initialize(llm_client:, schema:, max_retries: 3, think_block_stripper: ThinkBlockStripper, max_context_tokens: nil, token_counter: OllamaAgent::Context::TokenCounter) ⇒ Planner

rubocop:disable Metrics/ParameterLists – kernel boundary: explicit dependencies



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/ollama_agent/llm/planner.rb', line 14

def initialize(
  llm_client:,
  schema:,
  max_retries: 3,
  think_block_stripper: ThinkBlockStripper,
  max_context_tokens: nil,
  token_counter: OllamaAgent::Context::TokenCounter
)
  @llm_client = llm_client
  @schema = assert_schema!(schema)
  @max_retries = max_retries.to_i
  @think_block_stripper = think_block_stripper
  @max_context_tokens = max_context_tokens
  @token_counter = token_counter
end

Instance Method Details

#plan(prompt:, context:, phase:) ⇒ { plan: Hash }, ...

Returns:

  • ({ plan: Hash }, :invalid_after_retries, :budget_exceeded)


32
33
34
35
36
37
# File 'lib/ollama_agent/llm/planner.rb', line 32

def plan(prompt:, context:, phase:)
  base_messages = normalize_messages(context)
  return :budget_exceeded if context_over_budget?(base_messages, prompt)

  try_plan_with_retries(initial_chat_messages(base_messages, prompt, phase))
end