pub struct AgentBuilder { /* private fields */ }Expand description
Builder for creating Agent instances.
Implementations§
Source§impl AgentBuilder
impl AgentBuilder
pub fn new() -> Self
Sourcepub fn system_prompt(self, prompt: impl Into<String>) -> Self
pub fn system_prompt(self, prompt: impl Into<String>) -> Self
Sets the system prompt.
Sourcepub fn tools(
self,
tools: impl IntoIterator<Item = impl AgentTool + 'static>,
) -> Result<Self>
pub fn tools( self, tools: impl IntoIterator<Item = impl AgentTool + 'static>, ) -> Result<Self>
Adds multiple tools to the agent.
Sourcepub fn tool_registry(self, registry: ToolRegistry) -> Self
pub fn tool_registry(self, registry: ToolRegistry) -> Self
Sets the tool registry.
Sourcepub fn description(self, description: impl Into<String>) -> Self
pub fn description(self, description: impl Into<String>) -> Self
Sets the agent description.
Sourcepub fn state(self, state: AgentState) -> Self
pub fn state(self, state: AgentState) -> Self
Sets the agent state.
Sourcepub fn hooks(self, hooks: HookRegistry) -> Self
pub fn hooks(self, hooks: HookRegistry) -> Self
Sets the hook registry.
Sourcepub fn conversation_manager(
self,
manager: impl ConversationManager + 'static,
) -> Self
pub fn conversation_manager( self, manager: impl ConversationManager + 'static, ) -> Self
Sets the conversation manager.
Sourcepub fn record_direct_tool_call(self, record: bool) -> Self
pub fn record_direct_tool_call(self, record: bool) -> Self
Sets whether to record direct tool calls in message history.
Sourcepub fn trace_attribute(
self,
key: impl Into<String>,
value: impl Into<String>,
) -> Self
pub fn trace_attribute( self, key: impl Into<String>, value: impl Into<String>, ) -> Self
Sets a trace attribute.
Sourcepub fn trace_attributes(self, attrs: HashMap<String, String>) -> Self
pub fn trace_attributes(self, attrs: HashMap<String, String>) -> Self
Sets multiple trace attributes.
Sourcepub fn max_tool_calls(self, max: usize) -> Self
pub fn max_tool_calls(self, max: usize) -> Self
Sets the maximum number of tool calls per cycle.
Sourcepub fn structured_output_model<T: JsonSchema + DeserializeOwned + 'static>(
self,
) -> Self
pub fn structured_output_model<T: JsonSchema + DeserializeOwned + 'static>( self, ) -> Self
Sets the structured output model type.
This configures the agent to enforce responses matching the schema of type T.
The structured output tool will be dynamically registered at invocation time
and cleaned up afterward.
§Example
ⓘ
use schemars::JsonSchema;
use serde::Deserialize;
#[derive(JsonSchema, Deserialize)]
struct MyOutput {
name: String,
count: i32,
}
let agent = Agent::builder()
.model(model)
.structured_output_model::<MyOutput>()
.build()?;Sourcepub fn structured_output_context(self, context: StructuredOutputContext) -> Self
pub fn structured_output_context(self, context: StructuredOutputContext) -> Self
Sets a custom structured output context.
Trait Implementations§
Auto Trait Implementations§
impl Freeze for AgentBuilder
impl !RefUnwindSafe for AgentBuilder
impl Send for AgentBuilder
impl Sync for AgentBuilder
impl Unpin for AgentBuilder
impl !UnwindSafe 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
Source§impl<T> FutureExt for T
impl<T> FutureExt for T
Source§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
Source§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<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 moreCreates a shared type from an unshared type.