Class: Insika::Tools::GenerateImage

Inherits:
RubyLLM::Tool
  • Object
show all
Defined in:
lib/insika/tools/generate_image.rb

Overview

The agent's IMAGE output (WS9, saída). The engine transports media, never meaning: what the image IS for (a virtual try-on, a product mockup) is the skill's business — the contract here just produces the bytes and carries them in the turn's output_parts.

Wired ONLY when both gates pass (ChatBuilder): the agent opted in (outputs.image) AND the channel declared it can receive the media (channel.capabilities includes "image_output") — nothing leaks by default. The image is an envelope part, never part of the answer text; the provider's tokens are merged into the turn's usage like any ask.

Also EDITS — source_image_urls (or, absent that, the turn's own inbound photo) rides paint(with:); mask_url rides paint(mask:). What the edit MEANS (a try-on, a mockup) is the skill's business; this tool only transports the bytes.

Instance Method Summary collapse

Constructor Details

#initialize(runner:, config:, state:) ⇒ GenerateImage

runner: a duck exposing #generate_media_output(:image, prompt, config) -> [part, usage] and #account_media_usage(part, usage) (the Executor).



58
59
60
61
62
63
# File 'lib/insika/tools/generate_image.rb', line 58

def initialize(runner:, config:, state:, **)
  @runner = runner
  @config = config
  @state = state
  super()
end

Instance Method Details

#execute(prompt:, size: nil, source_image_urls: nil, mask_url: nil) ⇒ Object



65
66
67
68
69
70
71
72
73
# File 'lib/insika/tools/generate_image.rb', line 65

def execute(prompt:, size: nil, source_image_urls: nil, mask_url: nil)
  cfg = @config.merge("size" => size.to_s, "mask_url" => mask_url.to_s)
                .reject { |_, v| v.to_s.empty? }
  cfg = cfg.merge(source_config(source_image_urls))
  part, usage = @runner.generate_media_output(:image, prompt.to_s, cfg)
  @state.output_parts << part
  @runner.(@state, part, usage)
  "image generated and attached to the reply (#{part["mime_type"]})"
end

#nameObject



54
# File 'lib/insika/tools/generate_image.rb', line 54

def name = "generate_image"