pub struct AgentBuilder { /* private fields */ }Expand description
Agent Builder — fluent API to create a FunctionCallingAgent
Uses the Builder pattern so users can create and run an Agent in just 3 lines.
§Basic usage
ⓘ
let agent = AgentBuilder::new()
.llm(OpenAIChat::new(OpenAIConfig::new("sk-...")))
.system("You are a helpful assistant.")
.tool(Calculator::new())
.build()?;§Using Arc<dyn BaseChatModel>
ⓘ
let llm = wrap_chat_model(OpenAIChat::new(config));
let agent = AgentBuilder::new()
.llm_from_arc(llm)
.system("You are a helpful assistant.")
.build()?;Implementations§
Source§impl AgentBuilder
impl AgentBuilder
Sourcepub fn llm<L>(self, llm: L) -> Self
pub fn llm<L>(self, llm: L) -> Self
Sets the LLM (any type implementing BaseChatModel)
Automatically wraps it as Arc<dyn BaseChatModel<Error = ProviderError>>.
Sourcepub fn llm_from_arc(
self,
llm: Arc<dyn BaseChatModel<Error = ProviderError> + Send + Sync>,
) -> Self
pub fn llm_from_arc( self, llm: Arc<dyn BaseChatModel<Error = ProviderError> + Send + Sync>, ) -> Self
Sets the LLM (from an already-wrapped Arc<dyn BaseChatModel>)
For LLM instances already created via wrap_chat_model() or LLMClient.
Sourcepub fn max_iterations(self, n: usize) -> Self
pub fn max_iterations(self, n: usize) -> Self
Sets max iterations (clamped to [1, 100] to prevent 0 or runaway limits)
Sourcepub fn build(self) -> Result<FunctionCallingAgent, AgentError>
pub fn build(self) -> Result<FunctionCallingAgent, AgentError>
Sourcepub fn build_as_agent(self) -> Result<Arc<dyn BaseAgent>, AgentError>
pub fn build_as_agent(self) -> Result<Arc<dyn BaseAgent>, AgentError>
Builds and wraps as Arc<dyn BaseAgent> for direct use with AgentExecutor
§Errors
Returns AgentError::Other if no LLM was set.
Sourcepub fn get_max_iterations(&self) -> usize
pub fn get_max_iterations(&self) -> usize
Returns the max iterations
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for AgentBuilder
impl !UnwindSafe for AgentBuilder
impl Freeze for AgentBuilder
impl Send for AgentBuilder
impl Sync for AgentBuilder
impl Unpin for AgentBuilder
impl UnsafeUnpin for AgentBuilder
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