Module: RobotLab::Runnable

Included in:
Network, Robot
Defined in:
lib/robot_lab/runnable.rb

Overview

Shared interface for things you can run with a message: a single Robot or a multi-robot Network. It lets callers treat them uniformly instead of branching on is_a?(RobotLab::Network) — which otherwise spreads concrete type knowledge across every consumer.

Implementers provide:

- #run(message = nil, **opts) — execute with the given message (both Robot
and Network accept a positional message and keyword options)
- #crew                       — the constituent robots, as an Array
- #network?                   — true for a multi-robot network

The rest (chief, robot_count, single?) derive from those.

Examples:

treat either uniformly

runnable.run(prompt, mcp: :inherit, tools: :inherit)
names = runnable.crew.map(&:name)
show_network(runnable) if runnable.network?

Instance Method Summary collapse

Instance Method Details

#chiefRobot?

The lead robot — the chief of the crew.

Returns:



32
33
34
# File 'lib/robot_lab/runnable.rb', line 32

def chief
  crew.first
end

#crewArray<Robot>

The constituent robots as an Array. A single Robot is a crew of one.

Returns:

Raises:

  • (NotImplementedError)


25
26
27
# File 'lib/robot_lab/runnable.rb', line 25

def crew
  raise NotImplementedError, "#{self.class} must implement #crew"
end

#network?Boolean

Returns true for a multi-robot network.

Returns:

  • (Boolean)

    true for a multi-robot network



42
43
44
# File 'lib/robot_lab/runnable.rb', line 42

def network?
  false
end

#robot_countInteger

Returns number of constituent robots.

Returns:

  • (Integer)

    number of constituent robots



37
38
39
# File 'lib/robot_lab/runnable.rb', line 37

def robot_count
  crew.size
end

#single?Boolean

Returns true for a single robot.

Returns:

  • (Boolean)

    true for a single robot



47
48
49
# File 'lib/robot_lab/runnable.rb', line 47

def single?
  !network?
end