Class: Roast::Cogs::Agent::Input
- Inherits:
-
Roast::Cog::Input
- Object
- Roast::Cog::Input
- Roast::Cogs::Agent::Input
- Defined in:
- lib/roast/cogs/agent/input.rb
Overview
Input specification for the agent cog
The agent cog requires a prompt that will be sent to the agent for processing. Optionally, a session identifier can be provided to maintain context across multiple invocations.
Instance Attribute Summary collapse
-
#prompts ⇒ Object
The prompts to send to the agent for processing.
-
#session ⇒ Object
Optional session identifier for maintaining conversation context.
Instance Method Summary collapse
-
#coerce(input_return_value) ⇒ Object
Coerce the input from the return value of the input block.
-
#initialize ⇒ Input
constructor
: () -> void.
-
#prompt=(prompt) ⇒ Object
: (String) -> void.
-
#validate! ⇒ Object
Validate that the input has all required parameters.
Constructor Details
#initialize ⇒ Input
: () -> void
33 34 35 36 |
# File 'lib/roast/cogs/agent/input.rb', line 33 def initialize super @prompts = [] #: Array[String] end |
Instance Attribute Details
#prompts ⇒ Object
The prompts to send to the agent for processing
When multiple prompts are specified, each subsequent prompt is passed to the agent as soon as it completes the previous one, in the same session throughout. This can be useful for helping to ensure the agent produces final outputs in the form you desire after performing a long and complex task.
: Array
19 20 21 |
# File 'lib/roast/cogs/agent/input.rb', line 19 def prompts @prompts end |
#session ⇒ Object
Optional session identifier for maintaining conversation context
When provided, the agent will use this session to maintain context across multiple invocations, allowing for conversational interactions.
The agent will fork a new session from this point, so multiple agents can resume from the same session state.
: String?
30 31 32 |
# File 'lib/roast/cogs/agent/input.rb', line 30 def session @session end |
Instance Method Details
#coerce(input_return_value) ⇒ Object
Coerce the input from the return value of the input block
If the input block returns a String, it will be used as the prompt value. If the input block returns an Array of Strings, the first will be used as the prompt and the rest will be used as finalizers.
#### See Also
-
‘validate!`
: (untyped) -> void
61 62 63 64 65 66 67 68 |
# File 'lib/roast/cogs/agent/input.rb', line 61 def coerce(input_return_value) case input_return_value when String self.prompts = [input_return_value] when Array self.prompts = input_return_value.map(&:to_s) end end |
#prompt=(prompt) ⇒ Object
: (String) -> void
71 72 73 |
# File 'lib/roast/cogs/agent/input.rb', line 71 def prompt=(prompt) @prompts = [prompt] end |
#validate! ⇒ Object
Validate that the input has all required parameters
This method ensures that a prompt has been provided before the agent executes.
#### See Also
-
‘coerce`
: () -> void
46 47 48 49 |
# File 'lib/roast/cogs/agent/input.rb', line 46 def validate! raise Cog::Input::InvalidInputError, "At least one prompt is required" unless prompts.present? raise Cog::Input::InvalidInputError, "Blank prompts are not allowed" if prompts.any?(&:blank?) end |