Class: ComposableAgents::RubyAgent

Inherits:
Agent
  • Object
show all
Defined in:
lib/composable_agents/ruby_agent.rb

Overview

Agent implementation that wraps a Ruby Proc for custom logic

This agent allows wrapping arbitrary Ruby logic as an Agent by providing a Proc that handles the transformation of input artifacts to output artifacts.

Instance Attribute Summary

Attributes inherited from Agent

#name

Public API collapse

Methods inherited from Agent

#full_name

Methods included from Mixins::Logger

debug?

Constructor Details

#initialize(processor, *args, **kwargs) ⇒ RubyAgent

Initialize a new RubyAgent with a processing proc

Parameters:

  • processor (#call(Hash{Symbol => Object}) => Hash{Symbol => Object})

    The agent logic. This proc will receive the input artifacts hash and must return a hash of output artifacts.

    • Param input_artifacts [Hash{Symbol => Object}] Input artifacts provided to the agent
    • Return [Hash{Symbol => Object}] Output artifacts produced by the agent


15
16
17
18
# File 'lib/composable_agents/ruby_agent.rb', line 15

def initialize(processor, *args, **kwargs)
  super(*args, **kwargs)
  @processor = processor
end

Instance Method Details

#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, per artifact name

Returns:

  • (Hash{Symbol => Object})

    The output artifacts returned by the Proc



24
25
26
# File 'lib/composable_agents/ruby_agent.rb', line 24

def run(**input_artifacts)
  @processor.call(input_artifacts)
end