AgentBuilder

Struct AgentBuilder 

Source
pub struct AgentBuilder { /* private fields */ }
Expand description

Copy-on-write immutable builder for agent construction.

Every setter returns a new AgentBuilder, leaving the original unchanged. This makes builders safe to share as templates.

§Basic Usage

use gemini_adk_fluent_rs::builder::AgentBuilder;
use gemini_genai_rs::prelude::GeminiModel;

let agent = AgentBuilder::new("analyst")
    .model(GeminiModel::Gemini2_0FlashLive)
    .instruction("Analyze the given topic")
    .temperature(0.3);

assert_eq!(agent.name(), "analyst");
assert_eq!(agent.get_temperature(), Some(0.3));

§Copy-on-Write Pattern

Cloning a builder and modifying the clone leaves the original unchanged. This is useful for creating template builders with shared defaults.

use gemini_adk_fluent_rs::builder::AgentBuilder;

let base = AgentBuilder::new("researcher")
    .instruction("You are a research assistant.")
    .temperature(0.5);

let creative = base.clone().temperature(0.9);
let precise  = base.clone().temperature(0.1);

// Original unchanged
assert_eq!(base.get_temperature(), Some(0.5));
assert_eq!(creative.get_temperature(), Some(0.9));
assert_eq!(precise.get_temperature(), Some(0.1));

§Sampling Parameters

use gemini_adk_fluent_rs::builder::AgentBuilder;

let agent = AgentBuilder::new("sampler")
    .temperature(0.7)
    .top_p(0.95)
    .top_k(40)
    .max_output_tokens(4096);

assert_eq!(agent.get_top_p(), Some(0.95));
assert_eq!(agent.get_top_k(), Some(40));
assert_eq!(agent.get_max_output_tokens(), Some(4096));

§Built-in Tools

use gemini_adk_fluent_rs::builder::AgentBuilder;

let agent = AgentBuilder::new("searcher")
    .google_search()
    .code_execution()
    .url_context();

assert_eq!(agent.tool_count(), 3);

§Thinking Budget

use gemini_adk_fluent_rs::builder::AgentBuilder;

let agent = AgentBuilder::new("thinker")
    .thinking(2048);

assert_eq!(agent.get_thinking_budget(), Some(2048));

Implementations§

Source§

impl AgentBuilder

Source

pub fn new(name: impl Into<String>) -> Self

Create a new builder with the given agent name.

Source

pub fn name(&self) -> &str

The agent name.

Source

pub fn get_model(&self) -> Option<&GeminiModel>

Configured model, if any.

Source

pub fn get_instruction(&self) -> Option<&str>

Configured instruction, if any.

Source

pub fn get_voice(&self) -> Option<&Voice>

Configured voice, if any.

Source

pub fn get_temperature(&self) -> Option<f32>

Configured temperature, if any.

Source

pub fn is_text_only(&self) -> bool

Whether text-only mode is set.

Source

pub fn get_thinking_budget(&self) -> Option<u32>

Configured thinking budget, if any.

Source

pub fn get_writes(&self) -> &[String]

State keys this agent writes.

Source

pub fn get_reads(&self) -> &[String]

State keys this agent reads.

Source

pub fn get_sub_agents(&self) -> &[AgentBuilder]

Sub-agents registered.

Source

pub fn is_isolated(&self) -> bool

Whether agent runs in isolated state.

Source

pub fn is_stay(&self) -> bool

Whether agent stays after transfer.

Source

pub fn tool_count(&self) -> usize

Number of tool entries.

Source

pub fn get_top_p(&self) -> Option<f32>

Configured top_p, if any.

Source

pub fn get_top_k(&self) -> Option<u32>

Configured top_k, if any.

Source

pub fn get_max_output_tokens(&self) -> Option<u32>

Configured max_output_tokens, if any.

Source

pub fn get_stop_sequences(&self) -> &[String]

Configured stop sequences.

Source

pub fn get_description(&self) -> Option<&str>

Configured description, if any.

Source

pub fn get_output_schema(&self) -> Option<&Value>

Configured output schema, if any.

Source

pub fn get_output_key(&self) -> Option<&str>

Get the configured output key.

Source

pub fn get_transfer_to(&self) -> Option<&str>

Configured transfer target agent, if any.

Source

pub fn model(self, model: GeminiModel) -> Self

Set the Gemini model.

Source

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

Set the system instruction.

Source

pub fn voice(self, voice: Voice) -> Self

Set the output voice.

Source

pub fn temperature(self, t: f32) -> Self

Set the temperature.

Source

pub fn text_only(self) -> Self

Set text-only mode (no audio output).

Source

pub fn response_modalities(self, modalities: Vec<Modality>) -> Self

Set response modalities explicitly.

Source

pub fn thinking(self, budget: u32) -> Self

Enable thinking with a token budget.

Source

pub fn url_context(self) -> Self

Add a built-in URL context tool.

Add a built-in Google Search tool.

Source

pub fn code_execution(self) -> Self

Add a built-in code execution tool.

Source

pub fn writes(self, key: impl Into<String>) -> Self

Declare a state key this agent writes.

Source

pub fn reads(self, key: impl Into<String>) -> Self

Declare a state key this agent reads.

Source

pub fn sub_agent(self, agent: AgentBuilder) -> Self

Add a sub-agent for transfer.

Source

pub fn isolate(self) -> Self

Run this agent in isolated state (no shared state).

Source

pub fn stay(self) -> Self

Keep this agent active after transfer (don’t tear down).

Source

pub fn top_p(self, p: f32) -> Self

Set top_p (nucleus sampling).

Source

pub fn top_k(self, k: u32) -> Self

Set top_k (top-k sampling).

Source

pub fn max_output_tokens(self, n: u32) -> Self

Set maximum output tokens.

Source

pub fn stop_sequences(self, seqs: Vec<String>) -> Self

Set stop sequences.

Source

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

Set a description for this agent (used in tool/agent metadata).

Source

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

Set a JSON schema for structured output.

Source

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

Set the output key — agent’s final text response is auto-saved to this state key.

Source

pub fn transfer_to(self, agent_name: impl Into<String>) -> Self

Set a default transfer target agent.

Source

pub fn instruct(self, inst: impl Into<String>) -> Self

Alias for instruction — matches upstream Python Agent.instruct().

Source

pub fn describe(self, desc: impl Into<String>) -> Self

Alias for description — matches upstream Python Agent.describe().

Source

pub fn tool(self, f: Arc<dyn ToolFunction>) -> Self

Register a single tool function.

Agent::new("assistant").tool(Arc::new(my_tool))
Source

pub fn tools(self, composite: ToolComposite) -> Self

Register multiple tools from a ToolComposite.

let tools = T::simple("greet", "Greet", |_| async { Ok(json!({})) })
    | T::google_search();
Agent::new("assistant").tools(tools)
Source

pub fn guard(self, _guard: GComposite) -> Self

Set a guard composite for output validation.

Guards are evaluated after each agent response. This stores the guard configuration for use at compile time.

Source

pub fn context(self, _policy: ContextPolicy) -> Self

Set a context policy for conversation history management.

Source

pub fn no_peers(self) -> Self

Disallow transfer to peer agents.

Source

pub fn build(self, llm: Arc<dyn BaseLlm>) -> Arc<dyn TextAgent>

Compile this builder into an executable TextAgent.

The LLM is required because TextAgent makes BaseLlm::generate() calls. Builder configuration (instruction, temperature, tools) is transferred to the resulting agent.

let agent = AgentBuilder::new("analyst")
    .instruction("Analyze the topic")
    .temperature(0.3)
    .build(llm);

let result = agent.run(&state).await?;

Trait Implementations§

Source§

impl BitOr<AgentBuilder> for Composable

Composable | AgentBuilder → FanOut (flattening)

Source§

type Output = Composable

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: AgentBuilder) -> Self::Output

Performs the | operation. Read more
Source§

impl BitOr for AgentBuilder

AgentBuilder | AgentBuilder → FanOut

Source§

type Output = Composable

The resulting type after applying the | operator.
Source§

fn bitor(self, rhs: AgentBuilder) -> Self::Output

Performs the | operation. Read more
Source§

impl Clone for AgentBuilder

Source§

fn clone(&self) -> AgentBuilder

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for AgentBuilder

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Div<AgentBuilder> for Composable

Composable / AgentBuilder → Fallback (flattening)

Source§

type Output = Composable

The resulting type after applying the / operator.
Source§

fn div(self, rhs: AgentBuilder) -> Self::Output

Performs the / operation. Read more
Source§

impl Div for AgentBuilder

AgentBuilder / AgentBuilder → Fallback

Source§

type Output = Composable

The resulting type after applying the / operator.
Source§

fn div(self, rhs: AgentBuilder) -> Self::Output

Performs the / operation. Read more
Source§

impl From<AgentBuilder> for Composable

Source§

fn from(b: AgentBuilder) -> Self

Converts to this type from the input type.
Source§

impl Mul<LoopPredicate> for AgentBuilder

AgentBuilder * until(pred) → conditional Loop

Source§

type Output = Composable

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: LoopPredicate) -> Self::Output

Performs the * operation. Read more
Source§

impl Mul<u32> for AgentBuilder

AgentBuilder * 3 → Loop(max=3)

Source§

type Output = Composable

The resulting type after applying the * operator.
Source§

fn mul(self, rhs: u32) -> Self::Output

Performs the * operation. Read more
Source§

impl Shr<AgentBuilder> for Composable

Composable >> AgentBuilder → Pipeline (flattening)

Source§

type Output = Composable

The resulting type after applying the >> operator.
Source§

fn shr(self, rhs: AgentBuilder) -> Self::Output

Performs the >> operation. Read more
Source§

impl Shr<Composable> for AgentBuilder

AgentBuilder >> Composable → Pipeline (flattening)

Source§

type Output = Composable

The resulting type after applying the >> operator.
Source§

fn shr(self, rhs: Composable) -> Self::Output

Performs the >> operation. Read more
Source§

impl Shr for AgentBuilder

AgentBuilder >> AgentBuilder → Pipeline

Source§

type Output = Composable

The resulting type after applying the >> operator.
Source§

fn shr(self, rhs: AgentBuilder) -> Self::Output

Performs the >> operation. 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<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

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

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

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.

§

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

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: 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
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: 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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.
§

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

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

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
§

fn with_current_subscriber(self) -> WithDispatch<Self>

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