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::ModelId;
let agent = AgentBuilder::new("analyst")
.model(ModelId::LIVE_2_5_FLASH_NATIVE_AUDIO)
.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_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 middleware_layer_count(&self) -> usize
pub fn middleware_layer_count(&self) -> usize
Number of registered middleware layers.
Sourcepub fn instruction(self, inst: impl Into<String>) -> Self
pub fn instruction(self, inst: impl Into<String>) -> Self
Set the system instruction.
Sourcepub fn instruction_provider(
self,
provider: impl InstructionProvider + 'static,
) -> Self
pub fn instruction_provider( self, provider: impl InstructionProvider + 'static, ) -> Self
Set a dynamic instruction source — any Fn(&State) -> String
closure or a TemplateInstruction (feature templates), resolved
against live session state at the start of every run. Wins over
instruction when both are set.
Sourcepub fn llm_provider(
self,
provider: impl Fn(&State) -> Arc<dyn BaseLlm> + Send + Sync + 'static,
) -> Self
pub fn llm_provider( self, provider: impl Fn(&State) -> Arc<dyn BaseLlm> + Send + Sync + 'static, ) -> Self
Set a dynamic model source, resolved against session state at the start of every run — risk-based escalation to a stronger model, cost routing to a cheaper one, per-tenant model selection — without rebuilding the agent. Wins over the constructor’s model when set.
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: impl ToolFunction + 'static) -> Self
pub fn tool(self, f: impl ToolFunction + 'static) -> Self
Register one tool: anything that implements ToolFunction — a
SimpleTool/TypedTool, the value a #[tool] function returns, or an
Arc<dyn ToolFunction> you already hold.
#[tool("Get the weather for a city")]
async fn get_weather(city: String) -> Result<serde_json::Value, ToolError> {
Ok(serde_json::json!({"city": city, "temp": 22}))
}
let agent = AgentBuilder::new("assistant").tool(get_weather());Sourcepub fn tools(self, tools: impl Into<ToolComposite>) -> Self
pub fn tools(self, tools: impl Into<ToolComposite>) -> Self
Register tools: a |-composed ToolComposite from the T
namespace, or a single ToolFunction.
T::mcp(..) needs an async connection that this synchronous builder
cannot perform; it is rejected by build with a
ConfigError — attach MCP toolsets to a Live session instead.
let tools = T::simple("greet", "Greet", |_| async { Ok(json!({})) })
| T::google_search();
AgentBuilder::new("assistant").tools(tools);Sourcepub fn guard(self, guard: impl Into<GuardComposite>) -> Self
pub fn guard(self, guard: impl Into<GuardComposite>) -> Self
Attach output guards. Each model response is validated against every
guard; if any rejects the output the agent run fails with an
AgentError listing the violations.
Accepts a single guard or a |-composed GuardComposite:
AgentBuilder::new("writer").guard(G::pii() | G::length(1, 2000));The guards are installed as an after_model middleware layer, so they
accumulate with .middleware(...) and honor copy-on-write.
Sourcepub fn context(self, policy: impl Into<ContextComposite>) -> Self
pub fn context(self, policy: impl Into<ContextComposite>) -> Self
Attach a context policy that rewrites conversation history before each model call (e.g. windowing, role filtering, tool-result exclusion).
Accepts a single policy or a +-composed ContextComposite:
AgentBuilder::new("chat").context(C::window(10) + C::user_only());The policy is installed as a transform_request middleware layer.
Sourcepub fn middleware(self, middleware: impl Into<MiddlewareComposite>) -> Self
pub fn middleware(self, middleware: impl Into<MiddlewareComposite>) -> Self
Attach middleware — a |-composed MiddlewareComposite from the
M namespace or a single Arc<dyn Middleware>. All layers are
installed on the compiled LlmTextAgent in the order given.
Multiple calls to .middleware() accumulate: the new layers are
appended after any previously registered layers, preserving the
copy-on-write contract.
let agent = AgentBuilder::new("analyst")
.instruction("Analyze topics")
.middleware(M::log() | M::latency());Sourcepub fn build(
self,
llm: Arc<dyn BaseLlm>,
) -> Result<Arc<dyn TextAgent>, ConfigError>
pub fn build( self, llm: Arc<dyn BaseLlm>, ) -> Result<Arc<dyn TextAgent>, ConfigError>
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.
Fails with a ConfigError when the configuration cannot be realized
by a text agent — today, an MCP toolset (T::mcp) in
tools, which needs the async connect only a Live
session performs.
let llm = Arc::new(GeminiLlm::new(GeminiLlmParams::default()));
let agent = AgentBuilder::new("analyst")
.instruction("Analyze the topic")
.temperature(0.3)
.build(llm)?;
let state = State::new();
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.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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> FutureExt for T
impl<T> FutureExt for T
§fn with_context(self, otel_cx: Context) -> WithContext<Self>
fn with_context(self, otel_cx: Context) -> WithContext<Self>
§fn with_current_context(self) -> WithContext<Self>
fn with_current_context(self) -> WithContext<Self>
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§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>
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>
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§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request§impl<L> LayerExt<L> for L
impl<L> LayerExt<L> for L
§fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>where
L: Layer<S>,
Layered].