Class: Riffer::Agent::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/riffer/agent/response.rb

Overview

Wraps agent generation responses with optional tripwire information.

When guardrails block execution, the response will contain a tripwire with details about the block. The content will be empty for blocked responses.

response = agent.generate("Hello")
if response.blocked?
  puts "Blocked: #{response.tripwire.reason}"
else
  puts response.content
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content, tripwire: nil, modifications: []) ⇒ Response

Creates a new response.

content - the response content. tripwire - optional tripwire for blocked responses. modifications - guardrail modifications applied during processing.

: (String, ?tripwire: Riffer::Guardrails::Tripwire?, ?modifications: Array) -> void



32
33
34
35
36
# File 'lib/riffer/agent/response.rb', line 32

def initialize(content, tripwire: nil, modifications: [])
  @content = content
  @tripwire = tripwire
  @modifications = modifications
end

Instance Attribute Details

#contentObject (readonly)

The response content.



17
18
19
# File 'lib/riffer/agent/response.rb', line 17

def content
  @content
end

#modificationsObject (readonly)

The modifications made by guardrails during processing.



23
24
25
# File 'lib/riffer/agent/response.rb', line 23

def modifications
  @modifications
end

#tripwireObject (readonly)

The tripwire if execution was blocked.



20
21
22
# File 'lib/riffer/agent/response.rb', line 20

def tripwire
  @tripwire
end

Instance Method Details

#blocked?Boolean

Returns true if the response was blocked by a guardrail.

: () -> bool

Returns:

  • (Boolean)


41
42
43
# File 'lib/riffer/agent/response.rb', line 41

def blocked?
  !tripwire.nil?
end

#modified?Boolean

Returns true if any guardrail modified data during processing.

: () -> bool

Returns:

  • (Boolean)


48
49
50
# File 'lib/riffer/agent/response.rb', line 48

def modified?
  modifications.any?
end