Class: AgentHarness::SubAgentConfig

Inherits:
Object
  • Object
show all
Defined in:
lib/agent_harness/sub_agent_config.rb

Overview

Canonical provider-agnostic sub-agent definition.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, description:, instructions:, model: "default", tools: [], mcp_servers: [], constraints: {}, handoff_conditions: [], type: nil, sub_agents: [], routing: nil) ⇒ SubAgentConfig

Returns a new instance of SubAgentConfig.



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/agent_harness/sub_agent_config.rb', line 9

def initialize(name:, description:, instructions:, model: "default", tools: [],
  mcp_servers: [], constraints: {}, handoff_conditions: [], type: nil,
  sub_agents: [], routing: nil)
  @name = normalize_name(name)
  @description = validate_string!(:description, description)
  @instructions = validate_string!(:instructions, instructions)
  @model = normalize_model(model)
  @tools = normalize_array(:tools, tools)
  @mcp_servers = normalize_array(:mcp_servers, mcp_servers)
  @constraints = normalize_hash(:constraints, constraints)
  @handoff_conditions = normalize_array(:handoff_conditions, handoff_conditions)
  @type = type&.to_sym
  @sub_agents = normalize_array(:sub_agents, sub_agents)
  @routing = routing.nil? ? nil : normalize_hash(:routing, routing)
end

Instance Attribute Details

#constraintsObject (readonly)

Returns the value of attribute constraints.



7
8
9
# File 'lib/agent_harness/sub_agent_config.rb', line 7

def constraints
  @constraints
end

#descriptionObject (readonly)

Returns the value of attribute description.



6
7
8
# File 'lib/agent_harness/sub_agent_config.rb', line 6

def description
  @description
end

#handoff_conditionsObject (readonly)

Returns the value of attribute handoff_conditions.



7
8
9
# File 'lib/agent_harness/sub_agent_config.rb', line 7

def handoff_conditions
  @handoff_conditions
end

#instructionsObject (readonly)

Returns the value of attribute instructions.



6
7
8
# File 'lib/agent_harness/sub_agent_config.rb', line 6

def instructions
  @instructions
end

#mcp_serversObject (readonly)

Returns the value of attribute mcp_servers.



6
7
8
# File 'lib/agent_harness/sub_agent_config.rb', line 6

def mcp_servers
  @mcp_servers
end

#modelObject (readonly)

Returns the value of attribute model.



6
7
8
# File 'lib/agent_harness/sub_agent_config.rb', line 6

def model
  @model
end

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/agent_harness/sub_agent_config.rb', line 6

def name
  @name
end

#routingObject (readonly)

Returns the value of attribute routing.



7
8
9
# File 'lib/agent_harness/sub_agent_config.rb', line 7

def routing
  @routing
end

#sub_agentsObject (readonly)

Returns the value of attribute sub_agents.



7
8
9
# File 'lib/agent_harness/sub_agent_config.rb', line 7

def sub_agents
  @sub_agents
end

#toolsObject (readonly)

Returns the value of attribute tools.



6
7
8
# File 'lib/agent_harness/sub_agent_config.rb', line 6

def tools
  @tools
end

#typeObject (readonly)

Returns the value of attribute type.



7
8
9
# File 'lib/agent_harness/sub_agent_config.rb', line 7

def type
  @type
end

Class Method Details

.from_hash(hash) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/agent_harness/sub_agent_config.rb', line 25

def self.from_hash(hash)
  unless hash.is_a?(Hash)
    raise ConfigurationError, "Sub-agent definition must be a Hash, got #{hash.class}"
  end

  attrs = hash.each_with_object({}) do |(key, value), memo|
    memo[key.to_sym] = value
  end

  %i[name description instructions].each do |field|
    value = attrs[field]
    next if value.is_a?(String) && !value.strip.empty?
    next if value.is_a?(Symbol)

    raise ConfigurationError, "#{field} is required"
  end

  new(**attrs)
end

Instance Method Details

#to_hObject



45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/agent_harness/sub_agent_config.rb', line 45

def to_h
  {
    name: @name,
    description: @description,
    instructions: @instructions,
    model: @model,
    tools: deep_dup(@tools),
    mcp_servers: deep_dup(@mcp_servers),
    constraints: deep_dup(@constraints),
    handoff_conditions: deep_dup(@handoff_conditions),
    type: @type,
    sub_agents: deep_dup(@sub_agents),
    routing: deep_dup(@routing)
  }.compact
end