Class: Legion::LLM::Types::ToolCall

Inherits:
Data
  • Object
show all
Defined in:
lib/legion/llm/types/tool_call.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments

Returns:

  • (Object)

    the current value of arguments



8
9
10
# File 'lib/legion/llm/types/tool_call.rb', line 8

def arguments
  @arguments
end

#categoryObject (readonly)

Returns the value of attribute category

Returns:

  • (Object)

    the current value of category



8
9
10
# File 'lib/legion/llm/types/tool_call.rb', line 8

def category
  @category
end

#data_handling_classificationObject (readonly)

Returns the value of attribute data_handling_classification

Returns:

  • (Object)

    the current value of data_handling_classification



8
9
10
# File 'lib/legion/llm/types/tool_call.rb', line 8

def data_handling_classification
  @data_handling_classification
end

#duration_msObject (readonly)

Returns the value of attribute duration_ms

Returns:

  • (Object)

    the current value of duration_ms



8
9
10
# File 'lib/legion/llm/types/tool_call.rb', line 8

def duration_ms
  @duration_ms
end

#errorObject (readonly)

Returns the value of attribute error

Returns:

  • (Object)

    the current value of error



8
9
10
# File 'lib/legion/llm/types/tool_call.rb', line 8

def error
  @error
end

#exchange_idObject (readonly)

Returns the value of attribute exchange_id

Returns:

  • (Object)

    the current value of exchange_id



8
9
10
# File 'lib/legion/llm/types/tool_call.rb', line 8

def exchange_id
  @exchange_id
end

#finished_atObject (readonly)

Returns the value of attribute finished_at

Returns:

  • (Object)

    the current value of finished_at



8
9
10
# File 'lib/legion/llm/types/tool_call.rb', line 8

def finished_at
  @finished_at
end

#idObject (readonly)

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



8
9
10
# File 'lib/legion/llm/types/tool_call.rb', line 8

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



8
9
10
# File 'lib/legion/llm/types/tool_call.rb', line 8

def name
  @name
end

#policy_decisionObject (readonly)

Returns the value of attribute policy_decision

Returns:

  • (Object)

    the current value of policy_decision



8
9
10
# File 'lib/legion/llm/types/tool_call.rb', line 8

def policy_decision
  @policy_decision
end

#resultObject (readonly)

Returns the value of attribute result

Returns:

  • (Object)

    the current value of result



8
9
10
# File 'lib/legion/llm/types/tool_call.rb', line 8

def result
  @result
end

#sourceObject (readonly)

Returns the value of attribute source

Returns:

  • (Object)

    the current value of source



8
9
10
# File 'lib/legion/llm/types/tool_call.rb', line 8

def source
  @source
end

#started_atObject (readonly)

Returns the value of attribute started_at

Returns:

  • (Object)

    the current value of started_at



8
9
10
# File 'lib/legion/llm/types/tool_call.rb', line 8

def started_at
  @started_at
end

#statusObject (readonly)

Returns the value of attribute status

Returns:

  • (Object)

    the current value of status



8
9
10
# File 'lib/legion/llm/types/tool_call.rb', line 8

def status
  @status
end

Class Method Details

.build(**kwargs) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/legion/llm/types/tool_call.rb', line 14

def self.build(**kwargs)
  new(
    id:                           kwargs[:id] || "call_#{SecureRandom.hex(12)}",
    exchange_id:                  kwargs[:exchange_id],
    name:                         kwargs[:name],
    arguments:                    kwargs[:arguments] || {},
    source:                       kwargs[:source],
    status:                       kwargs[:status],
    duration_ms:                  kwargs[:duration_ms],
    result:                       kwargs[:result],
    error:                        kwargs[:error],
    started_at:                   kwargs[:started_at],
    finished_at:                  kwargs[:finished_at],
    category:                     kwargs[:category],
    data_handling_classification: kwargs[:data_handling_classification],
    policy_decision:              kwargs[:policy_decision]
  )
end

.from_hash(hash) ⇒ Object



33
34
35
36
# File 'lib/legion/llm/types/tool_call.rb', line 33

def self.from_hash(hash)
  hash = hash.transform_keys(&:to_sym) if hash.respond_to?(:transform_keys)
  build(**hash)
end

Instance Method Details

#error?Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/legion/llm/types/tool_call.rb', line 42

def error?
  status == :error
end

#success?Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/legion/llm/types/tool_call.rb', line 38

def success?
  status == :success
end

#to_audit_hashObject



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/legion/llm/types/tool_call.rb', line 69

def to_audit_hash
  {
    id:                           id,
    name:                         name,
    arguments:                    arguments,
    status:                       status,
    duration_ms:                  duration_ms,
    error:                        error,
    exchange_id:                  exchange_id,
    source:                       source,
    category:                     category,
    data_handling_classification: data_handling_classification,
    policy_decision:              policy_decision
  }.compact
end

#to_hObject



65
66
67
# File 'lib/legion/llm/types/tool_call.rb', line 65

def to_h
  super.compact
end

#with_result(result:, status:, duration_ms: nil, finished_at: nil) ⇒ Object



46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/legion/llm/types/tool_call.rb', line 46

def with_result(result:, status:, duration_ms: nil, finished_at: nil)
  ToolCall.new(
    id:                           id,
    exchange_id:                  exchange_id,
    name:                         name,
    arguments:                    arguments,
    source:                       source,
    status:                       status,
    duration_ms:                  duration_ms,
    result:                       result,
    error:                        status == :error ? result : error,
    started_at:                   started_at,
    finished_at:                  finished_at || Time.now,
    category:                     category,
    data_handling_classification: data_handling_classification,
    policy_decision:              policy_decision
  )
end