Class: SwarmSDK::Workflow::Builder

Inherits:
Builders::BaseBuilder show all
Defined in:
lib/swarm_sdk/workflow/builder.rb

Overview

Builder provides DSL for building multi-node workflows This is the top-level builder accessed via SwarmSDK.workflow

The DSL enables:

  • Node-based workflow configuration
  • Agent delegation per node
  • Input/output transformers for data flow
  • Context preservation across nodes

Examples:

Multi-stage workflow

workflow = SwarmSDK.workflow do
  name "Build Pipeline"
  start_node :planning

  agent :architect do
    model "gpt-5"
    prompt "You design systems"
  end

  agent :coder do
    model "gpt-4"
    prompt "You implement code"
  end

  node :planning do
    agent(:architect)
  end

  node :implementation do
    agent(:coder)
    depends_on :planning
  end
end

workflow.execute("Build auth system")

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Builders::BaseBuilder

#agent, #all_agents, #id, #name, #scratchpad, #swarms

Constructor Details

#initialize(allow_filesystem_tools: nil) ⇒ Builder

Returns a new instance of Builder.



57
58
59
60
61
# File 'lib/swarm_sdk/workflow/builder.rb', line 57

def initialize(allow_filesystem_tools: nil)
  super
  @nodes = {}
  @start_node = nil
end

Class Method Details

.build(allow_filesystem_tools: nil, &block) ⇒ Object



50
51
52
53
54
# File 'lib/swarm_sdk/workflow/builder.rb', line 50

def build(allow_filesystem_tools: nil, &block)
  builder = new(allow_filesystem_tools: allow_filesystem_tools)
  builder.instance_eval(&block)
  builder.build_swarm
end

Instance Method Details

#build_swarmObject

Build the actual Workflow instance

Raises:



104
105
106
107
108
109
110
111
112
113
114
# File 'lib/swarm_sdk/workflow/builder.rb', line 104

def build_swarm # Returns Workflow despite method name
  raise ConfigurationError, "Workflow name not set. Use: name 'My Workflow'" unless @swarm_name
  raise ConfigurationError, "No nodes defined. Use: node :name { ... }" if @nodes.empty?
  raise ConfigurationError, "start_node not set. Use: start_node :name" unless @start_node

  # Validate filesystem tools BEFORE building
  validate_all_agents_filesystem_tools if @all_agents_config
  validate_agent_filesystem_tools

  build_workflow
end

#node(name) { ... } ⇒ void

This method returns an undefined value.

Define a node (mini-swarm execution stage)

Nodes enable multi-stage workflows where different agent teams collaborate in sequence. Each node is an independent swarm execution.

Examples:

Solo agent node

node :planning do
  agent(:architect)
end

Multi-agent node with delegation

node :implementation do
  agent(:backend).delegates_to(:tester, :database)
  agent(:tester).delegates_to(:database)
  agent(:database)
  depends_on :planning
end

Parameters:

  • name (Symbol)

    Node name

Yields:

  • Block for node configuration



84
85
86
87
88
# File 'lib/swarm_sdk/workflow/builder.rb', line 84

def node(name, &block)
  builder = Workflow::NodeBuilder.new(name)
  builder.instance_eval(&block)
  @nodes[name] = builder
end

#start_node(name) ⇒ void

This method returns an undefined value.

Set the starting node for workflow execution

Required when nodes are defined. Specifies which node to execute first.

Examples:

start_node :planning

Parameters:

  • name (Symbol)

    Name of starting node



99
100
101
# File 'lib/swarm_sdk/workflow/builder.rb', line 99

def start_node(name)
  @start_node = name.to_sym
end