Class: Riffer::Agent::Response
- Inherits:
-
Object
- Object
- Riffer::Agent::Response
- 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
-
#content ⇒ Object
readonly
The response content.
-
#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.
-
#structured_output ⇒ Object
readonly
The parsed structured output, if structured output was configured.
-
#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: []) ⇒ Response
constructor
Creates a new response.
-
#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: []) ⇒ 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.
– : (String, ?tripwire: Riffer::Guardrails::Tripwire?, ?modifications: Array, ?interrupted: bool, ?interrupt_reason: (String | Symbol)?, ?structured_output: Hash[Symbol, untyped]?, ?messages: Array) -> void
46 47 48 49 50 51 52 53 54 |
# File 'lib/riffer/agent/response.rb', line 46 def initialize(content, tripwire: nil, modifications: [], interrupted: false, interrupt_reason: nil, structured_output: nil, messages: []) @content = content @tripwire = tripwire @modifications = modifications @interrupted = interrupted @interrupt_reason = interrupt_reason @structured_output = structured_output @messages = 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 |
#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.
32 33 34 |
# File 'lib/riffer/agent/response.rb', line 32 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 |
#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 |
#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
60 61 62 |
# File 'lib/riffer/agent/response.rb', line 60 def blocked? !tripwire.nil? end |
#interrupted? ⇒ Boolean
Returns true if the agent loop was interrupted by a callback via throw :riffer_interrupt.
– : () -> bool
77 78 79 |
# File 'lib/riffer/agent/response.rb', line 77 def interrupted? @interrupted end |
#modified? ⇒ Boolean
Returns true if any guardrail modified data during processing.
– : () -> bool
68 69 70 |
# File 'lib/riffer/agent/response.rb', line 68 def modified? modifications.any? end |