Module: LLM::MessageFilter::Rescue

Includes:
Rescue
Defined in:
lib/llm/message_filter/rescue.rb

Overview

The Rescue module prepends itself to every subclass of LLM::MessageFilter and ensures that a MessageFilter callback never crashes an agent.

When an error occurs, it is dumped to standard error and does not travel up the stack. But LLM::Interrupt, and any other exception not covered by the 'ERRORS' constant can crash the filter. So it handles most cases but not all, and LLM::Interrupt travelling up the stack is intentional.

Instance Method Summary collapse

Methods included from Rescue

#crash

Instance Method Details

#call(message:, **options) ⇒ LLM::Message

Parameters:

Returns:



23
24
25
26
27
28
29
# File 'lib/llm/message_filter/rescue.rb', line 23

def call(message:, **options)
  super
rescue LLM::Interrupt
  raise
rescue *ERRORS => ex
  crash(ex:)
end