Skip to main content

CodeActAgentBuilder

Struct CodeActAgentBuilder 

Source
pub struct CodeActAgentBuilder { /* private fields */ }
Available on crate features agents and codeact only.
Expand description

Builder for CodeActAgent.

model and runtime are required; every other setting has a default. The configuration surface mirrors LlmAgentBuilder (instructions, tools, toolsets, retries, guardrails, callbacks, transfer, output schema, …).

§Example

use std::sync::Arc;
use std::time::Duration;
use adk_agent::codeact::CodeActAgent;

let agent = CodeActAgent::builder()
    .name("assistant")
    .model(model)
    .runtime(runtime)
    .temperature(0.2)
    .tool_timeout(Duration::from_secs(30))
    .require_tool_confirmation("delete_file")
    .build()?;

Implementations§

Source§

impl CodeActAgentBuilder

Source

pub fn new() -> CodeActAgentBuilder

Create a builder with default settings.

Source

pub fn name(self, name: impl Into<String>) -> CodeActAgentBuilder

Set the agent name.

Source

pub fn description(self, description: impl Into<String>) -> CodeActAgentBuilder

Set the agent description.

Source

pub fn model(self, model: Arc<dyn Llm>) -> CodeActAgentBuilder

Set the model (required).

Source

pub fn runtime(self, runtime: Arc<dyn CodeRuntime>) -> CodeActAgentBuilder

Set the code runtime (required).

Source

pub fn tool(self, tool: Arc<dyn Tool>) -> CodeActAgentBuilder

Register a tool callable from scripts.

Source

pub fn sub_agent(self, agent: Arc<dyn Agent>) -> CodeActAgentBuilder

Add a sub-agent this agent may transfer control to.

When any sub-agent is present (or the Runner supplies transfer targets), the transfer_to_agent output is described to the model.

Source

pub fn toolset(self, toolset: Arc<dyn Toolset>) -> CodeActAgentBuilder

Add a toolset whose tools are resolved fresh on each invocation from the run’s ReadonlyContext (e.g. per-user or pooled tools). Resolved tools are merged with static tools; duplicate names are rejected at run time.

Source

pub fn with_skills(self, index: SkillIndex) -> CodeActAgentBuilder

Available on crate feature skills only.

Set a preloaded skills index. The most relevant skill for each user query is injected into the system prompt.

Source

pub fn with_auto_skills(self) -> Result<CodeActAgentBuilder, AdkError>

Available on crate feature skills only.

Auto-load skills from .skills/ in the current working directory.

§Errors

Returns an error if the skills directory cannot be loaded.

Source

pub fn with_skills_from_root( self, root: impl AsRef<Path>, ) -> Result<CodeActAgentBuilder, AdkError>

Available on crate feature skills only.

Load skills from .skills/ under a custom root directory.

§Errors

Returns an error if the skills directory cannot be loaded.

Source

pub fn with_skill_policy(self, policy: SelectionPolicy) -> CodeActAgentBuilder

Available on crate feature skills only.

Customize skill selection behavior.

Source

pub fn with_skill_budget(self, max_chars: usize) -> CodeActAgentBuilder

Available on crate feature skills only.

Limit injected skill content length (default 2000 chars).

Source

pub fn disallow_transfer_to_parent(self, disallow: bool) -> CodeActAgentBuilder

Prevent this agent from transferring control back to its parent.

Applies only to the parent the Runner supplies via RunConfig::parent_agent; sub-agents are unaffected.

Source

pub fn disallow_transfer_to_peers(self, disallow: bool) -> CodeActAgentBuilder

Prevent this agent from transferring control to peer agents.

Applies only to the runner-provided peers in RunConfig::transfer_targets; sub-agents are unaffected.

Source

pub fn tool_confirmation_policy( self, policy: ToolConfirmationPolicy, ) -> CodeActAgentBuilder

Set the tool confirmation policy.

Source

pub fn require_tool_confirmation( self, tool_name: impl Into<String>, ) -> CodeActAgentBuilder

Require human confirmation for a specific tool.

Source

pub fn require_tool_confirmation_for_all(self) -> CodeActAgentBuilder

Require human confirmation for every tool call.

Source

pub fn generate_content_config( self, config: GenerateContentConfig, ) -> CodeActAgentBuilder

Set the generation config (temperature, tokens, etc.) applied to every model request.

Source

pub fn temperature(self, temperature: f32) -> CodeActAgentBuilder

Set the default sampling temperature for model requests.

Source

pub fn top_p(self, top_p: f32) -> CodeActAgentBuilder

Set the default top-p for model requests.

Source

pub fn top_k(self, top_k: i32) -> CodeActAgentBuilder

Set the default top-k for model requests.

Source

pub fn max_output_tokens(self, max_tokens: i32) -> CodeActAgentBuilder

Set the default maximum output tokens for model requests.

Source

pub fn tool_timeout(self, timeout: Duration) -> CodeActAgentBuilder

Set the per-tool execution timeout (default: 5 minutes).

Source

pub fn output_key(self, key: impl Into<String>) -> CodeActAgentBuilder

Set a session state key under which the final result value is stored.

Source

pub fn before_callback( self, callback: Box<dyn Fn(Arc<dyn CallbackContext>) -> Pin<Box<dyn Future<Output = Result<Option<Content>, AdkError>> + Send>> + Sync + Send>, ) -> CodeActAgentBuilder

Add a before-agent callback.

Callbacks run in registration order before the loop starts; the first to return Some(content) short-circuits the run with that content.

Source

pub fn after_callback( self, callback: Box<dyn Fn(Arc<dyn CallbackContext>) -> Pin<Box<dyn Future<Output = Result<Option<Content>, AdkError>> + Send>> + Sync + Send>, ) -> CodeActAgentBuilder

Add an after-agent callback.

Callbacks run after the loop completes (not on suspension); the first to return Some(content) emits that content and wins.

Source

pub fn before_model_callback( self, callback: Box<dyn Fn(Arc<dyn CallbackContext>, LlmRequest) -> Pin<Box<dyn Future<Output = Result<BeforeModelResult, AdkError>> + Send>> + Sync + Send>, ) -> CodeActAgentBuilder

Add a before-model callback, invoked before each model request.

A callback may rewrite the request (BeforeModelResult::Continue) or skip the model call entirely with a synthetic response (BeforeModelResult::Skip).

Source

pub fn after_model_callback( self, callback: Box<dyn Fn(Arc<dyn CallbackContext>, LlmResponse) -> Pin<Box<dyn Future<Output = Result<Option<LlmResponse>, AdkError>> + Send>> + Sync + Send>, ) -> CodeActAgentBuilder

Add an after-model callback, invoked after each model response is assembled. Returning Some(response) replaces the response the loop uses to extract the next script.

Source

pub fn before_tool_callback( self, callback: Box<dyn Fn(Arc<dyn CallbackContext>) -> Pin<Box<dyn Future<Output = Result<Option<Content>, AdkError>> + Send>> + Sync + Send>, ) -> CodeActAgentBuilder

Add a before-tool callback, invoked before each tool call. The first to return Some(content) short-circuits the call; that content is converted to a value and fed back into the script as the tool’s result.

Source

pub fn after_tool_callback( self, callback: Box<dyn Fn(Arc<dyn CallbackContext>) -> Pin<Box<dyn Future<Output = Result<Option<Content>, AdkError>> + Send>> + Sync + Send>, ) -> CodeActAgentBuilder

Add an after-tool callback, invoked after each tool attempt resolves. The first to return Some(content) replaces the result fed back to the script.

Source

pub fn after_tool_callback_full( self, callback: Box<dyn Fn(Arc<dyn CallbackContext>, Arc<dyn Tool>, Value, Value) -> Pin<Box<dyn Future<Output = Result<Option<Value>, AdkError>> + Send>> + Sync + Send>, ) -> CodeActAgentBuilder

Add a rich after-tool callback receiving the tool, arguments, and response value. Returning Some(value) replaces the result fed back to the script. These run after the plain after_tool_callback chain.

Source

pub fn on_tool_error( self, callback: Box<dyn Fn(Arc<dyn CallbackContext>, Arc<dyn Tool>, Value, String) -> Pin<Box<dyn Future<Output = Result<Option<Value>, AdkError>> + Send>> + Sync + Send>, ) -> CodeActAgentBuilder

Add an on-tool-error callback. When a tool ultimately fails, callbacks run in order; the first to return Some(value) supplies a fallback result (fed back as if the tool succeeded). If none do, the error is raised into the script.

Source

pub fn default_retry_budget(self, budget: RetryBudget) -> CodeActAgentBuilder

Set the default retry budget applied to tools without a per-tool override.

Source

pub fn tool_retry_budget( self, tool_name: impl Into<String>, budget: RetryBudget, ) -> CodeActAgentBuilder

Set a per-tool retry budget override (takes precedence over the default).

Source

pub fn circuit_breaker_threshold(self, threshold: u32) -> CodeActAgentBuilder

Set the circuit-breaker threshold: after this many consecutive failures in one invocation, a tool is short-circuited with an immediate error until the next run.

Source

pub fn input_schema(self, schema: Value) -> CodeActAgentBuilder

Set a JSON schema describing this agent’s input (descriptive metadata, e.g. for exposing the agent as a tool; not enforced at runtime).

Source

pub fn output_schema(self, schema: Value) -> CodeActAgentBuilder

Require the final result to validate against this JSON schema. On a mismatch the model is asked to correct it, up to output_max_retries times.

Source

pub fn output_type<T>(self) -> CodeActAgentBuilder
where T: JsonSchema,

Require the final result to match T’s JSON schema. Convenience over output_schema using schemars.

Source

pub fn output_max_retries(self, retries: usize) -> CodeActAgentBuilder

Set the maximum number of output-schema correction retries (default 3).

Source

pub fn input_guardrails(self, guardrails: GuardrailSet) -> CodeActAgentBuilder

Set guardrails applied to the incoming user content before the run. A block aborts the run; a transform (e.g. PII redaction) rewrites it. No-op unless the guardrails feature is enabled.

Source

pub fn output_guardrails(self, guardrails: GuardrailSet) -> CodeActAgentBuilder

Set guardrails applied to the final result before it is emitted. No-op unless the guardrails feature is enabled.

Source

pub fn instruction(self, instruction: impl Into<String>) -> CodeActAgentBuilder

Set the agent instruction, placed first in the system prompt. Supports {state.key} template injection from session state.

Source

pub fn instruction_provider( self, provider: Box<dyn Fn(Arc<dyn ReadonlyContext>) -> Pin<Box<dyn Future<Output = Result<String, AdkError>> + Send>> + Sync + Send>, ) -> CodeActAgentBuilder

Set a dynamic instruction provider evaluated per invocation (takes precedence over the static instruction).

Source

pub fn global_instruction( self, instruction: impl Into<String>, ) -> CodeActAgentBuilder

Set a global instruction placed before the agent instruction. Supports {state.key} template injection.

Source

pub fn global_instruction_provider( self, provider: Box<dyn Fn(Arc<dyn ReadonlyContext>) -> Pin<Box<dyn Future<Output = Result<String, AdkError>> + Send>> + Sync + Send>, ) -> CodeActAgentBuilder

Set a dynamic global instruction provider evaluated per invocation (takes precedence over the static global_instruction).

Source

pub fn include_contents(self, include: IncludeContents) -> CodeActAgentBuilder

Control which conversation history the agent sees (default: full).

Source

pub fn max_iterations(self, max: u32) -> CodeActAgentBuilder

Set the maximum number of model turns.

Source

pub fn max_error_chars(self, max: usize) -> CodeActAgentBuilder

Set the maximum error-message length fed back to the model.

Source

pub fn build(self) -> Result<CodeActAgent, AdkError>

Build the CodeActAgent.

§Errors

Returns a config error if the model or runtime was not set.

Trait Implementations§

Source§

impl Default for CodeActAgentBuilder

Source§

fn default() -> CodeActAgentBuilder

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> Conv for T

Source§

fn conv<T>(self) -> T
where Self: Into<T>,

Converts self into T using Into<T>. Read more
Source§

impl<T> FmtForward for T

Source§

fn fmt_binary(self) -> FmtBinary<Self>
where Self: Binary,

Causes self to use its Binary implementation when Debug-formatted.
Source§

fn fmt_display(self) -> FmtDisplay<Self>
where Self: Display,

Causes self to use its Display implementation when Debug-formatted.
Source§

fn fmt_lower_exp(self) -> FmtLowerExp<Self>
where Self: LowerExp,

Causes self to use its LowerExp implementation when Debug-formatted.
Source§

fn fmt_lower_hex(self) -> FmtLowerHex<Self>
where Self: LowerHex,

Causes self to use its LowerHex implementation when Debug-formatted.
Source§

fn fmt_octal(self) -> FmtOctal<Self>
where Self: Octal,

Causes self to use its Octal implementation when Debug-formatted.
Source§

fn fmt_pointer(self) -> FmtPointer<Self>
where Self: Pointer,

Causes self to use its Pointer implementation when Debug-formatted.
Source§

fn fmt_upper_exp(self) -> FmtUpperExp<Self>
where Self: UpperExp,

Causes self to use its UpperExp implementation when Debug-formatted.
Source§

fn fmt_upper_hex(self) -> FmtUpperHex<Self>
where Self: UpperHex,

Causes self to use its UpperHex implementation when Debug-formatted.
Source§

fn fmt_list(self) -> FmtList<Self>
where &'a Self: for<'a> IntoIterator,

Formats each item in a sequence. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> MaybeSend for T
where T: Send,

Source§

impl<T> Pipe for T
where T: ?Sized,

Source§

fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> R
where Self: Sized,

Pipes by value. This is generally the method you want to use. Read more
Source§

fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> R
where R: 'a,

Borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> R
where R: 'a,

Mutably borrows self and passes that borrow into the pipe function. Read more
Source§

fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
where Self: Borrow<B>, B: 'a + ?Sized, R: 'a,

Borrows self, then passes self.borrow() into the pipe function. Read more
Source§

fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
where Self: BorrowMut<B>, B: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.borrow_mut() into the pipe function. Read more
Source§

fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
where Self: AsRef<U>, U: 'a + ?Sized, R: 'a,

Borrows self, then passes self.as_ref() into the pipe function.
Source§

fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
where Self: AsMut<U>, U: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.as_mut() into the pipe function.
Source§

fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
where Self: Deref<Target = T>, T: 'a + ?Sized, R: 'a,

Borrows self, then passes self.deref() into the pipe function.
Source§

fn pipe_deref_mut<'a, T, R>( &'a mut self, func: impl FnOnce(&'a mut T) -> R, ) -> R
where Self: DerefMut<Target = T> + Deref, T: 'a + ?Sized, R: 'a,

Mutably borrows self, then passes self.deref_mut() into the pipe function.
Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> Tap for T

Source§

fn tap(self, func: impl FnOnce(&Self)) -> Self

Immutable access to a value. Read more
Source§

fn tap_mut(self, func: impl FnOnce(&mut Self)) -> Self

Mutable access to a value. Read more
Source§

fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Immutable access to the Borrow<B> of a value. Read more
Source§

fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Mutable access to the BorrowMut<B> of a value. Read more
Source§

fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Immutable access to the AsRef<R> view of a value. Read more
Source§

fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Mutable access to the AsMut<R> view of a value. Read more
Source§

fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Immutable access to the Deref::Target of a value. Read more
Source§

fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Mutable access to the Deref::Target of a value. Read more
Source§

fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self

Calls .tap() only in debug builds, and is erased in release builds.
Source§

fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self

Calls .tap_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
where Self: Borrow<B>, B: ?Sized,

Calls .tap_borrow() only in debug builds, and is erased in release builds.
Source§

fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
where Self: BorrowMut<B>, B: ?Sized,

Calls .tap_borrow_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
where Self: AsRef<R>, R: ?Sized,

Calls .tap_ref() only in debug builds, and is erased in release builds.
Source§

fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
where Self: AsMut<R>, R: ?Sized,

Calls .tap_ref_mut() only in debug builds, and is erased in release builds.
Source§

fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
where Self: Deref<Target = T>, T: ?Sized,

Calls .tap_deref() only in debug builds, and is erased in release builds.
Source§

fn tap_deref_mut_dbg<T>(self, func: impl FnOnce(&mut T)) -> Self
where Self: DerefMut<Target = T> + Deref, T: ?Sized,

Calls .tap_deref_mut() only in debug builds, and is erased in release builds.
Source§

impl<T> TryConv for T

Source§

fn try_conv<T>(self) -> Result<T, Self::Error>
where Self: TryInto<T>,

Attempts to convert self into T using TryInto<T>. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more