Class: Phronomy::Agent::ProviderCallOutcome
- Inherits:
-
Data
- Object
- Data
- Phronomy::Agent::ProviderCallOutcome
- 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
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
-
#role ⇒ Object
readonly
Returns the value of attribute role.
-
#tool_calls ⇒ Object
readonly
Returns the value of attribute tool_calls.
-
#usage ⇒ Object
readonly
Returns the value of attribute usage.
Class Method Summary collapse
Instance Method Summary collapse
- #content_present? ⇒ Boolean
-
#initialize(role:, content:, tool_calls:, usage: {}, metadata: {}) ⇒ ProviderCallOutcome
constructor
A new instance of ProviderCallOutcome.
- #tool_call? ⇒ Boolean
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
#content ⇒ Object (readonly)
Returns the value of attribute content
8 9 10 |
# File 'lib/phronomy/agent/provider_call_outcome.rb', line 8 def content @content end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata
8 9 10 |
# File 'lib/phronomy/agent/provider_call_outcome.rb', line 8 def @metadata end |
#role ⇒ Object (readonly)
Returns the value of attribute role
8 9 10 |
# File 'lib/phronomy/agent/provider_call_outcome.rb', line 8 def role @role end |
#tool_calls ⇒ Object (readonly)
Returns the value of attribute tool_calls
8 9 10 |
# File 'lib/phronomy/agent/provider_call_outcome.rb', line 8 def tool_calls @tool_calls end |
#usage ⇒ Object (readonly)
Returns the value of attribute 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() return if .nil? calls = if .respond_to?(:tool_calls) && .tool_calls source = .tool_calls.respond_to?(:values) ? .tool_calls.values : Array(.tool_calls) source.map { |call| normalize(tool_call_hash(call)) } else [] end usage = if .respond_to?(:tokens) && .tokens normalize(.tokens.respond_to?(:to_h) ? .tokens.to_h : .tokens) else {} end = {} ["model_id"] = .model_id.to_s if .respond_to?(:model_id) && .model_id new( role: .respond_to?(:role) ? .role : :assistant, content: normalize(.respond_to?(:content) ? .content : nil), tool_calls: calls, usage: usage, metadata: ) end |
Instance Method Details
#content_present? ⇒ 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
85 86 87 |
# File 'lib/phronomy/agent/provider_call_outcome.rb', line 85 def tool_call? !tool_calls.empty? end |