Module: LLM::Intercept::Rescue

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

Overview

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

When an error occurs, it is dumped to standard error and the tool call is allowed through. But LLM::Interrupt, and any other exception not covered by the 'ERRORS' constant can crash the intercept. 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(function:, **options) ⇒ Object

Parameters:

  • function (LLM::Function) —

    A function

  • options (Hash) —

    An optional set of options



24
25
26
27
28
29
30
31
# File 'lib/llm/intercept/rescue.rb', line 24

def call(function:, **options)
  super
rescue LLM::Interrupt
  raise
rescue *ERRORS => ex
  crash(ex:)
  function.error(ex:, note: "an intercept crashed")
end