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: [], interrupted: false, interrupt_reason: nil, structured_output: nil, messages: [], healed_tool_call_ids: []) ⇒ Response

Creates a new response.

content

the response content.

tripwire

optional tripwire for blocked responses.

modifications

guardrail modifications applied during processing.

interrupted

whether the agent loop was interrupted by a callback.

interrupt_reason

optional reason passed via throw :riffer_interrupt, reason.

structured_output

parsed structured output when structured output is configured.

messages

the full message history from the agent conversation.

healed_tool_call_ids

call ids filled with placeholder tool results

when history healing is enabled.

– : (String, ?tripwire: Riffer::Guardrails::Tripwire?, ?modifications: Array, ?interrupted: bool, ?interrupt_reason: (String | Symbol)?, ?structured_output: Hash[Symbol, untyped]?, ?messages: Array, ?healed_tool_call_ids: Array) -> void



54
55
56
57
58
59
60
61
62
63
# File 'lib/riffer/agent/response.rb', line 54

def initialize(content, tripwire: nil, modifications: [], interrupted: false, interrupt_reason: nil, structured_output: nil, messages: [], healed_tool_call_ids: [])
  @content = content
  @tripwire = tripwire
  @modifications = modifications
  @interrupted = interrupted
  @interrupt_reason = interrupt_reason
  @structured_output = structured_output
  @messages = messages
  @healed_tool_call_ids = healed_tool_call_ids
end

Instance Attribute Details

#contentObject (readonly)

The response content.



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

def content
  @content
end

#healed_tool_call_idsObject (readonly)

Call ids of tool_use blocks that riffer filled with placeholder results during this turn — populated when an interrupt left them unanswered and Riffer.config.experimental_history_healing is on. Empty otherwise.



38
39
40
# File 'lib/riffer/agent/response.rb', line 38

def healed_tool_call_ids
  @healed_tool_call_ids
end

#interrupt_reasonObject (readonly)

The reason provided with the interrupt, if any.



26
27
28
# File 'lib/riffer/agent/response.rb', line 26

def interrupt_reason
  @interrupt_reason
end

#messagesObject (readonly)

The full message history from the agent conversation.



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

def messages
  @messages
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

#structured_outputObject (readonly)

The parsed structured output, if structured output was configured.



29
30
31
# File 'lib/riffer/agent/response.rb', line 29

def structured_output
  @structured_output
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:



69
70
71
# File 'lib/riffer/agent/response.rb', line 69

def blocked?
  !tripwire.nil?
end

#interrupted?Boolean

Returns true if the agent loop was interrupted by a callback via throw :riffer_interrupt.

– : () -> bool

Returns:



86
87
88
# File 'lib/riffer/agent/response.rb', line 86

def interrupted?
  @interrupted
end

#modified?Boolean

Returns true if any guardrail modified data during processing.

– : () -> bool

Returns:



77
78
79
# File 'lib/riffer/agent/response.rb', line 77

def modified?
  modifications.any?
end