Skip to main content

Module few_shot

Module few_shot 

Source
Expand description

Minimal few-shot example infrastructure.

Implements a keyword-based selector with token-budget enforcement per Section 18.3.3 of the agentic-AI guide:

Few-shot examples improve reliability but consume tokens. The harness should select relevant examples using embedding similarity to the current query, rotate examples to avoid overfitting, budget examples within the model allocation, and cache embeddings of the example library to avoid recomputation.

This module ships the keyword-based selector (no embedding provider dependency) and the token-budget enforcement (via vtcode_commons::tokens::estimate_tokens). Embedding-based selection and embedding-cache can layer on top later without changing the API.

§Example file format

Examples live under <workspace>/.vtcode/prompts/examples/*.md or the canonical user config prompts directory’s examples/*.md. The filename stem is the stable id; the file body uses YAML frontmatter for metadata:

---
id: read-then-edit-large-file
tags: [read, edit, large-file, patch]
summary: Read a large file in chunks, then patch with apply_patch.
---
# User
Refactor src/foo.rs to use the new API.

# Assistant
(the example body showing expected tool sequence)

Both tags and summary are optional; the loader derives sensible defaults when they are absent.

Structs§

FewShotExample
A single few-shot example loaded from disk.
FewShotStore
Library of few-shot examples discovered from disk.

Constants§

DEFAULT_FEW_SHOT_BUDGET_TOKENS
Default token budget for the [Few-Shot Examples] block. ~10% of an 8K context window, leaving the remainder for the base prompt, tools, history, and the model’s response.
FEW_SHOT_SECTION_HEADER
First line of every rendered few-shot block. The runloop persists the block in history once per user turn and recognizes it by this header.

Functions§

render_few_shot_section
Render selected examples into the prompt section body. Returns an empty string when examples is empty so callers can writeln! it unconditionally.