Class: Llm::Functions::SwitchAssignee

Inherits:
Base
  • Object
show all
Includes:
AttrReader
Defined in:
lib/llm/functions/switch_assignee.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(assignee, agents) ⇒ SwitchAssignee

Returns a new instance of SwitchAssignee.



11
12
13
14
15
16
# File 'lib/llm/functions/switch_assignee.rb', line 11

def initialize(assignee, agents)
  @messages = []
  @assignee = assignee
  @agents = agents
  @valid_agents = agents.map(&:name_with_type)
end

Instance Attribute Details

#assigneeObject (readonly)

Returns the value of attribute assignee.



5
6
7
# File 'lib/llm/functions/switch_assignee.rb', line 5

def assignee
  @assignee
end

#messagesObject (readonly)

Returns the value of attribute messages.



5
6
7
# File 'lib/llm/functions/switch_assignee.rb', line 5

def messages
  @messages
end

Instance Method Details

#definitionObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/llm/functions/switch_assignee.rb', line 31

def definition
  # @assigneeに応じて毎回作り直す
  definition = {
    name: self.function_name,
    description: I18n.t("ghostest.functions.#{self.function_name}.description"),
    parameters: {
      type: :object,
      properties: {
        next_assignee: {
          type: :string,
          description: I18n.t("ghostest.functions.#{self.function_name}.parameters.next_assignee"),
          enum: @valid_agents - [@assignee.name_with_type],
        },
        message: {
          type: :string,
          description: I18n.t("ghostest.functions.#{self.function_name}.parameters.message"),
        },
      },
      required: [:assignee, :message],
    },
  }
  definition
end

#execute_and_generate_message(args) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/llm/functions/switch_assignee.rb', line 55

def execute_and_generate_message(args)
  if args[:next_assignee].nil? || args[:next_assignee].empty?
    raise Ghostest::Error.new("next_assignee is required")
  end
  if args[:message].nil? || args[:message].empty?
    raise Ghostest::Error.new("message is required")
  end
  next_assignee = @agents.find { |agent| agent.name_with_type == args[:next_assignee] }
  message = {
    name: @assignee.name_with_type,
    next_assignee: next_assignee.name_with_type,
    message: args[:message],
  }
  @assignee = next_assignee
  @messages << message
  message
end

#function_nameObject



7
8
9
# File 'lib/llm/functions/switch_assignee.rb', line 7

def function_name
  :switch_assignee
end

#last_assigneeObject



27
28
29
# File 'lib/llm/functions/switch_assignee.rb', line 27

def last_assignee
  @messages.last[:name]
end

#last_messageObject



23
24
25
# File 'lib/llm/functions/switch_assignee.rb', line 23

def last_message
  @messages.last[:message]
end

#stop_llm_call?Boolean

Returns:

  • (Boolean)


18
19
20
21
# File 'lib/llm/functions/switch_assignee.rb', line 18

def stop_llm_call?
  # stop always
  true
end