Examples

The repository contains two sets of runnable examples:

  1. examples/cookbook/ — 30 progressive text-based examples demonstrating SDK composition patterns (no server required)
  2. gemini-adk-web-rs apps — Interactive voice/text demos bundled into a devtools-enabled web UI

Cookbook Examples (examples/cookbook/)

A structured Crawl → Walk → Run learning path. Each example is a self-contained Rust binary with detailed doc comments explaining every API used.

# Run any example directly
cargo run -p example-cookbook --example 01_simple_agent
cargo run -p example-cookbook --example 17_evaluation_suite
cargo run -p example-cookbook --example 30_production_pipeline

Crawl (01–10) — Foundations

The core builder API and composition primitives. No async runtime required for most examples.

#BinaryWhat it covers
0101_simple_agentAgentBuilder: name, model, instruction, temperature, thinking budget, copy-on-write semantics
0202_agent_with_toolsSimpleTool with raw JSON args; TypedTool with auto-generated JSON Schema from schemars::JsonSchema
0303_callbacksEvent callbacks: on_text, on_audio, on_thought, on_tool_call, on_interrupted, on_turn_complete
0404_sequential_pipeline>> operator: multi-step pipelines, state passing between agents, SequentialTextAgent
0505_parallel_fanout| operator: concurrent fan-out, ParallelTextAgent, merging results
0606_loop_agent* N fixed loop; * until(predicate) conditional loop; LoopTextAgent
0707_state_transformsS::pick, S::rename, S::merge, S::flatten, S::set, S::defaults, S::drop, S::map
0808_prompt_compositionP::role, P::task, P::constraint, P::format, P::example, P::guidelines, P::with_state, P::when
0909_tool_compositionT::simple | T::google_search | T::code_execution | T::url_context| operator for tools
1010_guardsG::rate_limit, G::toxicity, G::grounded, G::hallucination, G::llm_judge — input/output validation

Walk (11–20) — Multi-Agent Patterns

Compound agent topologies, evaluation, artifacts, and advanced state management.

#BinaryWhat it covers
1111_route_branchingRouteTextAgent, FnTextAgent, RouteRule, S::is_true, S::eq — deterministic state-driven routing
1212_fallback_chain/ operator: graceful degradation, FallbackTextAgent, primary/secondary chains
1313_review_loopReviewer + writer feedback cycle, * until(predicate) convergence, inter-agent state sharing
1414_map_overMapOverTextAgent: parallel item-level processing, collecting and aggregating results
1515_middleware_stackM::cache, M::dedup, M::metrics, M::fallback_model — composing middleware with |
1616_context_engineeringC::window, C::user_only, C::model_only, C::summarize, C::priority, C::exclude_tools, C::dedup
1717_evaluation_suiteE::suite, E::response_match, E::contains_match, E::trajectory, E::safety, E::semantic_match, E::hallucination, E::custom, E::persona
1818_artifactsA::json_output, A::text_output, A::publish, A::save, A::load, A::version — artifact I/O schemas
1919_agent_toolTextAgentTool: wrapping a TextAgent as a callable tool; agent-as-tool dispatch
2020_supervisedHuman-in-the-loop approval: TapTextAgent, approval callbacks, blocking and resuming pipelines

Run (21–30) — Production Patterns

Full-system compositions covering real-world architectures and every SDK capability.

#BinaryWhat it covers
2121_full_algebraAll operators together (>>, |, *, /, * until), all six composition namespaces
2222_contract_testingSchema validation, JSON contract tests, A::json_output with schema enforcement
2323_deep_researchMulti-source research pipeline with T::google_search, synthesis agent, and result merging
2424_customer_supportRouting, escalation state machine, RouteTextAgent, multi-phase support flow
2525_code_reviewAutomated code review: linting agent, security agent, summary agent in a >> pipeline
2626_dispatch_joinDispatchTextAgent + JoinTextAgent: fire-and-forget dispatch with join synchronization
2727_race_timeoutRaceTextAgent: first-to-finish wins; TimeoutTextAgent: deadline enforcement
2828_a2a_remoteAgent-to-agent protocol: remote agent declaration, T::a2a tool composition
2929_live_voiceFull Live::builder() API: phases, tools, extraction, watchers, steering, repair, persistence
3030_production_pipelineEnd-to-end production pipeline: telemetry, middleware, evaluation, artifact publishing

ADK Web UI (gemini-adk-web-rs)

The interactive multi-app web UI runs at http://localhost:25125 and bundles all demo apps into a single server with a shared DevTools panel.

cargo run -p gemini-adk-web-rs    # http://127.0.0.1:25125

For more on the web UI design system, dark/light mode, and DevTools panels, see the ADK Web UI guide.

Standalone Examples

These run independently outside of gemini-adk-web-rs, each with their own Axum server.

cargo run -p example-text-chat       # http://127.0.0.1:3001
cargo run -p example-voice-chat      # http://127.0.0.1:3002
cargo run -p example-tool-calling    # http://127.0.0.1:3003
cargo run -p example-transcription   # http://127.0.0.1:3004
ExampleLayerFeatures
text-chatL0Text-only session, streaming deltas, turn lifecycle
voice-chatL0Bidirectional audio, input/output transcription, VAD events
tool-callingL1TypedTool, ToolDispatcher, NonBlocking behavior, WhenIdle scheduling
transcriptionL0Every Gemini Live config option: VAD, compression, resumption, affective dialog

Web UI Apps

Crawl

text-chat — Minimal text session. Live::builder().text_only(), streaming.

voice-chat — Native audio. Modality::Audio, voice selection, transcription.

tool-calling — Three demo tools (get_weather, get_time, calculate). NonBlocking + WhenIdle.

Walk

all-config — Configuration playground. Every Gemini Live option exposed as a JSON config: modality, temperature, Google Search, code execution, session resumption, context compression.

guardrails — Policy monitoring with real-time corrective injection. RegexExtractor, .watch(), .instruction_amendment(). Policies: PII (SSN, credit cards), off-topic, negative sentiment.

playbook — 6-phase customer support state machine. .phase(), .transition_with(), .greeting(), .with_context(), RegexExtractor, .watch().

Run

support-assistant — Multi-agent handoff between billing and technical support. 10-phase dual state machine, .computed() derived state, .watch() escalation, cross-agent transitions, telemetry.

call-screening — Incoming call screening with sentiment analysis and smart routing. NonBlocking tools: check_contact_list, check_calendar, take_message, transfer_call, block_caller.

clinic — HIPAA-aware telehealth appointment scheduling. 8 tools with NonBlocking behavior. Patient intake, department routing, insurance check, appointment booking.

restaurant — Reservation assistant with menu context. 6 tools, dietary and occasion tracking.

debt-collection — FDCPA-compliant debt collection. StateKey<T> typed state, compliance watchers, identity verification, cease-and-desist handling.


Platform Support

All examples work with both Google AI (API key) and Vertex AI (project/location).

FeatureGoogle AIVertex AI
Async tool calling (NonBlocking)✓ SupportedStripped automatically
Response scheduling (WhenIdle / Silent)✓ SupportedStripped automatically
WebSocket framesTextBinary (handled automatically)
Thinking config✓ SupportedStripped automatically

The SDK detects your authentication method and strips unsupported wire fields transparently — no code changes needed when switching platforms.