ruby_llm-agents 3.8.0 → 3.10.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +30 -10
- data/app/controllers/ruby_llm/agents/requests_controller.rb +117 -0
- data/app/models/ruby_llm/agents/execution.rb +4 -0
- data/app/models/ruby_llm/agents/tool_execution.rb +25 -0
- data/app/views/layouts/ruby_llm/agents/application.html.erb +4 -2
- data/app/views/ruby_llm/agents/requests/index.html.erb +153 -0
- data/app/views/ruby_llm/agents/requests/show.html.erb +136 -0
- data/config/routes.rb +2 -0
- data/lib/generators/ruby_llm_agents/agent_generator.rb +2 -2
- data/lib/generators/ruby_llm_agents/demo_generator.rb +102 -0
- data/lib/generators/ruby_llm_agents/doctor_generator.rb +196 -0
- data/lib/generators/ruby_llm_agents/install_generator.rb +7 -19
- data/lib/generators/ruby_llm_agents/templates/agent.rb.tt +27 -80
- data/lib/generators/ruby_llm_agents/templates/application_agent.rb.tt +18 -51
- data/lib/generators/ruby_llm_agents/templates/initializer.rb.tt +19 -17
- data/lib/ruby_llm/agents/base_agent.rb +70 -7
- data/lib/ruby_llm/agents/core/base.rb +4 -0
- data/lib/ruby_llm/agents/core/configuration.rb +12 -0
- data/lib/ruby_llm/agents/core/errors.rb +3 -0
- data/lib/ruby_llm/agents/core/version.rb +1 -1
- data/lib/ruby_llm/agents/pipeline/context.rb +26 -0
- data/lib/ruby_llm/agents/pipeline/middleware/base.rb +58 -4
- data/lib/ruby_llm/agents/pipeline/middleware/budget.rb +17 -17
- data/lib/ruby_llm/agents/pipeline/middleware/cache.rb +34 -22
- data/lib/ruby_llm/agents/pipeline/middleware/instrumentation.rb +105 -50
- data/lib/ruby_llm/agents/pipeline/middleware/reliability.rb +7 -5
- data/lib/ruby_llm/agents/pipeline/middleware/tenant.rb +6 -4
- data/lib/ruby_llm/agents/rails/engine.rb +11 -0
- data/lib/ruby_llm/agents/results/background_removal_result.rb +7 -1
- data/lib/ruby_llm/agents/results/base.rb +39 -2
- data/lib/ruby_llm/agents/results/embedding_result.rb +4 -0
- data/lib/ruby_llm/agents/results/image_analysis_result.rb +7 -1
- data/lib/ruby_llm/agents/results/image_edit_result.rb +7 -1
- data/lib/ruby_llm/agents/results/image_generation_result.rb +7 -1
- data/lib/ruby_llm/agents/results/image_pipeline_result.rb +7 -1
- data/lib/ruby_llm/agents/results/image_transform_result.rb +7 -1
- data/lib/ruby_llm/agents/results/image_upscale_result.rb +7 -1
- data/lib/ruby_llm/agents/results/image_variation_result.rb +7 -1
- data/lib/ruby_llm/agents/results/speech_result.rb +6 -0
- data/lib/ruby_llm/agents/results/trackable.rb +25 -0
- data/lib/ruby_llm/agents/results/transcription_result.rb +6 -0
- data/lib/ruby_llm/agents/text/embedder.rb +7 -4
- data/lib/ruby_llm/agents/tool.rb +169 -0
- data/lib/ruby_llm/agents/tool_context.rb +71 -0
- data/lib/ruby_llm/agents/track_report.rb +127 -0
- data/lib/ruby_llm/agents/tracker.rb +32 -0
- data/lib/ruby_llm/agents.rb +212 -0
- data/lib/tasks/ruby_llm_agents.rake +6 -0
- metadata +13 -2
|
@@ -39,45 +39,47 @@ module RubyLLM
|
|
|
39
39
|
def call(context)
|
|
40
40
|
context.started_at = Time.current
|
|
41
41
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
begin
|
|
50
|
-
@app.call(context)
|
|
51
|
-
context.completed_at = Time.current
|
|
52
|
-
|
|
53
|
-
begin
|
|
54
|
-
complete_execution(execution, context, status: "success")
|
|
55
|
-
status_update_completed = true
|
|
56
|
-
rescue
|
|
57
|
-
# Let ensure block handle via mark_execution_failed!
|
|
58
|
-
end
|
|
59
|
-
|
|
60
|
-
emit_complete_notification(context, "success")
|
|
61
|
-
rescue => e
|
|
62
|
-
context.completed_at = Time.current
|
|
63
|
-
context.error = e
|
|
64
|
-
raised_exception = e
|
|
42
|
+
trace(context) do
|
|
43
|
+
# Create "running" record immediately (SYNC - must appear on dashboard)
|
|
44
|
+
execution = create_running_execution(context)
|
|
45
|
+
context.execution_id = execution&.id
|
|
46
|
+
emit_start_notification(context)
|
|
47
|
+
status_update_completed = false
|
|
48
|
+
raised_exception = nil
|
|
65
49
|
|
|
66
50
|
begin
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
51
|
+
@app.call(context)
|
|
52
|
+
context.completed_at = Time.current
|
|
53
|
+
|
|
54
|
+
begin
|
|
55
|
+
complete_execution(execution, context, status: "success")
|
|
56
|
+
status_update_completed = true
|
|
57
|
+
rescue
|
|
58
|
+
# Let ensure block handle via mark_execution_failed!
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
emit_complete_notification(context, "success")
|
|
62
|
+
rescue => e
|
|
63
|
+
context.completed_at = Time.current
|
|
64
|
+
context.error = e
|
|
65
|
+
raised_exception = e
|
|
66
|
+
|
|
67
|
+
begin
|
|
68
|
+
complete_execution(execution, context, status: determine_error_status(e))
|
|
69
|
+
status_update_completed = true
|
|
70
|
+
rescue
|
|
71
|
+
# Let ensure block handle via mark_execution_failed!
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
emit_complete_notification(context, determine_error_status(e))
|
|
75
|
+
raise
|
|
76
|
+
ensure
|
|
77
|
+
# Emergency fallback if update failed
|
|
78
|
+
mark_execution_failed!(execution, error: raised_exception || $!) unless status_update_completed
|
|
71
79
|
end
|
|
72
80
|
|
|
73
|
-
|
|
74
|
-
raise
|
|
75
|
-
ensure
|
|
76
|
-
# Emergency fallback if update failed
|
|
77
|
-
mark_execution_failed!(execution, error: raised_exception || $!) unless status_update_completed
|
|
81
|
+
context
|
|
78
82
|
end
|
|
79
|
-
|
|
80
|
-
context
|
|
81
83
|
end
|
|
82
84
|
|
|
83
85
|
private
|
|
@@ -111,7 +113,7 @@ module RubyLLM
|
|
|
111
113
|
|
|
112
114
|
execution
|
|
113
115
|
rescue => e
|
|
114
|
-
error("Failed to create running execution record: #{e.message}")
|
|
116
|
+
error("Failed to create running execution record: #{e.message}", context)
|
|
115
117
|
nil
|
|
116
118
|
end
|
|
117
119
|
|
|
@@ -142,7 +144,7 @@ module RubyLLM
|
|
|
142
144
|
# Save detail data (prompts, responses, tool calls, etc.)
|
|
143
145
|
save_execution_details(execution, context, status)
|
|
144
146
|
rescue => e
|
|
145
|
-
error("Failed to complete execution record: #{e.message}")
|
|
147
|
+
error("Failed to complete execution record: #{e.message}", context)
|
|
146
148
|
raise # Re-raise for ensure block to handle via mark_execution_failed!
|
|
147
149
|
end
|
|
148
150
|
|
|
@@ -158,7 +160,7 @@ module RubyLLM
|
|
|
158
160
|
return unless execution&.id
|
|
159
161
|
return unless execution.status == "running"
|
|
160
162
|
|
|
161
|
-
error_message = error
|
|
163
|
+
error_message = build_error_message(error)
|
|
162
164
|
|
|
163
165
|
update_data = {
|
|
164
166
|
status: "error",
|
|
@@ -183,6 +185,28 @@ module RubyLLM
|
|
|
183
185
|
error("CRITICAL: Failed emergency status update for execution #{execution&.id}: #{e.message}")
|
|
184
186
|
end
|
|
185
187
|
|
|
188
|
+
# Builds an informative error message including backtrace context
|
|
189
|
+
#
|
|
190
|
+
# Preserves the error class, message, and the most relevant
|
|
191
|
+
# backtrace frames (up to 10) so developers can trace the
|
|
192
|
+
# failure origin without needing to reproduce it.
|
|
193
|
+
#
|
|
194
|
+
# @param error [Exception, nil] The exception
|
|
195
|
+
# @return [String] Formatted error message with backtrace
|
|
196
|
+
def build_error_message(error)
|
|
197
|
+
return "Unknown error" unless error
|
|
198
|
+
|
|
199
|
+
parts = ["#{error.class}: #{error.message}"]
|
|
200
|
+
|
|
201
|
+
if error.backtrace&.any?
|
|
202
|
+
relevant_frames = error.backtrace.first(10)
|
|
203
|
+
parts << "Backtrace (first #{relevant_frames.size} frames):"
|
|
204
|
+
parts.concat(relevant_frames.map { |frame| " #{frame}" })
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
parts.join("\n").truncate(5000)
|
|
208
|
+
end
|
|
209
|
+
|
|
186
210
|
# Determines the status based on error type
|
|
187
211
|
#
|
|
188
212
|
# @param error [Exception] The exception that occurred
|
|
@@ -206,7 +230,7 @@ module RubyLLM
|
|
|
206
230
|
execution_id: context.execution_id
|
|
207
231
|
)
|
|
208
232
|
rescue => e
|
|
209
|
-
debug("Start notification failed: #{e.message}")
|
|
233
|
+
debug("Start notification failed: #{e.message}", context)
|
|
210
234
|
end
|
|
211
235
|
|
|
212
236
|
# Emits an AS::Notification for execution completion or error
|
|
@@ -243,7 +267,7 @@ module RubyLLM
|
|
|
243
267
|
error_message: context.error&.message
|
|
244
268
|
)
|
|
245
269
|
rescue => e
|
|
246
|
-
debug("Complete notification failed: #{e.message}")
|
|
270
|
+
debug("Complete notification failed: #{e.message}", context)
|
|
247
271
|
end
|
|
248
272
|
|
|
249
273
|
# Builds data for initial running execution record
|
|
@@ -295,6 +319,9 @@ module RubyLLM
|
|
|
295
319
|
data[:root_execution_id] = context.root_execution_id || context.parent_execution_id
|
|
296
320
|
end
|
|
297
321
|
|
|
322
|
+
# Inject tracker request_id and tags
|
|
323
|
+
inject_tracker_data(context, data)
|
|
324
|
+
|
|
298
325
|
data
|
|
299
326
|
end
|
|
300
327
|
|
|
@@ -322,7 +349,7 @@ module RubyLLM
|
|
|
322
349
|
context_meta = begin
|
|
323
350
|
context.metadata.dup
|
|
324
351
|
rescue => e
|
|
325
|
-
debug("Failed to read context metadata: #{e.message}")
|
|
352
|
+
debug("Failed to read context metadata: #{e.message}", context)
|
|
326
353
|
{}
|
|
327
354
|
end
|
|
328
355
|
context_meta.transform_keys!(&:to_s)
|
|
@@ -365,7 +392,7 @@ module RubyLLM
|
|
|
365
392
|
end
|
|
366
393
|
|
|
367
394
|
if context.error
|
|
368
|
-
detail_data[:error_message] =
|
|
395
|
+
detail_data[:error_message] = build_error_message(context.error)
|
|
369
396
|
end
|
|
370
397
|
|
|
371
398
|
if context[:tool_calls].present?
|
|
@@ -392,7 +419,7 @@ module RubyLLM
|
|
|
392
419
|
execution.create_detail!(detail_data)
|
|
393
420
|
end
|
|
394
421
|
rescue => e
|
|
395
|
-
error("Failed to save execution details: #{e.message}")
|
|
422
|
+
error("Failed to save execution details: #{e.message}", context)
|
|
396
423
|
end
|
|
397
424
|
|
|
398
425
|
# Persists execution data to database (legacy fallback)
|
|
@@ -412,7 +439,7 @@ module RubyLLM
|
|
|
412
439
|
create_execution_record(data)
|
|
413
440
|
end
|
|
414
441
|
rescue => e
|
|
415
|
-
error("Failed to record execution: #{e.message}")
|
|
442
|
+
error("Failed to record execution: #{e.message}", context)
|
|
416
443
|
end
|
|
417
444
|
|
|
418
445
|
# Builds execution data hash for the legacy single-step persistence path.
|
|
@@ -435,7 +462,7 @@ module RubyLLM
|
|
|
435
462
|
detail_data[:user_prompt] = context.input.to_s.presence
|
|
436
463
|
detail_data[:assistant_prompt] = exec_opts[:assistant_prefill] if assistant_prompt_column_exists?
|
|
437
464
|
end
|
|
438
|
-
detail_data[:error_message] =
|
|
465
|
+
detail_data[:error_message] = build_error_message(context.error) if context.error
|
|
439
466
|
detail_data[:tool_calls] = context[:tool_calls] if context[:tool_calls].present?
|
|
440
467
|
detail_data[:attempts] = context[:reliability_attempts] if context[:reliability_attempts].present?
|
|
441
468
|
if global_config.persist_responses && context.output.respond_to?(:content)
|
|
@@ -474,7 +501,7 @@ module RubyLLM
|
|
|
474
501
|
params = begin
|
|
475
502
|
context.agent_instance.send(:options)
|
|
476
503
|
rescue => e
|
|
477
|
-
debug("Failed to extract agent options: #{e.message}")
|
|
504
|
+
debug("Failed to extract agent options: #{e.message}", context)
|
|
478
505
|
{}
|
|
479
506
|
end
|
|
480
507
|
params = params.dup
|
|
@@ -505,10 +532,38 @@ module RubyLLM
|
|
|
505
532
|
result = context.agent_instance.metadata
|
|
506
533
|
result.is_a?(Hash) ? result : {}
|
|
507
534
|
rescue => e
|
|
508
|
-
debug("Failed to retrieve agent metadata: #{e.message}")
|
|
535
|
+
debug("Failed to retrieve agent metadata: #{e.message}", context)
|
|
509
536
|
{}
|
|
510
537
|
end
|
|
511
538
|
|
|
539
|
+
# Injects tracker request_id and tags into execution data
|
|
540
|
+
#
|
|
541
|
+
# Reads @_track_request_id and @_track_tags from the agent instance,
|
|
542
|
+
# which are set by BaseAgent#initialize when a Tracker is active.
|
|
543
|
+
#
|
|
544
|
+
# @param context [Context] The execution context
|
|
545
|
+
# @param data [Hash] The execution data hash to modify
|
|
546
|
+
def inject_tracker_data(context, data)
|
|
547
|
+
agent = context.agent_instance
|
|
548
|
+
return unless agent
|
|
549
|
+
|
|
550
|
+
# Inject request_id
|
|
551
|
+
track_request_id = agent.instance_variable_get(:@_track_request_id)
|
|
552
|
+
if track_request_id && data[:request_id].blank?
|
|
553
|
+
data[:request_id] = track_request_id
|
|
554
|
+
end
|
|
555
|
+
|
|
556
|
+
# Merge tracker tags into metadata
|
|
557
|
+
track_tags = agent.instance_variable_get(:@_track_tags)
|
|
558
|
+
if track_tags.is_a?(Hash) && track_tags.any?
|
|
559
|
+
data[:metadata] = (data[:metadata] || {}).merge(
|
|
560
|
+
"tags" => track_tags.transform_keys(&:to_s)
|
|
561
|
+
)
|
|
562
|
+
end
|
|
563
|
+
rescue
|
|
564
|
+
# Never let tracker data injection break execution
|
|
565
|
+
end
|
|
566
|
+
|
|
512
567
|
# Sensitive parameter keys that should be redacted
|
|
513
568
|
SENSITIVE_KEYS = %w[
|
|
514
569
|
password token api_key secret credential auth key
|
|
@@ -527,7 +582,7 @@ module RubyLLM
|
|
|
527
582
|
def truncate_error_message(message)
|
|
528
583
|
return "" if message.nil?
|
|
529
584
|
|
|
530
|
-
message.to_s.truncate(
|
|
585
|
+
message.to_s.truncate(5000)
|
|
531
586
|
rescue
|
|
532
587
|
message.to_s[0, 1000]
|
|
533
588
|
end
|
|
@@ -554,7 +609,7 @@ module RubyLLM
|
|
|
554
609
|
|
|
555
610
|
response_data
|
|
556
611
|
rescue => e
|
|
557
|
-
error("Failed to serialize response: #{e.message}")
|
|
612
|
+
error("Failed to serialize response: #{e.message}", context)
|
|
558
613
|
nil
|
|
559
614
|
end
|
|
560
615
|
|
|
@@ -581,7 +636,7 @@ module RubyLLM
|
|
|
581
636
|
|
|
582
637
|
detail_data[:response] = serialize_audio_response(context.output)
|
|
583
638
|
rescue => e
|
|
584
|
-
error("Failed to persist audio response: #{e.message}")
|
|
639
|
+
error("Failed to persist audio response: #{e.message}", context)
|
|
585
640
|
end
|
|
586
641
|
|
|
587
642
|
# Serializes a SpeechResult into a hash for the response column
|
|
@@ -637,7 +692,7 @@ module RubyLLM
|
|
|
637
692
|
cfg.track_executions
|
|
638
693
|
end
|
|
639
694
|
rescue => e
|
|
640
|
-
debug("Failed to check tracking config: #{e.message}")
|
|
695
|
+
debug("Failed to check tracking config: #{e.message}", context)
|
|
641
696
|
false
|
|
642
697
|
end
|
|
643
698
|
|
|
@@ -41,11 +41,13 @@ module RubyLLM
|
|
|
41
41
|
def call(context)
|
|
42
42
|
return @app.call(context) unless reliability_enabled?
|
|
43
43
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
44
|
+
trace(context) do
|
|
45
|
+
config = reliability_config
|
|
46
|
+
models_to_try = build_models_list(context, config)
|
|
47
|
+
total_deadline = calculate_deadline(config)
|
|
47
48
|
|
|
48
|
-
|
|
49
|
+
execute_with_reliability(context, models_to_try, config, total_deadline)
|
|
50
|
+
end
|
|
49
51
|
end
|
|
50
52
|
|
|
51
53
|
private
|
|
@@ -103,7 +105,7 @@ module RubyLLM
|
|
|
103
105
|
# Check circuit breaker for this model
|
|
104
106
|
breaker = get_circuit_breaker(current_model, context)
|
|
105
107
|
if breaker&.open?
|
|
106
|
-
debug("Circuit breaker open for #{current_model}, skipping")
|
|
108
|
+
debug("Circuit breaker open for #{current_model}, skipping", context)
|
|
107
109
|
tracker.record_short_circuit(current_model)
|
|
108
110
|
next
|
|
109
111
|
end
|
|
@@ -41,10 +41,12 @@ module RubyLLM
|
|
|
41
41
|
# @param context [Context] The execution context
|
|
42
42
|
# @return [Context] The context with tenant fields populated
|
|
43
43
|
def call(context)
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
trace(context) do
|
|
45
|
+
resolve_tenant!(context)
|
|
46
|
+
ensure_tenant_record!(context)
|
|
47
|
+
apply_api_configuration!(context)
|
|
48
|
+
@app.call(context)
|
|
49
|
+
end
|
|
48
50
|
end
|
|
49
51
|
|
|
50
52
|
private
|
|
@@ -53,6 +53,17 @@ module RubyLLM
|
|
|
53
53
|
helper RubyLLM::Agents::ApplicationHelper
|
|
54
54
|
before_action :authenticate_dashboard!
|
|
55
55
|
|
|
56
|
+
rescue_from ::ActiveRecord::StatementInvalid do |e|
|
|
57
|
+
if e.message.include?("ruby_llm_agents_")
|
|
58
|
+
render plain: "RubyLLM::Agents migrations are pending.\n\n" \
|
|
59
|
+
"Run: rails db:migrate\n" \
|
|
60
|
+
"Or: rails ruby_llm_agents:doctor",
|
|
61
|
+
status: :service_unavailable
|
|
62
|
+
else
|
|
63
|
+
raise
|
|
64
|
+
end
|
|
65
|
+
end
|
|
66
|
+
|
|
56
67
|
private
|
|
57
68
|
|
|
58
69
|
# Authenticates dashboard access using configured method
|
|
@@ -15,6 +15,8 @@ module RubyLLM
|
|
|
15
15
|
# result.success? # => true
|
|
16
16
|
#
|
|
17
17
|
class BackgroundRemovalResult
|
|
18
|
+
include Trackable
|
|
19
|
+
|
|
18
20
|
attr_reader :foreground, :mask, :source_image, :model_id, :output_format,
|
|
19
21
|
:alpha_matting, :refine_edges,
|
|
20
22
|
:started_at, :completed_at, :tenant_id, :remover_class,
|
|
@@ -38,7 +40,7 @@ module RubyLLM
|
|
|
38
40
|
# @param error_message [String, nil] Error message if failed
|
|
39
41
|
def initialize(foreground:, mask:, source_image:, model_id:, output_format:,
|
|
40
42
|
alpha_matting:, refine_edges:, started_at:, completed_at:,
|
|
41
|
-
tenant_id:, remover_class:, error_class: nil, error_message: nil)
|
|
43
|
+
tenant_id:, remover_class:, error_class: nil, error_message: nil, agent_class_name: nil)
|
|
42
44
|
@foreground = foreground
|
|
43
45
|
@mask = mask
|
|
44
46
|
@source_image = source_image
|
|
@@ -53,6 +55,10 @@ module RubyLLM
|
|
|
53
55
|
@error_class = error_class
|
|
54
56
|
@error_message = error_message
|
|
55
57
|
@execution_id = nil
|
|
58
|
+
|
|
59
|
+
# Tracking
|
|
60
|
+
@agent_class_name = agent_class_name
|
|
61
|
+
register_with_tracker
|
|
56
62
|
end
|
|
57
63
|
|
|
58
64
|
# Loads the associated Execution record from the database
|
|
@@ -107,6 +107,21 @@ module RubyLLM
|
|
|
107
107
|
# @return [Integer, nil] Database ID of the associated Execution record
|
|
108
108
|
attr_reader :execution_id
|
|
109
109
|
|
|
110
|
+
# @!group Tracking
|
|
111
|
+
# @!attribute [r] agent_class_name
|
|
112
|
+
# @return [String, nil] The agent class that produced this result
|
|
113
|
+
attr_reader :agent_class_name
|
|
114
|
+
|
|
115
|
+
# @!group Cancellation
|
|
116
|
+
# @!attribute [r] cancelled
|
|
117
|
+
# @return [Boolean] Whether the execution was cancelled
|
|
118
|
+
attr_reader :cancelled
|
|
119
|
+
|
|
120
|
+
# @!group Debug
|
|
121
|
+
# @!attribute [r] trace
|
|
122
|
+
# @return [Array<Hash>, nil] Pipeline trace entries (when debug: true)
|
|
123
|
+
attr_reader :trace
|
|
124
|
+
|
|
110
125
|
# Creates a new Result instance
|
|
111
126
|
#
|
|
112
127
|
# @param content [Hash, String] The processed response content
|
|
@@ -159,6 +174,19 @@ module RubyLLM
|
|
|
159
174
|
|
|
160
175
|
# Execution record
|
|
161
176
|
@execution_id = options[:execution_id]
|
|
177
|
+
|
|
178
|
+
# Tracking
|
|
179
|
+
@agent_class_name = options[:agent_class_name]
|
|
180
|
+
|
|
181
|
+
# Cancellation
|
|
182
|
+
@cancelled = options[:cancelled] || false
|
|
183
|
+
|
|
184
|
+
# Debug trace
|
|
185
|
+
@trace = options[:trace]
|
|
186
|
+
|
|
187
|
+
# Register with active tracker
|
|
188
|
+
tracker = Thread.current[:ruby_llm_agents_tracker]
|
|
189
|
+
tracker << self if tracker
|
|
162
190
|
end
|
|
163
191
|
|
|
164
192
|
# Loads the associated Execution record from the database
|
|
@@ -202,6 +230,13 @@ module RubyLLM
|
|
|
202
230
|
!success?
|
|
203
231
|
end
|
|
204
232
|
|
|
233
|
+
# Returns whether the execution was cancelled
|
|
234
|
+
#
|
|
235
|
+
# @return [Boolean] true if cancelled
|
|
236
|
+
def cancelled?
|
|
237
|
+
cancelled == true
|
|
238
|
+
end
|
|
239
|
+
|
|
205
240
|
# Returns whether a fallback model was used
|
|
206
241
|
#
|
|
207
242
|
# @return [Boolean] true if chosen_model_id differs from model_id
|
|
@@ -264,8 +299,10 @@ module RubyLLM
|
|
|
264
299
|
thinking_text: thinking_text,
|
|
265
300
|
thinking_signature: thinking_signature,
|
|
266
301
|
thinking_tokens: thinking_tokens,
|
|
267
|
-
execution_id: execution_id
|
|
268
|
-
|
|
302
|
+
execution_id: execution_id,
|
|
303
|
+
agent_class_name: agent_class_name,
|
|
304
|
+
trace: trace
|
|
305
|
+
}.compact
|
|
269
306
|
end
|
|
270
307
|
|
|
271
308
|
# @!group Deprecated Hash Delegation
|
|
@@ -25,6 +25,8 @@ module RubyLLM
|
|
|
25
25
|
#
|
|
26
26
|
# @api public
|
|
27
27
|
class EmbeddingResult
|
|
28
|
+
include Trackable
|
|
29
|
+
|
|
28
30
|
# @!attribute [r] vectors
|
|
29
31
|
# @return [Array<Array<Float>>] The embedding vectors
|
|
30
32
|
attr_reader :vectors
|
|
@@ -106,6 +108,8 @@ module RubyLLM
|
|
|
106
108
|
@error_class = attributes[:error_class]
|
|
107
109
|
@error_message = attributes[:error_message]
|
|
108
110
|
@execution_id = attributes[:execution_id]
|
|
111
|
+
@agent_class_name = attributes[:agent_class_name]
|
|
112
|
+
register_with_tracker
|
|
109
113
|
end
|
|
110
114
|
|
|
111
115
|
# Loads the associated Execution record from the database
|
|
@@ -17,6 +17,8 @@ module RubyLLM
|
|
|
17
17
|
# result.success? # => true
|
|
18
18
|
#
|
|
19
19
|
class ImageAnalysisResult
|
|
20
|
+
include Trackable
|
|
21
|
+
|
|
20
22
|
attr_reader :image, :model_id, :analysis_type,
|
|
21
23
|
:caption, :description, :tags, :objects, :colors, :text,
|
|
22
24
|
:raw_response, :started_at, :completed_at, :tenant_id, :analyzer_class,
|
|
@@ -43,7 +45,7 @@ module RubyLLM
|
|
|
43
45
|
# @param error_message [String, nil] Error message if failed
|
|
44
46
|
def initialize(image:, model_id:, analysis_type:, caption:, description:, tags:,
|
|
45
47
|
objects:, colors:, text:, raw_response:, started_at:, completed_at:,
|
|
46
|
-
tenant_id:, analyzer_class:, error_class: nil, error_message: nil)
|
|
48
|
+
tenant_id:, analyzer_class:, error_class: nil, error_message: nil, agent_class_name: nil)
|
|
47
49
|
@image = image
|
|
48
50
|
@model_id = model_id
|
|
49
51
|
@analysis_type = analysis_type
|
|
@@ -61,6 +63,10 @@ module RubyLLM
|
|
|
61
63
|
@error_class = error_class
|
|
62
64
|
@error_message = error_message
|
|
63
65
|
@execution_id = nil
|
|
66
|
+
|
|
67
|
+
# Tracking
|
|
68
|
+
@agent_class_name = agent_class_name
|
|
69
|
+
register_with_tracker
|
|
64
70
|
end
|
|
65
71
|
|
|
66
72
|
# Loads the associated Execution record from the database
|
|
@@ -17,6 +17,8 @@ module RubyLLM
|
|
|
17
17
|
# result.success? # => true
|
|
18
18
|
#
|
|
19
19
|
class ImageEditResult
|
|
20
|
+
include Trackable
|
|
21
|
+
|
|
20
22
|
attr_reader :images, :source_image, :mask, :prompt, :model_id, :size,
|
|
21
23
|
:started_at, :completed_at, :tenant_id, :editor_class,
|
|
22
24
|
:error_class, :error_message
|
|
@@ -38,7 +40,7 @@ module RubyLLM
|
|
|
38
40
|
# @param error_message [String, nil] Error message if failed
|
|
39
41
|
def initialize(images:, source_image:, mask:, prompt:, model_id:, size:,
|
|
40
42
|
started_at:, completed_at:, tenant_id:, editor_class:,
|
|
41
|
-
error_class: nil, error_message: nil)
|
|
43
|
+
error_class: nil, error_message: nil, agent_class_name: nil)
|
|
42
44
|
@images = images
|
|
43
45
|
@source_image = source_image
|
|
44
46
|
@mask = mask
|
|
@@ -52,6 +54,10 @@ module RubyLLM
|
|
|
52
54
|
@error_class = error_class
|
|
53
55
|
@error_message = error_message
|
|
54
56
|
@execution_id = nil
|
|
57
|
+
|
|
58
|
+
# Tracking
|
|
59
|
+
@agent_class_name = agent_class_name
|
|
60
|
+
register_with_tracker
|
|
55
61
|
end
|
|
56
62
|
|
|
57
63
|
# Loads the associated Execution record from the database
|
|
@@ -20,6 +20,8 @@ module RubyLLM
|
|
|
20
20
|
# result.save_all("./logos")
|
|
21
21
|
#
|
|
22
22
|
class ImageGenerationResult
|
|
23
|
+
include Trackable
|
|
24
|
+
|
|
23
25
|
attr_reader :images, :prompt, :model_id, :size, :quality, :style,
|
|
24
26
|
:started_at, :completed_at, :tenant_id, :generator_class,
|
|
25
27
|
:error_class, :error_message, :execution_id
|
|
@@ -40,7 +42,7 @@ module RubyLLM
|
|
|
40
42
|
# @param error_message [String, nil] Error message if failed
|
|
41
43
|
def initialize(images:, prompt:, model_id:, size:, quality:, style:,
|
|
42
44
|
started_at:, completed_at:, tenant_id:, generator_class:,
|
|
43
|
-
error_class: nil, error_message: nil, execution_id: nil)
|
|
45
|
+
error_class: nil, error_message: nil, execution_id: nil, agent_class_name: nil)
|
|
44
46
|
@images = images
|
|
45
47
|
@prompt = prompt
|
|
46
48
|
@model_id = model_id
|
|
@@ -54,6 +56,10 @@ module RubyLLM
|
|
|
54
56
|
@error_class = error_class
|
|
55
57
|
@error_message = error_message
|
|
56
58
|
@execution_id = execution_id
|
|
59
|
+
|
|
60
|
+
# Tracking
|
|
61
|
+
@agent_class_name = agent_class_name
|
|
62
|
+
register_with_tracker
|
|
57
63
|
end
|
|
58
64
|
|
|
59
65
|
# Loads the associated Execution record from the database
|
|
@@ -21,6 +21,8 @@ module RubyLLM
|
|
|
21
21
|
# result.analysis # => Shortcut to analyzer step result
|
|
22
22
|
#
|
|
23
23
|
class ImagePipelineResult
|
|
24
|
+
include Trackable
|
|
25
|
+
|
|
24
26
|
attr_reader :step_results, :started_at, :completed_at, :tenant_id,
|
|
25
27
|
:pipeline_class, :context, :error_class, :error_message
|
|
26
28
|
attr_accessor :execution_id
|
|
@@ -36,7 +38,7 @@ module RubyLLM
|
|
|
36
38
|
# @param error_class [String, nil] Error class name if failed
|
|
37
39
|
# @param error_message [String, nil] Error message if failed
|
|
38
40
|
def initialize(step_results:, started_at:, completed_at:, tenant_id:,
|
|
39
|
-
pipeline_class:, context:, error_class: nil, error_message: nil)
|
|
41
|
+
pipeline_class:, context:, error_class: nil, error_message: nil, agent_class_name: nil)
|
|
40
42
|
@step_results = step_results
|
|
41
43
|
@started_at = started_at
|
|
42
44
|
@completed_at = completed_at
|
|
@@ -46,6 +48,10 @@ module RubyLLM
|
|
|
46
48
|
@error_class = error_class
|
|
47
49
|
@error_message = error_message
|
|
48
50
|
@execution_id = nil
|
|
51
|
+
|
|
52
|
+
# Tracking
|
|
53
|
+
@agent_class_name = agent_class_name
|
|
54
|
+
register_with_tracker
|
|
49
55
|
end
|
|
50
56
|
|
|
51
57
|
# Loads the associated Execution record from the database
|
|
@@ -17,6 +17,8 @@ module RubyLLM
|
|
|
17
17
|
# result.success? # => true
|
|
18
18
|
#
|
|
19
19
|
class ImageTransformResult
|
|
20
|
+
include Trackable
|
|
21
|
+
|
|
20
22
|
attr_reader :images, :source_image, :prompt, :model_id, :size, :strength,
|
|
21
23
|
:started_at, :completed_at, :tenant_id, :transformer_class,
|
|
22
24
|
:error_class, :error_message
|
|
@@ -38,7 +40,7 @@ module RubyLLM
|
|
|
38
40
|
# @param error_message [String, nil] Error message if failed
|
|
39
41
|
def initialize(images:, source_image:, prompt:, model_id:, size:, strength:,
|
|
40
42
|
started_at:, completed_at:, tenant_id:, transformer_class:,
|
|
41
|
-
error_class: nil, error_message: nil)
|
|
43
|
+
error_class: nil, error_message: nil, agent_class_name: nil)
|
|
42
44
|
@images = images
|
|
43
45
|
@source_image = source_image
|
|
44
46
|
@prompt = prompt
|
|
@@ -52,6 +54,10 @@ module RubyLLM
|
|
|
52
54
|
@error_class = error_class
|
|
53
55
|
@error_message = error_message
|
|
54
56
|
@execution_id = nil
|
|
57
|
+
|
|
58
|
+
# Tracking
|
|
59
|
+
@agent_class_name = agent_class_name
|
|
60
|
+
register_with_tracker
|
|
55
61
|
end
|
|
56
62
|
|
|
57
63
|
# Loads the associated Execution record from the database
|
|
@@ -15,6 +15,8 @@ module RubyLLM
|
|
|
15
15
|
# result.success? # => true
|
|
16
16
|
#
|
|
17
17
|
class ImageUpscaleResult
|
|
18
|
+
include Trackable
|
|
19
|
+
|
|
18
20
|
attr_reader :image, :source_image, :model_id, :scale, :output_size, :face_enhance,
|
|
19
21
|
:started_at, :completed_at, :tenant_id, :upscaler_class,
|
|
20
22
|
:error_class, :error_message
|
|
@@ -36,7 +38,7 @@ module RubyLLM
|
|
|
36
38
|
# @param error_message [String, nil] Error message if failed
|
|
37
39
|
def initialize(image:, source_image:, model_id:, scale:, output_size:, face_enhance:,
|
|
38
40
|
started_at:, completed_at:, tenant_id:, upscaler_class:,
|
|
39
|
-
error_class: nil, error_message: nil)
|
|
41
|
+
error_class: nil, error_message: nil, agent_class_name: nil)
|
|
40
42
|
@image = image
|
|
41
43
|
@source_image = source_image
|
|
42
44
|
@model_id = model_id
|
|
@@ -50,6 +52,10 @@ module RubyLLM
|
|
|
50
52
|
@error_class = error_class
|
|
51
53
|
@error_message = error_message
|
|
52
54
|
@execution_id = nil
|
|
55
|
+
|
|
56
|
+
# Tracking
|
|
57
|
+
@agent_class_name = agent_class_name
|
|
58
|
+
register_with_tracker
|
|
53
59
|
end
|
|
54
60
|
|
|
55
61
|
# Loads the associated Execution record from the database
|
|
@@ -14,6 +14,8 @@ module RubyLLM
|
|
|
14
14
|
# result.success? # => true
|
|
15
15
|
#
|
|
16
16
|
class ImageVariationResult
|
|
17
|
+
include Trackable
|
|
18
|
+
|
|
17
19
|
attr_reader :images, :source_image, :model_id, :size, :variation_strength,
|
|
18
20
|
:started_at, :completed_at, :tenant_id, :variator_class,
|
|
19
21
|
:error_class, :error_message
|
|
@@ -34,7 +36,7 @@ module RubyLLM
|
|
|
34
36
|
# @param error_message [String, nil] Error message if failed
|
|
35
37
|
def initialize(images:, source_image:, model_id:, size:, variation_strength:,
|
|
36
38
|
started_at:, completed_at:, tenant_id:, variator_class:,
|
|
37
|
-
error_class: nil, error_message: nil)
|
|
39
|
+
error_class: nil, error_message: nil, agent_class_name: nil)
|
|
38
40
|
@images = images
|
|
39
41
|
@source_image = source_image
|
|
40
42
|
@model_id = model_id
|
|
@@ -47,6 +49,10 @@ module RubyLLM
|
|
|
47
49
|
@error_class = error_class
|
|
48
50
|
@error_message = error_message
|
|
49
51
|
@execution_id = nil
|
|
52
|
+
|
|
53
|
+
# Tracking
|
|
54
|
+
@agent_class_name = agent_class_name
|
|
55
|
+
register_with_tracker
|
|
50
56
|
end
|
|
51
57
|
|
|
52
58
|
# Loads the associated Execution record from the database
|