Class: SwarmSDK::Workflow::AgentConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/swarm_sdk/workflow/agent_config.rb

Overview

AgentConfig provides fluent API for configuring agents within a node

This class enables the chainable syntax:

agent(:backend).delegates_to(:tester, :database)
agent(:backend, reset_context: false)  # Preserve context across nodes
agent(:backend).tools(:Read, :Edit)    # Override tools for this node

Examples:

Basic delegation

agent(:backend).delegates_to(:tester)

No delegation (solo agent)

agent(:planner)

Preserve agent context

agent(:architect, reset_context: false)

Override tools for this node

agent(:backend).tools(:Read, :Think)

Combine delegation and tool override

agent(:backend).delegates_to(:tester).tools(:Read, :Edit, :Write)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(agent_name, node_builder, reset_context: true) ⇒ AgentConfig

Returns a new instance of AgentConfig.



29
30
31
32
33
34
35
36
# File 'lib/swarm_sdk/workflow/agent_config.rb', line 29

def initialize(agent_name, node_builder, reset_context: true)
  @agent_name = agent_name
  @node_builder = node_builder
  @delegates_to = []
  @reset_context = reset_context
  @tools = nil # nil means use global agent definition tools
  @finalized = false
end

Instance Attribute Details

#agent_nameObject (readonly)

Returns the value of attribute agent_name.



27
28
29
# File 'lib/swarm_sdk/workflow/agent_config.rb', line 27

def agent_name
  @agent_name
end

Instance Method Details

#delegates_to(*agent_names_and_options) ⇒ self

Set delegation targets for this agent

Supports multiple formats for flexibility:

  • Array: delegates_to(:frontend, :backend)
  • Hash: delegates_to(frontend: "AskFrontend", backend: "GetBackend")

Parameters:

  • agent_names_and_options (Array<Symbol, Hash>)

    Names and/or hash with custom tool names

Returns:

  • (self)

    For method chaining



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/swarm_sdk/workflow/agent_config.rb', line 46

def delegates_to(*agent_names_and_options)
  # Parse delegation configs (same logic as Agent::Builder)
  @delegates_to = []
  agent_names_and_options.each do |item|
    case item
    when Symbol, String
      @delegates_to << { agent: item.to_sym, tool_name: nil }
    when Hash
      item.each do |agent, tool_name|
        @delegates_to << { agent: agent.to_sym, tool_name: tool_name }
      end
    end
  end

  update_registration
  self
end

#finalizevoid

This method returns an undefined value.

Finalize agent configuration (backward compatibility)



90
91
92
# File 'lib/swarm_sdk/workflow/agent_config.rb', line 90

def finalize
  update_registration
end

#tools(*tool_names) ⇒ self

Override tools for this agent in this node

Examples:

agent(:backend).tools(:Read, :Edit)

Parameters:

  • tool_names (Array<Symbol>)

    Tool names to use (overrides global agent definition)

Returns:

  • (self)

    For method chaining



71
72
73
74
75
# File 'lib/swarm_sdk/workflow/agent_config.rb', line 71

def tools(*tool_names)
  @tools = tool_names.map(&:to_sym)
  update_registration
  self
end

#update_registrationvoid

This method returns an undefined value.

Update agent registration (called after each fluent method)

Always updates the registration with current state. This allows chaining: .delegates_to(...).tools(...)



83
84
85
# File 'lib/swarm_sdk/workflow/agent_config.rb', line 83

def update_registration
  @node_builder.register_agent(@agent_name, @delegates_to, @reset_context, @tools)
end