Struct ClientBuilder

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

Builder for creating Client instances with fluent configuration

The ClientBuilder provides a convenient way to construct client instances using the builder pattern. All methods are chainable and return self for fluent composition.

§Examples

let client = Client::builder()
    .model("claude-3-sonnet-20240229")
    .system_prompt("You are a helpful assistant")
    .stream_format(StreamFormat::Json)
    .timeout_secs(60)
    .build();

Implementations§

Source§

impl ClientBuilder

Source

pub fn new() -> Self

Create a new client builder with default configuration

Source

pub fn config(self, config: Config) -> Self

Set the configuration directly

This allows you to use a pre-built Config instance instead of configuring individual options.

Source

pub fn system_prompt(self, prompt: impl Into<String>) -> Self

Set the system prompt for the assistant

§Examples
let client = Client::builder()
    .system_prompt("You are a Rust expert")
    .build();
Source

pub fn model(self, model: impl Into<String>) -> Self

Set the Claude model to use

§Examples
let client = Client::builder()
    .model("claude-3-opus-20240229")
    .build();
Source

pub fn allowed_tools(self, tools: Vec<String>) -> Self

Set the list of allowed tools

§Examples
let client = Client::builder()
    .allowed_tools(vec!["bash".to_string(), "filesystem".to_string()])
    .build();
Source

pub fn stream_format(self, format: StreamFormat) -> Self

Set the output format for responses

§Examples
let client = Client::builder()
    .stream_format(StreamFormat::Json)
    .build();
Source

pub fn verbose(self, verbose: bool) -> Self

Enable or disable verbose output

§Examples
let client = Client::builder()
    .verbose(true)
    .build();
Source

pub fn timeout_secs(self, timeout_secs: u64) -> Self

Set the timeout in seconds

§Examples
let client = Client::builder()
    .timeout_secs(120)  // 2 minute timeout
    .build();
Source

pub fn continue_session(self) -> Self

Enable session continuation (–continue flag)

When enabled, the client will use the –continue flag to resume the most recent conversation session.

§Examples
let client = Client::builder()
    .continue_session()
    .build();
Source

pub fn resume_session(self, session_id: impl Into<String>) -> Self

Resume a specific session by ID (–resume flag)

When set, the client will use the –resume flag with the specified session ID to continue a specific conversation session.

§Examples
let client = Client::builder()
    .resume_session("session_123")
    .build();
Source

pub fn disallowed_tools(self, tools: Vec<String>) -> Self

Set the list of disallowed tools

Controls which tools Claude cannot access during execution. Provides fine-grained control over tool restrictions.

§Examples
let client = Client::builder()
    .disallowed_tools(vec!["bash".to_string(), "filesystem".to_string()])
    .build();
Source

pub fn skip_permissions(self, skip: bool) -> Self

Set whether to skip permission prompts (default: true)

When true (default), adds the --dangerously-skip-permissions flag to bypass tool permission prompts. Set to false for additional security.

§Examples
let client = Client::builder()
    .skip_permissions(false)  // Require permission prompts
    .build();
Source

pub fn append_system_prompt(self, prompt: impl Into<String>) -> Self

Set an additional system prompt to append

When set, adds the --append-system-prompt flag to extend the existing system prompt. Cannot be used with system_prompt.

§Examples
let client = Client::builder()
    .append_system_prompt("Additionally, be concise in your responses.")
    .build();
Source

pub fn max_turns(self, turns: u32) -> Self

Set the maximum number of conversation turns

Limits the conversation to the specified number of back-and-forth exchanges. Useful for controlling conversation length.

§Examples
let client = Client::builder()
    .max_turns(10)
    .build();
Source

pub fn security_level(self, level: SecurityLevel) -> Self

Set the security validation level

Controls how strictly user input is validated for potential security threats.

§Examples
let client = Client::builder()
    .security_level(SecurityLevel::Relaxed)  // Allow more flexible input
    .build();
Source

pub fn build(self) -> Result<Client>

Build the final client instance

§Examples
let client = Client::builder()
    .model("claude-3-sonnet-20240229")
    .stream_format(StreamFormat::Json)
    .build()
    .expect("valid configuration");
§Errors

Returns an error if the configuration is invalid

Trait Implementations§

Source§

impl Default for ClientBuilder

Source§

fn default() -> Self

Returns the “default value” for a type. 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.

Source§

impl<T> Instrument for T

Source§

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

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

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.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. 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.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

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
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

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