Class: Phronomy::Agent::ProviderCallOutcome

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

Overview

Immutable, Phronomy-owned snapshot of one completed Provider assistant output. It is captured before Agent-owned Tool execution begins, so durable logging never depends on RubyLLM's later control flow or Application callbacks.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(role:, content:, tool_calls:, usage: {}, metadata: {}) ⇒ ProviderCallOutcome

Returns a new instance of ProviderCallOutcome.



66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/phronomy/agent/provider_call_outcome.rb', line 66

def initialize(role:, content:, tool_calls:, usage: {}, metadata: {})
  super(
    role: role&.to_sym,
    content: Immutable.copy(content),
    tool_calls: Immutable.copy(Array(tool_calls)),
    usage: Immutable.copy(usage || {}),
    metadata: Immutable.copy( || {})
  )
  Immutable.validate_canonical_json!(content, label: "Provider assistant content")
  Immutable.validate_canonical_json!(tool_calls, label: "Provider Tool Calls")
  Immutable.validate_canonical_json!(usage, label: "Provider usage")
  Immutable.validate_canonical_json!(, label: "Provider outcome metadata")
  freeze
end

Instance Attribute Details

#contentObject (readonly)

Returns the value of attribute content

Returns:

  • (Object)

    the current value of content



8
9
10
# File 'lib/phronomy/agent/provider_call_outcome.rb', line 8

def content
  @content
end

#metadataObject (readonly)

Returns the value of attribute metadata

Returns:

  • (Object)

    the current value of metadata



8
9
10
# File 'lib/phronomy/agent/provider_call_outcome.rb', line 8

def 
  @metadata
end

#roleObject (readonly)

Returns the value of attribute role

Returns:

  • (Object)

    the current value of role



8
9
10
# File 'lib/phronomy/agent/provider_call_outcome.rb', line 8

def role
  @role
end

#tool_callsObject (readonly)

Returns the value of attribute tool_calls

Returns:

  • (Object)

    the current value of tool_calls



8
9
10
# File 'lib/phronomy/agent/provider_call_outcome.rb', line 8

def tool_calls
  @tool_calls
end

#usageObject (readonly)

Returns the value of attribute usage

Returns:

  • (Object)

    the current value of usage



8
9
10
# File 'lib/phronomy/agent/provider_call_outcome.rb', line 8

def usage
  @usage
end

Class Method Details

.capture(message) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/phronomy/agent/provider_call_outcome.rb', line 9

def self.capture(message)
  return if message.nil?

  calls = if message.respond_to?(:tool_calls) && message.tool_calls
    source = message.tool_calls.respond_to?(:values) ? message.tool_calls.values : Array(message.tool_calls)
    source.map { |call| normalize(tool_call_hash(call)) }
  else
    []
  end
  usage = if message.respond_to?(:tokens) && message.tokens
    normalize(message.tokens.respond_to?(:to_h) ? message.tokens.to_h : message.tokens)
  else
    {}
  end
   = {}
  ["model_id"] = message.model_id.to_s if message.respond_to?(:model_id) && message.model_id

  new(
    role: message.respond_to?(:role) ? message.role : :assistant,
    content: normalize(message.respond_to?(:content) ? message.content : nil),
    tool_calls: calls,
    usage: usage,
    metadata: 
  )
end

Instance Method Details

#content_present?Boolean

Returns:

  • (Boolean)


81
82
83
# File 'lib/phronomy/agent/provider_call_outcome.rb', line 81

def content_present?
  !content.nil? && !(content.respond_to?(:empty?) && content.empty?)
end

#tool_call?Boolean

Returns:

  • (Boolean)


85
86
87
# File 'lib/phronomy/agent/provider_call_outcome.rb', line 85

def tool_call?
  !tool_calls.empty?
end