Class: Riffer::Agent::Response
- Inherits:
-
Object
- Object
- Riffer::Agent::Response
- 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
-
#content ⇒ Object
readonly
The response content.
-
#healed_tool_call_ids ⇒ Object
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).
-
#interrupt_reason ⇒ Object
readonly
The reason provided with the interrupt, if any.
-
#messages ⇒ Object
readonly
The full message history from the agent conversation.
-
#modifications ⇒ Object
readonly
The modifications made by guardrails during processing.
-
#steps ⇒ Object
readonly
The number of LLM calls made during this run (0 when a before-guardrail blocks before any call).
-
#structured_output ⇒ Object
readonly
The parsed structured output, if structured output was configured.
-
#token_usage ⇒ Object
readonly
The aggregate token usage across this run’s LLM calls, if any was reported.
-
#tripwire ⇒ Object
readonly
The tripwire if execution was blocked.
Instance Method Summary collapse
-
#blocked? ⇒ Boolean
Returns true if the response was blocked by a guardrail.
-
#initialize(content, tripwire: nil, modifications: [], interrupted: false, interrupt_reason: nil, structured_output: nil, messages: [], healed_tool_call_ids: [], token_usage: nil, steps: 0) ⇒ Response
constructor
– : (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.
-
#interrupted? ⇒ Boolean
Returns true if the agent loop was interrupted by a callback via
throw :riffer_interrupt. -
#modified? ⇒ Boolean
Returns true if any guardrail modified data during processing.
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
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 = @healed_tool_call_ids = healed_tool_call_ids @token_usage = token_usage @steps = steps end |
Instance Attribute Details
#content ⇒ Object (readonly)
The response content.
17 18 19 |
# File 'lib/riffer/agent/response.rb', line 17 def content @content end |
#healed_tool_call_ids ⇒ Object (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_reason ⇒ Object (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 |
#messages ⇒ Object (readonly)
The full message history from the agent conversation.
39 40 41 |
# File 'lib/riffer/agent/response.rb', line 39 def @messages end |
#modifications ⇒ Object (readonly)
The modifications made by guardrails during processing.
23 24 25 |
# File 'lib/riffer/agent/response.rb', line 23 def modifications @modifications end |
#steps ⇒ Object (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_output ⇒ Object (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_usage ⇒ Object (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 |
#tripwire ⇒ Object (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
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
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
72 73 74 |
# File 'lib/riffer/agent/response.rb', line 72 def modified? modifications.any? end |