Class: ComposableAgents::Agent

Inherits:
Object
  • Object
show all
Includes:
Mixins::Logger
Defined in:
lib/composable_agents/agent.rb

Overview

Abstract computational unit that transforms inputs into outputs. Agents may internally use LLMs, tools, or other agents. Agents are stateless: they take input artifacts and return output artifacts.

Direct Known Subclasses

PromptDrivenAgent, RubyAgent

Public API collapse

Public API collapse

Methods included from Mixins::Logger

debug?

Internal collapse

Constructor Details

#initialize(name: nil, composable_agents_dir: '.composable_agents') ⇒ Agent

Constructor

Parameters:

  • name (String, nil) (defaults to: nil)

    Agent name, or nil if none

  • composable_agents_dir (String) (defaults to: '.composable_agents')

    Base directory where composable agents can store data



17
18
19
20
21
22
23
# File 'lib/composable_agents/agent.rb', line 17

def initialize(
  name: nil,
  composable_agents_dir: '.composable_agents'
)
  @name = name
  @composable_agents_dir = composable_agents_dir
end

Instance Attribute Details

#nameString? (readonly)

Returns The agent name, if any.

Returns:

  • (String, nil)

    The agent name, if any



11
12
13
# File 'lib/composable_agents/agent.rb', line 11

def name
  @name
end

Instance Method Details

#full_nameString

Return the full name of the agent. This method is intended to be overridden by subclasses to give better full names, tailored to the kind of agent. The full name can be used in logs and traces to better identify the agent.

Returns:

  • (String)

    The agent's full name



30
31
32
# File 'lib/composable_agents/agent.rb', line 30

def full_name
  "#{name || 'Unnamed'}#{" (#{self.class.name.split('::').last})" if self.class != Agent && self.class.name}"
end

#run(**input_artifacts) ⇒ Hash{Symbol => Object}

Execute the agent to generate some output artifacts based on some input artifacts.

Parameters:

  • input_artifacts (Hash{Symbol => Object})

    The input artifacts content

Returns:

  • (Hash{Symbol => Object})

    Output artifacts content

Raises:

  • (NotImplementedError)


40
41
42
# File 'lib/composable_agents/agent.rb', line 40

def run(**input_artifacts)
  raise NotImplementedError, 'This method should be implemented by an Agent subclass'
end