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: [], token_usage: nil, steps: 0) ⇒ 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, ?token_usage: Riffer::Providers::TokenUsage?, ?steps: Integer) -> void



47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/riffer/agent/response.rb', line 47

def initialize(content, tripwire: nil, modifications: [], interrupted: false, interrupt_reason: nil, structured_output: nil, messages: [], healed_tool_call_ids: [], token_usage: nil, steps: 0)
  @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
  @token_usage = token_usage
  @steps = steps
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).



43
44
45
# File 'lib/riffer/agent/response.rb', line 43

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.



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

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

#stepsObject (readonly)

The number of LLM calls made during this run (0 when a before-guardrail blocks before any call). Distinct from the session’s cumulative step count.



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

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

#token_usageObject (readonly)

The aggregate token usage across this run’s LLM calls, if any was reported.



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

def token_usage
  @token_usage
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)


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

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)


81
82
83
# File 'lib/riffer/agent/response.rb', line 81

def interrupted?
  @interrupted
end

#modified?Boolean

Returns true if any guardrail modified data during processing.

– : () -> bool

Returns:

  • (Boolean)


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

def modified?
  modifications.any?
end