Class: RubyLLM::Agents::Pipeline::Executor

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_llm/agents/pipeline/executor.rb

Overview

Wraps an agent’s execute method to work with the pipeline.

This is the “core” that middleware wraps around. It’s the final handler in the chain that actually performs the agent’s work.

The Executor adapts the agent’s #execute method to the middleware interface (call(context) -> context).

Examples:

Basic usage

executor = Executor.new(agent)
context = Context.new(input: "hello", agent_class: MyAgent)
result_context = executor.call(context)

With pipeline

pipeline = Builder.for(MyAgent).build(Executor.new(agent))
result = pipeline.call(context)

Convenience class method

result_context = Executor.execute(context)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(agent) ⇒ Executor

Returns a new instance of Executor.

Parameters:

  • agent (Object)

    The agent instance with an #execute method



42
43
44
# File 'lib/ruby_llm/agents/pipeline/executor.rb', line 42

def initialize(agent)
  @agent = agent
end

Class Method Details

.execute(context) ⇒ Context

Execute a context through the full pipeline

Builds the middleware stack based on the agent’s configuration, then executes the context through it.

Parameters:

  • context (Context)

    The execution context

Returns:

  • (Context)

    The context with output set



34
35
36
37
38
39
# File 'lib/ruby_llm/agents/pipeline/executor.rb', line 34

def self.execute(context)
  agent_instance = context.agent_instance
  core = new(agent_instance)
  pipeline = Builder.for(context.agent_class).build(core)
  pipeline.call(context)
end

Instance Method Details

#call(context) ⇒ Context

Execute the agent’s core logic

Calls the agent’s #execute method with the context. The agent is expected to set context.output with the result.

Parameters:

  • context (Context)

    The execution context

Returns:

  • (Context)

    The context with output set



53
54
55
56
# File 'lib/ruby_llm/agents/pipeline/executor.rb', line 53

def call(context)
  @agent.send(:execute, context)
  context
end