Module: SwarmSDK::Tools::PathResolver

Included in:
Edit, Glob, Grep, MultiEdit, Read, Write
Defined in:
lib/swarm_sdk/tools/path_resolver.rb

Overview

Shared path resolution and agent context logic for file tools

This module provides:

  • Path resolution (relative to agent's working directory)
  • Agent context initialization (agent_name, directory expansion)
  • Standard error message formatting

Tools resolve relative paths against the agent's directory. Absolute paths are used as-is.

Examples:

class Read < RubyLLM::Tool
  include PathResolver

  def initialize(agent_name:, directory:)
    super()
    initialize_agent_context(agent_name: agent_name, directory: directory)
  end

  def execute(file_path:)
    resolved_path = resolve_path(file_path)
    File.read(resolved_path)
  rescue StandardError => e
    error("Failed to read: #{e.message}")
  end
end

Instance Attribute Summary collapse

Instance Attribute Details

#agent_nameSymbol (readonly)

Agent context attributes

Returns:

  • (Symbol)

    The agent identifier



34
35
36
# File 'lib/swarm_sdk/tools/path_resolver.rb', line 34

def agent_name
  @agent_name
end

#directoryString (readonly)

Returns Absolute path to agent's working directory.

Returns:

  • (String)

    Absolute path to agent's working directory



37
38
39
# File 'lib/swarm_sdk/tools/path_resolver.rb', line 37

def directory
  @directory
end