Skip to main content
We’re back in agent.py with one final field to tighten: the instruction string. The model selection, agent name, and description are in place, but the current instruction — “Answer the user’s questions.” — is too vague. That tiny line often makes the difference between an unpredictable assistant and one that behaves reliably in production. Below you’ll see a weak, default instruction and a stronger alternative. Use the stronger pattern every time you build an agent. Weak (default) example the prebuilt project gives you:
It works, but it leaves every decision to the model. The assistant will answer anything — from order lookups to creative writing — and that increases the risk of hallucinations, inconsistent tone, or costly token usage. A stronger instruction performs three specific jobs. Every instruction you write should address these:
  • Job 1 — Role: define the assistant’s lane (what it should and should not do).
  • Job 2 — Constraints: list hard rules the assistant must follow.
  • Job 3 — Tone: two or three words that define the voice.
Concise, strong instruction example (inline or triple-quoted):
Why this works
  • Role keeps the agent focused (it should politely decline unrelated tasks).
  • Constraints prevent dangerous behavior (e.g., hallucinating order statuses).
  • Tone enforces a consistent voice across responses.
When you need a specific output shape, show it. A tiny example inside the instruction beats long prose. For instance, include a minimal JSON response example so the agent learns the exact format you expect.
When you require a strict output format, include a minimal, exact example inside the instruction or the prompt. Even a one-line JSON example helps the model produce predictable, parseable responses.
Example of a minimal JSON example you might include:
Quick reference: the three instruction jobs Choosing the right model tier
  • Gemini Flash (fast, inexpensive): handle routing, short conversations, and many common agents. Start here.
  • Gemini Pro (slower, costlier): use for heavy multi-step reasoning, complex planning, or when Flash isn’t sufficient.
Match the model to the hardest task the agent must handle — not the average task. Most agents are fine on Flash; move to Pro only when you see consistent failure modes that require deeper reasoning.
A dark-themed slide titled "Flash or Pro" showing a comparison table: Flash (fast and cheap, follows instructions, routes to tools, short conversations) versus Pro (slower, costs more, reasons harder, multi-step planning, tricky judgment calls). A highlighted tip at the bottom reads "Match the model to the hardest thing — not the average thing."
Final checklist before you ship an agent
  • Have a single-line Role.
  • List concise, enforceable Constraints.
  • Specify Tone in two or three words.
  • Include an exact output example when format matters.
  • Start with Flash; only upgrade to Pro when necessary.
Read your instruction string out loud. If it clearly states the agent’s role, rules, and voice, you’re done — the runtime now has a focused, predictable assistant to run in production.

Watch Video