pub struct AgentBuilder { /* private fields */ }Expand description
Agent Builder — 流畅 API 创建 FunctionCallingAgent
使用 Builder 模式,让用户只需 3 行代码就能创建并运行 Agent。
§基本用法
ⓘ
let agent = AgentBuilder::new()
.llm(OpenAIChat::new(OpenAIConfig::new("sk-...")))
.system("You are a helpful assistant.")
.tool(Calculator::new())
.build()?;§使用 Arc
ⓘ
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
设置 LLM(任何实现了 BaseChatModel 的类型)
自动包装为 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
设置 LLM(从已包装的 Arc<dyn BaseChatModel>)
适用于已通过 wrap_chat_model() 或 LLMClient 创建的 LLM 实例。
Sourcepub fn max_iterations(self, n: usize) -> Self
pub fn max_iterations(self, n: usize) -> Self
设置最大迭代次数
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>
Sourcepub fn get_max_iterations(&self) -> usize
pub fn get_max_iterations(&self) -> usize
获取最大迭代次数
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