Class: Miniswen::Agent::Result

Inherits:
Data
  • Object
show all
Defined in:
lib/miniswen/agent.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#cached_tokensObject (readonly)

Returns the value of attribute cached_tokens

Returns:

  • (Object)

    the current value of cached_tokens



168
169
170
# File 'lib/miniswen/agent.rb', line 168

def cached_tokens
  @cached_tokens
end

#cost_sourceObject (readonly)

Returns the value of attribute cost_source

Returns:

  • (Object)

    the current value of cost_source



168
169
170
# File 'lib/miniswen/agent.rb', line 168

def cost_source
  @cost_source
end

#cost_usdObject (readonly)

Returns the value of attribute cost_usd

Returns:

  • (Object)

    the current value of cost_usd



168
169
170
# File 'lib/miniswen/agent.rb', line 168

def cost_usd
  @cost_usd
end

#input_tokensObject (readonly)

Returns the value of attribute input_tokens

Returns:

  • (Object)

    the current value of input_tokens



168
169
170
# File 'lib/miniswen/agent.rb', line 168

def input_tokens
  @input_tokens
end

#messagesObject (readonly)

Returns the value of attribute messages

Returns:

  • (Object)

    the current value of messages



168
169
170
# File 'lib/miniswen/agent.rb', line 168

def messages
  @messages
end

#output_tokensObject (readonly)

Returns the value of attribute output_tokens

Returns:

  • (Object)

    the current value of output_tokens



168
169
170
# File 'lib/miniswen/agent.rb', line 168

def output_tokens
  @output_tokens
end

#statusObject (readonly)

Returns the value of attribute status

Returns:

  • (Object)

    the current value of status



168
169
170
# File 'lib/miniswen/agent.rb', line 168

def status
  @status
end

#stepsObject (readonly)

Returns the value of attribute steps

Returns:

  • (Object)

    the current value of steps



168
169
170
# File 'lib/miniswen/agent.rb', line 168

def steps
  @steps
end

#submissionObject (readonly)

Returns the value of attribute submission

Returns:

  • (Object)

    the current value of submission



168
169
170
# File 'lib/miniswen/agent.rb', line 168

def submission
  @submission
end

#thinking_tokensObject (readonly)

Returns the value of attribute thinking_tokens

Returns:

  • (Object)

    the current value of thinking_tokens



168
169
170
# File 'lib/miniswen/agent.rb', line 168

def thinking_tokens
  @thinking_tokens
end

Class Method Details

.deep_symbolize(value) ⇒ Object



190
191
192
193
194
195
196
197
198
199
200
201
# File 'lib/miniswen/agent.rb', line 190

def self.deep_symbolize(value)
  case value
  when Hash
    value.to_h do |key, item|
      key = key.to_sym
      # Tool-call arguments keep their provider-style string keys ("command").
      [key, key == :arguments ? item : deep_symbolize(item)]
    end
  when Array then value.map { deep_symbolize(_1) }
  else value
  end
end

.from_h(payload) ⇒ Object



174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
# File 'lib/miniswen/agent.rb', line 174

def self.from_h(payload)
  data = deep_symbolize(payload)
  source = data[:cost_source]
  new(
    status: data[:status]&.to_sym,
    submission: data[:submission],
    messages: data[:messages] || [],
    steps: data[:steps],
    cost_source: source && CostSource.new(name: source[:name]&.to_sym, model: source[:model],
                                          priced_as: source[:priced_as], registry: source[:registry]),
    input_tokens: data[:input_tokens], output_tokens: data[:output_tokens],
    cached_tokens: data[:cached_tokens], thinking_tokens: data[:thinking_tokens],
    cost_usd: data[:cost_usd]
  )
end

Instance Method Details

#success?Boolean

Returns:

  • (Boolean)


170
# File 'lib/miniswen/agent.rb', line 170

def success? = status == :submitted

#to_hObject



172
# File 'lib/miniswen/agent.rb', line 172

def to_h = super.merge(cost_source: cost_source&.to_h, version: Miniswen::VERSION)