Class: ActiveAgent::Providers::BaseProvider Abstract
- Inherits:
-
Object
- Object
- ActiveAgent::Providers::BaseProvider
- Extended by:
- ActiveSupport::Delegation
- Includes:
- ExceptionHandler, Instrumentation, Previewable, ToolChoiceClearing
- Defined in:
- lib/active_agent/providers/_base_provider.rb
Overview
Subclasses must implement #api_prompt_execute, #process_stream_chunk, #process_prompt_finished_extract_messages, and #process_prompt_finished_extract_function_calls
Orchestrates LLM provider API requests, streaming, and multi-turn tool calling.
Each provider (OpenAI, Anthropic, etc.) subclasses this to implement provider-specific API interactions.
Direct Known Subclasses
AnthropicProvider, MockProvider, OpenAI::Base, RubyLLMProvider
Defined Under Namespace
Classes: ProvidersError
Class Method Summary collapse
-
.embed_request_type ⇒ ActiveModel::Type::Value
For embedding casting/serialization.
-
.namespace ⇒ Module
E.g., ActiveAgent::Providers::OpenAI.
- .options_klass ⇒ Class
-
.prompt_request_type ⇒ ActiveModel::Type::Value
For prompt casting/serialization.
-
.service_name ⇒ String
E.g., “Anthropic”, “OpenAI”.
-
.tag_name ⇒ String
E.g., “Anthropic”, “OpenAI::Chat”.
Instance Method Summary collapse
-
#embed ⇒ ActiveAgent::Providers::Common::EmbedResponse
Executes embedding request with error handling and instrumentation.
-
#initialize(kwargs = {}) ⇒ BaseProvider
constructor
A new instance of BaseProvider.
-
#preview ⇒ String
Generates prompt preview without executing the API call.
-
#prompt ⇒ ActiveAgent::Providers::Common::PromptResponse
Executes prompt request with error handling and instrumentation.
Methods included from ToolChoiceClearing
Methods included from Previewable
Methods included from Instrumentation
#instrumentation_prompt_payload
Methods included from ExceptionHandler
#configure_exception_handler, #rescue_with_handler, #with_exception_handling
Constructor Details
#initialize(kwargs = {}) ⇒ BaseProvider
Returns a new instance of BaseProvider.
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/active_agent/providers/_base_provider.rb', line 98 def initialize(kwargs = {}) assert_service!(kwargs.delete(:service)) configure_exception_handler( exception_handler: kwargs.delete(:exception_handler) ) self.trace_id = kwargs[:trace_id] self.stream_broadcaster = kwargs.delete(:stream_broadcaster) self.streaming = false self.tools_function = kwargs.delete(:tools_function) self. = .new(kwargs.extract!(*.keys)) self.context = kwargs self. = [] self.usage_stack = [] end |
Class Method Details
.embed_request_type ⇒ ActiveModel::Type::Value
Returns for embedding casting/serialization.
87 88 89 |
# File 'lib/active_agent/providers/_base_provider.rb', line 87 def self. fail(NotImplementedError) end |
.namespace ⇒ Module
Returns e.g., ActiveAgent::Providers::OpenAI.
71 72 73 |
# File 'lib/active_agent/providers/_base_provider.rb', line 71 def self.namespace "#{name.deconstantize}::#{service_name}".safe_constantize end |
.options_klass ⇒ Class
76 77 78 |
# File 'lib/active_agent/providers/_base_provider.rb', line 76 def self. namespace::Options end |
.prompt_request_type ⇒ ActiveModel::Type::Value
Returns for prompt casting/serialization.
81 82 83 |
# File 'lib/active_agent/providers/_base_provider.rb', line 81 def self.prompt_request_type namespace::RequestType.new end |
.service_name ⇒ String
Returns e.g., “Anthropic”, “OpenAI”.
61 62 63 |
# File 'lib/active_agent/providers/_base_provider.rb', line 61 def self.service_name name.split("::").last.delete_suffix("Provider") end |
.tag_name ⇒ String
Returns e.g., “Anthropic”, “OpenAI::Chat”.
66 67 68 |
# File 'lib/active_agent/providers/_base_provider.rb', line 66 def self.tag_name name.delete_prefix("ActiveAgent::Providers::").delete_suffix("Provider") end |
Instance Method Details
#embed ⇒ ActiveAgent::Providers::Common::EmbedResponse
Executes embedding request with error handling and instrumentation.
140 141 142 143 144 145 146 147 148 149 |
# File 'lib/active_agent/providers/_base_provider.rb', line 140 def self.request = .cast(context.except(:trace_id)) instrument("embed.active_agent") do |payload| response = (payload, request, response) response end end |
#preview ⇒ String
Generates prompt preview without executing the API call.
118 119 120 121 |
# File 'lib/active_agent/providers/_base_provider.rb', line 118 def preview self.request = prompt_request_type.cast(context.except(:trace_id)) preview_prompt end |
#prompt ⇒ ActiveAgent::Providers::Common::PromptResponse
Executes prompt request with error handling and instrumentation.
126 127 128 129 130 131 132 133 134 135 |
# File 'lib/active_agent/providers/_base_provider.rb', line 126 def prompt self.request = prompt_request_type.cast(context.except(:trace_id)) instrument("prompt.active_agent") do |payload| response = resolve_prompt instrumentation_prompt_payload(payload, request, response) response end end |