Class: Ragents::Workflow

Inherits:
Object
  • Object
show all
Defined in:
lib/ragents/orchestrator.rb

Overview

Workflow builder for sequential agent execution

Instance Method Summary collapse

Constructor Details

#initialize(orchestrator) ⇒ Workflow

Returns a new instance of Workflow.



138
139
140
141
142
# File 'lib/ragents/orchestrator.rb', line 138

def initialize(orchestrator)
  @orchestrator = orchestrator
  @steps = []
  @current_context = nil
end

Instance Method Details

#executeContext

Execute all steps sequentially

Returns:



155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
# File 'lib/ragents/orchestrator.rb', line 155

def execute
  @steps.each do |step|
    opts = step[:options].dup

    # If a block is provided, call it with current context to get dynamic options
    if step[:block] && @current_context
      dynamic_opts = step[:block].call(@current_context)
      opts = opts.merge(dynamic_opts) if dynamic_opts.is_a?(Hash)
    end

    # Pass the previous context to maintain conversation flow
    opts[:context] = @current_context if @current_context && !opts.key?(:context)

    @current_context = @orchestrator.run(step[:name], **opts)
  end

  @current_context
end

#step(name, **options) {|Context| ... } ⇒ Object

Add a step to the workflow

Parameters:

  • name (Symbol)

    The agent name

  • options (Hash)

    Options for the agent

Yields:

  • (Context)

    Optional block to compute options from previous context



148
149
150
151
# File 'lib/ragents/orchestrator.rb', line 148

def step(name, **options, &block)
  @steps << { name: name, options: options, block: block }
  self
end