pub struct AgentBuilder<M>where
M: CompletionModel,{ /* private fields */ }
Expand description
A builder for creating an agent
§Example
use rig::{providers::openai, agent::AgentBuilder};
let openai = openai::Client::from_env();
let gpt4o = openai.completion_model("gpt-4o");
// Configure the agent
let agent = AgentBuilder::new(model)
.preamble("System prompt")
.context("Context document 1")
.context("Context document 2")
.tool(tool1)
.tool(tool2)
.temperature(0.8)
.additional_params(json!({"foo": "bar"}))
.build();
Implementations§
Source§impl<M> AgentBuilder<M>where
M: CompletionModel,
impl<M> AgentBuilder<M>where
M: CompletionModel,
pub fn new(model: M) -> Self
Sourcepub fn without_preamble(self) -> Self
pub fn without_preamble(self) -> Self
Remove the system prompt
Sourcepub fn append_preamble(self, doc: &str) -> Self
pub fn append_preamble(self, doc: &str) -> Self
Append to the preamble of the agent
pub fn rmcp_tool(self, tool: Tool, client: ServerSink) -> Self
Available on crate feature
rmcp
only.Sourcepub fn dynamic_context(
self,
sample: usize,
dynamic_context: impl VectorStoreIndexDyn + 'static,
) -> Self
pub fn dynamic_context( self, sample: usize, dynamic_context: impl VectorStoreIndexDyn + 'static, ) -> Self
Add some dynamic context to the agent. On each prompt, sample
documents from the
dynamic context will be inserted in the request.
Sourcepub fn dynamic_tools(
self,
sample: usize,
dynamic_tools: impl VectorStoreIndexDyn + 'static,
toolset: ToolSet,
) -> Self
pub fn dynamic_tools( self, sample: usize, dynamic_tools: impl VectorStoreIndexDyn + 'static, toolset: ToolSet, ) -> Self
Add some dynamic tools to the agent. On each prompt, sample
tools from the
dynamic toolset will be inserted in the request.
Sourcepub fn temperature(self, temperature: f64) -> Self
pub fn temperature(self, temperature: f64) -> Self
Set the temperature of the model
Sourcepub fn max_tokens(self, max_tokens: u64) -> Self
pub fn max_tokens(self, max_tokens: u64) -> Self
Set the maximum number of tokens for the completion
Sourcepub fn additional_params(self, params: Value) -> Self
pub fn additional_params(self, params: Value) -> Self
Set additional parameters to be passed to the model
Auto Trait Implementations§
impl<M> Freeze for AgentBuilder<M>where
M: Freeze,
impl<M> !RefUnwindSafe for AgentBuilder<M>
impl<M> Send for AgentBuilder<M>
impl<M> Sync for AgentBuilder<M>
impl<M> Unpin for AgentBuilder<M>where
M: Unpin,
impl<M> !UnwindSafe for AgentBuilder<M>
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<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
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 moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
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