Class: ComposableAgents::AiAgents::Tools::GetArtifactTool

Inherits:
Agents::Tool
  • Object
show all
Includes:
Mixins::Logger
Defined in:
lib/composable_agents/ai_agents/tools/get_artifact_tool.rb

Overview

Tool that is used to read an artifact's content

Instance Method Summary collapse

Methods included from Mixins::Logger

debug?

Constructor Details

#initialize(artifacts) ⇒ GetArtifactTool

Constructor

Parameters:

  • artifacts (Hash{Symbol => Object})

    ] The artifacts store



16
17
18
19
# File 'lib/composable_agents/ai_agents/tools/get_artifact_tool.rb', line 16

def initialize(artifacts)
  super()
  @artifacts = artifacts
end

Instance Method Details

#perform(_tool_context, name:) ⇒ String

Perform the tool's action. This is called by ai-agents when the model requires it.

Parameters:

  • _tool_context (Agents::ToolContext)

    The tool context

  • name (String)

    The required artifact's name

Returns:

  • (String)

    The tool's response



27
28
29
30
31
32
33
34
35
# File 'lib/composable_agents/ai_agents/tools/get_artifact_tool.rb', line 27

def perform(_tool_context, name:)
  name_sym = name.to_sym
  if @artifacts.key?(name_sym)
    log_debug "Artifact `#{name}` read successfully."
    @artifacts[name_sym].to_s.strip
  else
    "[ERROR] No artifact named #{name}, don't call this tool with the name #{name} anymore."
  end
end