Class: Legate::Agentic::Decision

Inherits:
Data
  • Object
show all
Defined in:
lib/legate/agentic/decision.rb

Overview

One step of an agentic loop: the model either calls a tool or gives a final answer. Immutable.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#actionObject (readonly)

Returns the value of attribute action

Returns:

  • (Object)

    the current value of action



15
16
17
# File 'lib/legate/agentic/decision.rb', line 15

def action
  @action
end

#answerObject (readonly)

Returns the value of attribute answer

Returns:

  • (Object)

    the current value of answer



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/legate/agentic/decision.rb', line 15

Decision = Data.define(:action, :thought, :tool, :params, :answer) do
  def self.tool(tool:, params:, thought: nil)
    new(action: :tool, thought: thought, tool: tool.to_sym, params: params || {}, answer: nil)
  end

  def self.final(answer:, thought: nil)
    new(action: :final, thought: thought, tool: nil, params: {}, answer: answer)
  end

  # An unusable decision (the model returned neither a valid tool call nor a
  # final answer).
  def self.invalid(thought: nil)
    new(action: :invalid, thought: thought, tool: nil, params: {}, answer: nil)
  end

  def final?
    action == :final
  end

  def tool?
    action == :tool && !tool.nil? && !tool.to_s.empty?
  end

  def invalid?
    !final? && !tool?
  end

  # The plan step hash that PlanExecutor#execute_step expects.
  # @return [Hash]
  def to_step
    { tool: tool, params: params }
  end
end

#paramsObject (readonly)

Returns the value of attribute params

Returns:

  • (Object)

    the current value of params



15
16
17
# File 'lib/legate/agentic/decision.rb', line 15

def params
  @params
end

#thoughtObject (readonly)

Returns the value of attribute thought

Returns:

  • (Object)

    the current value of thought



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/legate/agentic/decision.rb', line 15

Decision = Data.define(:action, :thought, :tool, :params, :answer) do
  def self.tool(tool:, params:, thought: nil)
    new(action: :tool, thought: thought, tool: tool.to_sym, params: params || {}, answer: nil)
  end

  def self.final(answer:, thought: nil)
    new(action: :final, thought: thought, tool: nil, params: {}, answer: answer)
  end

  # An unusable decision (the model returned neither a valid tool call nor a
  # final answer).
  def self.invalid(thought: nil)
    new(action: :invalid, thought: thought, tool: nil, params: {}, answer: nil)
  end

  def final?
    action == :final
  end

  def tool?
    action == :tool && !tool.nil? && !tool.to_s.empty?
  end

  def invalid?
    !final? && !tool?
  end

  # The plan step hash that PlanExecutor#execute_step expects.
  # @return [Hash]
  def to_step
    { tool: tool, params: params }
  end
end

#toolObject (readonly)

Returns the value of attribute tool

Returns:

  • (Object)

    the current value of tool



15
16
17
# File 'lib/legate/agentic/decision.rb', line 15

def tool
  @tool
end

Class Method Details

.final(answer:, thought: nil) ⇒ Object



20
21
22
# File 'lib/legate/agentic/decision.rb', line 20

def self.final(answer:, thought: nil)
  new(action: :final, thought: thought, tool: nil, params: {}, answer: answer)
end

.invalid(thought: nil) ⇒ Object

An unusable decision (the model returned neither a valid tool call nor a final answer).



26
27
28
# File 'lib/legate/agentic/decision.rb', line 26

def self.invalid(thought: nil)
  new(action: :invalid, thought: thought, tool: nil, params: {}, answer: nil)
end

.tool(tool:, params:, thought: nil) ⇒ Object



16
17
18
# File 'lib/legate/agentic/decision.rb', line 16

def self.tool(tool:, params:, thought: nil)
  new(action: :tool, thought: thought, tool: tool.to_sym, params: params || {}, answer: nil)
end

Instance Method Details

#action=(value) ⇒ Object (readonly)

:tool or :final



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/legate/agentic/decision.rb', line 15

Decision = Data.define(:action, :thought, :tool, :params, :answer) do
  def self.tool(tool:, params:, thought: nil)
    new(action: :tool, thought: thought, tool: tool.to_sym, params: params || {}, answer: nil)
  end

  def self.final(answer:, thought: nil)
    new(action: :final, thought: thought, tool: nil, params: {}, answer: answer)
  end

  # An unusable decision (the model returned neither a valid tool call nor a
  # final answer).
  def self.invalid(thought: nil)
    new(action: :invalid, thought: thought, tool: nil, params: {}, answer: nil)
  end

  def final?
    action == :final
  end

  def tool?
    action == :tool && !tool.nil? && !tool.to_s.empty?
  end

  def invalid?
    !final? && !tool?
  end

  # The plan step hash that PlanExecutor#execute_step expects.
  # @return [Hash]
  def to_step
    { tool: tool, params: params }
  end
end

#final?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/legate/agentic/decision.rb', line 30

def final?
  action == :final
end

#invalid?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/legate/agentic/decision.rb', line 38

def invalid?
  !final? && !tool?
end

#params=(value) ⇒ Object (readonly)

tool arguments (when action == :tool)



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/legate/agentic/decision.rb', line 15

Decision = Data.define(:action, :thought, :tool, :params, :answer) do
  def self.tool(tool:, params:, thought: nil)
    new(action: :tool, thought: thought, tool: tool.to_sym, params: params || {}, answer: nil)
  end

  def self.final(answer:, thought: nil)
    new(action: :final, thought: thought, tool: nil, params: {}, answer: answer)
  end

  # An unusable decision (the model returned neither a valid tool call nor a
  # final answer).
  def self.invalid(thought: nil)
    new(action: :invalid, thought: thought, tool: nil, params: {}, answer: nil)
  end

  def final?
    action == :final
  end

  def tool?
    action == :tool && !tool.nil? && !tool.to_s.empty?
  end

  def invalid?
    !final? && !tool?
  end

  # The plan step hash that PlanExecutor#execute_step expects.
  # @return [Hash]
  def to_step
    { tool: tool, params: params }
  end
end

#to_stepHash

The plan step hash that PlanExecutor#execute_step expects.

Returns:

  • (Hash)


44
45
46
# File 'lib/legate/agentic/decision.rb', line 44

def to_step
  { tool: tool, params: params }
end

#tool=(value) ⇒ Object (readonly)

the tool to call (when action == :tool)



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/legate/agentic/decision.rb', line 15

Decision = Data.define(:action, :thought, :tool, :params, :answer) do
  def self.tool(tool:, params:, thought: nil)
    new(action: :tool, thought: thought, tool: tool.to_sym, params: params || {}, answer: nil)
  end

  def self.final(answer:, thought: nil)
    new(action: :final, thought: thought, tool: nil, params: {}, answer: answer)
  end

  # An unusable decision (the model returned neither a valid tool call nor a
  # final answer).
  def self.invalid(thought: nil)
    new(action: :invalid, thought: thought, tool: nil, params: {}, answer: nil)
  end

  def final?
    action == :final
  end

  def tool?
    action == :tool && !tool.nil? && !tool.to_s.empty?
  end

  def invalid?
    !final? && !tool?
  end

  # The plan step hash that PlanExecutor#execute_step expects.
  # @return [Hash]
  def to_step
    { tool: tool, params: params }
  end
end

#tool?Boolean

Returns:

  • (Boolean)


34
35
36
# File 'lib/legate/agentic/decision.rb', line 34

def tool?
  action == :tool && !tool.nil? && !tool.to_s.empty?
end