Class: Mistri::ToolResult

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

Overview

A tool result with model content, host-only UI, and an explicit failure fact. Both channels and the error bit persist with the tool message; only content and provider-supported error signaling reach the model.

Tool.define("edit_page", "Edits the page.", schema: -> {
object :changes, "Page changes", required: true
}) do |args|
page = apply(args.fetch("changes"))
Mistri::ToolResult.new(content: "Updated.", ui: { "html" => page })
end

ui must be JSON-serializable; it is stored and delivered in canonical JSON form (string keys), the same shape a reloaded session reads.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(content:, ui: nil, error: false) ⇒ ToolResult

Returns a new instance of ToolResult.



18
19
20
21
22
23
24
# File 'lib/mistri/tool_result.rb', line 18

def initialize(content:, ui: nil, error: false)
  unless [true, false].include?(error)
    raise ArgumentError, "tool result error must be true or false"
  end

  super
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content

Returns:

  • (Object)

    the current value of content



17
18
19
# File 'lib/mistri/tool_result.rb', line 17

def content
  @content
end

#errorObject (readonly)

Returns the value of attribute error

Returns:

  • (Object)

    the current value of error



17
18
19
# File 'lib/mistri/tool_result.rb', line 17

def error
  @error
end

#uiObject (readonly)

Returns the value of attribute ui

Returns:

  • (Object)

    the current value of ui



17
18
19
# File 'lib/mistri/tool_result.rb', line 17

def ui
  @ui
end

Instance Method Details

#error?Boolean

Returns:

  • (Boolean)


26
# File 'lib/mistri/tool_result.rb', line 26

def error? = error