Conversation

Struct Conversation 

Source
pub struct Conversation { /* private fields */ }
Expand description

Fluent builder that produces a ConversationSpec; sugar over the spec.

(Not Debug: resolve_slot bindings hold async closures. The serializable ConversationSpec is Debug via spec.)

Implementations§

Source§

impl Conversation

Source

pub fn new(name: impl Into<String>) -> Self

Start a new conversation.

Source

pub fn stage(self, id: impl Into<String>) -> Self

Begin authoring a new stage; subsequent setters apply to it. Routes to the active overlay when between .overlay(..) and .end_overlay().

Source

pub fn overlay(self, name: impl Into<String>) -> Self

Begin authoring a digression/overlay; subsequent .stage(..) calls (until .end_overlay()) populate it. Set its activation guard with .trigger(..) (an overlay with no trigger never fires — fail-closed).

Source

pub fn trigger(self, guard: Guard) -> Self

Set the activation guard of the overlay currently being authored.

Source

pub fn resume(self, resume: Resume) -> Self

Set the resume policy of the overlay currently being authored.

Source

pub fn end_overlay(self) -> Self

End overlay authoring; subsequent .stage(..) calls target the main flow again. (Not a sub-builder exit — the Conversation is the same value throughout — so it is named for what it does.)

Source

pub fn add_stage(self, stage: StageSpec) -> Self

Append a pre-built StageSpec (e.g. from a Motif). Routes to the active overlay when authoring one, else the main flow. Subsequent stage setters (next, say, …) apply to it.

Source

pub fn add_overlay(self, overlay: OverlaySpec) -> Self

Append a pre-built OverlaySpec (e.g. a Motif::faq_digression). Leaves overlay-authoring mode (the overlay is already complete).

Source

pub fn policy(self, policy: impl Into<Policy>) -> Self

Attach a cross-cutting Policy aspect.

Source

pub fn instruction(self, text: impl Into<String>) -> Self

Set the stage’s instruction: guidance projected to the model while the stage is active. It steers what the model says; it is not verbatim speech and carries no guarantee of exact wording.

Source

pub fn say(self, text: impl Into<String>) -> Self

Alias of instruction. The name suggests exact speech, which this never was; prefer instruction in new code.

Source

pub fn ground(self, template: impl Into<String>) -> Self

Set the stage’s grounding template.

Source

pub fn collect<I, S>(self, fields: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Collect the given slots in this stage (drives default completion).

Source

pub fn collect_frame<F: Frame>(self) -> Self

Collect the slots of a typed gemini_adk_rs::frame::Frame in this stage. The frame’s slot state-keys drive the captured completion; its metadata (prompts/confirm/pii) is available via F::frame() for confirmation and repair.

Source

pub fn allow<I, S>(self, tools: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Allow the given tools while this stage is active.

Source

pub fn complete_when(self, guard: Guard) -> Self

Set an explicit completion guard for this stage: the stage counts as complete when guard holds (default: all collected slots captured).

Source

pub fn commit(self, tool: impl Into<String>, when: Guard) -> Self

Commit a confirm-before-act tool in this stage, gated by when.

Source

pub fn next(self, to: impl Into<String>, when: Guard) -> Self

Add a forward transition to to when when holds.

Source

pub fn resolve_slot<I, S, F, Fut>( self, name: impl Into<String>, args: I, ttl: Option<Duration>, fetch: F, ) -> Self
where I: IntoIterator<Item = S>, S: Into<String>, F: Fn(Value) -> Fut + Send + Sync + 'static, Fut: Future<Output = Result<Value, String>> + Send + 'static,

Fill a slot in the current stage from an async resolver — a tool call, HTTP fetch, MCP request, or agent. args names the State keys bound into the JSON object passed to fetch; the returned value fills name. With a ttl, results are memoized by (field, canonical args).

The slot is added to the stage’s collect, so its captured completion waits for the resolution. The closure lives only in the builder; the serializable spec is unaffected.

Source

pub fn after(self, dep: impl Into<String>) -> Self

Add an explicit dependency on another stage.

Source

pub fn terminal(self) -> Self

Mark the current stage terminal.

Source

pub fn repair(self, policy: RepairPolicy) -> Self

Attach a RepairPolicy to the current stage.

Source

pub fn verbatim(self, text: impl Into<String>) -> Self

Require the current stage to say text word for word (strict canned mode): it completes only once the model’s output transcript matches. The model holds the floor while it reads, unless the stage sets timing. Needs output transcription on the session.

Source

pub fn timing(self, timing: VoiceTiming) -> Self

Set the current stage’s voice pacing; see VoiceTiming.

use std::time::Duration;
Conversation::new("disclosure")
    .stage("read_terms")
    .say("Read the terms word for word.")
    .timing(VoiceTiming::new().uninterruptible())
    .stage("confirm")
    .collect(["agreed"])
    .timing(VoiceTiming::new().reprompt_after(Duration::from_secs(6)));
Source

pub fn require<I, S>(self, steps: I) -> Self
where I: IntoIterator<Item = S>, S: Into<String>,

Require these stages for completion (lowers to a Flow require). Targets the active overlay when authoring one, else the main flow.

Source

pub fn spec(&self) -> &ConversationSpec

The spec built so far.

Source

pub fn into_spec(self) -> ConversationSpec

Consume into the underlying spec.

Source

pub fn from_spec( spec: ConversationSpec, ) -> Result<CompiledConversation, ConversationError>

Compile from a ConversationSpec (e.g. parsed from JSON/YAML).

If the spec declares any named-resolver slots (stage.resolve), this errors — those slots would be collected but never filled. Use Conversation::from_spec_with_resolvers to bind them.

Source

pub fn from_spec_stubbing_resolvers( spec: ConversationSpec, ) -> Result<CompiledConversation, ConversationError>

Compile a ConversationSpec with its declared resolvers stubbed (each returns JSON null) — for structural validation, model-free simulation, and CI, where resolver outputs are supplied by scenario set steps rather than live fetches.

Use this (not from_spec) when compiling a spec from untrusted JSON for testing/authoring; use from_spec_with_resolvers at deploy time to bind real implementations.

Source

pub fn from_spec_with_resolvers( spec: ConversationSpec, registry: &ResolverRegistry, ) -> Result<CompiledConversation, ConversationError>

Compile a ConversationSpec and bind its declared named-resolver slots from registry. This makes a JSON spec + a resolver registry a complete deployable unit.

Errors if the spec references a resolver name absent from registry.

Source

pub fn compile(self) -> Result<CompiledConversation, ConversationError>

Lower and validate into a CompiledConversation.

Trait Implementations§

Source§

impl Clone for Conversation

Source§

fn clone(&self) -> Conversation

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Default for Conversation

Source§

fn default() -> Conversation

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> FromRef<T> for T
where T: Clone,

§

fn from_ref(input: &T) -> T

Converts to this type from a reference to the input type.
§

impl<S> FromSample<S> for S

§

fn from_sample_(s: S) -> S

§

impl<T> FutureExt for T

§

fn with_context(self, otel_cx: Context) -> WithContext<Self>

Attaches the provided Context to this type, returning a WithContext wrapper. Read more
§

fn with_current_context(self) -> WithContext<Self>

Attaches the current Context to this type, returning a WithContext wrapper. Read more
§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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

§

fn into_request(self) -> Request<T>

Wrap the input message T in a tonic::Request
§

impl<L> LayerExt<L> for L

§

fn named_layer<S>(&self, service: S) -> Layered<<L as Layer<S>>::Service, S>
where L: Layer<S>,

Applies the layer to a service and wraps it in [Layered].
§

impl<T> Pointable for T

§

const ALIGN: usize

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
§

impl<T> PolicyExt for T
where T: ?Sized,

§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] only if self and other return Action::Follow. Read more
§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns [Action::Follow] if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> ToSample<U> for T
where U: FromSample<T>,

§

fn to_sample_(self) -> U

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V

§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<T> CloneAny for T
where T: Any + Clone,

§

impl<S, T> Duplex<S> for T
where T: FromSample<S> + ToSample<S>,

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,