Class: LLM::Function::Sequential::Task

Inherits:
Task
  • Object
show all
Defined in:
lib/llm/function/sequential/task.rb

Overview

The Task class wraps a single direct function call behind the same task-like interface used by spawned concurrency modes.

Instance Attribute Summary

Attributes inherited from Task

#finished_at, #function, #span, #started_at, #tracer

Instance Method Summary collapse

Methods inherited from Task

#initialize, #intercepted?

Constructor Details

This class inherits a constructor from LLM::Function::Task

Instance Method Details

#spawn ⇒ nil

Returns:

  • (nil)


11
12
13
14
15
16
17
18
19
# File 'lib/llm/function/sequential/task.rb', line 11

def spawn
  @span = @tracer&.on_tool_start(
    id: @function.id,
    name: @function.name,
    arguments: @function.arguments,
    model: @function.model
  )
  nil
end

#alive? ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/llm/function/sequential/task.rb', line 23

def alive?
  false
end

#interrupt! ⇒ nil Also known as: cancel!

Returns:

  • (nil)


29
30
31
32
33
# File 'lib/llm/function/sequential/task.rb', line 29

def interrupt!
  @cancelled = true
  function.interrupt!
  nil
end

#wait ⇒ LLM::Function::Return, LLM::Interrupt Also known as: value



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/llm/function/sequential/task.rb', line 38

def wait
  return @intercepted if intercepted?
  result = LLM::Object.new(unbox: nil)
  if @cancelled and !@result
    @started_at = Process.clock_gettime(Process::CLOCK_MONOTONIC)
    @finished_at = Process.clock_gettime(Process::CLOCK_MONOTONIC)
    @result = result
    @result.unbox = LLM::Interrupt.new
  else
    @result = (@result || begin
      @started_at = Process.clock_gettime(Process::CLOCK_MONOTONIC)
      begin
        result.unbox = function.call
      rescue LLM::Interrupt => ex
        result.unbox = ex
      ensure
        @finished_at = Process.clock_gettime(Process::CLOCK_MONOTONIC)
      end
      result
    end)
  end
  @result.unbox
end

#group_class ⇒ Class

Returns:

  • (Class)


65
66
67
# File 'lib/llm/function/sequential/task.rb', line 65

def group_class
  LLM::Function::Sequential::Group
end