Class: Agents::Action
- Inherits:
-
Object
- Object
- Agents::Action
- Defined in:
- lib/actions/action.rb
Overview
Takes a block and executes it when the action is called.
Direct Known Subclasses
Agents::Actions::AskForClarificationAction, Agents::Actions::DelegateAction
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#examples ⇒ Object
readonly
Returns the value of attribute examples.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
Instance Method Summary collapse
- #for_prompt ⇒ Object
-
#initialize(name:, description: "", arguments: [], examples: []) ⇒ Action
constructor
Create a new action.
-
#perform(request:, args:) ⇒ Object
Execute the block with the given arguments.
Constructor Details
#initialize(name:, description: "", arguments: [], examples: []) ⇒ Action
Create a new action
12 13 14 15 16 17 |
# File 'lib/actions/action.rb', line 12 def initialize(name:, description: "", arguments: [], examples: []) @name = name @description = description @arguments = arguments @examples = examples end |
Instance Attribute Details
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments.
5 6 7 |
# File 'lib/actions/action.rb', line 5 def arguments @arguments end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
5 6 7 |
# File 'lib/actions/action.rb', line 5 def description @description end |
#examples ⇒ Object (readonly)
Returns the value of attribute examples.
5 6 7 |
# File 'lib/actions/action.rb', line 5 def examples @examples end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/actions/action.rb', line 5 def name @name end |
Instance Method Details
#for_prompt ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/actions/action.rb', line 23 def for_prompt s = "#{name}: #{description}\n" unless arguments.empty? s << " Arguments:\n" s << arguments.collect(&:for_prompt).join("\n") << "\n" end unless examples.empty? s << " For example:\n" s << examples.collect(&:for_prompt).join("\n") << "\n" end s end |
#perform(request:, args:) ⇒ Object
Execute the block with the given arguments.
20 21 |
# File 'lib/actions/action.rb', line 20 def perform(request:, args:) end |