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.

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



28
29
30
31
32
33
# File 'lib/insika/tools/generate_image.rb', line 28

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

Instance Method Details

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



35
36
37
38
39
40
41
# File 'lib/insika/tools/generate_image.rb', line 35

def execute(prompt:, size: nil)
  cfg = @config.merge("size" => size.to_s).reject { |_, v| v.to_s.empty? }
  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



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

def name = "generate_image"