Class: Mistri::ToolCall

Inherits:
Data
  • Object
show all
Defined in:
lib/mistri/tool_call.rb

Overview

One immutable tool invocation requested by the model. Completed arguments are deeply owned JSON; arguments_error records why an unsafe value became nil instead of letting it cross the execution boundary. Signature carries opaque replay state; provider_call_id distinguishes an optional wire ID from Mistri's always-present session correlation ID.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, name:, arguments: {}, signature: nil, arguments_error: nil, provider_call_id: nil, canonicalize: true) ⇒ ToolCall

Returns a new instance of ToolCall.



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

def initialize(id:, name:, arguments: {}, signature: nil, arguments_error: nil,
               provider_call_id: nil, canonicalize: true)
  id = id.dup.freeze if id.is_a?(String)
  name = name.dup.freeze if name.is_a?(String)
  signature = signature.dup.freeze if signature.is_a?(String)
  provider_call_id = provider_call_id.dup.freeze if provider_call_id.is_a?(String)
  @arguments_owned = canonicalize || !arguments_error.nil?
  if arguments_error.nil?
    arguments, arguments_error = ToolArguments.canonicalize(arguments) if canonicalize
  else
    arguments = nil
    arguments_error = ToolArguments.normalize_error(arguments_error)
  end
  super(id:, name:, arguments:, signature:, arguments_error:, provider_call_id:)
end

Instance Attribute Details

#argumentsObject (readonly)

Returns the value of attribute arguments

Returns:

  • (Object)

    the current value of arguments



11
12
13
# File 'lib/mistri/tool_call.rb', line 11

def arguments
  @arguments
end

#arguments_errorObject (readonly)

Returns the value of attribute arguments_error

Returns:

  • (Object)

    the current value of arguments_error



11
12
13
# File 'lib/mistri/tool_call.rb', line 11

def arguments_error
  @arguments_error
end

#idObject (readonly)

Returns the value of attribute id

Returns:

  • (Object)

    the current value of id



11
12
13
# File 'lib/mistri/tool_call.rb', line 11

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name

Returns:

  • (Object)

    the current value of name



11
12
13
# File 'lib/mistri/tool_call.rb', line 11

def name
  @name
end

#provider_call_idObject (readonly)

Returns the value of attribute provider_call_id

Returns:

  • (Object)

    the current value of provider_call_id



11
12
13
# File 'lib/mistri/tool_call.rb', line 11

def provider_call_id
  @provider_call_id
end

#signatureObject (readonly)

Returns the value of attribute signature

Returns:

  • (Object)

    the current value of signature



11
12
13
# File 'lib/mistri/tool_call.rb', line 11

def signature
  @signature
end

Instance Method Details

#arguments_error?Boolean

Returns:

  • (Boolean)


31
# File 'lib/mistri/tool_call.rb', line 31

def arguments_error? = !arguments_error.nil?

#arguments_owned?Boolean

Returns:

  • (Boolean)


33
# File 'lib/mistri/tool_call.rb', line 33

def arguments_owned? = @arguments_owned

#to_hObject



43
44
45
46
47
48
49
50
# File 'lib/mistri/tool_call.rb', line 43

def to_h
  hash = { type: :tool_call, id:, name: }.compact
  hash[:arguments] = arguments
  hash[:signature] = signature unless signature.nil?
  hash[:arguments_error] = arguments_error unless arguments_error.nil?
  hash[:provider_call_id] = provider_call_id unless provider_call_id.nil?
  hash
end

#typeObject



29
# File 'lib/mistri/tool_call.rb', line 29

def type = :tool_call

#with(id: self.id, name: self.name, arguments: self.arguments, signature: self.signature, arguments_error: self.arguments_error, provider_call_id: self.provider_call_id) ⇒ Object

Data#with bypasses custom initializers; this value must re-enter the ownership boundary whenever a normalizer replaces its arguments.



37
38
39
40
41
# File 'lib/mistri/tool_call.rb', line 37

def with(id: self.id, name: self.name, arguments: self.arguments,
         signature: self.signature, arguments_error: self.arguments_error,
         provider_call_id: self.provider_call_id)
  self.class.new(id:, name:, arguments:, signature:, arguments_error:, provider_call_id:)
end