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

#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

#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



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

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]
  )
end

.from_hash(hash) ⇒ Object



29
30
31
32
# File 'lib/legion/llm/types/tool_call.rb', line 29

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)


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

def error?
  status == :error
end

#success?Boolean

Returns:

  • (Boolean)


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

def success?
  status == :success
end

#to_audit_hashObject



62
63
64
65
# File 'lib/legion/llm/types/tool_call.rb', line 62

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

#to_hObject



58
59
60
# File 'lib/legion/llm/types/tool_call.rb', line 58

def to_h
  super.compact
end

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



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/legion/llm/types/tool_call.rb', line 42

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
  )
end