Example Store: Steer Behavior with Few-Shot Examples
Curate few-shot examples centrally in Example Store and retrieve the relevant ones at runtime to steer the agent's behavior — improving quality without retraining a model or bloating the prompt.
Download starter repoOn this page▾
- Before you start: this is a billed cloud service
- About this series
- What you'll build
- Why this matters (the 5-minute business case)
- Concepts you'll use (2-minute primer)
- Prerequisites
- Step 1 — Create an Example Store
- Step 2 — Upload curated examples
- Step 3 — Retrieve relevant examples at runtime
- Step 4 — Inject the examples and steer the agent
- Cost & cleanup
- Verified against
- What's next
Before you start: this is a billed cloud service
- Cost and account. A Google Cloud project with billing enabled and the Vertex AI APIs on. An Example Store instance and its embedding/search calls bill while it exists. Example Store is `us-central1`-only as of this writing — use that region.
- Authored against the docs, not executed live. The Python is written against the official docs and syntax-checked, not run during authoring. The example schema is detailed and evolving — pin your SDK version (
google-cloud-aiplatform>=1.87.0) and adjust shapes to match. - SDK-first.
About this series
This is Part 6 of the eleven-part Gemini Enterprise Agent Platform series. Lab 5 gave the agent memory of who it's talking to. This lab improves how it behaves — using Example Store to curate few-shot examples centrally and inject the relevant ones at runtime, so you can steer quality without retraining a model or endlessly editing a prompt.
What you'll build
You'll set up an Example Store for the Acme assistant and use it to lock in good behavior:
- Create an Example Store instance.
- Upload a handful of curated examples — good interactions that show the agent how to handle tricky cases (a return edge case, the right tool call, the right tone).
- Retrieve the most relevant examples at runtime by similarity to the user's message.
- Inject them into the agent's context so it follows the demonstrated pattern.
By the end you'll have a reusable library of "this is how we want it done" examples that any agent can pull from — behavior managed as data.
Why this matters (the 5-minute business case)
Read this before handing the lab to your team.
Few-shot examples are the cheapest, fastest lever for agent quality — and most teams manage them badly. When an agent misbehaves on a specific case, the usual fixes are bad: bolt another paragraph onto the prompt (which bloats and drifts), or fine-tune a model (slow and expensive). Showing the model a few good examples of the exact behavior you want is more effective than either — and Example Store makes those examples a managed, shared, searchable asset instead of strings buried in code.
Three reasons this is a leadership-level concern:
- Quality without retraining. Examples steer behavior at request time. Improving the agent becomes "add a few good examples," which a domain expert can do — not a training run that needs an ML team and a week. The feedback loop from "we found a bad case" to "it's fixed" shrinks to minutes.
- Behavior as curated data, not prompt sprawl. Hard-coded few-shot examples rot: they pile up in the prompt, apply to every request whether relevant or not, and nobody dares touch them. An Example Store holds them centrally, retrieves only the ones relevant to the current query, and lets you version and review them like the asset they are.
- It compounds and it's shareable. One curated library of "how Acme handles returns / escalations / edge cases" can steer every agent you build, and it gets better as you add cases from real failures. That's institutional knowledge captured as reusable examples.
The honest caveats:
- Garbage examples teach garbage. Examples are training-by-demonstration at runtime — a sloppy or wrong example will faithfully steer the agent wrong. Curate them like you'd review code.
- Relevance matters more than volume. A few well-chosen examples retrieved by similarity beat a hundred generic ones stuffed into every prompt. Don't dump; curate and let search pick.
- It's another managed resource with cost and a region constraint. It bills, and it's
us-central1-only for now. Factor both in.
A framing for a non-technical stakeholder: "Example Store is a shared library of 'good answer' examples. When the agent hits a tricky case, it pulls the most relevant examples and follows them — so we improve quality by curating examples, not by retraining models or rewriting prompts."
Concepts you'll use (2-minute primer)
- Example Store — a managed instance that stores curated examples and retrieves the relevant ones via similarity search. Backed by an embedding model you choose.
- An example — a demonstration of a good interaction: a representative user input plus the ideal response (which can include the right tool/function call and the final answer).
- Search key — the text an example is matched on. At runtime you search with the user's query; the store returns the closest examples.
- Fetch vs. search — fetch returns examples matching exact filter criteria (fast, for small sets); search returns the most similar examples to a query (for larger libraries). You'll mostly use search.
- Runtime injection — you take the retrieved examples and put them in the model's context (as few-shot demonstrations) before it answers.
One sentence: curate good interactions once, store them, and at request time retrieve the few most relevant and show them to the model so it copies the pattern.
Prerequisites
| You need | Notes |
|---|---|
| A Google Cloud project | Billing enabled; Vertex AI APIs on; use `us-central1` |
gcloud + auth | gcloud auth application-default login |
| The SDK | pip install "google-cloud-aiplatform>=1.87.0" — pin it |
| A few curated examples | Sample Acme examples are in the starter repo |
| Helpful | Lab 4 (the tools your examples will demonstrate calling) |
Step 1 — Create an Example Store
import vertexai
from vertexai.preview import example_stores
vertexai.init(project="your-project-id", location="us-central1") # us-central1 only
store = example_stores.ExampleStore.create(
example_store_config=example_stores.ExampleStoreConfig(
vertex_embedding_model="text-embedding-005"
)
)
print(store.resource_name) # save this — it's your handle to the storeThe embedding model is the lens the store uses to decide which examples are relevant to a query, so it's worth choosing deliberately.
Step 2 — Upload curated examples
Each example shows the agent a good interaction: a representative input and the ideal response. For a tool-using agent, an example can demonstrate when to call which tool and how to phrase the final answer:
store.upload_examples(
examples=[
{
"stored_contents_example": {
"search_key": "customer wants to return an opened electronic item",
"contents_example": {
"contents": [
{"role": "user",
"parts": [{"text": "Can I return my opened headphones?"}]}
],
"expected_contents": [
{"content": {"role": "model", "parts": [
{"function_call": {"name": "get_return_policy",
"args": {"category": "electronics"}}}]}},
{"content": {"role": "user", "parts": [
{"function_response": {"name": "get_return_policy",
"response": {"window_days": 15,
"restocking_fee": "10%"}}}]}},
{"content": {"role": "model", "parts": [
{"text": "Opened electronics are returnable within 15 days, "
"with a 10% restocking fee. Want me to start the return?"}]}},
],
},
}
},
# ...more curated examples: escalations, missing order IDs, tone, etc.
]
)Notice this single example teaches three things at once: reach for the policy tool, use the right category argument, and answer concisely with a next step. That's a lot of steering from one good demonstration.
The example schema is detailed and shifts between SDK versions. The shape above follows the docs as of authoring; if your version rejects it, print an existing example with fetch_examples() to see the exact structure your SDK expects.Step 3 — Retrieve relevant examples at runtime
When a user message comes in, search the store for the closest examples instead of injecting everything:
results = store.search_examples(
parameters={
"stored_contents_example_parameters": {
"search_keys": ["customer asking about returning a used product"]
}
},
top_k=3,
)
for r in results:
print(r)You can also fetch_examples() to pull a small, fixed set by filter when you don't need similarity ranking. For anything beyond a handful of examples, prefer search — relevance beats volume.
Step 4 — Inject the examples and steer the agent
Take the retrieved examples and put them in front of the model as few-shot demonstrations before it answers the live query. In ADK, a before_model_callback is the natural seam — it runs just before the model call, so you can search the store with the current message and prepend the results:
def inject_examples(callback_context, llm_request):
"""Retrieve relevant examples and add them as few-shot context."""
user_text = _latest_user_text(llm_request) # your helper
results = store.search_examples(
parameters={"stored_contents_example_parameters":
{"search_keys": [user_text]}},
top_k=3,
)
# Format `results` into demonstration turns and prepend them to
# llm_request.contents so the model sees the pattern before answering.
return None # let the (now example-augmented) request proceed
agent.before_model_callback = inject_examplesNow, when a customer asks something near a curated case, the agent sees the demonstrated good behavior first — the right tool call, the right tone — and follows it. Found a new bad case in production? Add one good example and the agent improves, no redeploy of the model required.
Cost & cleanup
# Delete the Example Store when you're done
store.delete()- The Example Store instance bills while it exists — delete it with the snippet above (or from the console).
- Confirm in Billing → Reports that nothing is still accruing.
If a lab created it and you're done, delete it today.
Verified against
- Vertex AI Example Store docs (create, upload, fetch/search) and the `google-cloud-aiplatform` (>=1.87.0) SDK, June 2026. Example Store was
us-central1-only. - The example schema and method signatures vary by SDK version; code is syntax-checked against the docs but not executed during authoring. Pin your version and inspect a stored example to confirm the exact shape.
What's next
You can now steer behavior with curated examples. The obvious next question is: how do you know it's actually better?
- Lab 7 — Gen AI Evaluation service: measure agent and model quality with managed metrics and datasets, and gate ship/no-ship on evidence — the natural partner to this lab's quality work.
- Cross-link: the standalone Evaluating Agents lab on treating evals as code, and ADK Lab 4 (evaluation & safety). Curated examples + real evaluation is how quality stops being a vibe.
Written by Wes Goldwater, Director of Engineering at Prosigliere.
Hands-on cloud & pragmatic AI from Goldwater.dev.