pub struct BoxedProvider(/* private fields */);Expand description
Type-erased LLM provider for use when dynamic dispatch is needed.
Wraps any LlmProvider behind Box<dyn DynLlmProvider>. Implements
LlmProvider itself, so it can be used with AgentRunner<BoxedProvider>
and Orchestrator<BoxedProvider>, eliminating the need for generic code
at the call site.
§Example
ⓘ
let provider = BoxedProvider::new(AnthropicProvider::new(key, model));
let runner = AgentRunner::builder(Arc::new(provider))
.name("agent")
.build()?;Implementations§
Source§impl BoxedProvider
impl BoxedProvider
Sourcepub fn new<P: LlmProvider + 'static>(provider: P) -> Self
pub fn new<P: LlmProvider + 'static>(provider: P) -> Self
Create a type-erased provider from any concrete LlmProvider.
Sourcepub fn from_arc<P: LlmProvider + 'static>(provider: Arc<P>) -> Self
pub fn from_arc<P: LlmProvider + 'static>(provider: Arc<P>) -> Self
Create a type-erased provider from an Arc<P>.
Useful when the provider is already behind an Arc (e.g., shared between
the orchestrator and sub-agents) and needs to be converted to BoxedProvider
for type erasure without consuming the original.
Trait Implementations§
Source§impl LlmProvider for BoxedProvider
impl LlmProvider for BoxedProvider
Source§async fn complete(
&self,
request: CompletionRequest,
) -> Result<CompletionResponse, Error>
async fn complete( &self, request: CompletionRequest, ) -> Result<CompletionResponse, Error>
Send a completion request and wait for the full response.
Source§async fn stream_complete(
&self,
request: CompletionRequest,
on_text: &OnText,
) -> Result<CompletionResponse, Error>
async fn stream_complete( &self, request: CompletionRequest, on_text: &OnText, ) -> Result<CompletionResponse, Error>
Stream a completion, calling
on_text for each text delta as it arrives. Read moreAuto Trait Implementations§
impl Freeze for BoxedProvider
impl !RefUnwindSafe for BoxedProvider
impl Send for BoxedProvider
impl Sync for BoxedProvider
impl Unpin for BoxedProvider
impl UnsafeUnpin for BoxedProvider
impl !UnwindSafe for BoxedProvider
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<P> DynLlmProvider for Pwhere
P: LlmProvider,
impl<P> DynLlmProvider for Pwhere
P: LlmProvider,
Source§fn complete<'a>(
&'a self,
request: CompletionRequest,
) -> Pin<Box<dyn Future<Output = Result<CompletionResponse, Error>> + Send + 'a>>
fn complete<'a>( &'a self, request: CompletionRequest, ) -> Pin<Box<dyn Future<Output = Result<CompletionResponse, Error>> + Send + 'a>>
Boxed-future version of
LlmProvider::complete for object-safe dispatch.Source§fn stream_complete<'a>(
&'a self,
request: CompletionRequest,
on_text: &'a (dyn Fn(&str) + Sync + Send + 'static),
) -> Pin<Box<dyn Future<Output = Result<CompletionResponse, Error>> + Send + 'a>>
fn stream_complete<'a>( &'a self, request: CompletionRequest, on_text: &'a (dyn Fn(&str) + Sync + Send + 'static), ) -> Pin<Box<dyn Future<Output = Result<CompletionResponse, Error>> + Send + 'a>>
Boxed-future version of
LlmProvider::stream_complete for object-safe dispatch.Source§fn model_name(&self) -> Option<&str>
fn model_name(&self) -> Option<&str>
Return the model identifier, if known.