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

Inherits:
BaseTool
  • Object
show all
Defined in:
lib/composable_agents/ai_agents/tools/get_artifact_tool.rb

Overview

Tool that is used to read an artifact's content

Internal collapse

Constructor Details

#initialize(artifacts, logger: ComposableAgents::Logger.instance) ⇒ GetArtifactTool

Constructor

Parameters:

  • artifacts (Hash{Symbol => Object})

    ] The artifacts store

  • logger (::Logger) (defaults to: ComposableAgents::Logger.instance)

    Logger to be used by this tool. Any Ruby-like logger is accepted. Defaults to ComposableAgents::Logger's singleton instance.



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

def initialize(artifacts, logger: ComposableAgents::Logger.instance)
  super(logger:)
  @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)
    @logger.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