Class: Hellm::Tools::AgentToolFactory

Inherits:
Object
  • Object
show all
Defined in:
lib/hellm/tools/agent_tool_factory.rb

Class Method Summary collapse

Class Method Details

.create_sub_agent_tool(agent_name, agent) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/hellm/tools/agent_tool_factory.rb', line 5

def self.create_sub_agent_tool(agent_name, agent)
  klass = Class.new do
    @@agent_name = agent_name

    extend Langchain::ToolDefinition

    def self.tool_name
      @@agent_name
    end

    define_function "run_agent", description: "Run the agent #{agent.name} and return its response.\n#{agent.description}" do
      property :content, type: "string", description: "Textual content to pass to the agent.", required: false
      property :image, type: "string", description: "Image URL or path to pass to the agent.", required: false
    end

    def initialize(agent)
      @agent = agent
    end

    def run_agent(content: nil, image: nil)
      @agent.new_session
      @agent.add(content: content, image: image)
      @agent.run
      @agent.response
    end
  end
  klass.new(agent)
end