Expand description
Declarative state-to-narrative context builder.
A ContextBuilder renders session State into a natural-language summary
that gets appended to the phase instruction via super::InstructionModifier::CustomAppend.
It replaces hand-written fn app_context(s: &State) -> String closures with a
declarative, composable API.
§How it works
- Declare sections — named groups of related state keys
- Each section has fields — state keys with display labels and render modes
- The builder checks each key in state, skips missing values, formats present ones
- If the current phase has
needsmetadata, appends a “Gathering:” line for missing keys so the model knows what to focus on
§Output format
[Caller] Name: Bob. Organization: Google. Known contact.
[Call] Purpose: schedule meeting. Urgency: high (0.8).
[Gathering] caller_organizationEmpty sections are omitted. When no state has been gathered, returns an empty string (no noise in the instruction).
§Example
ⓘ
use gemini_adk_rs::live::context_builder::ContextBuilder;
let ctx = ContextBuilder::new()
.section("Caller")
.field("caller_name", "Name")
.field("caller_organization", "Organization")
.flag("is_known_contact", "Known contact")
.section("Call")
.field("call_purpose", "Purpose")
.sentiment("caller_sentiment")
.build();
// Use with phase_defaults:
// .phase_defaults(|d| d.with_context(ctx))Structs§
- Context
Builder - Declarative state-to-narrative renderer.
- Section
Builder - Fluent builder for a single section.