Class: LLM::Guard
- Inherits:
-
Object
- Object
- LLM::Guard
- Defined in:
- lib/llm/guard.rb,
lib/llm/guard/loop.rb,
lib/llm/guard/null.rb
Overview
LLM::Guard is the superclass for context-level supervisors in llm.rb.
A guard is bound to a context and decides whether a tool call should
be blocked before it runs. Each subclass implements #call and returns
an LLM::Function::Return that closes the
pending tool call, or nil when execution should continue. The guard
is stamped onto the functions the context binds, so it runs whenever a
task is spawned — including tool calls queued from a stream. The
built-in implementation is LLM::Guard::Loop, which
detects repeated tool-call patterns. LLM::Guard::Null
is a no-op and the default.
LLM::Agent enables LLM::Guard::Loop by default through its wrapped context.
Defined Under Namespace
Instance Attribute Summary collapse
- #ctx ⇒ LLM::Context readonly
Instance Method Summary collapse
-
#call(function:, **opts) ⇒ LLM::Function::Return?
abstract
A tool return that closes this function's pending call when it should be blocked, or nil when execution should continue.
- #initialize(ctx) ⇒ LLM::Guard constructor
Constructor Details
#initialize(ctx) ⇒ LLM::Guard
31 32 33 |
# File 'lib/llm/guard.rb', line 31 def initialize(ctx) @ctx = LLM::Agent === ctx ? ctx.instance_variable_get(:@ctx) : ctx end |
Instance Attribute Details
Instance Method Details
#call(function:, **opts) ⇒ LLM::Function::Return?
Returns A tool return that closes this function's pending call when it should be blocked, or nil when execution should continue.
43 44 45 |
# File 'lib/llm/guard.rb', line 43 def call(function:, **opts) raise NotImplementedError end |