Skip to main content
This page collects practical patterns for building reliable, cost-effective agents. Read Getting started with Agents first if you haven’t set up an agent yet.

Write effective system instructions

The three instruction fields serve distinct purposes — using them well is the single highest-leverage thing you can do for quality:

Be specific about role and scope

Vague instructions produce inconsistent results. Give the agent a clear role and list what it should and should not do.

Use planning_prompt for multi-step work

For agents that orchestrate complex tasks — generating reports, extracting data across sources, or running multi-step workflows — planning_prompt tells the agent how to think before it acts:
Iterate instructions the same way you iterate code: start minimal, run real prompts, and refine based on failures. The generate → claim → create flow is useful for getting a first draft quickly.

Choose the right mode

The mode controls how much planning and tool use happens for each turn. Pick the lightest mode that meets your needs — heavier modes take longer and cost more.
magpie-2.5-flash is deprecated and being withdrawn. Do not use it for new agents. For Ask behavior, use chat_mode: "llm_router"; for retrieval-focused workflows, use magpie-1.1-flash.
See Converse modes for the full mapping between chat_mode, config.agent_model, in-app labels, and tool availability.

Scope knowledge for predictable behavior

By default an agent can reach all knowledge your organization has access to. This is convenient for exploration but problematic in production: the agent may pull in unrelated content, or expose knowledge that shouldn’t inform the answer. Set corpus explicitly to lock down what the agent reads.
You can also scope a single Converse turn without changing the stored agent by passing config.corpus on the request:
Each corpus item is either { "type": "knowledge", "knowledge_id": "kn_…" } or { "type": "page", "page_id": "page_…" }. Mixing both types in the same corpus is allowed. See Knowledge and corpus for more details.

Select tools with least privilege

Giving an agent every tool makes it flexible but also increases the risk of side effects (writing data when the agent should only read) and can add latency from unnecessary tool-selection overhead. Start with the minimum tools needed and add more only when required.

Use disabled_tools for fine-grained control

disabled_tools is applied after the tools list — useful when you want most of the default set but need to block specific tools:
magpie-1.1-flash (Extended tier) only supports semantic_search. llm-only supports no tools. Specifying unsupported tools for these models will cause the request to be rejected.

Use structured outputs for integrations

When Converse is part of a pipeline — a webhook handler, a data-processing job, or a typed API — use text.format to guarantee the response matches your schema. This works for every mode and agent.
Schema design tips:
  • Keep schemas flat where possible — deeply nested schemas are harder to validate and produce more hallucination surface.
  • Mark only the fields you always need as required. Optional fields reduce failures on partial data.
  • Use additionalProperties: false to prevent the model from adding undocumented keys.
See Structured outputs for the full reference.

Iterate faster with the generate → claim → create flow

When starting a new agent, use agents.generate to get a first draft of instructions and tool selection from a natural-language description, then refine by hand.
The claim_token expires after 7 days. The claim step retrieves the template — it does not create an agent. You still need to call agents.create to persist it.
After creating, use agents.update to iterate on instructions without destroying and re-creating the agent:

Cost and latency guidance

Mode choice is the primary lever for both cost and latency: The table below covers the currently recommended models. magpie-2.5-flash is deprecated and being withdrawn, so it is intentionally omitted. See Converse modes for the authoritative tier table.

Reduce streaming overhead

When streaming, set include_steps: false to suppress intermediate tool and reasoning events. This reduces event volume and is the right default for end-user-facing UIs that only need to show the final answer:
Use stream: true for any task that may take several seconds — it gives end-users visible progress instead of a silent wait, even if you’re only interested in the final end event. See Streaming for the full event shape.

Other latency tips

  • Narrow corpus — a tightly scoped corpus means the retrieval step searches less, returning results faster.
  • Narrow tools — fewer tools means less overhead for the agent to decide which to call.
  • Cache conversation_id — re-using a conversation_id gives the agent conversation history without re-sending it, keeping prompt size bounded over long sessions.

Next steps