Class: LLM::Function::Task

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

Overview

This class is the superclass that all concurrency strategies must subclass in order to implement their own Task class. It provides a common interface that is the same across all concurrency strategies.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fn, options = {}) ⇒ Task

Returns a new instance of Task.

Parameters:

  • fn (LLM::Function)
  • options (Hash) (defaults to: {}) —

    An optional set of options that are specific to a given concurrency strategy.

Options Hash (options):

  • :intercepted (LLM::Function::Return, nil) —

    A blocked return produced by the function's intercept, or the in-band error for a tool that cannot be built. When set, the task yields it without running the tool.



51
52
53
54
55
56
# File 'lib/llm/function/task.rb', line 51

def initialize(fn, options = {})
  @function = fn
  @intercepted = options[:intercepted]
  @tracer = options[:tracer]
  @finished_at = nil
end

Instance Attribute Details

#function ⇒ LLM::Function (readonly)

Returns:



12
13
14
# File 'lib/llm/function/task.rb', line 12

def function
  @function
end

#tracer ⇒ LLM::Tracer? (readonly)

The tracer for the task

Returns:



17
18
19
# File 'lib/llm/function/task.rb', line 17

def tracer
  @tracer
end

#span ⇒ Object (readonly)

The span returned by Tracer#on_tool_start

Returns:



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

def span
  @span
end

#started_at ⇒ Float? (readonly)

Note:

This method captures a monotonic clock time (Process::CLOCK_MONOTONIC) rather than a Time object.

Returns when a task started, or nil

Returns:

  • (Float, nil)


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

def started_at
  @started_at
end

#finished_at ⇒ Float? (readonly)

Note:

This method captures a monotonic clock time (Process::CLOCK_MONOTONIC) rather than a Time object.

Returns when a task finished, or nil

Returns:

  • (Float, nil)


40
41
42
# File 'lib/llm/function/task.rb', line 40

def finished_at
  @finished_at
end

Instance Method Details

#interrupt! ⇒ nil Also known as: cancel!

This method is abstract.

Returns:

  • (nil)

Raises:

  • (NotImplementedError)


75
76
77
# File 'lib/llm/function/task.rb', line 75

def interrupt!
  raise NotImplementedError
end

#spawn ⇒ nil

This method is abstract.

Returns:

  • (nil)

Raises:

  • (NotImplementedError)


61
62
63
# File 'lib/llm/function/task.rb', line 61

def spawn
  raise NotImplementedError
end

#alive? ⇒ Boolean

This method is abstract.

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


68
69
70
# File 'lib/llm/function/task.rb', line 68

def alive?
  raise NotImplementedError
end

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

This method is abstract.

This method returns an instance of Return or Interrupt when the task has received an interrupt.

An exception that occurs inside a tool is rescued, and returned by this method as a Return object. It can be distinguished from other returns through the Return#error? method.

Returns:

Raises:

  • (NotImplementedError)


93
94
95
# File 'lib/llm/function/task.rb', line 93

def wait
  raise NotImplementedError
end

#group_class ⇒ Class

This method is abstract.

Returns:

  • (Class)

Raises:

  • (NotImplementedError)


101
102
103
# File 'lib/llm/function/task.rb', line 101

def group_class
  raise NotImplementedError
end

#intercepted? ⇒ Boolean

Returns true when an intercept has returned Return.

Returns:

  • (Boolean)


109
110
111
# File 'lib/llm/function/task.rb', line 109

def intercepted?
  LLM::Function::Return === @intercepted
end