Class: ComposableAgents::Agent

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(name: nil, composable_agents_dir: '.composable_agents', logger: ComposableAgents::Logger.instance) ⇒ 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

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

    Logger to be used by this agent. Any Ruby-like logger is accepted. Defaults to ComposableAgents::Logger's singleton instance. This agent's log fields (see #log_fields) are prefixed to logged messages when the logger supports it (see ComposableAgents::Logger#tagged), and are left as-is otherwise.



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/composable_agents/agent.rb', line 22

def initialize(
  name: nil,
  composable_agents_dir: '.composable_agents',
  logger: ComposableAgents::Logger.instance
)
  @name = name
  @composable_agents_dir = composable_agents_dir
  @provided_logger = logger
  @runs_info = []
  @current_run_info = nil
end

Instance Attribute Details

#nameString? (readonly)

Returns The agent name, if any.

Returns:

  • (String, nil)

    The agent name, if any.



9
10
11
# File 'lib/composable_agents/agent.rb', line 9

def name
  @name
end

#runs_infoArray<RunInfo> (readonly)

Returns The list of run information of this agent.

Returns:

  • (Array<RunInfo>)

    The list of run information of this agent.



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

def runs_info
  @runs_info
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



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

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



47
48
49
50
51
52
# File 'lib/composable_agents/agent.rb', line 47

def run(**_input_artifacts)
  @current_run_info = RunInfo.new
  @runs_info << @current_run_info
  publish_run_info(started_at: Time.now)
  {}
end