Class: ComposableAgents::Instructions

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/composable_agents/instructions.rb

Overview

Provide a way to define instructions to be used by system and user prompts. Instructions are always normalized as a list of individual instructions that each can be rendered differently depending on the rendering strategy. This is used by PromptDrivenAgent agents only.

Instance Method Summary collapse

Constructor Details

#initialize(instructions) ⇒ Instructions

Constructor

Parameters:

  • instructions (Object)

    The instructions definition. Here are the possible kinds of system instructions:

    • [Array] List of instruction descriptions that should be appended
    • [Object] Individual instruction description. An individual instruction can be one of the following:
      • [String] Direct instructions to be used (equivalent to { text: instructions })
      • [Hash{Symbol => Object}] A structure describing the instructions Here is the list of keys that can define different instructions:
        • text [String] The instructions are given as text directly.
        • ordered_list [Array] The instructions are a precise list of steps to perform. Several keys can be used in the same Hash, and they will be treated in the order of the Hash.
    • 
      
      22
      23
      24
      25
      26
      27
      # File 'lib/composable_agents/instructions.rb', line 22
      
      def initialize(instructions)
        # Normalize system instructions to [Array<Hash{Symbol => Object}>].
        @instructions = (instructions.is_a?(Array) ? instructions : [instructions]).map do |instructions_set|
          instructions_set.is_a?(Hash) ? instructions_set : { text: instructions_set }
        end
      end

      Instance Method Details

      #each {|instruction_type, instruction| ... } ⇒ Object

      Iterate over all instructions

      Yields:

      • (instruction_type, instruction)

        Each instruction present in these instructions.

      Yield Parameters:

      • instruction_type (Symbol)

        The instruction type.

      • instruction (Object)

        The instruction itself.

      
      
      34
      35
      36
      37
      38
      39
      40
      # File 'lib/composable_agents/instructions.rb', line 34
      
      def each(&)
        return enum_for(:each) unless block_given?
      
        @instructions.each do |instructions_set|
          instructions_set.each(&)
        end
      end