Module context_builder

Module context_builder 

Source
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

  1. Declare sections — named groups of related state keys
  2. Each section has fields — state keys with display labels and render modes
  3. The builder checks each key in state, skips missing values, formats present ones
  4. If the current phase has needs metadata, 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_organization

Empty 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§

ContextBuilder
Declarative state-to-narrative renderer.
SectionBuilder
Fluent builder for a single section.