Class: Phronomy::LLMAdapter::Base
- Inherits:
-
Object
- Object
- Phronomy::LLMAdapter::Base
- Defined in:
- lib/phronomy/llm_adapter/base.rb
Overview
Beta extension SPI for LLM call adapters.
External adapters implement #complete and #stream. The adapter or the underlying provider client owns transport timeout, retry, backoff, and rate-limit behavior. Phronomy owns cooperative cancellation and isolates synchronous provider calls in OffloadPool.
The Agent pipeline calls the framework-owned #complete_async and #stream_async wrappers. Adapter implementers do not need to depend on EventLoop, FSMSession, OffloadPool, AgentInvocation, or ExecutionCoordinator.
The current input to this SPI is the configured/materialized chat runtime object. Formalizing this SPI therefore does not imply a provider-neutral replacement for RubyLLMMaterializer.
Direct Known Subclasses
Instance Method Summary collapse
-
#complete(chat, message, config: {}) ⇒ Object
Performs a blocking (non-streaming) LLM completion.
-
#complete_async(chat, message, config: {}, pool: default_pool) ⇒ Phronomy::Task
private
Submits a non-streaming LLM call to OffloadPool.
-
#stream(chat, message, config: {}) {|chunk| ... } ⇒ Object
Performs a blocking streaming LLM completion.
-
#stream_async(chat, message, config: {}, pool: default_pool) {|chunk| ... } ⇒ Phronomy::Task
private
Submits a streaming LLM call to OffloadPool.
Instance Method Details
#complete(chat, message, config: {}) ⇒ Object
Performs a blocking (non-streaming) LLM completion.
Implementors call the configured chat/runtime client and return its response object. Transport/retry policy remains adapter-owned.
33 34 35 |
# File 'lib/phronomy/llm_adapter/base.rb', line 33 def complete(chat, , config: {}) raise NotImplementedError, "#{self.class}#complete is not implemented" end |
#complete_async(chat, message, config: {}, pool: default_pool) ⇒ Phronomy::Task
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Submits a non-streaming LLM call to OffloadPool.
Transport timeout and retry remain the responsibility of the adapter or provider client; Phronomy does not attach an additional operation timeout.
57 58 59 60 61 62 |
# File 'lib/phronomy/llm_adapter/base.rb', line 57 def complete_async(chat, , config: {}, pool: default_pool) token = config[:cancellation_token] pool.submit(cancellation_token: token, on_full: :raise) do complete(chat, , config: config) end end |
#stream(chat, message, config: {}) {|chunk| ... } ⇒ Object
Performs a blocking streaming LLM completion.
46 47 48 |
# File 'lib/phronomy/llm_adapter/base.rb', line 46 def stream(chat, , config: {}, &block) raise NotImplementedError, "#{self.class}#stream is not implemented" end |
#stream_async(chat, message, config: {}, pool: default_pool) {|chunk| ... } ⇒ Phronomy::Task
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Submits a streaming LLM call to OffloadPool.
The block is invoked on an OffloadPool worker thread. Agent code must pass only a lightweight internal sink that posts a value to EventLoop; application callbacks must never be passed directly to this method.
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/phronomy/llm_adapter/base.rb', line 73 def stream_async(chat, , config: {}, pool: default_pool, &block) raise ArgumentError, "stream_async requires a block" unless block token = config[:cancellation_token] pool.submit(cancellation_token: token, on_full: :raise) do stream(chat, , config: config) do |chunk| token&.raise_if_cancelled!("invocation cancelled during streaming") block.call(chunk) end end end |