Module: Legion::LLM::Inference::Steps::ToolHistory

Includes:
Logging, StickyHelpers, Legion::Logging::Helper
Included in:
Executor
Defined in:
lib/legion/llm/inference/steps/tool_history.rb

Instance Method Summary collapse

Instance Method Details

#step_tool_history_injectObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/legion/llm/inference/steps/tool_history.rb', line 15

def step_tool_history_inject
  unless sticky_enabled?
    log_step_debug(:tool_history, :skipped, reason: :sticky_disabled)
    return
  end
  unless @request.conversation_id
    log_step_debug(:tool_history, :skipped, reason: :no_conversation_id)
    return
  end

  state   = Inference::Conversation.read_sticky_state(@request.conversation_id)
  history = state[:tool_call_history] || []
  if history.empty?
    log_step_debug(:tool_history, :skipped, reason: :empty_history)
    return
  end

  @enrichments['tool:call_history'] = {
    content:   format_history(history),
    data:      { entry_count: history.size },
    timestamp: Time.now
  }
  log_step_debug(:tool_history, :injected, history_count: history.size)
rescue StandardError => e
  @warnings << "tool_history_inject error: #{e.message}"
  handle_exception(e, level: :warn, operation: 'llm.pipeline.step_tool_history_inject')
end