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, network: 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
51
# File 'lib/robot_lab/task.rb', line 42

def initialize(name:, robot:, context: {}, mcp: :none, tools: :none, memory: nil, config: nil, network: nil)
  @name = name.to_sym
  @robot = robot
  @context = context
  @mcp = mcp
  @tools = tools
  @memory = memory
  @config = config
  @network = network
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



61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/robot_lab/task.rb', line 61

def call(result)
  context = TaskHookContext.new(
    network: @network,
    task: self,
    robot: @robot,
    memory: @memory || @network&.memory,
    config: @config
  )

  RobotLab::Hooks.run(:task, context, registries: [RobotLab.hooks, @network&.hooks]) do
    @robot.call(enhanced_result(result))
  end
end

#to_hHash

Converts the task to a hash representation.

Returns:

  • (Hash)


79
80
81
82
83
84
85
86
87
88
# File 'lib/robot_lab/task.rb', line 79

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