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
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.
97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/active_agent/providers/_base_provider.rb', line 97 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.
86 87 88 |
# File 'lib/active_agent/providers/_base_provider.rb', line 86 def self. fail(NotImplementedError) end |
.namespace ⇒ Module
Returns e.g., ActiveAgent::Providers::OpenAI.
70 71 72 |
# File 'lib/active_agent/providers/_base_provider.rb', line 70 def self.namespace "#{name.deconstantize}::#{service_name}".safe_constantize end |
.options_klass ⇒ Class
75 76 77 |
# File 'lib/active_agent/providers/_base_provider.rb', line 75 def self. namespace::Options end |
.prompt_request_type ⇒ ActiveModel::Type::Value
Returns for prompt casting/serialization.
80 81 82 |
# File 'lib/active_agent/providers/_base_provider.rb', line 80 def self.prompt_request_type namespace::RequestType.new end |
.service_name ⇒ String
Returns e.g., “Anthropic”, “OpenAI”.
60 61 62 |
# File 'lib/active_agent/providers/_base_provider.rb', line 60 def self.service_name name.split("::").last.delete_suffix("Provider") end |
.tag_name ⇒ String
Returns e.g., “Anthropic”, “OpenAI::Chat”.
65 66 67 |
# File 'lib/active_agent/providers/_base_provider.rb', line 65 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.
139 140 141 142 143 144 145 146 147 148 |
# File 'lib/active_agent/providers/_base_provider.rb', line 139 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.
117 118 119 120 |
# File 'lib/active_agent/providers/_base_provider.rb', line 117 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.
125 126 127 128 129 130 131 132 133 134 |
# File 'lib/active_agent/providers/_base_provider.rb', line 125 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 |