Class: Riffer::Agent::Response

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

Overview

Wraps an agent generation response. When a guardrail blocks execution, content is empty and tripwire carries the block details.

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

– : (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



40
41
42
43
44
45
46
47
48
49
# File 'lib/riffer/agent/response.rb', line 40

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 riffer filled with placeholder results this turn (when an interrupt left them unanswered and history healing is on).



36
37
38
# File 'lib/riffer/agent/response.rb', line 36

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:

  • (Boolean)


55
56
57
# File 'lib/riffer/agent/response.rb', line 55

def blocked?
  !tripwire.nil?
end

#interrupted?Boolean

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

– : () -> bool

Returns:

  • (Boolean)


72
73
74
# File 'lib/riffer/agent/response.rb', line 72

def interrupted?
  @interrupted
end

#modified?Boolean

Returns true if any guardrail modified data during processing.

– : () -> bool

Returns:

  • (Boolean)


63
64
65
# File 'lib/riffer/agent/response.rb', line 63

def modified?
  modifications.any?
end