Class: Legion::Extensions::Llm::Canonical::ToolCall
- Inherits:
-
Data
- Object
- Data
- Legion::Extensions::Llm::Canonical::ToolCall
- Defined in:
- lib/legion/extensions/llm/canonical/tool_call.rb
Overview
rubocop:disable Lint/ConstantDefinitionInBlock – required for Data.define block scope Canonical tool call with source enum and compliance fields. Ports field vocabulary from Legion::LLM::Types::ToolCall. Source enum per R7: :client | :registry | :special | :extension | :mcp Compliance fields per R8: data_handling_classification, policy_decision
Constant Summary collapse
- SOURCE_VALUES =
%i[client registry special extension mcp].freeze
- STATUS_VALUES =
%i[pending running success error].freeze
Instance Attribute Summary collapse
-
#arguments ⇒ Object
readonly
Returns the value of attribute arguments.
-
#category ⇒ Object
readonly
Returns the value of attribute category.
-
#data_handling_classification ⇒ Object
readonly
Returns the value of attribute data_handling_classification.
-
#duration_ms ⇒ Object
readonly
Returns the value of attribute duration_ms.
-
#error ⇒ Object
readonly
Returns the value of attribute error.
-
#exchange_id ⇒ Object
readonly
Returns the value of attribute exchange_id.
-
#finished_at ⇒ Object
readonly
Returns the value of attribute finished_at.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#policy_decision ⇒ Object
readonly
Returns the value of attribute policy_decision.
-
#result ⇒ Object
readonly
Returns the value of attribute result.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
-
#started_at ⇒ Object
readonly
Returns the value of attribute started_at.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Class Method Summary collapse
-
.build(name:, id: nil, exchange_id: nil, arguments: nil, source: nil, status: nil, duration_ms: nil, result: nil, error: nil, started_at: nil, finished_at: nil, category: nil, data_handling_classification: nil, policy_decision: nil) ⇒ Object
Build from keyword args (primary constructor).
-
.from_hash(hash) ⇒ Object
Build from a Hash (raw provider response or deserialized wire payload).
Instance Method Summary collapse
- #error? ⇒ Boolean
- #success? ⇒ Boolean
-
#to_audit_hash ⇒ Object
Subset for audit/ledger emission.
-
#to_h ⇒ Object
Serialize to a Hash for AMQP/fleet/wire transport.
-
#with_result(result:, status:, duration_ms: nil, finished_at: nil) ⇒ Object
Return a new ToolCall with execution result attached.
Instance Attribute Details
#arguments ⇒ Object (readonly)
Returns the value of attribute arguments
15 16 17 |
# File 'lib/legion/extensions/llm/canonical/tool_call.rb', line 15 def arguments @arguments end |
#category ⇒ Object (readonly)
Returns the value of attribute category
15 16 17 |
# File 'lib/legion/extensions/llm/canonical/tool_call.rb', line 15 def category @category end |
#data_handling_classification ⇒ Object (readonly)
Returns the value of attribute data_handling_classification
15 16 17 |
# File 'lib/legion/extensions/llm/canonical/tool_call.rb', line 15 def data_handling_classification @data_handling_classification end |
#duration_ms ⇒ Object (readonly)
Returns the value of attribute duration_ms
15 16 17 |
# File 'lib/legion/extensions/llm/canonical/tool_call.rb', line 15 def duration_ms @duration_ms end |
#error ⇒ Object (readonly)
Returns the value of attribute error
15 16 17 |
# File 'lib/legion/extensions/llm/canonical/tool_call.rb', line 15 def error @error end |
#exchange_id ⇒ Object (readonly)
Returns the value of attribute exchange_id
15 16 17 |
# File 'lib/legion/extensions/llm/canonical/tool_call.rb', line 15 def exchange_id @exchange_id end |
#finished_at ⇒ Object (readonly)
Returns the value of attribute finished_at
15 16 17 |
# File 'lib/legion/extensions/llm/canonical/tool_call.rb', line 15 def finished_at @finished_at end |
#id ⇒ Object (readonly)
Returns the value of attribute id
15 16 17 |
# File 'lib/legion/extensions/llm/canonical/tool_call.rb', line 15 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name
15 16 17 |
# File 'lib/legion/extensions/llm/canonical/tool_call.rb', line 15 def name @name end |
#policy_decision ⇒ Object (readonly)
Returns the value of attribute policy_decision
15 16 17 |
# File 'lib/legion/extensions/llm/canonical/tool_call.rb', line 15 def policy_decision @policy_decision end |
#result ⇒ Object (readonly)
Returns the value of attribute result
15 16 17 |
# File 'lib/legion/extensions/llm/canonical/tool_call.rb', line 15 def result @result end |
#source ⇒ Object (readonly)
Returns the value of attribute source
15 16 17 |
# File 'lib/legion/extensions/llm/canonical/tool_call.rb', line 15 def source @source end |
#started_at ⇒ Object (readonly)
Returns the value of attribute started_at
15 16 17 |
# File 'lib/legion/extensions/llm/canonical/tool_call.rb', line 15 def started_at @started_at end |
#status ⇒ Object (readonly)
Returns the value of attribute status
15 16 17 |
# File 'lib/legion/extensions/llm/canonical/tool_call.rb', line 15 def status @status end |
Class Method Details
.build(name:, id: nil, exchange_id: nil, arguments: nil, source: nil, status: nil, duration_ms: nil, result: nil, error: nil, started_at: nil, finished_at: nil, category: nil, data_handling_classification: nil, policy_decision: nil) ⇒ Object
Build from keyword args (primary constructor).
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/legion/extensions/llm/canonical/tool_call.rb', line 25 def self.build( name:, id: nil, exchange_id: nil, arguments: nil, source: nil, status: nil, duration_ms: nil, result: nil, error: nil, started_at: nil, finished_at: nil, category: nil, data_handling_classification: nil, policy_decision: nil ) new( id: id || "call_#{SecureRandom.hex(12)}", exchange_id: exchange_id, name: name, arguments: arguments || {}, source: source, status: status, duration_ms: duration_ms, result: result, error: error, started_at: started_at, finished_at: finished_at, category: category, data_handling_classification: data_handling_classification, policy_decision: policy_decision ) end |
.from_hash(hash) ⇒ Object
Build from a Hash (raw provider response or deserialized wire payload).
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/legion/extensions/llm/canonical/tool_call.rb', line 50 def self.from_hash(hash) return nil if hash.nil? h = hash.transform_keys(&:to_sym) # Normalize source to symbol source_raw = h[:source] h[:source] = source_raw&.to_sym if source_raw.is_a?(String) # Normalize status to symbol status_raw = h[:status] h[:status] = status_raw&.to_sym if status_raw.is_a?(String) # Parse arguments if they're a JSON string args = h[:arguments] if args.is_a?(String) && !args.empty? begin h[:arguments] = Legion::JSON.load(args) rescue Legion::JSON::ParseError => e Legion::Logging.debug("[lex-llm][canonical][tool_call] arguments not parseable as JSON, leaving as string: #{e.}") end end build(**h) end |
Instance Method Details
#error? ⇒ Boolean
100 101 102 |
# File 'lib/legion/extensions/llm/canonical/tool_call.rb', line 100 def error? status == :error end |
#success? ⇒ Boolean
96 97 98 |
# File 'lib/legion/extensions/llm/canonical/tool_call.rb', line 96 def success? status == :success end |
#to_audit_hash ⇒ Object
Subset for audit/ledger emission.
110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/legion/extensions/llm/canonical/tool_call.rb', line 110 def to_audit_hash { id: id, name: name, arguments: arguments, status: status, duration_ms: duration_ms, error: error, exchange_id: exchange_id, source: source, category: category, data_handling_classification: data_handling_classification, policy_decision: policy_decision }.compact end |
#to_h ⇒ Object
Serialize to a Hash for AMQP/fleet/wire transport.
105 106 107 |
# File 'lib/legion/extensions/llm/canonical/tool_call.rb', line 105 def to_h super.compact end |
#with_result(result:, status:, duration_ms: nil, finished_at: nil) ⇒ Object
Return a new ToolCall with execution result attached.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/legion/extensions/llm/canonical/tool_call.rb', line 77 def with_result(result:, status:, duration_ms: nil, finished_at: nil) self.class.new( id: id, exchange_id: exchange_id, name: name, arguments: arguments, source: source, status: status, duration_ms: duration_ms, result: result, error: status == :error ? result : error, started_at: started_at, finished_at: finished_at || ::Time.now, category: category, data_handling_classification: data_handling_classification, policy_decision: policy_decision ) end |