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
impl AgentBuilder
Sourcepub fn get_model(&self) -> Option<&GeminiModel>
pub fn get_model(&self) -> Option<&GeminiModel>
Configured model, if any.
Sourcepub fn get_instruction(&self) -> Option<&str>
pub fn get_instruction(&self) -> Option<&str>
Configured instruction, if any.
Sourcepub fn get_temperature(&self) -> Option<f32>
pub fn get_temperature(&self) -> Option<f32>
Configured temperature, if any.
Sourcepub fn is_text_only(&self) -> bool
pub fn is_text_only(&self) -> bool
Whether text-only mode is set.
Sourcepub fn get_thinking_budget(&self) -> Option<u32>
pub fn get_thinking_budget(&self) -> Option<u32>
Configured thinking budget, if any.
Sourcepub fn get_writes(&self) -> &[String]
pub fn get_writes(&self) -> &[String]
State keys this agent writes.
Sourcepub fn get_sub_agents(&self) -> &[AgentBuilder]
pub fn get_sub_agents(&self) -> &[AgentBuilder]
Sub-agents registered.
Sourcepub fn is_isolated(&self) -> bool
pub fn is_isolated(&self) -> bool
Whether agent runs in isolated state.
Sourcepub fn tool_count(&self) -> usize
pub fn tool_count(&self) -> usize
Number of tool entries.
Sourcepub fn get_max_output_tokens(&self) -> Option<u32>
pub fn get_max_output_tokens(&self) -> Option<u32>
Configured max_output_tokens, if any.
Sourcepub fn get_stop_sequences(&self) -> &[String]
pub fn get_stop_sequences(&self) -> &[String]
Configured stop sequences.
Sourcepub fn get_description(&self) -> Option<&str>
pub fn get_description(&self) -> Option<&str>
Configured description, if any.
Sourcepub fn get_output_schema(&self) -> Option<&Value>
pub fn get_output_schema(&self) -> Option<&Value>
Configured output schema, if any.
Sourcepub fn get_output_key(&self) -> Option<&str>
pub fn get_output_key(&self) -> Option<&str>
Get the configured output key.
Sourcepub fn get_transfer_to(&self) -> Option<&str>
pub fn get_transfer_to(&self) -> Option<&str>
Configured transfer target agent, if any.
Sourcepub fn model(self, model: GeminiModel) -> Self
pub fn model(self, model: GeminiModel) -> Self
Set the Gemini model.
Sourcepub fn instruction(self, inst: impl Into<String>) -> Self
pub fn instruction(self, inst: impl Into<String>) -> Self
Set the system instruction.
Sourcepub fn temperature(self, t: f32) -> Self
pub fn temperature(self, t: f32) -> Self
Set the temperature.
Sourcepub fn response_modalities(self, modalities: Vec<Modality>) -> Self
pub fn response_modalities(self, modalities: Vec<Modality>) -> Self
Set response modalities explicitly.
Sourcepub fn url_context(self) -> Self
pub fn url_context(self) -> Self
Add a built-in URL context tool.
Sourcepub fn google_search(self) -> Self
pub fn google_search(self) -> Self
Add a built-in Google Search tool.
Sourcepub fn code_execution(self) -> Self
pub fn code_execution(self) -> Self
Add a built-in code execution tool.
Sourcepub fn sub_agent(self, agent: AgentBuilder) -> Self
pub fn sub_agent(self, agent: AgentBuilder) -> Self
Add a sub-agent for transfer.
Sourcepub fn max_output_tokens(self, n: u32) -> Self
pub fn max_output_tokens(self, n: u32) -> Self
Set maximum output tokens.
Sourcepub fn stop_sequences(self, seqs: Vec<String>) -> Self
pub fn stop_sequences(self, seqs: Vec<String>) -> Self
Set stop sequences.
Sourcepub fn description(self, desc: impl Into<String>) -> Self
pub fn description(self, desc: impl Into<String>) -> Self
Set a description for this agent (used in tool/agent metadata).
Sourcepub fn output_schema(self, schema: Value) -> Self
pub fn output_schema(self, schema: Value) -> Self
Set a JSON schema for structured output.
Sourcepub fn output_key(self, key: impl Into<String>) -> Self
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.
Sourcepub fn transfer_to(self, agent_name: impl Into<String>) -> Self
pub fn transfer_to(self, agent_name: impl Into<String>) -> Self
Set a default transfer target agent.
Sourcepub fn instruct(self, inst: impl Into<String>) -> Self
pub fn instruct(self, inst: impl Into<String>) -> Self
Alias for instruction — matches upstream Python Agent.instruct().
Sourcepub fn describe(self, desc: impl Into<String>) -> Self
pub fn describe(self, desc: impl Into<String>) -> Self
Alias for description — matches upstream Python Agent.describe().
Sourcepub fn tool(self, f: Arc<dyn ToolFunction>) -> Self
pub fn tool(self, f: Arc<dyn ToolFunction>) -> Self
Register a single tool function.
Agent::new("assistant").tool(Arc::new(my_tool))Sourcepub fn tools(self, composite: ToolComposite) -> Self
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)Sourcepub fn guard(self, _guard: GComposite) -> Self
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.
Sourcepub fn context(self, _policy: ContextPolicy) -> Self
pub fn context(self, _policy: ContextPolicy) -> Self
Set a context policy for conversation history management.
Sourcepub fn build(self, llm: Arc<dyn BaseLlm>) -> Arc<dyn TextAgent>
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)
impl BitOr<AgentBuilder> for Composable
Composable | AgentBuilder → FanOut (flattening)
Source§type Output = Composable
type Output = Composable
| operator.Source§impl BitOr for AgentBuilder
AgentBuilder | AgentBuilder → FanOut
impl BitOr for AgentBuilder
AgentBuilder | AgentBuilder → FanOut
Source§type Output = Composable
type Output = Composable
| operator.Source§impl Clone for AgentBuilder
impl Clone for AgentBuilder
Source§fn clone(&self) -> AgentBuilder
fn clone(&self) -> AgentBuilder
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for AgentBuilder
impl Debug for AgentBuilder
Source§impl Div<AgentBuilder> for Composable
Composable / AgentBuilder → Fallback (flattening)
impl Div<AgentBuilder> for Composable
Composable / AgentBuilder → Fallback (flattening)
Source§type Output = Composable
type Output = Composable
/ operator.Source§impl Div for AgentBuilder
AgentBuilder / AgentBuilder → Fallback
impl Div for AgentBuilder
AgentBuilder / AgentBuilder → Fallback
Source§type Output = Composable
type Output = Composable
/ operator.Source§impl From<AgentBuilder> for Composable
impl From<AgentBuilder> for Composable
Source§fn from(b: AgentBuilder) -> Self
fn from(b: AgentBuilder) -> Self
Source§impl Mul<LoopPredicate> for AgentBuilder
AgentBuilder * until(pred) → conditional Loop
impl Mul<LoopPredicate> for AgentBuilder
AgentBuilder * until(pred) → conditional Loop
Source§type Output = Composable
type Output = Composable
* operator.Source§impl Mul<u32> for AgentBuilder
AgentBuilder * 3 → Loop(max=3)
impl Mul<u32> for AgentBuilder
AgentBuilder * 3 → Loop(max=3)
Source§impl Shr<AgentBuilder> for Composable
Composable >> AgentBuilder → Pipeline (flattening)
impl Shr<AgentBuilder> for Composable
Composable >> AgentBuilder → Pipeline (flattening)
Source§type Output = Composable
type Output = Composable
>> operator.Source§impl Shr<Composable> for AgentBuilder
AgentBuilder >> Composable → Pipeline (flattening)
impl Shr<Composable> for AgentBuilder
AgentBuilder >> Composable → Pipeline (flattening)
Source§type Output = Composable
type Output = Composable
>> operator.Source§impl Shr for AgentBuilder
AgentBuilder >> AgentBuilder → Pipeline
impl Shr for AgentBuilder
AgentBuilder >> AgentBuilder → Pipeline
Source§type Output = Composable
type Output = Composable
>> operator.