pub struct LlmAgentBuilder { /* private fields */ }Implementations§
Source§impl LlmAgentBuilder
impl LlmAgentBuilder
pub fn new(name: impl Into<String>) -> Self
pub fn description(self, desc: impl Into<String>) -> Self
pub fn model(self, model: Arc<dyn Llm>) -> Self
pub fn instruction(self, instruction: impl Into<String>) -> Self
pub fn instruction_provider(self, provider: InstructionProvider) -> Self
pub fn global_instruction(self, instruction: impl Into<String>) -> Self
pub fn global_instruction_provider( self, provider: GlobalInstructionProvider, ) -> Self
Sourcepub fn with_skills(self, index: SkillIndex) -> Self
pub fn with_skills(self, index: SkillIndex) -> Self
Set a preloaded skills index for this agent.
Sourcepub fn with_auto_skills(self) -> Result<Self>
pub fn with_auto_skills(self) -> Result<Self>
Auto-load skills from .skills/ in the current working directory.
Sourcepub fn with_skills_from_root(self, root: impl AsRef<Path>) -> Result<Self>
pub fn with_skills_from_root(self, root: impl AsRef<Path>) -> Result<Self>
Auto-load skills from .skills/ under a custom root directory.
Sourcepub fn with_skill_policy(self, policy: SelectionPolicy) -> Self
pub fn with_skill_policy(self, policy: SelectionPolicy) -> Self
Customize skill selection behavior.
Sourcepub fn with_skill_budget(self, max_chars: usize) -> Self
pub fn with_skill_budget(self, max_chars: usize) -> Self
Limit injected skill content length.
pub fn input_schema(self, schema: Value) -> Self
pub fn output_schema(self, schema: Value) -> Self
pub fn disallow_transfer_to_parent(self, disallow: bool) -> Self
pub fn disallow_transfer_to_peers(self, disallow: bool) -> Self
pub fn include_contents(self, include: IncludeContents) -> Self
pub fn output_key(self, key: impl Into<String>) -> Self
Sourcepub fn generate_content_config(self, config: GenerateContentConfig) -> Self
pub fn generate_content_config(self, config: GenerateContentConfig) -> Self
Set default generation parameters (temperature, top_p, top_k, max_output_tokens) applied to every LLM request made by this agent.
These defaults are merged with any per-request config. If output_schema is also
set, the schema is preserved alongside these generation parameters.
§Example
use adk_core::GenerateContentConfig;
let agent = LlmAgentBuilder::new("my-agent")
.model(model)
.generate_content_config(GenerateContentConfig {
temperature: Some(0.7),
max_output_tokens: Some(2048),
..Default::default()
})
.build()?;Sourcepub fn temperature(self, temperature: f32) -> Self
pub fn temperature(self, temperature: f32) -> Self
Set the default temperature for LLM requests.
Shorthand for setting just temperature without a full GenerateContentConfig.
Sourcepub fn max_output_tokens(self, max_tokens: i32) -> Self
pub fn max_output_tokens(self, max_tokens: i32) -> Self
Set the default max output tokens for LLM requests.
Sourcepub fn max_iterations(self, max: u32) -> Self
pub fn max_iterations(self, max: u32) -> Self
Set the maximum number of LLM round-trips (iterations) before the agent stops. Default is 100.
Sourcepub fn tool_timeout(self, timeout: Duration) -> Self
pub fn tool_timeout(self, timeout: Duration) -> Self
Set the timeout for individual tool executions. Default is 5 minutes. Tools that exceed this timeout will return an error.
pub fn tool(self, tool: Arc<dyn Tool>) -> Self
Sourcepub fn toolset(self, toolset: Arc<dyn Toolset>) -> Self
pub fn toolset(self, toolset: Arc<dyn Toolset>) -> Self
Register a dynamic toolset for per-invocation tool resolution.
Toolsets are resolved at the start of each run() call using the
invocation’s ReadonlyContext. This enables context-dependent tools
like per-user browser sessions from a pool.
pub fn sub_agent(self, agent: Arc<dyn Agent>) -> Self
pub fn before_callback(self, callback: BeforeAgentCallback) -> Self
pub fn after_callback(self, callback: AfterAgentCallback) -> Self
pub fn before_model_callback(self, callback: BeforeModelCallback) -> Self
pub fn after_model_callback(self, callback: AfterModelCallback) -> Self
pub fn before_tool_callback(self, callback: BeforeToolCallback) -> Self
pub fn after_tool_callback(self, callback: AfterToolCallback) -> Self
Sourcepub fn after_tool_callback_full(self, callback: AfterToolCallbackFull) -> Self
pub fn after_tool_callback_full(self, callback: AfterToolCallbackFull) -> Self
Register a rich after-tool callback that receives the tool, arguments, and response value.
This is the V2 callback surface aligned with the Python/Go ADK model
where after_tool_callback receives the full tool execution context.
Unlike after_tool_callback (which only
receives CallbackContext), this callback can inspect and modify tool
results directly.
Return Ok(None) to keep the original response, or Ok(Some(value))
to replace the function response sent to the LLM.
These callbacks run after the legacy after_tool_callback chain.
ToolOutcome is available via ctx.tool_outcome().
Sourcepub fn on_tool_error(self, callback: OnToolErrorCallback) -> Self
pub fn on_tool_error(self, callback: OnToolErrorCallback) -> Self
Register a callback invoked when a tool execution fails (after retries are exhausted).
If the callback returns Ok(Some(value)), the value is used as a
fallback function response to the LLM. If it returns Ok(None),
the next callback in the chain is tried. If no callback provides a
fallback, the original error is reported to the LLM.
Sourcepub fn default_retry_budget(self, budget: RetryBudget) -> Self
pub fn default_retry_budget(self, budget: RetryBudget) -> Self
Set a default retry budget applied to all tools that do not have a per-tool override.
When a tool execution fails and a retry budget applies, the agent
retries up to budget.max_retries times with the configured delay
between attempts.
Sourcepub fn tool_retry_budget(
self,
tool_name: impl Into<String>,
budget: RetryBudget,
) -> Self
pub fn tool_retry_budget( self, tool_name: impl Into<String>, budget: RetryBudget, ) -> Self
Set a per-tool retry budget that overrides the default for the named tool.
Per-tool budgets take precedence over the default retry budget.
Sourcepub fn circuit_breaker_threshold(self, threshold: u32) -> Self
pub fn circuit_breaker_threshold(self, threshold: u32) -> Self
Configure a circuit breaker that temporarily disables tools after
threshold consecutive failures within a single invocation.
When a tool’s consecutive failure count reaches the threshold, subsequent calls to that tool are short-circuited with an immediate error response until the next invocation (which resets the state).
Sourcepub fn tool_confirmation_policy(self, policy: ToolConfirmationPolicy) -> Self
pub fn tool_confirmation_policy(self, policy: ToolConfirmationPolicy) -> Self
Configure tool confirmation requirements for this agent.
Sourcepub fn require_tool_confirmation(self, tool_name: impl Into<String>) -> Self
pub fn require_tool_confirmation(self, tool_name: impl Into<String>) -> Self
Require confirmation for a specific tool name.
Sourcepub fn require_tool_confirmation_for_all(self) -> Self
pub fn require_tool_confirmation_for_all(self) -> Self
Require confirmation for all tool calls.
Sourcepub fn input_guardrails(self, guardrails: GuardrailSet) -> Self
pub fn input_guardrails(self, guardrails: GuardrailSet) -> Self
Set input guardrails to validate user input before processing.
Input guardrails run before the agent processes the request and can:
- Block harmful or off-topic content
- Redact PII from user input
- Enforce input length limits
Requires the guardrails feature.
Sourcepub fn output_guardrails(self, guardrails: GuardrailSet) -> Self
pub fn output_guardrails(self, guardrails: GuardrailSet) -> Self
Set output guardrails to validate agent responses.
Output guardrails run after the agent generates a response and can:
- Enforce JSON schema compliance
- Redact PII from responses
- Block harmful content in responses
Requires the guardrails feature.
pub fn build(self) -> Result<LlmAgent>
Auto Trait Implementations§
impl Freeze for LlmAgentBuilder
impl !RefUnwindSafe for LlmAgentBuilder
impl Send for LlmAgentBuilder
impl Sync for LlmAgentBuilder
impl Unpin for LlmAgentBuilder
impl UnsafeUnpin for LlmAgentBuilder
impl !UnwindSafe for LlmAgentBuilder
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
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> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request