Skip to main content

AnthropicProvider

Struct AnthropicProvider 

Source
pub struct AnthropicProvider { /* private fields */ }
Expand description

Built-in provider for the Anthropic Messages API.

Requires the anthropic feature flag.

§Example

use llm_agent_runtime::providers::AnthropicProvider;
let provider = AnthropicProvider::new("sk-ant-...");

Implementations§

Source§

impl AnthropicProvider

Source

pub fn new(api_key: impl Into<String>) -> Self

Create a new Anthropic provider with the given API key.

Source

pub fn with_base_url( api_key: impl Into<String>, api_url: impl Into<String>, ) -> Self

Create a provider pointing to a custom API endpoint.

Useful for testing against a mock server or routing through a proxy.

Source

pub fn with_max_concurrent_streams( api_key: impl Into<String>, max: usize, ) -> Self

Create a provider with a custom limit on concurrent streaming tasks.

Useful when many agents share a single provider and you want to cap the number of simultaneous SSE parse tasks.

Source

pub fn with_stream_max_tokens(self, max_tokens: u32) -> Self

Set the maximum output tokens used by stream_complete.

By default stream_complete uses the hard-coded MAX_TOKENS constant (1024). Call this method to override that value, e.g. when a task requires longer streamed responses.

Trait Implementations§

Source§

impl LlmProvider for AnthropicProvider

Source§

fn complete_with_options<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, prompt: &'life1 str, options: CompletionOptions<'life2>, ) -> Pin<Box<dyn Future<Output = Result<String, AgentRuntimeError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Complete with per-request options (max_tokens, temperature).

Falls back to Self::MAX_TOKENS when options.max_tokens is not set.

Source§

fn stream_complete<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, prompt: &'life1 str, model: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<Receiver<Result<String, AgentRuntimeError>>, AgentRuntimeError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Stream the completion token-by-token using chunk() for true streaming.

Uses response.chunk() to consume the SSE body incrementally so tokens are emitted as they arrive rather than after the entire response has been buffered, fixing the original bytes().await implementation.

Source§

fn complete<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, prompt: &'life1 str, model: &'life2 str, ) -> Pin<Box<dyn Future<Output = Result<String, AgentRuntimeError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Send a prompt to the model and return the completion text. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more