Module tape

Module tape 

Source
Expand description

Record model and resolver outputs once; replay them without the network.

replay_session re-drives a recorded Live session through the real control plane, but anything that calls a model or a remote service out of band still runs for real:

  • an LLM extractor;
  • an async resolver behind a slot;
  • a background agent.

A replay would then cost money, need credentials, and could answer differently. A Tape closes that gap. While recording, every call’s input and output are appended to it. While replaying, calls are answered from it, in the order they were recorded, and nothing leaves the process.

Calls are matched on their canonical JSON input: the request, or the resolver’s name and arguments. The same input recorded twice replays its two outputs in order. A replay that asks for something the tape does not hold fails loudly rather than calling out.

use std::sync::Arc;
use gemini_adk_rs::llm::{BaseLlm, LlmRequest, LlmResponse, MockLlm};
use gemini_adk_rs::tape::{MemoryTape, TapedLlm};

let tape = Arc::new(MemoryTape::new());

// Record against a real (here: scripted) model.
let live = TapedLlm::recording(MockLlm::script([LlmResponse::from_text("Paris")]), tape.clone());
live.generate(LlmRequest::from_text("Capital of France?")).await?;

// Replay with no model at all.
let offline = TapedLlm::replaying("gemini-2.5-flash", tape);
let reply = offline.generate(LlmRequest::from_text("Capital of France?")).await?;
assert_eq!(reply.text(), "Paris");

Structs§

FileTape
A tape kept in a JSONL file, one TapeEntry per line.
MemoryTape
A tape held in memory.
TapeEntry
One recorded call: what went in and what came out.
TapedLlm
A BaseLlm that records its calls to a Tape or answers them from one. See the module docs.

Enums§

TapeMode
Whether a taped_resolver records calls or answers them from the tape.

Constants§

LLM_CALL
The kind of call a TapeEntry records.

Traits§

Tape
Where recorded calls are kept.

Functions§

canonical_json
Canonical JSON for value: object keys sorted, no whitespace.
taped_resolver
Wrap a resolver’s fetch so its calls are recorded on, or answered from, tape.