Class: RobotLab::Task

Inherits:
Object
  • Object
show all
Defined in:
lib/robot_lab/task.rb

Overview

Wraps a Robot for use as a pipeline step with per-task configuration

Task provides a way to pass step-specific context, MCP servers, tools, and memory to individual robots within a network pipeline. The task’s context is deep-merged with the network’s run parameters.

Examples:

Basic task with context

task = Task.new(
  name: :billing,
  robot: billing_robot,
  context: { department: "billing", escalation_level: 2 }
)

Task with MCP and tools

task = Task.new(
  name: :developer,
  robot: dev_robot,
  context: { project: "api" },
  mcp: [filesystem_server, github_server],
  tools: [CodeSearch, FileReader]
)

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name:, robot:, context: {}, mcp: :none, tools: :none, memory: nil, config: nil) ⇒ Task

Creates a new Task instance.

Parameters:

  • name (Symbol)

    the task/step name

  • robot (Robot)

    the robot instance to wrap

  • context (Hash) (defaults to: {})

    task-specific context (deep-merged with run params)

  • mcp (Symbol, Array) (defaults to: :none)

    MCP server config (:none, :inherit, or array)

  • tools (Symbol, Array) (defaults to: :none)

    tools config (:none, :inherit, or array)

  • memory (Memory, Hash, nil) (defaults to: nil)

    task-specific memory



42
43
44
45
46
47
48
49
50
# File 'lib/robot_lab/task.rb', line 42

def initialize(name:, robot:, context: {}, mcp: :none, tools: :none, memory: nil, config: nil)
  @name = name.to_sym
  @robot = robot
  @context = context
  @mcp = mcp
  @tools = tools
  @memory = memory
  @config = config
end

Instance Attribute Details

#nameSymbol (readonly)

Returns the task/step name.

Returns:

  • (Symbol)

    the task/step name



31
32
33
# File 'lib/robot_lab/task.rb', line 31

def name
  @name
end

#robotObject (readonly)

Returns the value of attribute robot.



31
# File 'lib/robot_lab/task.rb', line 31

attr_reader :name, :robot

Instance Method Details

#call(result) ⇒ SimpleFlow::Result

SimpleFlow step interface

Enhances the result’s run_params with task-specific configuration before delegating to the wrapped robot.

Parameters:

  • result (SimpleFlow::Result)

    incoming result from previous step

Returns:

  • (SimpleFlow::Result)

    result with robot output



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/robot_lab/task.rb', line 60

def call(result)
  # Get current run params and deep merge with task context
  run_params = deep_merge(
    result.context[:run_params] || {},
    @context
  )

  # Add task-specific robot config
  run_params[:mcp] = @mcp unless @mcp == :none
  run_params[:tools] = @tools unless @tools == :none
  run_params[:memory] = @memory if @memory

  # Merge task's config on top of network's config
  if @config
    network_rc = run_params[:network_config]
    run_params[:network_config] = network_rc ? network_rc.merge(@config) : @config
  end

  # Create enhanced result with merged params
  enhanced_result = result.with_context(:run_params, run_params)

  # Delegate to robot
  @robot.call(enhanced_result)
end

#to_hHash

Converts the task to a hash representation.

Returns:

  • (Hash)


89
90
91
92
93
94
95
96
97
98
# File 'lib/robot_lab/task.rb', line 89

def to_h
  {
    name: @name,
    robot: @robot.name,
    context: @context,
    mcp: @mcp,
    tools: @tools,
    memory: @memory ? true : nil
  }.compact
end